From 14918e187ebb0eb7c688931df81b253f226ccf3e Mon Sep 17 00:00:00 2001 From: dbalatoni13 <40299962+dbalatoni13@users.noreply.github.com> Date: Wed, 2 Apr 2025 08:11:55 +0200 Subject: [PATCH] Dvd and some progress --- .gitignore | 9 ++ .vscode/settings.json | 61 +------- CMakeLists.txt | 4 +- src/game/init.c | 334 +++++++++++++++++++++--------------------- src/game/main.c | 4 +- src/port/dvd.c | 149 +++++++++++++++++++ src/port/stubs.c | 20 +++ 7 files changed, 352 insertions(+), 229 deletions(-) create mode 100644 src/port/dvd.c diff --git a/.gitignore b/.gitignore index c8875b51..a23cdeee 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,12 @@ compile_commands.json # Miscellaneous /*.txt *.exe + +.clang-format +tools/ +*.svg +main.s +decompiled.c +debug_source.c +decompiled_common.c +build_iso.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 1e7df332..dcf6fec4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -83,63 +83,4 @@ "compile_commands.json": true }, "cmake.ignoreCMakeListsMissing": true, - "editor.fontFamily": "Fira Code", - "editor.fontLigatures": true, - "C_Cpp_Runner.cCompilerPath": "gcc", - "C_Cpp_Runner.cppCompilerPath": "g++", - "C_Cpp_Runner.debuggerPath": "gdb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wcast-align", - "-Wconversion", - "-Wsign-conversion", - "-Wnull-dereference" - ], - "C_Cpp_Runner.msvcWarnings": [ - "/W4", - "/permissive-", - "/w14242", - "/w14287", - "/w14296", - "/w14311", - "/w14826", - "/w44062", - "/w44242", - "/w14905", - "/w14906", - "/w14263", - "/w44265", - "/w14928" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.useUndefinedSanitizer": false, - "C_Cpp_Runner.useLeakSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false -} \ No newline at end of file +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c723aca..c2948344 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(extern/aurora EXCLUDE_FROM_ALL) add_subdirectory(extern/musyx EXCLUDE_FROM_ALL) set(DOLPHIN_FILES + # libraries/dolphin_pc/GX.c # libraries/dolphin_pc/vi.c # libraries/dolphin_pc/pad_evdev.c @@ -24,11 +25,12 @@ set(DOLPHIN_FILES set(GAME_FILES src/game/main.c - # src/game/init.c + src/game/init.c ) set(PORT_FILES # src/port/byteswap.cpp + src/port/dvd.c src/port/imgui.cpp src/port/stubs.c ) diff --git a/src/game/init.c b/src/game/init.c index 8fcc7b8b..59e2fe05 100644 --- a/src/game/init.c +++ b/src/game/init.c @@ -54,6 +54,7 @@ void HuSysInit(GXRenderModeObj *mode) VISetWindowTitle("Mario Party 4"); #endif PADInit(); + #if !TARGET_PC #if VERSION_NTSC if(OSGetProgressiveMode() == 1 && VIGetDTVStatus() == 1) { mode = &GXNtsc480Prog; @@ -61,28 +62,29 @@ void HuSysInit(GXRenderModeObj *mode) #else mode->efbHeight = 480; #endif - InitRenderMode(mode); - InitMem(); - VIConfigure(RenderMode); - #if VERSION_NTSC - VIConfigurePan(0, 0, 640, 480); #endif - DefaultFifo = OSAlloc(0x100000); - DefaultFifoObj = GXInit(DefaultFifo, 0x100000); - InitGX(); - InitVI(); - HuFaultInitXfbDirectDraw(RenderMode); - HuFaultSetXfbAddress(0, DemoFrameBuffer1); - HuFaultSetXfbAddress(1, DemoFrameBuffer2); - HuDvdErrDispInit(RenderMode, DemoFrameBuffer1, DemoFrameBuffer2); - rnd_temp = frand(); - HuMemInitAll(); - HuAudInit(); - HuARInit(); - minimumVcount = minimumVcountf = 1.0f; - worstVcount = 0; - OSInitFastCast(); - HuCardInit(); + InitRenderMode(mode); + InitMem(); + // VIConfigure(RenderMode); + // #if VERSION_NTSC + // VIConfigurePan(0, 0, 640, 480); + // #endif + // DefaultFifo = OSAlloc(0x100000); + // DefaultFifoObj = GXInit(DefaultFifo, 0x100000); + // InitGX(); + // InitVI(); + // HuFaultInitXfbDirectDraw(RenderMode); + // HuFaultSetXfbAddress(0, DemoFrameBuffer1); + // HuFaultSetXfbAddress(1, DemoFrameBuffer2); + // HuDvdErrDispInit(RenderMode, DemoFrameBuffer1, DemoFrameBuffer2); + // rnd_temp = frand(); + // HuMemInitAll(); + // HuAudInit(); + // HuARInit(); + // minimumVcount = minimumVcountf = 1.0f; + // worstVcount = 0; + // OSInitFastCast(); + // HuCardInit(); } static void InitRenderMode(GXRenderModeObj *mode) @@ -136,169 +138,169 @@ static void InitGX() static void InitMem() { - void *arena_lo = OSGetArenaLo(); - void *arena_hi = OSGetArenaHi(); - u32 fb_size = (u16)(((u16)RenderMode->fbWidth+15) & ~15)*RenderMode->xfbHeight*2; - u32 *fb1; - u32 *fb2; - u32 i; - DemoFrameBuffer1 = (void *)OSRoundUp32B((u32)arena_lo); - DemoFrameBuffer2 = (void *)OSRoundUp32B((u32)DemoFrameBuffer1+fb_size); - DemoCurrentBuffer = DemoFrameBuffer2; - #if VERSION_PAL - fb1 = DemoFrameBuffer1; - fb2 = DemoFrameBuffer2; - for(i=0; ifbWidth+15) & ~15)*RenderMode->xfbHeight*2; +// u32 *fb1; +// u32 *fb2; +// u32 i; +// DemoFrameBuffer1 = (void *)OSRoundUp32B((u32)arena_lo); +// DemoFrameBuffer2 = (void *)OSRoundUp32B((u32)DemoFrameBuffer1+fb_size); +// DemoCurrentBuffer = DemoFrameBuffer2; +// #if VERSION_PAL +// fb1 = DemoFrameBuffer1; +// fb2 = DemoFrameBuffer2; +// for(i=0; iviTVmode & 0x1; - if(interlace) { - VIWaitForRetrace(); - } +// u32 interlace; +// VISetNextFrameBuffer(DemoFrameBuffer1); +// DemoCurrentBuffer = DemoFrameBuffer2; +// VIFlush(); +// VIWaitForRetrace(); +// interlace = RenderMode->viTVmode & 0x1; +// if(interlace) { +// VIWaitForRetrace(); +// } } void HuSysBeforeRender() { - if(RenderMode->field_rendering) { - GXSetViewportJitter(0, 0, RenderMode->fbWidth, RenderMode->xfbHeight, 0, 1, VIGetNextField()); - } else { - GXSetViewport(0, 0, RenderMode->fbWidth, RenderMode->xfbHeight, 0, 1); - } - GXInvalidateVtxCache(); - GXInvalidateTexAll(); +// if(RenderMode->field_rendering) { +// GXSetViewportJitter(0, 0, RenderMode->fbWidth, RenderMode->xfbHeight, 0, 1, VIGetNextField()); +// } else { +// GXSetViewport(0, 0, RenderMode->fbWidth, RenderMode->xfbHeight, 0, 1); +// } +// GXInvalidateVtxCache(); +// GXInvalidateTexAll(); } 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() { - u32 size; - u32 copy_size; - u32 offset; - u32 entries; - u32 i; - void *arena_lo; - void *arena_hi; - void *alloc_max; - void *alloc_min; - - struct memory_info *buf_ptr; - DVDFileInfo file; - char buf[240]; - - OSReport("\nNow, try to find memory info file...\n\n"); - if(!DVDOpen("/meminfo.bin", &file)) { - OSReport("\nCan't find memory info file. Use /XXX toolname/ to maximize available\n"); - OSReport("memory space. For now, we only use the first %dMB.\n", (OSGetConsoleSimulatedMemSize()/1024)/1024); - arena_lo = OSGetArenaLo(); - arena_hi = OSGetArenaHi(); - arena_lo = OSInitAlloc(arena_lo, arena_hi, 1); - OSSetArenaLo(arena_lo); - arena_lo = (void *)OSRoundUp32B((u32)arena_lo); - arena_hi = (void *)OSRoundDown32B((u32)arena_hi); - OSSetCurrentHeap(OSCreateHeap(arena_lo, arena_hi)); - arena_lo = arena_hi; - OSSetArenaLo(arena_lo); - } else { - buf_ptr = (struct memory_info *)OSRoundUp32B((u32)buf); - alloc_max = OSGetArenaHi(); - alloc_min = (void *)(OSGetConsoleSimulatedMemSize()+0x80000000); - OSSetArenaHi((void *)(OSGetPhysicalMemSize()+0x80000000)); - arena_lo = OSGetArenaLo(); - arena_hi = OSGetArenaHi(); - arena_lo = OSInitAlloc(arena_lo, arena_hi, 1); - OSSetArenaLo(arena_lo); - arena_lo = (void *)OSRoundUp32B((u32)arena_lo); - arena_hi = (void *)OSRoundDown32B((u32)arena_hi); - OSSetCurrentHeap(OSCreateHeap(arena_lo, arena_hi)); - arena_lo = arena_hi; - OSSetArenaLo(arena_lo); - OSAllocFixed(&alloc_max, &alloc_min); - size = file.length; - offset = 0; - while(size) { - OSReport("loop\n"); - copy_size = (size < 32) ? size : 32; - if(DVDRead(&file, buf_ptr, OSRoundUp32B(copy_size), offset) < 0) { - OSPanic("init.c", ASSERT_LINE(576, 586), "An error occurred when issuing read to /meminfo.bin\n"); - } - entries = copy_size/sizeof(struct memory_info); - for(i=0; i +#include +#include +#include +#ifdef _WIN32 +#include +#include + +#else +#include +#endif +#include + +#ifndef PATH_MAX +#define PATH_MAX 256 +#endif + +static char (*s_pathEntries)[PATH_MAX] = NULL; +static int s_pathEntriesCount = 0; +static char s_rootDir[PATH_MAX]; + +void DVDInit(void) +{ + chdir("GMPE01_00/files"); + if (getcwd(s_rootDir, sizeof(s_rootDir)) == NULL) + exit(1); +} + +BOOL DVDChangeDir(char *dir) +{ + printf("DVDChangeDir: %s\n", dir); + if (dir[0] == '/') { + char path[PATH_MAX]; + if (snprintf(path, sizeof(path), "%s/%s", s_rootDir, dir) >= PATH_MAX) + return FALSE; + return chdir(path) == 0; + } + else + return chdir(dir) == 0; +} + +s32 DVDConvertPathToEntrynum(char *pathPtr) +{ + int i; + FILE *f; + char absolute[PATH_MAX]; + + printf("DVDConvertPathToEntrynum: %s\n", pathPtr); +#ifdef _WIN32 + if (GetFullPathNameA(pathPtr, sizeof(absolute), absolute, NULL) == 0) + return -1; +#else + if (realpath(pathPtr, absolute) == NULL) + return -1; +#endif + for (i = 0; i < s_pathEntriesCount; i++) { + if (strcmp(absolute, s_pathEntries[i]) == 0) + return i; + } + + if (strlen(absolute) + 1 > PATH_MAX) + return -1; + + // check if file exists + f = fopen(absolute, "rb"); + if (f == NULL) + return -1; + fclose(f); + + // add new entry + printf("size = %i\n", sizeof(*s_pathEntries)); + s_pathEntries = realloc(s_pathEntries, (s_pathEntriesCount + 1) * sizeof(*s_pathEntries)); + strcpy(s_pathEntries[s_pathEntriesCount], absolute); + return s_pathEntriesCount++; +} + +BOOL DVDOpen(char *fileName, DVDFileInfo *fileInfo) +{ + FILE *f; + + printf("DVDOpen: %s\n", fileName); + f = fopen(fileName, "rb"); + if (f == NULL) { + puts("open failed\n"); + return FALSE; + } + fileInfo->cb.addr = f; + fseek(f, 0, SEEK_END); + fileInfo->length = ftell(f); + return TRUE; +} + +BOOL DVDFastOpen(s32 entrynum, DVDFileInfo *fileInfo) +{ + printf("DVDFastOpen: %li\n", entrynum); + if (entrynum < s_pathEntriesCount) + return DVDOpen(s_pathEntries[entrynum], fileInfo); + return FALSE; +} + +BOOL DVDClose(DVDFileInfo *fileInfo) +{ + FILE *f = fileInfo->cb.addr; + + if (f != NULL) + fclose(f); + fileInfo->cb.addr = NULL; + return TRUE; +} + +BOOL DVDReadAsyncPrio(DVDFileInfo *fileInfo, void *addr, s32 length, s32 offset, DVDCallback callback, s32 prio) +{ + FILE *f = fileInfo->cb.addr; + BOOL success; + + printf("DVDReadAsyncPrio: length %li, offset %li\n", length, offset); + fseek(f, offset, SEEK_SET); + success = (fread(addr, length, 1, f) == 1) || feof(f); + if (!success) + puts("read failed"); + callback(success ? 0 : -1, fileInfo); + return TRUE; +} + +BOOL DVDOpenDir(char *dirName, DVDDir *dir) +{ + puts("DVDOpenDir is a stub"); + return FALSE; +} + +BOOL DVDCloseDir(DVDDir *dir) +{ + puts("DVDCloseDir is a stub"); + return FALSE; +} + +BOOL DVDReadDir(DVDDir *dir, DVDDirEntry *dirent) +{ + puts("DVDReadDir is a stub"); + return FALSE; +} + +s32 DVDGetDriveStatus(void) +{ + // puts("DVDGetDriveStatus is a stub"); + return 0; +} diff --git a/src/port/stubs.c b/src/port/stubs.c index e69de29b..a6389fdc 100644 --- a/src/port/stubs.c +++ b/src/port/stubs.c @@ -0,0 +1,20 @@ +#include +#include +#include + +void OSInit() +{ + printf("OSInit is a stub\n"); +} + +void OSReport(const char *msg, ...) +{ + va_list args; + va_start(args, msg); + vprintf(msg, args); + va_end(args); +} + +void OSPanic(const char *file, int line, const char *msg, ...) { + printf("Panic in \"%s\" on line %d.\n", file, line); +}