From 2f75767d00d7ab405b55f8114e9b7c0af2998f47 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 11 Jan 2023 16:12:37 -0800 Subject: [PATCH] Add CWordInstruction --- asm/Kyoto/Text/CTextExecuteBuffer.s | 8 ++++---- asm/Kyoto/Text/CWordInstruction.s | 8 ++++---- configure.py | 2 +- include/Kyoto/Text/CBlockInstruction.hpp | 13 ++++++++++++ include/Kyoto/Text/CDrawStringOptions.hpp | 1 + include/Kyoto/Text/CFontRenderState.hpp | 19 ++++++++++++++++-- include/Kyoto/Text/CSaveableState.hpp | 2 +- include/Kyoto/Text/CWordInstruction.hpp | 13 ++++++++++++ src/Kyoto/Text/CWordInstruction.cpp | 24 +++++++++++++++++++++++ 9 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 include/Kyoto/Text/CWordInstruction.hpp create mode 100644 src/Kyoto/Text/CWordInstruction.cpp diff --git a/asm/Kyoto/Text/CTextExecuteBuffer.s b/asm/Kyoto/Text/CTextExecuteBuffer.s index 4f3b93b7..45a61b8b 100644 --- a/asm/Kyoto/Text/CTextExecuteBuffer.s +++ b/asm/Kyoto/Text/CTextExecuteBuffer.s @@ -1158,10 +1158,10 @@ MoveWordLTR__18CTextExecuteBufferFv: /* 80302B34 002FFA94 7C 7E 1B 79 */ or. r30, r3, r3 /* 80302B38 002FFA98 41 82 00 1C */ beq .L_80302B54 /* 80302B3C 002FFA9C 3C 80 80 3E */ lis r4, __vt__12CInstruction@ha -/* 80302B40 002FFAA0 3C 60 80 3F */ lis r3, lbl_803ED8A8@ha +/* 80302B40 002FFAA0 3C 60 80 3F */ lis r3, __vt__16CWordInstruction@ha /* 80302B44 002FFAA4 38 04 9A 6C */ addi r0, r4, __vt__12CInstruction@l /* 80302B48 002FFAA8 90 1E 00 00 */ stw r0, 0(r30) -/* 80302B4C 002FFAAC 38 03 D8 A8 */ addi r0, r3, lbl_803ED8A8@l +/* 80302B4C 002FFAAC 38 03 D8 A8 */ addi r0, r3, __vt__16CWordInstruction@l /* 80302B50 002FFAB0 90 1E 00 00 */ stw r0, 0(r30) .L_80302B54: /* 80302B54 002FFAB4 3C 80 80 3D */ lis r4, lbl_803D6E90@ha @@ -1348,10 +1348,10 @@ StartNewWord__18CTextExecuteBufferFv: /* 80302DE8 002FFD48 7C 7F 1B 79 */ or. r31, r3, r3 /* 80302DEC 002FFD4C 41 82 00 1C */ beq .L_80302E08 /* 80302DF0 002FFD50 3C 80 80 3E */ lis r4, __vt__12CInstruction@ha -/* 80302DF4 002FFD54 3C 60 80 3F */ lis r3, lbl_803ED8A8@ha +/* 80302DF4 002FFD54 3C 60 80 3F */ lis r3, __vt__16CWordInstruction@ha /* 80302DF8 002FFD58 38 04 9A 6C */ addi r0, r4, __vt__12CInstruction@l /* 80302DFC 002FFD5C 90 1F 00 00 */ stw r0, 0(r31) -/* 80302E00 002FFD60 38 03 D8 A8 */ addi r0, r3, lbl_803ED8A8@l +/* 80302E00 002FFD60 38 03 D8 A8 */ addi r0, r3, __vt__16CWordInstruction@l /* 80302E04 002FFD64 90 1F 00 00 */ stw r0, 0(r31) .L_80302E08: /* 80302E08 002FFD68 3C 80 80 3D */ lis r4, lbl_803D6E90@ha diff --git a/asm/Kyoto/Text/CWordInstruction.s b/asm/Kyoto/Text/CWordInstruction.s index a6fe0f69..105692a8 100644 --- a/asm/Kyoto/Text/CWordInstruction.s +++ b/asm/Kyoto/Text/CWordInstruction.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803ED8A8 -lbl_803ED8A8: +.global __vt__16CWordInstruction +__vt__16CWordInstruction: # ROM: 0x3EA8A8 .4byte 0 .4byte 0 @@ -25,8 +25,8 @@ __dt__16CWordInstructionFv: /* 80305BF4 00302B54 93 E1 00 0C */ stw r31, 0xc(r1) /* 80305BF8 00302B58 7C 7F 1B 79 */ or. r31, r3, r3 /* 80305BFC 00302B5C 41 82 00 30 */ beq lbl_80305C2C -/* 80305C00 00302B60 3C 60 80 3F */ lis r3, lbl_803ED8A8@ha -/* 80305C04 00302B64 38 03 D8 A8 */ addi r0, r3, lbl_803ED8A8@l +/* 80305C00 00302B60 3C 60 80 3F */ lis r3, __vt__16CWordInstruction@ha +/* 80305C04 00302B64 38 03 D8 A8 */ addi r0, r3, __vt__16CWordInstruction@l /* 80305C08 00302B68 90 1F 00 00 */ stw r0, 0(r31) /* 80305C0C 00302B6C 41 82 00 10 */ beq lbl_80305C1C /* 80305C10 00302B70 3C 60 80 3E */ lis r3, __vt__12CInstruction@ha diff --git a/configure.py b/configure.py index 3d2ad531..661b7100 100755 --- a/configure.py +++ b/configure.py @@ -551,7 +551,7 @@ LIBS = [ "Kyoto/Text/CTextInstruction", ["Kyoto/Text/CTextParser", False], ["Kyoto/Text/CWordBreakTables", False], - "Kyoto/Text/CWordInstruction", + ["Kyoto/Text/CWordInstruction", False], ["Kyoto/Text/CBlockInstruction", True], ["Kyoto/Text/CFont", True], ["Kyoto/Graphics/CLight", True], diff --git a/include/Kyoto/Text/CBlockInstruction.hpp b/include/Kyoto/Text/CBlockInstruction.hpp index d1e97999..8ff4146e 100644 --- a/include/Kyoto/Text/CBlockInstruction.hpp +++ b/include/Kyoto/Text/CBlockInstruction.hpp @@ -27,6 +27,19 @@ public: void TestLargestFont(int monoW, int monoH, int baseline); void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const; + int GetOutputX() const { return x4_offsetX; } + int GetOutputY() const { return x8_offsetY; } + int GetOutputWidth() const { return xc_blockExtentX; } + int GetOutputHeight() const { return x10_blockExtentY; } + ETextDirection GetTextDirection() const { return x14_dir; } + EJustification GetJustification() const { return x18_justification; } + EVerticalJustification GetVerticalJustification() const { return x1c_vertJustification; } + int GetLargestFontWidth() const { return x20_largestMonoW; } + int GetLargestFontHeight() const { return x24_largestMonoH; } + int GetLineX() const { return x2c_lineX; } + int GetLineY() const { return x30_lineY; } + int GetLines() const { return x34_lineCount; } + private: int x4_offsetX; int x8_offsetY; diff --git a/include/Kyoto/Text/CDrawStringOptions.hpp b/include/Kyoto/Text/CDrawStringOptions.hpp index 47534f09..40e25652 100644 --- a/include/Kyoto/Text/CDrawStringOptions.hpp +++ b/include/Kyoto/Text/CDrawStringOptions.hpp @@ -10,6 +10,7 @@ public: CDrawStringOptions(); void SetTextDirection(ETextDirection dir) { x0_direction = dir; } + ETextDirection GetTextDirection() const { return x0_direction; } void SetPaletteEntry(int idx, uint color) { x4_colors[idx] = color; } private: ETextDirection x0_direction; diff --git a/include/Kyoto/Text/CFontRenderState.hpp b/include/Kyoto/Text/CFontRenderState.hpp index 86ad6b8b..68ae2e3e 100644 --- a/include/Kyoto/Text/CFontRenderState.hpp +++ b/include/Kyoto/Text/CFontRenderState.hpp @@ -6,6 +6,7 @@ #include "Kyoto/Text/TextCommon.hpp" class CBlockInstruction; +class CLineInstruction; class CFontRenderState { public: @@ -15,22 +16,36 @@ public: void SetColor(EColorType type, const CTextColor& color); void RefreshPalette(); CDrawStringOptions& GetOptions() { return x0_state.GetOptions(); } - const TToken< CRasterFont >& GetFont() { return x0_state.GetFont(); } + TToken< CRasterFont >& GetFont() { return x0_state.GetFont(); } rstl::vector< CTextColor >& GetColors() { return x0_state.GetColors(); } rstl::vector< bool >& GetOverride() { return x0_state.GetOverride(); } void SetLineSpacing(float spacing) { x0_state.SetLineSpacing(spacing); } void SetExtraLineSpace(int spacing) { x0_state.SetLineExtraSpace(spacing); } - void SetBlock(const CBlockInstruction* block) { x88_curBlock = const_cast(block); } + const CBlockInstruction* GetBlock() const { return x88_curBlock; } + void SetBlock(const CBlockInstruction* block) { + x88_curBlock = const_cast< CBlockInstruction* >(block); + } void SetX(int x) { xd4_curX = x; } int GetX() const { return xd4_curX; } void SetY(int y) { xd8_curY = y; } int GetY() const { return xd8_curY; } + const CLineInstruction* GetLine() const { return xdc_currentLineInst; } + bool IsFirstWordOnLine() const { return x108_lineInitialized; } + void SetFirstWordOnLine(bool v) { x108_lineInitialized = v; } + private: CSaveableState x0_state; CBlockInstruction* x88_curBlock; CDrawStringOptions x8c_drawOpts; int xd4_curX; int xd8_curY; + const CLineInstruction* xdc_currentLineInst; + uint xe0_; + uint xe4_; + rstl::vector< uint > xe8_; + rstl::vector< uchar > xf8_; + bool x108_lineInitialized; + rstl::list< CSaveableState > x10c_pushedStates; }; #endif // _CFONTRENDERSTATE diff --git a/include/Kyoto/Text/CSaveableState.hpp b/include/Kyoto/Text/CSaveableState.hpp index 55f4f124..2d58cbf3 100644 --- a/include/Kyoto/Text/CSaveableState.hpp +++ b/include/Kyoto/Text/CSaveableState.hpp @@ -14,7 +14,7 @@ public: bool IsFinishedLoading(); CDrawStringOptions& GetOptions() { return x0_drawStringOptions; } - const TToken& GetFont() const { return *x48_font; } + TToken& GetFont() { return *x48_font; } rstl::vector& GetColors() { return x54_colors; } rstl::vector& GetOverride() { return x64_colorOverrides; } void SetLineSpacing(float spacing) { x74_lineSpacing = spacing; } diff --git a/include/Kyoto/Text/CWordInstruction.hpp b/include/Kyoto/Text/CWordInstruction.hpp new file mode 100644 index 00000000..81856ea8 --- /dev/null +++ b/include/Kyoto/Text/CWordInstruction.hpp @@ -0,0 +1,13 @@ +#ifndef _CWORDINSTRUCTION +#define _CWORDINSTRUCTION + +#include "Kyoto/Text/CInstruction.hpp" + +class CWordInstruction : public CInstruction { +public: + void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const; + void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const; + void InvokeLTR(CFontRenderState& state) const; +}; + +#endif // _CWORDINSTRUCTION diff --git a/src/Kyoto/Text/CWordInstruction.cpp b/src/Kyoto/Text/CWordInstruction.cpp new file mode 100644 index 00000000..fe27a083 --- /dev/null +++ b/src/Kyoto/Text/CWordInstruction.cpp @@ -0,0 +1,24 @@ +#include "Kyoto/Text/CWordInstruction.hpp" + +#include "Kyoto/Text/CFontRenderState.hpp" +#include "Kyoto/Text/CRasterFont.hpp" +#include "Kyoto/Text/CBlockInstruction.hpp" +//#include "Kyoto/Text/CLineInstruction.hpp" + +void CWordInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const { + if (!state.IsFirstWordOnLine()) { + if (state.GetOptions().GetTextDirection() == kTD_Horizontal) { + InvokeLTR(state); + } + } else { + state.SetFirstWordOnLine(false); + } +} + +void CWordInstruction::PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const { + state.SetFirstWordOnLine(false); +} + +void CWordInstruction::InvokeLTR(CFontRenderState& state) const { + // TODO: Implement this +}