## Calculate destination PSP screen pixel from variable buffer?

I have a buffer that contains all the pixels for a screen resolution (see 80386 interrupt 10h graphic modes).

When a pixel is plotted in the buffer (e.g. 10,12 (x,y) is plotted at (12*rowsize)+10), i want it to update the correct pixel on the screen with resizing the original screen resolution to the PSP screen.

e.g.

Code:
```typedef unsigned char byte; //Typedef for handling further down and ease.

u32 screen_buffer[1024*768];

//Resolution of PSP Screen!
#define PSP_SCREEN_ROWS 272
#define PSP_SCREEN_COLUMNS 480

byte emu_screenbuffer[1280*1024]; //Video buffer (of max 1280x1024 pixels!)

byte videomode = 0; //Video mode used!

word GPU_screenxsize = 1024; //X size of screen
word GPU_screenysize = 768; //Y size of screen

void psp_graphics_putpixel(int x, int y, uint_32 color) //Putpixel directly on screen!
{
vram[x+512*y]=color; //Plot pixel to the PSP screen!
}

//Relative convert for 256-colors!
#define convertrel(old,oldsize,newsize) (int)((old/oldsize)*newsize)
u32 getcol256(byte color)
{
return RGB(convertrel(((color&0xE0)>>5),7,255),convertrel(((color&0x1C)>>2),7,255),convertrel((color&0x03),3,255)); //Use relative RGB convert!
}

//16 colors taken from here: http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter

u32 getcol16(byte color) //Convert color to RGB!
{
u32 colordb = { //Colour lookup table
RGB(0x00,0x00,0x00), //0x00 black
RGB(0x00,0x00,0xAA), //0x01 blue
RGB(0x00,0xAA,0x00), //0x02 green
RGB(0x00,0xAA,0xAA), //0x03 cyan
RGB(0xAA,0x00,0x00), //0x04 red
RGB(0xAA,0x00,0xAA), //0x05 magenta
RGB(0xAA,0x55,0x00), //0x06 brown
RGB(0xAA,0xAA,0xAA), //0x07 lightgray

RGB(0x55,0x55,0x55), //0x08 darkgray
RGB(0x55,0x55,0xFF), //0x09 lightblue
RGB(0x55,0xFF,0x55), //0x0A lightgreen
RGB(0x55,0xFF,0xFF), //0x0B lightcyan
RGB(0xFF,0x55,0x55), //0x0C lightred
RGB(0xFF,0x55,0xFF), //0x0D lightmagenta
RGB(0xFF,0xFF,0x55), //0x0E yellow
RGB(0xFF,0xFF,0xFF), //0x0F white
};
return colordb[color&0x0F]; //Give the color from the color lookup table!
}

int video_on = 0; //Video on?

void initVideo() //Initialises the video
{
if (!video_on) //Video is off?
{
//initGraphics(); //Initialise graphics!
//sceDisplaySetFrameBuf((void*)vram,512,1,0);
vram = (u32*)0x44000000; //Point to REAL VRAM for direct access!
}
else //Reset video!
{
int x, y; //X&Y!
for (y=0;y<PSP_SCREEN_ROWS;x++) //All rows
{
for (x=0;x<PSP_SCREEN_ROWS;x++)
{
psp_graphics_putpixel(x,y,0); //Clear all!
}
}
}
}

void putpixel(int x, int y, byte color) //Might be 8-bit or 16 colours
{

int pixX;
int pixY;
pixX = (x%GPU_screenxsize); //Wrap arround screen!
pixY = (y%GPU_screenysize); //Wrap arround screen!

if (mode==0) //16-colours?
{
screen_buffer[(pixX*GPU_screenxsize)+pixY] = getcol16(color); //Plot to buffer (wrap arround the screen)!
}
else //256-colours?
{
screen_buffer[(pixX*GPU_screenxsize)+pixY] = getcol256(color); //Plot to buffer (wrap arround the screen)!
}

//Now we need to find the cropped/stretched pixel in the buffer that this and plot it to the psp screen
//info: pixX & pixY contain the pixel edited in the buffer (which might or might not need to be plotted on the PSP screen using the psp_graphics_putpixel() function)

}```