Blast Corps (U) (V1.1) ROM Extending Updated: 2016 Feb 13 By: queueRAM For updates, check: http://origami64.net/showthread.php?tid=334&pid=2566 This doc describes the process used to extend the Blast Corps (U) (V1.1) ROM to facilitate hacking and modifying levels. The vanilla ROM isn't suitable for modifying because the offsets of the level and vehicle data are stored in code and data blocks that are gzip compressed. Changing these offsets would involve inflating the gzip code, changing the offsets in code, and compressing as gzip and hoping the new file size isn't larger than the current one. A better approach is to store the level offsets in the ROM and modify the lookup code to reference this new table. This also has the benefit of reducing the code size. Below are the steps needed to extend the Blast Corps (U) (V1.1) ROM. 1. Store Level Offsets at 0x7FA000 in ROM There are four offsets stored for each level a. level start b. level end c. display list start d. display list end The game code only needs a. and d. since both blocks are copied together, however, having all four makes it quicker for the editor to look things up. 0x7FA000 is somewhat arbitrarily chosen as the first address with three zeros in the unused block from 0x7FA1E0-0x7FFFFF. 2. Inflate the hd_code_text.raw and hd_code_data.raw and level gzip blocks: 787FD0-7D73B4 hd_code_text.raw  main asm code 7D73B4-7E3AD0 hd_code_data.raw  data for main asm 4ACC10-4B71AB chimp.raw Simian Acres 4B71AB-4B8960 chimp_dl.raw Simian Acres display list hd_code_data.raw.gz is not modified, but it needs to be reinserted immediately after hd_code_text.raw.gz for the inflate methods to work correctly. 3. Patch code at 0x01199C in hd_code_text.raw This is done with bass MIPS assembler: > bass -o hd_code_text.raw hd_code_text.asm Description of code changes: proc_8025615C: # begin 8025615C (01199C), T6 = Level ID // existing code addiu $sp, $sp, -0x28 sw $a0, 0x28($sp) lw $t6, 0x28($sp) sw $ra, 0x1c($sp) sw $a1, 0x2c($sp) sltiu $at, $t6, 0x3c beqz $at, .Lproc_8025615C_8A4 sw $a2, 0x30($sp) // new code starting at 119BC/8025617C sll t6, t6, 0x4 // each entry is four words (* 16) lui at, 0xB080 // %hi(0xB07FA000), 0xB0000000 = ROM addu at, at, t6 // lw t6, 0xA000(at) // %lo(0xB07FA000) sw t6, 0x24(sp) // lw t7, 0xA00C(at) // %lo(0xB07FA00C) sub t7, t7, t6 // compute length lw t4, 0x30(sp) // sw t7, 0x0(t4) // b 0x12240 // skip over old code // replace this with nops .Lproc_8025615C_8A4: // offset 0x12240 addiu $t7, $zero, 0xa addiu $t8, $zero, 1 sw $t8, 0x14($sp) sw $t7, 0x10($sp) lw $a0, 0x24($sp) lw $a1, 0x2c($sp) lw $a2, 0x30($sp) jal proc_8028B4C4 addiu $a3, $zero, 0xc lw $ra, 0x1c($sp) addiu $sp, $sp, 0x28 jr $ra nop 4. Compress patched hd_code_text.raw in gzip: > gzip -c hd_code_text.raw > hd_code_text.raw.gz 5. Insert the hd_code_text.raw.gz and hd_code_data.raw.gz back-to-back in the Blast Corps ROM at offset 787FD0 and Simian Acres level at 0x0x800000. Also update the Simian Acres offset in the level lookup table. This is done with bass MIPS assembler bass. > bass -o "Blast Corps (U) (V1.1).z64" blast_corps_rom.asm