Merge pull request #6 from gamemasterplc/main

Decompile process.c
This commit is contained in:
gamemasterplc 2023-11-23 10:27:32 -06:00 committed by GitHub
commit b6fda5e899
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 500 additions and 121 deletions

View file

@ -44,6 +44,12 @@ game/decode.c:
.data start:0x8011FDE0 end:0x8011FE00
.bss start:0x80145640 end:0x80145A40
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
@ -53,6 +59,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

View file

@ -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
@ -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

View file

@ -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"
@ -227,8 +229,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(Matching, "game/process.c"),
Object(NonMatching, "game/sprman.c"),
Object(NonMatching, "game/sprput.c"),
],

View file

@ -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 *first_child;
void *heap;
u16 exec;
u16 stat;
u16 prio;
s32 sleep_time;
u32 base_sp;
jmp_buf jump;
void (*dtor)(void);
void *user_data;
} Process;
typedef struct unkStruct1D3B44 {
struct unkStruct1D3B44 *prev;

View file

@ -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,26 @@ s32 HuMemUsedMemoryBlockGet(void *heap_ptr);
s32 HuMemMemoryAllocSizeGet(s32 size);
void HuMemHeapDump(void *heap_ptr, s16 status);
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);
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

51
src/game/printfunc.c Normal file
View file

@ -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;
}
}
}

357
src/game/process.c Normal file
View file

@ -0,0 +1,357 @@
#include "common.h"
#include "dolphin/os.h"
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;
static Process *processtop;
static Process *processcur;
static u16 processcnt;
u32 procfunc;
void HuPrcInit(void)
{
processcnt = 0;
processtop = 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;
}
}
}
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;
}
}
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);
if(!(heap = HuMemDirectMalloc(0, alloc_size))) {
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 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;
}
}
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);
}
}
}
Process *HuPrcCurrentGet()
{
return processcur;
}
static int SetKillStatusProcess(Process *process)
{
if(process->exec != EXEC_KILLED) {
HuPrcWakeup(process);
process->exec = EXEC_KILLED;
return 0;
} else {
return -1;
}
}
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(Process *process)
{
process->sleep_time = 0;
}
void HuPrcDestructorSet2(Process *process, void (*func)(void))
{
process->dtor = func;
}
void HuPrcDestructorSet(void (*func)(void))
{
Process *process = HuPrcCurrentGet();
process->dtor = func;
}
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(s32 size)
{
Process *process = HuPrcCurrentGet();
return HuMemMemoryAlloc(process->heap, size, 0xA5A5A5A5);
}
void HuPrcMemFree(void *ptr)
{
HuMemMemoryFree(ptr, 0xA5A5A5A5);
}
void HuPrcSetStat(Process *process, u16 value)
{
process->stat |= value;
}
void HuPrcResetStat(Process *process, u16 value)
{
process->stat &= ~value;
}
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(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;
}
}
}

View file

@ -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;
}
}