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.

ASM > Auto header Fixup with GNU Assembler

#11615 - ace - Tue Oct 14, 2003 1:09 pm

I don't like odd little utilities if they can be avoided.

One thing that is annoying is the checksum in the Program header for GBA ROMS/Multiboot images. Usually you need some strange little utility to fix it. this is annoying.

Following is code that can be added to the assembler startup section of the GBA ROM/Multibbot image to automatically calculate this checksum for GNU Assembler:

// Nifty autogenerate header checksum
.set checksum, 0

// Game Title - Must be 12 characters (80000A0h)
.irp param,'M','y',' ','R','o','m',' ','I','m','a','g','e'
.set char, \param
.byte char
.set checksum, checksum - char
.endr

// Game Code - might ned to set to 'M','B',' ',' ' for some emulators - 4 characters (80000ACh)
.irp param,'0','0','0','0'
.set char, \param
.byte char
.set checksum, checksum - char
.endr

// Maker Code - 2 characters (80000B0h)
.irp param,'0','0'
.set char, \param
.byte char
.set checksum, checksum - char
.endr

// Fixed Value 0x96 (80000B2h)
// Main Unit Code (80000B3h)
// Device Type (80000B4h)
// Unused Data - 7 Bytes (80000B5h)
// Software Version No (80000BCh)
.irp param,0x96,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
.set char, \param
.byte char
.set checksum, checksum - char
.endr
// On FIQ or Invalid Instruction
// Call 09fe2000 if MS Bit of 0x080000B4 set and 0x800009C = 0xA5 for debug rom.
// Call 09ffc000 if MS Bit of 0x080000B4 clear and 0x800009C = 0xA5 for debug rom.


// Complement Check (80000BDh)
// Needs to be auto generated thus :
// 1) Add all the values from ROM locations $a0 to (and including) $bc.
// 2) Add $19 to this value.
// 3) Exclusive OR with $ff.
// 4) Save the 8 least significant bits of the result to ROM location $bd.
.set checksum, checksum - 0x19
.set checksum, checksum & 0xFF
.byte checksum

// Reserved - 2 bytes (80000BEh) -- Needs to be zero ??? (does it??)
.byte 0x00,0x00


Now you dont need a utility to "fix up" the header. The only other thing you need is the "Fixed Nintendo Logo" data, but thats not hard to track down on the net.

Hope this is usefull to anyone.

ACE.

#102689 - SoLo2 - Sat Sep 16, 2006 4:09 am

Thanks to ace for this little clue.

I haven't tried it, yet it seems to
concord with Martin's GBATEK info.

Greetings,
SoLo2
_________________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Visit:
http://thebitsclub.tripod.com
http://biis.tripod.com