diff --git a/CMakeLists.txt b/CMakeLists.txt index ee8effb7..50aaa17c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ set(DOLPHIN_FILES ) set(GAME_FILES + src/game/card.c src/game/fault.c src/game/frand.c src/game/main.c diff --git a/include/game/process.h b/include/game/process.h index f2515e29..8d1b80f7 100644 --- a/include/game/process.h +++ b/include/game/process.h @@ -2,8 +2,13 @@ #define _GAME_PROCESS_H #include "dolphin/types.h" -#include "game/jmp.h" +#ifdef TARGET_PC +#include +typedef int JMPBUF; +#else +#include "game/jmp.h" +#endif #define PROCESS_STAT_PAUSE 0x1 #define PROCESS_STAT_UPAUSE 0x2 diff --git a/src/game/init.c b/src/game/init.c index 364b86f2..4a730fc8 100644 --- a/src/game/init.c +++ b/src/game/init.c @@ -79,12 +79,12 @@ void HuSysInit(GXRenderModeObj *mode) HuDvdErrDispInit(RenderMode, DemoFrameBuffer1, DemoFrameBuffer2); rnd_temp = frand(); HuMemInitAll(); - // HuAudInit(); - //HuARInit(); - // minimumVcount = minimumVcountf = 1.0f; - // worstVcount = 0; - // OSInitFastCast(); - // HuCardInit(); + HuAudInit(); + HuARInit(); + minimumVcount = minimumVcountf = 1.0f; + worstVcount = 0; + OSInitFastCast(); + HuCardInit(); } static void InitRenderMode(GXRenderModeObj *mode) @@ -199,44 +199,44 @@ void HuSysBeforeRender() void HuSysDoneRender(s32 retrace_count) { -// s32 retrace_dist; -// if(DemoStatEnable) { -// GXDrawDone(); -// DEMOUpdateStats(1); -// DEMOPrintStats(); -// GXDrawDone(); -// DEMOUpdateStats(0); -// } -// GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); -// GXSetColorUpdate(GX_TRUE); -// GXDrawDone(); -// GXCopyDisp(DemoCurrentBuffer, GX_TRUE); -// if(minimumVcount != 0) { -// retrace_dist = VIGetRetraceCount()-retrace_count; -// if(worstVcount < retrace_dist) { -// worstVcount = retrace_dist; -// } -// while(VIGetRetraceCount()-retrace_count < minimumVcount-1) { -// VIWaitForRetrace(); -// } -// } -// SwapBuffers(); + s32 retrace_dist; + if(DemoStatEnable) { + GXDrawDone(); + DEMOUpdateStats(1); + DEMOPrintStats(); + GXDrawDone(); + DEMOUpdateStats(0); + } + GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); + GXSetColorUpdate(GX_TRUE); + GXDrawDone(); + GXCopyDisp(DemoCurrentBuffer, GX_TRUE); + if(minimumVcount != 0) { + retrace_dist = VIGetRetraceCount()-retrace_count; + if(worstVcount < retrace_dist) { + worstVcount = retrace_dist; + } + while(VIGetRetraceCount()-retrace_count < minimumVcount-1) { + VIWaitForRetrace(); + } + } + SwapBuffers(); } static void SwapBuffers() { -// VISetNextFrameBuffer(DemoCurrentBuffer); -// if(FirstFrame) { -// VISetBlack(GX_FALSE); -// FirstFrame = FALSE; -// } -// VIFlush(); -// VIWaitForRetrace(); -// if(DemoCurrentBuffer == DemoFrameBuffer1) { -// DemoCurrentBuffer = DemoFrameBuffer2; -// } else { -// DemoCurrentBuffer = DemoFrameBuffer1; -// } + VISetNextFrameBuffer(DemoCurrentBuffer); + if(FirstFrame) { + VISetBlack(GX_FALSE); + FirstFrame = FALSE; + } + VIFlush(); + VIWaitForRetrace(); + if(DemoCurrentBuffer == DemoFrameBuffer1) { + DemoCurrentBuffer = DemoFrameBuffer2; + } else { + DemoCurrentBuffer = DemoFrameBuffer1; + } } static void LoadMemInfo() diff --git a/src/game/main.c b/src/game/main.c index c56ab575..c8119734 100644 --- a/src/game/main.c +++ b/src/game/main.c @@ -1,20 +1,20 @@ -#include "game/gamework_data.h" -#include "game/dvd.h" -#include "game/printfunc.h" -#include "game/object.h" -#include "game/wipe.h" -#include "game/init.h" -#include "game/process.h" -#include "game/pad.h" #include "game/data.h" -#include "game/sprite.h" +#include "game/dvd.h" +#include "game/gamework.h" +#include "game/gamework_data.h" #include "game/hsfformat.h" #include "game/hsfman.h" +#include "game/init.h" #include "game/minigame_seq.h" #include "game/msm.h" +#include "game/object.h" +#include "game/pad.h" #include "game/perf.h" -#include "game/gamework.h" +#include "game/printfunc.h" +#include "game/process.h" +#include "game/sprite.h" #include "game/sreset.h" +#include "game/wipe.h" #ifdef TARGET_PC #include "port/imgui.h" @@ -53,29 +53,27 @@ void aurora_log_callback(AuroraLogLevel level, const char *message, unsigned int { const char *levelStr = "??"; FILE *out = stdout; - switch (level) - { - case LOG_DEBUG: - levelStr = "DEBUG"; - break; - case LOG_INFO: - levelStr = "INFO"; - break; - case LOG_WARNING: - levelStr = "WARNING"; - break; - case LOG_ERROR: - levelStr = "ERROR"; - out = stderr; - break; - case LOG_FATAL: - levelStr = "FATAL"; - out = stderr; - break; + switch (level) { + case LOG_DEBUG: + levelStr = "DEBUG"; + break; + case LOG_INFO: + levelStr = "INFO"; + break; + case LOG_WARNING: + levelStr = "WARNING"; + break; + case LOG_ERROR: + levelStr = "ERROR"; + out = stderr; + break; + case LOG_FATAL: + levelStr = "FATAL"; + out = stderr; + break; } fprintf(out, "[%s: %s]\n", levelStr, message); - if (level == LOG_FATAL) - { + if (level == LOG_FATAL) { fflush(out); abort(); } @@ -83,72 +81,69 @@ void aurora_log_callback(AuroraLogLevel level, const char *message, unsigned int #endif #ifdef TARGET_PC -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) #else void main(void) #endif { #ifdef TARGET_PC const AuroraInfo auroraInfo = aurora_initialize(argc, argv, - &(AuroraConfig){ - .appName = "Mario Party 4", - .logCallback = &aurora_log_callback, - }); + &(AuroraConfig) { + .appName = "Mario Party 4", + .logCallback = &aurora_log_callback, + }); #endif u32 met0; u32 met1; s16 i; s32 retrace; - #if VERSION_PAL +#if VERSION_PAL s16 temp = 0; - #endif - +#endif + HuDvdErrWait = 0; SystemInitF = 0; - #if VERSION_NTSC +#if VERSION_NTSC HuSysInit(&GXNtsc480IntDf); - #else +#else HuSysInit(&GXPal528IntDf); - #endif - /*HuPrcInit(); - HuPadInit(); - GWInit(); - pfInit(); - GlobalCounter = 0; - HuSprInit(); - Hu3DInit(); - HuDataInit(); - HuPerfInit(); - HuPerfCreate("USR0", 0xFF, 0xFF, 0xFF, 0xFF); - HuPerfCreate("USR1", 0, 0xFF, 0xFF, 0xFF); - WipeInit(RenderMode); - +#endif + //HuPrcInit(); + // HuPadInit(); + // GWInit(); + // pfInit(); + // GlobalCounter = 0; + // HuSprInit(); + // Hu3DInit(); + // HuDataInit(); + // HuPerfInit(); + // HuPerfCreate("USR0", 0xFF, 0xFF, 0xFF, 0xFF); + // HuPerfCreate("USR1", 0, 0xFF, 0xFF, 0xFF); + // WipeInit(RenderMode); + for (i = 0; i < 4; i++) { - GWPlayerCfg[i].character = -1; + // GWPlayerCfg[i].character = -1; } - - omMasterInit(0, _ovltbl, OVL_COUNT, OVL_BOOT); + + //omMasterInit(0, _ovltbl, OVL_COUNT, OVL_BOOT); VIWaitForRetrace(); - + if (VIGetNextField() == 0) { OSReport("VI_FIELD_BELOW\n"); VIWaitForRetrace(); - }*/ + } while (1) { #ifdef TARGET_PC const AuroraEvent *event = aurora_update(); bool exiting = false; - while (event != NULL && event->type != AURORA_NONE) - { - if (event->type == AURORA_EXIT) - { + while (event != NULL && event->type != AURORA_NONE) { + if (event->type == AURORA_EXIT) { exiting = true; break; } ++event; } - if (exiting) - { + if (exiting) { break; } #endif @@ -156,35 +151,35 @@ void main(void) if (HuSoftResetButtonCheck() != 0 || HuDvdErrWait != 0) { continue; }*/ - //HuPerfZero(); + // HuPerfZero(); - //HuPerfBegin(2); + // HuPerfBegin(2); #ifdef TARGET_PC aurora_begin_frame(); #endif - /* HuSysBeforeRender(); - GXSetGPMetric(GX_PERF0_CLIP_VTX, GX_PERF1_VERTICES); - GXClearGPMetric(); - GXSetVCacheMetric(GX_VC_ALL); - GXClearVCacheMetric(); - GXClearPixMetric(); - GXClearMemMetric(); + /* HuSysBeforeRender(); + GXSetGPMetric(GX_PERF0_CLIP_VTX, GX_PERF1_VERTICES); + GXClearGPMetric(); + GXSetVCacheMetric(GX_VC_ALL); + GXClearVCacheMetric(); + GXClearPixMetric(); + GXClearMemMetric(); - HuPerfBegin(0); - Hu3DPreProc(); - HuPadRead(); - pfClsScr(); + HuPerfBegin(0); + Hu3DPreProc(); + HuPadRead(); + pfClsScr(); - HuPrcCall(1); - MGSeqMain(); - HuPerfBegin(1); - Hu3DExec(); - HuDvdErrorWatch(); - WipeExecAlways(); - HuPerfEnd(0); + HuPrcCall(1); + MGSeqMain(); + HuPerfBegin(1); + Hu3DExec(); + HuDvdErrorWatch(); + WipeExecAlways(); + HuPerfEnd(0); - pfDrawFonts(); - HuPerfEnd(1);*/ + pfDrawFonts(); + HuPerfEnd(1);*/ #ifdef TARGET_PC imgui_main(&auroraInfo); @@ -210,16 +205,16 @@ void main(void) #endif } -//void HuSysVWaitSet(s16 vcount) +// void HuSysVWaitSet(s16 vcount) //{ -// minimumVcount = vcount; -// minimumVcountf = vcount; -//} +// minimumVcount = vcount; +// minimumVcountf = vcount; +// } // -//s16 HuSysVWaitGet(s16 param) +// s16 HuSysVWaitGet(s16 param) //{ -// return (s16) minimumVcount; -//} +// return (s16) minimumVcount; +// } s32 rnd_seed = 0x0000D9ED; diff --git a/src/game/process.c b/src/game/process.c index ccb93970..cc13c72b 100644 --- a/src/game/process.c +++ b/src/game/process.c @@ -1,10 +1,14 @@ #include "game/process.h" #include "dolphin/os.h" +#include "game/jmp.h" #include "game/memory.h" - #define FAKE_RETADDR 0xA5A5A5A5 +#ifdef TARGET_PC +#include +#endif + #define EXEC_NORMAL 0 #define EXEC_SLEEP 1 #define EXEC_CHILDWATCH 2 @@ -81,9 +85,12 @@ Process *HuPrcCreate(void (*func)(void), u16 prio, u32 stack_size, s32 extra_siz process->prio = prio; process->sleep_time = 0; process->base_sp = ((u32)HuMemMemoryAlloc(heap, stack_size, FAKE_RETADDR)) + stack_size - 8; +#ifdef TARGET_PC +#else gcsetjmp(&process->jump); process->jump.lr = (u32)func; process->jump.sp = process->base_sp; +#endif process->dtor = NULL; process->user_data = NULL; LinkProcess(&processtop, process); @@ -133,9 +140,12 @@ void HuPrcChildWatch() Process *curr = HuPrcCurrentGet(); if (curr->child) { curr->exec = EXEC_CHILDWATCH; +#ifdef TARGET_PC +#else if (!gcsetjmp(&curr->jump)) { gclongjmp(&processjmpbuf, 1); } +#endif } } @@ -186,7 +196,10 @@ static void gcTerminateProcess(Process *process) } UnlinkProcess(&processtop, process); processcnt--; +#ifdef TARGET_PC +#else gclongjmp(&processjmpbuf, 2); +#endif } void HuPrcEnd() @@ -204,9 +217,12 @@ void HuPrcSleep(s32 time) process->exec = EXEC_SLEEP; process->sleep_time = time; } +#ifdef TARGET_PC +#else if (!gcsetjmp(&process->jump)) { gclongjmp(&processjmpbuf, 1); } +#endif } void HuPrcVSleep() @@ -235,7 +251,10 @@ void HuPrcCall(s32 tick) Process *process; s32 ret; processcur = processtop; +#ifdef TARGET_PC +#else ret = gcsetjmp(&processjmpbuf); +#endif while (1) { switch (ret) { case 2: @@ -255,7 +274,10 @@ void HuPrcCall(s32 tick) if (!process) { return; } +#ifdef TARGET_PC +#else procfunc = process->jump.lr; +#endif if ((process->stat & (PROCESS_STAT_PAUSE | PROCESS_STAT_UPAUSE)) && process->exec != EXEC_KILLED) { ret = 1; continue; @@ -283,9 +305,15 @@ void HuPrcCall(s32 tick) break; case EXEC_KILLED: +#ifdef TARGET_PC +#else process->jump.lr = (u32)HuPrcEnd; +#endif case EXEC_NORMAL: +#ifdef TARGET_PC +#else gclongjmp(&process->jump, 1); +#endif break; } } diff --git a/src/port/stubs.c b/src/port/stubs.c index e405d81b..d9c1ed60 100644 --- a/src/port/stubs.c +++ b/src/port/stubs.c @@ -24,6 +24,12 @@ s32 CARDCancel(CARDFileInfo *fileInfo) return 0; } +s32 CARDCheck(s32 chan) +{ + puts("CARDCheck is a stub"); + return 0; +} + s32 CARDCheckAsync(s32 chan, CARDCallback callback) { puts("CARDCheckAsync is a stub"); @@ -36,6 +42,12 @@ s32 CARDClose(CARDFileInfo *fileInfo) return 0; } +s32 CARDCreate(s32 chan, const char *fileName, u32 size, CARDFileInfo *fileInfo) +{ + puts("CARDCreate is a stub"); + return 0; +} + s32 CARDCreateAsync(s32 chan, const char *fileName, u32 size, CARDFileInfo *fileInfo, CARDCallback callback) { puts("CARDCreateAsync is a stub"); @@ -66,6 +78,12 @@ s32 CARDFastOpen(s32 chan, s32 fileNo, CARDFileInfo *fileInfo) return 0; } +s32 CARDFormat(s32 chan) +{ + puts("CARDFormat is a stub"); + return 0; +} + s32 CARDFreeBlocks(s32 chan, s32 *byteNotUsed, s32 *filesNotUsed) { puts("CARDFreeBlocks is a stub"); @@ -84,6 +102,12 @@ s32 CARDGetStatus(s32 chan, s32 fileNo, CARDStat *stat) return 0; } +s32 CARDGetSectorSize(s32 chan, u32 *size) +{ + puts("CARDGetSectorSize is a stub"); + return 0; +} + void CARDInit() { puts("CARDInit is a stub"); @@ -113,6 +137,12 @@ s32 CARDProbeEx(s32 chan, s32 *memSize, s32 *sectorSize) return 0; } +s32 CARDRead(CARDFileInfo *fileInfo, void *addr, s32 length, s32 offset) +{ + puts("CARDRead is a stub"); + return 0; +} + s32 CARDReadAsync(CARDFileInfo *fileInfo, void *addr, s32 length, s32 offset, CARDCallback callback) { puts("CARDReadAsync is a stub"); @@ -143,6 +173,12 @@ s32 CARDUnmount(s32 chan) return 0; } +s32 CARDWrite(CARDFileInfo *fileInfo, const void *addr, s32 length, s32 offset) +{ + puts("CARDWrite is a stub"); + return 0; +} + s32 CARDWriteAsync(CARDFileInfo *fileInfo, const void *addr, s32 length, s32 offset, CARDCallback callback) { puts("CARDWriteAsync is a stub"); @@ -175,6 +211,16 @@ void DCStoreRange(void *addr, u32 nBytes) puts("DCStoreRange is a stub"); } +void DEMOUpdateStats(unsigned char inc) +{ + puts("DEMOUpdateStats is a stub"); +} + +void DEMOPrintStats(void) +{ + puts("DEMOPrintStats is a stub"); +} + s32 DVDCancel(DVDCommandBlock *block) { puts("DVDCancel is a stub"); @@ -401,6 +447,12 @@ void VIConfigurePan(u16 xOrg, u16 yOrg, u16 width, u16 height) puts("VIConfigurePan is a stub"); } +u32 VIGetRetraceCount() +{ + puts("VIGetRetraceCount is a stub"); + return 0; // TODO this might be important +} + u32 VIGetNextField() { puts("VIGetNextField is a stub"); @@ -468,3 +520,5 @@ OSInterruptMask __OSUnmaskInterrupts(OSInterruptMask mask) // Hudson void HuDvdErrDispInit(GXRenderModeObj *rmode, void *xfb1, void *xfb2) { } +void HuAudInit() { } +void HuARInit() { }