GP32 Gamempark Lib & Temp Array


JyCet

Member
Joined
Feb 23, 2004
Messages
469
Age
118
Location
France
Website
Visit site
Hi,

I use the gfx part of gamepark lib for all display (sprites, background etc ...)
but I search how to create a temporary array, where I can put one BG and some sprites, for display a BG with fixed sprites and not BG and after sprite on LCD.

example i want to use this function but in a temporary array not dierctly in frame buffer
GpBitBlt(NULL,&gpDraw[nflip],0,226,16,13,(unsigned char*)spr_COW,0,0,16,13);

Any idea are welcome :)
 
GamePark library's blit functions will only work with a gpdrawsurface structure... So either you create a 3rd frame buffer that you will never display, or you can try to create a gpdrawsurface structure yourself and blit on it...
 
ok i've made this test:

GPDRAWSURFACE gpDraw[3];

//before display loop
//calcul tampon
GpBitBlt(NULL,&gpDraw[2],224,0,96,240,(unsigned char*)spr_INFOPLY,0,0,96,240);

//In display loop
GpBitBlt(NULL,&gpDraw[nflip],224,0,96,240,(unsigned char*)&gpDraw[2],224,0,320,240);

= lot of bug gfx :(


Does this function :
gm_memcpy(gpDraw[nflip].ptbuffer,&gpDraw[2],320*240);
is really faster ?

thk
 
I assume you've done something like this for gpDraw[2]?
Code:
gpDraw[2].buf_w=320;
gpDraw[2].buf_h=240;
GpMemSurfaceGet(&gpDraw[2]);
and then your display line should be something like this -
GpBitBlt(NULL,&gpDraw[nflip],224,0,96,240,(unsigned char*)gpDraw[2].ptbuffer,224,0,320,240);
 
Yes you should do something like GpLcdSurfaceGet(&gpDraw[0], 0); for the three of them.

Also you should use the dma0 to copy a whole screen. With some good timing you can have this copy for no cpu time :)
 
Ok thk for your help

I had already tested with GpLcdSurfaceGet(&gpDraw[2], 2);, but the GP32 locked at the tampom initialisation, so with your post I've search and find my pb ... a stupid pb :)

The GpBitBlt was in a big for (...) loop ... so that's why the prg locked :)

Thanks a lot for your help :D
Code:
GPDRAWSURFACE gpDraw[3];

GpGraphicModeSet(8,NULL);
GpLcdSurfaceGet(&gpDraw[0], 0);
GpLcdSurfaceGet(&gpDraw[1], 1);
GpLcdSurfaceGet(&gpDraw[2], 2);
GpSurfaceSet(&gpDraw[0]);

GpBitBlt(NULL,&gpDraw[2],224,0,96,240,(unsigned char*)spr_INFOPLY,0,0,96,240);

GpBitBlt(NULL,&gpDraw[nflip],224,0,96,240,(unsigned char*)gpDraw[2].ptbuffer,224,0,320,240);

I win some cpu time I'm very happy

I will bench gm_memcpy to see if I can reduce the CPU time :)

Regards
 
Good !!

I've just finish my bench and gm_memcpy is really fast than GpBitBlt !! :)
So I'll switch from :
GpBitBlt(NULL,&gpDraw[nflip],0,0,320,240,(unsigned char*)gpDraw[2].ptbuffer,0,0,320,240);
to :
gm_memcpy(gpDraw[nflip].ptbuffer,gpDraw[2].ptbuffer,320*240);

Now I win lot of cpu time :rolleyes:
 
Well, yes, no problem. Also I can give you some advices if you want to get the best timing and the copy for no cpu time at all.

Here's the dma0 function:

Code:
void DMA0FastCopy(unsigned char *src, unsigned char *dst, long size) {
	rDISRC0 = (long)src;

	rDIDST0 = (long)dst;

	rDCON0 = (1 << 29) | //sync hclk
  (1 << 26) | //whole servmode
  (1 << 22) | //auto reload OFF
  (0x02 << 20) | //data size = word
  (size >> 2); //count

	rDMASKTRIG0 = 0x03;
}

You can activate the burst mode (1 << 27), but I never noticed any noticeable speed difference using it (and the DESTINATION adress must be word aligned).

So, just after you swapped your screens, you can launch the dma0 copy. Don't forget to wait for it to end before you draw the next frame:

Code:
volatile void DMA0WaitEnd(void) {
	while(rDSTAT0 >> 20);
}

Using this method, you will gain some time, because when the game will be moving everything on the screen before the display, your copy will be running.

There is also a better way, to get the copy totally for free. You'll need a 3rd buffer, but that you will display. When you display a frame, you draw on the next, and the dma copies on the 3rd.
 
There is also a better way, to get the copy totally for free. You'll need a 3rd buffer, but that you will display. When you display a frame, you draw on the next, and the dma copies on the 3rd.


Could you post a small example of that solution?
I've heard of the triple buffer trick, but never found any really useful code using this, and I'm very interested in accelarating my font engine and version 2 of my Pyramids game.
 
Last edited by a moderator:
No problem, here is an example of my main loop:

Code:
while(true) {
	time += framelength;

	if(!pause) game();

	display();

	check_keys();

	DMA0FastCopy( (unsigned char *)background, (unsigned char *)gpDraw[db2].ptbuffer, screen_width * screen_height);

	if(time < GpTickCountGet() ) { //We're late, frameskip
  if(!pause) game();

  check_keys();

  time += framelength; //We synchronize on the next frame then
	}

	main_flip(); //Flip

	while(time > GpTickCountGet() ); //Synchronization
}

So, after the display, we check the keys to get an update of the positions just before we start the dma copy. In case of scrolling, the screen position will be closer to what it should be.

To flip the screen:
Code:
void main_flip() {
	GpSurfaceFlip(&gpDraw[db] );

	db++;
	if(db > 2) db = 0;
	db2++;
	if(db2 > 2) db2 = 0;
}

There is one thing important: you'll have to init the db values correctly:
db = 0;
db2 = 1;

So the dma0 copies the background to the db2 frame, while we trace everything on the db frame, and the 3rd one is displayed.

About the framelength, well it's easy to figure out: it depends on the cpu speed, but you can get the values with a simple program, that will flip the frames and display the gp ticks between them.
I set it to 38 for 66MHz, 74 for 133MHz.
 
you got me i'm still learning how to master C64 basic and Qbasic without missing up sice i was a kid. they're tough programs to figure out but one easy progam i heard about is 3DGenisis it's for creating 3d/4d stlye games on windows or networks and it's easy to use.
try using that then convert the files over to GP32
 
you got me i'm still learning how to master C64 basic and Qbasic without missing up sice i was a kid. they're tough programs to figure out but one easy progam i heard about is 3DGenisis it's for creating 3d/4d stlye games on windows or networks and it's easy to use.
try using that then convert the files over to GP32

Stop hijacking threads, Genesis3D won't work on a GP32 and you're not helping anyone.
 
Last edited by a moderator:
you got me i'm still learning how to master C64 basic and Qbasic without missing up sice i was a kid. they're tough programs to figure out but one easy progam i heard about is 3DGenisis it's for creating 3d/4d stlye games on windows or networks and it's easy to use.
try using that then convert the files over to GP32

Stop hijacking threads, Genesis3D won't work on a GP32 and you're not helping anyone.


@ Inverse_Loser:
There are big differences between everything that has a cpu in it.
And you act like you can make something for something, press the big
red button, and its converted with absolutly no work and it works perfectly.
 
Last edited by a moderator:
Back
Top