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.

Coding > Just wondering if I am using swi correctly...

#150770 - yaazz - Tue Feb 12, 2008 1:55 pm

I just finished reading the tutorial on GBA bios functions and I am just wondering If I am using it correctly as Visual Boy Advance still seems to hover at around 8-10% cpu usage.

What i did is I just put the call swi_call(0x05) inside the while loop in main(). Other then that the code is the same as the topic I started earlier today

Is this the right way to make the cpu sleep?

#150771 - eKid - Tue Feb 12, 2008 2:28 pm

I'm not sure how your swi_call works, but remember that SWI 5 (wait for vblank interrupt) relies on a vblank interrupt and a proper interrupt handler.

#150773 - yaazz - Tue Feb 12, 2008 2:46 pm

Yep vblank interrupts are all set up prior to calling swi_call(0x05), but what im asking is do I just put this call in a while loop inside the main function and then battery life will be preserved?

Also, how does HALT work? does it just wait for any interrupt?

Should I be moving all of my code into interrupts (keys, drawing, game logic) in order to save battery life?

#150774 - eKid - Tue Feb 12, 2008 6:01 pm

Quote:
Also, how does HALT work? does it just wait for any interrupt?

yeah
Quote:
Should I be moving all of my code into interrupts (keys, drawing, game logic) in order to save battery life?

That sounds like it would complicate things... I usually setup my main loop like this:
Code:

while( true )
{
    // ...update game logic...

    // wait for new frame
    VBlankIntrWait();
   
    // ...update graphics...
}


The VBlankIntrWait is all that is necessary to save the battery life, because it's the only thing that you have to wait for. ...Unless your program sits idle until some keypresses or something...

#150785 - Cearn - Tue Feb 12, 2008 8:56 pm

As far as I know, the percentage in the VBA title bar doesn't actually represent GBA-CPU usage, but the speed relative to 'normal'. If you hit SPACE, for example, you can ramp up the speed and the number goes with it. If you want an actual CPU usage figure, use the debug version of no$gba.