From 84fda38879319e90ca3675cf0dd12706aecdefdb Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Wed, 20 Oct 2021 14:36:39 -0400 Subject: [PATCH] Match an unsused printf function, and almost match render_printf --- asm/non_matchings/printf/func_800B4A14.s | 13 -------- src/particles.c | 6 +++- src/printf.c | 38 +++++++++++++++++------- 3 files changed, 33 insertions(+), 24 deletions(-) delete mode 100644 asm/non_matchings/printf/func_800B4A14.s diff --git a/asm/non_matchings/printf/func_800B4A14.s b/asm/non_matchings/printf/func_800B4A14.s deleted file mode 100644 index 6b50dcf3..00000000 --- a/asm/non_matchings/printf/func_800B4A14.s +++ /dev/null @@ -1,13 +0,0 @@ -glabel func_800B4A14 -/* 0B5614 800B4A14 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 0B5618 800B4A18 AFBF0014 */ sw $ra, 0x14($sp) -/* 0B561C 800B4A1C AFA60028 */ sw $a2, 0x28($sp) -/* 0B5620 800B4A20 AFA50024 */ sw $a1, 0x24($sp) -/* 0B5624 800B4A24 AFA7002C */ sw $a3, 0x2c($sp) -/* 0B5628 800B4A28 0C02D290 */ jal sprintf -/* 0B562C 800B4A2C 27A60028 */ addiu $a2, $sp, 0x28 -/* 0B5630 800B4A30 8FBF0014 */ lw $ra, 0x14($sp) -/* 0B5634 800B4A34 27BD0020 */ addiu $sp, $sp, 0x20 -/* 0B5638 800B4A38 03E00008 */ jr $ra -/* 0B563C 800B4A3C 00000000 */ nop - diff --git a/src/particles.c b/src/particles.c index ee50ae88..0d15c031 100644 --- a/src/particles.c +++ b/src/particles.c @@ -172,7 +172,11 @@ s32 D_80127CCC; s16 D_80127CD0; s16 D_80127CD2; s32 D_80127CD4; -s32 D_80127CD8[576]; +s8 D_80127CD8; +s8 D_80127CD9; +s8 D_80127CDA; +s8 D_80127CDB; +s32 D_80127CDC[574]; s32 D_801285D8[1026]; s32 D_801295E0[108]; s32 D_80129790[6]; diff --git a/src/printf.c b/src/printf.c index b885fe4b..53e00fe5 100644 --- a/src/printf.c +++ b/src/printf.c @@ -6,6 +6,9 @@ #include "macros.h" #include "f3ddkr.h" #include "thread0_epc.h" +#include "stdarg.h" +#include "textures_sprites.h" +#include "stdio.h" /************ .data ************/ @@ -61,7 +64,7 @@ const char D_800E8C64[] = "*** diPrintf Error *** ---> Out of string space. (Pri extern s32 D_80127CA0; extern s32 D_80127CA4; extern s32 D_80127CA8; -extern u8 D_80127CD8[576]; +extern u8 D_80127CD8; extern u8 *D_801285D8; /******************************/ @@ -81,15 +84,12 @@ void func_800B4A08(s32 arg0) { D_800E2EF0 = arg0; } -#ifdef NON_MATCHING -// Unused. -// Regalloc issues. I can't get sprintf to work properly. -void func_800B4A14(char *arg0, s32 arg1, s32 arg2, s32 arg3) { - sprintf(arg0, &arg2); +void func_800B4A14(char *s, char *format, ...) { + va_list args; + va_start(args, format); + sprintf(s, format, args); + va_end(args); } -#else -GLOBAL_ASM("asm/non_matchings/printf/func_800B4A14.s") -#endif GLOBAL_ASM("asm/non_matchings/printf/sprintf.s") @@ -97,10 +97,28 @@ void func_800B5E88(void) { D_80127CA0 = load_texture(0); D_80127CA4 = load_texture(1); D_80127CA8 = load_texture(2); - D_801285D8 = &D_80127CD8[0]; + D_801285D8 = &D_80127CD8; } +#if 0 +s32 render_printf(const char *format, ...) { + s32 written; + va_list args; + va_start(args, format); + if ((D_801285D8 - &D_80127CD8) >= 0x801) { + return -1; + } + func_800B4A08(1); + written = sprintf(D_801285D8, format, args); + func_800B4A08(0); + if (written > 0) { + D_801285D8 = &D_801285D8[written] + 1; + } + return 0; +} +#else GLOBAL_ASM("asm/non_matchings/printf/render_printf.s") +#endif GLOBAL_ASM("asm/non_matchings/printf/func_800B5F78.s") void set_render_printf_color(u8 red, u8 green, u8 blue, u8 alpha) {