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 > software reset

#25387 - hakanyuksel - Sat Aug 21, 2004 10:12 pm

I am trying to use the mbv2 cable. I just learned that i can reset the gba by an asm code like this

.GLOBL software_reset

.ARM
@.SECTION .iwram
.ALIGN
.TEXT

software_reset:
mov r0,#0x8c
bx r0

infin:
b infin
(this is in an .s file)


and my code is like this
MULTIBOOT
extern void software_reset();

int main(void)
{
software_reset();
init_game();
....
....
etc.

when i run the code a white screen appears an the emulator window. Is there any mistakes in my code. And can I make any unrecoverable damage to my gba by doing something by software like these(I mean asm)?
_________________
--------------------
Hakan Yuksel
3TE GAmes
www.3tegames.com

#25389 - Lord Graga - Sat Aug 21, 2004 10:27 pm

To do a software reset, use a SWI call.

#25404 - tepples - Sun Aug 22, 2004 1:21 am

The problem is you're running it on an emulator. Most current GBA emulators for the PC use a technique called "high level emulation," where the function of a BIOS call is implemented in native PC code, rather than requiring the user to own a GBA, own a GBA to PC cable, and dump the GBA's BIOS himself. This assembly code you speak of jumps directly into the GBA's BIOS code.

In addition, I've read that it's best to run the software reset code from within an interrupt handler.

As for harming your GBA, it probably won't hurt under the current version of the BIOS used in the GBA, GBA SP, and Game Boy Player, but I can't guarantee anything, nor can I guarantee that it'll work on future GBA compatible game decks such as the Nintendo DS and the GBA II.

Lord Graga: IIRC, the SoftReset BIOS call doesn't display the logo.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#25413 - DKL - Sun Aug 22, 2004 11:06 am

Like Tepples said, it's never good to jump right into the bios code, for sake of forward compatibility.

To do a softreset, simply call the SWI 0 function. It seems you're using a GCC compiler, so simply do something like this :

Code:

#define SOFT_RESET() asm volatile ("swi 0")


No need for an asm file. :)

If you know what you're doing, you could also set SP (the stack pointer register) to its initial value (__sp_usr if you're using Jeff Frohwein linker script) et jump to the appropriate part of code (0x2000000 or 0x8000000).
But this a dirty way, since interrupt handlers, privileged mode registers, etc. won't be reset. SWI is easy and compatible, and I don't think you need speed for a reset. ;)

DKL

#25414 - hakanyuksel - Sun Aug 22, 2004 1:30 pm

tepples wrote:

In addition, I've read that it's best to run the software reset code from within an interrupt handler.


I dont know much about the interrupts yet. So i cant understand why we're calling this macro in an interupt handler. I mean when i press the start button it will reset the GBA like this
Code:

.....
.....
#define SOFT_RESET() asm volatile ("swi 0")

MULTIBOOT
int main(void)
{
    init_game();
    while(exit==0)
    {
            precess_keys();
            if(start_pressed)
            {
                  SOFT_RESET()
            }
            ...........
            ...........
     }
     return 0;
}

thanks for all the information.
_________________
--------------------
Hakan Yuksel
3TE GAmes
www.3tegames.com

#25415 - DKL - Sun Aug 22, 2004 1:45 pm

hakanyuksel wrote:
tepples wrote:

In addition, I've read that it's best to run the software reset code from within an interrupt handler.

I dont know much about the interrupts yet. So i cant understand why we're calling this macro in an interupt handler.

I don't see any reason for SWI 0 to be called from an interrupt handler. You can call it from anywhere. It will reset privileged regs (like privileged SP) and clean the IWRAM for you. It means that any information about a possible IRQ will be erased too. In other words, don't care about that. :)

Quote:
I mean when i press the start button it will reset the GBA like this


Yep, that's ok the way you did it.

DKL