Attempt to decompile init

This commit is contained in:
Ryan Dwyer 2021-01-27 22:58:44 +10:00
parent 1795313cff
commit c3edb83df6
13 changed files with 142 additions and 20 deletions

View File

@ -119,9 +119,19 @@ SECTIONS
_antipiracyUncloakWriteAddress = 0x7002a324;
osTvType = 0x80000300;
osRomType = 0x80000304;
osRomBase = 0x80000308;
osResetType = 0x8000030c;
osCicId = 0x80000310;
osVersion = 0x80000314;
osMemSize = 0x80000318;
osAppNMIBuffer = 0x8000031c;
var803f50b8 = 0x803f50b8;
vara00002e8 = 0xa00002e8;
varbc000c02 = 0xbc000c02; /* for ntsc-beta */
var800902e4 = 0x800902e4; /* for ntsc-beta */
var800902e8 = 0x800902e8; /* for ntsc-beta */
/***************************************************************************
* romheader
@ -171,6 +181,8 @@ SECTIONS
}
END_SEG(boot)
_bootSegmentStart = 0x70001050;
/***************************************************************************
* lib
* -------------------------------------------------------------------------

View File

@ -77,8 +77,8 @@ glabel func00001050
/* 1088: 00000000 */ nop
/* 108c: 00000000 */ nop
/* 1090: 00000000 */ nop
/* 1094: 3c087000 */ lui $t0,%hi(func000016cc)
/* 1098: 250816cc */ addiu $t0,$t0,%lo(func000016cc)
/* 1094: 3c087000 */ lui $t0,%hi(init)
/* 1098: 250816cc */ addiu $t0,$t0,%lo(init)
/* 109c: 01000008 */ jr $t0
/* 10a0: 00000000 */ nop
);

View File

