Dvd and some progress

This commit is contained in:
dbalatoni13 2025-04-02 08:11:55 +02:00
parent 1bd8f3e14e
commit 14918e187e
7 changed files with 352 additions and 229 deletions

9
.gitignore vendored
View file

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

61
.vscode/settings.json vendored
View file

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

View file

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

View file

@ -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; i<fb_size/4; i++, fb1++, fb2++) {
*fb1 = *fb2 = 0x800080;
}
DCStoreRangeNoSync(DemoFrameBuffer1, fb_size);
DCStoreRangeNoSync(DemoFrameBuffer2, fb_size);
#endif
arena_lo = (void *)OSRoundUp32B((u32)DemoFrameBuffer2+fb_size);
OSSetArenaLo(arena_lo);
if(OSGetConsoleType() == OS_CONSOLE_DEVHW1 && OSGetPhysicalMemSize() != 0x400000 && OSGetConsoleSimulatedMemSize() < 0x1800000) {
LoadMemInfo();
} else {
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(currentHeapHandle = OSCreateHeap(arena_lo, arena_hi));
arena_lo = arena_hi;
OSSetArenaLo(arena_lo);
}
// 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; i<fb_size/4; i++, fb1++, fb2++) {
// *fb1 = *fb2 = 0x800080;
// }
// DCStoreRangeNoSync(DemoFrameBuffer1, fb_size);
// DCStoreRangeNoSync(DemoFrameBuffer2, fb_size);
// #endif
// arena_lo = (void *)OSRoundUp32B((u32)DemoFrameBuffer2+fb_size);
// OSSetArenaLo(arena_lo);
// if(OSGetConsoleType() == OS_CONSOLE_DEVHW1 && OSGetPhysicalMemSize() != 0x400000 && OSGetConsoleSimulatedMemSize() < 0x1800000) {
// LoadMemInfo();
// } else {
// 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(currentHeapHandle = OSCreateHeap(arena_lo, arena_hi));
// arena_lo = arena_hi;
// OSSetArenaLo(arena_lo);
// }
}
static void InitVI()
{
u32 interlace;
VISetNextFrameBuffer(DemoFrameBuffer1);
DemoCurrentBuffer = DemoFrameBuffer2;
VIFlush();
VIWaitForRetrace();
interlace = RenderMode->viTVmode & 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<entries; i++) {
OSReport("start: 0x%08x, end: 0x%08x\n", buf_ptr[i].start, buf_ptr[i].end);
OSAllocFixed(&buf_ptr[i].start, &buf_ptr[i].end);
OSReport("Removed 0x%08x - 0x%08x from the current heap\n", buf_ptr[i].start, (u32)buf_ptr[i].end-1);
}
size -= copy_size;
offset += copy_size;
}
DVDClose(&file);
OSDumpHeap(__OSCurrHeap);
}
// 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<entries; i++) {
// OSReport("start: 0x%08x, end: 0x%08x\n", buf_ptr[i].start, buf_ptr[i].end);
// OSAllocFixed(&buf_ptr[i].start, &buf_ptr[i].end);
// OSReport("Removed 0x%08x - 0x%08x from the current heap\n", buf_ptr[i].start, (u32)buf_ptr[i].end-1);
// }
// size -= copy_size;
// offset += copy_size;
// }
// DVDClose(&file);
// OSDumpHeap(__OSCurrHeap);
// }
}

View file

@ -88,7 +88,7 @@ int main(int argc, char* argv[])
void main(void)
#endif
{
#ifdef AURORA
#ifdef TARGET_PC
const AuroraInfo auroraInfo = aurora_initialize(argc, argv,
&(AuroraConfig){
.appName = "Mario Party 4",
@ -106,7 +106,7 @@ void main(void)
HuDvdErrWait = 0;
SystemInitF = 0;
#if VERSION_NTSC
//HuSysInit(&GXNtsc480IntDf);
HuSysInit(&GXNtsc480IntDf);
#else
HuSysInit(&GXPal528IntDf);
#endif

149
src/port/dvd.c Normal file
View file

@ -0,0 +1,149 @@
// Credits: Super Monkey Ball
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <direct.h>
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <dolphin.h>
#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;
}

View file

@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdarg.h>
#include <types.h>
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);
}