gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > VBA running at uber-speeds...

#27656 - mr_square - Mon Oct 18, 2004 1:22 pm

Sorry, not quite sure which forum this should go in...

Running my rom via VBA at home, its fine. I implemented DMA which sped it up loads, but I got it back to a fairly reasonable speed by having a counter in my main method that only executes the code once every 3 v-blanks.

Trying it via VBA in my uni department though, the same code runs stupidly fast. I tried sending it to a friend via MSN and he said it was far too fast too. Whats going on? Using the throttle settings on VBA doesnt help either, as it just makes it go all jerky :(

#27657 - FluBBa - Mon Oct 18, 2004 1:50 pm

How exactly do you check that 3 vblanks has occured?
Are you using the BIOS call? It might be that you have the old (pre release) BIOS at your home, that one allways waits for a new VBlank no matter what you put in r1.
_________________
I probably suck, my not is a programmer.

#27658 - mr_square - Mon Oct 18, 2004 2:00 pm

Like this:

Code:

while(1)
{

animTimer++;

   if(animTimer%3 == 0)
   {

   ....execute code here.....

   }

waitforVsync()
}



I've sort of fixed it now by changing it to "if animtimer%7 == 0", but its a bit odd. I'm thinking its a problem with my home PC, although thats the fastest of all the ones I tried the code on! :\

#27671 - Lord Graga - Mon Oct 18, 2004 7:24 pm

Code:
while(1){
   animTimer++;
   if(animTimer&4){
      amimTimer = 0;
      DoStuff();
   }
   waitforVsync();
}
This is a lot faster :)

#27672 - sajiimori - Mon Oct 18, 2004 7:41 pm

Graga, your code is not equivalent because it resets the timer. Also, the compiler will automatically convert to bitwise-AND when possible.

#27673 - poslundc - Mon Oct 18, 2004 7:48 pm

Also, it will cycle every 4 times instead of every 3.

Also, if you want to correctly emulate the modulus operator (although it works in this case because you manually reset the counter to zero) it should be value & 3, not value & 4. (x % y == x & (y - 1) where y is an even power of two.)

Dan.

#27674 - sajiimori - Mon Oct 18, 2004 8:17 pm

In other words, test your code. :P

#27676 - sgeos - Mon Oct 18, 2004 9:53 pm

mr_square wrote:
Using the throttle settings on VBA doesnt help either, as it just makes it go all jerky :(

Is sound enabled? Some emulators are unable to speed throttle if sound is disabled.

Have you tested on hardware?

-Brendan

#27680 - allenu - Mon Oct 18, 2004 11:50 pm

mr_square wrote:
Like this:

Code:

while(1)
{

animTimer++;

   if(animTimer%3 == 0)
   {

   ....execute code here.....

   }

waitforVsync()
}



I've sort of fixed it now by changing it to "if animtimer%7 == 0", but its a bit odd. I'm thinking its a problem with my home PC, although thats the fastest of all the ones I tried the code on! :\


Just a thought, but it may be more accurate for your code to update your counter in a V-sync interrupt service routine instead. Depending on how long your code takes to execute, you might miss a V-sync. I'm not sure how heavy duty the processing you're doing, and at the moment it may be fine, but it is certainly possible for you to miss a V-sync if your processing takes too long.

Actually, I'm not sure if this would be related to your problem, but it's good to know.

Allen

#27682 - sajiimori - Tue Oct 19, 2004 1:17 am

IMO, you should only do things in the vblank interrupt if they should be done even when the game is lagging. I mean, it would look odd if the game started to lag due to a CPU shortage but some animations continued to run full-speed.

An example of something that should be done unconditionally would be sprite flickering for the poor-man's transparency effect. You wouldn't want to lose the illusion of transparency if you went over your available CPU cycles.

Erm... this thread seems to really want to diverge for some reason.

#27683 - allenu - Tue Oct 19, 2004 1:37 am

sajiimori wrote:
IMO, you should only do things in the vblank interrupt if they should be done even when the game is lagging. I mean, it would look odd if the game started to lag due to a CPU shortage but some animations continued to run full-speed.

An example of something that should be done unconditionally would be sprite flickering for the poor-man's transparency effect. You wouldn't want to lose the illusion of transparency if you went over your available CPU cycles.

Erm... this thread seems to really want to diverge for some reason.


Yeah, you're right. If he's doing something that requires three *separately rendered* frames to be displayed before executing that code, then the ISR is not a good idea. I was thinking more along the lines of something time-based that requires updating every 1/20th of a second. In my case, I just added some sound mixing code to the VSYNC ISR as I require that to be done every displayed frame regardless of the rendering speed.

#27684 - sajiimori - Tue Oct 19, 2004 1:40 am

Oh yeah, sound is the perfect example.