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 > Howto place the GBA in HALT mode!!

#16439 - NeoGeo - Mon Feb 16, 2004 4:12 pm

Can anyone pleace help me, I need to get detailed instructions on how to place the GBA in HALT mode. Code examples would be great !!

#16441 - tepples - Mon Feb 16, 2004 4:21 pm

To go into halt mode, which stops the CPU until an interrupt occurs:
1. Set up a working ISR.
2. Call the following function (assuming Thumb mode):
Code:
void gba_halt(void)
{
  asm volatile("swi 0x02");
}

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#16447 - dagamer34 - Mon Feb 16, 2004 7:15 pm

I am guessing you want to put your GBA in "sleep" mode, right?

Code:

// Puts the GBA in sleep until certain keys are pressed
void GBASleep (u16 keys)
{
   u16 sound;
   u16 interupt;
   u16 savedkeys;
   
   // Save sound if turned on, then turn it off
   sound = REG_SOUNDCNT_X;
   REG_SOUNDCNT_X = 0;
   
   // Save previous interrupts, then turn off all except joypad
   REG_IME = 0;
   interupt = REG_IE;
   REG_IE = INT_KEYBOARD; // INT_KEYBOARD = 0x1000
   savedkeys = REG_P1CNT;
   REG_P1CNT = keys | BIT14 | BIT15;
   REG_IME = 1;
   
   // Wait 2 blanks
   WaitBlanks (2);
      
   // Disable video
   ForceBlank (1); // Sets the 7th bit in REG_DISPCNT
   
   // Wait for 420 VBlanks (7 seconds)
   WaitBlanks (420);
   
   // Stop the GBA and all processes
   Stop ();
   
   // Reinitialize video
   ForceBlank (0); // Clears the 7th bit in REG_DISPCNT
   
   // Restore the interupt flags
   REG_IE = interupt;
   
   // Restore the key interrupt flags
   REG_P1CNT = savedkeys;
      
   // Turn on sound if it was on
   REG_SOUNDCNT_X = sound;
}


and Stop is defined as what tepples wrote.

You're welcome.
_________________
Little kids and Playstation 2's don't mix. :(

#16450 - poslundc - Mon Feb 16, 2004 8:27 pm

Curious... I have a few questions:

1. What's the reason for waiting 7 seconds after forcing the display to blank?

2. I understand the interrupt will reactivate the CPU and resume the code wherever the PC last was at, but will it also attempt to load/jump to code at 0x03007FFC, or does being in halt mode prevent this?

3. Isn't there a danger that the interrupt will be activated (if the correct keys are pressed) before the 7 seconds elapse, thus causing an ISR to activate instead of reactivating the CPU? (Implying a complementary ISR ought to be setup in order to handle this scenario, perhaps setting a flag in a global variable that prevents Stop() from being called?)

Thanks,

Dan.

#16500 - dagamer34 - Wed Feb 18, 2004 12:53 am

1) For some reason on my GBA, if I immediately call Stop (), it quickly kills the screen such that it looks as if you are turning it off. I am doing it like Golden Sun does it. It first makes the screen turn white, waits some seconds, and THEN calls the bios function.

2) No clue.

3) My keyboard (button) interrupt doesn't do anything. I think that the bios call will start capturing input after its called. Before that point in my code, nothing else will happen if the button interrupt occurs.
_________________
Little kids and Playstation 2's don't mix. :(

#16507 - poslundc - Wed Feb 18, 2004 5:56 am

dagamer34 wrote:
1) For some reason on my GBA, if I immediately call Stop (), it quickly kills the screen such that it looks as if you are turning it off. I am doing it like Golden Sun does it. It first makes the screen turn white, waits some seconds, and THEN calls the bios function.


OK, I getcha. I think I would actually prefer the former method over the latter, though... aside from it avoiding the potential conflicts I detailed earlier, I think I like the way the screen sort of de-interlaces and dies as though it had been turned off when you put the majority of games to sleep. It's kind of a cool effect, making it look as though you are able to physically switch the unit off through software. :)

Dan.

#16552 - NeoGeo - Thu Feb 19, 2004 2:01 pm

I dont know how to set up a 'working ISR' can anyone please help ???

#16555 - poslundc - Thu Feb 19, 2004 3:53 pm

http://www.thepernproject.com - see Day 5 of the tutorial.

Dan.

#16588 - dagamer34 - Fri Feb 20, 2004 12:30 am

To save you some trouble, ISR, i think, stands for Interrupt Service Routice, aka interrupt.

If you have MSVC++ 6.0, go download the GBA AppWizard. It has some good novice code in there for you to use. Don't re-invent the wheel.
_________________
Little kids and Playstation 2's don't mix. :(

#18218 - Lupin - Mon Mar 22, 2004 6:48 pm

Uhm, i tried to just use the gba_halt function posted by tepples to replace it with my main loop (that loop did nothing at all...), but VBA seems to have troubles with it because i get very strange output...

It only works on emu if i do both, the halt and right after it my endless loop... I will try it on hardware, maybe VBA needs the loop as some kind of backup because it doesn't understand the halt function...
_________________
Team Pokeme
My blog and PM ASM tutorials