PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

I'm stumped (38xx GAPI issue)

First off, I know you guys must be getting sick of me... thank you for not saying so... yet :)

Anyway, I've been fighting with getting my graphics library working on devices other than my Casio E-125, and I actually made some progress today. However, it still doesn't work on the iPaq 38xx series and, having looked through my code 10 more times, I just can't figure out why.

Can you help? :)

Here's my initialization code called at program start (including the globals it accesses up top)...

Code:

HINSTANCE GX_hInst = NULL;
unsigned long int GX_bufferSize = 0;
BOOL GX_isBuffered = FALSE;
BOOL GX_BBBypass = FALSE;
unsigned short int* GX_pScreenBuffer = NULL;
unsigned short int* GX_pVidMem = NULL;
BOOL GX_Initialize(const HINSTANCE GXI_hInst, const HWND GXI_hWnd) {
GX_hInst = GXI_hInst;
GXOpenDisplay(GXI_hWnd, GX_FULLSCREEN);
GX_isBuffered = GXIsDisplayDRAMBuffer();
GX_g_gxdp = GXGetDisplayProperties();
GX_xPitch = GX_g_gxdp.cbxPitch >> 1;
GX_yPitch = GX_g_gxdp.cbyPitch >> 1;
TCHAR OEMModelInfo[64];
SystemParametersInfo(SPI_GETOEMINFO, 64, OEMModelInfo, 0);
if (wcscmp(OEMModelInfo, L"Compaq iPAQ H3800") == 0) {
if (!(GX_g_gxdp.cbxPitch < 0 && GX_g_gxdp.cbyPitch > 0)) {
GX_pVidMem = (unsigned short int*)0xAC0755A0;
GX_g_gxdp.cxWidth = 240;
GX_g_gxdp.cyHeight = 320;
GX_g_gxdp.cbxPitch = -640;
GX_g_gxdp.cbyPitch = 2;
GX_xPitch = GX_g_gxdp.cbxPitch >> 1;
GX_yPitch = GX_g_gxdp.cbyPitch >> 1;
GX_g_gxdp.cBPP = 16;
GX_g_gxdp.ffFormat = 0xA8;
GX_isBuffered = false;
GX_BBBypass = true;
}
}
GX_bufferSize = 320 * max(GX_xPitch, GX_yPitch) * (GX_g_gxdp.cBPP / 8);
if (!GX_isBuffered) {
GX_pScreenBuffer = (unsigned short int*)malloc(GX_bufferSize);
}
GXOpenInput();
GX_g_gxkl = GXGetDefaultKeys(GX_NORMALKEYS);
return true;
}


(Remember that this is NOT final code, so any comments you might have about style or efficiency aren't my concern at this point, only the functionality)

Then, at the start of every frame, I call the following:

Code:

void GX_beginDraw() {
if (GX_isBuffered) {
GX_pScreenBuffer = (unsigned short int*)GXBeginDraw();
}
}


Then, at the end of every frame:

Code:

void GX_endDraw() {
if (GX_isBuffered) {
GXEndDraw();
}
if (!GX_isBuffered) {
if (GX_BBBypass) { // Must be a 38xx series
memcpy(GX_pVidMem, GX_pScreenBuffer, GX_bufferSize);
} else { // Not a 38xx series
memcpy(GXBeginDraw(), GX_pScreenBuffer, GX_bufferSize);
GXEndDraw();
}
}
}


Anyone spot the stupid mistake that I'm sure it will turn out to be? Thank you!
Hi,

Most of the code is wrong. Basically there are two issues that should be avoided:

(1) You should not write to screen areas outside the width and height of the display.
(2) The memory pointer returned from GXBeginDraw is not the same as buffer pointer. The following code you supplied will not work correctly on any device except for the E-125:

Code:
void GX_endDraw() {
if (GX_isBuffered) {
GXEndDraw();
}
if (!GX_isBuffered) {
if (GX_BBBypass) { // Must be a 38xx series
memcpy(GX_pVidMem, GX_pScreenBuffer, GX_bufferSize);
} else { // Not a 38xx series
memcpy(GXBeginDraw(), GX_pScreenBuffer, GX_bufferSize);
GXEndDraw();
}
}
}


Above: This is no-no.

To use memcpy (which you can if you are certain that the width or height equals the largest pitch value) you have to adjust the pointer returned from GXBeginDraw AND the pointer to the H38xx buffer so that it points to buffer start, not pixel origo.

While the above code appears to work on the 36xx and other Pocket PC devices it really does not, and you ARE writing outside the screen area. The only devices the above code will work 100% on are the older Casio devices like the E-125 (where buffer pointer is actually the same as the pixel origo).

/Johan
Thank you for your input! I somewhat understood what you were saying, but it would be very helpful if you could direct me what in my code to change? I have to believe I'm somewhat close since it works on a number of devices now, even if just by luck!, so is there some specific suggestions you can make on what to change to take it the rest of the way? Thanks again!