Skip to content

Instantly share code, notes, and snippets.

@mid-kid
Last active October 22, 2023 06:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mid-kid/149e7415e5da89cca5e2dd36459eeac5 to your computer and use it in GitHub Desktop.
Save mid-kid/149e7415e5da89cca5e2dd36459eeac5 to your computer and use it in GitHub Desktop.
Convert GBA multiboot game to cartridge format
@ Bootstrap for running a GBA multiboot game stored in a ROM cartridge
@ Assemble with:
@ arm-none-eabi-as -o mb2gba.o mb2gba.s
@ arm-none-eabi-objcopy -O binary mb2gba.o mb2gba.bin
@ base64 mb2gba.bin
start:
@ Copy the game into ram
mov r0, #0x04000000
adr r1, rom
str r1, [r0, #0xd4] @ DMA3SAD
mov r1, #0x02000000
str r1, [r0, #0xd8] @ DMA3DAD
mov r1, #0x84000000 @ Transfer type = 32bit, size = 0x10000 * 4
str r1, [r0, #0xdc] @ DMA3CNT
@ Set reset address to ram
mov r0, #0x03000000
add r0, #0x8000
mov r1, #1
strb r1, [r0, #-6]
@ Reset
swi 0
@ Pad the ROM to at least 0x140 to avoid mGBA's multiboot detection
.org 0x140 - 0xc0 - start, 0
rom:
#!/bin/sh
# Convert a GBA multiboot binary into a GBA ROM, by including a pre-assembled bootstrap
# This can be used to play multiboot games using a flash cartridge.
# Example usage:
# ./mb2gba.sh < game.mb > game.gba
# Back up game header from the multiboot rom
header="$(dd bs=1 count=192 | base64)"
# Set the start address to 0x080000c0
echo LgAA6g== | base64 -d
# Copy the rest of the header from the multiboot rom
echo "$header" | base64 -d | dd bs=1 skip=4
# Add the bootstrap binary with padding up to 0x140
echo AQOg43QQj+LUEIDlAhSg49gQgOUhE6Dj3BCA5QMEoOMCCYDiARCg4wYQQOUAAADvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | base64 -d
# Append the entire multiboot binary
echo "$header" | base64 -d
dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment