From 2b875b0304cb88c8fbac3b00bbbfdc5a3b9631a3 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Wed, 29 Sep 2021 08:46:57 -0400 Subject: [PATCH] Rework simple_printf, and identify it as rmonPrintf --- asm/non_matchings/camera/func_80069F64.s | 8 ++--- asm/non_matchings/main/func_80065E30.s | 2 +- .../unknown_0255E0/func_8002C0C4.s | 2 +- .../unknown_032760/func_8003B368.s | 2 +- .../unknown_032760/func_8003B7CC.s | 2 +- .../unknown_032760/func_8003C644.s | 2 +- lib/src/libc/rmonPrintf.c | 27 +++++++++++++++++ lib/src/libc/rmonPrintf.h | 8 +++++ lib/src/libc/simplesprintf.c | 29 ------------------- lib/src/libc/simplesprintf.h | 9 ------ src/camera.c | 16 +++++----- src/main.c | 4 +-- src/screen_asset.c | 4 +-- 13 files changed, 56 insertions(+), 59 deletions(-) create mode 100644 lib/src/libc/rmonPrintf.c create mode 100644 lib/src/libc/rmonPrintf.h delete mode 100644 lib/src/libc/simplesprintf.c delete mode 100644 lib/src/libc/simplesprintf.h diff --git a/asm/non_matchings/camera/func_80069F64.s b/asm/non_matchings/camera/func_80069F64.s index e3070290..75fd9e45 100644 --- a/asm/non_matchings/camera/func_80069F64.s +++ b/asm/non_matchings/camera/func_80069F64.s @@ -40,24 +40,24 @@ glabel func_80069F64 /* 06ABB8 80069FB8 02E08025 */ move $s0, $s7 .L80069FBC: /* 06ABBC 80069FBC 86050000 */ lh $a1, ($s0) -/* 06ABC0 80069FC0 0C032755 */ jal simple_sprintf +/* 06ABC0 80069FC0 0C032755 */ jal rmonPrintf /* 06ABC4 80069FC4 02602025 */ move $a0, $s3 /* 06ABC8 80069FC8 86050020 */ lh $a1, 0x20($s0) /* 06ABCC 80069FCC 02802025 */ move $a0, $s4 /* 06ABD0 80069FD0 30AEFFFF */ andi $t6, $a1, 0xffff -/* 06ABD4 80069FD4 0C032755 */ jal simple_sprintf +/* 06ABD4 80069FD4 0C032755 */ jal rmonPrintf /* 06ABD8 80069FD8 01C02825 */ move $a1, $t6 /* 06ABDC 80069FDC 26310002 */ addiu $s1, $s1, 2 /* 06ABE0 80069FE0 1635FFF6 */ bne $s1, $s5, .L80069FBC /* 06ABE4 80069FE4 26100002 */ addiu $s0, $s0, 2 -/* 06ABE8 80069FE8 0C032755 */ jal simple_sprintf +/* 06ABE8 80069FE8 0C032755 */ jal rmonPrintf /* 06ABEC 80069FEC 03C02025 */ move $a0, $fp /* 06ABF0 80069FF0 26D60004 */ addiu $s6, $s6, 4 /* 06ABF4 80069FF4 24010010 */ li $at, 16 /* 06ABF8 80069FF8 16C1FFEE */ bne $s6, $at, .L80069FB4 /* 06ABFC 80069FFC 26F70008 */ addiu $s7, $s7, 8 /* 06AC00 8006A000 3C04800E */ lui $a0, %hi(D_800E7088) # $a0, 0x800e -/* 06AC04 8006A004 0C032755 */ jal simple_sprintf +/* 06AC04 8006A004 0C032755 */ jal rmonPrintf /* 06AC08 8006A008 24847088 */ addiu $a0, %lo(D_800E7088) # addiu $a0, $a0, 0x7088 /* 06AC0C 8006A00C 8FBF003C */ lw $ra, 0x3c($sp) /* 06AC10 8006A010 8FB00018 */ lw $s0, 0x18($sp) diff --git a/asm/non_matchings/main/func_80065E30.s b/asm/non_matchings/main/func_80065E30.s index 06b4410b..ae0cfe90 100644 --- a/asm/non_matchings/main/func_80065E30.s +++ b/asm/non_matchings/main/func_80065E30.s @@ -21,7 +21,7 @@ glabel func_80065E30 /* 066A7C 80065E7C 132B0003 */ beq $t9, $t3, .L80065E8C .L80065E80: /* 066A80 80065E80 3C04800E */ lui $a0, %hi(D_800E6ED0) # $a0, 0x800e -/* 066A84 80065E84 0C032755 */ jal simple_sprintf +/* 066A84 80065E84 0C032755 */ jal rmonPrintf /* 066A88 80065E88 24846ED0 */ addiu $a0, %lo(D_800E6ED0) # addiu $a0, $a0, 0x6ed0 .L80065E8C: /* 066A8C 80065E8C 8FBF0014 */ lw $ra, 0x14($sp) diff --git a/asm/non_matchings/unknown_0255E0/func_8002C0C4.s b/asm/non_matchings/unknown_0255E0/func_8002C0C4.s index 544d18c7..61f3ebab 100644 --- a/asm/non_matchings/unknown_0255E0/func_8002C0C4.s +++ b/asm/non_matchings/unknown_0255E0/func_8002C0C4.s @@ -288,7 +288,7 @@ glabel func_8002C0C4 /* 02D0FC 8002C4FC 14200004 */ bnez $at, .L8002C510 /* 02D100 8002C500 3C04800E */ lui $a0, %hi(D_800E5E38) # $a0, 0x800e /* 02D104 8002C504 24845E38 */ addiu $a0, %lo(D_800E5E38) # addiu $a0, $a0, 0x5e38 -/* 02D108 8002C508 0C032755 */ jal simple_sprintf +/* 02D108 8002C508 0C032755 */ jal rmonPrintf /* 02D10C 8002C50C 02602825 */ move $a1, $s3 .L8002C510: /* 02D110 8002C510 0C01C42C */ jal set_free_queue_state diff --git a/asm/non_matchings/unknown_032760/func_8003B368.s b/asm/non_matchings/unknown_032760/func_8003B368.s index 430c396f..574faaf5 100644 --- a/asm/non_matchings/unknown_032760/func_8003B368.s +++ b/asm/non_matchings/unknown_032760/func_8003B368.s @@ -30,7 +30,7 @@ glabel func_8003B368 /* 03BFBC 8003B3BC 15C10006 */ bne $t6, $at, .L8003B3D8 /* 03BFC0 8003B3C0 3C04800E */ lui $a0, %hi(D_800E5FA0) # $a0, 0x800e /* 03BFC4 8003B3C4 24845FA0 */ addiu $a0, %lo(D_800E5FA0) # addiu $a0, $a0, 0x5fa0 -/* 03BFC8 8003B3C8 0C032755 */ jal simple_sprintf +/* 03BFC8 8003B3C8 0C032755 */ jal rmonPrintf /* 03BFCC 8003B3CC AFA60024 */ sw $a2, 0x24($sp) /* 03BFD0 8003B3D0 8FA60024 */ lw $a2, 0x24($sp) /* 03BFD4 8003B3D4 00000000 */ nop diff --git a/asm/non_matchings/unknown_032760/func_8003B7CC.s b/asm/non_matchings/unknown_032760/func_8003B7CC.s index 6229949e..5b106911 100644 --- a/asm/non_matchings/unknown_032760/func_8003B7CC.s +++ b/asm/non_matchings/unknown_032760/func_8003B7CC.s @@ -46,7 +46,7 @@ glabel func_8003B7CC /* 03C460 8003B860 15210007 */ bne $t1, $at, .L8003B880 /* 03C464 8003B864 A0680012 */ sb $t0, 0x12($v1) /* 03C468 8003B868 AFA30024 */ sw $v1, 0x24($sp) -/* 03C46C 8003B86C 0C032755 */ jal simple_sprintf +/* 03C46C 8003B86C 0C032755 */ jal rmonPrintf /* 03C470 8003B870 AFA6002C */ sw $a2, 0x2c($sp) /* 03C474 8003B874 8FA30024 */ lw $v1, 0x24($sp) /* 03C478 8003B878 8FA6002C */ lw $a2, 0x2c($sp) diff --git a/asm/non_matchings/unknown_032760/func_8003C644.s b/asm/non_matchings/unknown_032760/func_8003C644.s index 7973ff23..f8af78a0 100644 --- a/asm/non_matchings/unknown_032760/func_8003C644.s +++ b/asm/non_matchings/unknown_032760/func_8003C644.s @@ -26,7 +26,7 @@ glabel func_8003C644 /* 03D288 8003C688 2401FFFF */ li $at, -1 /* 03D28C 8003C68C 15C10003 */ bne $t6, $at, .L8003C69C /* 03D290 8003C690 3C04800E */ lui $a0, %hi(D_800E5FC8) # $a0, 0x800e -/* 03D294 8003C694 0C032755 */ jal simple_sprintf +/* 03D294 8003C694 0C032755 */ jal rmonPrintf /* 03D298 8003C698 24845FC8 */ addiu $a0, %lo(D_800E5FC8) # addiu $a0, $a0, 0x5fc8 .L8003C69C: /* 03D29C 8003C69C 92380008 */ lbu $t8, 8($s1) diff --git a/lib/src/libc/rmonPrintf.c b/lib/src/libc/rmonPrintf.c new file mode 100644 index 00000000..fb49c982 --- /dev/null +++ b/lib/src/libc/rmonPrintf.c @@ -0,0 +1,27 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C9D40 */ + +#include "rmonPrintf.h" +#include "types.h" +#include "macros.h" +#include "stdarg.h" +#include "xprintf.h" + +/** + * This gets called inside of _PrintF, but it is just a fake pointer returned + */ +static void *is_proutSyncPrintf(void *str, const char *buf, size_t n) { + return ((void *) 1); /* return a fake pointer so that it's not NULL */ +} + +/** + * Like sprintf, but simpler. It just hardcodes NULL for the dst, + * and calls a function that just hardcodes a fake pointer + */ +void rmonPrintf(const char *format, ...) { + s32 written; + va_list args; + va_start(args, format); + written = _Printf(is_proutSyncPrintf, NULL, format, args); + va_end(args); +} diff --git a/lib/src/libc/rmonPrintf.h b/lib/src/libc/rmonPrintf.h new file mode 100644 index 00000000..40aedd96 --- /dev/null +++ b/lib/src/libc/rmonPrintf.h @@ -0,0 +1,8 @@ +#ifndef _RMONPRINTF_H_ +#define _RMONPRINTF_H_ +#include "types.h" +#include + +void rmonPrintf(const char *format, ...); + +#endif diff --git a/lib/src/libc/simplesprintf.c b/lib/src/libc/simplesprintf.c deleted file mode 100644 index bc02e18b..00000000 --- a/lib/src/libc/simplesprintf.c +++ /dev/null @@ -1,29 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C9D40 */ - -#include "simplesprintf.h" -#include "types.h" -#include "macros.h" -#include "stdarg.h" -#include "xprintf.h" - -/** - * This gets called inside of _PrintF, but it is just hardcoded to return true. - */ -char *prout_simple_sprintf(char *dst, const char *src, size_t count) { - return TRUE; -} - -/** - * Like sprintf, but simpler. It just hardcodes 0 for the dst, - * and calls a function that just hardcodes a return of TRUE. - */ -s32 simple_sprintf(const char *format, ...) { - s32 written; - va_list args; - va_start(args, format); - written = _Printf(prout_simple_sprintf, 0, format, args); - va_end(args); - - return written; -} diff --git a/lib/src/libc/simplesprintf.h b/lib/src/libc/simplesprintf.h deleted file mode 100644 index bfa33910..00000000 --- a/lib/src/libc/simplesprintf.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _SIMPLESPRINTF_H_ -#define _SIMPLESPRINTF_H_ -#include "types.h" -#include - -char *prout_simple_sprintf(char *dst, const char *src, size_t count); -s32 simple_sprintf(const char *format, ...); - -#endif diff --git a/src/camera.c b/src/camera.c index 6252a309..cc8aa85d 100644 --- a/src/camera.c +++ b/src/camera.c @@ -7,7 +7,7 @@ #include "unknown_06B2B0.h" #include "unknown_0255E0.h" #include "video.h" -#include "lib/src/libc/simplesprintf.h" +#include "lib/src/libc/rmonPrintf.h" extern u32 osTvType; @@ -879,13 +879,13 @@ void func_80069F64(s16 *mtx) { for(i = 0; i < 4; i++) { for(j = 0; j < 4; j++) { val = mtx[i * 4 + j]; - simple_sprintf("%x.", val); + rmonPrintf("%x.", val); val = mtx[((i + 4) * 4 + j)]; // Issue here. - simple_sprintf("%x ", (u16)val); + rmonPrintf("%x ", (u16)val); } - simple_sprintf("\n"); + rmonPrintf("\n"); } - simple_sprintf("\n"); + rmonPrintf("\n"); } #else GLOBAL_ASM("asm/non_matchings/camera/func_80069F64.s") @@ -897,11 +897,11 @@ void func_8006A03C(f32 *mtx) { for(i = 0; i < 4; i++) { for(j = 0; j < 4; j++) { - simple_sprintf("%f ", mtx[i * 4 + j]); + rmonPrintf("%f ", mtx[i * 4 + j]); } - simple_sprintf("\n"); + rmonPrintf("\n"); } - simple_sprintf("\n"); + rmonPrintf("\n"); } OSMesgQueue *func_8006A100(void) { diff --git a/src/main.c b/src/main.c index df46ba48..20e4669b 100644 --- a/src/main.c +++ b/src/main.c @@ -4,7 +4,7 @@ #include "main.h" #include "thread0_epc.h" #include "unknown_06B2B0.h" -#include "lib/src/libc/simplesprintf.h" +#include "lib/src/libc/rmonPrintf.h" /************ .rodata ************/ @@ -65,7 +65,7 @@ void func_80065E30(void) { D_8011D758[1] = temp3; D_8011D758[0] = temp4; if ((temp2 != temp4) || (temp != temp3)) { - simple_sprintf("WARNING: Stack overflow/underflow!!!\n"); + rmonPrintf("WARNING: Stack overflow/underflow!!!\n"); } } #else diff --git a/src/screen_asset.c b/src/screen_asset.c index dfcd06c7..d96945c8 100644 --- a/src/screen_asset.c +++ b/src/screen_asset.c @@ -2,7 +2,7 @@ /* RAM_POS: 0x8007F640 */ #include "screen_asset.h" -#include "lib/src/libc/simplesprintf.h" +#include "lib/src/libc/rmonPrintf.h" // Render settings for the screens Gfx gRdpSetModeScreenAsset[] = { @@ -36,7 +36,7 @@ u8 *load_screen(s32 screenIndex) { return 0x80100000; } else { if (screenIndex < 0 || screenIndex >= screenTableCount) { - simple_sprintf("SCREEN: No out of range!!\n"); + rmonPrintf("SCREEN: No out of range!!\n"); screenIndex = 0; }