From 7256d985762ceffc45f670aa294a72b50631229a Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 5 Aug 2024 21:25:06 -0400 Subject: [PATCH] initial work on shifting --- calcprogress.py | 0 include/functions.h | 1 + include/{fragments.h => sections.h} | 28 +++++- include/ultra64.h | 2 + splat.yaml | 92 ++++++++++++++++++-- src/29BA0.c | 13 ++- src/3FB0.c | 111 ++++++++++++++++++++++-- src/E1C0.c | 8 +- tools/m2ctx.py | 0 tools/symbol_addrs.txt | 130 ++++++++++++++++++++++++++++ 10 files changed, 361 insertions(+), 24 deletions(-) mode change 100644 => 100755 calcprogress.py rename include/{fragments.h => sections.h} (93%) mode change 100644 => 100755 tools/m2ctx.py diff --git a/calcprogress.py b/calcprogress.py old mode 100644 new mode 100755 diff --git a/include/functions.h b/include/functions.h index 43b5bf4b..049ed488 100644 --- a/include/functions.h +++ b/include/functions.h @@ -11,6 +11,7 @@ extern void _bcopy(void *, void *, u32); // 3FB0.s extern void func_80003B30(void *, s32, s32, s32); // types unknown +extern void func_80004200(); // 5580.s extern void func_80004CC0(OSThread *, s32, s32); diff --git a/include/fragments.h b/include/sections.h similarity index 93% rename from include/fragments.h rename to include/sections.h index f8525c6c..2ef59fa7 100644 --- a/include/fragments.h +++ b/include/sections.h @@ -1,5 +1,5 @@ -#ifndef _FRAGMENTS_H_ -#define _FRAGMENTS_H_ +#ifndef _SECTIONS_H_ +#define _SECTIONS_H_ // fragment 1 extern u8 fragment1_TEXT_START[]; @@ -386,4 +386,26 @@ extern u8 fragment77_TEXT_START[]; extern u8 fragment77_ROM_START[]; extern u8 fragment77_ROM_END[]; -#endif // _FRAGMENTS_H_ +// Asset externs + +extern u8 _3B96B0_ROM_START[]; +extern u8 _3BA190_ROM_START[]; +extern u8 _3CB130_ROM_START[]; +extern u8 _45B580_ROM_START[]; +extern u8 _4A21C0_ROM_START[]; +extern u8 _4BD6B0_ROM_START[]; +extern u8 _4BE810_ROM_START[]; +extern u8 _4D1330_ROM_START[]; +extern u8 _4EB0C0_ROM_START[]; +extern u8 _5046B0_ROM_START[]; +extern u8 _52ABA0_ROM_START[]; +extern u8 _52F6D0_ROM_START[]; +extern u8 _533B20_ROM_START[]; +extern u8 _56E7D0_ROM_START[]; +extern u8 _5C7A70_ROM_START[]; +extern u8 _5C7AD0_ROM_START[]; +extern u8 _5F6790_ROM_START[]; +extern u8 _5F92A0_ROM_START[]; +extern u8 _5FFC30_ROM_START[]; + +#endif // _SECTIONS_H_ diff --git a/include/ultra64.h b/include/ultra64.h index d309e52c..9d75085d 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -44,4 +44,6 @@ #include "functions.h" #include "variables.h" +#include "sections.h" + #endif diff --git a/splat.yaml b/splat.yaml index 1ffbacb3..e4b4d6f6 100644 --- a/splat.yaml +++ b/splat.yaml @@ -830,8 +830,31 @@ segments: - [0x23C270, c, fragments/29/fragment29_code] - [0x23D3C0, data, fragments/29/fragment29_data] - [0x23D430, bin, fragments/29/fragment29_reloc] + + - name: fragment29_misc_1 + type: code + bss_size: 0x0 + start: 0x23D500 + vram: 0x88910000 # unk VRAM, shuts linker up + subsegments: - [0x23D500, bin, fragments/29/fragment29_unk_bin_1] # PERS-SZP file, pokeball, c buttons etc textures + - name: fragment29_misc_2 + type: code + bss_size: 0x0 + start: 0x23FB60 + vram: 0x88920000 # unk VRAM, shuts linker up + subsegments: + - [0x23FB60, bin, fragments/29/fragment29_unk_bin_2] # PERS-SZP file, pokeball, c buttons etc textures + + - name: fragment29_misc_3 + type: code + bss_size: 0x0 + start: 0x24F430 + vram: 0x88920000 # unk VRAM, shuts linker up + subsegments: + - [0x24F430, bin, fragments/29/fragment29_unk_bin_3] # PERS-SZP file, pokeball, c buttons etc textures + - name: fragment30 type: code bss_size: 0x0 @@ -880,6 +903,13 @@ segments: - [0x25ECF0, data, fragments/33/fragment33_data] - [0x25F020, rodata, fragments/33/fragment33_rodata] - [0x25F070, bin, fragments/33/fragment33_reloc] + + - name: fragment33_misc + type: code + bss_size: 0x0 + start: 0x25F440 + vram: 0x81310000 # unk vram, shuts linker up + subsegments: - [0x25F440, bin, fragments/33/fragment33_unk_bin_1] # PRES-JPEG, transfer machine background # alternative pokemon textures pointer loader @@ -1408,12 +1438,58 @@ segments: - [0x3B9640, c, fragments/77/fragment77_code] - [0x3B96A0, bin, fragments/77/fragment77_reloc] - # Rest of the ROM - - name: assets - type: code - bss_size: 0x0 - start: 0x3B96B0 - vram: 0x80000000 # unknown vram - subsegments: - - [0x3B96B0, bin] + - [0x3B96B0, bin] + - [0x3BA190, bin] + - [0x3CB130, bin] + - [0x45B580, bin] + - [0x4A21C0, bin] + - [0x4BD6B0, bin] + - [0x4BE810, bin] + - [0x4D1330, bin] + - [0x4EB0C0, bin] + - [0x5046B0, bin] + - [0x52ABA0, bin] + - [0x52F6D0, bin] + - [0x533B20, bin] + - [0x56E7D0, bin] + - [0x5C7A70, bin] + - [0x5C7AD0, bin] + - [0x5F6790, bin] + - [0x5F92A0, bin] + - [0x5FFC30, bin] + - [0x613110, bin] + - [0x6230D0, bin] + - [0x66E1D0, bin] + - [0x66F540, bin] + - [0x66FD80, bin] + - [0x675FA0, bin] + - [0x696350, bin] + - [0x69D090, bin] + - [0x6A9750, bin] + - [0x6AE1D0, bin] + - [0x6B0FB0, bin] + - [0x6B4F00, bin] + - [0x6C1AB0, bin] + - [0x6C4CE0, bin] + - [0x6C4E50, bin] + - [0x6CA730, bin] + - [0x6E2FC0, bin] + - [0x6E8910, bin] + - [0x6EB340, bin] + - [0x6EC4D0, bin] + - [0x6ECE80, bin] + - [0x701E50, bin] + - [0x70D3A0, bin] + - [0x7820E0, bin] + - [0x783760, bin] + - [0x798CD0, bin] + - [0x7994B0, bin] + - [0x79AFB0, bin] + - [0x79B8F0, bin] # not a file, just so it doesnt complain + - [0x7C0000] + + # rest of ROM.. part 2. This area and beyond NEEDS to be hard-aligned to this address. + # for the ROM to be shiftable, we need a way to fix this area beyond here to this address and for the prior area + # to be filled with FFs instead of being binned. TODO: Make it shift + - [0x7C0000, bin] - [0x2000000] diff --git a/src/29BA0.c b/src/29BA0.c index 42cc330f..c88603a5 100644 --- a/src/29BA0.c +++ b/src/29BA0.c @@ -1,8 +1,17 @@ -#include "common.h" +#include +#include "memory.h" #pragma GLOBAL_ASM("asm/nonmatchings/29BA0/func_80028FA0.s") -#pragma GLOBAL_ASM("asm/nonmatchings/29BA0/func_80029008.s") +s32 func_80029008(s32 arg0, s32 romStart, s32 romEnd, s32 arg3, s32 arg4) { + s32 result; + s32 (*func)(s32, s32); + + func = func_80004454(arg0, romStart, romEnd); + result = func(arg3, arg4); + main_pool_try_free(func); + return result; +} #pragma GLOBAL_ASM("asm/nonmatchings/29BA0/func_80029048.s") diff --git a/src/3FB0.c b/src/3FB0.c index 8b2d7db2..f982368a 100644 --- a/src/3FB0.c +++ b/src/3FB0.c @@ -1,4 +1,5 @@ -#include "common.h" +#include +#include "memory.h" #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_800033B0.s") @@ -32,7 +33,43 @@ #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_80003D64.s") -#pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_80003DC4.s") +void* func_80003DC4(uintptr_t romStart, uintptr_t romEnd, s32 arg2, s32 arg3) { + u32* addr; + u32* newaddr; + u32* ret; + s32 pad; + int side; + + side = (arg2 == 0) ? MEMORY_POOL_RIGHT : MEMORY_POOL_LEFT; + + addr = main_pool_alloc(0x18, side); + if (addr != NULL) { + func_80003B30(addr, romStart, romStart + 0x18, arg3); + // is PERS-SZP? + if ((addr[0] == 'PERS') && (addr[1] == '-SZP')) { + newaddr = main_pool_alloc(ALIGN16(romEnd - romStart), side); + if (newaddr != NULL) { + func_80003B30(newaddr, romStart, romEnd, arg3); + ret = func_80003D18(newaddr, newaddr, arg2); + } + // is PRESJPEG? + } else if ((addr[0] == 'PRES') && (addr[1] == 'JPEG')) { + newaddr = main_pool_alloc(ALIGN16(romEnd - romStart), side); + if (newaddr != NULL) { + func_80003B30(newaddr, romStart, romEnd, arg3); + ret = func_80003C80(newaddr, newaddr, arg2); + } + } else { + newaddr = main_pool_alloc(ALIGN16(romEnd - romStart), arg2); + ret = newaddr; + if (newaddr != NULL) { + func_80003B30(ret, romStart, romEnd, arg3); + } + } + main_pool_try_free(addr); + } + return ret; +} #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_80003F54.s") @@ -44,7 +81,15 @@ #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_80004200.s") -#pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_80004258.s") +s32 func_80004258(s32 id, s32 arg1, s32 arg2, s32 arg3) { + s32 vaddr = func_80003DC4(arg1, arg2, arg3, 0); + + if ((vaddr != 0) && (id > 0)) { + Memmap_SetSegmentMap(id, vaddr, main_pool_get_block_dist(vaddr)); + main_pool_set_func(vaddr, id + 0x82000000, &func_80004200); + } + return vaddr; +} #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_800042E0.s") @@ -52,11 +97,67 @@ #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_800043BC.s") -#pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_80004454.s") +void *func_80004454(s32 arg0, uintptr_t romStart, uintptr_t romEnd) { + void *addr = func_80003DC4(romStart, romEnd, 0, 0); + + if (addr != NULL) { + func_800043BC(arg0, addr); + } + return addr; +} #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_800044A8.s") -#pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_800044F4.s") +void* func_800044F4(uintptr_t romStart, uintptr_t romEnd, s32 arg2, s32 arg3) { + u32* ret; + unsigned long sp28_2; + unsigned long sp28; + u16* newaddr; + + ret = NULL; + switch (arg2) { + case 0: + newaddr = func_80003DC4(romStart, romEnd, 0, 0); + ret = newaddr; + if (newaddr != NULL) { + newaddr[0] |= 1; + } + break; + case 1: + newaddr = func_80003DC4(romStart, romStart + 0x20, 0, 0); + ret = newaddr; + if (newaddr != NULL) { + sp28_2 = (ret[3] * 0x10) + 0x10; + main_pool_try_free(ret); + newaddr = func_80003DC4(romStart, romStart + sp28_2, 0, 0); + ret = newaddr; + if (newaddr != NULL) { + *newaddr |= 2; + if (arg3 == 1) { + *newaddr |= 4; + } + } + } + break; + case 2: + newaddr = func_80003DC4(romStart, romStart + 0x20, 1, 0); + ret = newaddr; + if (newaddr != NULL) { + sp28 = (ret[3] * 0x10) + 0x10; + main_pool_try_free(ret); + newaddr = func_80003DC4(romStart, romStart + sp28, 1, 0); + ret = newaddr; + if ((newaddr != NULL) && (arg3 == 1)) { + *newaddr |= 4; + } + } + break; + } + if (ret != NULL) { + ret[1] = romStart; + } + return ret; +} #pragma GLOBAL_ASM("asm/nonmatchings/3FB0/func_80004660.s") diff --git a/src/E1C0.c b/src/E1C0.c index 0a14856f..01567a4d 100644 --- a/src/E1C0.c +++ b/src/E1C0.c @@ -1,7 +1,7 @@ #include #include #include "dp_intro.h" -#include "fragments.h" +#include "sections.h" #include "memory.h" #include "dp_intro.h" #include "util.h" @@ -32,10 +32,6 @@ extern char D_800AA668; extern u8 D_81200000[]; -// ROM offsets -extern u8 D_3BA190[]; -extern u8 D_3CB130[]; - // from fragment 1 void func_81206D9C(void); void func_81206E64(void); @@ -90,7 +86,7 @@ void func_8000D738(struct UnkInputStruct8000D738* arg0) { D_800AA664 = main_pool_alloc(0x21E0, 0); func_80004454(((u32)((u32)&fragment1_TEXT_START & 0x0FF00000) >> 0x14) - 0x10, &fragment1_ROM_START, &fragment1_ROM_END); - temp_v0 = func_800044F4(&D_3BA190, &D_3CB130, 1, 1); + temp_v0 = func_800044F4(&_3BA190_ROM_START, &_3CB130_ROM_START, 1, 1); D_800AA660->unk21FC = func_8000484C(temp_v0, 0); D_800AA660->unk2200 = func_8000484C(temp_v0, 1); D_800AA660->unk2204 = *arg0; diff --git a/tools/m2ctx.py b/tools/m2ctx.py old mode 100644 new mode 100755 diff --git a/tools/symbol_addrs.txt b/tools/symbol_addrs.txt index 4de72f51..b5ebd6d7 100644 --- a/tools/symbol_addrs.txt +++ b/tools/symbol_addrs.txt @@ -610,3 +610,133 @@ SoftReset_Thread = 0x80005674; SoftReset_CreateThread = 0x800057C0; func_80004DB4 = 0x80004DB4; //defined:true gControllers = 0x800A7320; //defined:true +fragment1_ROM_START = 0x7F980; // defined:true +fragment1_misc_yay0_ROM_START = 0xADC80; // defined:true +fragment2_ROM_START = 0x107FA0; // defined:true +fragment3_ROM_START = 0x118990; // defined:true +fragment4_ROM_START = 0x11F560; // defined:true +fragment5_ROM_START = 0x120920; // defined:true +fragment6_ROM_START = 0x120A10; // defined:true +fragment7_ROM_START = 0x1278D0; // defined:true +fragment8_ROM_START = 0x12DF40; // defined:true +fragment9_ROM_START = 0x1329E0; // defined:true +fragment10_ROM_START = 0x134680; // defined:true +fragment11_ROM_START = 0x138F20; // defined:true +fragment12_ROM_START = 0x142B10; // defined:true +fragment13_ROM_START = 0x143700; // defined:true +fragment14_ROM_START = 0x1442E0; // defined:true +fragment15_ROM_START = 0x14CA50; // defined:true +fragment16_ROM_START = 0x1589E0; // defined:true +fragment17_ROM_START = 0x15F990; // defined:true +fragment18_ROM_START = 0x1708B0; // defined:true +fragment19_ROM_START = 0x17FB40; // defined:true +fragment20_ROM_START = 0x1802B0; // defined:true +fragment21_ROM_START = 0x185A10; // defined:true +fragment22_ROM_START = 0x191660; // defined:true +fragment23_ROM_START = 0x1A8570; // defined:true +fragment24_ROM_START = 0x1CE9E0; // defined:true +fragment25_ROM_START = 0x1EA640; // defined:true +fragment26_ROM_START = 0x1EA860; // defined:true +fragment27_ROM_START = 0x1F7C90; // defined:true +fragment28_ROM_START = 0x214900; // defined:true +fragment29_ROM_START = 0x23C250; // defined:true +fragment29_misc_1_ROM_START = 0x23D500; // defined:true +fragment29_misc_2_ROM_START = 0x23FB60; // defined:true +fragment29_misc_3_ROM_START = 0x24F430; // defined:true +fragment30_ROM_START = 0x255230; // defined:true +fragment31_ROM_START = 0x2552C0; // defined:true +fragment32_ROM_START = 0x25A740; // defined:true +fragment33_ROM_START = 0x25B0D0; // defined:true +fragment33_misc_ROM_START = 0x25F440; // defined:true +fragment34_ROM_START = 0x261F70; // defined:true +fragment35_ROM_START = 0x271260; // defined:true +fragment36_ROM_START = 0x2717E0; // defined:true +fragment37_ROM_START = 0x272830; // defined:true +fragment38_ROM_START = 0x275CE0; // defined:true +fragment39_ROM_START = 0x27BCA0; // defined:true +fragment40_ROM_START = 0x285DC0; // defined:true +fragment41_ROM_START = 0x287EB0; // defined:true +fragment42_ROM_START = 0x29DD30; // defined:true +fragment43_ROM_START = 0x2A1B30; // defined:true +fragment44_ROM_START = 0x2A4DF0; // defined:true +fragment45_ROM_START = 0x2A9790; // defined:true +fragment46_ROM_START = 0x2AD270; // defined:true +fragment47_ROM_START = 0x2AD8F0; // defined:true +fragment48_ROM_START = 0x2B3F70; // defined:true +fragment49_ROM_START = 0x2B46F0; // defined:true +fragment50_ROM_START = 0x2B5350; // defined:true +fragment51_ROM_START = 0x2BD0A0; // defined:true +fragment52_ROM_START = 0x2BD130; // defined:true +fragment53_ROM_START = 0x2BD6E0; // defined:true +fragment54_ROM_START = 0x2BDAC0; // defined:true +fragment55_ROM_START = 0x2BED20; // defined:true +fragment56_ROM_START = 0x2C3220; // defined:true +fragment57_ROM_START = 0x2C49D0; // defined:true +fragment58_ROM_START = 0x2CF350; // defined:true +fragment59_ROM_START = 0x2D24C0; // defined:true +fragment60_ROM_START = 0x2D5CB0; // defined:true +fragment61_ROM_START = 0x2D7890; // defined:true +fragment62_ROM_START = 0x2EA8C0; // defined:true +fragment63_ROM_START = 0x394100; // defined:true +fragment64_ROM_START = 0x3AEE50; // defined:true +fragment65_ROM_START = 0x3B2AE0; // defined:true +fragment66_ROM_START = 0x3B6130; // defined:true +fragment67_ROM_START = 0x3B8530; // defined:true +fragment68_ROM_START = 0x3B8570; // defined:true +fragment69_ROM_START = 0x3B8600; // defined:true +fragment70_ROM_START = 0x3B8690; // defined:true +fragment71_ROM_START = 0x3B8720; // defined:true +fragment72_ROM_START = 0x3B87B0; // defined:true +fragment73_ROM_START = 0x3B8840; // defined:true +fragment74_ROM_START = 0x3B88D0; // defined:true +fragment75_ROM_START = 0x3B8960; // defined:true +fragment76_ROM_START = 0x3B9590; // defined:true +fragment77_ROM_START = 0x3B9620; // defined:true +_3B96B0_ROM_START = 0x3B96B0; // defined:true +_3BA190_ROM_START = 0x3BA190; // defined:true +_3CB130_ROM_START = 0x3CB130; // defined:true +_45B580_ROM_START = 0x45B580; // defined:true +_4A21C0_ROM_START = 0x4A21C0; // defined:true +_4BD6B0_ROM_START = 0x4BD6B0; // defined:true +_4BE810_ROM_START = 0x4BE810; // defined:true +_4D1330_ROM_START = 0x4D1330; // defined:true +_4EB0C0_ROM_START = 0x4EB0C0; // defined:true +_5046B0_ROM_START = 0x5046B0; // defined:true +_52ABA0_ROM_START = 0x52ABA0; // defined:true +_52F6D0_ROM_START = 0x52F6D0; // defined:true +_533B20_ROM_START = 0x533B20; // defined:true +_56E7D0_ROM_START = 0x56E7D0; // defined:true +_5C7A70_ROM_START = 0x5C7A70; // defined:true +_5C7AD0_ROM_START = 0x5C7AD0; // defined:true +_5F6790_ROM_START = 0x5F6790; // defined:true +_5F92A0_ROM_START = 0x5F92A0; // defined:true +_5FFC30_ROM_START = 0x5FFC30; // defined:true +_613110_ROM_START = 0x613110; // defined:true +_6230D0_ROM_START = 0x6230D0; // defined:true +_66E1D0_ROM_START = 0x66E1D0; // defined:true +_66F540_ROM_START = 0x66F540; // defined:true +_66FD80_ROM_START = 0x66FD80; // defined:true +_675FA0_ROM_START = 0x675FA0; // defined:true +_696350_ROM_START = 0x696350; // defined:true +_69D090_ROM_START = 0x69D090; // defined:true +_6A9750_ROM_START = 0x6A9750; // defined:true +_6AE1D0_ROM_START = 0x6AE1D0; // defined:true +_6B0FB0_ROM_START = 0x6B0FB0; // defined:true +_6B4F00_ROM_START = 0x6B4F00; // defined:true +_6C1AB0_ROM_START = 0x6C1AB0; // defined:true +_6C4CE0_ROM_START = 0x6C4CE0; // defined:true +_6C4E50_ROM_START = 0x6C4E50; // defined:true +_6CA730_ROM_START = 0x6CA730; // defined:true +_6E2FC0_ROM_START = 0x6E2FC0; // defined:true +_6E8910_ROM_START = 0x6E8910; // defined:true +_6EB340_ROM_START = 0x6EB340; // defined:true +_6EC4D0_ROM_START = 0x6EC4D0; // defined:true +_6ECE80_ROM_START = 0x6ECE80; // defined:true +_701E50_ROM_START = 0x701E50; // defined:true +_70D3A0_ROM_START = 0x70D3A0; // defined:true +_7820E0_ROM_START = 0x7820E0; // defined:true +_783760_ROM_START = 0x783760; // defined:true +_798CD0_ROM_START = 0x798CD0; // defined:true +_7994B0_ROM_START = 0x7994B0; // defined:true +_79AFB0_ROM_START = 0x79AFB0; // defined:true +_79AFB0_ROM_END = 0x79B8F0; // defined:true