diff options
author | Akira Akashi <rubenru09@aol.com> | 2021-06-21 02:30:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-21 02:30:06 +0100 |
commit | d192b6951f54d1397ded3db03b5e486ec679ac6f (patch) | |
tree | ad606c5dd51de3e4df460887add66cd51566a4d7 /arm9/src | |
parent | f87cb8749a8a41f7e207b151c7d5e7d3668a58cf (diff) | |
parent | dc026c3c75898a9e3a0ea8533af4e02c5156ead6 (diff) |
Merge pull request #409 from remicalixte/unk_020023C0
decompile unk_020023C0.s into render_text.c
Diffstat (limited to 'arm9/src')
-rw-r--r-- | arm9/src/render_text.c | 502 | ||||
-rw-r--r-- | arm9/src/scrcmd_sound.c | 5 | ||||
-rw-r--r-- | arm9/src/text_02054590.c | 11 | ||||
-rw-r--r-- | arm9/src/unk_0201B8B8.c | 4 | ||||
-rw-r--r-- | arm9/src/unk_0206015C.c | 6 |
5 files changed, 513 insertions, 15 deletions
diff --git a/arm9/src/render_text.c b/arm9/src/render_text.c new file mode 100644 index 00000000..af0218c8 --- /dev/null +++ b/arm9/src/render_text.c @@ -0,0 +1,502 @@ +#include "global.h" +#include "render_text.h" +#include "game_init.h" +#include "string_util.h" +#include "text.h" +#include "unk_0201B8B8.h" + +u16 unk00; + +TextFlags gTextFlags; + +const u8 UNK_020ECB50[] = { 0, 1, 2, 1 }; + +extern const char *FUN_02002D94(u8, u16); +extern void PlaySE(u16); + +THUMB_FUNC u32 RenderText(struct TextPrinter *printer) +{ + + struct TextPrinterSubStruct *subStruct = + (struct TextPrinterSubStruct *)(&printer->subStructFields); + u16 currentChar; + + switch (printer->state) + { + case 0: + if (((gMain.heldKeys & 3) != 0 && subStruct->hasPrintBeenSpedUp != 0) || + (gMain.touchHeld != 0 && gTextFlags.unk0_4 != 0)) + { + printer->delayCounter = 0; + if (printer->textSpeedBottom != 0) + { + gTextFlags.unk0_6 = 1; + } + } + + if (printer->delayCounter && printer->textSpeedBottom) + { + printer->delayCounter--; + + if (gTextFlags.canABSpeedUpPrint != 0) + { + if ((gMain.newKeys & 3) || (gMain.touchNew != 0 && gTextFlags.unk0_4)) + { + subStruct->hasPrintBeenSpedUp = 1; + printer->delayCounter = 0; + } + } + + return 3; + } + + printer->delayCounter = printer->textSpeedBottom; + currentChar = *printer->printerTemplate.currentChar.raw; + printer->printerTemplate.currentChar.raw++; + + GF_ASSERT(currentChar != 0xF100); + + switch (currentChar) + { + case EOS: + return 1; + case 0xE000: + printer->printerTemplate.currentX = printer->printerTemplate.x; + s32 fontAttribute = GetFontAttribute(printer->printerTemplate.fontId, 1); + + printer->printerTemplate.currentY += + printer->printerTemplate.lineSpacing + fontAttribute; + + return 2; + + case 0xF0FD: + printer->printerTemplate.currentChar.raw++; + return 2; + case 0xFFFE: + printer->printerTemplate.currentChar.raw--; + switch ((u16)MsgArray_GetControlCode(printer->printerTemplate.currentChar.raw)) + { + case 0xFF00: + u16 field = (u16)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + if (field == 0xff) + { + u8 r2 = printer->printerTemplate.unk4; + printer->printerTemplate.unk4 = + (u8)((printer->printerTemplate.fgColor - 1) / 2 + 100); + + if (!(r2 >= 100 && r2 < 107)) + { + break; + } + + field = (u16)(r2 - 100); + } + else + { + if (field >= 0x64) + { + printer->printerTemplate.unk4 = (u8)field; + break; + } + } + + printer->printerTemplate.fgColor = (u8)(field * 2 + 1); + printer->printerTemplate.shadowColor = (u8)(field * 2 + 2); + + GenerateFontHalfRowLookupTable(printer->printerTemplate.fgColor, + printer->printerTemplate.bgColor, + printer->printerTemplate.shadowColor); + + break; + + case 0x200: + field = (u16)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + + FUN_0201C1EC(printer, + printer->printerTemplate.currentX, + printer->printerTemplate.currentY, + field); + if (printer->textSpeedTop != 0) + { + CopyWindowToVram(printer->printerTemplate.window); + } + + break; + case 0x201: + printer->delayCounter = (u8)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + printer->printerTemplate.currentChar.raw = + MsgArray_SkipControlCode(printer->printerTemplate.currentChar.raw); + printer->state = 6; + + return 3; + case 0x202: + printer->Unk2A = (u16)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + printer->printerTemplate.currentChar.raw = + MsgArray_SkipControlCode(printer->printerTemplate.currentChar.raw); + + return 3; + case 0x203: + printer->printerTemplate.currentX = (u8)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + break; + case 0x204: + printer->printerTemplate.currentY = (u8)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + break; + + case 0xFF01: + field = (u16)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + + switch (field) + { + case 100: + printer->printerTemplate.unk2 = 0; + printer->printerTemplate.unk3 = 0; + break; + case 200: + printer->printerTemplate.unk2 = 0xFFFC; + printer->printerTemplate.unk3 = 0; + break; + } + + break; + + case 0xFE06: + field = (u16)MsgArray_ControlCodeGetField( + printer->printerTemplate.currentChar.raw, 0); + if (field != 0xFE00) + { + if (field != 0xFE01) + { + break; + } + + printer->state = 2; + TextPrinterInitDownArrowCounters(printer); + printer->printerTemplate.currentChar.raw = MsgArray_SkipControlCode( + printer->printerTemplate.currentChar.raw); + + return 3; + } + + printer->state = 3; + TextPrinterInitDownArrowCounters(printer); + printer->printerTemplate.currentChar.raw = + MsgArray_SkipControlCode(printer->printerTemplate.currentChar.raw); + + return 3; + } + + printer->printerTemplate.currentChar.raw = + MsgArray_SkipControlCode(printer->printerTemplate.currentChar.raw); + return 2; + + case 0x25BC: + printer->state = 2; + TextPrinterInitDownArrowCounters(printer); + return 3; + + case 0x25BD: + printer->state = 3; + TextPrinterInitDownArrowCounters(printer); + return 3; + } + + const char *r5 = FUN_02002D94(subStruct->glyphId, currentChar); + CopyGlyphToWindow(printer->printerTemplate.window, + r5, + r5[0x80], + r5[0x81], + printer->printerTemplate.currentX, + printer->printerTemplate.currentY, + printer->printerTemplate.unk2); + + printer->printerTemplate.currentX += r5[0x80] + printer->printerTemplate.letterSpacing; + + return 0; + case 1: + if (TextPrinterWait(printer) != 0) + { + TextPrinterClearDownArrow(printer); + + printer->state = 0; + } + + return 3; + case 2: + if (TextPrinterWaitWithDownArrow(printer) != 0) + { + TextPrinterClearDownArrow(printer); + FillWindowPixelBuffer( + printer->printerTemplate.window, printer->printerTemplate.bgColor); + printer->printerTemplate.currentX = printer->printerTemplate.x; + printer->printerTemplate.currentY = printer->printerTemplate.y; + printer->state = 0; + } + + return 3; + case 3: + if (TextPrinterWaitWithDownArrow(printer) != 0) + { + TextPrinterClearDownArrow(printer); + printer->scrollDistance = + (u8)(GetFontAttribute(printer->printerTemplate.fontId, 1) + + printer->printerTemplate.lineSpacing); + printer->printerTemplate.currentX = printer->printerTemplate.x; + printer->state = 4; + } + + return 3; + case 4: + if (printer->scrollDistance != 0) + { + if ((int)printer->scrollDistance < 4) + { + ScrollWindow(printer->printerTemplate.window, + 0, + printer->scrollDistance, + (u8)(printer->printerTemplate.bgColor | + (printer->printerTemplate.bgColor << 4))); + printer->scrollDistance = 0; + } + else + { + ScrollWindow(printer->printerTemplate.window, + 0, + 4, + (u8)(printer->printerTemplate.bgColor | + (printer->printerTemplate.bgColor << 4))); + + printer->scrollDistance -= 4; + } + + CopyWindowToVram(printer->printerTemplate.window); + } + else + { + printer->state = 0; + } + + return 3; + case 5: + printer->state = 0; + return 3; + case 6: + if (printer->delayCounter != 0) + { + printer->delayCounter--; + } + else + { + printer->state = 0; + } + + return 3; + } + + return 1; +} + +THUMB_FUNC void FUN_02002840(u16 flag) +{ + unk00 = flag; +} + +THUMB_FUNC void TextPrinterInitDownArrowCounters(struct TextPrinter *printer) +{ + struct TextPrinterSubStruct *subStruct = + (struct TextPrinterSubStruct *)(&printer->subStructFields); + + if (gTextFlags.autoScroll) + { + subStruct->autoScrollDelay = 0; + return; + } + + subStruct->downArrowYPosIdx = 0; + subStruct->downArrowDelay = 0; +} + +THUMB_FUNC void TextPrinterDrawDownArrow(struct TextPrinter *printer) +{ + struct TextPrinterSubStruct *subStruct = + (struct TextPrinterSubStruct *)(&printer->subStructFields); + + if (gTextFlags.autoScroll) + { + return; + } + + if (subStruct->downArrowDelay != 0) + { + subStruct->downArrowDelay--; + return; + } + + u8 bg_id = GetWindowBgId(printer->printerTemplate.window); + u8 x = GetWindowX(printer->printerTemplate.window); + u8 y = GetWindowY(printer->printerTemplate.window); + u8 width = GetWindowWidth(printer->printerTemplate.window); + u16 r6 = unk00; + + FillBgTilemapRect(printer->printerTemplate.window->bgConfig, + bg_id, + (u16)(r6 + 18 + UNK_020ECB50[subStruct->downArrowYPosIdx] * 4), + (u8)(x + width + 1), + (u8)(y + 2), + 1, + 1, + 0x10); + + FillBgTilemapRect(printer->printerTemplate.window->bgConfig, + bg_id, + (u16)(r6 + 19 + UNK_020ECB50[subStruct->downArrowYPosIdx] * 4), + (u8)(x + width + 2), + (u8)(y + 2), + 1, + 1, + 0x10); + FillBgTilemapRect(printer->printerTemplate.window->bgConfig, + bg_id, + (u16)(r6 + 20 + UNK_020ECB50[subStruct->downArrowYPosIdx] * 4), + (u8)(x + width + 1), + (u8)(y + 3), + 1, + 1, + 0x10); + FillBgTilemapRect(printer->printerTemplate.window->bgConfig, + bg_id, + (u16)(r6 + 21 + UNK_020ECB50[subStruct->downArrowYPosIdx] * 4), + (u8)(x + width + 2), + (u8)(y + 3), + 1, + 1, + 0x10); + + BgCommitTilemapBufferToVram(printer->printerTemplate.window->bgConfig, bg_id); + subStruct->downArrowDelay = 8; + subStruct->downArrowYPosIdx++; +} + +THUMB_FUNC void TextPrinterClearDownArrow(struct TextPrinter *printer) +{ + u8 bg_id = GetWindowBgId(printer->printerTemplate.window); + u8 x = GetWindowX(printer->printerTemplate.window); + u8 y = GetWindowY(printer->printerTemplate.window); + u8 width = GetWindowWidth(printer->printerTemplate.window); + u16 r6 = unk00; + + FillBgTilemapRect(printer->printerTemplate.window->bgConfig, + bg_id, + (u16)(r6 + 10), + (u8)(x + width + 1), + (u8)(y + 2), + 1, + 2, + 0x10); + FillBgTilemapRect(printer->printerTemplate.window->bgConfig, + bg_id, + (u16)(r6 + 11), + (u8)(x + width + 2), + (u8)(y + 2), + 1, + 2, + 0x10); + BgCommitTilemapBufferToVram(printer->printerTemplate.window->bgConfig, bg_id); +} + +THUMB_FUNC BOOL TextPrinterContinue(struct TextPrinter *printer) +{ +#pragma unused(printer) + if ((gMain.newKeys & 3) != 0 || (gMain.touchNew != 0 && gTextFlags.unk0_4 != 0)) + { + PlaySE(0x5DC); + + gTextFlags.unk0_7 = 1; + + return TRUE; + } + + return FALSE; +} + +THUMB_FUNC BOOL TextPrinterWaitAutoMode(struct TextPrinter *printer) +{ + struct TextPrinterSubStruct *subStruct = + (struct TextPrinterSubStruct *)(&printer->subStructFields); + + if (subStruct->autoScrollDelay == 100) + { + return TRUE; + } + + subStruct->autoScrollDelay++; + if (gTextFlags.unk0_5) + { + return TextPrinterContinue(printer); + } + + return FALSE; +} + +THUMB_FUNC BOOL TextPrinterWaitWithDownArrow(struct TextPrinter *printer) +{ + if (gTextFlags.autoScroll) + { + return TextPrinterWaitAutoMode(printer); + } + TextPrinterDrawDownArrow(printer); + + return TextPrinterContinue(printer); +} + +THUMB_FUNC u8 TextPrinterWait(struct TextPrinter *printer) +{ + if (gTextFlags.autoScroll) + { + return (u8)TextPrinterWaitAutoMode(printer); + } + + return (u8)TextPrinterContinue(printer); +} + +THUMB_FUNC void TextFlags_SetCanABSpeedUpPrint(BOOL param0) +{ + gTextFlags.canABSpeedUpPrint = param0; +} + +THUMB_FUNC void FUN_02002B7C(s32 param0) +{ + gTextFlags.autoScroll = param0 & 1; + gTextFlags.unk0_5 = (param0 >> 1) & 1; +} + +THUMB_FUNC void FUN_02002BB8(u32 param0) +{ + gTextFlags.unk0_4 = param0; +} + +THUMB_FUNC u8 FUN_02002BD4() +{ + return gTextFlags.unk0_6; +} + +THUMB_FUNC void FUN_02002BE4() +{ + gTextFlags.unk0_6 = 0; +} + +THUMB_FUNC u8 FUN_02002BF4() +{ + return gTextFlags.unk0_7; +} + +THUMB_FUNC void FUN_02002C04() +{ + gTextFlags.unk0_7 = 0; +} diff --git a/arm9/src/scrcmd_sound.c b/arm9/src/scrcmd_sound.c index ec5ab7f8..1251c612 100644 --- a/arm9/src/scrcmd_sound.c +++ b/arm9/src/scrcmd_sound.c @@ -18,7 +18,7 @@ extern void FUN_0200538C(u32, u16, u32); extern void FUN_020053CC(u16, u16); extern BOOL FUN_02005404(void); extern u16 FUN_02005410(u16); -extern void FUN_020054C8(u16); +extern void PlaySE(u16); extern void FUN_020054F0(u16, u32); extern void FUN_020047C8(u8, u8); extern void FUN_020040F4(u8); @@ -123,7 +123,7 @@ THUMB_FUNC BOOL ScrCmd_Unk0058(struct ScriptContext* ctx) THUMB_FUNC BOOL ScrCmd_PlayFanfare(struct ScriptContext* ctx) { u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); - FUN_020054C8(unk); + PlaySE(unk); return FALSE; } @@ -263,4 +263,3 @@ THUMB_FUNC BOOL ScrCmd_SetVolume(struct ScriptContext* ctx) return FALSE; } - diff --git a/arm9/src/text_02054590.c b/arm9/src/text_02054590.c index d4984f78..f5527257 100644 --- a/arm9/src/text_02054590.c +++ b/arm9/src/text_02054590.c @@ -1,6 +1,7 @@ #include "text_02054590.h" #include "text.h" #include "bg_window.h" +#include "render_text.h" extern void FUN_0201BD5C(void); extern void FUN_02002ED0(u32 param0, u32 param1, u32 param2); @@ -10,10 +11,6 @@ extern void FUN_0200CD68( struct BgConfig *param0, u32 param1, u32 param2, u32 param3, u8 param4, u32 param5); extern void FUN_0200D0BC(struct Window *param0, u32 param1, u32 param2, u32 param3); -extern void FUN_02002B60(u8 param0); -extern void FUN_02002B7C(u32 param0); -extern void FUN_02002BB8(u32 param0); - extern void FUN_0200D300(struct BgConfig *param0, u32 param1, u32 param2, @@ -59,15 +56,15 @@ THUMB_FUNC void FUN_0205464C(struct Window *param0) THUMB_FUNC u16 FUN_02054658(struct Window * window, struct String *str, struct Options *options, u8 param3) { - FUN_02002B60(param3); + TextFlags_SetCanABSpeedUpPrint(param3); FUN_02002B7C(0); FUN_02002BB8(0); return AddTextPrinterParameterized(window, 1, str, 0, 0, (u32)Options_GetTextFrameDelay(options), NULL); } -THUMB_FUNC u16 DrawFieldMessage(struct Window * window, struct String *str, u8 fontId, u32 speed, u8 a4, u32 a5) +THUMB_FUNC u16 DrawFieldMessage(struct Window * window, struct String *str, u8 fontId, u32 speed, u8 a4, s32 a5) { - FUN_02002B60(a4); + TextFlags_SetCanABSpeedUpPrint(a4); FUN_02002B7C(a5); FUN_02002BB8(0); return AddTextPrinterParameterized(window, fontId, str, 0, 0, speed, NULL); diff --git a/arm9/src/unk_0201B8B8.c b/arm9/src/unk_0201B8B8.c index c7f77f87..b8e978f2 100644 --- a/arm9/src/unk_0201B8B8.c +++ b/arm9/src/unk_0201B8B8.c @@ -14,7 +14,7 @@ const u16 * MsgArray_SkipControlCode(const u16 * r4) return r4; } -u16 MsgArray_GetControlCode(const u16 * r4) +u32 MsgArray_GetControlCode(const u16 * r4) { GF_ASSERT(*r4 == 0xFFFE); return r4[1]; @@ -25,7 +25,7 @@ BOOL MsgArray_ControlCodeIsStrVar(const u16 * r4) return (MsgArray_GetControlCode(r4) & 0xFF00) == 0x100; } -u16 MsgArray_ControlCodeGetField(const u16 * r5, u32 r4) +u32 MsgArray_ControlCodeGetField(const u16 * r5, u32 r4) { GF_ASSERT(*r5 == 0xFFFE); GF_ASSERT(r4 < r5[2]); diff --git a/arm9/src/unk_0206015C.c b/arm9/src/unk_0206015C.c index a217f52c..0bf3a15a 100644 --- a/arm9/src/unk_0206015C.c +++ b/arm9/src/unk_0206015C.c @@ -21,7 +21,7 @@ extern THUMB_FUNC void MOD06_02245190(u32); extern THUMB_FUNC void MOD06_02245198(u8, u32); extern THUMB_FUNC u32 MOD06_022451F0(u32); -extern THUMB_FUNC void FUN_020054C8(u32); +extern THUMB_FUNC void PlaySE(u32); extern THUMB_FUNC void FUN_02049160(struct UnkStruct_0204639C*, u32); extern THUMB_FUNC void FUN_0204AF84(struct UnkStruct_0204639C*); extern THUMB_FUNC void FUN_0204AF3C(struct UnkStruct_0204639C *); @@ -97,7 +97,7 @@ THUMB_FUNC BOOL FUN_02060194(struct UnkStruct_0204639C *unkStruct0) MOD06_02244DC4(unkStruct1->unk0, unkAddr); MOD06_02244EF8(unkStruct1->unk0); unkStruct1->unkE = 0; - FUN_020054C8(1657); + PlaySE(1657); FUN_0204C1B4(unkStruct0, 0x3, 0x11, 0x0000FFFF, 0, 6, 1, 0xb); unkStruct1->action = 5; } @@ -117,7 +117,7 @@ THUMB_FUNC BOOL FUN_02060194(struct UnkStruct_0204639C *unkStruct0) MOD06_02245198(unkStruct1->unkD, unkStruct1->unk4); unkStruct1->unk8 = MOD06_022451F0(unkStruct1->unk4); - FUN_020054C8(1657); + PlaySE(1657); FUN_0204C1B4(unkStruct0, 0x3, 0x10, 0x0000FFFF, 0, 6, 1, 0xb); unkStruct1->action = 6; break; |