@ -1,6 +1,8 @@
#include <ultra64.h>
#include "boot/entry.h"
#include "boot/init.h"
#include "boot/reset.h"
#include "boot/segments.h"
#include "constants.h"
#include "game/data/data_000000.h"
#include "game/data/data_0083d0.h"
@ -41,9 +43,21 @@ s32 osGetMemSize(void)
}
#endif
extern u8 *_bootSegmentStart;
extern u8 *_datazipSegmentRomStart;
extern u8 *_datazipSegmentRomEnd;
extern u8 *_dataSegmentStart;
extern u8 *_inflateSegmentRomStart;
extern u8 *_inflateSegmentRomEnd;
extern u32 var803f50b8;
extern u32 vara00002e8;
extern u16 varbc000c02;
extern u16 *var800902e4;
extern s16 var800902e8;
#if VERSION >= VERSION_NTSC_1_0
GLOBAL_ASM(
glabel func000016cc
glabel init
/* 16cc: 3c0e8000 */ lui $t6,0x8000
/* 16d0: 8dce030c */ lw $t6,0x30c($t6)
/* 16d4: 27bdffd8 */ addiu $sp,$sp,-40
@ -147,15 +161,15 @@ glabel func000016cc
/* 183c: 3c048000 */ lui $a0,0x8000
/* 1840: 0c012054 */ jal osInvalICache
/* 1844: 24054000 */ addiu $a1,$zero,0x4000
/* 1848: 0c012074 */ jal func000481d0
/* 1848: 0c012074 */ jal __osGetFpcCsr
/* 184c: 00000000 */ nop
/* 1850: 0c012078 */ jal __osSetFpcCsr
/* 1854: 34440e80 */ ori $a0,$v0,0xe80
/* 1858: 24040003 */ addiu $a0,$zero,0x3
/* 185c: 0c00062b */ jal allocateStack
/* 1860: 34059800 */ dli $a1,0x9800
/* 1864: 3c108009 */ lui $s0,%hi(var8008d6d0)
/* 1868: 2610d6d0 */ addiu $s0,$s0,%lo(var8008d6d0)
/* 1864: 3c108009 */ lui $s0,%hi(g_MainThread)
/* 1868: 2610d6d0 */ addiu $s0,$s0,%lo(g_MainThread)
/* 186c: 3c067000 */ lui $a2,%hi(mainproc)
/* 1870: 2409000a */ addiu $t1,$zero,0xa
/* 1874: afa90014 */ sw $t1,0x14($sp)
@ -175,7 +189,7 @@ glabel func000016cc
);
#else
GLOBAL_ASM(
glabel func000016cc
glabel init
/* 1720: 3c040003 */ lui $a0,0x3
/* 1724: 3c0e0004 */ lui $t6,0x4
/* 1728: 3c0f0004 */ lui $t7,0x4
@ -288,6 +302,99 @@ glabel func000016cc
);
#endif
/**
* Prepares the inflate, .data and lib segments, then creates and starts the
* main thread.
*
* This function relies on the fact that the N64 BIOS loads the first 1MB of ROM
* data into memory at power on. The inflate, .data and lib segments are already
* in RAM thanks to this but need to be relocated, and .data and lib need to be
* unzipped too.
*/
// Mismatch: Goal uses s0 for dst in some places.
// Also uses way less stack somehow.
//void init(void)
//{
// u32 datacomplen;
// u32 inflatelen;
// u32 src;
// u32 dst;
// u32 i;
// s32 j;
//
//#if VERSION >= VERSION_NTSC_1_0
// if (osResetType == RESET_TYPE_NMI) {
// g_OsMemSize = var803f50b8;
// } else {
// g_OsMemSize = osMemSize;
// var803f50b8 = g_OsMemSize;
// }
//#endif
//
// // Copy compressed .data and inflate segments
// // .data is copied to 0x701eb000 - 0x70200000
// // inflate is copied to 0x70200000 - 0x702013f0
// src = (u32)&_datazipSegmentRomStart | 0x70000000;
// datacomplen = (u32)&_datazipSegmentRomEnd - (u32)&_datazipSegmentRomStart;
// inflatelen = (u32)&_inflateSegmentRomEnd - (u32)&_inflateSegmentRomStart;
// dst = 0x70200000 - datacomplen;
//
// for (j = datacomplen + inflatelen - 1; j >= 0; j--) {
// ((u8 *)dst)[j] = ((u8 *)src)[j];
// }
//
// // Copy compressed lib segment to 0x70280000.
// // It's assumed that lib is placed immediately after boot in the ROM and
// // that boot's length is 0x2000.
// // It's also assumed that lib's compressed length is less than 0x124f8
// // words. This is fine, as it's about half that.
// src = 0;
// src += (u32)&_bootSegmentStart;
// src += 0x2000;
// dst = 0x70280000;
//
// for (i = 0; i < 0x124f8; i++) {
// ((u32 *)dst)[i] = ((u32 *)src)[i];
// }
//
// // Inflate lib
// bootInflate(dst, src, 0x80300000);
//
// // Inflate .data
// bootInflate(0x70200000 - datacomplen, &_dataSegmentStart, 0x80300000);
//
//#if VERSION >= VERSION_NTSC_1_0
//#if PIRACYCHECKS
// if (vara00002e8 != 0xc86e2000) {
// while (1);
// }
//#endif
//#endif
//
// func00001634(1, 0x1f);
//
// // Clear the stack allocation pointers
// for (i = 0; i < ARRAYCOUNT(g_StackStartAddrs); i++) {
// g_StackStartAddrs[i] = NULL;
// g_StackEndAddrs[i] = NULL;
// }
//
// osInitialize();
// osWritebackDCacheAll();
// osInvalICache((void *) 0x80000000, 0x4000);
// __osSetFpcCsr(__osGetFpcCsr() | 0xe80);
//
//#if VERSION == VERSION_NTSC_BETA
// var800902e4 = &varbc000c02;
// var800902e8 = 0x4040;
// varbc000c02 = 0x4040;
//#endif
//
// // Create and start the main thread
// osCreateThread(&g_MainThread, THREAD_MAIN, mainproc, NULL, allocateStack(THREAD_MAIN, STACKSIZE_MAIN), THREADPRI_MAIN);
// osStartThread(&g_MainThread);
//}
#if VERSION >= VERSION_NTSC_1_0
GLOBAL_ASM(
glabel allocateStack
@ -467,7 +574,7 @@ void schedCreateThread(void)
g_SchedCmdQ = osScGetCmdQ(&g_SchedThread);
}
void mainproc(u32 value)
void mainproc(void *arg)
{
idleCreateThread();
func00013750();

View File

@ -19,9 +19,9 @@ glabel resetproc
/* 2e28: 3c018006 */ lui $at,%hi(var8005ced0)
/* 2e2c: 0c002449 */ jal audioStopThread
/* 2e30: a02eced0 */ sb $t6,%lo(var8005ced0)($at)
/* 2e34: 3c048009 */ lui $a0,%hi(var8008d6d0)
/* 2e34: 3c048009 */ lui $a0,%hi(g_MainThread)
/* 2e38: 0c0120dc */ jal osStopThread
/* 2e3c: 2484d6d0 */ addiu $a0,$a0,%lo(var8008d6d0)
/* 2e3c: 2484d6d0 */ addiu $a0,$a0,%lo(g_MainThread)
/* 2e40: 00002025 */ or $a0,$zero,$zero
/* 2e44: 0c01210c */ jal osSetThreadPri
/* 2e48: 2405000b */ addiu $a1,$zero,0xb

View File

@ -254,7 +254,8 @@ void func00002078(OSSched *sc)
func00001b98(sc->frameCount);
}
#if VERSION >= VERSION_NTSC_1_0
//#if VERSION >= VERSION_NTSC_1_0
#if VERSION >= 0
void __scHandleRetrace(OSSched *sc)
{
s32 state;
@ -289,7 +290,7 @@ void __scHandleRetrace(OSSched *sc)
{
u32 checksum = 0;
s32 *end = (s32 *)&allocateStack;
s32 *ptr = (s32 *)&func000016cc;
s32 *ptr = (s32 *)&init;
s32 i;
while (ptr < end) {

View File

@ -2392,7 +2392,7 @@ u32 var8008d6c0 = 0;
u32 var8008d6c4 = 0;
u32 var8008d6c8 = 0;
u32 var8008d6cc = 0;
OSThread var8008d6d0 = {0};
OSThread g_MainThread = {0};
u32 var8008d880 = 0;
u32 var8008d884 = 0;
u32 var8008d888 = 0;

View File

@ -5,5 +5,6 @@
s32 func000010a4(void);
s32 func0000113c(void);
s32 func00001180(void);
void func00001634(u32 arg0, u32 arg1);
#endif

View File

@ -2,8 +2,9 @@
#define _IN_BOOT_INIT_H
#include <ultra64.h>
s32 func000016cc(void);
void init(void);
s32 osGetMemSize(void);
void *allocateStack(s32 threadid, s32 size);
void mainproc(void *arg);
#endif

View File

@ -40,8 +40,8 @@ extern s32 g_AlarmTimer; // counts upwards
extern u32 var80059fe0;
extern u32 var8005a0b0;
extern u32 var8005b4d0;
extern u8 *g_StackStartAddrs[];
extern u8 *g_StackEndAddrs[];
extern u8 *g_StackStartAddrs[7];
extern u8 *g_StackEndAddrs[7];
extern u8 *g_StackAllocatedPos;
extern s32 var8005ce74;
extern f32 var8005ce78[2];

View File

@ -326,7 +326,7 @@ extern u32 var8008be38;
extern u32 var8008d238;
extern OSThread g_RmonThread;
extern OSThread g_IdleThread;
extern OSThread var8008d6d0;
extern OSThread g_MainThread;
extern u32 var8008d900;
extern OSMesgQueue var8008db30;
extern OSMesg var8008db48;

View File

@ -3,6 +3,6 @@
#include <ultra64.h>
#include "types.h"
u32 func000481d0(void);
u32 __osGetFpcCsr(void);
#endif

View File

@ -11,7 +11,7 @@
#include "types.h"
GLOBAL_ASM(
glabel func000481d0
glabel __osGetFpcCsr
/* 481d0: 4442f800 */ cfc1 $v0,$31
/* 481d4: 03e00008 */ jr $ra
/* 481d8: 00000000 */ nop

View File

@ -185,7 +185,7 @@ class Tool:
self.fd = open(sys.argv[1], 'rb+')
self.patch(algo01, '__scHandleRetrace', 'func000016cc')
self.patch(algo01, '__scHandleRetrace', 'init')
self.patch(algo02, 'cheatMenuHandleDialog', '__scHandleRetrace')
self.patch(algo03, 'propobjHandlePickupByAibot', 'func0f08e2ac')
self.patch(algo04, 'chrUncloak', 'propobjHandlePickupByAibot')