From ac0e3ef534f1607f99f53b93d2a592ae9f4f7cca Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 8 Oct 2022 23:55:24 -0700 Subject: [PATCH] Match CConsoleOutputWindow, regswaps in constructor Former-commit-id: 27bd20ff1daa1fdfd0557197aaeefbb1e9f8ca89 --- asm/MetroidPrime/CConsoleOutputWindow.s | 30 +++++------ include/Kyoto/Text/CFont.hpp | 14 +++++ include/MetroidPrime/CArchMsgParmReal32.hpp | 5 +- include/MetroidPrime/CArchitectureMessage.hpp | 3 ++ include/MetroidPrime/CConsoleOutputWindow.hpp | 18 +++++-- include/MetroidPrime/Decode.hpp | 15 ++++++ src/MetroidPrime/CConsoleOutputWindow.cpp | 52 +++++++++++++++++++ 7 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 include/Kyoto/Text/CFont.hpp create mode 100644 include/MetroidPrime/Decode.hpp create mode 100644 src/MetroidPrime/CConsoleOutputWindow.cpp diff --git a/asm/MetroidPrime/CConsoleOutputWindow.s b/asm/MetroidPrime/CConsoleOutputWindow.s index 6be237d5..d43a256a 100644 --- a/asm/MetroidPrime/CConsoleOutputWindow.s +++ b/asm/MetroidPrime/CConsoleOutputWindow.s @@ -1,5 +1,16 @@ .include "macros.inc" +.section .rodata +.balign 8 +.global lbl_803CEE00 +lbl_803CEE00: + # ROM: 0x3CBE00 + .asciz "ConsoleOutputWindow" + .4byte 0x003F3F28 + .4byte 0x3F3F2900 + .4byte 0 + + .section .data .balign 8 @@ -32,8 +43,8 @@ lbl_805A7544: .balign 8 # CConsoleOutputWindow -.global lbl_805A8F00 -lbl_805A8F00: +.global mInstance__20CConsoleOutputWindow +mInstance__20CConsoleOutputWindow: .skip 0x8 .section .sdata2, "a" @@ -139,7 +150,7 @@ __dt__20CConsoleOutputWindowFv: /* 800FE988 000FB8E8 38 63 FE 50 */ addi r3, r3, lbl_803DFE50@l /* 800FE98C 000FB8EC 38 00 00 00 */ li r0, 0 /* 800FE990 000FB8F0 90 7E 00 00 */ stw r3, 0(r30) -/* 800FE994 000FB8F4 90 0D A3 40 */ stw r0, lbl_805A8F00@sda21(r13) +/* 800FE994 000FB8F4 90 0D A3 40 */ stw r0, mInstance__20CConsoleOutputWindow@sda21(r13) /* 800FE998 000FB8F8 41 82 00 44 */ beq lbl_800FE9DC /* 800FE99C 000FB8FC 80 1E 00 34 */ lwz r0, 0x34(r30) /* 800FE9A0 000FB900 80 7E 00 3C */ lwz r3, 0x3c(r30) @@ -336,7 +347,7 @@ lbl_800FEC44: lbl_800FEC54: /* 800FEC54 000FBBB4 7C 1E E8 00 */ cmpw r30, r29 /* 800FEC58 000FBBB8 41 80 FF 38 */ blt lbl_800FEB90 -/* 800FEC5C 000FBBBC 93 8D A3 40 */ stw r28, lbl_805A8F00@sda21(r13) +/* 800FEC5C 000FBBBC 93 8D A3 40 */ stw r28, mInstance__20CConsoleOutputWindow@sda21(r13) /* 800FEC60 000FBBC0 7F 83 E3 78 */ mr r3, r28 /* 800FEC64 000FBBC4 E3 E1 00 68 */ psq_l f31, 104(r1), 0, qr0 /* 800FEC68 000FBBC8 CB E1 00 60 */ lfd f31, 0x60(r1) @@ -350,14 +361,3 @@ lbl_800FEC54: /* 800FEC88 000FBBE8 7C 08 03 A6 */ mtlr r0 /* 800FEC8C 000FBBEC 38 21 00 70 */ addi r1, r1, 0x70 /* 800FEC90 000FBBF0 4E 80 00 20 */ blr - -.section .rodata -.balign 8 -.global lbl_803CEE00 -lbl_803CEE00: - # ROM: 0x3CBE00 - .asciz "ConsoleOutputWindow" - .4byte 0x003F3F28 - .4byte 0x3F3F2900 - .4byte 0 - diff --git a/include/Kyoto/Text/CFont.hpp b/include/Kyoto/Text/CFont.hpp new file mode 100644 index 00000000..4e204dc3 --- /dev/null +++ b/include/Kyoto/Text/CFont.hpp @@ -0,0 +1,14 @@ +#ifndef _CFONT +#define _CFONT + +class CFont { +public: + CFont(float scale); + ~CFont(); + int CharWidth(char) const; +private: + float mFontSize; + float mScale; +}; + +#endif // _CFONT diff --git a/include/MetroidPrime/CArchMsgParmReal32.hpp b/include/MetroidPrime/CArchMsgParmReal32.hpp index 146b92e9..c2395d41 100644 --- a/include/MetroidPrime/CArchMsgParmReal32.hpp +++ b/include/MetroidPrime/CArchMsgParmReal32.hpp @@ -6,11 +6,12 @@ #include "MetroidPrime/CArchitectureMessage.hpp" class CArchMsgParmReal32 : public IArchitectureMessageParm { - float mVal; - public: CArchMsgParmReal32(float); ~CArchMsgParmReal32(); + float GetReal() const { return mVal; } +private: + float mVal; }; #endif // _CARCHMSGPARMREAL32 diff --git a/include/MetroidPrime/CArchitectureMessage.hpp b/include/MetroidPrime/CArchitectureMessage.hpp index 9422ffed..c7155ee1 100644 --- a/include/MetroidPrime/CArchitectureMessage.hpp +++ b/include/MetroidPrime/CArchitectureMessage.hpp @@ -31,6 +31,9 @@ struct IArchitectureMessageParm { IArchitectureMessageParm::~IArchitectureMessageParm() {} class CArchitectureMessage { + +public: + EArchMsgType GetType() const { return x4_type; } private: EArchMsgTarget x0_target; EArchMsgType x4_type; diff --git a/include/MetroidPrime/CConsoleOutputWindow.hpp b/include/MetroidPrime/CConsoleOutputWindow.hpp index 73d6b2c5..6ff090fb 100644 --- a/include/MetroidPrime/CConsoleOutputWindow.hpp +++ b/include/MetroidPrime/CConsoleOutputWindow.hpp @@ -1,17 +1,29 @@ #ifndef _CCONSOLEOUTPUTWINDOW #define _CCONSOLEOUTPUTWINDOW -#include "types.h" - #include "MetroidPrime/CIOWin.hpp" +#include "Kyoto/Text/CFont.hpp" + +#include + class CConsoleOutputWindow : public CIOWin { + static CConsoleOutputWindow* mInstance; public: CConsoleOutputWindow(int, float, float); ~CConsoleOutputWindow() override; EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; - void Draw() override; + void Update(float); + void Draw() const; +private: + CFont mFont; + float mUnk; + rstl::vector mText; + rstl::vector mUnkFloats; + int x40_; + int x44_; + int x48_; }; #endif // _CCONSOLEOUTPUTWINDOW diff --git a/include/MetroidPrime/Decode.hpp b/include/MetroidPrime/Decode.hpp new file mode 100644 index 00000000..0720e672 --- /dev/null +++ b/include/MetroidPrime/Decode.hpp @@ -0,0 +1,15 @@ +#ifndef _DECODE +#define _DECODE + +#include "MetroidPrime/CArchMsgParmInt32.hpp" +#include "MetroidPrime/CArchMsgParmInt32Int32VoidPtr.hpp" +#include "MetroidPrime/CArchMsgParmNull.hpp" +#include "MetroidPrime/CArchMsgParmReal32.hpp" +#include "MetroidPrime/CArchMsgParmUserInput.hpp" +#include "MetroidPrime/CArchMsgParmControllerStatus.hpp" + +namespace MakeMsg { + const CArchMsgParmReal32& GetParmTimerTick(const CArchitectureMessage& msg); +} + +#endif // _DECODE diff --git a/src/MetroidPrime/CConsoleOutputWindow.cpp b/src/MetroidPrime/CConsoleOutputWindow.cpp new file mode 100644 index 00000000..22b910f8 --- /dev/null +++ b/src/MetroidPrime/CConsoleOutputWindow.cpp @@ -0,0 +1,52 @@ +#include "MetroidPrime/CConsoleOutputWindow.hpp" + +#include "MetroidPrime/CArchitectureMessage.hpp" +#include "MetroidPrime/Decode.hpp" + + +#include + +CConsoleOutputWindow* CConsoleOutputWindow::mInstance = nullptr; + +CConsoleOutputWindow::CConsoleOutputWindow(int stringCount, float f1, float fontScale) +: CIOWin(rstl::string_l("ConsoleOutputWindow")) +, mFont(fontScale) +, mUnk(f1) +, x40_(632.f / mFont.CharWidth('0')) +, x44_(0) +, x48_(0) { + mText.reserve(stringCount); + mUnkFloats.reserve(stringCount); + for (int i = 0; i < stringCount; i++) { + mText.push_back(rstl::string("", x40_ + 1)); + mUnkFloats.push_back(0.f); + } + mInstance = this; +} + +CConsoleOutputWindow::~CConsoleOutputWindow() { mInstance = nullptr; } +CIOWin::EMessageReturn CConsoleOutputWindow::OnMessage(const CArchitectureMessage& msg, + CArchitectureQueue& queue) { + switch (msg.GetType()) { + case kAM_UserInput: + return kMR_Normal; + break; + case kAM_TimerTick: + Update(MakeMsg::GetParmTimerTick(msg).GetReal()); + return kMR_Normal; + default: + return kMR_Normal; + } +} + + +void CConsoleOutputWindow::Update(float dt) { + for (int i = 0; i < mText.size(); ++i) { + mUnkFloats[i] = rstl::max_val(0.f, mUnkFloats[i] - dt); + } +} + + +void CConsoleOutputWindow::Draw() const { + +}