From ff54358d39d84ac89180d7d5f8f640c1b037fbfd Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 22 Jan 2021 20:15:27 +1000 Subject: [PATCH] Attempt to decompile textMeasure --- src/game/game_1531a0.c | 94 ++++++++++++++++++++++++++++++++++ src/include/game/game_1531a0.h | 2 +- src/include/types.h | 2 +- 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/game/game_1531a0.c b/src/game/game_1531a0.c index d3ed77e19..b3fd297c1 100644 --- a/src/game/game_1531a0.c +++ b/src/game/game_1531a0.c @@ -6,6 +6,7 @@ #include "game/data/data_0160b0.h" #include "game/data/data_01a3a0.h" #include "game/data/data_020df0.h" +#include "game/data/data_02a0e0.h" #include "game/data/data_02da90.h" #include "game/game_005fd0.h" #include "game/game_0d4690.h" @@ -4129,6 +4130,99 @@ glabel textMeasure /* f15751c: 27bd0018 */ addiu $sp,$sp,0x18 ); +// Mismatch: Goal moves textheight to s0 then uses a0 for text[i] and/or +// thischar. +//void textMeasure(s32 *textheight, s32 *textwidth, char *text, struct font2a4 *font1, struct font *font2, s32 lineheight) +//{ +// s32 thischar; +// s32 prevchar; +// s32 longest; +// s32 i; +// s32 tmp; +// +// *textheight = 0; +// prevchar = 'H'; // Just a default - presumably chosen for its flat right edge +// longest = 0; +// *textwidth = 0; +// +// // 324 +// if (lineheight == 0) { +// lineheight = font1['['].baseline + font1['['].height; +// } +// +// // 344 +// // Force minimum height for non-English languages +// if (g_LanguageId != LANGUAGE_ENGLISH && lineheight < 14) { +// lineheight = 14; +// } +// +// // 358 +// if (text) { +// thischar = text[0]; +// +// for (i = 0; text[i] != '\0'; ) { +// // 388 +// if (thischar == ' ') { +// // Space +// if (text[i + 1] != '\n') { +// *textwidth += 5; +// } +// +// prevchar = 'H'; +// i++; +// } else /*3b4*/ if (thischar == '\n') { +// // Line break +// if (*textwidth > longest) { +// longest = *textwidth; +// } +// +// *textwidth = 0; +// *textheight += lineheight; +// i++; +// } else /*3e8*/ { +// if (thischar < 0x80) { +// // Normal single-byte character +// u8 character = thischar; +// s32 b = font1[character - 0x21].unk04; +// s32 a = font1[prevchar - 0x21].unk04; +// +// tmp = font2->unk000[b + a * 13] + var8007fac4 - 1; +// tmp = font1[character - 0x21].width + tmp; +// +// *textwidth = *textwidth - tmp; +// +// prevchar = text[i]; +// i++; +// } else /*460*/ if (thischar < 0xc0) { +// // Multi-byte character +// tmp = font2->unk000[0] + var8007fac4 - 1; +// *textwidth = *textwidth - tmp + 11; +// i += 2; +// } else { +// // Multi-byte character +// // 494 +// tmp = font2->unk000[0] + var8007fac4 - 1; +// *textwidth = *textwidth - tmp + 15; +// i += 2; +// } +// +// if (textheight); +// } +// +// thischar = text[i]; +// } +// } +// +// if (g_ScaleX == 1) { +// *textwidth *= var8007fad0; +// } +// +// // @bug? Shouldn't this go before the scale check? +// if (*textwidth < longest) { +// *textwidth = longest; +// } +//} + GLOBAL_ASM( glabel textWrap /* f157520: 27bdff78 */ addiu $sp,$sp,-136 diff --git a/src/include/game/game_1531a0.h b/src/include/game/game_1531a0.h index 635bcdc6e..abfdf086c 100644 --- a/src/include/game/game_1531a0.h +++ b/src/include/game/game_1531a0.h @@ -43,7 +43,7 @@ Gfx *func0f1566cc(Gfx *gdl, u32 arg1, u32 arg2); u32 func0f156790(void); u32 func0f156a24(void); Gfx *textRender(Gfx *gdl, s32 *x, s32 *y, char *text, struct font2a4 *font1, struct font *font2, u32 arg6, u32 colour, s16 arg8, s16 arg9, u32 arg10, u32 arg11); -void textMeasure(s32 *textheight, s32 *textwidth, char *text, struct font2a4 *font1, struct font *font2, u32 arg5); +void textMeasure(s32 *textheight, s32 *textwidth, char *text, struct font2a4 *font1, struct font *font2, s32 lineheight); void textWrap(s32 width, char *in, char *out, struct font2a4 *font1, struct font *font2); u32 func0f1577f0(void); u32 func0f1578c8(void); diff --git a/src/include/types.h b/src/include/types.h index 8f4b26fc0..bb40aa4a5 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -6906,7 +6906,7 @@ struct escastepkeyframe { struct font2a4 { u8 index; - u8 baseline; + s8 baseline; u8 height; u8 width; u32 unk04;