From 4e754e9163f3569149b99b8d5da345e67ae7cbb0 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 29 Sep 2022 21:24:13 -0700 Subject: [PATCH] Minor fixes, start CTextParser Former-commit-id: e39a8e4c47d5d09c8aa322c4a6532819258c83e1 --- asm/Kyoto/Alloc/CMemory.s | 20 ++--- asm/Kyoto/Text/CTextExecuteBuffer.s | 16 ++-- asm/Kyoto/Text/CTextParser.s | 18 ++--- include/Kyoto/Text/CTextColor.hpp | 17 ++++ include/Kyoto/Text/CTextExecuteBuffer.hpp | 8 ++ include/Kyoto/Text/CTextParser.hpp | 30 +++++++ src/Kyoto/Text/CTextParser.cpp | 99 +++++++++++++++++++++++ 7 files changed, 180 insertions(+), 28 deletions(-) create mode 100644 include/Kyoto/Text/CTextColor.hpp create mode 100644 include/Kyoto/Text/CTextExecuteBuffer.hpp create mode 100644 include/Kyoto/Text/CTextParser.hpp create mode 100644 src/Kyoto/Text/CTextParser.cpp diff --git a/asm/Kyoto/Alloc/CMemory.s b/asm/Kyoto/Alloc/CMemory.s index aececa2f..ec268f5c 100644 --- a/asm/Kyoto/Alloc/CMemory.s +++ b/asm/Kyoto/Alloc/CMemory.s @@ -24,11 +24,11 @@ mpAllocator__7CMemory: .global lbl_805A9460 lbl_805A9460: .skip 0x4 -.global lbl_805A9464 -lbl_805A9464: +.global gLeakCount +gLeakCount: .skip 0x4 -.global lbl_805A9468 -lbl_805A9468: +.global gLeakBytes +gLeakBytes: .skip 0x8 .section .text, "ax" @@ -206,10 +206,10 @@ Shutdown__7CMemoryFv: /* 80315A68 003129C8 38 00 00 00 */ li r0, 0 /* 80315A6C 003129CC 3C 60 80 31 */ lis r3, cmemory_enum_alloc_cb__FRCQ210IAllocator10SAllocInfoPCv@ha /* 80315A70 003129D0 38 83 5A BC */ addi r4, r3, cmemory_enum_alloc_cb__FRCQ210IAllocator10SAllocInfoPCv@l -/* 80315A74 003129D4 90 0D A8 A4 */ stw r0, lbl_805A9464@sda21(r13) +/* 80315A74 003129D4 90 0D A8 A4 */ stw r0, gLeakCount@sda21(r13) /* 80315A78 003129D8 80 6D 9C A8 */ lwz r3, mpAllocator__7CMemory@sda21(r13) /* 80315A7C 003129DC 38 A0 00 00 */ li r5, 0 -/* 80315A80 003129E0 90 0D A8 A8 */ stw r0, lbl_805A9468@sda21(r13) +/* 80315A80 003129E0 90 0D A8 A8 */ stw r0, gLeakBytes@sda21(r13) /* 80315A84 003129E4 38 C0 00 00 */ li r6, 0 /* 80315A88 003129E8 81 83 00 00 */ lwz r12, 0(r3) /* 80315A8C 003129EC 81 8C 00 30 */ lwz r12, 0x30(r12) @@ -234,13 +234,13 @@ cmemory_enum_alloc_cb__FRCQ210IAllocator10SAllocInfoPCv: /* 80315AC8 00312A28 88 03 00 09 */ lbz r0, 9(r3) /* 80315ACC 00312A2C 28 00 00 00 */ cmplwi r0, 0 /* 80315AD0 00312A30 40 82 00 20 */ bne lbl_80315AF0 -/* 80315AD4 00312A34 80 AD A8 A4 */ lwz r5, lbl_805A9464@sda21(r13) -/* 80315AD8 00312A38 80 8D A8 A8 */ lwz r4, lbl_805A9468@sda21(r13) +/* 80315AD4 00312A34 80 AD A8 A4 */ lwz r5, gLeakCount@sda21(r13) +/* 80315AD8 00312A38 80 8D A8 A8 */ lwz r4, gLeakBytes@sda21(r13) /* 80315ADC 00312A3C 80 03 00 04 */ lwz r0, 4(r3) /* 80315AE0 00312A40 38 65 00 01 */ addi r3, r5, 1 -/* 80315AE4 00312A44 90 6D A8 A4 */ stw r3, lbl_805A9464@sda21(r13) +/* 80315AE4 00312A44 90 6D A8 A4 */ stw r3, gLeakCount@sda21(r13) /* 80315AE8 00312A48 7C 04 02 14 */ add r0, r4, r0 -/* 80315AEC 00312A4C 90 0D A8 A8 */ stw r0, lbl_805A9468@sda21(r13) +/* 80315AEC 00312A4C 90 0D A8 A8 */ stw r0, gLeakBytes@sda21(r13) lbl_80315AF0: /* 80315AF0 00312A50 38 60 00 01 */ li r3, 1 /* 80315AF4 00312A54 4E 80 00 20 */ blr diff --git a/asm/Kyoto/Text/CTextExecuteBuffer.s b/asm/Kyoto/Text/CTextExecuteBuffer.s index 0c134602..c07997a4 100644 --- a/asm/Kyoto/Text/CTextExecuteBuffer.s +++ b/asm/Kyoto/Text/CTextExecuteBuffer.s @@ -1256,7 +1256,7 @@ StartNewLine__18CTextExecuteBufferFv: /* 80302C90 002FFBF0 80 03 00 A4 */ lwz r0, 0xa4(r3) /* 80302C94 002FFBF4 28 00 00 00 */ cmplwi r0, 0 /* 80302C98 002FFBF8 41 82 00 08 */ beq lbl_80302CA0 -/* 80302C9C 002FFBFC 48 00 02 05 */ bl sub_80302ea0 +/* 80302C9C 002FFBFC 48 00 02 05 */ bl TerminateLine__18CTextExecuteBufferFv lbl_80302CA0: /* 80302CA0 002FFC00 3C 80 80 3D */ lis r4, lbl_803D6E90@ha /* 80302CA4 002FFC04 38 60 00 34 */ li r3, 0x34 @@ -1394,8 +1394,8 @@ lbl_80302E30: /* 80302E98 002FFDF8 38 21 00 20 */ addi r1, r1, 0x20 /* 80302E9C 002FFDFC 4E 80 00 20 */ blr -.global sub_80302ea0 -sub_80302ea0: +.global TerminateLine__18CTextExecuteBufferFv +TerminateLine__18CTextExecuteBufferFv: /* 80302EA0 002FFE00 94 21 FF F0 */ stwu r1, -0x10(r1) /* 80302EA4 002FFE04 7C 08 02 A6 */ mflr r0 /* 80302EA8 002FFE08 90 01 00 14 */ stw r0, 0x14(r1) @@ -1477,8 +1477,8 @@ lbl_80302FA0: /* 80302FB8 002FFF18 38 21 00 30 */ addi r1, r1, 0x30 /* 80302FBC 002FFF1C 4E 80 00 20 */ blr -.global __ct__20CPopStateInstructionFv -__ct__20CPopStateInstructionFv: +.global AddPopState__18CTextExecuteBufferFv +AddPopState__18CTextExecuteBufferFv: /* 80302FC0 002FFF20 94 21 FF E0 */ stwu r1, -0x20(r1) /* 80302FC4 002FFF24 7C 08 02 A6 */ mflr r0 /* 80302FC8 002FFF28 3C 80 80 3D */ lis r4, lbl_803D6E90@ha @@ -1541,8 +1541,8 @@ lbl_80303088: /* 803030A0 00300000 38 21 00 20 */ addi r1, r1, 0x20 /* 803030A4 00300004 4E 80 00 20 */ blr -.global __ct__21CPushStateInstructionFv -__ct__21CPushStateInstructionFv: +.global AddPushState__18CTextExecuteBufferFv +AddPushState__18CTextExecuteBufferFv: /* 803030A8 00300008 94 21 FF E0 */ stwu r1, -0x20(r1) /* 803030AC 0030000C 7C 08 02 A6 */ mflr r0 /* 803030B0 00300010 3C 80 80 3D */ lis r4, lbl_803D6E90@ha @@ -2282,7 +2282,7 @@ EndBlock__18CTextExecuteBufferFv: /* 80303B3C 00300A9C 80 03 00 A4 */ lwz r0, 0xa4(r3) /* 80303B40 00300AA0 28 00 00 00 */ cmplwi r0, 0 /* 80303B44 00300AA4 41 82 00 08 */ beq lbl_80303B4C -/* 80303B48 00300AA8 4B FF F3 59 */ bl sub_80302ea0 +/* 80303B48 00300AA8 4B FF F3 59 */ bl TerminateLine__18CTextExecuteBufferFv lbl_80303B4C: /* 80303B4C 00300AAC 38 00 00 00 */ li r0, 0 /* 80303B50 00300AB0 90 1F 00 A4 */ stw r0, 0xa4(r31) diff --git a/asm/Kyoto/Text/CTextParser.s b/asm/Kyoto/Text/CTextParser.s index a30e8a9d..a25506ab 100644 --- a/asm/Kyoto/Text/CTextParser.s +++ b/asm/Kyoto/Text/CTextParser.s @@ -694,7 +694,7 @@ lbl_80304C24: /* 80304C3C 00301B9C 54 60 06 3F */ clrlwi. r0, r3, 0x18 /* 80304C40 00301BA0 41 82 00 10 */ beq lbl_80304C50 /* 80304C44 00301BA4 7F A3 EB 78 */ mr r3, r29 -/* 80304C48 00301BA8 4B FF E4 61 */ bl __ct__21CPushStateInstructionFv +/* 80304C48 00301BA8 4B FF E4 61 */ bl AddPushState__18CTextExecuteBufferFv /* 80304C4C 00301BAC 48 00 00 44 */ b lbl_80304C90 lbl_80304C50: /* 80304C50 00301BB0 3C 80 80 3F */ lis r4, lbl_803ED718@ha @@ -706,7 +706,7 @@ lbl_80304C50: /* 80304C68 00301BC8 54 60 06 3F */ clrlwi. r0, r3, 0x18 /* 80304C6C 00301BCC 41 82 00 10 */ beq lbl_80304C7C /* 80304C70 00301BD0 7F A3 EB 78 */ mr r3, r29 -/* 80304C74 00301BD4 4B FF E3 4D */ bl __ct__20CPopStateInstructionFv +/* 80304C74 00301BD4 4B FF E3 4D */ bl AddPopState__18CTextExecuteBufferFv /* 80304C78 00301BD8 48 00 00 18 */ b lbl_80304C90 lbl_80304C7C: /* 80304C7C 00301BDC 7F 83 E3 78 */ mr r3, r28 @@ -1655,7 +1655,7 @@ lbl_8030598C: .global lbl_805AE478 lbl_805AE478: # ROM: 0x3FAD18 - .4byte 0x42C80000 + .float 100.0 .4byte 0 .global lbl_805AE480 @@ -1667,7 +1667,6 @@ lbl_805AE480: lbl_805AE488: # ROM: 0x3FAD28 .float 1.0 - .4byte 0 .section .rodata @@ -1676,10 +1675,9 @@ lbl_805AE488: lbl_803D6EA0: # ROM: 0x3D3EA0 .asciz "%02x%02x%02x%02x" - .byte 0x3F, 0x3F, 0x28 - .4byte 0x3F3F2900 - .4byte 0x2C004100 - .4byte 0x53410053 - .4byte 0x49000000 - .4byte 0 + .asciz "??(??)" + .asciz "," + .asciz "A" + .asciz "SA" + .asciz "SI" diff --git a/include/Kyoto/Text/CTextColor.hpp b/include/Kyoto/Text/CTextColor.hpp new file mode 100644 index 00000000..f87cb836 --- /dev/null +++ b/include/Kyoto/Text/CTextColor.hpp @@ -0,0 +1,17 @@ +#ifndef __CTEXTCOLOR_HPP__ +#define __CTEXTCOLOR_HPP__ + +#include + +class CTextColor { +public: + CTextColor(uchar r, uchar g, uchar b, uchar a) + : mR(r), mG(g), mB(b), mA(a) {} +private: + uchar mR; + uchar mG; + uchar mB; + uchar mA; +}; + +#endif \ No newline at end of file diff --git a/include/Kyoto/Text/CTextExecuteBuffer.hpp b/include/Kyoto/Text/CTextExecuteBuffer.hpp new file mode 100644 index 00000000..a609ee42 --- /dev/null +++ b/include/Kyoto/Text/CTextExecuteBuffer.hpp @@ -0,0 +1,8 @@ +#ifndef __CTEXTEXECUTEBUFFER_HPP__ +#define __CTEXTEXECUTEBUFFER_HPP__ + +class CTextExecuteBuffer { + +}; + +#endif \ No newline at end of file diff --git a/include/Kyoto/Text/CTextParser.hpp b/include/Kyoto/Text/CTextParser.hpp new file mode 100644 index 00000000..aa89c97f --- /dev/null +++ b/include/Kyoto/Text/CTextParser.hpp @@ -0,0 +1,30 @@ +#ifndef __CTEXTPARSER_HPP__ +#define __CTEXTPARSER_HPP__ + +#include +#include + +#include + +class IObjectStore; +class CTextExecuteBuffer; +class CTextParser { +public: + CTextParser(IObjectStore& store); + void ParseText(CTextExecuteBuffer&, const wchar_t* str, int len); + uint GetAssetIdFromString(const rstl::string& str); + uint GetFont(const wchar_t* str, int len); + uint GetImage(const wchar_t* str, int len); + uint HandleUserTag(CTextExecuteBuffer& buffer, const wchar_t* str, int len); + void ParseTag(CTextExecuteBuffer&, const wchar_t* str, int len); + static bool BeginsWith(const wchar_t* str1, int len, const wchar_t* str2); + static bool Equals(const wchar_t* str1, int len, const wchar_t* str2); + static uint ParseInt(const wchar_t* str, int len, bool); + static uint FromHex(wchar_t c); + static uint GetColorValue(const wchar_t* str); + CTextColor ParseColor(const wchar_t* str, int len); +private: + IObjectStore& mObjectStore; +}; + +#endif \ No newline at end of file diff --git a/src/Kyoto/Text/CTextParser.cpp b/src/Kyoto/Text/CTextParser.cpp new file mode 100644 index 00000000..ffeae001 --- /dev/null +++ b/src/Kyoto/Text/CTextParser.cpp @@ -0,0 +1,99 @@ +#include + +#include +#include + +CTextParser::CTextParser(IObjectStore& store) +: mObjectStore(store) {} + +void CTextParser::ParseText(CTextExecuteBuffer& buffer, const wchar_t* str, int len) { +} + +uint CTextParser::GetAssetIdFromString(const rstl::string& str) { + +} + +uint CTextParser::GetFont(const wchar_t* str, int len) { + return -1; +} + +uint CTextParser::GetImage(const wchar_t* str, int len) { + return -1; +} + +uint CTextParser::HandleUserTag(CTextExecuteBuffer& buffer, const wchar_t* string, int len) { + return 0; +} + +void CTextParser::ParseTag(CTextExecuteBuffer& buffer, const wchar_t* string, int len) { + +} + +bool CTextParser::BeginsWith(const wchar_t* str1, int len, const wchar_t* str2) { + int i = 0; + for (; str2[i] != L'\x0' && i < len; ++i) { + if (str1[i] != str2[i]) { + return false; + } + } + + return str2[i] == L'\x0'; +} + +bool CTextParser::Equals(const wchar_t* str1, int len, const wchar_t* str2) { + int i = 0; + for (;str2[i] != L'\x0' && i < len; ++i) { + if (str1[i] != str2[i]) { + return false; + } + } + + return str2[i] == L'\x0'; +} + +uint CTextParser::ParseInt(const wchar_t* str, int len, bool signVal) { + bool neg = false; + int procCur = 0; + if (signVal && len > 0 && *str == L'-') { + neg = true; + procCur = 1; + } + + int val = 0; + while (len > procCur) { + val *= 10; + wchar_t ch = str[procCur]; + val += ch - L'0'; + ++procCur; + } + + return neg ? -val : val; +} + +uint CTextParser::FromHex(wchar_t ch) { + if (ch >= L'0' && ch <= L'9') + return ch - L'0'; + + if (ch >= L'A' && ch <= L'F') + return ch - L'A' + 10; + + if (ch >= L'a' && ch <= L'f') + return ch - L'a' + 10; + + return 0; +} + +uint CTextParser::GetColorValue(const wchar_t* str) { + uint a = (FromHex(str[0]) << 4); + uint b = FromHex(str[1]); + return b + a; +} + +CTextColor CTextParser::ParseColor(const wchar_t* str, int len) { + uint r = GetColorValue(str + 1); + uint g = GetColorValue(str + 3); + uint b = GetColorValue(str + 5); + uint a = len == 9 ? GetColorValue(str + 7) : 255; + + return CTextColor(r, g, b, a); +}