From 2e79185e91e492b16281814ea52b04540439a73f Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 08:07:29 -0600 Subject: [PATCH 01/10] Split font.c, printfunc.c, and process.c --- config/GMPE01_00/splits.txt | 16 ++++++++++++++++ config/GMPE01_00/symbols.txt | 36 ++++++++++++++++++------------------ configure.py | 3 +++ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/config/GMPE01_00/splits.txt b/config/GMPE01_00/splits.txt index 0490a5fa..edae67a7 100644 --- a/config/GMPE01_00/splits.txt +++ b/config/GMPE01_00/splits.txt @@ -44,6 +44,9 @@ game/decode.c: .data start:0x8011FDE0 end:0x8011FE00 .bss start:0x80145640 end:0x80145A40 +game/font.c: + .data start:0x8011FE00 end:0x80121E00 + game/malloc.c: .text start:0x8000A558 end:0x8000A938 .data start:0x80121F50 end:0x80121FC8 @@ -53,6 +56,19 @@ game/memory.c: .text start:0x8000A938 end:0x8000AEF0 .data start:0x80121FC8 end:0x80122140 +game/printfunc.c: + .text start:0x8000AEF0 end:0x8000C4A4 + .data start:0x80122140 end:0x80122180 + .bss start:0x80145A98 end:0x8014C398 + .sbss start:0x801D3B28 end:0x801D3B38 + .sdata2 start:0x801D4978 end:0x801D49C8 + +game/process.c: + .text start:0x8000C4A4 end:0x8000D348 + .data start:0x80122180 end:0x801221D0 + .bss start:0x8014C398 end:0x8014C490 + .sbss start:0x801D3B38 end:0x801D3B48 + game/sprman.c: .text start:0x8000D348 end:0x8000F6A0 .rodata start:0x8011DD00 end:0x8011DD10 diff --git a/config/GMPE01_00/symbols.txt b/config/GMPE01_00/symbols.txt index a502889b..55f9d873 100644 --- a/config/GMPE01_00/symbols.txt +++ b/config/GMPE01_00/symbols.txt @@ -124,12 +124,12 @@ HuMemUsedMemoryBlockGet = .text:0x8000ACF8; // type:function size:0x44 HuMemMemoryAllocSizeGet = .text:0x8000AD3C; // type:function size:0xC HuMemHeapDump = .text:0x8000AD48; // type:function size:0x158 HuMemMemorySizeGet = .text:0x8000AEA0; // type:function size:0x50 -fn_8000AEF0 = .text:0x8000AEF0; // type:function size:0x64 -fn_8000AF54 = .text:0x8000AF54; // type:function size:0xA0 -fn_8000AFF4 = .text:0x8000AFF4; // type:function size:0x15C -DrawBox = .text:0x8000B150; // type:function size:0xAC -fn_8000B1FC = .text:0x8000B1FC; // type:function size:0xEE8 -fn_8000C0E4 = .text:0x8000C0E4; // type:function size:0x3C0 +pfInit = .text:0x8000AEF0; // type:function size:0x64 +pfClsScr = .text:0x8000AF54; // type:function size:0xA0 +print8 = .text:0x8000AFF4; // type:function size:0x15C +printWin = .text:0x8000B150; // type:function size:0xAC +pfDrawFonts = .text:0x8000B1FC; // type:function size:0xEE8 +WireDraw = .text:0x8000C0E4; // type:function size:0x3C0 scope:local HuPrcInit = .text:0x8000C4A4; // type:function size:0x14 HuPrcCreate = .text:0x8000C4B8; // type:function size:0x1E8 HuPrcChildLink = .text:0x8000C6A0; // type:function size:0x68 @@ -4838,7 +4838,7 @@ lbl_8011FC68 = .data:0x8011FC68; // type:object size:0x3C lbl_8011FCA4 = .data:0x8011FCA4; // type:object size:0x1A data:string lbl_8011FCBE = .data:0x8011FCBE; // type:object size:0x122 lbl_8011FDE0 = .data:0x8011FDE0; // type:object size:0x20 -lbl_8011FE00 = .data:0x8011FE00; // type:object size:0x2000 +ank8x8_4b = .data:0x8011FE00; // type:object size:0x2000 align:32 lbl_80121E00 = .data:0x80121E00; // type:object size:0x150 HeapSizeTbl = .data:0x80121F50; // type:object size:0x78 scope:local lbl_80121FC8 = .data:0x80121FC8; // type:object size:0x50 @@ -5357,9 +5357,9 @@ ReadDataStat = .bss:0x80142840; // type:object size:0x2E00 align:32 data:4byte TextBuffer = .bss:0x80145640; // type:object size:0x400 lbl_80145A40 = .bss:0x80145A40; // type:object size:0x40 HeapTbl = .bss:0x80145A80; // type:object size:0x14 scope:local -lbl_80145A98 = .bss:0x80145A98; // type:object size:0x6800 -lbl_8014C298 = .bss:0x8014C298; // type:object size:0x100 data:byte -lbl_8014C398 = .bss:0x8014C398; // type:object size:0xF8 +strline = .bss:0x80145A98; // type:object size:0x6800 scope:local +pfStrBuf = .bss:0x8014C298; // type:object size:0x100 scope:local data:byte +processjmpbuf = .bss:0x8014C398; // type:object size:0xF8 align:8 HuSprData = .bss:0x8014C490; // type:object size:0x9600 HuSprGrpData = .bss:0x80155A90; // type:object size:0x5400 data:2byte HuSprOrder = .bss:0x8015AE90; // type:object size:0x1800 @@ -5954,14 +5954,14 @@ lbl_801D3B14 = .sbss:0x801D3B14; // type:object size:0x4 data:4byte lbl_801D3B18 = .sbss:0x801D3B18; // type:object size:0x4 data:4byte currentHeapHandle = .sbss:0x801D3B1C; // type:object size:0x4 data:4byte lbl_801D3B20 = .sbss:0x801D3B20; // type:object size:0x8 data:4byte -lbl_801D3B28 = .sbss:0x801D3B28; // type:object size:0x4 data:4byte -lbl_801D3B2C = .sbss:0x801D3B2C; // type:object size:0x2 data:2byte -lbl_801D3B2E = .sbss:0x801D3B2E; // type:object size:0x2 data:2byte -debugFontColor = .sbss:0x801D3B30; // type:object size:0x8 data:4byte -lbl_801D3B38 = .sbss:0x801D3B38; // type:object size:0x4 data:4byte -lbl_801D3B3C = .sbss:0x801D3B3C; // type:object size:0x2 data:2byte -lbl_801D3B40 = .sbss:0x801D3B40; // type:object size:0x4 data:4byte -lbl_801D3B44 = .sbss:0x801D3B44; // type:object size:0x4 data:4byte +saftyFrameF = .sbss:0x801D3B28; // type:object size:0x4 data:4byte +strlinecnt = .sbss:0x801D3B2C; // type:object size:0x2 data:2byte +empstrline = .sbss:0x801D3B2E; // type:object size:0x2 data:2byte +fontcolor = .sbss:0x801D3B30; // type:object size:0x8 data:4byte +procfunc = .sbss:0x801D3B38; // type:object size:0x4 data:4byte +processcnt = .sbss:0x801D3B3C; // type:object size:0x2 scope:local data:2byte +processcur = .sbss:0x801D3B40; // type:object size:0x4 scope:local data:4byte +processtop = .sbss:0x801D3B44; // type:object size:0x4 scope:local data:4byte HuSprPauseF = .sbss:0x801D3B48; // type:object size:0x4 data:4byte HuSprOrderNo = .sbss:0x801D3B4C; // type:object size:0x2 data:2byte HuSprOrderNum = .sbss:0x801D3B4E; // type:object size:0x2 data:2byte diff --git a/configure.py b/configure.py index b7bbae46..3f035642 100755 --- a/configure.py +++ b/configure.py @@ -227,8 +227,11 @@ config.libs = [ Object(NonMatching, "game/dvd.c"), Object(NonMatching, "game/data.c"), Object(Matching, "game/decode.c"), + Object(NonMatching, "game/font.c"), Object(Matching, "game/malloc.c"), Object(Matching, "game/memory.c"), + Object(NonMatching, "game/printfunc.c"), + Object(NonMatching, "game/process.c"), Object(NonMatching, "game/sprman.c"), Object(NonMatching, "game/sprput.c"), ], From 41f0ffb565ad5e2317237a23ffa8e580c036f4df Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 08:42:06 -0600 Subject: [PATCH 02/10] Start decompiling some code --- configure.py | 4 +- include/common_structs.h | 35 +++++++++--- include/functions.h | 6 +-- src/game/printfunc.c | 51 ++++++++++++++++++ src/game/process.c | 112 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+), 12 deletions(-) create mode 100644 src/game/printfunc.c create mode 100644 src/game/process.c diff --git a/configure.py b/configure.py index 3f035642..14180103 100755 --- a/configure.py +++ b/configure.py @@ -173,6 +173,7 @@ cflags_runtime = [ cflags_rel = [ *cflags_base, "-O0,s", + "-char unsigned", "-sdata 0", "-sdata2 0", ] @@ -181,6 +182,7 @@ cflags_rel = [ cflags_game = [ *cflags_base, "-O0,p", + "-char unsigned", ] config.linker_version = "GC/2.6" @@ -231,7 +233,7 @@ config.libs = [ Object(Matching, "game/malloc.c"), Object(Matching, "game/memory.c"), Object(NonMatching, "game/printfunc.c"), - Object(NonMatching, "game/process.c"), + Object(Matching, "game/process.c"), Object(NonMatching, "game/sprman.c"), Object(NonMatching, "game/sprput.c"), ], diff --git a/include/common_structs.h b/include/common_structs.h index 6bc0e07c..cc12f449 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -15,14 +15,33 @@ typedef struct Vec3f { f32 z; } Vec3f; -typedef struct unkStruct145A98 { - s16 unk_00; - char unk_02[10]; - s16 unk_0C; - char unk_0E[6]; - u8 unk_14; - char unk_15[0x53]; -} unkStruct145A98; // sizeof 0x68 +typedef struct jump_buf { + u32 lr; + u32 cr; + u32 sp; + u32 r2; + u32 pad; + u32 regs[19]; + double flt_regs[19]; +} jmp_buf; + +typedef struct process { + struct process *next; + struct process *prev; + struct process *child; + struct process *parent; + struct process *next_child; + struct process *last_child; + void *heap; + u16 exec; + u16 stat; + u16 prio; + s32 sleep_time; + void *base_sp; + jmp_buf jump; + void (*dtor)(void); + void *user_data; +} Process; typedef struct unkStruct1D3B44 { struct unkStruct1D3B44 *prev; diff --git a/include/functions.h b/include/functions.h index cb626b73..a6e79d03 100644 --- a/include/functions.h +++ b/include/functions.h @@ -4,9 +4,6 @@ #include "types.h" #include "common_structs.h" -void* HuPrcCreate(void (*), s32, s32, s32); -void HuPrcSleep(s32, f32); -void HuPrcVSleep(void); void Hu3DBGColorSet(u8, u8, u8); void Hu3DCameraCreate(s16); void Hu3DCameraPerspectiveSet(s16, f32, f32, f32, f32); @@ -43,6 +40,9 @@ s32 HuMemUsedMemoryBlockGet(void *heap_ptr); s32 HuMemMemoryAllocSizeGet(s32 size); void HuMemHeapDump(void *heap_ptr, s16 status); +Process *HuPrcCreate(void (*func)(void), u16 prio, s32 stack_size, s32 extra_size); +void HuPrcSleep(s32 time); +void HuPrcVSleep(void); #endif diff --git a/src/game/printfunc.c b/src/game/printfunc.c new file mode 100644 index 00000000..82adf6c2 --- /dev/null +++ b/src/game/printfunc.c @@ -0,0 +1,51 @@ +#include "common.h" +#include "dolphin/gx.h" + +struct strline_data { + u16 type; + u16 last_idx; + s16 x; + s16 y; + s16 w; + s16 h; + s16 empty_line; + float scale; + char str[80]; + GXColor color; +}; + +static struct strline_data strline[256]; +static char pfStrBuf[256]; + +BOOL saftyFrameF; +u16 strlinecnt; +u16 empstrline; +int fontcolor; + +void pfClsScr(void); + +void pfInit(void) +{ + int i; + fontcolor = 15; + empstrline = 0; + + for (i = 0; i < 256; i++) { + strline[i].str[0] = 0; + } + pfClsScr(); +} + +void pfClsScr(void) +{ + int i; + empstrline = 0; + strlinecnt = 0; + for (i = 0; i < 256; i++) { + strline[i].empty_line = i+1; + strline[i].type = 0; + if (strline[i].str[0] != 0) { + strline[i].str[0] = 0; + } + } +} \ No newline at end of file diff --git a/src/game/process.c b/src/game/process.c new file mode 100644 index 00000000..94b49fc4 --- /dev/null +++ b/src/game/process.c @@ -0,0 +1,112 @@ +#include "common.h" +#include "dolphin/os.h" + +void HuPrcInit() +{ + +} + +Process *HuPrcCreate(void (*func)(void), u16 prio, s32 stack_size, s32 extra_size) +{ + return NULL; +} + +void HuPrcChildLink() +{ + +} + +void HuPrcChildUnlink() +{ + +} + +void HuPrcChildCreate() +{ + +} + +void HuPrcChildWatch() +{ + +} + +void HuPrcCurrentGet() +{ + +} + +void HuPrcKill() +{ + +} + +void HuPrcChildKill() +{ + +} + +void HuPrcEnd() +{ + +} + +void HuPrcSleep(s32 time) +{ + +} + +void HuPrcVSleep() +{ + +} + +void HuPrcWakeup() +{ + +} + +void HuPrcDestructorSet2() +{ + +} + +void HuPrcDestructorSet() +{ + +} + +void HuPrcCall() +{ + +} + +void HuPrcMemAlloc() +{ + +} + +void HuPrcMemFree() +{ + +} + +void HuPrcSetStat() +{ + +} + +void HuPrcResetStat() +{ + +} + +void HuPrcAllPause() +{ + +} + +void HuPrcAllUPause() +{ + +} \ No newline at end of file From 015fbf39b15b3301519bd4b1217318fcd251e53c Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 09:47:39 -0600 Subject: [PATCH 03/10] Match much of process.c --- config/GMPE01_00/splits.txt | 3 + config/GMPE01_00/symbols.txt | 4 +- include/common_structs.h | 4 +- include/functions.h | 15 +- src/game/process.c | 270 +++++++++++++++++++++++++++++++---- 5 files changed, 261 insertions(+), 35 deletions(-) diff --git a/config/GMPE01_00/splits.txt b/config/GMPE01_00/splits.txt index edae67a7..7be80bd4 100644 --- a/config/GMPE01_00/splits.txt +++ b/config/GMPE01_00/splits.txt @@ -47,6 +47,9 @@ game/decode.c: game/font.c: .data start:0x8011FE00 end:0x80121E00 +game/jmp.c: + .text start:0x8000A464 end:0x8000A558 + game/malloc.c: .text start:0x8000A558 end:0x8000A938 .data start:0x80121F50 end:0x80121FC8 diff --git a/config/GMPE01_00/symbols.txt b/config/GMPE01_00/symbols.txt index 55f9d873..0d89aaa5 100644 --- a/config/GMPE01_00/symbols.txt +++ b/config/GMPE01_00/symbols.txt @@ -99,8 +99,8 @@ fn_80009FF8 = .text:0x80009FF8; // type:function size:0xE4 fn_8000A0DC = .text:0x8000A0DC; // type:function size:0xC8 fn_8000A1A4 = .text:0x8000A1A4; // type:function size:0x6C fn_8000A210 = .text:0x8000A210; // type:function size:0x254 -fn_8000A464 = .text:0x8000A464; // type:function size:0x74 -fn_8000A4D8 = .text:0x8000A4D8; // type:function size:0x80 +gcsetjmp = .text:0x8000A464; // type:function size:0x74 +gclongjmp = .text:0x8000A4D8; // type:function size:0x80 HuMemInitAll = .text:0x8000A558; // type:function size:0x12C HuMemInit = .text:0x8000A684; // type:function size:0x30 HuMemDCFlushAll = .text:0x8000A6B4; // type:function size:0x2C diff --git a/include/common_structs.h b/include/common_structs.h index cc12f449..734a40e3 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -31,13 +31,13 @@ typedef struct process { struct process *child; struct process *parent; struct process *next_child; - struct process *last_child; + struct process *first_child; void *heap; u16 exec; u16 stat; u16 prio; s32 sleep_time; - void *base_sp; + u32 base_sp; jmp_buf jump; void (*dtor)(void); void *user_data; diff --git a/include/functions.h b/include/functions.h index a6e79d03..4f1c39a2 100644 --- a/include/functions.h +++ b/include/functions.h @@ -40,9 +40,20 @@ s32 HuMemUsedMemoryBlockGet(void *heap_ptr); s32 HuMemMemoryAllocSizeGet(s32 size); void HuMemHeapDump(void *heap_ptr, s16 status); -Process *HuPrcCreate(void (*func)(void), u16 prio, s32 stack_size, s32 extra_size); +void HuPrcInit(void); +Process *HuPrcCreate(void (*func)(void), u16 prio, u32 stack_size, s32 extra_size); +void HuPrcChildLink(Process *parent, Process *child); +void HuPrcChildUnlink(Process *process); +Process *HuPrcChildCreate(void (*func)(void), u16 prio, u32 stack_size, s32 extra_size, Process *parent); +void HuPrcChildWatch(); +Process *HuPrcCurrentGet(); +int HuPrcKill(Process *process); +void HuPrcChildKill(Process *process); void HuPrcSleep(s32 time); void HuPrcVSleep(void); - +void HuPrcWakeup(Process *process); +void HuPrcDestructorSet2(Process *process, void (*func)(void)); +void HuPrcDestructorSet(void (*func)(void)); +void HuPrcCall(int tick); #endif diff --git a/src/game/process.c b/src/game/process.c index 94b49fc4..1252b3c7 100644 --- a/src/game/process.c +++ b/src/game/process.c @@ -1,84 +1,296 @@ #include "common.h" #include "dolphin/os.h" -void HuPrcInit() +extern int gcsetjmp(jmp_buf *jump); +extern void gclongjmp(jmp_buf *jump, int status); + +#define EXEC_NORMAL 0 +#define EXEC_SLEEP 1 +#define EXEC_CHILDWATCH 2 +#define EXEC_KILLED 3 + +static jmp_buf processjmpbuf; +u32 procfunc; +static u16 processcnt; +static Process *processcur; +static Process *processtop; + +void HuPrcInit(void) { - + processcnt = 0; + processtop = NULL; } -Process *HuPrcCreate(void (*func)(void), u16 prio, s32 stack_size, s32 extra_size) -{ - return NULL; +static void LinkProcess(Process** root, Process* process) { + Process* src_process = *root; + + if (src_process && (src_process->prio >= process->prio)) { + while (src_process->next && src_process->next->prio >= process->prio) { + src_process = src_process->next; + } + + process->next = src_process->next; + process->prev = src_process; + src_process->next = process; + if (process->next) { + process->next->prev = process; + } + } else { + process->next = (*root); + process->prev = NULL; + *root = process; + if (src_process) { + src_process->prev = process; + } + } } -void HuPrcChildLink() -{ - +static void UnlinkProcess(Process **root, Process *process) { + if (process->next) { + process->next->prev = process->prev; + } + + if (process->prev) { + process->prev->next = process->next; + } + + else { + *root = process->next; + } } -void HuPrcChildUnlink() +Process *HuPrcCreate(void (*func)(void), u16 prio, u32 stack_size, s32 extra_size) { - + Process *process; + s32 alloc_size; + void *heap; + if(stack_size == 0) { + stack_size = 2048; + } + alloc_size = HuMemMemoryAllocSizeGet(sizeof(Process)) + +HuMemMemoryAllocSizeGet(stack_size) + +HuMemMemoryAllocSizeGet(extra_size); + heap = HuMemDirectMalloc(0, alloc_size); + if(!heap) { + OSReport("process> malloc error size %d\n", alloc_size); + return NULL; + } + HuMemHeapInit(heap, alloc_size); + process = HuMemMemoryAlloc(heap, sizeof(Process), 0xA5A5A5A5); + process->heap = heap; + process->exec = EXEC_NORMAL; + process->stat = 0; + process->prio = prio; + process->sleep_time = 0; + process->base_sp = ((u32)HuMemMemoryAlloc(heap, stack_size, 0xA5A5A5A5))+stack_size-8; + gcsetjmp(&process->jump); + process->jump.lr = (u32)func; + process->jump.sp = process->base_sp; + process->dtor = NULL; + process->user_data = NULL; + LinkProcess(&processtop, process); + process->child = NULL; + process->parent = NULL; + processcnt++; + return process; } -void HuPrcChildCreate() +void HuPrcChildLink(Process *parent, Process *child) { - + HuPrcChildUnlink(child); + if(parent->child) { + parent->child->first_child = child; + } + child->next_child = parent->child; + child->first_child = NULL; + parent->child = child; + child->parent = parent; +} + +void HuPrcChildUnlink(Process *process) +{ + if(process->parent) { + if(process->next_child) { + process->next_child->first_child = process->first_child; + } + if(process->first_child) { + process->first_child->next_child = process->next_child; + } else { + process->parent->child = process->next_child; + } + process->parent = NULL; + } +} + +//Issues with swapped stack_size and heap local variable in HuPrcCreate inline +Process *HuPrcChildCreate(void (*func)(void), u16 prio, u32 stack_size, s32 extra_size, Process *parent) +{ + Process *child = HuPrcCreate(func, prio, stack_size, extra_size); + HuPrcChildLink(parent, child); + return child; } void HuPrcChildWatch() { + Process *curr = HuPrcCurrentGet(); + if(curr->child) { + curr->exec = EXEC_CHILDWATCH; + if(!gcsetjmp(&curr->jump)) { + gclongjmp(&processjmpbuf, 1); + } + } } -void HuPrcCurrentGet() +Process *HuPrcCurrentGet() { - + return processcur; } -void HuPrcKill() +static int SetKillStatusProcess(Process *process) { - + if(process->exec != EXEC_KILLED) { + HuPrcWakeup(process); + process->exec = EXEC_KILLED; + return 0; + } else { + return -1; + } } -void HuPrcChildKill() +int HuPrcKill(Process *process) { - + if(process == NULL) { + process = HuPrcCurrentGet(); + } + HuPrcChildKill(process); + HuPrcChildUnlink(process); + return SetKillStatusProcess(process); +} + +void HuPrcChildKill(Process *process) +{ + Process *child = process->child; + while(child) { + if(child->child) { + HuPrcChildKill(child); + } + SetKillStatusProcess(child); + child = child->next_child; + } + process->child = NULL; +} + +static void gcTerminateProcess(Process *process) +{ + if(process->dtor) { + process->dtor(); + } + UnlinkProcess(&processtop, process); + processcnt--; + gclongjmp(&processjmpbuf, 2); } void HuPrcEnd() { - + Process *process = HuPrcCurrentGet(); + HuPrcChildKill(process); + HuPrcChildUnlink(process); + gcTerminateProcess(process); } void HuPrcSleep(s32 time) { - + Process *process = HuPrcCurrentGet(); + if(time != 0 && process->exec != EXEC_KILLED) { + process->exec = EXEC_SLEEP; + process->sleep_time = time; + } + if(!gcsetjmp(&process->jump)) { + gclongjmp(&processjmpbuf, 1); + } } void HuPrcVSleep() { - + Process *process = HuPrcCurrentGet(); + if(!gcsetjmp(&process->jump)) { + gclongjmp(&processjmpbuf, 1); + } } -void HuPrcWakeup() +void HuPrcWakeup(Process *process) { - + process->sleep_time = 0; } -void HuPrcDestructorSet2() +void HuPrcDestructorSet2(Process *process, void (*func)(void)) { - + process->dtor = func; } -void HuPrcDestructorSet() +void HuPrcDestructorSet(void (*func)(void)) { - + Process *process = HuPrcCurrentGet(); + process->dtor = func; } -void HuPrcCall() +void HuPrcCall(int tick) { - + Process *process; + int ret; + processcur = processtop; + ret = gcsetjmp(&processjmpbuf); + while(1) { + switch(ret) { + case 2: + HuMemDirectFree(processcur->heap); + case 1: + if(((u8 *)(processcur->heap))[4] != 165) { + printf("stack overlap error.(process pointer %x)\n", processcur); + while(1); + } else { + processcur = processcur->next; + } + break; + } + process = processcur; + if(!process) { + return; + } + procfunc = process->jump.lr; + if((process->stat & 0x3) && process->exec != EXEC_KILLED) { + ret = 1; + continue; + } + switch(process->exec) { + case EXEC_SLEEP: + if(process->sleep_time > 0) { + process->sleep_time -= tick; + if(process->sleep_time <= 0) { + process->sleep_time = 0; + process->exec = EXEC_NORMAL; + } + } + ret = 1; + break; + + case EXEC_CHILDWATCH: + if(process->child) { + ret = 1; + } else { + process->exec = EXEC_NORMAL; + ret = 0; + } + break; + + case EXEC_KILLED: + process->jump.lr = (u32)HuPrcEnd; + case EXEC_NORMAL: + gclongjmp(&process->jump, 1); + break; + } + } } void HuPrcMemAlloc() From 244a856837ad50e2b8549db280605afb0730f9b9 Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 09:54:42 -0600 Subject: [PATCH 04/10] Match all but HuPrcChildCreate --- include/functions.h | 6 +++++ src/game/process.c | 59 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/include/functions.h b/include/functions.h index 4f1c39a2..9978fd3c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -55,5 +55,11 @@ void HuPrcWakeup(Process *process); void HuPrcDestructorSet2(Process *process, void (*func)(void)); void HuPrcDestructorSet(void (*func)(void)); void HuPrcCall(int tick); +void *HuPrcMemAlloc(s32 size); +void HuPrcMemFree(void *ptr); +void HuPrcSetStat(Process *process, u16 value); +void HuPrcResetStat(Process *process, u16 value); +void HuPrcAllPause(int flag); +void HuPrcAllUPause(int flag); #endif diff --git a/src/game/process.c b/src/game/process.c index 1252b3c7..802d6699 100644 --- a/src/game/process.c +++ b/src/game/process.c @@ -293,32 +293,67 @@ void HuPrcCall(int tick) } } -void HuPrcMemAlloc() +void *HuPrcMemAlloc(s32 size) { - + Process *process = HuPrcCurrentGet(); + return HuMemMemoryAlloc(process->heap, size, 0xA5A5A5A5); } -void HuPrcMemFree() +void HuPrcMemFree(void *ptr) { - + HuMemMemoryFree(ptr, 0xA5A5A5A5); } -void HuPrcSetStat() +void HuPrcSetStat(Process *process, u16 value) { - + process->stat |= value; } -void HuPrcResetStat() +void HuPrcResetStat(Process *process, u16 value) { - + process->stat &= ~value; } -void HuPrcAllPause() +void HuPrcAllPause(int flag) { - + Process *process = processtop; + if(flag) { + while(process != NULL) { + if(!(process->stat & 0x4)) { + HuPrcSetStat(process, 0x1); + } + + process = process->next; + } + } else { + while(process != NULL) { + if(process->stat & 0x1) { + HuPrcResetStat(process, 0x1); + } + + process = process->next; + } + } } -void HuPrcAllUPause() +void HuPrcAllUPause(int flag) { - + Process *process = processtop; + if(flag) { + while(process != NULL) { + if(!(process->stat & 0x8)) { + HuPrcSetStat(process, 0x2); + } + + process = process->next; + } + } else { + while(process != NULL) { + if(process->stat & 0x2) { + HuPrcResetStat(process, 0x2); + } + + process = process->next; + } + } } \ No newline at end of file From b7a4ffb221df2277580538d2f760b0ebb60b7132 Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 10:00:55 -0600 Subject: [PATCH 05/10] Match HuPrcChildCreate --- src/game/process.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/game/process.c b/src/game/process.c index 802d6699..3dbc58f0 100644 --- a/src/game/process.c +++ b/src/game/process.c @@ -70,8 +70,7 @@ Process *HuPrcCreate(void (*func)(void), u16 prio, u32 stack_size, s32 extra_siz alloc_size = HuMemMemoryAllocSizeGet(sizeof(Process)) +HuMemMemoryAllocSizeGet(stack_size) +HuMemMemoryAllocSizeGet(extra_size); - heap = HuMemDirectMalloc(0, alloc_size); - if(!heap) { + if(!(heap = HuMemDirectMalloc(0, alloc_size))) { OSReport("process> malloc error size %d\n", alloc_size); return NULL; } @@ -139,7 +138,6 @@ void HuPrcChildWatch() gclongjmp(&processjmpbuf, 1); } } - } Process *HuPrcCurrentGet() From ff69afeb4e7ae8950dd2364b61571ce931cc3c1e Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 10:05:19 -0600 Subject: [PATCH 06/10] Remove Match Comment from HuPrcChildCreate --- src/game/process.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/game/process.c b/src/game/process.c index 3dbc58f0..67915cc5 100644 --- a/src/game/process.c +++ b/src/game/process.c @@ -121,7 +121,6 @@ void HuPrcChildUnlink(Process *process) } } -//Issues with swapped stack_size and heap local variable in HuPrcCreate inline Process *HuPrcChildCreate(void (*func)(void), u16 prio, u32 stack_size, s32 extra_size, Process *parent) { Process *child = HuPrcCreate(func, prio, stack_size, extra_size); From b3452a8b910f702ea42810e5e32e874133d88df5 Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 10:25:18 -0600 Subject: [PATCH 07/10] Fix variable ordering --- src/game/process.c | 7 ++-- src/unsplit/unsplit.c | 89 ------------------------------------------- 2 files changed, 4 insertions(+), 92 deletions(-) diff --git a/src/game/process.c b/src/game/process.c index 67915cc5..ae05bf07 100644 --- a/src/game/process.c +++ b/src/game/process.c @@ -10,10 +10,11 @@ extern void gclongjmp(jmp_buf *jump, int status); #define EXEC_KILLED 3 static jmp_buf processjmpbuf; -u32 procfunc; -static u16 processcnt; -static Process *processcur; static Process *processtop; +static Process *processcur; +static u16 processcnt; +u32 procfunc; + void HuPrcInit(void) { diff --git a/src/unsplit/unsplit.c b/src/unsplit/unsplit.c index 225d956b..e69de29b 100644 --- a/src/unsplit/unsplit.c +++ b/src/unsplit/unsplit.c @@ -1,89 +0,0 @@ -#include "common.h" - -extern unkStruct145A98 lbl_80145A98[0x100]; -extern s32 debugFontColor; -extern s16 lbl_801D3B2C; -extern s16 lbl_801D3B2E; -extern unkStruct1D3B44* lbl_801D3B44; - -void fn_8000AEF0(void) { - s32 i; - - debugFontColor = 0xF; - lbl_801D3B2E = 0; - - for (i = 0; i < 0x100; i++) { - lbl_80145A98[i].unk_14 = 0; - } - fn_8000AF54(); -} - -void fn_8000AF54(void) { - s32 i; - - lbl_801D3B2E = 0; - lbl_801D3B2C = 0; - for (i = 0; i < 0x100; i++) { - lbl_80145A98[i].unk_0C = (s16) (i + 1); - lbl_80145A98[i].unk_00 = 0; - if (lbl_80145A98[i].unk_14 != 0) { - lbl_80145A98[i].unk_14 = 0; - } - } -} - -// HuPrcCall - -// HuPrcMemAlloc - -// HuPrcMemFree - -void HuPrcSetStat(unkStruct1D3B44* arg0, u16 arg1) { - arg0->unk_1E |= arg1; -} - -void HuPrcResetStat(unkStruct1D3B44* arg0, s32 arg1) { - arg0->unk_1E &= ~arg1; -} - -void HuPrcAllPause(s32 arg0) { - unkStruct1D3B44* var_r31; - - var_r31 = lbl_801D3B44; - if (arg0 != 0) { - while (var_r31 != NULL) { - if ((var_r31->unk_1E & 4) == 0) { - var_r31->unk_1E |= (u16) 1; - } - var_r31 = var_r31->prev; - } - return; - } - while (var_r31 != NULL) { - if ((var_r31->unk_1E & 1) != 0) { - var_r31->unk_1E &= -2; - } - var_r31 = var_r31->prev; - } -} - -void HuPrcAllUPause(s32 arg0) { - unkStruct1D3B44* var_r31; - - var_r31 = lbl_801D3B44; - if (arg0 != 0) { - while (var_r31 != NULL) { - if ((var_r31->unk_1E & 8) == 0) { - var_r31->unk_1E |= (u16) 2; - } - var_r31 = var_r31->prev; - } - return; - } - while (var_r31 != NULL) { - if ((var_r31->unk_1E & 2) != 0) { - var_r31->unk_1E &= -3; - } - var_r31 = var_r31->prev; - } -} From 824ccd1ac60c9f38e9dc6267e331f558b54d31cf Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 12:18:50 -0600 Subject: [PATCH 08/10] Decompile subchrdll.c --- config/GMPE01_00/rels/subchrselDll/splits.txt | 9 + .../GMPE01_00/rels/subchrselDll/symbols.txt | 58 +++--- config/GMPE01_00/symbols.txt | 12 +- configure.py | 12 ++ include/common_structs.h | 18 +- include/functions.h | 9 +- src/REL/subchrselDll/subchrselDll.c | 175 ++++++++++++++++-- src/REL/subchrselDll/subchrselDll.h | 38 ---- 8 files changed, 240 insertions(+), 91 deletions(-) delete mode 100644 src/REL/subchrselDll/subchrselDll.h diff --git a/config/GMPE01_00/rels/subchrselDll/splits.txt b/config/GMPE01_00/rels/subchrselDll/splits.txt index 531cd645..62fd2695 100644 --- a/config/GMPE01_00/rels/subchrselDll/splits.txt +++ b/config/GMPE01_00/rels/subchrselDll/splits.txt @@ -5,3 +5,12 @@ Sections: .rodata type:rodata align:8 .data type:data align:8 .bss type:bss align:8 + +REL/executor.c: + .text start:0x00000000 end:0x000000A0 + +REL/subchrselDll/subchrselDll.c: + .text start:0x000000A0 end:0x000007B8 + .rodata start:0x00000000 end:0x00000018 + .data start:0x00000000 end:0x000000E1 + .bss start:0x00000000 end:0x00000004 diff --git a/config/GMPE01_00/rels/subchrselDll/symbols.txt b/config/GMPE01_00/rels/subchrselDll/symbols.txt index 4b25743d..8f028b97 100644 --- a/config/GMPE01_00/rels/subchrselDll/symbols.txt +++ b/config/GMPE01_00/rels/subchrselDll/symbols.txt @@ -1,33 +1,33 @@ _prolog = .text:0x00000000; // type:function size:0x54 scope:global _epilog = .text:0x00000054; // type:function size:0x4C scope:global -fn_1_A0 = .text:0x000000A0; // type:function size:0x6C -fn_1_10C = .text:0x0000010C; // type:function size:0x58 -fn_1_164 = .text:0x00000164; // type:function size:0x654 +ModuleProlog = .text:0x000000A0; // type:function size:0x6C +GetBtns = .text:0x0000010C; // type:function size:0x58 scope:local +SubchrMain = .text:0x00000164; // type:function size:0x654 scope:local _ctors = .ctors:0x00000000; // type:label scope:global data:4byte _dtors = .dtors:0x00000000; // type:label scope:global data:4byte -lbl_1_rodata_10 = .rodata:0x00000010; // type:object size:0x4 data:float -lbl_1_rodata_14 = .rodata:0x00000014; // type:object size:0x4 data:float -lbl_1_data_0 = .data:0x00000000; // type:object size:0x8 data:string -lbl_1_data_8 = .data:0x00000008; // type:object size:0x8 data:string -lbl_1_data_10 = .data:0x00000010; // type:object size:0x8 data:string -lbl_1_data_18 = .data:0x00000018; // type:object size:0x8 data:string -lbl_1_data_20 = .data:0x00000020; // type:object size:0x10 -lbl_1_data_30 = .data:0x00000030; // type:object size:0x6 data:string -lbl_1_data_36 = .data:0x00000036; // type:object size:0x6 data:string -lbl_1_data_3C = .data:0x0000003C; // type:object size:0x6 data:string -lbl_1_data_42 = .data:0x00000042; // type:object size:0x6 data:string -lbl_1_data_48 = .data:0x00000048; // type:object size:0x6 data:string -lbl_1_data_4E = .data:0x0000004E; // type:object size:0x7 data:string -lbl_1_data_55 = .data:0x00000055; // type:object size:0x6 data:string -lbl_1_data_5B = .data:0x0000005B; // type:object size:0x9 -lbl_1_data_64 = .data:0x00000064; // type:object size:0x20 -lbl_1_data_84 = .data:0x00000084; // type:object size:0x1 -lbl_1_data_85 = .data:0x00000085; // type:object size:0x6 data:string -lbl_1_data_8B = .data:0x0000008B; // type:object size:0x8 data:string -lbl_1_data_93 = .data:0x00000093; // type:object size:0x7 data:string -lbl_1_data_9A = .data:0x0000009A; // type:object size:0x7 data:string -lbl_1_data_A1 = .data:0x000000A1; // type:object size:0x6 data:string -lbl_1_data_A7 = .data:0x000000A7; // type:object size:0x9 -lbl_1_data_B0 = .data:0x000000B0; // type:object size:0x1C -lbl_1_data_CC = .data:0x000000CC; // type:object size:0x15 data:string -lbl_1_bss_0 = .bss:0x00000000; // type:object size:0x4 data:byte +lbl_1_rodata_10 = .rodata:0x00000010; // type:object size:0x4 scope:local data:float +lbl_1_rodata_14 = .rodata:0x00000014; // type:object size:0x4 scope:local data:float +lbl_1_data_0 = .data:0x00000000; // type:object size:0x8 scope:local data:string +lbl_1_data_8 = .data:0x00000008; // type:object size:0x8 scope:local data:string +lbl_1_data_10 = .data:0x00000010; // type:object size:0x8 scope:local data:string +lbl_1_data_18 = .data:0x00000018; // type:object size:0x8 scope:local data:string +player_numstr = .data:0x00000020; // type:object size:0x10 scope:local +lbl_1_data_30 = .data:0x00000030; // type:object size:0x6 scope:local data:string +lbl_1_data_36 = .data:0x00000036; // type:object size:0x6 scope:local data:string +lbl_1_data_3C = .data:0x0000003C; // type:object size:0x6 scope:local data:string +lbl_1_data_42 = .data:0x00000042; // type:object size:0x6 scope:local data:string +lbl_1_data_48 = .data:0x00000048; // type:object size:0x6 scope:local data:string +lbl_1_data_4E = .data:0x0000004E; // type:object size:0x7 scope:local data:string +lbl_1_data_55 = .data:0x00000055; // type:object size:0x6 scope:local data:string +lbl_1_data_5B = .data:0x0000005B; // type:object size:0x9 scope:local +character_str = .data:0x00000064; // type:object size:0x20 scope:local +lbl_1_data_84 = .data:0x00000084; // type:object size:0x1 scope:local +lbl_1_data_85 = .data:0x00000085; // type:object size:0x6 scope:local data:string +lbl_1_data_8B = .data:0x0000008B; // type:object size:0x8 scope:local data:string +lbl_1_data_93 = .data:0x00000093; // type:object size:0x7 scope:local data:string +lbl_1_data_9A = .data:0x0000009A; // type:object size:0x7 scope:local data:string +lbl_1_data_A1 = .data:0x000000A1; // type:object size:0x6 scope:local data:string +lbl_1_data_A7 = .data:0x000000A7; // type:object size:0x9 scope:local +ext_character_str = .data:0x000000B0; // type:object size:0x1C scope:local +lbl_1_data_CC = .data:0x000000CC; // type:object size:0x15 scope:local data:string +lbl_1_bss_0 = .bss:0x00000000; // type:object size:0x4 scope:local data:byte diff --git a/config/GMPE01_00/symbols.txt b/config/GMPE01_00/symbols.txt index 0d89aaa5..e33b7341 100644 --- a/config/GMPE01_00/symbols.txt +++ b/config/GMPE01_00/symbols.txt @@ -511,8 +511,8 @@ fn_8002EA6C = .text:0x8002EA6C; // type:function size:0x16C fn_8002EBD8 = .text:0x8002EBD8; // type:function size:0x90 fn_8002EC68 = .text:0x8002EC68; // type:function size:0x170 fn_8002EDD8 = .text:0x8002EDD8; // type:function size:0xE8 -fn_8002EEC0 = .text:0x8002EEC0; // type:function size:0x60 -fn_8002EF20 = .text:0x8002EF20; // type:function size:0xF4 +omOvlGotoEx = .text:0x8002EEC0; // type:function size:0x60 +omOvlReturnEx = .text:0x8002EF20; // type:function size:0xF4 fn_8002F014 = .text:0x8002F014; // type:function size:0xB8 omOvlHisChg = .text:0x8002F0CC; // type:function size:0xA0 omOvlHisGet = .text:0x8002F16C; // type:function size:0x78 @@ -728,7 +728,7 @@ fn_80040D60 = .text:0x80040D60; // type:function size:0x36C fn_800410CC = .text:0x800410CC; // type:function size:0xA4 fn_80041170 = .text:0x80041170; // type:function size:0xB4 fn_80041224 = .text:0x80041224; // type:function size:0x288 -fn_800414AC = .text:0x800414AC; // type:function size:0x12C +WipeCreate = .text:0x800414AC; // type:function size:0x12C fn_800415D8 = .text:0x800415D8; // type:function size:0x28 fn_80041600 = .text:0x80041600; // type:function size:0x10 fn_80041610 = .text:0x80041610; // type:function size:0x8 @@ -5400,7 +5400,7 @@ lbl_8018F790 = .bss:0x8018F790; // type:object size:0x370 lbl_8018FB00 = .bss:0x8018FB00; // type:object size:0x38 lbl_8018FB38 = .bss:0x8018FB38; // type:object size:0xC0 lbl_8018FBF8 = .bss:0x8018FBF8; // type:object size:0x18 -lbl_8018FC10 = .bss:0x8018FC10; // type:object size:0x28 +gPlayerConfig = .bss:0x8018FC10; // type:object size:0x28 gPlayerData = .bss:0x8018FC38; // type:object size:0xC0 data:byte lbl_8018FCF8 = .bss:0x8018FCF8; // type:object size:0xE0 data:byte lbl_8018FDD8 = .bss:0x8018FDD8; // type:object size:0x230 @@ -5419,8 +5419,8 @@ lbl_80190E60 = .bss:0x80190E60; // type:object size:0x1200 data:4byte lbl_80192060 = .bss:0x80192060; // type:object size:0x100 lbl_80192160 = .bss:0x80192160; // type:object size:0x100 lbl_80192260 = .bss:0x80192260; // type:object size:0x100 -lbl_80192360 = .bss:0x80192360; // type:object size:0x60 data:4byte -winData = .bss:0x801923C0; // type:object size:0x3000 data:byte +wipeData = .bss:0x80192360; // type:object size:0x60 data:4byte +winData = .bss:0x801923C0; // type:object size:0x3000 align:32 data:byte lbl_801953C0 = .bss:0x801953C0; // type:object size:0x10 lbl_801953D0 = .bss:0x801953D0; // type:object size:0x1410 lbl_801967E0 = .bss:0x801967E0; // type:object size:0x400 data:byte diff --git a/configure.py b/configure.py index 14180103..658075f8 100755 --- a/configure.py +++ b/configure.py @@ -176,6 +176,7 @@ cflags_rel = [ "-char unsigned", "-sdata 0", "-sdata2 0", + "-pool off", ] # Game flags @@ -230,6 +231,7 @@ config.libs = [ Object(NonMatching, "game/data.c"), Object(Matching, "game/decode.c"), Object(NonMatching, "game/font.c"), + Object(NonMatching, "game/jmp.c"), Object(Matching, "game/malloc.c"), Object(Matching, "game/memory.c"), Object(NonMatching, "game/printfunc.c"), @@ -268,6 +270,16 @@ config.libs = [ Object(Matching, "REL/_minigameDLL/_minigameDLL.c"), ], }, + { + "lib": "subchrselDll", + "mw_version": config.linker_version, + "cflags": cflags_rel, + "host": False, + "objects": [ + Object(Matching, "REL/executor.c"), + Object(Matching, "REL/subchrselDll/subchrselDll.c"), + ], + }, ] if args.mode == "configure": diff --git a/include/common_structs.h b/include/common_structs.h index 734a40e3..c17271d7 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -43,10 +43,18 @@ typedef struct process { void *user_data; } Process; -typedef struct unkStruct1D3B44 { - struct unkStruct1D3B44 *prev; - char unk_04[0x1A]; - u16 unk_1E; -} unkStruct1D3B44; // sizeof ??? +typedef struct player_config { + s16 character; + s16 pad_idx; + s16 diff; + s16 group; + s16 iscom; +} PlayerConfig; + +typedef struct wipe_state { + u8 unk[52]; + float duration; + u8 unk2[20]; +} WipeState; #endif diff --git a/include/functions.h b/include/functions.h index 9978fd3c..0f0fb250 100644 --- a/include/functions.h +++ b/include/functions.h @@ -14,7 +14,8 @@ void* omInitObjMan(s32, s32); void fn_80044920(s16); void fn_80045F74(s16, s32); s32 fn_800578E4(void); -void fn_1_26C(void); +void fn_80032A58(int arg0); +void fn_80035A0C(void); void HuDecodeData(void *src, void *dst, u32 size, int decode_type); void HuMemInitAll(void); @@ -62,4 +63,10 @@ void HuPrcResetStat(Process *process, u16 value); void HuPrcAllPause(int flag); void HuPrcAllUPause(int flag); +void omOvlGotoEx(int id, s16 end_mode, int stat, int event); +void omOvlReturnEx(int level, s16 end_mode); +void WipeCreate(char dir, char type, short duration); + +u16 print8(s16 x, s16 y, float scale, char *str, ...); + #endif diff --git a/src/REL/subchrselDll/subchrselDll.c b/src/REL/subchrselDll/subchrselDll.c index 3c5a4c59..8d2279c8 100644 --- a/src/REL/subchrselDll/subchrselDll.c +++ b/src/REL/subchrselDll/subchrselDll.c @@ -1,20 +1,171 @@ -#include "subchrselDll.h" +#include "common.h" -void fn_1_A0(void) { +//HACK: Force 0.5 and 3.0 double constants to appear in REL +const double _half = 0.5; +const double _three = 3.0; + +extern WipeState wipeData; + +extern PlayerConfig gPlayerConfig[4]; +extern u16 HuPadBtnDown[4]; +extern u8 HuPadDStk[4]; +extern int fontcolor; + +static void SubchrMain(void); + +static u8 cur_direction[4]; + +static char *player_numstr[4] = { + "PLAYER1", + "PLAYER2", + "PLAYER3", + "PLAYER4" +}; + +static char *character_str[8] = { + "MARIO", + "LUIGI", + "PEACH", + "YOSHI", + "WARIO", + "DONKEY", + "DAISY", + "WALUIGI" +}; + +static char *ext_character_str[7] = { + "", + "KOOPA", + "KINOPIO", + "HEIHOH", + "TERESA", + "NOKO2", + "MKOOPA" +}; + +void ModuleProlog(void) +{ void* sp8 = omInitObjMan(0x32, 0x2000); - Hu3DBGColorSet(0U, 0U, 0U); - fn_8000C760(&fn_1_164, 0x1000, 0x3000, 0, fn_8000CA3C()); - fn_800414AC(1, 0, -1); + Hu3DBGColorSet(0, 0, 0); + HuPrcChildCreate(SubchrMain, 4096, 12288, 0, HuPrcCurrentGet()); + WipeCreate(1, 0, -1); } -u16 fn_1_10C(void) { - u16 var_r31; +static u16 GetBtns(void) +{ + u16 btns; - var_r31 = lbl_801D3AD0; - if (lbl_1_bss_0 != lbl_801D3AAC) { - var_r31 |= lbl_801D3AAC; + btns = HuPadBtnDown[0]; + if (cur_direction[0] != HuPadDStk[0]) { + btns |= HuPadDStk[0]; } - return var_r31; + return btns; } -// void fn_1_164(void) +static void SubchrMain() +{ + int prev_character[4]; + int character[4]; + int i, cursor_pos; + for(i=0; i<4; i++) { + prev_character[i] = gPlayerConfig[i].character; + character[i] = 0; + cur_direction[i] = 0; + } + cursor_pos = 0; + while(1) { + int y, x; + u16 btns; + fontcolor = 14; + print8(150, 64, 2.0f, "Sub Character Select"); + x = 170; + y = 120; + for(i=0; i<4; i++, y += 16) { + fontcolor = 12; + print8(x, y, 2.0f, player_numstr[i]); + if(i == cursor_pos) { + fontcolor = 13; + } else { + fontcolor = 12; + } + if(character[i] != 0) { + print8(x+200, y, 2.0f, ext_character_str[character[i]]); + } else { + print8(x+200, y, 2.0f, character_str[prev_character[i]]); + } + } + if(GetBtns() & 0x1000) { + for(i=0; i<4; i++) { + if(character[i] != 0) { + gPlayerConfig[i]. character = character[i]+7; + } + } + fn_80032A58(30); + WipeCreate(2, 0, -1); + HuPrcSleep(wipeData.duration+1.0f); + fn_80035A0C(); + omOvlGotoEx(41, 1, 0, 0); + do { + HuPrcVSleep(); + } while(1); + } else { + if(GetBtns() & 0x1) { + do { + character[cursor_pos]--; + if(character[cursor_pos] < 0) { + character[cursor_pos] = 6; + } + for(i=0; i<4; i++) { + if(cursor_pos != i) { + if(character[cursor_pos] == character[i] && character[cursor_pos] != 0) { + break; + } + } + } + } while(i < 4); + } + if(GetBtns() & 0x2) { + do { + character[cursor_pos]++; + if(character[cursor_pos] > 6) { + character[cursor_pos] = 0; + } + for(i=0; i<4; i++) { + if(cursor_pos != i) { + if(character[cursor_pos] == character[i] && character[cursor_pos] != 0) { + break; + } + } + } + } while(i < 4); + } + if(GetBtns() & 0x4) { + cursor_pos++; + } + if(GetBtns() & 0x8) { + cursor_pos--; + } + if(cursor_pos < 0) { + cursor_pos = 3; + } + if(cursor_pos > 3) { + cursor_pos = 0; + } + if(GetBtns() & 0x200) { + fn_80032A58(30); + WipeCreate(2, 0, -1); + HuPrcSleep(wipeData.duration+1.0f); + fn_80035A0C(); + omOvlReturnEx(1, 1); + do { + HuPrcVSleep(); + } while(1); + } else { + if(cur_direction[0] != HuPadDStk[0]) { + cur_direction[0] = HuPadDStk[0]; + } + } + } + HuPrcVSleep(); + } +} \ No newline at end of file diff --git a/src/REL/subchrselDll/subchrselDll.h b/src/REL/subchrselDll/subchrselDll.h deleted file mode 100644 index 9c0762c0..00000000 --- a/src/REL/subchrselDll/subchrselDll.h +++ /dev/null @@ -1,38 +0,0 @@ -#include "common.h" -#include "REL/executor.h" - -void fn_8000C760(void*, s32, s32, s32, s32); -s32 fn_8000CA3C(); -void fn_800414AC(s16, s16, s16); - -extern u8 lbl_1_bss_0; -extern u8 lbl_801D3AAC; -extern u16 lbl_801D3AD0; - -typedef struct unkStruct192360 { - char unk_00[0x34]; - f32 unk_34; -} unkStruct192360; - -s16 fn_8000AFF4(s16, s16, f32, char*, ...); /* extern */ -void fn_8000CF0C(s32, f32); /* extern */ -void fn_8000CF8C(); /* extern */ -void fn_8002EEC0(s32, s16, s32, s32); /* extern */ -void fn_8002EF20(s16, s16); /* extern */ -void fn_80032A58(s32); /* extern */ -void fn_80035A0C(void); /* extern */ -void fn_800414AC(s16, s16, s16); /* extern */ -extern s32 debugFontColor; -extern u8 lbl_1_bss_0; -extern char *lbl_1_data_20[4]; -extern char *lbl_1_data_64[8]; -extern char *lbl_1_data_B0[7]; -extern char lbl_1_data_CC[20]; -extern s16 lbl_8018FC10[]; -extern unkStruct192360 lbl_80192360; -extern u8 lbl_801D3AAC; -extern u16 lbl_801D3AD0; - -void fn_1_A0(void); -u16 fn_1_10C(void); -void fn_1_164(void); From 905f5a7e7320eac6601ba6a211be022ae94234dc Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 12:32:29 -0600 Subject: [PATCH 09/10] Improve local variable names in SubchrMain --- src/REL/subchrselDll/subchrselDll.c | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/REL/subchrselDll/subchrselDll.c b/src/REL/subchrselDll/subchrselDll.c index 8d2279c8..22659be6 100644 --- a/src/REL/subchrselDll/subchrselDll.c +++ b/src/REL/subchrselDll/subchrselDll.c @@ -64,12 +64,12 @@ static u16 GetBtns(void) static void SubchrMain() { - int prev_character[4]; int character[4]; + int ext_character[4]; int i, cursor_pos; for(i=0; i<4; i++) { - prev_character[i] = gPlayerConfig[i].character; - character[i] = 0; + character[i] = gPlayerConfig[i].character; + ext_character[i] = 0; cur_direction[i] = 0; } cursor_pos = 0; @@ -88,16 +88,16 @@ static void SubchrMain() } else { fontcolor = 12; } - if(character[i] != 0) { - print8(x+200, y, 2.0f, ext_character_str[character[i]]); + if(ext_character[i] != 0) { + print8(x+200, y, 2.0f, ext_character_str[ext_character[i]]); } else { - print8(x+200, y, 2.0f, character_str[prev_character[i]]); + print8(x+200, y, 2.0f, character_str[character[i]]); } } if(GetBtns() & 0x1000) { for(i=0; i<4; i++) { - if(character[i] != 0) { - gPlayerConfig[i]. character = character[i]+7; + if(ext_character[i] != 0) { + gPlayerConfig[i]. character = ext_character[i]+7; } } fn_80032A58(30); @@ -111,13 +111,13 @@ static void SubchrMain() } else { if(GetBtns() & 0x1) { do { - character[cursor_pos]--; - if(character[cursor_pos] < 0) { - character[cursor_pos] = 6; + ext_character[cursor_pos]--; + if(ext_character[cursor_pos] < 0) { + ext_character[cursor_pos] = 6; } for(i=0; i<4; i++) { if(cursor_pos != i) { - if(character[cursor_pos] == character[i] && character[cursor_pos] != 0) { + if(ext_character[cursor_pos] == ext_character[i] && ext_character[cursor_pos] != 0) { break; } } @@ -126,13 +126,13 @@ static void SubchrMain() } if(GetBtns() & 0x2) { do { - character[cursor_pos]++; - if(character[cursor_pos] > 6) { - character[cursor_pos] = 0; + ext_character[cursor_pos]++; + if(ext_character[cursor_pos] > 6) { + ext_character[cursor_pos] = 0; } for(i=0; i<4; i++) { if(cursor_pos != i) { - if(character[cursor_pos] == character[i] && character[cursor_pos] != 0) { + if(ext_character[cursor_pos] == ext_character[i] && ext_character[cursor_pos] != 0) { break; } } From 39286d7a62bf2b17c6cf482d5258cc34e1c60a8c Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 12:53:00 -0600 Subject: [PATCH 10/10] Add variables to common.h --- include/common.h | 1 + include/variables.h | 23 +++++++++++++++++++++++ src/REL/subchrselDll/subchrselDll.c | 7 ------- src/game/malloc.c | 2 -- 4 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 include/variables.h diff --git a/include/common.h b/include/common.h index 70f5399c..4875c13a 100644 --- a/include/common.h +++ b/include/common.h @@ -4,5 +4,6 @@ #include "types.h" #include "common_structs.h" #include "functions.h" +#include "variables.h" #endif \ No newline at end of file diff --git a/include/variables.h b/include/variables.h new file mode 100644 index 00000000..8ed35427 --- /dev/null +++ b/include/variables.h @@ -0,0 +1,23 @@ +#ifndef _VARIABLES_H +#define _VARIABLES_H + +#include "types.h" +#include "common_structs.h" +#include "dolphin/os.h" + +extern u16 HuPadBtnDown[4]; +extern u8 HuPadDStk[4]; + +extern OSHeapHandle currentHeapHandle; + +extern BOOL saftyFrameF; +extern u16 strlinecnt; +extern u16 empstrline; +extern int fontcolor; +extern u32 procfunc; + +extern WipeState wipeData; + +extern PlayerConfig gPlayerConfig[4]; + +#endif diff --git a/src/REL/subchrselDll/subchrselDll.c b/src/REL/subchrselDll/subchrselDll.c index 22659be6..20b9801f 100644 --- a/src/REL/subchrselDll/subchrselDll.c +++ b/src/REL/subchrselDll/subchrselDll.c @@ -4,13 +4,6 @@ const double _half = 0.5; const double _three = 3.0; -extern WipeState wipeData; - -extern PlayerConfig gPlayerConfig[4]; -extern u16 HuPadBtnDown[4]; -extern u8 HuPadDStk[4]; -extern int fontcolor; - static void SubchrMain(void); static u8 cur_direction[4]; diff --git a/src/game/malloc.c b/src/game/malloc.c index d93463e2..4dab78e4 100644 --- a/src/game/malloc.c +++ b/src/game/malloc.c @@ -1,8 +1,6 @@ #include "common.h" #include "dolphin/os.h" -extern OSHeapHandle currentHeapHandle; - static u32 HeapSizeTbl[5] = { 0x240000, 0x140000, 0xA80000, 0x580000, 0 }; static void *HeapTbl[5];