Hey, I’m not new to programming but have recently been learning C/C++, reading books and looking over sample PSP code. I’ve managed to get quite a few things to compile and run on my PSP but there are a few things still confusing me:
/**
* Display set framebuf
*
* @param topaddr - address of start of framebuffer
* @param bufferwidth - buffer width (must be power of 2)
* @param pixelformat - One of ::PspDisplayPixelFormats.
* @param sync - One of ::PspDisplaySetBufSync
*/
void sceDisplaySetFrameBuf(void *topaddr, int bufferwidth, int pixelformat, int sync);
How do I calculate the bufferwidth I’m meant to use if I’m using the 32-bit RGBA pixel format (PSP_DISPLAY_PIXEL_FORMAT_8888)? Allot of the examples I’ve been looking at seam to have this as 512 but I just can’t understand why (512 what?).
What are the u16/u32 (etc) data types for? What are they meant to contain? I haven’t come across them in any C/C++ books I’ve been reading yet.
/usr/local/pspdev/psp/sdk/include/psptypes.h:typedef unsigned short u16;
/usr/local/pspdev/psp/sdk/include/psptypes.h:typedef unsigned int u32;
You calculate the buffer width by taking the width of the screen (480 pixels) and round up to the nearest power of 2 (512 pixels). The last 32 pixels are not used, and http://www.scorpioncity.com/dj2.html briefly explains why (and has a nice ascii diagram):
Even though the screen resolution might be, say, 640x480x32, this does not necessarily mean that each row of pixels will take up 640*4 bytes in memory. For speed reasons, graphics cards often store surfaces wider than their logical width (a trade-off of memory for speed.) For example, a graphics card that supports a maximum of 1024x768 might store all modes from 320x200 up to 1024x768 as 1024x768 internally. This leaves a "margin" on the right side of a surface. This actual allocated width for a surface is known as the pitch or stride of the surface.
I'm sorry, I might be completely wrong here, but I dont believe its in bytes, I believe its in PIXELS. In which case it should always be 512, unless you are... for some reason... not using a 480x272 screen.
It does the internal conversion since it knows the size of each pixel.