Code: Select all
#define LINESIZE 512 //in short
#define FRAMESIZE 0xAA000 //in byte
unsigned char *vramtop=(unsigned char *)0x04000000;
unsigned long drawframe;
// get vram address for character position
unsigned char *GetVramAddr(unsigned long x,unsigned long y)
{
return vramtop+(drawframe?FRAMESIZE:0)+x*4+y*LINESIZE*4+0x40000000;
}
1) (I'm sure VERY noobish) how are these large numbers being handled by unsigned chars? Isn't the maximum size being exceeded many times over?
2) Is the vram set up with 2 frames for double buffering, and thats why drawframe is used to determine where to draw? or is this something different?
3) What is the +0x40000000 for?
Any other information would help greatly, because while I play with it I piece it together little by little, but my graphics are still flashing. This is what I have:
Code: Select all
void DrawSquare(int x,int y,int w,int h,int color)
{
unsigned char * vram = GetVramAddr(x,y);
int i,j;
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
*((unsigned long *)(vram+j*4)) = color;
}
vram+=LINESIZE*4;
}
}
int main()
{
pspDebugScreenInit();
SetupCallbacks();
int x=50,y=50;
SceCtrlData pad;
while(1)
{
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS)
break;
else if(pad.Buttons & PSP_CTRL_LEFT)
{
x--;
}
else if(pad.Buttons & PSP_CTRL_RIGHT)
{
x++;
}
else if(pad.Buttons & PSP_CTRL_UP)
{
y--;
}
else if(pad.Buttons & PSP_CTRL_DOWN)
{
y++;
}
char buf[16];
Fillvram(0x00FF00FF);
DrawSquare(x,y,10,10,0x00FFFFFF);
printcoords(x,y,buf); //buf will be: "x:00003 y:00002" if (x,y) = (3,2)
Print(0,0,0x00FFFFFF,buf);
drawframe = !drawframe;
}
sceKernelSleepThread();
return 0;
}