From 75b9be7f7c53ead5beb594e01dab4a33d6b780a3 Mon Sep 17 00:00:00 2001 From: red031000 Date: Wed, 10 Mar 2021 17:26:54 +0000 Subject: start of text.c --- arm9/src/text.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 arm9/src/text.c (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c new file mode 100644 index 00000000..cd846135 --- /dev/null +++ b/arm9/src/text.c @@ -0,0 +1,85 @@ +#include "text.h" +#include "heap.h" + +const struct FontInfo *gFonts = NULL; + +u8 UNK_021C5734[0x200]; +u32 UNK_021C5714[8]; +u8 UNK_021C570C[8]; + +extern u32 FUN_0200CA7C(void *param0, u32 param1, u32 param2); + +extern void *FUN_0201B6C8(void); +extern void FUN_0200CAB4(u32 param0); +extern void FUN_0201C238(void); + +THUMB_FUNC void SetFontsPointer(const struct FontInfo *fonts) +{ + gFonts = fonts; +} + +THUMB_FUNC u8 FUN_0201BCC8(void *param0, u32 param1, u32 param2) +{ + u32 *r4 = UNK_021C5714; + s32 i; + for (i = 0; i < 8; i++, r4++) + { + if (r4[0] != 0) + { + continue; + } + UNK_021C5714[i] = FUN_0200CA7C(param0, param1, param2); + if (UNK_021C5714[i] != 0) + { + break; + } + i = 8; + break; + } + return (u8)i; +} + +THUMB_FUNC void FUN_0201BCFC(u32 param0) +{ + GF_ASSERT(param0 < 8); + GF_ASSERT(UNK_021C5714[param0] != 0); + if (param0 >= 8) + { + return; + } + if (UNK_021C5714[param0] == 0) + { + return; + } + void *r5 = FUN_0201B6C8(); + if (r5) + { + FUN_0201C238(); + FreeToHeap(r5); + } + FUN_0200CAB4(UNK_021C5714[param0]); + UNK_021C5714[param0] = 0; +} + +THUMB_FUNC BOOL FUN_0201BD44(u32 param0) +{ + return UNK_021C5714[param0] ? TRUE : FALSE; +} + +THUMB_FUNC void FUN_0201BD5C(void) +{ + for (s32 i = 0; i < 8; i++) + { + UNK_021C5714[i] = 0; + } +} + +THUMB_FUNC u8 FUN_0201BD70(u32 param0) +{ + return (u8)FUN_0201BD44(param0); +} + +THUMB_FUNC void FUN_0201BD7C(u32 param0) +{ + FUN_0201BCFC(param0); +} -- cgit v1.2.3 From 253e743399d41bd5b3a10b65308a962924563196 Mon Sep 17 00:00:00 2001 From: red031000 Date: Wed, 10 Mar 2021 21:45:44 +0000 Subject: AddTextPrinterParameterized --- arm9/src/text.c | 24 ++++++++++++++++++++++++ arm9/src/text_02054590.c | 16 +++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c index cd846135..1a62608d 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -8,6 +8,7 @@ u32 UNK_021C5714[8]; u8 UNK_021C570C[8]; extern u32 FUN_0200CA7C(void *param0, u32 param1, u32 param2); +extern u16 AddTextPrinter(struct TextPrinterTemplate *template, u32 speed, void (*callback)(void *, u16)); extern void *FUN_0201B6C8(void); extern void FUN_0200CAB4(u32 param0); @@ -83,3 +84,26 @@ THUMB_FUNC void FUN_0201BD7C(u32 param0) { FUN_0201BCFC(param0); } + +THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u8 *str, u32 x, u32 y, u32 speed, void (*callback)(void *, u16)) +{ + struct TextPrinterTemplate printerTemplate; + + printerTemplate.windowId = windowId; + printerTemplate.currentChar = str; + printerTemplate.fontId = fontId; + printerTemplate.x = (u8)x; + printerTemplate.y = (u8)y; + printerTemplate.currentX = (u8)x; + printerTemplate.currentY = (u8)y; + printerTemplate.letterSpacing = gFonts[fontId].letterSpacing; + printerTemplate.lineSpacing = gFonts[fontId].lineSpacing; + printerTemplate.unk = gFonts[fontId].unk; + printerTemplate.fgColor = gFonts[fontId].fgColor; + printerTemplate.bgColor = gFonts[fontId].bgColor; + printerTemplate.shadowColor = gFonts[fontId].shadowColor; + printerTemplate.unk2 = 0; + printerTemplate.unk3 = 0; + printerTemplate.unk4 = 255; + return AddTextPrinter(&printerTemplate, speed, callback); +} diff --git a/arm9/src/text_02054590.c b/arm9/src/text_02054590.c index f0c63a2b..393ac3b2 100644 --- a/arm9/src/text_02054590.c +++ b/arm9/src/text_02054590.c @@ -1,4 +1,5 @@ #include "text_02054590.h" +#include "text.h" extern void FUN_0201BD5C(void); extern void FUN_02002ED0(u32 param0, u32 param1, u32 param2); @@ -15,9 +16,6 @@ extern void FUN_02019620(u32 *param0, u32 param1); extern void FUN_02002B60(u8 param0); extern void FUN_02002B7C(u32 param0); extern void FUN_02002BB8(u32 param0); -extern void AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u32 speed, void (*callback)(void *, u16)); - -extern u32 FUN_0201BD70(void); extern void FUN_0200D300(u32 param0, u32 param1, u32 param2, u32 param3, u8 param4, u32 param5, u32 param6); extern void FUN_0200D6F8(u32 *param0, u32 param1, u32 param2, u32 param3, u8 param4); @@ -57,25 +55,25 @@ THUMB_FUNC void FUN_0205464C(u32 *param0) FUN_02019620(param0, 15); } -THUMB_FUNC void FUN_02054658(u8 windowId, const u8 *str, struct Options *options, u8 param3) +THUMB_FUNC u16 FUN_02054658(u8 windowId, const u8 *str, struct Options *options, u8 param3) { FUN_02002B60(param3); FUN_02002B7C(0); FUN_02002BB8(0); - AddTextPrinterParameterized(windowId, 1, str, 0, 0, (u32)Options_GetTextFrameDelay(options), NULL); + return AddTextPrinterParameterized(windowId, 1, str, 0, 0, (u32)Options_GetTextFrameDelay(options), NULL); } -THUMB_FUNC void DrawFieldMessage(u8 windowId, const u8 *str, u8 fontId, u32 speed, u8 a4, u32 a5) +THUMB_FUNC u16 DrawFieldMessage(u8 windowId, const u8 *str, u8 fontId, u32 speed, u8 a4, u32 a5) { FUN_02002B60(a4); FUN_02002B7C(a5); FUN_02002BB8(0); - AddTextPrinterParameterized(windowId, fontId, str, 0, 0, speed, NULL); + return AddTextPrinterParameterized(windowId, fontId, str, 0, 0, speed, NULL); } -THUMB_FUNC u8 FUN_020546C8(void) //bool8? +THUMB_FUNC u8 FUN_020546C8(u32 param0) //bool8? { - return !FUN_0201BD70(); + return !FUN_0201BD70(param0); } THUMB_FUNC void FUN_020546E0(u32 param0, u32 param1, u32 param2, u32 param3) -- cgit v1.2.3 From c00f7030cbfd128dec0387d7ea9e45885d0d0f93 Mon Sep 17 00:00:00 2001 From: red031000 Date: Wed, 10 Mar 2021 22:41:14 +0000 Subject: paramatised2 and 3 --- arm9/src/text.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c index 1a62608d..0379769f 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -107,3 +107,49 @@ THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u8 *st printerTemplate.unk4 = 255; return AddTextPrinter(&printerTemplate, speed, callback); } + +THUMB_FUNC u16 AddTextPrinterParameterized2(u32 windowId, u8 fontId, const u8 *str, u32 x, u32 y, u32 speed, u32 colors, void (*callback)(void *, u16)) +{ + struct TextPrinterTemplate printerTemplate; + + printerTemplate.windowId = windowId; + printerTemplate.currentChar = str; + printerTemplate.fontId = fontId; + printerTemplate.x = (u8)x; + printerTemplate.y = (u8)y; + printerTemplate.currentX = (u8)x; + printerTemplate.currentY = (u8)y; + printerTemplate.letterSpacing = gFonts[fontId].letterSpacing; + printerTemplate.lineSpacing = gFonts[fontId].lineSpacing; + printerTemplate.unk = gFonts[fontId].unk; + printerTemplate.fgColor = colors >> 16; + printerTemplate.shadowColor = colors >> 8; + printerTemplate.bgColor = colors; + printerTemplate.unk2 = 0; + printerTemplate.unk3 = 0; + printerTemplate.unk4 = 255; + return AddTextPrinter(&printerTemplate, speed, callback); +} + +THUMB_FUNC u16 AddTextPrinterParameterized3(u32 windowId, u8 fontId, const u8 *str, u32 x, u32 y, u32 speed, u32 colors, u32 letterSpacing, u32 lineSpacing, void (*callback)(void *, u16)) +{ + struct TextPrinterTemplate printerTemplate; + + printerTemplate.windowId = windowId; + printerTemplate.currentChar = str; + printerTemplate.fontId = fontId; + printerTemplate.x = (u8)x; + printerTemplate.y = (u8)y; + printerTemplate.currentX = (u8)x; + printerTemplate.currentY = (u8)y; + printerTemplate.letterSpacing = letterSpacing; + printerTemplate.lineSpacing = lineSpacing; + printerTemplate.unk = gFonts[fontId].unk; + printerTemplate.fgColor = colors >> 16; + printerTemplate.shadowColor = colors >> 8; + printerTemplate.bgColor = colors; + printerTemplate.unk2 = 0; + printerTemplate.unk3 = 0; + printerTemplate.unk4 = 255; + return AddTextPrinter(&printerTemplate, speed, callback); +} -- cgit v1.2.3 From 82b20d5a8badb77010fb5dfc4d20b9282985703a Mon Sep 17 00:00:00 2001 From: red031000 Date: Thu, 11 Mar 2021 22:03:17 +0000 Subject: decompile AddTextPrinter --- arm9/src/text.c | 102 +++++++++++++++++++++++++++++++++++++---------- arm9/src/text_02054590.c | 4 +- 2 files changed, 83 insertions(+), 23 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c index 0379769f..ccc86bab 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -1,5 +1,6 @@ #include "text.h" #include "heap.h" +#include "string16.h" const struct FontInfo *gFonts = NULL; @@ -7,19 +8,24 @@ u8 UNK_021C5734[0x200]; u32 UNK_021C5714[8]; u8 UNK_021C570C[8]; -extern u32 FUN_0200CA7C(void *param0, u32 param1, u32 param2); -extern u16 AddTextPrinter(struct TextPrinterTemplate *template, u32 speed, void (*callback)(void *, u16)); +extern u32 FUN_0200CA7C(void *func, struct TextPrinter *printer, u32 param2); -extern void *FUN_0201B6C8(void); +extern struct TextPrinter *FUN_0201B6C8(void); extern void FUN_0200CAB4(u32 param0); -extern void FUN_0201C238(void); +extern void FUN_0201C238(struct TextPrinter *printer); + +extern u32 RenderFont(struct TextPrinter *printer); +extern void FUN_0201C1A8(struct TextPrinter *printer); +extern FUN_0201BFDC(); //no idea what this is +extern void FUN_0201C05C(u8 fgColor, u8 bgColor, u8 shadowColor); +extern void FUN_020191D0(u32 windowId); THUMB_FUNC void SetFontsPointer(const struct FontInfo *fonts) { gFonts = fonts; } -THUMB_FUNC u8 FUN_0201BCC8(void *param0, u32 param1, u32 param2) +THUMB_FUNC u8 FUN_0201BCC8(void *func, struct TextPrinter *printer, u32 param2) { u32 *r4 = UNK_021C5714; s32 i; @@ -29,7 +35,7 @@ THUMB_FUNC u8 FUN_0201BCC8(void *param0, u32 param1, u32 param2) { continue; } - UNK_021C5714[i] = FUN_0200CA7C(param0, param1, param2); + UNK_021C5714[i] = FUN_0200CA7C(func, printer, param2); if (UNK_021C5714[i] != 0) { break; @@ -52,11 +58,11 @@ THUMB_FUNC void FUN_0201BCFC(u32 param0) { return; } - void *r5 = FUN_0201B6C8(); - if (r5) + struct TextPrinter *printer = FUN_0201B6C8(); + if (printer) { - FUN_0201C238(); - FreeToHeap(r5); + FUN_0201C238(printer); + FreeToHeap((void *)printer); } FUN_0200CAB4(UNK_021C5714[param0]); UNK_021C5714[param0] = 0; @@ -85,7 +91,7 @@ THUMB_FUNC void FUN_0201BD7C(u32 param0) FUN_0201BCFC(param0); } -THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u8 *str, u32 x, u32 y, u32 speed, void (*callback)(void *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, void (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; @@ -108,7 +114,7 @@ THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u8 *st return AddTextPrinter(&printerTemplate, speed, callback); } -THUMB_FUNC u16 AddTextPrinterParameterized2(u32 windowId, u8 fontId, const u8 *str, u32 x, u32 y, u32 speed, u32 colors, void (*callback)(void *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized2(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, void (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; @@ -122,16 +128,16 @@ THUMB_FUNC u16 AddTextPrinterParameterized2(u32 windowId, u8 fontId, const u8 *s printerTemplate.letterSpacing = gFonts[fontId].letterSpacing; printerTemplate.lineSpacing = gFonts[fontId].lineSpacing; printerTemplate.unk = gFonts[fontId].unk; - printerTemplate.fgColor = colors >> 16; - printerTemplate.shadowColor = colors >> 8; - printerTemplate.bgColor = colors; + printerTemplate.fgColor = (u8)(colors >> 16); + printerTemplate.shadowColor = (u8)(colors >> 8); + printerTemplate.bgColor = (u8)colors; printerTemplate.unk2 = 0; printerTemplate.unk3 = 0; printerTemplate.unk4 = 255; return AddTextPrinter(&printerTemplate, speed, callback); } -THUMB_FUNC u16 AddTextPrinterParameterized3(u32 windowId, u8 fontId, const u8 *str, u32 x, u32 y, u32 speed, u32 colors, u32 letterSpacing, u32 lineSpacing, void (*callback)(void *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized3(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, u32 letterSpacing, u32 lineSpacing, void (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; @@ -142,14 +148,68 @@ THUMB_FUNC u16 AddTextPrinterParameterized3(u32 windowId, u8 fontId, const u8 *s printerTemplate.y = (u8)y; printerTemplate.currentX = (u8)x; printerTemplate.currentY = (u8)y; - printerTemplate.letterSpacing = letterSpacing; - printerTemplate.lineSpacing = lineSpacing; + printerTemplate.letterSpacing = (u8)letterSpacing; + printerTemplate.lineSpacing = (u8)lineSpacing; printerTemplate.unk = gFonts[fontId].unk; - printerTemplate.fgColor = colors >> 16; - printerTemplate.shadowColor = colors >> 8; - printerTemplate.bgColor = colors; + printerTemplate.fgColor = (u8)(colors >> 16); + printerTemplate.shadowColor = (u8)(colors >> 8); + printerTemplate.bgColor = (u8)colors; printerTemplate.unk2 = 0; printerTemplate.unk3 = 0; printerTemplate.unk4 = 255; return AddTextPrinter(&printerTemplate, speed, callback); } + +THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 speed, void (*callback)(struct TextPrinterTemplate *, u16)) +{ + if (!gFonts) + return 0xff; + + struct TextPrinter *printer = (struct TextPrinter *)AllocFromHeap(0, sizeof(struct TextPrinter)); + + printer->active = TRUE; + printer->state = 0; + printer->textSpeedBottom = (u8)speed; + printer->delayCounter = 0; + printer->scrollDistance = 0; + printer->japanese = 0; + + for (s32 i = 0; i < 7; i++) + { + printer->subStructFields[i] = 0; + } + + printer->printerTemplate = *printerTemplate; + printer->printerTemplate.currentChar = String_c_str((struct String *)printer->printerTemplate.currentChar); //TODO clean up + printer->callback = callback; + UNK_021C570C[0] = 0; + FUN_0201C1A8(printer); + if (speed != 0xff && speed != 0) + { + printer->textSpeedBottom += 0xff; + printer->textSpeedTop = 1; + printer->minLetterSpacing = FUN_0201BCC8(FUN_0201BFDC, printer, 1); + return printer->minLetterSpacing; + } + else + { + u32 j = 0; + printer->textSpeedBottom = 0; + printer->textSpeedTop = 0; + FUN_0201C05C(printerTemplate->fgColor, printerTemplate->bgColor, printerTemplate->shadowColor); //GenerateFontHalfRowLookupTable ? + for (; j < 0x400; ++j) + { + if (RenderFont(printer) == 1) + { + break; + } + } + if (speed != 0xff) + { + FUN_020191D0(printer->printerTemplate.windowId); // CopyWindowToVram? + } + FUN_0201C238(printer); + FreeToHeap((void *)printer); + return 8; + } +} diff --git a/arm9/src/text_02054590.c b/arm9/src/text_02054590.c index 393ac3b2..470a2fe3 100644 --- a/arm9/src/text_02054590.c +++ b/arm9/src/text_02054590.c @@ -55,7 +55,7 @@ THUMB_FUNC void FUN_0205464C(u32 *param0) FUN_02019620(param0, 15); } -THUMB_FUNC u16 FUN_02054658(u8 windowId, const u8 *str, struct Options *options, u8 param3) +THUMB_FUNC u16 FUN_02054658(u8 windowId, const u16 *str, struct Options *options, u8 param3) { FUN_02002B60(param3); FUN_02002B7C(0); @@ -63,7 +63,7 @@ THUMB_FUNC u16 FUN_02054658(u8 windowId, const u8 *str, struct Options *options, return AddTextPrinterParameterized(windowId, 1, str, 0, 0, (u32)Options_GetTextFrameDelay(options), NULL); } -THUMB_FUNC u16 DrawFieldMessage(u8 windowId, const u8 *str, u8 fontId, u32 speed, u8 a4, u32 a5) +THUMB_FUNC u16 DrawFieldMessage(u8 windowId, const u16 *str, u8 fontId, u32 speed, u8 a4, u32 a5) { FUN_02002B60(a4); FUN_02002B7C(a5); -- cgit v1.2.3 From c7b8a8b0762c5eef4a678eb9cbc036e4fbb5568b Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 12 Mar 2021 03:30:43 +0000 Subject: name GenerateFontHalfRowLookupTable and CopyWindowToVram --- arm9/src/text.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c index ccc86bab..58bfa220 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -17,8 +17,8 @@ extern void FUN_0201C238(struct TextPrinter *printer); extern u32 RenderFont(struct TextPrinter *printer); extern void FUN_0201C1A8(struct TextPrinter *printer); extern FUN_0201BFDC(); //no idea what this is -extern void FUN_0201C05C(u8 fgColor, u8 bgColor, u8 shadowColor); -extern void FUN_020191D0(u32 windowId); +extern void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor); +extern void CopyWindowToVram(u32 windowId); THUMB_FUNC void SetFontsPointer(const struct FontInfo *fonts) { @@ -196,7 +196,7 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s u32 j = 0; printer->textSpeedBottom = 0; printer->textSpeedTop = 0; - FUN_0201C05C(printerTemplate->fgColor, printerTemplate->bgColor, printerTemplate->shadowColor); //GenerateFontHalfRowLookupTable ? + GenerateFontHalfRowLookupTable(printerTemplate->fgColor, printerTemplate->bgColor, printerTemplate->shadowColor); for (; j < 0x400; ++j) { if (RenderFont(printer) == 1) @@ -206,7 +206,7 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s } if (speed != 0xff) { - FUN_020191D0(printer->printerTemplate.windowId); // CopyWindowToVram? + CopyWindowToVram(printer->printerTemplate.windowId); // CopyWindowToVram? } FUN_0201C238(printer); FreeToHeap((void *)printer); -- cgit v1.2.3 From fd3ac04d131ba3237c90695b2a59f11959af75ce Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 12 Mar 2021 04:04:34 +0000 Subject: RunTextPrinter --- arm9/src/text.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c index 58bfa220..04f443e9 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -16,7 +16,6 @@ extern void FUN_0201C238(struct TextPrinter *printer); extern u32 RenderFont(struct TextPrinter *printer); extern void FUN_0201C1A8(struct TextPrinter *printer); -extern FUN_0201BFDC(); //no idea what this is extern void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor); extern void CopyWindowToVram(u32 windowId); @@ -91,7 +90,7 @@ THUMB_FUNC void FUN_0201BD7C(u32 param0) FUN_0201BCFC(param0); } -THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, void (*callback)(struct TextPrinterTemplate *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u8 (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; @@ -114,7 +113,7 @@ THUMB_FUNC u16 AddTextPrinterParameterized(u32 windowId, u8 fontId, const u16 *s return AddTextPrinter(&printerTemplate, speed, callback); } -THUMB_FUNC u16 AddTextPrinterParameterized2(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, void (*callback)(struct TextPrinterTemplate *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized2(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, u8 (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; @@ -137,7 +136,7 @@ THUMB_FUNC u16 AddTextPrinterParameterized2(u32 windowId, u8 fontId, const u16 * return AddTextPrinter(&printerTemplate, speed, callback); } -THUMB_FUNC u16 AddTextPrinterParameterized3(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, u32 letterSpacing, u32 lineSpacing, void (*callback)(struct TextPrinterTemplate *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized3(u32 windowId, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, u32 letterSpacing, u32 lineSpacing, u8 (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; @@ -160,7 +159,7 @@ THUMB_FUNC u16 AddTextPrinterParameterized3(u32 windowId, u8 fontId, const u16 * return AddTextPrinter(&printerTemplate, speed, callback); } -THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 speed, void (*callback)(struct TextPrinterTemplate *, u16)) +THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 speed, u8 (*callback)(struct TextPrinterTemplate *, u16)) { if (!gFonts) return 0xff; @@ -172,7 +171,7 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s printer->textSpeedBottom = (u8)speed; printer->delayCounter = 0; printer->scrollDistance = 0; - printer->japanese = 0; + printer->Unk29 = 0; for (s32 i = 0; i < 7; i++) { @@ -188,7 +187,7 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s { printer->textSpeedBottom += 0xff; printer->textSpeedTop = 1; - printer->minLetterSpacing = FUN_0201BCC8(FUN_0201BFDC, printer, 1); + printer->minLetterSpacing = FUN_0201BCC8(RunTextPrinter, printer, 1); return printer->minLetterSpacing; } else @@ -213,3 +212,39 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s return 8; } } + +THUMB_FUNC void RunTextPrinter(u32 param0, struct TextPrinter *printer) +{ +#pragma unused(param0) + if (UNK_021C570C[0] == 0) + { + if (printer->Unk29 == 0) + { + printer->Unk2A = 0; + GenerateFontHalfRowLookupTable(printer->printerTemplate.fgColor, printer->printerTemplate.bgColor, printer->printerTemplate.shadowColor); + u32 temp = RenderFont(printer); + switch (temp) + { + case 0: + CopyWindowToVram(printer->printerTemplate.windowId); + //fallthrough + case 3: + if (printer->callback == NULL) + { + return; + } + printer->Unk29 = printer->callback(&printer->printerTemplate, printer->Unk2A); //TODO check + return; + case 1: + FUN_0201BCFC(printer->minLetterSpacing); + return; + default: + return; + } + } + else + { + printer->Unk29 = printer->callback(&printer->printerTemplate, printer->Unk2A); + } + } +} -- cgit v1.2.3 From 63bcf753d4d57c1585140c7b3eec1aace1e89caf Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 12 Mar 2021 17:21:48 +0000 Subject: GenerateFontHalfRowLookupTable nonmatching --- arm9/src/text.c | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 255 insertions(+), 5 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c index 04f443e9..8ec3efe8 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -8,23 +8,23 @@ u8 UNK_021C5734[0x200]; u32 UNK_021C5714[8]; u8 UNK_021C570C[8]; -extern u32 FUN_0200CA7C(void *func, struct TextPrinter *printer, u32 param2); +extern u32 FUN_0200CA7C(void (*func)(u32, struct TextPrinter *), struct TextPrinter *printer, u32 param2); extern struct TextPrinter *FUN_0201B6C8(void); extern void FUN_0200CAB4(u32 param0); extern void FUN_0201C238(struct TextPrinter *printer); -extern u32 RenderFont(struct TextPrinter *printer); extern void FUN_0201C1A8(struct TextPrinter *printer); -extern void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor); extern void CopyWindowToVram(u32 windowId); +extern u32 FontFunc(u8 fontId, struct TextPrinter *printer); + THUMB_FUNC void SetFontsPointer(const struct FontInfo *fonts) { gFonts = fonts; } -THUMB_FUNC u8 FUN_0201BCC8(void *func, struct TextPrinter *printer, u32 param2) +THUMB_FUNC u8 FUN_0201BCC8(void (*func)(u32, struct TextPrinter *), struct TextPrinter *printer, u32 param2) { u32 *r4 = UNK_021C5714; s32 i; @@ -233,7 +233,7 @@ THUMB_FUNC void RunTextPrinter(u32 param0, struct TextPrinter *printer) { return; } - printer->Unk29 = printer->callback(&printer->printerTemplate, printer->Unk2A); //TODO check + printer->Unk29 = printer->callback(&printer->printerTemplate, printer->Unk2A); return; case 1: FUN_0201BCFC(printer->minLetterSpacing); @@ -248,3 +248,253 @@ THUMB_FUNC void RunTextPrinter(u32 param0, struct TextPrinter *printer) } } } + +THUMB_FUNC u32 RenderFont(struct TextPrinter *printer) +{ + u32 ret; + while (TRUE) + { + ret = FontFunc(printer->printerTemplate.fontId, printer); + if (ret != 2) + { + return ret; + } + } +} + +#ifdef NONMATCHING +THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor) +{ + u32 fg12, bg12, shadow12; + u32 temp; + + u16 *current = UNK_021C570C; + + bg12 = bgColor << 12; + fg12 = fgColor << 12; + shadow12 = shadowColor << 12; + + temp = (bgColor << 8) | (bgColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (bgColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (bgColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (fgColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (fgColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (fgColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (shadowColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (shadowColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (shadowColor << 4) | bgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (bgColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (bgColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (bgColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (fgColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (fgColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (fgColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (shadowColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (shadowColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (shadowColor << 4) | fgColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (bgColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (bgColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (bgColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (fgColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (fgColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (fgColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (bgColor << 8) | (shadowColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (fgColor << 8) | (shadowColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; + + temp = (shadowColor << 8) | (shadowColor << 4) | shadowColor; + *(current++) = (bg12) | temp; + *(current++) = (fg12) | temp; + *(current++) = (shadow12) | temp; +} +#else +THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor) //TODO use asm preprocessor +{ + asm { + // push {r3-r7, lr} + sub sp, #0x30 + ldr r3, =UNK_021C570C + mov r5, #0x0 + str r5, [sp, #0x20] + str r0, [sp, #0x24] + str r2, [sp, #0x28] + str r1, [sp, #0x2c] + strh r1, [r3, #0x6] + strh r0, [r3, #0x2] + add r0, sp, #0x20 + strh r2, [r3, #0x4] + str r5, [sp, #0x14] + str r0, [sp, #0x8] + mov r12, r0 + mov lr, r0 + str r0, [sp, #0x18] + _0201C07E: + mov r0, #0x0 + str r0, [sp, #0x10] + ldr r0, [sp, #0x18] + str r0, [sp, #0x4] + ldr r0, [sp, #0x8] + ldr r0, [r0, #0x0] + str r0, [sp, #0x1c] + _0201C08C: + mov r0, #0x0 + str r0, [sp, #0xc] + mov r0, lr + str r0, [sp, #0x0] + ldr r0, [sp, #0x4] + ldr r0, [r0, #0x0] + lsl r7, r0, #0x4 + _0201C09A: + ldr r0, [sp, #0x0] + mov r3, #0x0 + ldr r0, [r0, #0x0] + mov r4, r12 + lsl r6, r0, #0x8 + _0201C0A4: + ldr r0, [r4, #0x0] + add r1, r7, #0x0 + lsl r0, r0, #0xc + orr r0, r6 + orr r1, r0 + ldr r0, [sp, #0x1c] + add r3, r3, #0x1 + add r2, r0, #0x0 + orr r2, r1 + lsl r1, r5, #0x1 + ldr r0, =UNK_021C5734 + add r5, r5, #0x1 + add r4, r4, #0x4 + strh r2, [r0, r1] + cmp r3, #0x4 + blt _0201C0A4 + ldr r0, [sp, #0x0] + add r0, r0, #0x4 + str r0, [sp, #0x0] + ldr r0, [sp, #0xc] + add r0, r0, #0x1 + str r0, [sp, #0xc] + cmp r0, #0x4 + blt _0201C09A + ldr r0, [sp, #0x4] + add r0, r0, #0x4 + str r0, [sp, #0x4] + ldr r0, [sp, #0x10] + add r0, r0, #0x1 + str r0, [sp, #0x10] + cmp r0, #0x4 + blt _0201C08C + ldr r0, [sp, #0x8] + add r0, r0, #0x4 + str r0, [sp, #0x8] + ldr r0, [sp, #0x14] + add r0, r0, #0x1 + str r0, [sp, #0x14] + cmp r0, #0x4 + blt _0201C07E + add sp, #0x30 + // pop {r3-r7, pc} + } +} +#endif -- cgit v1.2.3 From bc398f3c399b5211a8b8ed38702670df654c66db Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 12 Mar 2021 20:54:37 +0000 Subject: finished text.c --- arm9/src/text.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/text.c b/arm9/src/text.c index 8ec3efe8..6207d913 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -1,10 +1,11 @@ #include "text.h" #include "heap.h" #include "string16.h" +#include "MI_memory.h" const struct FontInfo *gFonts = NULL; -u8 UNK_021C5734[0x200]; +u16 UNK_021C5734[0x100]; u32 UNK_021C5714[8]; u8 UNK_021C570C[8]; @@ -12,13 +13,18 @@ extern u32 FUN_0200CA7C(void (*func)(u32, struct TextPrinter *), struct TextPrin extern struct TextPrinter *FUN_0201B6C8(void); extern void FUN_0200CAB4(u32 param0); -extern void FUN_0201C238(struct TextPrinter *printer); extern void FUN_0201C1A8(struct TextPrinter *printer); extern void CopyWindowToVram(u32 windowId); extern u32 FontFunc(u8 fontId, struct TextPrinter *printer); +extern void *FUN_02006BB0(u32 param0, u32 param1, u32 param2, struct TextPrinter **param3, u32 param4); + +extern u32 FUN_0201AB0C(u32 windowId); +extern void FUN_02019658(u32 param0, u32 param1, u32 param2, u32 param3, u32 param4, u32 param5, u32 param6, u32 param7, u32 param8, u32 param9); + + THUMB_FUNC void SetFontsPointer(const struct FontInfo *fonts) { gFonts = fonts; @@ -498,3 +504,61 @@ THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadow } } #endif + +THUMB_FUNC void DecompressGlyphTile(const u16 *src, u16 *dst) +{ + dst[0] = UNK_021C5734[(u32)src[0] >> 8]; + dst[1] = UNK_021C5734[(u8)src[0]]; + dst[2] = UNK_021C5734[(u32)src[1] >> 8]; + dst[3] = UNK_021C5734[(u8)src[1]]; + dst[4] = UNK_021C5734[(u32)src[2] >> 8]; + dst[5] = UNK_021C5734[(u8)src[2]]; + dst[6] = UNK_021C5734[(u32)src[3] >> 8]; + dst[7] = UNK_021C5734[(u8)src[3]]; + dst[8] = UNK_021C5734[(u32)src[4] >> 8]; + dst[9] = UNK_021C5734[(u8)src[4]]; + dst[10] = UNK_021C5734[(u32)src[5] >> 8]; + dst[11] = UNK_021C5734[(u8)src[5]]; + dst[12] = UNK_021C5734[(u32)src[6] >> 8]; + dst[13] = UNK_021C5734[(u8)src[6]]; + dst[14] = UNK_021C5734[(u32)src[7] >> 8]; + dst[15] = UNK_021C5734[(u8)src[7]]; +} + +THUMB_FUNC void FUN_0201C1A8(struct TextPrinter *printer) +{ + printer->Unk2C = NULL; +} + +THUMB_FUNC void *FUN_0201C1B0(void) +{ + void *res = AllocFromHeap(0, sizeof(struct TextPrinter) * 32); + struct TextPrinter *var; + void *tmp = FUN_02006BB0(14, 5, 0, &var, 0); + MIi_CpuCopy32((void *)var->printerTemplate.Unk20, res, sizeof(struct TextPrinter) * 32); //todo Unk20 can't be right here + FreeToHeap(tmp); + return res; +} + +THUMB_FUNC void FUN_0201C1EC(struct TextPrinter *printer, u32 param1, u32 param2, u32 param3) +{ +#pragma unused (param1, param2) + u32 windowId = printer->printerTemplate.windowId; + if (printer->Unk2C == NULL) + { + printer->Unk2C = FUN_0201C1B0(); + } + u32 r6 = (u32)printer->Unk2C + param3 * (sizeof(struct TextPrinter) * 8); + u32 r2 = ((FUN_0201AB0C(windowId) - 3) << 0x13) >> 0x10; + FUN_02019658(windowId, r6, 0, 0, 24, 32, r2, 0, 24, 32); +} + +THUMB_FUNC void FUN_0201C238(struct TextPrinter *printer) +{ + if (printer->Unk2C == NULL) + { + return; + } + FreeToHeap(printer->Unk2C); + printer->Unk2C = NULL; +} -- cgit v1.2.3