From c92bef0352d1ca894e5c40d250b14218c97893c2 Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Thu, 19 Mar 2026 20:49:02 +0100 Subject: [PATCH] coreinit: Refactor OSScreen --- .../OS/libs/coreinit/coreinit_OSScreen.cpp | 74 +++++++------------ src/Cafe/OS/libs/coreinit/coreinit_OSScreen.h | 14 +++- 2 files changed, 38 insertions(+), 50 deletions(-) diff --git a/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.cpp b/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.cpp index 7b51629e..a0ee1ac2 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.cpp @@ -5,9 +5,6 @@ #include "Cafe/OS/libs/coreinit/coreinit_OSScreen_font.h" #include "Cafe/OS/libs/coreinit/coreinit_OSScreen.h" -#define OSSCREEN_TV (0) -#define OSSCREEN_DRC (1) - namespace coreinit { @@ -39,19 +36,16 @@ namespace coreinit } } - void coreinitExport_OSScreenInit(PPCInterpreter_t* hCPU) + void OSScreenInit() { // todo - init VI registers? - - osLib_returnFromFunction(hCPU, 0); } - void coreinitExport_OSScreenGetBufferSizeEx(PPCInterpreter_t* hCPU) + uint32 OSScreenGetBufferSizeEx(uint32 screenIndex) { - ppcDefineParamU32(screenIndex, 0); cemu_assert(screenIndex < 2); uint32 bufferSize = screenSizes[screenIndex].pitch * screenSizes[screenIndex].y * 4 * 2; - osLib_returnFromFunction(hCPU, bufferSize); + return bufferSize; } void _updateCurrentDrawScreen(sint32 screenIndex) @@ -64,59 +58,40 @@ namespace coreinit currentScreenBasePtr[screenIndex] = memory_getPointerFromPhysicalOffset(LatteGPUState.osScreen.screen[screenIndex].physPtr); } - void coreinitExport_OSScreenSetBufferEx(PPCInterpreter_t* hCPU) + void OSScreenSetBufferEx(uint32 screenIndex, uint32 buffer) { - ppcDefineParamU32(screenIndex, 0); - ppcDefineParamU32(buffer, 1); cemu_assert(screenIndex < 2); LatteGPUState.osScreen.screen[screenIndex].physPtr = buffer; _updateCurrentDrawScreen(screenIndex); - osLib_returnFromFunction(hCPU, 0); } - void coreinitExport_OSScreenEnableEx(PPCInterpreter_t* hCPU) + void OSScreenEnableEx(uint32 screenIndex, uint32 isEnabled) { - ppcDefineParamU32(screenIndex, 0); - ppcDefineParamU32(isEnabled, 1); cemu_assert(screenIndex < 2); LatteGPUState.osScreen.screen[screenIndex].isEnabled = isEnabled != 0; - osLib_returnFromFunction(hCPU, 0); } - void coreinitExport_OSScreenClearBufferEx(PPCInterpreter_t* hCPU) + void OSScreenClearBufferEx(uint32 screenIndex, uint32 color) { - ppcDefineParamU32(screenIndex, 0); - ppcDefineParamU32(color, 1); cemu_assert(screenIndex < 2); _OSScreen_Clear(screenIndex, color); - osLib_returnFromFunction(hCPU, 0); } - void coreinitExport_OSScreenFlipBuffersEx(PPCInterpreter_t* hCPU) + void OSScreenFlipBuffersEx(uint32 screenIndex) { - ppcDefineParamU32(screenIndex, 0); cemu_assert(screenIndex < 2); LatteGPUState.osScreen.screen[screenIndex].flipRequestCount++; _updateCurrentDrawScreen(screenIndex); - osLib_returnFromFunction(hCPU, 0); } - void coreinitExport_OSScreenPutPixelEx(PPCInterpreter_t* hCPU) + void OSScreenPutPixelEx(uint32 screenIndex, sint32 x, sint32 y, uint32 color) { - ppcDefineParamU32(screenIndex, 0); - ppcDefineParamS32(x, 1); - ppcDefineParamS32(y, 2); - ppcDefineParamU32(color, 3); if (screenIndex >= 2) - { - osLib_returnFromFunction(hCPU, 0); return; - } if (x >= 0 && x < screenSizes[screenIndex].x && y >= 0 && y < screenSizes[screenIndex].y) { *(uint32*)((uint8*)currentScreenBasePtr[screenIndex] + (x + y * screenSizes[screenIndex].pitch) * 4) = _swapEndianS32(color); } - osLib_returnFromFunction(hCPU, 0); } const char* osScreenCharset = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; @@ -135,13 +110,8 @@ namespace coreinit return -1; } - void coreinitExport_OSScreenPutFontEx(PPCInterpreter_t* hCPU) + void OSScreenPutFontEx(uint32 screenIndex, sint32 x, sint32 y, const char* str) { - ppcDefineParamU32(screenIndex, 0); - ppcDefineParamS32(x, 1); - ppcDefineParamS32(y, 2); - ppcDefineParamStr(str, 3); - // characters are: // 16 x 32 (including the margin) // with a margin of 4 x 8 @@ -149,16 +119,23 @@ namespace coreinit if (y < 0) { debug_printf("OSScreenPutFontEx: y has invalid value\n"); - osLib_returnFromFunction(hCPU, 0); return; } sint32 px = x * 16; sint32 py = y * 24; + sint32 initialPx = px; while (*str) { sint32 charIndex = _getOSScreenFontCharIndex(*str); + if (*str == (uint8)'\n') + { + px = initialPx; + py += 24; + str++; + continue; + } if (charIndex >= 0) { const uint8* charBitmap = osscreenBitmapFont + charIndex * 50; @@ -175,18 +152,17 @@ namespace coreinit px += 16; str++; } - osLib_returnFromFunction(hCPU, 0); } void InitializeOSScreen() { - osLib_addFunction("coreinit", "OSScreenInit", coreinitExport_OSScreenInit); - osLib_addFunction("coreinit", "OSScreenGetBufferSizeEx", coreinitExport_OSScreenGetBufferSizeEx); - osLib_addFunction("coreinit", "OSScreenSetBufferEx", coreinitExport_OSScreenSetBufferEx); - osLib_addFunction("coreinit", "OSScreenEnableEx", coreinitExport_OSScreenEnableEx); - osLib_addFunction("coreinit", "OSScreenClearBufferEx", coreinitExport_OSScreenClearBufferEx); - osLib_addFunction("coreinit", "OSScreenFlipBuffersEx", coreinitExport_OSScreenFlipBuffersEx); - osLib_addFunction("coreinit", "OSScreenPutPixelEx", coreinitExport_OSScreenPutPixelEx); - osLib_addFunction("coreinit", "OSScreenPutFontEx", coreinitExport_OSScreenPutFontEx); + cafeExportRegister("coreinit", OSScreenInit, LogType::Placeholder); + cafeExportRegister("coreinit", OSScreenGetBufferSizeEx, LogType::Placeholder); + cafeExportRegister("coreinit", OSScreenSetBufferEx, LogType::Placeholder); + cafeExportRegister("coreinit", OSScreenEnableEx, LogType::Placeholder); + cafeExportRegister("coreinit", OSScreenClearBufferEx, LogType::Placeholder); + cafeExportRegister("coreinit", OSScreenFlipBuffersEx, LogType::Placeholder); + cafeExportRegister("coreinit", OSScreenPutPixelEx, LogType::Placeholder); + cafeExportRegister("coreinit", OSScreenPutFontEx, LogType::Placeholder); } } diff --git a/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.h b/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.h index 29011123..1d2b3b36 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.h +++ b/src/Cafe/OS/libs/coreinit/coreinit_OSScreen.h @@ -1,6 +1,18 @@ #pragma once +#define OSSCREEN_TV (0) +#define OSSCREEN_DRC (1) + namespace coreinit { + void OSScreenInit(); + uint32 OSScreenGetBufferSizeEx(uint32 screenIndex); + void OSScreenSetBufferEx(uint32 screenIndex, uint32 buffer); + void OSScreenEnableEx(uint32 screenIndex, uint32 isEnabled); + void OSScreenClearBufferEx(uint32 screenIndex, uint32 color); + void OSScreenFlipBuffersEx(uint32 screenIndex); + void OSScreenPutPixelEx(uint32 screenIndex, sint32 x, sint32 y, uint32 color); + void OSScreenPutFontEx(uint32 screenIndex, sint32 x, sint32 y, const char* str); + void InitializeOSScreen(); -} \ No newline at end of file +}