coreinit: Refactor OSScreen

This commit is contained in:
Exzap 2026-03-19 20:49:02 +01:00
parent 5e0e3f42da
commit c92bef0352
2 changed files with 38 additions and 50 deletions

View File

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

View File

@ -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();
}
}