From 1d833e2f0d2e013d73ab9c4826fac8efefdc830b Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sat, 20 Jan 2024 21:48:32 -0800 Subject: [PATCH] print stuff --- include/PR/xstdio.h | 6 +++--- include/fault_internal.h | 1 - include/gfxprint.h | 5 ++--- include/libc64/aprintf.h | 2 ++ src/boot/O2/gfxprint.c | 10 ++++++++-- src/boot/fault_drawer.c | 4 ++-- src/boot/libc64/aprintf.c | 2 +- src/boot/libc64/sprintf.c | 4 ++-- src/libultra/libc/xprintf.c | 2 +- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/PR/xstdio.h b/include/PR/xstdio.h index 76972871d2..b8166c3b90 100644 --- a/include/PR/xstdio.h +++ b/include/PR/xstdio.h @@ -23,15 +23,15 @@ typedef struct { /* 0x34 */ u8 qual; } _Pft; -typedef void* (*PrintCallback)(void*, const char*, size_t); - #define FLAGS_SPACE 1 #define FLAGS_PLUS 2 #define FLAGS_MINUS 4 #define FLAGS_HASH 8 #define FLAGS_ZERO 16 -int _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap); +typedef char *outfun(char*,const char*,size_t); + +int _Printf(outfun pfn, char* arg, const char* fmt, va_list ap); void _Litob(_Pft* args, u8 type); void _Ldtob(_Pft* args, u8 type); diff --git a/include/fault_internal.h b/include/fault_internal.h index 24379e629c..692cb1ee29 100644 --- a/include/fault_internal.h +++ b/include/fault_internal.h @@ -9,7 +9,6 @@ typedef void (*FaultDrawerCallback)(void); void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled); void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color); void FaultDrawer_FillScreen(void); -void* FaultDrawer_FormatStringFunc(void* arg, const char* str, size_t count); void FaultDrawer_SetDrawerFrameBuffer(void* frameBuffer, u16 w, u16 h); void FaultDrawer_SetInputCallback(FaultDrawerCallback callback); void FaultDrawer_Init(void); diff --git a/include/gfxprint.h b/include/gfxprint.h index 6149a5c4a2..adad7948f8 100644 --- a/include/gfxprint.h +++ b/include/gfxprint.h @@ -1,10 +1,9 @@ #ifndef GFXPRINT_H #define GFXPRINT_H +#include "ultra64.h" #include "color.h" -#include "PR/gbi.h" -#include "PR/ultratypes.h" -#include "PR/xstdio.h" +#include "libc64/aprintf.h" #include "unk.h" #define GFXP_UNUSED "\x8E" diff --git a/include/libc64/aprintf.h b/include/libc64/aprintf.h index f7b9dcdee8..81a79ecca6 100644 --- a/include/libc64/aprintf.h +++ b/include/libc64/aprintf.h @@ -3,6 +3,8 @@ #include "ultra64.h" +typedef void* (*PrintCallback)(void*, const char*, size_t); + int vaprintf(PrintCallback* pfn, const char* fmt, va_list args); int aprintf(PrintCallback* pfn, const char* fmt, ...); diff --git a/src/boot/O2/gfxprint.c b/src/boot/O2/gfxprint.c index 368ef7d68c..735514e459 100644 --- a/src/boot/O2/gfxprint.c +++ b/src/boot/O2/gfxprint.c @@ -1,5 +1,4 @@ -#include "global.h" -#include "libc64/aprintf.h" +#include "gfxprint.h" #define GFXP_FLAG_HIRAGANA (1 << 0) #define GFXP_FLAG_RAINBOW (1 << 1) @@ -127,30 +126,37 @@ void GfxPrint_PrintChar(GfxPrint* this, u8 c) { switch (c) { case '\0': break; + case '\n': this->posY += 32; case '\r': this->posX = this->baseX; break; + case '\t': do { GfxPrint_PrintCharImpl(this, ' '); } while ((this->posX - this->baseX) % 256); break; + case GFXP_HIRAGANA_CHAR: this->flags |= GFXP_FLAG_HIRAGANA; break; + case GFXP_KATAKANA_CHAR: this->flags &= ~GFXP_FLAG_HIRAGANA; break; + case GFXP_RAINBOW_ON_CHAR: this->flags |= GFXP_FLAG_RAINBOW; this->flags |= GFXP_FLAG_UPDATE; break; + case GFXP_RAINBOW_OFF_CHAR: this->flags &= ~GFXP_FLAG_RAINBOW; this->flags |= GFXP_FLAG_UPDATE; break; + case GFXP_UNUSED_CHAR: default: break; diff --git a/src/boot/fault_drawer.c b/src/boot/fault_drawer.c index 78dc4fd38c..22ea57aedd 100644 --- a/src/boot/fault_drawer.c +++ b/src/boot/fault_drawer.c @@ -215,7 +215,7 @@ void FaultDrawer_FillScreen() { FaultDrawer_SetCursor(sFaultDrawerInstance->xStart, sFaultDrawerInstance->yStart); } -void* FaultDrawer_FormatStringFunc(void* arg, const char* str, size_t count) { +char* FaultDrawer_FormatStringFunc(char* arg, const char* str, size_t count) { for (; count > 0; count--, str++) { if (sFaultDrawerInstance->escCode) { sFaultDrawerInstance->escCode = false; @@ -267,7 +267,7 @@ void* FaultDrawer_FormatStringFunc(void* arg, const char* str, size_t count) { const char D_80099080[] = "(null)"; s32 FaultDrawer_VPrintf(const char* fmt, va_list ap) { - return _Printf(FaultDrawer_FormatStringFunc, sFaultDrawerInstance, fmt, ap); + return _Printf(FaultDrawer_FormatStringFunc, (void*)sFaultDrawerInstance, fmt, ap); } s32 FaultDrawer_Printf(const char* fmt, ...) { diff --git a/src/boot/libc64/aprintf.c b/src/boot/libc64/aprintf.c index 5e69e97f87..e3f048dcb8 100644 --- a/src/boot/libc64/aprintf.c +++ b/src/boot/libc64/aprintf.c @@ -1,7 +1,7 @@ #include "libc64/aprintf.h" int vaprintf(PrintCallback* pfn, const char* fmt, va_list args) { - return _Printf(*pfn, pfn, fmt, args); + return _Printf((outfun*)*pfn, (char*)pfn, fmt, args); } int aprintf(PrintCallback* pfn, const char* fmt, ...) { diff --git a/src/boot/libc64/sprintf.c b/src/boot/libc64/sprintf.c index 07bee8064d..49b3083cc8 100644 --- a/src/boot/libc64/sprintf.c +++ b/src/boot/libc64/sprintf.c @@ -7,7 +7,7 @@ void* proutPrintf(void* dst, const char* fmt, size_t size) { } int vsprintf(char* dst, const char* fmt, va_list args) { - int ans = _Printf(proutPrintf, dst, fmt, args); + int ans = _Printf((outfun*)proutPrintf, dst, fmt, args); if (ans > -1) { dst[ans] = 0; @@ -20,7 +20,7 @@ int sprintf(char* dst, const char* fmt, ...) { va_list args; va_start(args, fmt); - ans = _Printf(&proutPrintf, dst, fmt, args); + ans = _Printf((outfun*)proutPrintf, dst, fmt, args); if (ans > -1) { dst[ans] = 0; } diff --git a/src/libultra/libc/xprintf.c b/src/libultra/libc/xprintf.c index a4094833fa..76a3c92cee 100644 --- a/src/libultra/libc/xprintf.c +++ b/src/libultra/libc/xprintf.c @@ -31,7 +31,7 @@ char zeroes[] = "00000000000000000000000000000000"; void _Putfld(_Pft* px, va_list* pap, unsigned char code, unsigned char* ac); -int _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap) { +int _Printf(outfun pfn, void* arg, const char* fmt, va_list ap) { _Pft x; x.nchar = 0; while (1) {