PocketMatrix forums

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

Doom and gapi

I am trying to make a port of Doom for the HP Jornada 525, but I get errors from gx.h when I include it in the build, but I don't even know how to use GAPI, and cannot find any websites that tell how. Please help me! Any assistance would be greatly appreciated.
The gx.h header will not compile properly for straight C builds (it conforms to C++ but not C).

I modified lines 56 and 57 of gx.h as follows to correct the problem:
Code:

//The following two lines modified by Dan East to make this header C compatible:
//Added "struct" to the following two prototypes:
GXDLL_API struct GXDisplayProperties GXGetDisplayProperties();
GXDLL_API struct GXKeyList GXGetDefaultKeys(int iOptions);


Dan East
Thanks. I figured that it didn't conform to C. Unfortunately, I have never used the Game API before, and don't have a clue as to where to go from here. Anyone know any good GAPI tutorials?
Thanks to all.
Dan-
If you're still here, I downloaded your PocketQuake source, and by some copying and pasting, opened the display. My first sign of progress- the disappearance of the menu bar. Anyways, how do I write to the display memory using a palette?
Well, you can check out one of the extended GAPI libraries here at Pocket Matrix, such as Easy CE (Overloaded), GAPIDraw and PocketFrog.

Basically, you create an array of RGB 565 color values to represent your palette. When you blit your palletized bitmap, lookup the element in your RGB palette table and copy the value to the display buffer. That is exactly what Pocket Quake does.


Dan East
Since I have an 8-bit device, it would have to be an 888 palette, right?
888 would be 24 bit color (8 + 8 + 8). What device are you using? Is it color? Many devices, like the first generation iPaqs, may only have 12 bit display hardware, but they still expose the hardware buffer as 16 bit RGB 565.

If you check out the Pocket PC SDK documentation, under the topic for the "GXDisplayProperties" struct, you will find info about the different types of pixel formats.

Dan East
He is using a J525.
simonjacobs · 08 Jul 2002, 16:27 UTC
This file contains source code for adding HP 525 support to GAPI games. It should work fine on any 256 color palette based pocket pc as far as I know, but it has only been tested on the following machines:

HP Jornada 525
HP Jornada 545 set to 256 color mode

If you test on any other machines please let me know the results.

Overview:

The code uses GDI functions to set up the palette, but this does not affect game speed as it only needs doing at:

1) Start up after grabbing the screen with GAPI
2) If the game is hidden then reactivated in the WM_SETFOCUS message
3) If you want to change the palette

so it doesnt need to be done each update. You can set the palette to anything you like, but to save trouble you might find it easier to just set up a RGB 332 palette and convert from the standard RGB 565 you would normally be using with shift and mask operations. The example code below uses a RGB 332 palette but it is obvious how to set up your own custom colors if you like.

General code changes:

You can detect that you are running on a 256 color machine with the GXGetDisplayProperties function. If you find:

g_gxdp.cBPP == 8 && (g_gxdp.ffFormat & kfPalette) != 0

then you should use the code for palette based machines.

YOU MUST TAKE INTO ACCOUNT that each pixel in the GAPI buffer is an unsigned char instead of an unsigned short and alter your screen update code accordingly.

Setting up the palette.

This should be done in the 3 situations mentioned above, and the code is:

struct {
LOGPALETTE lp;
PALETTEENTRY ape[255];
} pal;

LOGPALETTE *pLP = (LOGPALETTE*) &pal;
pLP->palVersion = 0x300;
pLP->palNumEntries = 256;

for (int i=0; i<256; i++)
{
pLP->palPalEntry[i].peRed = ((i&0xE0)>>5)<<5;
pLP->palPalEntry[i].peGreen = ((i&0x1C)>>2)<<5;
pLP->palPalEntry[i].peBlue = (i&0x03)<<6;
pLP->palPalEntry[i].peFlags = 0;
}

HPALETTE mypal = CreatePalette(pLP);
if (mypal)
{
HDC screenDC = GetDC(NULL);
if (screenDC)
{
SelectPalette(screenDC,mypal,FALSE);
RealizePalette(screenDC);

ReleaseDC(NULL,screenDC);
}
DeleteObject(mypal);
}

This creates an RGB 332 palette, you can do your own colors by altering the red/green/blue settings for each color in the for (int i=0; i<256; i++) loop.

Writing to the screen.

Exactly the same as normal, but remember each pixel is one byte long! If you write the number 1 to a pixel you will get the color in palette entry 1. If you set up the palette as above you will have the equivalent of a RGB 332 palette, that is writing 0x03 will give you pure blue. The code to convert an RGB 565 color to RGB 332 is:

unsigned short rgb565col = whatever;
int rval = (rgb565col&0xE000)>>8;
int gval = (rgb565col&0x0700)>>6;
int bval = (rgb565col&0x0018)>>3;
unsigned char rgb332col = rval|gval|bval;
The quickest easiest way to get doom on a 525 is to use Bruce Lewis's DoomCE as a base.

