diff --git a/configure.py b/configure.py index 46ef767a..30b7cc23 100644 --- a/configure.py +++ b/configure.py @@ -334,8 +334,8 @@ config.libs = [ Object(Matching, "game/objmain.c"), Object(Matching, "game/fault.c"), Object(Matching, "game/gamework.c"), - Object(NonMatching, "game/objsysobj.c"), - Object(NonMatching, "game/objdll.c"), + Object(Matching, "game/objsysobj.c"), + Object(Matching, "game/objdll.c"), Object(Matching, "game/frand.c"), Object(Matching, "game/audio.c"), Object(Matching, "game/EnvelopeExec.c"), diff --git a/include/game/minigame_seq.h b/include/game/minigame_seq.h new file mode 100644 index 00000000..95a04e6e --- /dev/null +++ b/include/game/minigame_seq.h @@ -0,0 +1,21 @@ +#ifndef _GAME_MINIGAME_SEQ_H +#define _GAME_MINIGAME_SEQ_H + +#include "game/object.h" + +void MGSeqInit(void); +void MGSeqMain(void); +s16 MGSeqCreate(s16 type, ...); +u8 MGSeqStatGet(s16 id); +void MGSeqPosSet(s16 id, float x, float y); +void MGSeqParamSet(s16 id, s16 param1, s16 param2); +void MGSeqKill(s16 id); +void MGSeqKillAll(void); +s32 MGSeqDoneCheck(void); +void MGSeqStub(void); +void MGSeqPauseInit(void); +void MGSeqPauseEnableCtrl(s32 flag); +void MGSeqPracticeInit(void); +void MGSeqPracticeExitCheck(omObjData *object); + +#endif diff --git a/include/game/object.h b/include/game/object.h index 83b891f5..ecc9c99e 100644 --- a/include/game/object.h +++ b/include/game/object.h @@ -5,6 +5,8 @@ #include "game/process.h" #include "game/dvd.h" +#define OM_DLL_MAX 20 + #define OVL_DEFINE(name, path) name, typedef enum { @@ -55,6 +57,13 @@ typedef struct om_obj_data { /* 0x5C */ void *data; } omObjData; +typedef struct om_dll_data { + char *name; + OSModuleHeader *module; + void *bss; + s32 ret; +} omDllData; + void omMasterInit(int prio, FileListEntry *ovl_list, int ovl_count, OverlayID start_ovl); void omOvlCallEx(OverlayID overlay, s16 arg2, int event, int stat); void omOvlGotoEx(OverlayID overlay, s16 arg2, int event, int stat); @@ -83,8 +92,14 @@ OverlayID omCurrentOvlGet(void); void omDLLDBGOut(void); void omDLLInit(FileListEntry *ovl_list); -int omDLLStart(s16 ovl, s16 dll); -void omDLLNumEnd(s16 ovl, s16 arg2); +int omDLLStart(s16 overlay, s16 flag); +void omDLLNumEnd(s16 overlay, s16 flag); +void omDLLEnd(s16 dllno, s16 flag); +omDllData *omDLLLink(omDllData **dll_ptr, s16 overlay, s16 flag); +void omDLLUnlink(omDllData *dll_ptr, s16 flag); +s32 omDLLSearch(s16 overlay); +void omDLLInfoDump(OSModuleInfo *module); +void omDLLHeaderDump(OSModuleHeader *module); void omSysPauseEnable(u8 flag); @@ -102,7 +117,9 @@ extern int omovlstat; extern char omUPauseFlag; extern s16 omSysExitReq; extern s16 omdispinfo; -extern char omSysPauseEnableFlag; +extern u8 omSysPauseEnableFlag; extern OverlayID omprevovl; +extern omDllData *omDLLinfoTbl[OM_DLL_MAX]; + #endif \ No newline at end of file diff --git a/src/game/minigame_seq.c b/src/game/minigame_seq.c index a4a7f58a..dc8d41cd 100644 --- a/src/game/minigame_seq.c +++ b/src/game/minigame_seq.c @@ -8,6 +8,7 @@ #include "game/window.h" #include "game/wipe.h" #include "game/pad.h" +#include "game/minigame_seq.h" #include "math.h" @@ -18,10 +19,6 @@ #define ABS(x) (((x) < 0) ? -(x) : (x)) -void MGSeqStub(void); - -void MGSeqPauseEnableCtrl(s32 flag); - extern s16 HuSysVWaitGet(s16 param); typedef struct seq_work SeqWork; @@ -329,7 +326,7 @@ void MGSeqParamSet(s16 id, s16 param1, s16 param2) } } -void MGSeqKill(s16 id, s16 param1, s16 param2) +void MGSeqKill(s16 id) { if(id >= 0 && id < 8) { if(seqWorkData[id].stat != 0) { @@ -338,7 +335,7 @@ void MGSeqKill(s16 id, s16 param1, s16 param2) } } -void MGSeqKillAll(s16 id, s16 param1, s16 param2) +void MGSeqKillAll(void) { seqDoneF = 1; MGSeqMain(); @@ -3170,7 +3167,6 @@ static int SeqUpdateRecord(SeqWork *work) } } } - if(seqDoneF || (work->stat & 0x8)) { MGSeqSprKill(work); return 0; diff --git a/src/game/objdll.c b/src/game/objdll.c new file mode 100644 index 00000000..067bee54 --- /dev/null +++ b/src/game/objdll.c @@ -0,0 +1,172 @@ +#include "game/object.h" +#include "game/dvd.h" +#include "game/memory.h" + +typedef s32 (*DLLProlog)(void); +typedef void (*DLLEpilog)(void); + +omDllData *omDLLinfoTbl[OM_DLL_MAX]; + +static FileListEntry *omDLLFileList; + +void omDLLDBGOut(void) +{ + OSReport("DLL DBG OUT\n"); +} + +void omDLLInit(FileListEntry *ovl_list) +{ + int i; + OSReport("DLL DBG OUT\n"); + for(i=0; i= 0 && !flag) { + omDllData *dll = omDLLinfoTbl[dllno]; + OSReport("objdll>Already Loaded %s(%08x %08x)\n", dll->name, dll->module, dll->bss); + + omDLLInfoDump(&dll->module->info); + omDLLHeaderDump(dll->module); + memset(dll->bss, 0, dll->module->bssSize); + HuMemDCFlushAll(); + dll->ret = ((DLLProlog)dll->module->prolog)(); + OSReport("objdll> %s prolog end\n", dll->name); + return dllno; + } else { + for(dllno=0; dllnoomDLLNumEnd Invalid dllno %d\n", overlay); + return; + } + OSReport("objdll>omDLLNumEnd %d %d\n", overlay, flag); + dllno = omDLLSearch(overlay); + if(dllno < 0) { + OSReport("objdll>omDLLNumEnd not found DLL No%d\n", overlay); + return; + } + omDLLEnd(dllno, flag); +} + +void omDLLEnd(s16 dllno, s16 flag) +{ + OSReport("objdll>omDLLEnd %d %d\n", dllno, flag); + if(flag == 1) { + OSReport("objdll>End DLL:%s\n", omDLLinfoTbl[dllno]->name); + omDLLUnlink(omDLLinfoTbl[dllno], 1); + omDLLinfoTbl[dllno] = NULL; + } else { + omDllData *dll; + dll = omDLLinfoTbl[dllno]; + OSReport("objdll>Call Epilog\n"); + ((DLLEpilog)dll->module->epilog)(); + OSReport("objdll>End DLL stayed:%s\n", omDLLinfoTbl[dllno]->name); + } + OSReport("objdll>End DLL finish\n"); +} + +omDllData *omDLLLink(omDllData **dll_ptr, s16 overlay, s16 flag) +{ + omDllData *dll; + FileListEntry *dllFile = &omDLLFileList[overlay]; + OSReport("objdll>Link DLL:%s\n", dllFile->name); + dll = HuMemDirectMalloc(HEAP_SYSTEM, sizeof(omDllData)); + *dll_ptr = dll; + dll->name = dllFile->name; + dll->module = HuDvdDataReadDirect(dllFile->name, HEAP_SYSTEM); + dll->bss = HuMemDirectMalloc(HEAP_SYSTEM, dll->module->bssSize); + if(OSLink(&dll->module->info, dll->bss) != TRUE) { + OSReport("objdll>++++++++++++++++ DLL Link Failed\n"); + } + omDLLInfoDump(&dll->module->info); + omDLLHeaderDump(dll->module); + OSReport("objdll>LinkOK %08x %08x\n", dll->module, dll->bss); + if(flag == 1) { + OSReport("objdll> %s prolog start\n", dllFile->name); + dll->ret = ((DLLProlog)dll->module->prolog)(); + OSReport("objdll> %s prolog end\n", dllFile->name); + } + return dll; +} + +void omDLLUnlink(omDllData *dll_ptr, s16 flag) +{ + OSReport("odjdll>Unlink DLL:%s\n", dll_ptr->name); + if(flag == 1) { + OSReport("objdll>Unlink DLL epilog\n"); + ((DLLEpilog)dll_ptr->module->epilog)(); + OSReport("objdll>Unlink DLL epilog finish\n"); + } + if(OSUnlink(&dll_ptr->module->info) != TRUE) { + OSReport("objdll>+++++++++++++++++ DLL Unlink Failed\n"); + } + HuMemDirectFree(dll_ptr->bss); + HuMemDirectFree(dll_ptr->module); + HuMemDirectFree(dll_ptr); +} + +s32 omDLLSearch(s16 overlay) +{ + s32 i; + FileListEntry *dllFile = &omDLLFileList[overlay]; + OSReport("Search:%s\n", dllFile->name); + for(i=0; iname, dllFile->name) == 0) { + OSReport("+++++++++++ Find%d: %s\n", i, dll->name); + return i; + } + } + return -1; +} + +void omDLLInfoDump(OSModuleInfo *module) +{ + OSReport("===== DLL Module Info dump ====\n"); + OSReport(" ID:0x%08x\n", module->id); + OSReport(" LinkPrev:0x%08x\n", module->link.prev); + OSReport(" LinkNext:0x%08x\n", module->link.next); + OSReport(" Section num:%d\n", module->numSections); + OSReport("Section info tbl ofst:0x%08x\n", module->sectionInfoOffset); + OSReport(" nameOffset:0x%08x\n", module->nameOffset); + OSReport(" nameSize:%d\n", module->nameSize); + OSReport(" version:0x%08x\n", module->version); + OSReport("===============================\n"); +} + +void omDLLHeaderDump(OSModuleHeader *module) +{ + OSReport("==== DLL Module Header dump ====\n"); + OSReport(" bss Size:0x%08x\n", module->bssSize); + OSReport(" rel Offset:0x%08x\n", module->relOffset); + OSReport(" imp Offset:0x%08x\n", module->impOffset); + OSReport(" prolog Section:%d\n", module->prologSection); + OSReport(" epilog Section:%d\n", module->epilogSection); + OSReport("unresolved Section:%d\n", module->unresolvedSection); + OSReport(" prolog func:0x%08x\n", module->prolog); + OSReport(" epilog func:0x%08x\n", module->epilog); + OSReport(" unresolved func:0x%08x\n", module->unresolved); + OSReport("================================\n"); +} \ No newline at end of file diff --git a/src/game/objmain.c b/src/game/objmain.c index 5712f4d5..4cd4a998 100644 --- a/src/game/objmain.c +++ b/src/game/objmain.c @@ -45,7 +45,7 @@ s16 omdispinfo; static omOvlHisData omovlhis[OM_OVL_HIS_MAX]; -char omSysPauseEnableFlag = TRUE; +u8 omSysPauseEnableFlag = TRUE; OverlayID omprevovl = OVL_INVALID; static void omWatchOverlayProc(void); diff --git a/src/game/objsysobj.c b/src/game/objsysobj.c new file mode 100644 index 00000000..478db6ef --- /dev/null +++ b/src/game/objsysobj.c @@ -0,0 +1,149 @@ +#include "game/object.h" +#include "game/hsfman.h" +#include "game/pad.h" +#include "game/objsub.h" +#include "game/minigame_seq.h" +#include "game/sprite.h" +#include "game/hsfman.h" +#include "game/audio.h" +#include "math.h" + +Vec CRot; +Vec Center; +float CZoom; +Vec CRotM[16]; +Vec CenterM[16]; +float CZoomM[16]; + +omObjData *omDBGMenuButton; + +void omOutView(omObjData *object) +{ + Vec pos, target, up; + float rot_x = CRot.x; + float rot_y = CRot.y; + float rot_z = CRot.z; + pos.x = (sin(M_PI*rot_y/180.0)*cos(M_PI*rot_x/180.0)*CZoom)+Center.x; + pos.y = (-sin(M_PI*rot_x/180.0)*CZoom)+Center.y; + pos.z = (cos(M_PI*rot_y/180.0)*cos(M_PI*rot_x/180.0)*CZoom)+Center.z; + target.x = Center.x; + target.y = Center.y; + target.z = Center.z; + up.x = sin(M_PI*rot_y/180.0)*sin(M_PI*rot_x/180.0); + up.y = cos(M_PI*rot_x/180.0); + up.z = cos(M_PI*rot_y/180.0)*sin(M_PI*rot_x/180.0); + Hu3DCameraPosSet(1, pos.x, pos.y, pos.z, up.x, up.y, up.z, target.x, target.y, target.z); +} + +void omOutViewMulti(omObjData *object) +{ + u8 i; + for(i=0; iwork[0]; i++) { + Vec pos, target, up; + float rot_x = CRotM[i].x; + float rot_y = CRotM[i].y; + float rot_z = CRotM[i].z; + pos.x = (sin(M_PI*rot_y/180.0)*cos(M_PI*rot_x/180.0)*CZoomM[i])+CenterM[i].x; + pos.y = (-sin(M_PI*rot_x/180.0)*CZoomM[i])+CenterM[i].y; + pos.z = (cos(M_PI*rot_y/180.0)*cos(M_PI*rot_x/180.0)*CZoomM[i])+CenterM[i].z; + target.x = CenterM[i].x; + target.y = CenterM[i].y; + target.z = CenterM[i].z; + up.x = sin(M_PI*rot_y/180.0)*sin(M_PI*rot_x/180.0); + up.y = cos(M_PI*rot_x/180.0); + up.z = cos(M_PI*rot_y/180.0)*sin(M_PI*rot_x/180.0); + Hu3DCameraPosSetV((1 << i), &pos, &up, &target); + } +} + +void omSystemKeyCheck(omObjData *object); + +void omSystemKeyCheckSetup(Process *objman) +{ + omObjData *object; + object = omAddObjEx(objman, 32731, 0, 0, -1, omSystemKeyCheck); + omDBGSysKeyObj = object; + omSetStatBit(object, 0xA0); + object->work[0] = 0; + object->work[1] = 0; + object->work[2] = 0; +} + +void omSystemKeyCheck(omObjData *object) +{ + if(!omSysPauseEnableFlag) { + return; + } + if(object->work[0] & 0x1) { + u32 pad = object->work[1]; + if(pad != (u16)-1 && HuPadStatGet(pad) == 0 && (HuPadBtnDown[pad] & PAD_BUTTON_START)) { + object->work[0] |= 0x200; + } + if(object->work[0] & 0x200) { + if(omMgIndexGet(omcurovl) != -1) { + MGSeqPauseKill(); + } else { + object->work[0] |= 0x100; + } + } + if(object->work[0] & 0x100) { + object->work[0] &= ~0x301; + omAllPause(0); + HuPrcAllPause(0); + Hu3DPauseSet(0); + HuSprPauseSet(0); + HuAudFXPauseAll(0); + HuAudSeqPauseAll(0); + } + } else { + int i; + s16 pause = 0; + if(WipeStatGet() || omCurrentOvlGet() == OVL_INVALID || omSysExitReq) { + return; + } + for(i=0; i<4; i++) { + if(HuPadStatGet(i) == 0 && (HuPadBtnDown[i] & PAD_BUTTON_START)) { + pause = 1; + break; + } + } + if(object->work[0] & 0x80) { + object->work[0] &= ~0x80; + pause = 1; + i = (u16)-1; + } + if(pause) { + object->work[0] |= 0x1; + object->work[1] = i; + omAllPause(1); + HuPrcAllPause(1); + Hu3DPauseSet(1); + HuSprPauseSet(1); + HuAudFXPauseAll(1); + HuAudSeqPauseAll(1); + if(omMgIndexGet(omcurovl) != -1) { + MGSeqPauseInit(); + } + HuPadRumbleAllStop(); + } + } +} + + +void omSysPauseEnable(u8 flag) +{ + omSysPauseEnableFlag = flag; +} + +void omSysPauseCtrl(s16 flag) +{ + if(!omDBGSysKeyObj) { + return; + } + omDBGSysKeyObj->work[0] &= ~0x180; + if(flag) { + omDBGSysKeyObj->work[0] |= 0x80; + } else { + omDBGSysKeyObj->work[0] |= 0x100; + } +} \ No newline at end of file