From b3543b3b91441f314ec7e50127126db4139bcdb1 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 26 Aug 2020 20:05:04 +1000 Subject: [PATCH] Allow relocation of ROM segments --- ld/pd.ld | 28 ++++++++++++++++++++++------ src/game/data/data_020df0.c | 4 ++-- src/game/game_00b190.c | 8 ++++---- src/game/game_015470.c | 4 ++-- src/game/game_16e810.c | 4 ++-- src/game/game_19aa80.c | 4 ++-- src/game/propobj.c | 4 ++-- src/game/training.c | 8 ++++---- src/lib/lib_233c0.c | 12 ++++++------ 9 files changed, 46 insertions(+), 30 deletions(-) diff --git a/ld/pd.ld b/ld/pd.ld index 97926a0a0..d53f7c81a 100644 --- a/ld/pd.ld +++ b/ld/pd.ld @@ -59,7 +59,6 @@ #define ROMALLOCATION_LIB 0x036800 #define ROMALLOCATION_DATA 0x015000 #define ROMALLOCATION_GAME 0x151980 -#define ROMALLOCATION_FILES 0xe8dba0 OUTPUT_ARCH (mips) @@ -163,6 +162,8 @@ SECTIONS * ROM range: 0x00003050 - 0x00039850 (compressed) * RAM range: 0x70003050 - 0x70059fe0 * ------------------------------------------------------------------------- + * This compressed segment must be placed immediately after boot, because + * the boot code calculates the lib address as boot start + boot length. */ _libzipSegmentRomStart = __rompos; @@ -232,7 +233,7 @@ SECTIONS __savedrompos = __rompos; __rampos = 0x70200000; - __rompos = _datazipSegmentRomStart + ROMALLOCATION_DATA; + __rompos = _datazipSegmentRomEnd; BEGIN_SEG(inflate) { @@ -276,6 +277,9 @@ SECTIONS } END_SEG(animations) + _animationsTableRomStart = _animationsSegmentRomEnd - 0x38a0; + _animationsTableRomEnd = _animationsSegmentRomEnd; + /*************************************************************************** * mpconfigs * ------------------------------------------------------------------------- @@ -455,7 +459,7 @@ SECTIONS /*************************************************************************** * filenames * ------------------------------------------------------------------------- - * ROM range: 0x01d5ca00 - 0x01d5e980 + * ROM range: 0x01d5ca00 - 0x01d65740 * RAM range: N/A * ------------------------------------------------------------------------- */ @@ -469,6 +473,19 @@ SECTIONS } END_SEG(filenames) + /*************************************************************************** + * blank + * ------------------------------------------------------------------------- + * ROM range: 0x01d65740 - 0x01d65f40 + * RAM range: N/A + * ------------------------------------------------------------------------- + * Yes, this segment is blank and it has to exist. The game loads it. + */ + + _blankSegmentRomStart = __rompos; + __rompos += 0x800; + _blankSegmentRomEnd = __rompos; + /*************************************************************************** * textures * ------------------------------------------------------------------------- @@ -477,7 +494,6 @@ SECTIONS * ------------------------------------------------------------------------- */ - __rompos = _filesSegmentRomStart + ROMALLOCATION_FILES; __rampos = 0; BEGIN_SEG(textures) @@ -486,8 +502,8 @@ SECTIONS } END_SEG(textures) - _texturesSegmentTableStart = _texturesSegmentRomEnd - 0x6d80; - _texturesSegmentTableEnd = _texturesSegmentRomEnd; + _texturesTableRomStart = _texturesSegmentRomEnd - 0x6d80; + _texturesTableRomEnd = _texturesSegmentRomEnd; /*************************************************************************** * copyright diff --git a/src/game/data/data_020df0.c b/src/game/data/data_020df0.c index c45c0a8f0..d954001c8 100644 --- a/src/game/data/data_020df0.c +++ b/src/game/data/data_020df0.c @@ -2032,7 +2032,7 @@ extern void *_file_Ap29_15_joM; extern void *_file_Ap16_03_joM; extern void *_file_Acarrbye02M; extern void *_file_Asaucerexp1M; -extern void *_filesSegmentRomEnd; +extern void *_filenamesSegmentRomStart; // 20df0 u16 var8007add0[] = { @@ -9571,7 +9571,7 @@ void *filetable[] = { /*0x07db*/ &_file_Ap16_03_joM, /*0x07dc*/ &_file_Acarrbye02M, /*0x07dd*/ &_file_Asaucerexp1M, - /*0x07de*/ &_filesSegmentRomEnd, + /*0x07de*/ &_filenamesSegmentRomStart, /*0x07df*/ NULL, }; diff --git a/src/game/game_00b190.c b/src/game/game_00b190.c index 5b856aa31..f2e0fadb2 100644 --- a/src/game/game_00b190.c +++ b/src/game/game_00b190.c @@ -14,12 +14,12 @@ void loadTextureList(void) { - extern u8 _texturesSegmentTableStart; - extern u8 _texturesSegmentTableEnd; + extern u8 _texturesTableRomStart; + extern u8 _texturesTableRomEnd; - u32 len = ((&_texturesSegmentTableEnd - &_texturesSegmentTableStart) + 15) & -16; + u32 len = ((&_texturesTableRomEnd - &_texturesTableRomStart) + 15) & -16; g_Textures = malloc(len, 6); - func0000d410(g_Textures, &_texturesSegmentTableStart, len); + func0000d410(g_Textures, &_texturesTableRomStart, len); } diff --git a/src/game/game_015470.c b/src/game/game_015470.c index 637e5801a..0976e582d 100644 --- a/src/game/game_015470.c +++ b/src/game/game_015470.c @@ -693,9 +693,9 @@ glabel func0f0155f0 /* f015e58: afbf0014 */ sw $ra,0x14($sp) /* f015e5c: ac202498 */ sw $zero,%lo(var80062498)($at) /* f015e60: 34d8003f */ ori $t8,$a2,0x3f -/* f015e64: 3c05007f */ lui $a1,0x7f +/* f015e64: 3c05007f */ lui $a1,%hi(_unknown2SegmentRomStart) /* f015e68: ac440000 */ sw $a0,0x0($v0) -/* f015e6c: 24a5bdc0 */ addiu $a1,$a1,-16960 +/* f015e6c: 24a5bdc0 */ addiu $a1,$a1,%lo(_unknown2SegmentRomStart) /* f015e70: 0c003504 */ jal func0000d410 /* f015e74: 3b06003f */ xori $a2,$t8,0x3f /* f015e78: 8fbf0014 */ lw $ra,0x14($sp) diff --git a/src/game/game_16e810.c b/src/game/game_16e810.c index fe1c61010..28bf8cb3c 100644 --- a/src/game/game_16e810.c +++ b/src/game/game_16e810.c @@ -5805,9 +5805,9 @@ glabel func0f1735c0 /* f1735f0: 24050004 */ addiu $a1,$zero,0x4 /* f1735f4: 3c03800b */ lui $v1,%hi(var800ab554) /* f1735f8: 2463b554 */ addiu $v1,$v1,%lo(var800ab554) -/* f1735fc: 3c05007f */ lui $a1,0x7f +/* f1735fc: 3c05007f */ lui $a1,%hi(_unknown1SegmentRomStart) /* f173600: ac620000 */ sw $v0,0x0($v1) -/* f173604: 24a5b270 */ addiu $a1,$a1,-19856 +/* f173604: 24a5b270 */ addiu $a1,$a1,%lo(_unknown1SegmentRomStart) /* f173608: 00402025 */ or $a0,$v0,$zero /* f17360c: 0c003504 */ jal func0000d410 /* f173610: 02203025 */ or $a2,$s1,$zero diff --git a/src/game/game_19aa80.c b/src/game/game_19aa80.c index 3a1f59920..0ef690bfb 100644 --- a/src/game/game_19aa80.c +++ b/src/game/game_19aa80.c @@ -1099,11 +1099,11 @@ glabel mpLoadConfig /* f19b960: adc1fffc */ sw $at,-0x4($t6) /* f19b964: 8de10000 */ lw $at,0x0($t7) /* f19b968: 8de80004 */ lw $t0,0x4($t7) -/* f19b96c: 3c0b007d */ lui $t3,0x7d +/* f19b96c: 3c0b007d */ lui $t3,%hi(_mpconfigsSegmentRomStart) /* f19b970: adc10000 */ sw $at,0x0($t6) /* f19b974: adc80004 */ sw $t0,0x4($t6) /* f19b978: 8fa901c8 */ lw $t1,0x1c8($sp) -/* f19b97c: 256b0a40 */ addiu $t3,$t3,0xa40 +/* f19b97c: 256b0a40 */ addiu $t3,$t3,%lo(_mpconfigsSegmentRomStart) /* f19b980: 8fa401cc */ lw $a0,0x1cc($sp) /* f19b984: 00095080 */ sll $t2,$t1,0x2 /* f19b988: 01495023 */ subu $t2,$t2,$t1 diff --git a/src/game/propobj.c b/src/game/propobj.c index 53190bb17..e336bf121 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -32343,8 +32343,8 @@ glabel func0f082d74 /* f082d90: 55e0fffe */ bnezl $t7,.L0f082d8c /* f082d94: 24e70004 */ addiu $a3,$a3,0x4 .L0f082d98: -/* f082d98: 3c0501d6 */ lui $a1,0x1d6 -/* f082d9c: 24a55740 */ addiu $a1,$a1,0x5740 +/* f082d98: 3c0501d6 */ lui $a1,%hi(_blankSegmentRomStart) +/* f082d9c: 24a55740 */ addiu $a1,$a1,%lo(_blankSegmentRomStart) /* f082da0: afa50020 */ sw $a1,0x20($sp) /* f082da4: 00e02025 */ or $a0,$a3,$zero /* f082da8: 24060040 */ addiu $a2,$zero,0x40 diff --git a/src/game/training.c b/src/game/training.c index 0774ffcbf..1a028dc28 100644 --- a/src/game/training.c +++ b/src/game/training.c @@ -1649,10 +1649,10 @@ glabel frLoadData /* f19e7b4: 27bdffd0 */ addiu $sp,$sp,-48 /* f19e7b8: afbf0014 */ sw $ra,0x14($sp) /* f19e7bc: 15c0004c */ bnez $t6,.L0f19e8f0 -/* f19e7c0: 3c0f007f */ lui $t7,0x7f -/* f19e7c4: 3c18007f */ lui $t8,0x7f -/* f19e7c8: 27189d20 */ addiu $t8,$t8,-25312 -/* f19e7cc: 25efb270 */ addiu $t7,$t7,-19856 +/* f19e7c0: 3c0f007f */ lui $t7,%hi(_firingrangeSegmentRomEnd) +/* f19e7c4: 3c18007f */ lui $t8,%hi(_firingrangeSegmentRomStart) +/* f19e7c8: 27189d20 */ addiu $t8,$t8,%lo(_firingrangeSegmentRomStart) +/* f19e7cc: 25efb270 */ addiu $t7,$t7,%lo(_firingrangeSegmentRomEnd) /* f19e7d0: 01f82023 */ subu $a0,$t7,$t8 /* f19e7d4: 24070001 */ addiu $a3,$zero,0x1 /* f19e7d8: 24190001 */ addiu $t9,$zero,0x1 diff --git a/src/lib/lib_233c0.c b/src/lib/lib_233c0.c index e2b2cc162..c6244a61e 100644 --- a/src/lib/lib_233c0.c +++ b/src/lib/lib_233c0.c @@ -35,11 +35,11 @@ const u32 var700546ac[] = {0x3a83126f}; GLOBAL_ASM( glabel func000233c0 /* 233c0: 27bdffd8 */ addiu $sp,$sp,-40 -/* 233c4: 3c0e007d */ lui $t6,0x7d -/* 233c8: 3c0f007d */ lui $t7,0x7d +/* 233c4: 3c0e007d */ lui $t6,%hi(_animationsTableRomEnd) +/* 233c8: 3c0f007d */ lui $t7,%hi(_animationsTableRomStart) /* 233cc: afb00018 */ sw $s0,0x18($sp) -/* 233d0: 25efd1a0 */ addiu $t7,$t7,-11872 -/* 233d4: 25ce0a40 */ addiu $t6,$t6,0xa40 +/* 233d0: 25efd1a0 */ addiu $t7,$t7,%lo(_animationsTableRomStart) +/* 233d4: 25ce0a40 */ addiu $t6,$t6,%lo(_animationsTableRomEnd) /* 233d8: 01cf8023 */ subu $s0,$t6,$t7 /* 233dc: 2610003f */ addiu $s0,$s0,0x3f /* 233e0: 3618003f */ ori $t8,$s0,0x3f @@ -48,8 +48,8 @@ glabel func000233c0 /* 233ec: 00808025 */ or $s0,$a0,$zero /* 233f0: 0c0048f2 */ jal malloc /* 233f4: 24050006 */ addiu $a1,$zero,0x6 -/* 233f8: 3c05007d */ lui $a1,0x7d -/* 233fc: 24a5d1a0 */ addiu $a1,$a1,-11872 +/* 233f8: 3c05007d */ lui $a1,%hi(_animationsTableRomStart) +/* 233fc: 24a5d1a0 */ addiu $a1,$a1,%lo(_animationsTableRomStart) /* 23400: 00402025 */ or $a0,$v0,$zero /* 23404: 02003025 */ or $a2,$s0,$zero /* 23408: 0c003504 */ jal func0000d410