From b397c886e755ef84911b34af99ad72668ac4f8d5 Mon Sep 17 00:00:00 2001 From: PJB3005 Date: Mon, 2 Mar 2026 14:27:20 +0100 Subject: [PATCH] Move some OS functionality to rely on Aurora --- CMakeLists.txt | 2 +- libs/JSystem/src/J3DGraphBase/J3DGD.cpp | 4 ++ src/dusk/stubs.cpp | 79 ------------------------- src/m_Do/m_Do_main.cpp | 13 +--- 4 files changed, 7 insertions(+), 91 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa728aff89..bdd458d5bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,7 @@ target_include_directories(game_debug PUBLIC extern/aurora/include/dolphin ${CMAKE_BINARY_DIR}/../${DUSK_TP_VERSION}/include build/${DUSK_TP_VERSION}/include) -target_link_libraries(game_debug PUBLIC aurora::core aurora::gx aurora::si aurora::vi aurora::pad aurora::mtx) +target_link_libraries(game_debug PUBLIC aurora::core aurora::gx aurora::si aurora::vi aurora::pad aurora::mtx aurora::os) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) add_library(game SHARED ${DOLZEL_FILES} ${Z2AUDIOLIB_FILES} ${SSYSTEM_FILES} ${JSYSTEM_FILES} ${REL_FILES} ${DUSK_FILES}) diff --git a/libs/JSystem/src/J3DGraphBase/J3DGD.cpp b/libs/JSystem/src/J3DGraphBase/J3DGD.cpp index de18c40798..3eea255cd0 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DGD.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DGD.cpp @@ -349,7 +349,11 @@ void J3DGDSetTexImgAttr(GXTexMapID id, u16 width, u16 height, GXTexFmt format) { } void J3DGDSetTexImgPtr(GXTexMapID id, void* image_ptr) { +#if TARGET_PC + puts("J3DGDSetTexImgPtr is a stub"); +#else J3DGDWriteBPCmd(BP_IMAGE_PTR(OSCachedToPhysical(image_ptr) >> 5, J3DGDTexImage3Ids[id])); +#endif } void J3DGDSetTexImgPtrRaw(GXTexMapID id, u32 image_ptr_raw) { diff --git a/src/dusk/stubs.cpp b/src/dusk/stubs.cpp index b967e8b4fd..eece4d356e 100644 --- a/src/dusk/stubs.cpp +++ b/src/dusk/stubs.cpp @@ -46,34 +46,6 @@ static bool PerfInitialized = false; // General OS // ========================================================================== - -// Credits: Super Monkey Ball - -static u64 GetGCTicks() { -#if __APPLE__ - return mach_absolute_time() * MachToDolphinNum / MachToDolphinDenom; -#elif __linux__ || __FreeBSD__ - struct timespec tp; - clock_gettime(CLOCK_MONOTONIC, &tp); - - return ((tp.tv_sec * 1000000000ull) + tp.tv_nsec) * OS_CORE_CLOCK / 1000000000ull; -#elif _WIN32 - if (!PerfInitialized) { - QueryPerformanceFrequency(&PerfFrequency); - PerfInitialized = true; - } - LARGE_INTEGER perf; - QueryPerformanceCounter(&perf); - - perf.QuadPart *= OS_CORE_CLOCK; - perf.QuadPart /= PerfFrequency.QuadPart; - - return perf.QuadPart; -#else - return 0; -#endif -} - u32 OSGetConsoleType() { return OS_CONSOLE_RETAIL1; } @@ -82,10 +54,6 @@ u32 OSGetSoundMode() { return 2; } -void OSInit() { - // Thread system is lazy-initialized via OSGetCurrentThread() -} - // ========================================================================== // Message Queue (thread-safe implementation) // ========================================================================== @@ -232,45 +200,6 @@ int OSJamMessage(OSMessageQueue* mq, void* msg, s32 flags) { // Arena Functions // ========================================================================== -static void* sArenaLo = nullptr; -static void* sArenaHi = nullptr; - -void* OSGetArenaHi(void) { - return sArenaHi; -} - -void* OSGetArenaLo(void) { - return sArenaLo; -} - -void OSSetArenaHi(void* newHi) { - sArenaHi = newHi; -} - -void OSSetArenaLo(void* newLo) { - sArenaLo = newLo; -} - -void* OSAllocFromArenaLo(u32 size, u32 align) { - if (!sArenaLo || !sArenaHi) return nullptr; - - uintptr_t lo = (uintptr_t)sArenaLo; - if (align > 0) { - lo = (lo + align - 1) & ~((uintptr_t)align - 1); - } - - uintptr_t hi = (uintptr_t)sArenaHi; - if (lo + size > hi) { - OSReport("[PC-Arena] OSAllocFromArenaLo: out of arena space (need %u, have %u)\n", - size, (u32)(hi - lo)); - return nullptr; - } - - void* result = (void*)lo; - sArenaLo = (void*)(lo + size); - return result; -} - void* OSInitAlloc(void* arenaStart, void* arenaEnd, int maxHeaps) { return arenaStart; } @@ -289,14 +218,6 @@ void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime* td) { if (td) memset(td, 0, sizeof(OSCalendarTime)); } -OSTime OSGetTime(void) { - return (OSTime)GetGCTicks(); -} - -OSTick OSGetTick(void) { - return (OSTick)GetGCTicks(); -} - u16 OSGetFontEncode() { return 0; } char* OSGetFontTexture(char* string, void** image, s32* x, s32* y, s32* width) { return 0; } diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 424e99c507..4919f8699e 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -231,19 +231,11 @@ int game_main(int argc, char* argv[]) { config.windowHeight = 480; config.configPath = "."; config.logCallback = &aurora_log_callback; + config.mem1Size = 256 * 1024 * 1024; auroraInfo = aurora_initialize(argc, argv, &config); - // 2. Setup Virtual Game RAM - // Simulates Gamecube RAM (24MB + Audio etc, we take 256MB) -#define GAME_RAM_SIZE (256 * 1024 * 1024) - void* virtualGameRam = calloc(1, GAME_RAM_SIZE); - if (!virtualGameRam) { - printf("Fatal: Failed to allocate game RAM\n"); - return -1; - } - OSSetArenaLo(virtualGameRam); - OSSetArenaHi((char*)virtualGameRam + GAME_RAM_SIZE); + OSInit(); // 3. Init DVD Emulation DvdEmu::setBasePath("data"); @@ -269,7 +261,6 @@ int game_main(int argc, char* argv[]) { main01(); aurora_shutdown(); - free(virtualGameRam); return 0; }