diff --git a/include/JSystem/JUtility/JUTDirectPrint.h b/include/JSystem/JUtility/JUTDirectPrint.h index fb1fd9dab17..ba2c3b94c6f 100644 --- a/include/JSystem/JUtility/JUTDirectPrint.h +++ b/include/JSystem/JUtility/JUTDirectPrint.h @@ -6,7 +6,7 @@ struct base_process_class {}; -struct __va_list_struct {}; +struct __va_list_struct; class JUTDirectPrint { public: diff --git a/include/msl_c/string.h b/include/msl_c/string.h index 75333f3f9f5..ceb5696ed19 100644 --- a/include/msl_c/string.h +++ b/include/msl_c/string.h @@ -3,6 +3,7 @@ #include "dolphin/types.h" +// TODO: move to MSL_C.PPCEABI.bare.H/ extern "C" { void memcpy(void*, const void*, s32); void* memset(void* dest, int ch, u32 count); @@ -19,6 +20,9 @@ int tolower(int); int sprintf(char*, const char*, ...); int printf(const char*, ...); int snprintf(char*, u32, const char*, ...); + +struct __va_list_struct; +size_t vsnprintf(char* buffer, size_t buffer_size, const char* format, __va_list_struct* args); } #endif \ No newline at end of file diff --git a/libs/JSystem/JUtility/JUTDirectPrint.cpp b/libs/JSystem/JUtility/JUTDirectPrint.cpp index a3381d786fe..6179226f7ae 100644 --- a/libs/JSystem/JUtility/JUTDirectPrint.cpp +++ b/libs/JSystem/JUtility/JUTDirectPrint.cpp @@ -5,8 +5,10 @@ #include "JSystem/JUtility/JUTDirectPrint.h" #include "dol2asm.h" +#include "dolphin/os/OSCache.h" #include "dolphin/types.h" #include "global.h" +#include "msl_c/string.h" // // Types: @@ -46,12 +48,10 @@ extern "C" u8 sDirectPrint__14JUTDirectPrint[4 + 4 /* padding */]; extern "C" void fpcBs_Delete__FP18base_process_class(); extern "C" void __dt__Q27JStudio29TFunctionValue_list_parameterFv(); extern "C" void* __nw__FUl(); -extern "C" void DCStoreRange(); extern "C" void _savegpr_24(); extern "C" void _savegpr_27(); extern "C" void _restgpr_24(); extern "C" void _restgpr_27(); -extern "C" void vsnprintf(); // // Declarations: @@ -298,18 +298,44 @@ void JUTDirectPrint::changeFrameBuffer(void* frameBuffer, u16 width, u16 height) mFrameBufferSize = (u32)mStride * (u32)mFrameBufferHeight * 2; } - /* 802E45A4-802E46D8 2DEEE4 0134+00 1/1 0/0 0/0 .text * printSub__14JUTDirectPrintFUsUsPCcP16__va_list_structb */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JUTDirectPrint::printSub(u16 param_0, u16 param_1, char const* param_2, - __va_list_struct* param_3, bool param_4) { - nofralloc -#include "asm/JSystem/JUtility/JUTDirectPrint/printSub__14JUTDirectPrintFUsUsPCcP16__va_list_structb.s" +void JUTDirectPrint::printSub(u16 position_x, u16 position_y, char const* format, + __va_list_struct* args, bool clear) { + char buffer[256]; + if (!mFrameBuffer) { + return; + } + + int buffer_length = vsnprintf(buffer, ARRAY_SIZE(buffer), format, args); + u16 x = position_x; + if (buffer_length > 0) { + if (clear) { + erase(position_x - 6, position_y - 3, (buffer_length + 2) * 6, 0xd); + } + + char* ptr = buffer; + for (; 0 < buffer_length; buffer_length--, ptr++) { + int codepoint = sAsciiTable[*ptr & 0x7f]; + if (codepoint == 0xfe) { + position_x = x; + position_y += 7; + } else if (codepoint == 0xfd) { + s32 current_position = (int)position_x; + s32 tab = (current_position - x + 0x2f) % 0x30; + position_x = current_position + 0x30 - tab; + } else { + if (codepoint != 0xff) { + drawChar(position_x, position_y, codepoint); + } + position_x += 6; + } + } + } + + DCStoreRange(mFrameBuffer, mFrameBufferSize); } -#pragma pop + /* ############################################################################################## */ /* 8039D9A0-8039D9A0 02A000 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ diff --git a/libs/MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.cpp b/libs/MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.cpp index 5494a4dc33a..1b06f8c5ef3 100644 --- a/libs/MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.cpp +++ b/libs/MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.cpp @@ -11,9 +11,11 @@ // Forward References: // +struct __va_list_struct; + extern "C" void sprintf(); extern "C" void snprintf(); -extern "C" void vsnprintf(); +extern "C" size_t vsnprintf(char* buffer, size_t buffer_size, const char* format, __va_list_struct* args); extern "C" void vprintf(); extern "C" void fprintf(); extern "C" void printf(); @@ -77,7 +79,7 @@ asm void snprintf() { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void vsnprintf() { +asm size_t vsnprintf(char* buffer, size_t buffer_size, const char* format, __va_list_struct* args) { nofralloc #include "asm/MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf/vsnprintf.s" }