Dump the GDI code for GAPI and your away.

I got the basic version of HPC Doom up and running in about 2 hours!

Your device is a 256 color which should be very easy. Make a lookup table of the colors from the Doom frame buffer (screens[0]) and map them to the jornada's pallette. Blit them using
*fb = pallete[*source]
Look at the PocketQuake code. (Vid_ppc.c)

I was considering porting HPC DOOM to the PPC, but if your going to, I wont bother and I'll do Hexen & Heritic instead.

If you need more detailed help, ask me. I think im pretty well-aquanited with the Doom code! :D
Thanks to all for your help thus far. I apologize for being stupid, but now I get GXGetDisplayproperties as an unresolved external.

Oh, and gamefreaks, could I have your HPC Doom source to look at?
You need to link to gx.lib.

Dan East
At first glance, that would seem like the problem, but I was not stupid enough to forget to include gx.lib in the link. *phew* What else could be wrong?
That'll be because you are calling GAPI functions from C code. I think we sussed that one last night. Its hard to help unless I can see the code. Post a snippet.
Maybe you should forget GAPI and compile it 'as-is' first. Don't forget to define WAVEOUT and DIRECT_COLOR in the project settings.
That way we can see whats what.

Dump the code from CreateSurface() and just allocate 320*200 bytes of memory and assign screens[0] to that pointer. Thats your surface.

Drop BlitScreen and replace it with code that blits screens[0] using the pallette array to your vid memory.
Maybe screens[0] could be assigned directly to vram saving a blit? That wouldnt work with my port, because of the centering and stretching code...But maybe on your port.
This is a cpp function used to initialize GAPI in wcedoom.c:

Code:

extern "C" GXInit(void) {

GXOpenDisplay(hwnd, GX_FULLSCREEN);
GXOpenInput();
}


But it seems to do absolutely nothing; GAPI doesn't initialize. I have never used GAPI before, as I think I have stated previously. Doom itself works fine, though without GAPI.
Ahha!!!
Heres what I am using.
This code may be useful to anyone who needs to use GAPI and GameX in the same code...
Just define USE_GAPI to compile usigng GAPI HPC, else it will use GameX calls. This is what I am using in HPC Doom.

Code:

//*******************************************************************
// GAPI (ARM) and GameX (other CPU's) interface with game code
//*******************************************************************

#include <windows.h>
#include "C_GAPI.h"

#ifndef USE_GAPI //GameX code
#include <GameX.h>
#include "DispProps.h"
GameX *gx = new GameX;
#else //Gapi Code
#include <gx.h>
#endif


extern "C" int GXOPENDISPLAY()
{
#ifndef USE_GAPI
gx->OpenSound();
return gx->OpenGraphics();
#else
return 1; //GXOpenDisplay does nothing on a HPC.
#endif
}


extern "C" int GXCLOSEDISPLAY(void)
{
#ifndef USE_GAPI
return gx->CloseGraphics();
#else
return GXCloseDisplay();
#endif
}


extern "C" void* GXBEGINDRAW(void)
{
unsigned short *pAddress = 0;

#ifndef USE_GAPI

pAddress = (unsigned short*) gx->GetFBAddress();

if (pAddress)
gx->BeginDraw();

#else
pAddress = (unsigned short*) GXBeginDraw();

//We could try...
//pAddress = (unsigned short*) (0x06130000);
//This would *possibly* be a 710/German720 fix...
//This would also show no nag-screen...
#endif

return pAddress;

}


extern "C" int GXENDDRAW(void)
{
#ifndef USE_GAPI
return gx->EndDraw();
#else
return GXEndDraw();
#endif
}


extern "C" GXDisplayProperties GXGETDISPLAYPROPERTIES(void)
{
#ifndef USE_GAPI
GXDisplayProperties gxdp;
RECT gxrt;

gx->GetScreenRect(&gxrt;);

gxdp.cBPP = gx->m_cBitsPP;
gxdp.cbxPitch = (gx->m_cBitsPP/8);
gxdp.cbyPitch = gx->m_cbFBModulo;
gxdp.cxWidth = ((gxrt.right) - (gxrt.left));
gxdp.cyHeight = ((gxrt.bottom) - (gxrt.top));
gxdp.ffFormat = kfDirect; //565 only for now. Should really use
//bpp to figure this out....
return gxdp;
#else
return GXGetDisplayProperties();
#endif
}


extern "C" GXKeyList GXGETKEYLIST(int i)
{
#ifndef USE_GAPI
GXKeyList gxkl;
return gxkl; //No use on a HPC. Do you play prtrait on a J720? :-)
#else
return GXGetDefaultKeys(i); //Does this do anything?
#endif

}