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 > NO$GBA errors (Sleep in main loop)

#70571 - wiz - Tue Feb 07, 2006 1:15 pm

Hi

In my main loop I use the following statement to put the GBA to sleep, as I read this is best to help with power saving.

Code:
   asm("swi 0x05");


However this causes no$gba to report an error (when you click Utilities->Errors (or F3)). This is the only line in my current test project, and the error vanishes when I remark the line.

Why could this be?

Thanks.

#70575 - FluBBa - Tue Feb 07, 2006 1:30 pm

Are you calling it from ARM or Thumb mode?
_________________
I probably suck, my not is a programmer.

#70577 - wiz - Tue Feb 07, 2006 1:44 pm

ok let me see, I believe it is THUMB code. If I change it to ARM the emulator says "the rom image has crashed"

sorry if I seem a bit thick just incase you need to see here is my compile statement

THUMB?:

arm-elf-g++ -O2 -g -mcpu=arm7tdmi -mthumb -mthumb-interwork -c main.c


here is what I think is correct to change it to ARM?:
arm-elf-g++ -O2 -g -mcpu=arm7tdmi -mthumb-interwork -c main.c

#70590 - FluBBa - Tue Feb 07, 2006 3:18 pm

Maybe you have to tell GCC that the SWI can destroy the r0-r3,r12 registers?
_________________
I probably suck, my not is a programmer.

#70591 - wiz - Tue Feb 07, 2006 3:51 pm

Any clue on how to do that please =)

believe me - Im a n00b ;D

#70605 - wintermute - Tue Feb 07, 2006 6:36 pm

from libgba gba_base.h

Code:

//---------------------------------------------------------------------------------
/*! \def SystemCall(Number)

    \brief helper macro to insert a bios call.
      \param Number swi number to call
      
      Inserts a swi of the correct format for arm or thumb code.

*/
#if   defined   ( __thumb__ )
#define   SystemCall(Number)    asm ("SWI     "#Number"\n" :::  "r0", "r1", "r2", "r3")
#else
#define   SystemCall(Number)    asm ("SWI     "#Number"   << 16\n" :::"r0", "r1", "r2", "r3")
#endif

_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#70609 - wiz - Tue Feb 07, 2006 7:20 pm

That did it!

Thanks a lot you two!

Back to technically perfect ;)