If anyone has some sample code i could use, that'd be great. I want to do this the most effecient way possible for where we are at right now (the method might get outdated later). I think that might be using the GPU (GU?)
Code: Select all
//Function For Printing An Image to the Screen
//Created by Yeldarb (with help from other code) on August 21, 2005
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
/* Define the module info section */
PSP_MODULE_INFO("xxxxxxx", 0, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
//External Files (Images)
extern u32 image_start[];
extern u32 image1_start[];
u32* images[] = { image_start, image1_start };
//Color "Functions" (Conversion and Test)
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
#define IS_ALPHA(value) (((value)&0xff000000)==0)
//constants
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272
#define	PSP_PIXEL_FORMAT 3  // 32 bit RGBA
#define	PSP_LINE_SIZE 512   // in u32
//480*272 = 60*38
#define CMAX_X 60
#define CMAX_Y 38
#define CMAX2_X 30
#define CMAX2_Y 19
#define CMAX4_X 15
#define CMAX4_Y 9
u32* pg_vramtop = (u32*)(0x04000000+0x40000000);
long pg_screenmode;
long pg_showframe;
long pg_drawframe;
int exit_callback(void) {
	sceKernelExitGame();
	return 0;
}
void CallbackThread(void *arg) {
	int cbid;
	cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
	sceKernelRegisterExitCallback(cbid);
	sceKernelSleepThreadCB();
}
int SetupCallbacks(void) {
	int thid = 0;
	thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
	if(thid >= 0) {
		sceKernelStartThread(thid, 0, 0);
	}
	return thid;
}
void pgWaitVn(unsigned long count) {
	for (; count>0; --count) {
		sceDisplayWaitVblankStart();
	}
}
void pgWaitV() {
	sceDisplayWaitVblankStart();
}
u32* pgGetVramAddr(unsigned long x,unsigned long y) {
	return pg_vramtop+(y * PSP_LINE_SIZE)+x+(pg_drawframe?PSP_LINE_SIZE*SCREEN_HEIGHT:0);
}
void pgScreenFrame(long mode,long frame) {
	pg_screenmode=mode;
	frame=(frame?1:0);
	pg_showframe=frame;
	if (mode==0) {
		//screen off
		pg_drawframe=frame;
		sceDisplaySetFrameBuf(0,0,0,1);
	} else if (mode==1) {
		//show/draw same
		pg_drawframe=frame;
		sceDisplaySetFrameBuf((char*)(pg_vramtop+(pg_drawframe?PSP_LINE_SIZE*SCREEN_HEIGHT:0)),PSP_LINE_SIZE,PSP_PIXEL_FORMAT,1);
	} else if (mode==2) {
		//show/draw different
		pg_drawframe=(frame?0:1);
		sceDisplaySetFrameBuf((char*)(pg_vramtop+(pg_drawframe?PSP_LINE_SIZE*SCREEN_HEIGHT:0)),PSP_LINE_SIZE,PSP_PIXEL_FORMAT,1);
	}
}
void pgInit() {
	sceDisplaySetMode(0,SCREEN_WIDTH,SCREEN_HEIGHT);
	pgScreenFrame(0,0);
}
void pgScreenFlip() {
	pg_showframe=(pg_showframe?0:1);
	pg_drawframe=(pg_drawframe?0:1);
	sceDisplaySetFrameBuf((char*)(pg_vramtop+(pg_showframe?PSP_LINE_SIZE*SCREEN_HEIGHT:0)),PSP_LINE_SIZE,PSP_PIXEL_FORMAT,0);
}
void pgScreenFlipV() {
	pgWaitV();
	pgScreenFlip();
}
void pgFlipDrawFrame() {
	pg_drawframe=(pg_drawframe?0:1);
}
void pgFlipShowFrameV() {
	pgWaitV();
	pg_showframe=(pg_showframe?0:1);
	sceDisplaySetFrameBuf((char*)(pg_vramtop+(pg_showframe?PSP_LINE_SIZE*SCREEN_HEIGHT:0)),PSP_LINE_SIZE,PSP_PIXEL_FORMAT,0);
}
void plotImage(int x, int y, u32* image, int sizeX, int sizeY) {
	u32* vram = pgGetVramAddr(x, y);
	int xo, yo;
	for (yo = 0; yo < sizeY; yo++) {
		for (xo = 0; xo < sizeX; xo++) {
			if (!IS_ALPHA(*image)) {
				vram[xo + yo * PSP_LINE_SIZE] = *image;
			} else {
                //Uncomment this Line if You Want a Background Image (And Don't Clear the Screen)
				//vram[xo + yo * PSP_LINE_SIZE] = background_start[x + xo + (y + yo) * SCREEN_WIDTH];
			}
			image++;
		}
	}
}
int main() {
	SetupCallbacks();
	pgInit();
	pgScreenFrame(1, 1);
	
	int x=0;
	int y=0;
	int cursorWidth = 15;
	int cursorHeight = 25
	int speed = 5;
	
	SceCtrlData pad;
	int changed = 1;
	while(1) {
        sceDisplayWaitVblankStart();
        
		sceCtrlReadBufferPositive(&pad, 1); 
		if (pad.Buttons & PSP_CTRL_LEFT) {
            if(x-speed >= 0) {
                x -= speed;
                changed = 1;
            }
        } 
        if(pad.Buttons & PSP_CTRL_RIGHT) {
            if(x+speed+50 <= 480) {
                x += speed;
                changed = 1;
            }
        }
        if(pad.Buttons & PSP_CTRL_UP) {
            if(y-speed >= 0) {
                y -= speed;
                changed = 1;
            }
        } 
        if(pad.Buttons & PSP_CTRL_DOWN) {
            if(y+speed+50 <= 272) {
                y += speed;
                changed = 1;
            }
        }
        if(changed) {
            plotImage(0, 0, images[0], 480, 272);
            plotImage(x, y, images[1], 15, 25);
            changed = 0;
        }    
    }
    
    return 0;
}
