Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Platform:Game Boy Advance/BIOS calls

From ReverseEngineering.wiki

The GBA BIOS software interrupts SWI 0x00-0x2A with their names as mGBA lists them, how the number is encoded in ARM and Thumb code, and which calls an HLE emulator implements itself.

GBA games call the 16 KiB BIOS (at 0x00000000, unreadable from game code) through the SWI instruction. In Thumb code swi N carries N in the low 8 bits; in ARM code the 24-bit comment field holds N << 16, so swi 0x060000 is call 6. mGBA's handler GBASwi32 simply shifts the ARM immediate right by 16 and reuses GBASwi16 (src/gba/bios.c lines 408 and 615-617). Arguments go in r0-r3, results come back in r0-r3.

Call numbers

Names as in mGBA's enum GBASwi (include/mgba/internal/gba/bios.h lines 21-65); the libgba/tonc names differ only in style. See Fact:Game Boy Advance/enum/BIOS SWI numbers.

N Name N Name
0x00 SoftReset 0x16 Diff8bitUnFilterWram
0x01 RegisterRamReset 0x17 Diff8bitUnFilterVram
0x02 Halt 0x18 Diff16bitUnFilter
0x03 Stop 0x19 SoundBias
0x04 IntrWait 0x1A SoundDriverInit
0x05 VBlankIntrWait 0x1B SoundDriverMode
0x06 Div (r0 / r1) 0x1C SoundDriverMain
0x07 DivArm (r1 / r0) 0x1D SoundDriverVSync
0x08 Sqrt 0x1E SoundChannelClear
0x09 ArcTan 0x1F MidiKey2Freq
0x0A ArcTan2 0x20-0x24 MusicPlayerOpen, Start, Stop, Continue, FadeOut
0x0B CpuSet 0x25 MultiBoot
0x0C CpuFastSet 0x26 HardReset
0x0D GetBiosChecksum 0x27 CustomHalt
0x0E BgAffineSet 0x28 SoundDriverVSyncOff
0x0F ObjAffineSet 0x29 SoundDriverVSyncOn
0x10 BitUnPack 0x2A SoundDriverGetJumpList
0x11 / 0x12 LZ77UnCompWram / Vram
0x13 HuffUnComp
0x14 / 0x15 RLUnCompWram / Vram

Decompression calls take r0 = source, r1 = destination and read a 4-byte header whose low byte is the type: 0x10 LZ77 (Format:Nintendo LZ77 (LZ10 and LZ11)), 0x2n Huffman and 0x30 run-length (Format:Nintendo BIOS Huffman and run-length). The Wram variants write bytes, the Vram variants write 16-bit units (VRAM cannot take byte writes), so choose by destination.

Identifying the BIOS

GetBiosChecksum (0x0D) returns r0 = 0xBAAE187F, r1 = 1, r3 = 0x4000 in mGBA's HLE; the same header defines 0xBAAE1880 (the BIOS as run in DS mode) and 0x242CEF81 (a debug BIOS). See Fact:Game Boy Advance/behavior/GetBiosChecksum values.

High-level emulation

Without a real BIOS file mGBA handles only some calls itself (Div, DivArm, Sqrt, ArcTan, ArcTan2, BgAffineSet, ObjAffineSet, BitUnPack, LZ77, Huffman, RL, UnFilter, RegisterRamReset, GetBiosChecksum, MidiKey2Freq, Stop) and forwards Halt, IntrWait, VBlankIntrWait, CpuSet, CpuFastSet and SoundDriverGetJumpList to its small built-in BIOS image; every other number, including the music-player and most sound-driver calls, only logs Stub software interrupt (src/gba/bios.c lines 408-607). A game using the Nintendo sound driver (m4a/MP2K) therefore normally needs a real BIOS or its own copy of the driver code in ROM. Unverified: whether every commercial m4a game calls 0x1A-0x24 through SWI rather than carrying the driver in ROM; test by disassembling a game's SWI sites.

Related

Format:Game Boy Advance ROM image, Platform:Game Boy Advance/Save types.

Code & repositories

  • https://github.com/mgba-emu/mgba @ 9660a668f2093cb4aba5983f52bebf8878dc5b8b · license: MPL-2.0
    GBA/GB emulator (MPL-2.0). Read for SWI names (include/mgba/internal/gba/bios.h), HLE BIOS and decompressors (src/gba/bios.c), save chips (src/gba/savedata.c, memory.c) and ROM/multiboot detection (src/gba/gba.c).
    Tested on: source read, not run · checked 2026-10-19; last activity 2026-10-17; Note: the latest release ships binaries; the wiki links only the source, never the binaries

Evidence & references

mGBA (MPL-2.0) at commit 9660a668f2093cb4aba5983f52bebf8878dc5b8b.