The BIOS is a set of pre-coded routines that are within the GBA. We can call them at will with an instruction called SWI.
SWI stands for SoftWare Interrupt. What SWI does is call one of the builtin routines. Just give it a number and off it goes :). Example:
mov r0, #0x10
swi 0x80000
- SWI number 8 is SQRT (SQuare RooT). It will take the square root of r0 (and put the result in r0).
Notice that even though the SWI number is 8, with the ARM version of SWI, you need to do the SWI number * 0x10000 (or <<16, same thing). After running the
above code, r0 should be 4.
There are several other BIOS routines, see GBAtek.htm for a list and how they work.
Now let's do two things, see the Division BIOS routine. And then we'll make a rotating Mode 3 background using the BGAffineTransform BIOS routines.
Division is SWI number 6, it works like so:
INPUT:
r0 = signed number
r1 = signed number to divide r0 by.
OUTPUT:
r0 = r0 / r1
r1 = r0 MOD r1 (this means remainder)
r3 = ABSOLUTE VALUE(r0 / r1) (will be the positive version of the number in r0)
I don't think you need a code example there, pretty self-explanatory.
I don't think that's too hard for you to be able to understand after some work at this point. A word of caution, when you use BIOS routines use a BIOS dump with VisualBoyAdvance, or just test with no$gba. It would seem that no$gba's BIOS emulation is somewhat better than VBA's. The program above works on the real GBA as do all programs I give you, unless otherwise noted. :)
In the next chapter, we'll have some fun learning a couple new instructions, including a discussion of THUMB mode.
That's all for now, How about ? Or the GBA ASM index?