Merge branch 'main' of https://github.com/Rainchus/mp4-dtk into main

This commit is contained in:
CreateSource 2023-11-23 14:05:26 -05:00
commit c7189d056b
14 changed files with 731 additions and 198 deletions

View file

@ -1,20 +1,164 @@
#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;
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 character[4];
int ext_character[4];
int i, cursor_pos;
for(i=0; i<4; i++) {
character[i] = gPlayerConfig[i].character;
ext_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(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[character[i]]);
}
}
if(GetBtns() & 0x1000) {
for(i=0; i<4; i++) {
if(ext_character[i] != 0) {
gPlayerConfig[i]. character = ext_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 {
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(ext_character[cursor_pos] == ext_character[i] && ext_character[cursor_pos] != 0) {
break;
}
}
}
} while(i < 4);
}
if(GetBtns() & 0x2) {
do {
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(ext_character[cursor_pos] == ext_character[i] && ext_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();
}
}

View file

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

View file

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

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

View file

@ -1,97 +1,356 @@
#include "common.h"
#include "dolphin/os.h"
extern unkStruct145A98 lbl_80145A98[0x100];
extern s32 debugFontColor;
extern s16 lbl_801D3B2C;
extern s16 lbl_801D3B2E;
extern s16 lbl_801D3B3C;
extern unkStruct1D3B44* lbl_801D3B44;
extern int gcsetjmp(jmp_buf *jump);
extern void gclongjmp(jmp_buf *jump, int status);
void fn_8000AEF0(void) {
s32 i;
#define EXEC_NORMAL 0
#define EXEC_SLEEP 1
#define EXEC_CHILDWATCH 2
#define EXEC_KILLED 3
debugFontColor = 0xF;
lbl_801D3B2E = 0;
for (i = 0; i < 0x100; i++) {
lbl_80145A98[i].unk_14 = 0;
}
fn_8000AF54();
static jmp_buf processjmpbuf;
static Process *processtop;
static Process *processcur;
static u16 processcnt;
u32 procfunc;
void HuPrcInit(void)
{
processcnt = 0;
processtop = NULL;
}
void fn_8000AF54(void) {
s32 i;
static void LinkProcess(Process** root, Process* process) {
Process* src_process = *root;
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;
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);
}
}
}
void HuPrcInit(void) {
lbl_801D3B3C = 0;
lbl_801D3B44 = NULL;
Process *HuPrcCurrentGet()
{
return processcur;
}
// ...
// HuPrcCall
// HuPrcMemAlloc
// HuPrcMemFree
void HuPrcSetStat(unkStruct1D3B44* arg0, u16 arg1) {
arg0->unk_1E |= arg1;
static int SetKillStatusProcess(Process *process)
{
if(process->exec != EXEC_KILLED) {
HuPrcWakeup(process);
process->exec = EXEC_KILLED;
return 0;
} else {
return -1;
}
}
void HuPrcResetStat(unkStruct1D3B44* arg0, s32 arg1) {
arg0->unk_1E &= ~arg1;
int HuPrcKill(Process *process)
{
if(process == NULL) {
process = HuPrcCurrentGet();
}
HuPrcChildKill(process);
HuPrcChildUnlink(process);
return SetKillStatusProcess(process);
}
void HuPrcAllPause(s32 arg0) {
unkStruct1D3B44* var_r31;
void HuPrcChildKill(Process *process)
{
Process *child = process->child;
while(child) {
if(child->child) {
HuPrcChildKill(child);
}
SetKillStatusProcess(child);
child = child->next_child;
}
process->child = NULL;
}
var_r31 = lbl_801D3B44;
if (arg0 != 0) {
while (var_r31 != NULL) {
if ((var_r31->unk_1E & 4) == 0) {
var_r31->unk_1E |= (u16) 1;
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);
}
var_r31 = var_r31->prev;
process = process->next;
}
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;
} else {
while(process != NULL) {
if(process->stat & 0x1) {
HuPrcResetStat(process, 0x1);
}
var_r31 = var_r31->prev;
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;
}
return;
}
while (var_r31 != NULL) {
if ((var_r31->unk_1E & 2) != 0) {
var_r31->unk_1E &= -3;
}
var_r31 = var_r31->prev;
}
}