From b2fc1d2683958a772da702d74bbbfd8e4a1d514c Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 20 Sep 2023 09:22:35 -0700 Subject: [PATCH 1/4] Move statics out of actor/ dir --- config/GZLE01/splits.txt | 26 ++++++++++----------- config/GZLJ01/splits.txt | 26 ++++++++++----------- config/GZLP01/splits.txt | 26 ++++++++++----------- configure.py | 2 +- src/d/{actor => }/d_a_boko_static.cpp | 0 src/d/{actor => }/d_a_bomb_static.cpp | 0 src/d/{actor => }/d_a_branch_static.cpp | 0 src/d/{actor => }/d_a_item_static.cpp | 0 src/d/{actor => }/d_a_itembase_static.cpp | 0 src/d/{actor => }/d_a_leaflift_static.cpp | 0 src/d/{actor => }/d_a_mgameboard_static.cpp | 0 src/d/{actor => }/d_a_npc_cb1_static.cpp | 0 src/d/{actor => }/d_a_npc_mk_static.cpp | 0 src/d/{actor => }/d_a_obj_tribox_static.cpp | 0 src/d/{actor => }/d_a_race_item_static.cpp | 0 src/d/{actor => }/d_a_ship_static.cpp | 0 src/d/{actor => }/d_a_shop_item_static.cpp | 0 17 files changed, 40 insertions(+), 40 deletions(-) rename src/d/{actor => }/d_a_boko_static.cpp (100%) rename src/d/{actor => }/d_a_bomb_static.cpp (100%) rename src/d/{actor => }/d_a_branch_static.cpp (100%) rename src/d/{actor => }/d_a_item_static.cpp (100%) rename src/d/{actor => }/d_a_itembase_static.cpp (100%) rename src/d/{actor => }/d_a_leaflift_static.cpp (100%) rename src/d/{actor => }/d_a_mgameboard_static.cpp (100%) rename src/d/{actor => }/d_a_npc_cb1_static.cpp (100%) rename src/d/{actor => }/d_a_npc_mk_static.cpp (100%) rename src/d/{actor => }/d_a_obj_tribox_static.cpp (100%) rename src/d/{actor => }/d_a_race_item_static.cpp (100%) rename src/d/{actor => }/d_a_ship_static.cpp (100%) rename src/d/{actor => }/d_a_shop_item_static.cpp (100%) diff --git a/config/GZLE01/splits.txt b/config/GZLE01/splits.txt index 76202e490..6226bc5ed 100644 --- a/config/GZLE01/splits.txt +++ b/config/GZLE01/splits.txt @@ -489,52 +489,52 @@ d/actor/d_a_obj.cpp: .sbss start:0x803F6BA0 end:0x803F6BA8 .sdata2 start:0x803F84C8 end:0x803F8530 -d/actor/d_a_obj_tribox_static.cpp: +d/d_a_obj_tribox_static.cpp: .text start:0x80067D1C end:0x80067D94 .ctors start:0x803386C8 end:0x803386CC .bss start:0x803E1F30 end:0x803E1F48 .sbss start:0x803F6BA8 end:0x803F6BC0 -d/actor/d_a_ship_static.cpp: +d/d_a_ship_static.cpp: .text start:0x80067D94 end:0x80067E78 .sdata2 start:0x803F8530 end:0x803F8538 -d/actor/d_a_boko_static.cpp: +d/d_a_boko_static.cpp: .text start:0x80067E78 end:0x80067FA0 .data start:0x80377018 end:0x80377168 .sdata start:0x803F61E0 end:0x803F61E8 -d/actor/d_a_bomb_static.cpp: +d/d_a_bomb_static.cpp: .text start:0x80067FA0 end:0x800684F4 .text start:0x800684F4 end:0x80068510 .rodata start:0x8034FC58 end:0x8034FC90 -d/actor/d_a_branch_static.cpp: +d/d_a_branch_static.cpp: .text start:0x80068510 end:0x800685F8 .rodata start:0x8034FC90 end:0x8034FCC0 -d/actor/d_a_mgameboard_static.cpp: +d/d_a_mgameboard_static.cpp: .text start:0x800685F8 end:0x80068650 -d/actor/d_a_itembase_static.cpp: +d/d_a_itembase_static.cpp: .text start:0x80068650 end:0x80068820 .rodata start:0x8034FCC0 end:0x8034FD10 -d/actor/d_a_item_static.cpp: +d/d_a_item_static.cpp: .text start:0x80068820 end:0x800689F0 .sdata2 start:0x803F8538 end:0x803F8540 -d/actor/d_a_shop_item_static.cpp: +d/d_a_shop_item_static.cpp: .text start:0x800689F0 end:0x80068A58 .rodata start:0x8034FD10 end:0x80351DF0 .sdata2 start:0x803F8540 end:0x803F8550 -d/actor/d_a_race_item_static.cpp: +d/d_a_race_item_static.cpp: .text start:0x80068A58 end:0x800690E4 .data start:0x80377168 end:0x80377228 .sdata2 start:0x803F8550 end:0x803F8558 -d/actor/d_a_leaflift_static.cpp: +d/d_a_leaflift_static.cpp: .text start:0x800690E4 end:0x800692C4 .sdata2 start:0x803F8558 end:0x803F8580 @@ -952,11 +952,11 @@ d/d_2dnumber.cpp: .data start:0x803890C8 end:0x80389138 .sdata2 start:0x803F9488 end:0x803F9508 -d/actor/d_a_npc_cb1_static.cpp: +d/d_a_npc_cb1_static.cpp: .text start:0x800CB5C4 end:0x800CB5CC .sbss start:0x803F6E60 end:0x803F6E68 -d/actor/d_a_npc_mk_static.cpp: +d/d_a_npc_mk_static.cpp: .text start:0x800CB5CC end:0x800CC734 .sdata2 start:0x803F9508 end:0x803F9560 diff --git a/config/GZLJ01/splits.txt b/config/GZLJ01/splits.txt index 25011b85a..8a10d4cd7 100644 --- a/config/GZLJ01/splits.txt +++ b/config/GZLJ01/splits.txt @@ -489,52 +489,52 @@ d/actor/d_a_obj.cpp: .sbss start:0x803EA070 end:0x803EA078 .sdata2 start:0x803EB980 end:0x803EB9E8 -d/actor/d_a_obj_tribox_static.cpp: +d/d_a_obj_tribox_static.cpp: .text start:0x80065B50 end:0x80065BC8 .ctors start:0x803360C4 end:0x803360C8 .bss start:0x803D5420 end:0x803D5438 .sbss start:0x803EA078 end:0x803EA090 -d/actor/d_a_ship_static.cpp: +d/d_a_ship_static.cpp: .text start:0x80065BC8 end:0x80065CAC .sdata2 start:0x803EB9E8 end:0x803EB9F0 -d/actor/d_a_boko_static.cpp: +d/d_a_boko_static.cpp: .text start:0x80065CAC end:0x80065DD4 .data start:0x8036A4B8 end:0x8036A608 .sdata start:0x803E96C8 end:0x803E96D0 -d/actor/d_a_bomb_static.cpp: +d/d_a_bomb_static.cpp: .text start:0x80065DD4 end:0x80066328 .text start:0x80066328 end:0x80066344 .rodata start:0x803436B8 end:0x803436F0 -d/actor/d_a_branch_static.cpp: +d/d_a_branch_static.cpp: .text start:0x80066344 end:0x8006642C .rodata start:0x803436F0 end:0x80343720 -d/actor/d_a_mgameboard_static.cpp: +d/d_a_mgameboard_static.cpp: .text start:0x8006642C end:0x80066484 -d/actor/d_a_itembase_static.cpp: +d/d_a_itembase_static.cpp: .text start:0x80066484 end:0x80066654 .rodata start:0x80343720 end:0x80343770 -d/actor/d_a_item_static.cpp: +d/d_a_item_static.cpp: .text start:0x80066654 end:0x80066824 .sdata2 start:0x803EB9F0 end:0x803EB9F8 -d/actor/d_a_shop_item_static.cpp: +d/d_a_shop_item_static.cpp: .text start:0x80066824 end:0x8006688C .rodata start:0x80343770 end:0x80345850 .sdata2 start:0x803EB9F8 end:0x803EBA08 -d/actor/d_a_race_item_static.cpp: +d/d_a_race_item_static.cpp: .text start:0x8006688C end:0x80066F18 .data start:0x8036A608 end:0x8036A6C8 .sdata2 start:0x803EBA08 end:0x803EBA10 -d/actor/d_a_leaflift_static.cpp: +d/d_a_leaflift_static.cpp: .text start:0x80066F18 end:0x800670F8 .sdata2 start:0x803EBA10 end:0x803EBA38 @@ -952,11 +952,11 @@ d/d_2dnumber.cpp: .data start:0x8037C568 end:0x8037C5D8 .sdata2 start:0x803EC950 end:0x803EC9D0 -d/actor/d_a_npc_cb1_static.cpp: +d/d_a_npc_cb1_static.cpp: .text start:0x800C855C end:0x800C8564 .sbss start:0x803EA330 end:0x803EA338 -d/actor/d_a_npc_mk_static.cpp: +d/d_a_npc_mk_static.cpp: .text start:0x800C8564 end:0x800C96CC .sdata2 start:0x803EC9D0 end:0x803ECA28 diff --git a/config/GZLP01/splits.txt b/config/GZLP01/splits.txt index 409e61d08..9a79cbdb2 100644 --- a/config/GZLP01/splits.txt +++ b/config/GZLP01/splits.txt @@ -489,52 +489,52 @@ d/actor/d_a_obj.cpp: .sbss start:0x803FE3A0 end:0x803FE3A8 .sdata2 start:0x803FFCF0 end:0x803FFD58 -d/actor/d_a_obj_tribox_static.cpp: +d/d_a_obj_tribox_static.cpp: .text start:0x8006BAFC end:0x8006BB74 .ctors start:0x8033DC08 end:0x8033DC0C .bss start:0x803E9858 end:0x803E9870 .sbss start:0x803FE3A8 end:0x803FE3C0 -d/actor/d_a_ship_static.cpp: +d/d_a_ship_static.cpp: .text start:0x8006BB74 end:0x8006BC58 .sdata2 start:0x803FFD58 end:0x803FFD60 -d/actor/d_a_boko_static.cpp: +d/d_a_boko_static.cpp: .text start:0x8006BC58 end:0x8006BD80 .data start:0x8037DCF8 end:0x8037DE48 .sdata start:0x803FD9E0 end:0x803FD9E8 -d/actor/d_a_bomb_static.cpp: +d/d_a_bomb_static.cpp: .text start:0x8006BD80 end:0x8006C2D4 .text start:0x8006C2D4 end:0x8006C2F0 .rodata start:0x80355FA8 end:0x80355FE0 -d/actor/d_a_branch_static.cpp: +d/d_a_branch_static.cpp: .text start:0x8006C2F0 end:0x8006C3D8 .rodata start:0x80355FE0 end:0x80356010 -d/actor/d_a_mgameboard_static.cpp: +d/d_a_mgameboard_static.cpp: .text start:0x8006C3D8 end:0x8006C430 -d/actor/d_a_itembase_static.cpp: +d/d_a_itembase_static.cpp: .text start:0x8006C430 end:0x8006C600 .rodata start:0x80356010 end:0x80356060 -d/actor/d_a_item_static.cpp: +d/d_a_item_static.cpp: .text start:0x8006C600 end:0x8006C7D0 .sdata2 start:0x803FFD60 end:0x803FFD68 -d/actor/d_a_shop_item_static.cpp: +d/d_a_shop_item_static.cpp: .text start:0x8006C7D0 end:0x8006C838 .rodata start:0x80356060 end:0x80358140 .sdata2 start:0x803FFD68 end:0x803FFD78 -d/actor/d_a_race_item_static.cpp: +d/d_a_race_item_static.cpp: .text start:0x8006C838 end:0x8006CEC4 .data start:0x8037DE48 end:0x8037DF08 .sdata2 start:0x803FFD78 end:0x803FFD80 -d/actor/d_a_leaflift_static.cpp: +d/d_a_leaflift_static.cpp: .text start:0x8006CEC4 end:0x8006D0A4 .sdata2 start:0x803FFD80 end:0x803FFDA8 @@ -952,11 +952,11 @@ d/d_2dnumber.cpp: .data start:0x8038FDA8 end:0x8038FE18 .sdata2 start:0x80400CB0 end:0x80400D30 -d/actor/d_a_npc_cb1_static.cpp: +d/d_a_npc_cb1_static.cpp: .text start:0x800CF264 end:0x800CF26C .sbss start:0x803FE660 end:0x803FE668 -d/actor/d_a_npc_mk_static.cpp: +d/d_a_npc_mk_static.cpp: .text start:0x800CF26C end:0x800D03D4 .sdata2 start:0x80400D30 end:0x80400D88 diff --git a/configure.py b/configure.py index fe08176ca..74c1054bb 100644 --- a/configure.py +++ b/configure.py @@ -413,7 +413,7 @@ config.libs = [ Object(NonMatching, "d/actor/d_a_boomerang.cpp"), Object(NonMatching, "d/actor/d_a_dai_item.cpp"), Object(NonMatching, "d/actor/d_a_demo00.cpp"), - Object(Matching, "d/actor/d_a_disappear.cpp"), + Object(Matching, "d/actor/d_a_disappear.cpp"), Object(NonMatching, "d/actor/d_a_esa.cpp"), Object(NonMatching, "d/actor/d_a_grid.cpp"), Object(NonMatching, "d/actor/d_a_himo2.cpp"), diff --git a/src/d/actor/d_a_boko_static.cpp b/src/d/d_a_boko_static.cpp similarity index 100% rename from src/d/actor/d_a_boko_static.cpp rename to src/d/d_a_boko_static.cpp diff --git a/src/d/actor/d_a_bomb_static.cpp b/src/d/d_a_bomb_static.cpp similarity index 100% rename from src/d/actor/d_a_bomb_static.cpp rename to src/d/d_a_bomb_static.cpp diff --git a/src/d/actor/d_a_branch_static.cpp b/src/d/d_a_branch_static.cpp similarity index 100% rename from src/d/actor/d_a_branch_static.cpp rename to src/d/d_a_branch_static.cpp diff --git a/src/d/actor/d_a_item_static.cpp b/src/d/d_a_item_static.cpp similarity index 100% rename from src/d/actor/d_a_item_static.cpp rename to src/d/d_a_item_static.cpp diff --git a/src/d/actor/d_a_itembase_static.cpp b/src/d/d_a_itembase_static.cpp similarity index 100% rename from src/d/actor/d_a_itembase_static.cpp rename to src/d/d_a_itembase_static.cpp diff --git a/src/d/actor/d_a_leaflift_static.cpp b/src/d/d_a_leaflift_static.cpp similarity index 100% rename from src/d/actor/d_a_leaflift_static.cpp rename to src/d/d_a_leaflift_static.cpp diff --git a/src/d/actor/d_a_mgameboard_static.cpp b/src/d/d_a_mgameboard_static.cpp similarity index 100% rename from src/d/actor/d_a_mgameboard_static.cpp rename to src/d/d_a_mgameboard_static.cpp diff --git a/src/d/actor/d_a_npc_cb1_static.cpp b/src/d/d_a_npc_cb1_static.cpp similarity index 100% rename from src/d/actor/d_a_npc_cb1_static.cpp rename to src/d/d_a_npc_cb1_static.cpp diff --git a/src/d/actor/d_a_npc_mk_static.cpp b/src/d/d_a_npc_mk_static.cpp similarity index 100% rename from src/d/actor/d_a_npc_mk_static.cpp rename to src/d/d_a_npc_mk_static.cpp diff --git a/src/d/actor/d_a_obj_tribox_static.cpp b/src/d/d_a_obj_tribox_static.cpp similarity index 100% rename from src/d/actor/d_a_obj_tribox_static.cpp rename to src/d/d_a_obj_tribox_static.cpp diff --git a/src/d/actor/d_a_race_item_static.cpp b/src/d/d_a_race_item_static.cpp similarity index 100% rename from src/d/actor/d_a_race_item_static.cpp rename to src/d/d_a_race_item_static.cpp diff --git a/src/d/actor/d_a_ship_static.cpp b/src/d/d_a_ship_static.cpp similarity index 100% rename from src/d/actor/d_a_ship_static.cpp rename to src/d/d_a_ship_static.cpp diff --git a/src/d/actor/d_a_shop_item_static.cpp b/src/d/d_a_shop_item_static.cpp similarity index 100% rename from src/d/actor/d_a_shop_item_static.cpp rename to src/d/d_a_shop_item_static.cpp From 12ddfa5d0023df3a72c640370aa626ddf1ceafe6 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Wed, 20 Sep 2023 21:07:19 -0700 Subject: [PATCH 2/4] JUTAssert, JUTConsole, JUTException (#63) * JUTAssert * JUTConsole * JUTException --- configure.py | 2 +- include/JSystem/JUtility/JUTAssert.h | 5 +- include/JSystem/JUtility/JUTConsole.h | 15 +- include/JSystem/JUtility/JUTDirectPrint.h | 2 + include/JSystem/JUtility/JUTException.h | 7 +- include/dolphin/gx/GXFrameBuf.h | 6 + src/JSystem/JUtility/JUTAssert.cpp | 165 +++- src/JSystem/JUtility/JUTConsole.cpp | 430 ++++++++-- src/JSystem/JUtility/JUTException.cpp | 981 ++++++++++++++++++++-- 9 files changed, 1455 insertions(+), 158 deletions(-) diff --git a/configure.py b/configure.py index 74c1054bb..b670caf99 100644 --- a/configure.py +++ b/configure.py @@ -814,7 +814,7 @@ config.libs = [ Object(NonMatching, "JSystem/JUtility/JUTGamePad.cpp"), Object(NonMatching, "JSystem/JUtility/JUTException.cpp"), Object(NonMatching, "JSystem/JUtility/JUTDirectPrint.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTAssert.cpp"), + Object(Matching, "JSystem/JUtility/JUTAssert.cpp"), Object(NonMatching, "JSystem/JUtility/JUTVideo.cpp"), Object(NonMatching, "JSystem/JUtility/JUTXfb.cpp"), Object(NonMatching, "JSystem/JUtility/JUTFader.cpp"), diff --git a/include/JSystem/JUtility/JUTAssert.h b/include/JSystem/JUtility/JUTAssert.h index d4f10e24e..73910d909 100644 --- a/include/JSystem/JUtility/JUTAssert.h +++ b/include/JSystem/JUtility/JUTAssert.h @@ -33,6 +33,9 @@ namespace JUTAssertion { void setMessageCount(int); }; -extern bool sAssertVisible; +extern "C" { + void setWarningMessage_f_va(u32 device, const char* file, int line, const char* msg, va_list args); + void setLogMessage_f_va(u32 device, const char* file, int line, const char* msg, va_list args); +} #endif /* JUTASSERT_H */ diff --git a/include/JSystem/JUtility/JUTConsole.h b/include/JSystem/JUtility/JUTConsole.h index 3915b9033..5ec6c776a 100644 --- a/include/JSystem/JUtility/JUTConsole.h +++ b/include/JSystem/JUtility/JUTConsole.h @@ -67,6 +67,7 @@ public: bool isVisible() const { return mVisible; } void setVisible(bool visible) { mVisible = visible; } + u8 getLineAttr(int param_0) { return mBuf[(field_0x20 + 2) * param_0]; } void setLineAttr(int param_0, u8 param_1) { mBuf[(field_0x20 + 2) * param_0] = param_1; } u8* getLinePtr(int param_0) const { return &mBuf[(field_0x20 + 2) * param_0] + 1; } int diffIndex(int param_0, int param_1) const { @@ -77,13 +78,12 @@ public: return diff += mMaxLines; } - int nextIndex(int param_0) const { - int index = param_0 + 1; - if (mMaxLines <= index) { - index = 0; - } + int prevIndex(int index) const { + return --index < 0 ? index = mMaxLines - 1 : index; + } - return index; + int nextIndex(int index) const { + return ++index >= mMaxLines ? 0 : index; } void scrollToLastLine() { scroll(mMaxLines); } @@ -94,7 +94,7 @@ private: private: /* 0x20 */ u32 field_0x20; - /* 0x24 */ u32 mMaxLines; + /* 0x24 */ int mMaxLines; /* 0x28 */ u8* mBuf; /* 0x2C */ bool field_0x2c; /* 0x30 */ int field_0x30; @@ -146,6 +146,7 @@ extern "C" JUTConsole* JUTGetWarningConsole(); extern "C" void JUTReportConsole_f_va(const char*, va_list); extern "C" void JUTReportConsole_f(const char*, ...); extern "C" void JUTWarningConsole(const char* message); +extern "C" void JUTWarningConsole_f_va(const char*, va_list); extern "C" void JUTWarningConsole_f(const char* message, ...); extern "C" void JUTReportConsole(const char* message); diff --git a/include/JSystem/JUtility/JUTDirectPrint.h b/include/JSystem/JUtility/JUTDirectPrint.h index bc17dab88..756d02c3d 100644 --- a/include/JSystem/JUtility/JUTDirectPrint.h +++ b/include/JSystem/JUtility/JUTDirectPrint.h @@ -21,8 +21,10 @@ public: /* 802E4240 */ static JUTDirectPrint* start(); + void* getFrameBuffer() { return field_0x00; } bool isActive() const { return field_0x00 != 0; } JUtility::TColor getCharColor() const { return mCharColor; } + void changeFrameBuffer(void *param_0) { changeFrameBuffer(param_0, mFrameBufferWidth, mFrameBufferHeight); } static JUTDirectPrint* getManager() { return sDirectPrint; } diff --git a/include/JSystem/JUtility/JUTException.h b/include/JSystem/JUtility/JUTException.h index 0380caf3c..f2f9b5aaf 100644 --- a/include/JSystem/JUtility/JUTException.h +++ b/include/JSystem/JUtility/JUTException.h @@ -56,7 +56,7 @@ public: }; /* 802E1D5C */ JUTException(JUTDirectPrint*); - /* 802E40EC */ virtual ~JUTException(); + /* 802E40EC */ virtual ~JUTException() {}; /* 802E22C4 */ void showFloatSub(int, f32); /* 802E2454 */ void showFloat(OSContext*); @@ -108,7 +108,7 @@ private: static OSMessageQueue sMessageQueue; static const char* sCpuExpName[17]; static JSUList sMapFileList; - static u8 sMessageBuffer[4 + 4 /* padding */]; + static OSMessage sMessageBuffer[1]; static JUTException* sErrorManager; static OSErrorHandler sPreUserCallback; static OSErrorHandler sPostUserCallback; @@ -128,10 +128,9 @@ private: /* 0x80 */ u32 mTraceSuppress; /* 0x84 */ u32 field_0x98; /* 0x88 */ u32 mPrintFlags; - /* 0x8C */ u32 mStackPointer; }; -STATIC_ASSERT(sizeof(JUTException) == 0x90); +STATIC_ASSERT(sizeof(JUTException) == 0x8C); struct JUTWarn { JUTWarn& operator<<(const char*) { return *this; } diff --git a/include/dolphin/gx/GXFrameBuf.h b/include/dolphin/gx/GXFrameBuf.h index 781a397f3..b65dd454a 100644 --- a/include/dolphin/gx/GXFrameBuf.h +++ b/include/dolphin/gx/GXFrameBuf.h @@ -8,6 +8,12 @@ extern "C" { #endif +extern GXRenderModeObj GXNtsc480IntDf; +extern GXRenderModeObj GXNtsc480Int; +extern GXRenderModeObj GXMpal480IntDf; +extern GXRenderModeObj GXPal528IntDf; +extern GXRenderModeObj GXEurgb60Hz480IntDf; + void GXSetDispCopySrc(u16 left, u16 top, u16 width, u16 height); void GXSetTexCopySrc(u16 left, u16 top, u16 width, u16 height); void GXSetDispCopyDst(u16 arg0, u16 arg1); diff --git a/src/JSystem/JUtility/JUTAssert.cpp b/src/JSystem/JUtility/JUTAssert.cpp index 59daa0746..056885bdf 100644 --- a/src/JSystem/JUtility/JUTAssert.cpp +++ b/src/JSystem/JUtility/JUTAssert.cpp @@ -4,69 +4,182 @@ // #include "JSystem/JUtility/JUTAssert.h" -#include "dolphin/types.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTDbPrint.h" +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "MSL_C/stdio.h" +#include "dolphin/vi/vi.h" -/* 802C740C-802C7410 .text create__12JUTAssertionFv */ -void JUTAssertion::create() { - /* Nonmatching */ +namespace JUTAssertion { + namespace { + static char sMessageFileLine[64]; + static char sMessageString[96]; + static s32 sDisplayTime = -1; + static s32 sDevice = 3; + static bool mVisible = true; + static u32 sMessageLife; + static s32 sMessageOwner; + static u8 mSynchro; + } } +/* 802C740C-802C7410 .text create__12JUTAssertionFv */ +void JUTAssertion::create() {} + /* 802C7410-802C744C .text flush_subroutine__12JUTAssertionFv */ -void JUTAssertion::flush_subroutine() { - /* Nonmatching */ +u32 JUTAssertion::flush_subroutine() { + if (sMessageLife == 0) { + return 0; + } + + if (sMessageLife != -1) { + sMessageLife--; + } + + if (sMessageLife >= 5) { + return sMessageLife; + } + + return 0; } /* 802C744C-802C74B0 .text flushMessage__12JUTAssertionFv */ void JUTAssertion::flushMessage() { - /* Nonmatching */ + if (flush_subroutine() && mVisible == true) { + JUTDirectPrint::getManager()->drawString(16, 16, sMessageFileLine); + JUTDirectPrint::getManager()->drawString(16, 24, sMessageString); + } } /* 802C74B0-802C7690 .text flushMessage_dbPrint__12JUTAssertionFv */ void JUTAssertion::flushMessage_dbPrint() { - /* Nonmatching */ + if (flush_subroutine() && mVisible == true && JUTDbPrint::getManager() != NULL) { + JUTFont* font = JUTDbPrint::getManager()->getFont(); + if (font != NULL) { + u8 tmp = ((VIGetRetraceCount() & 0x3C) << 2) | 0xF; + font->setGX(); + font->setCharColor(JUtility::TColor(255, tmp, tmp, 255)); + font->drawString(30, 36, sMessageFileLine, true); + font->drawString(30, 54, sMessageString, true); + } + } } /* 802C7690-802C7698 .text getSDevice__12JUTAssertionFv */ -void JUTAssertion::getSDevice() { - /* Nonmatching */ +u32 JUTAssertion::getSDevice() { + return sDevice; } /* 802C7698-802C7788 .text setConfirmMessage__12JUTAssertionFUlPcibPCc */ -void JUTAssertion::setConfirmMessage(unsigned long, char*, int, bool, const char*) { - /* Nonmatching */ +void JUTAssertion::setConfirmMessage(u32 param_1, char* file, int line, bool param_4, const char* msg) { + if (param_4 == 1) { + return; + } + u32 r28 = sMessageLife; + if (r28 == 0 && (param_1 & 1) != 0) { + sMessageLife = sDisplayTime; + sMessageOwner = 2; + snprintf(sMessageFileLine, sizeof(sMessageFileLine) - 1, "FAILED [%s:%d]", file, line); + snprintf(sMessageString, sizeof(sMessageString) - 1, "%s", msg); + } + if ((r28 == 0 || mSynchro == 0) && (param_1 & 2) != 0) { + JUTWarningConsole_f("FAILED [%s:%d] %s\n", file, line, msg); + } } /* 802C7788-802C78E4 .text showAssert__12JUTAssertionFUlPCciPCc */ -void JUTAssertion::showAssert(unsigned long, const char*, int, const char*) { - /* Nonmatching */ +void JUTAssertion::showAssert(u32 device, const char* file, int line, const char* msg) { + OSReport("Failed assertion %s in \"%s\" on line %d\n", msg, file, line); + if ((device & 1) == 0) { + return; + } + if (!JUTDirectPrint::getManager()) { + return; + } + JUTDirectPrint::getManager()->erase(10, 0x10, 0x132, 0x18); + char buffer[0x100]; + snprintf(buffer, 95, "Failed assertion: %s:%d", file, line); + JUTDirectPrint::getManager()->drawString(0x10, 0x10, buffer); + snprintf(buffer, 95, "%s", msg); + JUTDirectPrint::getManager()->drawString(0x10, 0x18, buffer); + VISetNextFrameBuffer(JUTDirectPrint::getManager()->getFrameBuffer()); + VIWaitForRetrace(); + VIFlush(); + // busy loop for 2 seconds + OSTime var1 = OSGetTime(); + while (OSTicksToMilliseconds(OSGetTime() - var1) < 2000) {} } /* 802C78E4-802C79FC .text setWarningMessage_f_va */ -void setWarningMessage_f_va { - /* Nonmatching */ +void setWarningMessage_f_va(u32 device, const char* file, int line, const char* msg, va_list args) { + u32 messageLife = JUTAssertion::sMessageLife; + bool r26 = false; + if (messageLife == 0) { + if (device & 1) { + JUTAssertion::sMessageLife = JUTAssertion::sDisplayTime; + JUTAssertion::sMessageOwner = 3; + snprintf(JUTAssertion::sMessageFileLine, sizeof(JUTAssertion::sMessageFileLine) - 1, "WARNING [%s:%d]", file, line); + } + vsnprintf(JUTAssertion::sMessageString, sizeof(JUTAssertion::sMessageString) - 1, msg, args); + r26 = true; + } + if ((messageLife == 0 || JUTAssertion::mSynchro == 0) && (device & 2)) { + JUTWarningConsole_f("WARNING [%s:%d] ", file, line); + if (!r26) { + JUTWarningConsole_f_va(msg, args); + } else { + JUTWarningConsole(JUTAssertion::sMessageString); + } + JUTWarningConsole("\n"); + } } /* 802C79FC-802C7A7C .text setWarningMessage_f__12JUTAssertionFUlPciPCce */ -void JUTAssertion::setWarningMessage_f(unsigned long, char*, int, const char*, ...) { - /* Nonmatching */ +void JUTAssertion::setWarningMessage_f(u32 device, char* file, int line, const char* msg, ...) { + va_list args; + va_start(args, msg); + setWarningMessage_f_va(device, file, line, msg, args); + va_end(args); } /* 802C7A7C-802C7B94 .text setLogMessage_f_va */ -void setLogMessage_f_va { - /* Nonmatching */ +void setLogMessage_f_va(u32 device, const char* file, int line, const char* msg, va_list args) { + u32 messageLife = JUTAssertion::sMessageLife; + bool r26 = false; + if (messageLife == 0) { + if (device & 1) { + JUTAssertion::sMessageLife = JUTAssertion::sDisplayTime; + JUTAssertion::sMessageOwner = 4; + snprintf(JUTAssertion::sMessageFileLine, sizeof(JUTAssertion::sMessageFileLine) - 1, "[%s:%d]", file, line); + } + vsnprintf(JUTAssertion::sMessageString, sizeof(JUTAssertion::sMessageString) - 1, msg, args); + r26 = true; + } + if ((messageLife == 0 || JUTAssertion::mSynchro == 0) && (device & 2)) { + JUTReportConsole_f("[%s:%d] ", file, line); + if (!r26) { + JUTReportConsole_f_va(msg, args); + } else { + JUTReportConsole(JUTAssertion::sMessageString); + } + JUTReportConsole("\n"); + } } /* 802C7B94-802C7C14 .text setLogMessage_f__12JUTAssertionFUlPciPCce */ -void JUTAssertion::setLogMessage_f(unsigned long, char*, int, const char*, ...) { - /* Nonmatching */ +void JUTAssertion::setLogMessage_f(u32 device, char* file, int line, const char* msg, ...) { + va_list args; + va_start(args, msg); + setLogMessage_f_va(device, file, line, msg, args); + va_end(args); } /* 802C7C14-802C7C1C .text setVisible__12JUTAssertionFb */ -void JUTAssertion::setVisible(bool) { - /* Nonmatching */ +void JUTAssertion::setVisible(bool visible) { + mVisible = visible; } /* 802C7C1C-802C7C34 .text setMessageCount__12JUTAssertionFi */ -void JUTAssertion::setMessageCount(int) { - /* Nonmatching */ +void JUTAssertion::setMessageCount(int msg_count) { + sMessageLife = msg_count <= 0 ? 0 : msg_count; } diff --git a/src/JSystem/JUtility/JUTConsole.cpp b/src/JSystem/JUtility/JUTConsole.cpp index a2f7e64a7..febc5e286 100644 --- a/src/JSystem/JUtility/JUTConsole.cpp +++ b/src/JSystem/JUtility/JUTConsole.cpp @@ -4,100 +4,376 @@ // #include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/J2DGraph/J2DOrthoGraph.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTAssert.h" +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "MSL_C/stdio.h" #include "dolphin/types.h" +JUTConsoleManager* JUTConsoleManager::sManager; + /* 802CA2FC-802CA3CC .text create__10JUTConsoleFUiUiP7JKRHeap */ -void JUTConsole::create(unsigned int, unsigned int, JKRHeap*) { - /* Nonmatching */ +JUTConsole* JUTConsole::create(unsigned int param_0, unsigned int maxLines, JKRHeap* p_heap) { + JUTConsoleManager* pManager = JUTConsoleManager::getManager(); + JUT_ASSERT(33, pManager != 0); + + void* buffer = JKRAllocFromHeap(p_heap, getObjectSizeFromBufferSize(param_0, maxLines), 0); + u8* tmpBuf = (u8*)buffer; + + JUTConsole* newConsole = new (tmpBuf) JUTConsole(param_0, maxLines, true); + newConsole->mBuf = tmpBuf + sizeof(JUTConsole); + newConsole->clear(); + + pManager->appendConsole(newConsole); + return newConsole; } /* 802CA3CC-802CA4C8 .text create__10JUTConsoleFUiPvUl */ -void JUTConsole::create(unsigned int, void*, unsigned long) { - /* Nonmatching */ +JUTConsole* JUTConsole::create(unsigned int param_0, void* buffer, u32 bufferSize) { + JUTConsoleManager* pManager = JUTConsoleManager::getManager(); + JUT_ASSERT(59, pManager != 0); + JUT_ASSERT(62, ( (u32)buffer & 0x3 ) == 0); + u32 maxLines = getLineFromObjectSize(bufferSize, param_0); + + JUTConsole* newConsole = new (buffer) JUTConsole(param_0, maxLines, false); + newConsole->mBuf = (u8*)buffer + sizeof(JUTConsole); + newConsole->clear(); + + pManager->appendConsole(newConsole); + return newConsole; } /* 802CA4C8-802CA5AC .text __ct__10JUTConsoleFUiUib */ -JUTConsole::JUTConsole(unsigned int, unsigned int, bool) { - /* Nonmatching */ +JUTConsole::JUTConsole(unsigned int param_0, unsigned int maxLines, bool param_2) { + field_0x2c = param_2; + field_0x20 = param_0; + mMaxLines = maxLines; + + mPositionX = 30; + mPositionY = 50; + mHeight = 20; + + if (mHeight > mMaxLines) { + mHeight = mMaxLines; + } + + mFont = NULL; + mVisible = true; + field_0x65 = false; + field_0x66 = false; + mOutput = 1; + + field_0x5c.set(0, 0, 0, 100); + field_0x60.set(0, 0, 0, 230); +} + +static void dummy1() { + OSReport("console != 0"); } /* 802CA5AC-802CA658 .text __dt__10JUTConsoleFv */ JUTConsole::~JUTConsole() { - /* Nonmatching */ + JUT_ASSERT(150, JUTConsoleManager::getManager()); + JUTConsoleManager::getManager()->removeConsole(this); } /* 802CA658-802CA668 .text getObjectSizeFromBufferSize__10JUTConsoleFUiUi */ -void JUTConsole::getObjectSizeFromBufferSize(unsigned int, unsigned int) { - /* Nonmatching */ +size_t JUTConsole::getObjectSizeFromBufferSize(unsigned int param_0, unsigned int maxLines) { + return (param_0 + 2) * maxLines + sizeof(JUTConsole); } /* 802CA668-802CA678 .text getLineFromObjectSize__10JUTConsoleFUlUi */ -void JUTConsole::getLineFromObjectSize(unsigned long, unsigned int) { - /* Nonmatching */ +size_t JUTConsole::getLineFromObjectSize(u32 bufferSize, unsigned int param_1) { + return (bufferSize - sizeof(JUTConsole)) / (param_1 + 2); } /* 802CA678-802CA6D4 .text clear__10JUTConsoleFv */ void JUTConsole::clear() { - /* Nonmatching */ + field_0x30 = 0; + field_0x34 = 0; + field_0x38 = 0; + field_0x3c = 0; + + for (u32 i = 0; i < mMaxLines; i++) { + setLineAttr(i, 0); + } + setLineAttr(0, -1); + *getLinePtr(0) = 0; } /* 802CA6D4-802CAC1C .text doDraw__10JUTConsoleCFQ210JUTConsole12EConsoleType */ -void JUTConsole::doDraw(JUTConsole::EConsoleType) const { +void JUTConsole::doDraw(JUTConsole::EConsoleType consoleType) const { /* Nonmatching */ + f32 font_yOffset; + s32 changeLine_1; + s32 changeLine_2; + + if (mVisible && (mFont != NULL || consoleType == CONSOLE_TYPE_2)) { + if (mHeight != 0) { + bool temp_r30 = consoleType == CONSOLE_TYPE_0; + font_yOffset = 2.0f + mFontSizeY; + + if (consoleType != CONSOLE_TYPE_2) { + if (JUTVideo::getManager() == NULL) { + J2DOrthoGraph ortho(0.0f, 0.0f, 640.0f, 480.0f, -1.0f, 1.0f); + ortho.setPort(); + } else { + J2DOrthoGraph ortho(0.0f, 0.0f, JUTVideo::getManager()->getFbWidth(), + JUTVideo::getManager()->getEfbHeight(), -1.0f, 1.0f); + ortho.setPort(); + } + + const JUtility::TColor* color; + if (temp_r30) { + color = &field_0x60; + } else { + color = &field_0x5c; + } + + J2DFillBox(mPositionX - 2, (int)(mPositionY - font_yOffset), + (int)((mFontSizeX * field_0x20) + 4.0f), (int)(font_yOffset * mHeight), + *color); + mFont->setGX(); + + if (temp_r30) { + s32 s = (diffIndex(field_0x30, field_0x38) - mHeight) + 1; + if (s <= 0) { + mFont->setCharColor(JUtility::TColor(255, 255, 255, 255)); + } else if (field_0x30 == field_0x34) { + mFont->setCharColor(JUtility::TColor(255, 230, 230, 255)); + } else { + mFont->setCharColor(JUtility::TColor(230, 230, 255, 255)); + } + } else { + mFont->setCharColor(JUtility::TColor(230, 230, 230, 255)); + } + } else { + JUTDirectPrint::getManager()->erase(mPositionX - 3, mPositionY - 2, + (field_0x20 * 6) + 6, + (int)(font_yOffset * mHeight) + 4); + } + + char* linePtr; + s32 curLine = field_0x30; + s32 yFactor = 0; + + do { + linePtr = (char*)getLinePtr(curLine); + + if ((u8)linePtr[-1] != NULL) { + if (consoleType != CONSOLE_TYPE_2) { + mFont->drawString_scale(mPositionX, ((yFactor * font_yOffset) + mPositionY), + mFontSizeX, mFontSizeY, linePtr, true); + } else { + JUTDirectPrint::getManager()->drawString( + mPositionX, ((yFactor * font_yOffset) + mPositionY), linePtr); + } + + changeLine_1 = curLine + 1; + yFactor += 1; + changeLine_2 = changeLine_1 & ~(-((s32)mMaxLines <= (s32)changeLine_1)); + curLine = changeLine_2; + } else { + break; + } + } while (yFactor < mHeight && changeLine_2 != field_0x34); + } + } } /* 802CAC1C-802CAC9C .text print_f__10JUTConsoleFPCce */ -void JUTConsole::print_f(const char*, ...) { - /* Nonmatching */ +void JUTConsole::print_f(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + JUTConsole_print_f_va_(this, fmt, args); + va_end(args); } /* 802CAC9C-802CAFB0 .text print__10JUTConsoleFPCc */ -void JUTConsole::print(const char*) { - /* Nonmatching */ +void JUTConsole::print(const char* param_0) { + if (mOutput & 2) { + OSReport("%s", param_0); + } + if (mOutput & 1) { + const u8* r29 = (const u8*)param_0; + u8* r28 = getLinePtr(field_0x38) + field_0x3c; + while (*r29) { + if (field_0x66 && field_0x34 == nextIndex(field_0x38)) { + break; + } + if (*r29 == '\n') { + r29++; + field_0x3c = field_0x20; + } else if (*r29 == '\t') { + r29++; + while (field_0x3c < field_0x20) { + *(r28++) = ' '; + field_0x3c++; + if (field_0x3c % 8 == 0) { + break; + } + } + } else if (mFont && mFont->isLeadByte(*r29)) { + if (field_0x3c + 1 < field_0x20) { + *(r28++) = *(r29++); + *(r28++) = *(r29++); + field_0x3c++; + field_0x3c++; + } else { + *(r28++) = 0; + field_0x3c++; + } + } else { + *(r28++) = *(r29++); + field_0x3c++; + } + + if (field_0x3c < field_0x20) { + continue; + } + *r28 = 0; + field_0x38 = nextIndex(field_0x38); + field_0x3c = 0; + setLineAttr(field_0x38, 0xff); + r28 = getLinePtr(field_0x38); + *r28 = 0; + int local_28 = diffIndex(field_0x30, field_0x38); + if (local_28 == mHeight) { + field_0x30 = nextIndex(field_0x30); + } + if (field_0x38 == field_0x34) { + field_0x34 = nextIndex(field_0x34); + } + if (field_0x38 == field_0x30) { + field_0x30 = nextIndex(field_0x30); + } + } + *r28 = 0; + } } /* 802CAFB0-802CB03C .text JUTConsole_print_f_va_ */ -void JUTConsole_print_f_va_ { - /* Nonmatching */ +void JUTConsole_print_f_va_(JUTConsole* console, const char* fmt, va_list args) { + JUT_ASSERT(561, console!=0); + char buf[1024]; + vsnprintf(buf, sizeof(buf), fmt, args); + console->print(buf); } /* 802CB03C-802CB19C .text dumpToTerminal__10JUTConsoleFUi */ -void JUTConsole::dumpToTerminal(unsigned int) { +void JUTConsole::dumpToTerminal(unsigned int param_0) { /* Nonmatching */ + if (param_0 == 0) { + return; + } + u32 r29 = field_0x34; + if (param_0 != -1) { + r29 = field_0x38; + for (int i = 0; i != param_0; i++) { + int r25 = prevIndex(r29); + if (getLineAttr(r25) == 0) { + break; + } + r29 = r25; + if (r25 == field_0x34) { + break; + } + } + } + + int r27 = 0; + OSReport("\n:::dump of console[%x]--------------------------------\n",this); + do { + u8* r28 = getLinePtr(r29); + u8 r24 = r28[-1]; + if (r24 == 0) { + break; + } + if (field_0x65) { + OSReport("[%03d] %s\n", r27, r28); + } else { + OSReport("%s\n", r28); + } + r29 = nextIndex(r29); + r27++; + } while (r27 != field_0x34); + OSReport(":::dump of console[%x] END----------------------------\n",this); } /* 802CB19C-802CB278 .text scroll__10JUTConsoleFi */ -void JUTConsole::scroll(int) { - /* Nonmatching */ +void JUTConsole::scroll(int scrollAmnt) { + if (scrollAmnt < 0) { + int diff = diffIndex(field_0x34, field_0x30); + if (scrollAmnt < -diff) { + scrollAmnt = -diff; + } + } else { + if (scrollAmnt > 0) { + int diff = diffIndex(field_0x34, field_0x38); + if (diff + 1 <= mHeight) { + scrollAmnt = 0; + } else { + diff = diffIndex(field_0x30, field_0x38); + if (scrollAmnt > (int)(diff - mHeight) + 1) { + scrollAmnt = (int)(diff - mHeight) + 1; + } + } + } + } + + field_0x30 += scrollAmnt; + if (field_0x30 < 0) { + field_0x30 += mMaxLines; + } + + if (field_0x30 >= mMaxLines) { + field_0x30 -= mMaxLines; + } } /* 802CB278-802CB29C .text getUsedLine__10JUTConsoleCFv */ -void JUTConsole::getUsedLine() const { - /* Nonmatching */ +int JUTConsole::getUsedLine() const { + return diffIndex(field_0x34, field_0x38); } /* 802CB29C-802CB2C0 .text getLineOffset__10JUTConsoleCFv */ -void JUTConsole::getLineOffset() const { - /* Nonmatching */ +int JUTConsole::getLineOffset() const { + return diffIndex(field_0x34, field_0x30); } /* 802CB2C0-802CB2E8 .text __ct__17JUTConsoleManagerFv */ JUTConsoleManager::JUTConsoleManager() { - /* Nonmatching */ + mActiveConsole = NULL; + mDirectConsole = NULL; +} + +static void dummy2() { + OSReport("console != this && console != 0"); + OSReport("\n:::dump of console[%x]----------------\n"); + OSReport(":::dump of console[%x] END------------\n"); } /* 802CB2E8-802CB380 .text createManager__17JUTConsoleManagerFP7JKRHeap */ -void JUTConsoleManager::createManager(JKRHeap*) { - /* Nonmatching */ +JUTConsoleManager* JUTConsoleManager::createManager(JKRHeap* pHeap) { + JUT_ASSERT(922, sManager == 0); + if (pHeap == NULL) { + pHeap = JKRHeap::sCurrentHeap; + } + + JUTConsoleManager* manager = new (pHeap, 0) JUTConsoleManager(); + sManager = manager; + return manager; } /* 802CB380-802CB4C4 .text appendConsole__17JUTConsoleManagerFP10JUTConsole */ -void JUTConsoleManager::appendConsole(JUTConsole*) { +void JUTConsoleManager::appendConsole(JUTConsole* console) { /* Nonmatching */ } /* 802CB4C4-802CB674 .text removeConsole__17JUTConsoleManagerFP10JUTConsole */ -void JUTConsoleManager::removeConsole(JUTConsole*) { +void JUTConsoleManager::removeConsole(JUTConsole* console) { /* Nonmatching */ } @@ -107,61 +383,105 @@ void JUTConsoleManager::draw() const { } /* 802CB740-802CB7B4 .text drawDirect__17JUTConsoleManagerCFb */ -void JUTConsoleManager::drawDirect(bool) const { - /* Nonmatching */ +void JUTConsoleManager::drawDirect(bool waitRetrace) const { + if (mDirectConsole != NULL) { + if (waitRetrace) { + s32 interrupt_status = OSEnableInterrupts(); + u32 retrace_count = VIGetRetraceCount(); + u32 new_count; + do { + new_count = VIGetRetraceCount(); + } while (retrace_count == new_count); + OSRestoreInterrupts(interrupt_status); + } + mDirectConsole->doDraw(JUTConsole::CONSOLE_TYPE_2); + } } /* 802CB7B4-802CB810 .text setDirectConsole__17JUTConsoleManagerFP10JUTConsole */ -void JUTConsoleManager::setDirectConsole(JUTConsole*) { - /* Nonmatching */ +void JUTConsoleManager::setDirectConsole(JUTConsole* p_console) { + if (mDirectConsole != NULL) { + appendConsole(mDirectConsole); + } + + if (p_console != NULL) { + removeConsole(p_console); + } + mDirectConsole = p_console; } +static JUTConsole* sReportConsole; + /* 802CB810-802CB818 .text JUTSetReportConsole */ -void JUTSetReportConsole { - /* Nonmatching */ +void JUTSetReportConsole(JUTConsole* p_console) { + sReportConsole = p_console; } /* 802CB818-802CB820 .text JUTGetReportConsole */ -void JUTGetReportConsole { - /* Nonmatching */ +JUTConsole* JUTGetReportConsole() { + return sReportConsole; } +static JUTConsole* sWarningConsole; + /* 802CB820-802CB828 .text JUTSetWarningConsole */ -void JUTSetWarningConsole { - /* Nonmatching */ +void JUTSetWarningConsole(JUTConsole* p_console) { + sWarningConsole = p_console; } /* 802CB828-802CB830 .text JUTGetWarningConsole */ -void JUTGetWarningConsole { - /* Nonmatching */ +JUTConsole* JUTGetWarningConsole() { + return sWarningConsole; } /* 802CB830-802CB8D0 .text JUTReportConsole_f_va */ -void JUTReportConsole_f_va { - /* Nonmatching */ +void JUTReportConsole_f_va(const char* fmt, va_list args) { + char buf[256]; + + if (JUTGetReportConsole() == NULL) { + vsnprintf(buf, sizeof(buf), fmt, args); + OSReport("%s", buf); + } else if (JUTGetReportConsole()->getOutput() & (JUTConsole::OUTPUT_CONSOLE | JUTConsole::OUTPUT_OSREPORT)) { + vsnprintf(buf, sizeof(buf), fmt, args); + JUTGetReportConsole()->print(buf); + } } /* 802CB8D0-802CB950 .text JUTReportConsole_f */ -void JUTReportConsole_f { - /* Nonmatching */ +void JUTReportConsole_f(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + JUTReportConsole_f_va(fmt, args); + va_end(args); } /* 802CB950-802CB984 .text JUTReportConsole */ -void JUTReportConsole { - /* Nonmatching */ +void JUTReportConsole(const char* message) { + JUTReportConsole_f("%s", message); } /* 802CB984-802CBA24 .text JUTWarningConsole_f_va */ -void JUTWarningConsole_f_va { - /* Nonmatching */ +void JUTWarningConsole_f_va(const char* fmt, va_list args) { + char buf[256]; + + if (JUTGetWarningConsole() == NULL) { + vsnprintf(buf, sizeof(buf), fmt, args); + OSReport("%s", buf); + } else if (JUTGetWarningConsole()->getOutput() & (JUTConsole::OUTPUT_CONSOLE | JUTConsole::OUTPUT_OSREPORT)) { + vsnprintf(buf, sizeof(buf), fmt, args); + JUTGetWarningConsole()->print(buf); + } } /* 802CBA24-802CBAA4 .text JUTWarningConsole_f */ -void JUTWarningConsole_f { - /* Nonmatching */ +void JUTWarningConsole_f(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + JUTReportConsole_f_va(fmt, args); + va_end(args); } /* 802CBAA4-802CBAD8 .text JUTWarningConsole */ -void JUTWarningConsole { - /* Nonmatching */ +void JUTWarningConsole(const char* message) { + JUTReportConsole_f("%s", message); } diff --git a/src/JSystem/JUtility/JUTException.cpp b/src/JSystem/JUtility/JUTException.cpp index 7e113e680..b32a961b9 100644 --- a/src/JSystem/JUtility/JUTException.cpp +++ b/src/JSystem/JUtility/JUTException.cpp @@ -4,154 +4,1007 @@ // #include "JSystem/JUtility/JUTException.h" -#include "dolphin/types.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTDirectFile.h" +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "MSL_C/math.h" +#include "MSL_C/stdio.h" +#include "MSL_C/stdlib.h" +#include "dolphin/base/PPCArch.h" +#include "dolphin/gx/GX.h" +#include "dolphin/os/OS.h" +#include "dolphin/vi/vi.h" + +struct CallbackObject { + /* 0x00 */ OSErrorHandler callback; + /* 0x04 */ u16 error; + /* 0x06 */ u16 pad_0x06; + /* 0x08 */ OSContext* context; + /* 0x0C */ int param_3; + /* 0x10 */ int param_4; +}; + +void search_name_part(u8*, u8*, int); + +OSMessageQueue JUTException::sMessageQueue = {}; +static OSTime c3bcnt[4] = {0, 0, 0, 0}; +const char* JUTException::sCpuExpName[] = { + "SYSTEM RESET", + "MACHINE CHECK", + "DSI", + "ISI", + "EXTERNAL INTERRUPT", + "ALIGNMENT", + "PROGRAM", + "FLOATING POINT", + "DECREMENTER", + "SYSTEM CALL", + "TRACE", + "PERFORMACE MONITOR", + "BREAK POINT", + "SYSTEM INTERRUPT", + "THERMAL INTERRUPT", + "PROTECTION", + "FLOATING POINT", +}; +JUTException* JUTException::sErrorManager; +OSErrorHandler JUTException::sPreUserCallback; +OSErrorHandler JUTException::sPostUserCallback; /* 802C4AC8-802C4BAC .text __ct__12JUTExceptionFP14JUTDirectPrint */ -JUTException::JUTException(JUTDirectPrint*) { - /* Nonmatching */ +JUTException::JUTException(JUTDirectPrint* directPrint) : JKRThread(0x4000, 0x10, 0) { + mDirectPrint = directPrint; + OSSetErrorHandler(EXCEPTION_DSI, errorHandler); + OSSetErrorHandler(EXCEPTION_ISI, errorHandler); + OSSetErrorHandler(EXCEPTION_PROGRAM, errorHandler); + OSSetErrorHandler(EXCEPTION_ALIGNMENT, errorHandler); + OSSetErrorHandler(EXCEPTION_MEMORY_PROTECTION, errorHandler); + setFPException(0); + + sPreUserCallback = NULL; + sPostUserCallback = NULL; + + setGamePad(NULL); + + this->mPrintWaitTime0 = 10; + this->mPrintWaitTime1 = 10; + this->mTraceSuppress = -1; + this->field_0x98 = 0; + this->mPrintFlags = + JUT_PRINT_GPR | JUT_PRINT_GPR_MAP | JUT_PRINT_SRR0_MAP | JUT_PRINT_FLOAT | JUT_PRINT_STACK; } /* 802C4BAC-802C4C14 .text create__12JUTExceptionFP14JUTDirectPrint */ -void JUTException::create(JUTDirectPrint*) { - /* Nonmatching */ +JUTException* JUTException::create(JUTDirectPrint* directPrint) { + if (!sErrorManager) { + JKRHeap* systemHeap = JKRGetSystemHeap(); + sErrorManager = new (systemHeap, 0) JUTException(directPrint); + sErrorManager->resume(); + } + + return sErrorManager; } +OSMessage JUTException::sMessageBuffer[1] = {0}; + /* 802C4C14-802C4CEC .text run__12JUTExceptionFv */ -void JUTException::run() { - /* Nonmatching */ +void* JUTException::run() { + PPCMtmsr(PPCMfmsr() & ~0x0900); + OSInitMessageQueue(&sMessageQueue, sMessageBuffer, 1); + OSMessage message; + while (true) { + OSReceiveMessage(&sMessageQueue, &message, OS_MESSAGE_BLOCK); + CallbackObject* cb = (CallbackObject*)message; + OSErrorHandler callback = cb->callback; + u16 error = cb->error; + OSContext* context = cb->context; + int r24 = cb->param_3; + int r23 = cb->param_4; + mFrameMemory = (JUTExternalFB*)sErrorManager->mDirectPrint->getFrameBuffer(); + if (!sErrorManager->mDirectPrint->getFrameBuffer()) { + sErrorManager->createFB(); + } + if (callback) { + callback(error, context, r24, r23); + } + OSDisableInterrupts(); + sErrorManager->printContext(error, context, r24, r23); + } } +static CallbackObject exCallbackObject; +void* JUTException::sConsoleBuffer; +u32 JUTException::sConsoleBufferSize; +JUTConsole* JUTException::sConsole; +u32 JUTException::msr; +u32 JUTException::fpscr; + /* 802C4CEC-802C5084 .text errorHandler__12JUTExceptionFUsP9OSContextUlUl */ -void JUTException::errorHandler(unsigned short, OSContext*, unsigned long, unsigned long) { +void JUTException::errorHandler(OSError error, OSContext* context, u32 param_3, u32 param_4) { /* Nonmatching */ + if (error == 0x10) { + OSReport("\x1b[41;37m"); + OSReport(" FPE: 浮動小数点例外が発生しました。アドレスは %08x fpscr=%08x\n", context->srr0, context->fpscr); + u8 stack_38[0x20]; + u32 stack_3c; + u32 stack_40; + u32 stack_44; + u32 stack_48; + if (searchPartialModule(context->srr0, &stack_40, &stack_44, &stack_48, &stack_3c) == 1) { + search_name_part((u8*)stack_3c, stack_38, 0x20); + OSReport("%s:%x section:%d\n", stack_38, stack_48, stack_44); + } + u32 r31 = context->fpscr; + r31 &= ((context->fpscr & 0xf8) << 22) | 0x01f80700; + if (r31 & 0x20000000) { + context->fpscr &= ~0x80; + OSReport(" FPE: Invalid operation(無効な演算)\n"); + if (fpscr & 0x01000000) { + OSReport(" SNaN\n"); + } + if (fpscr & 0x00800000) { + OSReport(" Infinity - Infinity\n"); + } + if (fpscr & 0x00400000) { + OSReport(" Infinity / Infinity\n"); + } + if (fpscr & 0x00200000) { + OSReport(" 0 / 0\n"); + } + if (fpscr & 0x00100000) { + OSReport(" Infinity * 0\n"); + } + if (fpscr & 0x00080000) { + OSReport(" Invalid compare\n"); + } + if (fpscr & 0x0400) { + OSReport(" Software request\n"); + } + if (fpscr & 0x0200) { + OSReport(" Invalid square root\n"); + } + if (fpscr & 0x0100) { + OSReport(" Invalid integer convert\n"); + } + } + if (r31 & 0x10000000) { + context->fpscr &= ~0x40; + OSReport(" FPE: Overflow(オーバーフロー)\n"); + } + if (r31 & 0x08000000) { + context->fpscr &= ~0x20; + OSReport(" FPE: Underflow(アンダーフロー)\n"); + } + if (r31 & 0x04000000) { + context->fpscr &= ~0x10; + OSReport(" FPE: Zero division(0による割り算)\n"); + } + if (r31 & 0x02000000) { + context->fpscr &= ~0x08; + OSReport(" FPE: Inexact result(不正確な結果)\n"); + } + OSReport("\x1b[m"); + return; + } + + msr = PPCMfmsr(); + fpscr = context->fpscr; + OSFillFPUContext(context); + OSSetErrorHandler(error, NULL); + if (error == OS_ERROR_MEMORY_PROTECTION) { + OSProtectRange(0, NULL, 0, 3); + OSProtectRange(1, NULL, 0, 3); + OSProtectRange(2, NULL, 0, 3); + OSProtectRange(3, NULL, 0, 3); + } + + exCallbackObject.callback = sPreUserCallback; + exCallbackObject.error = error; + exCallbackObject.context = context; + exCallbackObject.param_3 = param_3; + exCallbackObject.param_4 = param_4; + + OSSendMessage(&sMessageQueue, &exCallbackObject, OS_MESSAGE_BLOCK); + OSEnableScheduler(); + OSYieldThread(); } /* 802C5084-802C50CC .text setFPException__12JUTExceptionFUl */ -void JUTException::setFPException(unsigned long) { - /* Nonmatching */ +void JUTException::setFPException(u32 fpscr_enable_bits) { + __OSFpscrEnableBits = fpscr_enable_bits; + if (fpscr_enable_bits) { + OSSetErrorHandler(EXCEPTION_FLOATING_POINT_EXCEPTION, errorHandler); + } else { + OSSetErrorHandler(EXCEPTION_FLOATING_POINT_EXCEPTION, NULL); + } } /* 802C50CC-802C525C .text showFloatSub__12JUTExceptionFif */ -void JUTException::showFloatSub(int, float) { - /* Nonmatching */ +void JUTException::showFloatSub(int index, f32 value) { + if (fpclassify(value) == FP_NAN) { + sConsole->print_f("F%02d: Nan ", index); + } else if (fpclassify(value) == FP_INFINITE) { + if (signbit(value)) { + sConsole->print_f("F%02d:+Inf ", index); + } else { + sConsole->print_f("F%02d:-Inf ", index); + } + } else if (value == 0.0f) { + sConsole->print_f("F%02d: 0.0 ", index); + } else { + sConsole->print_f("F%02d:%+.3E", index, value); + } } /* 802C525C-802C5380 .text showFloat__12JUTExceptionFP9OSContext */ -void JUTException::showFloat(OSContext*) { - /* Nonmatching */ +void JUTException::showFloat(OSContext* context) { + if (!sConsole) { + return; + } + + sConsole->print("-------------------------------- FPR\n"); + for (int i = 0; i < 10; i++) { + showFloatSub(i, context->fpr[i]); + sConsole->print(" "); + showFloatSub(i + 11, context->fpr[i + 11]); + sConsole->print(" "); + showFloatSub(i + 22, context->fpr[i + 22]); + sConsole->print("\n"); + } + showFloatSub(10, context->fpr[10]); + sConsole->print(" "); + showFloatSub(21, context->fpr[21]); + sConsole->print("\n"); } /* 802C5380-802C5440 .text searchPartialModule__12JUTExceptionFUlPUlPUlPUlPUl */ -void JUTException::searchPartialModule(unsigned long, unsigned long*, unsigned long*, unsigned long*, unsigned long*) { - /* Nonmatching */ +bool JUTException::searchPartialModule(u32 address, u32* module_id, u32* section_id, u32* section_offset, u32* name_offset) { + if (!address) { + return false; + } + + OSModuleInfo* module = *(OSModuleInfo**)0x800030C8; + while (module) { + OSSectionInfo* section = (OSSectionInfo*)module->info.sectionInfoOffset; + for (u32 i = 0; i < module->mNumSections; section = section + 1, i++) { + if (section->mSize) { + u32 addr = ALIGN_PREV(section->mOffset, 2); + if ((addr <= address) && (address < addr + section->mSize)) { + if (module_id) + *module_id = module->mId; + if (section_id) + *section_id = i; + if (section_offset) + *section_offset = address - addr; + if (name_offset) + *name_offset = module->mModuleNameOffset; + return true; + } + } + } + + module = (OSModuleInfo*)module->mNext; + } + + return false; } /* 802C5440-802C54B8 .text search_name_part__FPUcPUci */ -void search_name_part(unsigned char*, unsigned char*, int) { - /* Nonmatching */ +void search_name_part(u8* src, u8* dst, int dst_length) { + for (u8* p = src; *p; p++) { + if (*p == '\\') { + src = p; + } + } + + if (*src == '\\') { + src++; + } + + for (int i = 0; (*src != 0) && (i < dst_length);) { + if (*src == '.') + break; + *dst++ = *src++; + i++; + } + + *dst = '\0'; } /* 802C54B8-802C55BC .text showStack__12JUTExceptionFP9OSContext */ -void JUTException::showStack(OSContext*) { - /* Nonmatching */ +void JUTException::showStack(OSContext* context) { + if (!sConsole) { + return; + } + + u32 i; + u32* stackPointer; + sConsole->print("-------------------------------- TRACE\n"); + sConsole->print_f("Address: BackChain LR save\n"); + + for (i = 0, stackPointer = (u32*)context->gpr[1]; (stackPointer != NULL) && (stackPointer != (u32*)0xFFFFFFFF) && (i++ < 0x10);) { + if (i > mTraceSuppress) { + sConsole->print("Suppress trace.\n"); + return; + } + + sConsole->print_f("%08X: %08X %08X\n", stackPointer, stackPointer[0], stackPointer[1]); + showMapInfo_subroutine(stackPointer[1], false); + JUTConsoleManager* manager = JUTConsoleManager::sManager; + manager->drawDirect(true); + waitTime(mPrintWaitTime1); + stackPointer = (u32*)stackPointer[0]; + } } /* 802C55BC-802C586C .text showMainInfo__12JUTExceptionFUsP9OSContextUlUl */ -void JUTException::showMainInfo(unsigned short, OSContext*, unsigned long, unsigned long) { - /* Nonmatching */ +void JUTException::showMainInfo(u16 error, OSContext* context, u32 dsisr, u32 dar) { + if (!sConsole) { + return; + } + + sConsole->print_f("CONTEXT:%08XH (%s EXCEPTION)\n", context, sCpuExpName[error]); + + if (error == OS_ERROR_FLOATING_POINT_EXCEPTION) { + u32 flags = fpscr & (((fpscr & 0xf8) << 0x16) | 0x1f80700); + if ((flags & 0x20000000) != 0) { + sConsole->print_f(" FPE: Invalid operation\n"); + if ((fpscr & 0x1000000) != 0) { + sConsole->print_f(" SNaN\n"); + } + if ((fpscr & 0x800000) != 0) { + sConsole->print_f(" Infinity - Infinity\n"); + } + if ((fpscr & 0x400000) != 0) { + sConsole->print_f(" Infinity / Infinity\n"); + } + if ((fpscr & 0x200000) != 0) { + sConsole->print_f(" 0 / 0\n"); + } + if ((fpscr & 0x100000) != 0) { + sConsole->print_f(" Infinity * 0\n"); + } + if ((fpscr & 0x80000) != 0) { + sConsole->print_f(" Invalid compare\n"); + } + if ((fpscr & 0x400) != 0) { + sConsole->print_f(" Software request\n"); + } + if ((fpscr & 0x200) != 0) { + sConsole->print_f(" Invalid square root\n"); + } + if ((fpscr & 0x100) != 0) { + sConsole->print_f(" Invalid integer convert\n"); + } + } + if ((flags & 0x10000000) != 0) { + sConsole->print_f(" FPE: Overflow\n"); + } + if ((flags & 0x8000000) != 0) { + sConsole->print_f(" FPE: Underflow\n"); + } + if ((flags & 0x4000000) != 0) { + sConsole->print_f(" FPE: Zero division\n"); + } + if ((flags & 0x2000000) != 0) { + sConsole->print_f(" FPE: Inexact result\n"); + } + } + sConsole->print_f("SRR0: %08XH SRR1:%08XH\n", context->srr0, context->srr1); + sConsole->print_f("DSISR: %08XH DAR: %08XH\n", dsisr, dar); } /* 802C586C-802C592C .text showGPR__12JUTExceptionFP9OSContext */ -void JUTException::showGPR(OSContext*) { - /* Nonmatching */ +void JUTException::showGPR(OSContext* context) { + if (!sConsole) { + return; + } + + sConsole->print("-------------------------------- GPR\n"); + for (int i = 0; i < 10; i++) { + sConsole->print_f("R%02d:%08XH R%02d:%08XH R%02d:%08XH\n", i, context->gpr[i], i + 11, + context->gpr[i + 11], i + 22, context->gpr[i + 22]); + } + sConsole->print_f("R%02d:%08XH R%02d:%08XH\n", 10, context->gpr[10], 21, context->gpr[21]); } +JSUList JUTException::sMapFileList(false); + /* 802C592C-802C5A88 .text showMapInfo_subroutine__12JUTExceptionFUlb */ -void JUTException::showMapInfo_subroutine(unsigned long, bool) { - /* Nonmatching */ +bool JUTException::showMapInfo_subroutine(u32 address, bool begin_with_newline) { + if ((address < 0x80000000) || (0x82ffffff < address)) { + return false; + } + + u32 name_offset; + u32 module_id; + u32 section_id; + u32 section_offset; + u8 name_part[36]; + + const char* new_line = "\n"; + if (begin_with_newline == false) { + new_line = ""; + } + + bool result = + searchPartialModule(address, &module_id, §ion_id, §ion_offset, &name_offset); + if (result == true) { + search_name_part((u8*)name_offset, name_part, 32); + sConsole->print_f("%s %s:%x section:%d\n", new_line, name_part, section_offset, section_id); + begin_with_newline = false; + } + + JSUListIterator last = sMapFileList.getEnd(); + JSUListIterator first = sMapFileList.getFirst(); + if (first != last) { + u32 out_addr; + u32 out_size; + char out_line[256]; + + if (result == true) { + result = + queryMapAddress((char*)name_part, section_offset, section_id, &out_addr, &out_size, + out_line, ARRAY_SIZE(out_line), true, begin_with_newline); + } else { + result = queryMapAddress(NULL, address, -1, &out_addr, &out_size, out_line, + ARRAY_SIZE(out_line), true, begin_with_newline); + } + + if (result == true) { + return true; + } + } + + return false; } /* 802C5A88-802C5B94 .text showGPRMap__12JUTExceptionFP9OSContext */ -void JUTException::showGPRMap(OSContext*) { - /* Nonmatching */ +void JUTException::showGPRMap(OSContext* context) { + if (!sConsole) { + return; + } + + bool found_address_register = false; + sConsole->print("-------------------------------- GPRMAP\n"); + + for (int i = 0; i < 31; i++) { + u32 address = context->gpr[i]; + + if (address >= 0x80000000 && 0x83000000 - 1 >= address) { + found_address_register = true; + + sConsole->print_f("R%02d: %08XH", i, address); + if (!showMapInfo_subroutine(address, true)) { + sConsole->print(" no information\n"); + } + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime1); + } + } + + if (!found_address_register) { + sConsole->print(" no register which seem to address.\n"); + } } /* 802C5B94-802C5C58 .text showSRR0Map__12JUTExceptionFP9OSContext */ -void JUTException::showSRR0Map(OSContext*) { - /* Nonmatching */ +void JUTException::showSRR0Map(OSContext* context) { + if (!sConsole) { + return; + } + + sConsole->print("-------------------------------- SRR0MAP\n"); + u32 address = context->srr0; + if (address >= 0x80000000 && 0x83000000 - 1 >= address) { + sConsole->print_f("SRR0: %08XH", address); + if (showMapInfo_subroutine(address, true) == false) { + sConsole->print(" no information\n"); + } + JUTConsoleManager::getManager()->drawDirect(true); + } } /* 802C5C58-802C5D00 .text printDebugInfo__12JUTExceptionFQ212JUTException9EInfoPageUsP9OSContextUlUl */ -void JUTException::printDebugInfo(JUTException::EInfoPage, unsigned short, OSContext*, unsigned long, unsigned long) { - /* Nonmatching */ +void JUTException::printDebugInfo(JUTException::EInfoPage page, OSError error, OSContext* context, u32 param_3, u32 param_4) { + switch (page) { + case EINFO_PAGE_GPR: + return showGPR(context); + case EINFO_PAGE_FLOAT: + showFloat(context); + if (sConsole) { + sConsole->print_f(" MSR:%08XH\t FPSCR:%08XH\n", msr, fpscr); + } + break; + case EINFO_PAGE_STACK: + return showStack(context); + case EINFO_PAGE_GPR_MAP: + return showGPRMap(context); + case EINFO_PAGE_SSR0_MAP: + return showSRR0Map(context); + } } /* 802C5D00-802C5D3C .text isEnablePad__12JUTExceptionCFv */ -void JUTException::isEnablePad() const { - /* Nonmatching */ +bool JUTException::isEnablePad() const { + if (mGamePad == (JUTGamePad*)0xFFFFFFFF) + return true; + + if (mGamePadPort >= 0) + return true; + + return mGamePad; } /* 802C5D3C-802C62A8 .text readPad__12JUTExceptionFPUlPUl */ -void JUTException::readPad(unsigned long*, unsigned long*) { - /* Nonmatching */ +bool JUTException::readPad(u32* out_trigger, u32* out_button) { + bool result = false; + OSTime start_time = OSGetTime(); + OSTime ms; + do { + OSTime end_time = OSGetTime(); + OSTime ticks = end_time - start_time; + ms = ticks / (OS_TIMER_CLOCK / 1000); + } while (ms < 0x32); + + if (mGamePad == (JUTGamePad*)0xffffffff) { + JUTGamePad gamePad0(JUTGamePad::Port_1); + JUTGamePad gamePad1(JUTGamePad::Port_2); + JUTGamePad gamePad2(JUTGamePad::Port_3); + JUTGamePad gamePad3(JUTGamePad::Port_4); + JUTGamePad::read(); + + c3bcnt[0] = + (gamePad0.isPushing3ButtonReset() ? (c3bcnt[0] != 0 ? c3bcnt[0] : OSGetTime()) : 0); + c3bcnt[1] = + (gamePad1.isPushing3ButtonReset() ? (c3bcnt[1] != 0 ? c3bcnt[1] : OSGetTime()) : 0); + c3bcnt[2] = + (gamePad2.isPushing3ButtonReset() ? (c3bcnt[2] != 0 ? c3bcnt[2] : OSGetTime()) : 0); + c3bcnt[3] = + (gamePad3.isPushing3ButtonReset() ? (c3bcnt[3] != 0 ? c3bcnt[3] : OSGetTime()) : 0); + + OSTime resetTime0 = (c3bcnt[0] != 0) ? (OSGetTime() - c3bcnt[0]) : 0; + OSTime resetTime1 = (c3bcnt[1] != 0) ? (OSGetTime() - c3bcnt[1]) : 0; + OSTime resetTime2 = (c3bcnt[2] != 0) ? (OSGetTime() - c3bcnt[2]) : 0; + OSTime resetTime3 = (c3bcnt[3] != 0) ? (OSGetTime() - c3bcnt[3]) : 0; + + gamePad0.checkResetCallback(resetTime0); + gamePad1.checkResetCallback(resetTime1); + gamePad2.checkResetCallback(resetTime2); + gamePad3.checkResetCallback(resetTime3); + + if (out_trigger) { + *out_trigger = gamePad0.getTrigger() | gamePad1.getTrigger() | gamePad2.getTrigger() | + gamePad3.getTrigger(); + } + if (out_button) { + *out_button = gamePad0.getButton() | gamePad1.getButton() | gamePad2.getButton() | + gamePad3.getButton(); + } + + result = true; + } else if (mGamePadPort >= 0) { + JUTGamePad gamePad(mGamePadPort); + OSTime& gamePadTime = c3bcnt[0]; + gamePadTime = + (gamePad.isPushing3ButtonReset() ? (gamePadTime != 0 ? gamePadTime : OSGetTime()) : 0); + + OSTime resetTime = (gamePadTime != 0) ? (OSGetTime() - gamePadTime) : 0; + gamePad.checkResetCallback(resetTime); + + JUTGamePad::read(); + if (out_trigger) { + *out_trigger = gamePad.getTrigger(); + } + if (out_button) { + *out_button = gamePad.getButton(); + } + + result = true; + } else if (mGamePad) { + JUTGamePad::read(); + if (out_trigger) { + *out_trigger = mGamePad->getTrigger(); + } + if (out_button) { + *out_button = mGamePad->getButton(); + } + + result = true; + } + + return result; } /* 802C62A8-802C6724 .text printContext__12JUTExceptionFUsP9OSContextUlUl */ -void JUTException::printContext(unsigned short, OSContext*, unsigned long, unsigned long) { - /* Nonmatching */ +void JUTException::printContext(OSError error, OSContext* context, u32 dsisr, u32 dar) { + bool is_pad_enabled = isEnablePad() == 0; + if (!sErrorManager->mDirectPrint->isActive()) { + return; + } + + if (!sConsole) { + return; + } + + sConsole->print_f("******** EXCEPTION OCCURRED! ********\nFrameMemory:%XH\n", getFrameMemory()); + + int post_callback_executed = false; + while (true) { + showMainInfo(error, context, dsisr, dar); + + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + + if ((mPrintFlags & JUT_PRINT_GPR) != 0) { + printDebugInfo(EINFO_PAGE_GPR, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & JUT_PRINT_SRR0_MAP) != 0) { + printDebugInfo(EINFO_PAGE_SSR0_MAP, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & JUT_PRINT_GPR_MAP) != 0) { + printDebugInfo(EINFO_PAGE_GPR_MAP, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & JUT_PRINT_FLOAT) != 0) { + printDebugInfo(EINFO_PAGE_FLOAT, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & JUT_PRINT_STACK) != 0) { + printDebugInfo(EINFO_PAGE_STACK, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime1); + } + + sConsole->print("--------------------------------\n"); + JUTConsoleManager::sManager->drawDirect(true); + + if (post_callback_executed == 0 && sPostUserCallback) { + BOOL enable = OSEnableInterrupts(); + post_callback_executed = true; + (*sPostUserCallback)(error, context, dsisr, dar); + OSRestoreInterrupts(enable); + } + + if (this->field_0x98 == 0 || !is_pad_enabled) { + break; + } + + sConsole->setOutput(sConsole->getOutput() & 1); + } + + if (!is_pad_enabled) { + OSEnableInterrupts(); + + u32 button; + u32 trigger; + + int down = 0; + int up = 0; + do { + readPad(&trigger, &button); + + bool draw = false; + if (trigger == 0x100) { + sConsole->scrollToLastLine(); + draw = true; + } + + if (trigger == 0x200) { + sConsole->scrollToFirstLine(); + draw = true; + } + + if (button == 8) { + JUTConsole* console = sConsole; + up = (down < 3) ? -1 : ((down < 5) ? -2 : ((down < 7) ? -4 : -8)); + + console->scroll(up); + draw = true; + up = 0; + down++; + } else if (button == 4) { + JUTConsole* console = sConsole; + down = (up < 3) ? 1 : ((up < 5) ? 2 : ((up < 7) ? 4 : 8)); + + console->scroll(down); + draw = true; + down = 0; + up++; + } else { + down = 0; + up = 0; + } + + if (draw == true) { + u32 start = VIGetRetraceCount(); + while (start == VIGetRetraceCount()) + ; + JUTConsoleManager::sManager->drawDirect(true); + } + + waitTime(30); + } while (true); + } + + while (true) { + sConsole->scrollToFirstLine(); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(2000); + + int line_offset; + int used_line; + u32 height; + next: + for (u32 i = sConsole->getHeight(); i > 0; i--) { + sConsole->scroll(1); + JUTConsoleManager::sManager->drawDirect(true); + + height = sConsole->getHeight(); + JUTConsole* console = sConsole; + line_offset = console->getLineOffset(); + used_line = console->getUsedLine(); + if ((used_line - height) + 1U <= line_offset) + break; + waitTime(20); + } + + waitTime(3000); + height = sConsole->getHeight(); + JUTConsole* console = sConsole; + line_offset = console->getLineOffset(); + used_line = console->getUsedLine(); + if ((used_line - height) + 1U <= line_offset) { + continue; + } + goto next; + } } /* 802C6724-802C67AC .text waitTime__12JUTExceptionFl */ -void JUTException::waitTime(long) { - /* Nonmatching */ +void JUTException::waitTime(s32 timeout_ms) { + if (timeout_ms) { + OSTime start_time = OSGetTime(); + OSTime ms; + do { + OSTime end_time = OSGetTime(); + OSTime ticks = end_time - start_time; + ms = ticks / (OS_TIMER_CLOCK / 1000); + } while (ms < timeout_ms); + } } /* 802C67AC-802C6868 .text createFB__12JUTExceptionFv */ void JUTException::createFB() { - /* Nonmatching */ + GXRenderModeObj* renderMode = &GXNtsc480Int; + void* end = (void*)OSGetArenaHi(); + u16 width = ALIGN_NEXT(renderMode->fb_width, 16); + u16 height = renderMode->xfb_height; + u32 pixel_count = width * height; + u32 size = pixel_count * 2; + + void* begin = (void*)ALIGN_PREV((u32)end - size, 32); + void* object = (void*)ALIGN_PREV((s32)begin - sizeof(JUTExternalFB), 32); + new (object) JUTExternalFB(renderMode, GX_GM_1_7, begin, size); + + mDirectPrint->changeFrameBuffer(object); + VIConfigure(renderMode); + VISetNextFrameBuffer(begin); + VISetBlack(FALSE); + VIFlush(); + + mFrameMemory = (JUTExternalFB*)object; } /* 802C6868-802C6878 .text setPreUserCallback__12JUTExceptionFPFUsP9OSContextUlUl_v */ -void JUTException::setPreUserCallback(void (*)(unsigned short, OSContext*, unsigned long, unsigned long)) { - /* Nonmatching */ +OSErrorHandler JUTException::setPreUserCallback(OSErrorHandler callback) { + OSErrorHandler previous = sPreUserCallback; + sPreUserCallback = callback; + return previous; } /* 802C6878-802C6888 .text setPostUserCallback__12JUTExceptionFPFUsP9OSContextUlUl_v */ -void JUTException::setPostUserCallback(void (*)(unsigned short, OSContext*, unsigned long, unsigned long)) { - /* Nonmatching */ +OSErrorHandler JUTException::setPostUserCallback(OSErrorHandler callback) { + OSErrorHandler previous = sPostUserCallback; + sPostUserCallback = callback; + return previous; } /* 802C6888-802C691C .text appendMapFile__12JUTExceptionFPCc */ -void JUTException::appendMapFile(const char*) { - /* Nonmatching */ +void JUTException::appendMapFile(const char* path) { + if (!path) { + return; + } + + JSUListIterator iterator; + for (iterator = sMapFileList.getFirst(); iterator != sMapFileList.getEnd(); ++iterator) { + if (strcmp(path, iterator->mPath) == 0) { + return; + } + } + + JUTExMapFile* mapFile = new JUTExMapFile((char*)path); + sMapFileList.append(&mapFile->mLink); } /* 802C691C-802C6A0C .text queryMapAddress__12JUTExceptionFPcUllPUlPUlPcUlbb */ -void JUTException::queryMapAddress(char*, unsigned long, long, unsigned long*, unsigned long*, char*, unsigned long, bool, bool) { - /* Nonmatching */ +bool JUTException::queryMapAddress(char* mapPath, u32 address, s32 section_id, u32* out_addr, u32* out_size, char* out_line, u32 line_length, bool print, bool begin_with_newline) { + if (mapPath) { + char buffer[80]; + snprintf(buffer, sizeof(buffer), "/maps/%s.map", mapPath); + if (queryMapAddress_single(buffer, address, section_id, out_addr, out_size, out_line, + line_length, print, begin_with_newline) == true) + { + return true; + } + } else if (sMapFileList.getFirst() != sMapFileList.getEnd()) { + if (queryMapAddress_single(sMapFileList.getFirst()->getObject()->mPath, address, -1, + out_addr, out_size, out_line, line_length, print, + begin_with_newline) == true) + { + return true; + } + } + + return false; } /* 802C6A0C-802C6D60 .text queryMapAddress_single__12JUTExceptionFPcUllPUlPUlPcUlbb */ -void JUTException::queryMapAddress_single(char*, unsigned long, long, unsigned long*, unsigned long*, char*, unsigned long, bool, bool) { +bool JUTException::queryMapAddress_single(char* mapPath, u32 address, s32 section_id, u32* out_addr, u32* out_size, char* out_line, u32 line_length, bool print, bool begin_with_newline) { /* Nonmatching */ + if (!mapPath) { + return false; + } + + char section_name[16]; + char buffer[0x200]; + JUTDirectFile file; + int i = 0; + if (!file.fopen(mapPath)) { + return false; + } + + int result = 0; + do { + char* src = buffer; + int found_section = 0; + do { + i++; + while (true) { + while (true) { + int length = file.fgets(buffer, ARRAY_SIZE(buffer)); + if (length < 0) + goto next_section; + if (buffer[0] == '.') + break; + } + + char* dst = section_name; + int i = 0; + char* src = buffer + 1; + for (; *src != '\0'; i++, dst++, src++) { + *dst = *src; + if (*src == ' ' || i == 0xf) + break; + } + + section_name[i] = 0; + if (*src == 0) + break; + + if (src[1] == 's' && src[2] == 'e' && src[3] == 'c' && src[4] == 't') { + found_section = true; + break; + } + } + if ((found_section & 0xFF) == 0) + goto end; + } while (section_id >= 0 && section_id != i); + next_section:; + + u32 addr; + int size; + do { + int length; + do { + length = file.fgets(buffer, ARRAY_SIZE(buffer)); + if (length <= 4) + goto next_symbol; + } while ((length < 28) || (buffer[28] != '4')); + + addr = strtol(buffer + 19, NULL, 16); + addr = ((buffer[18] - '0') << 28) | addr; + size = strtol(buffer + 11, NULL, 16); + } while (addr > address || address >= addr + size); + + if (out_addr) + *out_addr = addr; + + if (out_size) + *out_size = size; + + if (out_line) { + src = buffer + 0x1e; + char* dst = out_line; + u32 length = 0; + for (; length < line_length - 1; src++) { + u32 ch = *(u8*)src; + if (ch < ' ' && ch != '\t') + break; + if (((int)ch == ' ' || ch == '\t') && (length != 0)) { + if (dst[-1] != ' ') { + *dst = ' '; + dst++; + length++; + } + } else { + *dst = ch; + dst++; + length++; + } + } + if (length != 0 && dst[-1] == ' ') { + dst--; + } + *dst = 0; + if (print) { + if (begin_with_newline) { + sConsole->print("\n"); + } + sConsole->print_f(" [%08X]: .%s [%08X: %XH]\n %s\n", address, section_name, addr, size, out_line); + begin_with_newline = false; + } + } + + result = true; + + next_symbol:; + } while (section_id >= 0 && section_id != i); + + if (print && begin_with_newline) { + sConsole->print("\n"); + } + +end: + file.fclose(); + bool bresult = (result & 0xff) != 0; + return bresult; } /* 802C6D60-802C6E40 .text createConsole__12JUTExceptionFPvUl */ -void JUTException::createConsole(void*, unsigned long) { - /* Nonmatching */ +void JUTException::createConsole(void* console_buffer, u32 console_buffer_size) { + if (!console_buffer || !console_buffer_size) { + return; + } + + u32 lines = JUTConsole::getLineFromObjectSize(console_buffer_size, 0x32); + if (lines != 0) { + sConsoleBuffer = console_buffer; + sConsoleBufferSize = console_buffer_size; + sConsole = JUTConsole::create(0x32, console_buffer, console_buffer_size); + + JUTConsoleManager* manager = JUTConsoleManager::sManager; + manager->setDirectConsole(sConsole); + + sConsole->setFontSize(10.0, 6.0); + sConsole->setPosition(12, 40); + sConsole->setHeight(23); + sConsole->setVisible(true); + sConsole->setOutput(JUTConsole::OUTPUT_OSREPORT | JUTConsole::OUTPUT_CONSOLE); + } } /* 802C6E40-802C6E60 .text __ct__13JUTExternalFBFP16_GXRenderModeObj8_GXGammaPvUl */ -JUTExternalFB::JUTExternalFB(_GXRenderModeObj*, _GXGamma, void*, unsigned long) { - /* Nonmatching */ -} - -/* 802C6E60-802C6EC0 .text __dt__12JUTExceptionFv */ -JUTException::~JUTException() { - /* Nonmatching */ -} - -/* 802C6F08-802C6F5C .text __dt__39JSUListFv */ -JSUList::~JSUList() { - /* Nonmatching */ +JUTExternalFB::JUTExternalFB(GXRenderModeObj* renderMode, GXGamma gamma, void* buffer, u32 size) { + mRenderMode = renderMode; + mSize = size; + field_0x0C = 1; + mGamma = gamma; + field_0x10 = false; } From 1ad444aa73d7d5ac8c2ecb29862866f44480e989 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Thu, 21 Sep 2023 00:09:23 -0400 Subject: [PATCH 3/4] Started d_a_arrow (#64) * More d_bg header improvements * Cleanup, use mtx inlines in more places * Added JntHit_c to headers * Started d_a_arrow --- include/SSystem/SComponent/c_bg_s_chk.h | 6 +- include/SSystem/SComponent/c_bg_s_lin_chk.h | 6 +- include/SSystem/SComponent/c_bg_w.h | 2 +- include/SSystem/SComponent/c_m3d_g_cps.h | 4 +- include/d/actor/d_a_arrow.h | 90 ++++ include/d/actor/d_a_player.h | 4 +- include/d/actor/d_a_player_link.h | 4 +- include/d/d_bg_s_gnd_chk.h | 4 +- include/d/d_bg_s_grp_pass_chk.h | 28 +- include/d/d_bg_s_lin_chk.h | 15 +- include/d/d_bg_s_poly_pass_chk.h | 16 +- include/d/d_bg_w.h | 3 +- include/d/d_cc_d.h | 8 +- include/d/d_com_inf_game.h | 11 + include/d/d_jnt_hit.h | 30 ++ include/d/d_particle.h | 1 + include/f_op/f_op_actor.h | 4 +- include/f_op/f_op_actor_mng.h | 8 +- include/m_Do/m_Do_mtx.h | 16 +- src/d/actor/d_a_arrow.cpp | 434 +++++++++++--------- src/d/actor/d_a_branch.cpp | 2 +- src/d/actor/d_a_kaji.cpp | 4 +- src/d/actor/d_a_nh.cpp | 11 +- src/d/actor/d_a_obj_movebox.cpp | 4 +- src/d/actor/d_a_obj_paper.cpp | 2 +- src/d/actor/d_a_scene_change.cpp | 6 +- src/d/actor/d_a_spotbox.cpp | 8 +- 27 files changed, 476 insertions(+), 255 deletions(-) create mode 100644 include/d/actor/d_a_arrow.h create mode 100644 include/d/d_jnt_hit.h diff --git a/include/SSystem/SComponent/c_bg_s_chk.h b/include/SSystem/SComponent/c_bg_s_chk.h index 4b76bad12..bb28ccce6 100644 --- a/include/SSystem/SComponent/c_bg_s_chk.h +++ b/include/SSystem/SComponent/c_bg_s_chk.h @@ -22,7 +22,11 @@ private: /* 0x10 */ // __vtable__ public: - cBgS_Chk(); + cBgS_Chk() { + mPolyPassChk = NULL; + mGrpPassChk = NULL; + unk_0x0C = 1; + } void SetExtChk(cBgS_Chk&); bool ChkSameActorPid(unsigned int) const; diff --git a/include/SSystem/SComponent/c_bg_s_lin_chk.h b/include/SSystem/SComponent/c_bg_s_lin_chk.h index f1ff9f872..c690833f3 100644 --- a/include/SSystem/SComponent/c_bg_s_lin_chk.h +++ b/include/SSystem/SComponent/c_bg_s_lin_chk.h @@ -18,13 +18,13 @@ public: /* 0x054 */ bool mBackFlag; public: - cBgS_LinChk(); + cBgS_LinChk() { ct(); } void ct(); void Set2(cXyz*, cXyz*, unsigned int); void PreCalc(); void GetCross(); - virtual ~cBgS_LinChk(); + virtual ~cBgS_LinChk() {} void ClrHit() { field_0x4c &= ~16; } void SetHit() { field_0x4c |= 16; } @@ -37,6 +37,6 @@ public: bool GetPreWallChk() const { return mPreWallChk; } bool GetPreGroundChk() const { return mPreGroundChk; } bool GetPreRoofChk() const { return mPreRoofChk; } -}; +}; // Size: 0x58 #endif /* C_BG_S_LIN_CHK_H */ diff --git a/include/SSystem/SComponent/c_bg_w.h b/include/SSystem/SComponent/c_bg_w.h index 9bd6781ea..ec806ff68 100644 --- a/include/SSystem/SComponent/c_bg_w.h +++ b/include/SSystem/SComponent/c_bg_w.h @@ -87,7 +87,7 @@ public: virtual void ClassifyPlane(); virtual void ChkPolyThrough(int, cBgS_PolyPassChk*); virtual void ChkShdwDrawThrough(int, cBgS_PolyPassChk*); - virtual void ChkGrpThrough(int, cBgS_GrpPassChk*, int); + virtual bool ChkGrpThrough(int, cBgS_GrpPassChk*, int); /* 0x08 */ Mtx* mpModelMtx; /* 0x0C */ Mtx mOldMtx; diff --git a/include/SSystem/SComponent/c_m3d_g_cps.h b/include/SSystem/SComponent/c_m3d_g_cps.h index e9ab1bbc4..510ef3869 100644 --- a/include/SSystem/SComponent/c_m3d_g_cps.h +++ b/include/SSystem/SComponent/c_m3d_g_cps.h @@ -15,8 +15,8 @@ class cM3dGCps : public cM3dGLin { public: /* 0x1C */ f32 mRadius; - cM3dGCps(void); - virtual ~cM3dGCps(void); + cM3dGCps(void) {} + virtual ~cM3dGCps(void) {} void Set(const cXyz&, const cXyz&, f32); void Set(const cM3dGCpsS&); void SetCps(const cM3dGCps&); diff --git a/include/d/actor/d_a_arrow.h b/include/d/actor/d_a_arrow.h new file mode 100644 index 000000000..8be7fd254 --- /dev/null +++ b/include/d/actor/d_a_arrow.h @@ -0,0 +1,90 @@ + +#include "f_op/f_op_actor_mng.h" +#include "d/d_cc_d.h" +#include "d/d_bg_s_lin_chk.h" +#include "d/d_bg_s_gnd_chk.h" +#include "d/d_particle.h" +#include "dolphin/types.h" + +class daArrow_c : fopAc_ac_c { +public: + enum ArrowType { + NORMAL_ARROWS = 0, + FIRE_ARROWS = 1, + ICE_ARROWS = 2, + LIGHT_ARROWS = 3, + }; + + BOOL _createHeap(); + void _atHit(dCcD_GObjInf*, fopAc_ac_c*, dCcD_GObjInf*); + void checkCreater(); + void setLightEffect(); + void setBlur(); + void createBlur(); + void setArrowShootSe(); + void setDrawShapeMaterial(); + void arrowShooting(); + void arrowUseMp(); + void ShieldReflect(); + void check_water_in(); + BOOL changeArrowMp(); + void changeArrowType(); + void changeArrowTypeNotReady(); + void setRoomInfo(); + void setKeepMatrix(); + void setStopActorMatrix(); + void procWait(); + void procMove(); + void procReturn(); + void procStop_BG(); + void procStop_Actor(); + void procWater(); + void checkRestMp(); + void setTypeByPlayer(); + void createInit(); + BOOL _execute(); + BOOL _draw(); + s32 _create(); + daArrow_c(); + BOOL _delete(); + +public: + /* 0x290 */ bool mbShotByZelda; + /* 0x291 */ u8 field_0x291[0x294 - 0x291]; + /* 0x294 */ J3DModel* mpModel; + /* 0x298 */ u8 field_0x298[0x2A0 - 0x298]; + /* 0x2A0 */ dBgS_ArrowLinChk mLinChk; + /* 0x30C */ dBgS_ObjGndChk mGndChk; + /* 0x360 */ dCcD_Stts mStts; + /* 0x39C */ dCcD_Cps mCps; + /* 0x4D4 */ dCcD_Sph mSph; + /* 0x600 */ u8 field_0x600[0x601 - 0x600]; + /* 0x601 */ u8 mArrowType; + /* 0x602 */ s16 field_0x602; + /* 0x604 */ s16 field_0x604; + /* 0x606 */ u8 field_0x606[0x610 - 0x606]; + /* 0x610 */ s32 mHitActorProcID; + /* 0x614 */ s32 mHitJointIndex; + /* 0x618 */ cXyz field_0x618; + /* 0x624 */ u8 field_0x624[0x668 - 0x624]; + /* 0x668 */ dPa_followEcallBack mPtclFollowCb; + /* 0x67C */ csXyz field_0x67c; + /* 0x682 */ u8 field_0x682; + /* 0x683 */ u8 field_0x683[0x684 - 0x683]; + /* 0x684 */ u32 field_0x684; + /* 0x688 */ bool field_0x688; + /* 0x689 */ u8 field_0x689[0x6A8 - 0x689]; + /* 0x6A8 */ cXyz field_0x6a8; + /* 0x6B4 */ u8 field_0x6B4[0x6E6 - 0x6B4]; + /* 0x6E6 */ csXyz field_0x6e6; + /* 0x6EC */ fopAc_ac_c* field_0x6ec; + /* 0x6F0 */ cXyz mNearestHitPos; + /* 0x6FC */ f32 mNearestHitDist; + /* 0x700 */ bool mbHitActor; + /* 0x701 */ u8 field_0x701[0x704 - 0x701]; + + static u8 m_keep_type; + static const char m_arc_name[]; +}; + +STATIC_ASSERT(sizeof(daArrow_c) == 0x704); diff --git a/include/d/actor/d_a_player.h b/include/d/actor/d_a_player.h index 9ee182448..1ea7d325d 100644 --- a/include/d/actor/d_a_player.h +++ b/include/d/actor/d_a_player.h @@ -90,8 +90,8 @@ public: /* 0x300 */ f32 field_0x300; /* 0x304 */ daPy_demo_c mDemo; - virtual void getLeftHandMatrix(); - virtual void getRightHandMatrix(); + virtual MtxP getLeftHandMatrix(); + virtual MtxP getRightHandMatrix(); virtual void getGroundY(); virtual void getTactMusic() const; virtual void getTactTimerCancel() const; diff --git a/include/d/actor/d_a_player_link.h b/include/d/actor/d_a_player_link.h index f885549bb..05fa50c6f 100644 --- a/include/d/actor/d_a_player_link.h +++ b/include/d/actor/d_a_player_link.h @@ -839,8 +839,8 @@ public: void checkRopeTag(); void checkPlayerNoDraw(); void getGroundY(); - void getLeftHandMatrix(); - void getRightHandMatrix(); + MtxP getLeftHandMatrix(); + MtxP getRightHandMatrix(); void checkPlayerFly() const; void checkFrontRoll() const; void checkBottleSwing() const; diff --git a/include/d/d_bg_s_gnd_chk.h b/include/d/d_bg_s_gnd_chk.h index a669d6c9e..de2c971c1 100644 --- a/include/d/d_bg_s_gnd_chk.h +++ b/include/d/d_bg_s_gnd_chk.h @@ -7,8 +7,8 @@ class dBgS_GndChk : public cBgS_GndChk, public dBgS_Chk { public: /* 8007757C */ dBgS_GndChk() { - this->SetPolyPassChk(this->GetPolyPassChkInfo()); - this->SetGrpPassChk(this->GetGrpPassChkInfo()); + SetPolyPassChk(GetPolyPassChkInfo()); + SetGrpPassChk(GetGrpPassChkInfo()); } /* 800775F0 */ virtual ~dBgS_GndChk() {} }; // Size: 0x54 diff --git a/include/d/d_bg_s_grp_pass_chk.h b/include/d/d_bg_s_grp_pass_chk.h index 54e695478..703607fbe 100644 --- a/include/d/d_bg_s_grp_pass_chk.h +++ b/include/d/d_bg_s_grp_pass_chk.h @@ -6,23 +6,33 @@ class dBgS_GrpPassChk : public cBgS_GrpPassChk { public: enum { - /* 0x1 */ NORMAL_GRP = 1, - /* 0x2 */ WATER_GRP = 2, - /* 0x3 */ FULL_GRP = NORMAL_GRP | WATER_GRP | 4 | 8, + NORMAL_GRP = 0x01, + WATER_GRP = 0x02, + YOGAN_GRP = 0x04, // Lava + DOKU_GRP = 0x08, // Unused, for poison? + SPL_GRP = WATER_GRP | YOGAN_GRP | DOKU_GRP, + FULL_GRP = NORMAL_GRP | SPL_GRP, + LIGHT_GRP = 0x10, }; /* 80077BA0 */ dBgS_GrpPassChk() { mGrp = NORMAL_GRP; } /* 80077BC4 */ virtual ~dBgS_GrpPassChk() {} - void OnWaterGrp() { mGrp |= WATER_GRP; } - void OnSpl() { mGrp |= WATER_GRP; } void OnNormalGrp() { mGrp |= NORMAL_GRP; } - void OffNormalGrp() { mGrp &= ~NORMAL_GRP; } - void OffFullGrp() { mGrp &= ~FULL_GRP; } + void OnWaterGrp() { mGrp |= WATER_GRP; } + void OnYoganGrp() { mGrp |= YOGAN_GRP; } + void OnSpl() { mGrp |= SPL_GRP; } void OnAll() { mGrp |= FULL_GRP; } - u32 MaskNormalGrp() const {return mGrp & 1; } - u32 MaskWaterGrp() const {return mGrp & 2; } + void OnLightGrp() { mGrp |= LIGHT_GRP; } + void OffNormalGrp() { mGrp &= ~NORMAL_GRP; } + void OffWaterGrp() { mGrp &= ~WATER_GRP; } + void OffFullGrp() { mGrp &= ~FULL_GRP; } + u32 MaskNormalGrp() const { return mGrp & NORMAL_GRP; } + u32 MaskWaterGrp() const { return mGrp & WATER_GRP; } + u32 MaskYoganGrp() const { return mGrp & YOGAN_GRP; } + u32 MaskDokuGrp() const { return mGrp & DOKU_GRP; } + u32 MaskLightGrp() const { return mGrp & LIGHT_GRP; } private: /* 0x4 */ u32 mGrp; }; diff --git a/include/d/d_bg_s_lin_chk.h b/include/d/d_bg_s_lin_chk.h index bda6674e8..6f4d533e5 100644 --- a/include/d/d_bg_s_lin_chk.h +++ b/include/d/d_bg_s_lin_chk.h @@ -8,10 +8,13 @@ class fopAc_ac_c; class dBgS_LinChk : public cBgS_LinChk, public dBgS_Chk { public: - /* 80077C68 */ dBgS_LinChk(); + /* 80077C68 */ dBgS_LinChk() { + SetPolyPassChk(GetPolyPassChkInfo()); + SetGrpPassChk(GetGrpPassChkInfo()); + } /* 80077D64 */ void Set(cXyz const* pi_start, cXyz const* pi_end, fopAc_ac_c const*); - /* 80077CDC */ virtual ~dBgS_LinChk(); + /* 80077CDC */ virtual ~dBgS_LinChk() {} /* 0x00 cBgS_LinChk */; /* 0x58 dBgS_Chk */; @@ -40,9 +43,13 @@ public: class dBgS_ArrowLinChk : public dBgS_LinChk { public: - /* 800781D8 */ dBgS_ArrowLinChk(); + /* 800781D8 */ dBgS_ArrowLinChk() { + SetArrow(); // Don't check arrows + OnYoganGrp(); // Check lava + OnNormalGrp(); + } - /* 80078240 */ virtual ~dBgS_ArrowLinChk(); + /* 80078240 */ virtual ~dBgS_ArrowLinChk() {} }; class dBgS_ObjLinChk : public dBgS_LinChk { diff --git a/include/d/d_bg_s_poly_pass_chk.h b/include/d/d_bg_s_poly_pass_chk.h index b8135a719..22d5d7c37 100644 --- a/include/d/d_bg_s_poly_pass_chk.h +++ b/include/d/d_bg_s_poly_pass_chk.h @@ -10,10 +10,10 @@ public: /* 0x4 */ u8 mbObjThrough; /* 0x5 */ u8 mbCamThrough; /* 0x6 */ u8 mbLinkThrough; - /* 0x7 */ u8 mbArrowsAndLightThrough; + /* 0x7 */ u8 mbArrowThrough; // Also light /* 0x8 */ u8 mbBombThrough; /* 0x9 */ u8 mbBoomerangThrough; - /* 0xA */ u8 mbHookshotThrough; + /* 0xA */ u8 mbRopeThrough; // Actually Hookshot? }; class dBgS_PolyPassChk : public cBgS_PolyPassChk { @@ -22,14 +22,20 @@ public: mbObjThrough = 0; mbCamThrough = 0; mbLinkThrough = 0; - mbArrowsAndLightThrough = 0; + mbArrowThrough = 0; mbBombThrough = 0; mbBoomerangThrough = 0; - mbHookshotThrough = 0; + mbRopeThrough = 0; } virtual ~dBgS_PolyPassChk() {} - void SetObj() { mbObjThrough = 1; } + void SetObj() { mbObjThrough = true; } + void SetCam() { mbCamThrough = true; } + void SetLink() { mbLinkThrough = true; } + void SetArrow() { mbArrowThrough = true; } + void SetBomb() { mbBombThrough = true; } + void SetBoomerang() { mbBoomerangThrough = true; } + void SetRope() { mbRopeThrough = true; } }; STATIC_ASSERT(sizeof(dBgS_PolyPassChk) == 0xC); diff --git a/include/d/d_bg_w.h b/include/d/d_bg_w.h index 79df61fed..f65e266d4 100644 --- a/include/d/d_bg_w.h +++ b/include/d/d_bg_w.h @@ -2,6 +2,7 @@ #define D_BG_W_H #include "SSystem/SComponent/c_bg_w.h" +#include "SSystem/SComponent/c_sxyz.h" class dBgS_Acch; class cM3dGPla; @@ -45,7 +46,7 @@ public: virtual ~dBgW() {} virtual void ChkPolyThrough(int, cBgS_PolyPassChk*); virtual void ChkShdwDrawThrough(int, cBgS_PolyPassChk*); - virtual void ChkGrpThrough(int, cBgS_GrpPassChk*, int); + virtual bool ChkGrpThrough(int, cBgS_GrpPassChk*, int); virtual void CrrPos(cBgS_PolyInfo&, void*, bool, cXyz*, csXyz*, csXyz*); virtual void TransPos(cBgS_PolyInfo&, void*, bool, cXyz*, csXyz*, csXyz*); virtual void MatrixCrrPos(cBgS_PolyInfo&, void*, bool, cXyz*, csXyz*, csXyz*); diff --git a/include/d/d_cc_d.h b/include/d/d_cc_d.h index 6a128e776..f2fb07ea4 100644 --- a/include/d/d_cc_d.h +++ b/include/d/d_cc_d.h @@ -173,6 +173,7 @@ public: u8 GetHitMark() { return mHitMark; } void SetRVec(cXyz& vec) { mRVec = vec; } void SetHitPos(cXyz& pos) { mHitPos = pos; } + cXyz* GetHitPosP() { return &mHitPos; } // private: /* 0x1C */ u8 mSe; @@ -202,6 +203,7 @@ public: void SetRVec(cXyz& vec) { mRVec = vec; } cXyz* GetVecP() { return &mVec; } void SetHitPos(cXyz& pos) { mHitPos = pos; } + cXyz* GetHitPosP() { return &mHitPos; } private: /* 0x1C */ u8 mSe; @@ -344,6 +346,8 @@ public: void SetAtRVec(cXyz& vec) { mGObjAt.SetRVec(vec); } void SetTgHitPos(cXyz& pos) { mGObjTg.SetHitPos(pos); } void SetAtHitPos(cXyz& pos) { mGObjAt.SetHitPos(pos); } + cXyz* GetAtHitPosP() { return mGObjAt.GetHitPosP(); } + cXyz* GetTgHitPosP() { return mGObjTg.GetHitPosP(); } protected: /* 0x050 */ dCcD_GObjAt mGObjAt; @@ -372,7 +376,7 @@ public: void Set(dCcD_SrcSph const&); void StartCAt(cXyz&); void MoveCAt(cXyz&); - virtual cCcD_ShapeAttr* GetShapeAttr(); + virtual cCcD_ShapeAttr* GetShapeAttr() { return (cCcD_ShapeAttr*)this; } virtual ~dCcD_Sph() {} }; // Size = 0x12C @@ -380,7 +384,7 @@ public: class dCcD_Cps : public dCcD_GObjInf, public cCcD_CpsAttr { public: void Set(dCcD_SrcCps const&); - cCcD_ShapeAttr* GetShapeAttr(); + cCcD_ShapeAttr* GetShapeAttr() { return (cCcD_ShapeAttr*)this; } void CalcAtVec(); void CalcTgVec(); virtual ~dCcD_Cps() {} diff --git a/include/d/d_com_inf_game.h b/include/d/d_com_inf_game.h index 6b63209bb..e4c763af9 100644 --- a/include/d/d_com_inf_game.h +++ b/include/d/d_com_inf_game.h @@ -186,6 +186,9 @@ public: dTimer_c* getTimerPtr() { return mTimerInfo.mTimerPtr; } s32 getTimerMode() { return mTimerInfo.mTimerMode; } + + s16 getItemMagicCount() { return mItemMagicCount; } + void setItemMagicCount(s16 magic) { mItemMagicCount = magic; } /* 0x0000 */ dBgS mBgS; /* 0x1404 */ dCcS mCcS; @@ -984,6 +987,14 @@ inline void dComIfGp_setMessageCountNumber(s16 num) { g_dComIfG_gameInfo.play.setMessageCountNumber(num); } +inline s16 dComIfGp_getItemMagicCount() { + return g_dComIfG_gameInfo.play.getItemMagicCount(); +} + +inline void dComIfGp_setItemMagicCount(s16 magic) { + g_dComIfG_gameInfo.play.setItemMagicCount(magic); +} + /** * === EVENT ===*/ diff --git a/include/d/d_jnt_hit.h b/include/d/d_jnt_hit.h new file mode 100644 index 000000000..2b7d7292d --- /dev/null +++ b/include/d/d_jnt_hit.h @@ -0,0 +1,30 @@ +#ifndef D_JNT_HIT_H +#define D_JNT_HIT_H + +#include "global.h" +#include "SSystem/SComponent/c_xyz.h" +#include "JSystem/J3DGraphAnimator/J3DModel.h" + +struct __jnt_hit_data_c { +public: + /* 0x0 */ s16 mJointIndex; + /* 0x2 */ s16 field_0x2; + /* 0x4 */ f32 field_0x4; + /* 0x8 */ cXyz* field_0x8; +}; + +class JntHit_c { +public: + J3DModel* getModel() { return mpModel; } + + /* 0x00 */ __jnt_hit_data_c* mpHitData; + /* 0x04 */ J3DModel* mpModel; + /* 0x08 */ cXyz* field_0x08; + /* 0x0C */ short* field_0x0c; + /* 0x10 */ short* field_0x10; + /* 0x14 */ short* mpJointIndexes; + /* 0x18 */ s16 mHitDataCount; + /* 0x1A */ u8 field_0x1A[0x20 - 0x1A]; +}; + +#endif /* D_JNT_HIT_H */ diff --git a/include/d/d_particle.h b/include/d/d_particle.h index 5d3713edf..e3ba9c64c 100644 --- a/include/d/d_particle.h +++ b/include/d/d_particle.h @@ -47,6 +47,7 @@ public: class dPa_followEcallBack : public dPa_levelEcallBack { public: + dPa_followEcallBack(u8, u8); virtual ~dPa_followEcallBack(); virtual void execute(JPABaseEmitter*); diff --git a/include/f_op/f_op_actor.h b/include/f_op/f_op_actor.h index 92b134fd4..05a0bfca8 100644 --- a/include/f_op/f_op_actor.h +++ b/include/f_op/f_op_actor.h @@ -168,7 +168,7 @@ struct actor_attention_types { /* 0x14 */ u32 mFlags; }; // Size = 0x18 -class dJntCol_c; +class JntHit_c; struct cull_sphere { /* 0x0 */ Vec mCenter; @@ -211,7 +211,7 @@ public: } mCull; /* 0x248 */ f32 mCullSizeFar; /* 0x24C */ J3DModel* model; - /* 0x250 */ dJntCol_c* mJntCol; + /* 0x250 */ JntHit_c* mJntHit; /* 0x254 */ f32 speedF; /* 0x258 */ f32 mGravity; /* 0x25C */ f32 mMaxFallSpeed; diff --git a/include/f_op/f_op_actor_mng.h b/include/f_op/f_op_actor_mng.h index cf98a4cad..85f10094b 100644 --- a/include/f_op/f_op_actor_mng.h +++ b/include/f_op/f_op_actor_mng.h @@ -119,8 +119,8 @@ inline void fopAcM_SetParam(void* p_actor, u32 param) { fpcM_SetParam(p_actor, param); } -inline void fopAcM_SetJntCol(fopAc_ac_c* i_actorP, dJntCol_c* i_jntColP) { - i_actorP->mJntCol = i_jntColP; +inline void fopAcM_SetJntHit(fopAc_ac_c* i_actorP, JntHit_c* i_jntHitP) { + i_actorP->mJntHit = i_jntHitP; } inline s16 fopAcM_GetProfName(void* pActor) { @@ -251,8 +251,8 @@ inline f32 fopAcM_GetMaxFallSpeed(fopAc_ac_c* p_actor) { return p_actor->mMaxFallSpeed; } -inline dJntCol_c* fopAcM_GetJntCol(fopAc_ac_c* i_actor) { - return i_actor->mJntCol; +inline JntHit_c* fopAcM_GetJntHit(fopAc_ac_c* i_actor) { + return i_actor->mJntHit; } inline void fopAcM_setCullSizeFar(fopAc_ac_c* i_actor, f32 i_far) { diff --git a/include/m_Do/m_Do_mtx.h b/include/m_Do/m_Do_mtx.h index 3c7a63d9c..432ba072b 100644 --- a/include/m_Do/m_Do_mtx.h +++ b/include/m_Do/m_Do_mtx.h @@ -135,6 +135,12 @@ public: */ /* 8000CD64 */ static inline void transS(cXyz const& xyz) { MTXTrans(now, xyz.x, xyz.y, xyz.z); } + /** + * Translates a new Matrix by the given cXyz and then concatenates it with the `now` matrix + * @param xyz The xyz translation vector + */ + /* 8000CD64 */ static inline void transM(cXyz const& xyz) { transM(xyz.x, xyz.y, xyz.z); } + /** * Translates a new Matrix by the given X, Y, and Z values and then concatenates it with the `now` matrix * @param x The x-axis translation value @@ -153,7 +159,7 @@ public: * Scales a new Matrix by the given cXyz and then concatenates it with the `now` matrix * @param xyz The xyz scale vector */ - /* 8000CE70 */ static void scaleM(cXyz const& xyz); + /* 8000CE70 */ static void scaleM(cXyz const& xyz) { scaleM(xyz.x, xyz.y, xyz.z); } /** * Scales a new Matrix by the given X, Y, and Z values and then concatenates it with the `now` matrix @@ -166,7 +172,7 @@ public: /* 8000CE9C */ static void XYZrotS(csXyz const& xyz); /** - * Rotates the `now` matrix by the given csXyz in the order Z, Y, X + * Rotates the `now` matrix by the given csXyz in the order X, Y, Z * @param xyz The xyz rotation vector */ /* 8000CED4 */ static void XYZrotM(csXyz const& xyz); @@ -174,10 +180,10 @@ public: /* 8000CF0C */ static void ZXYrotS(csXyz const& xyz); /** - * Rotates the `now` matrix by the given csXyz in the order X, Y, Z + * Rotates the `now` matrix by the given csXyz in the order Z, X, Y * @param xyz The xyz rotation vector */ - /* 8000CF44 */ static void ZXYrotM(csXyz const& xyz); + /* 8000CF44 */ static void ZXYrotM(csXyz const& xyz) { ZXYrotM(xyz.x, xyz.y, xyz.z); } /* 8000CF7C */ static void quatM(Quaternion const*); @@ -232,7 +238,7 @@ public: static void XYZrotS(s16 x, s16 y, s16 z) { mDoMtx_XYZrotS(now, x, y, z); } /** - * Rotates the `now` matrix by the given X, Y, and Z values in the order Z, Y, X + * Rotates the `now` matrix by the given X, Y, and Z values in the order X, Y, Z * @param x The x-axis rotation value * @param y The y-axis rotation value * @param z The z-axis rotation value diff --git a/src/d/actor/d_a_arrow.cpp b/src/d/actor/d_a_arrow.cpp index 9b7dcbe55..a0c831c18 100644 --- a/src/d/actor/d_a_arrow.cpp +++ b/src/d/actor/d_a_arrow.cpp @@ -3,47 +3,128 @@ // Translation Unit: d_a_arrow.cpp // -#include "d_a_arrow.h" +#include "d/actor/d_a_arrow.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "m_Do/m_Do_mtx.h" +#include "d/d_com_inf_game.h" +#include "d/d_procname.h" +#include "d/d_npc.h" +#include "d/actor/d_a_player.h" +#include "d/d_jnt_hit.h" #include "dolphin/types.h" +const char daArrow_c::m_arc_name[] = "Link"; + /* 800D455C-800D457C .text createHeap_CB__FP10fopAc_ac_c */ -void createHeap_CB(fopAc_ac_c*) { - /* Nonmatching */ +static BOOL createHeap_CB(fopAc_ac_c* i_this) { + return ((daArrow_c*)i_this)->_createHeap(); } /* 800D457C-800D4648 .text _createHeap__9daArrow_cFv */ -void daArrow_c::_createHeap() { - /* Nonmatching */ +BOOL daArrow_c::_createHeap() { + // arrowglitter.bdl for Light Arrows, arrow.bdl otherwise. + s32 modelFileIndex = (mArrowType == LIGHT_ARROWS ? 0x38 : 0x37) & 0xFFFF; + J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(m_arc_name, modelFileIndex); + JUT_ASSERT(190, modelData != 0); + + mpModel = mDoExt_J3DModel__create(modelData, 0x00080000, 0x11000022); + if (!mpModel) { + return FALSE; + } + return TRUE; } /* 800D4648-800D4668 .text atHit_CB__FP10fopAc_ac_cP12dCcD_GObjInfP10fopAc_ac_cP12dCcD_GObjInf */ -void atHit_CB(fopAc_ac_c*, dCcD_GObjInf*, fopAc_ac_c*, dCcD_GObjInf*) { - /* Nonmatching */ +void atHit_CB(fopAc_ac_c* i_this, dCcD_GObjInf* thisObjInf, fopAc_ac_c* hitActor, dCcD_GObjInf* hitObjInf) { + ((daArrow_c*)i_this)->_atHit(thisObjInf, hitActor, hitObjInf); } /* 800D4668-800D47C0 .text _atHit__9daArrow_cFP12dCcD_GObjInfP10fopAc_ac_cP12dCcD_GObjInf */ -void daArrow_c::_atHit(dCcD_GObjInf*, fopAc_ac_c*, dCcD_GObjInf*) { - /* Nonmatching */ +void daArrow_c::_atHit(dCcD_GObjInf* thisObjInf, fopAc_ac_c* hitActor, dCcD_GObjInf* hitObjInf) { + // Keep track of which actor this arrow hit as well as the position the hit occurred at. + if (!hitActor) { + return; + } + if (!fopAc_IsActor(hitActor)) { + return; + } + if (!fopAcM_GetJntHit(hitActor)) { + return; + } + + cXyz hitPos(*thisObjInf->GetAtHitPosP()); + f32 hitDist = (hitPos - current.pos).abs(); + if (hitDist < mNearestHitDist) { + mNearestHitDist = hitDist; + mHitActorProcID = fpcM_GetID(hitActor); + if (hitObjInf->ChkTgShield()) { + mbHitActor = false; + field_0x6ec = NULL; + } else { + mbHitActor = true; + field_0x6ec = hitActor; + } + mNearestHitPos = *thisObjInf->GetAtHitPosP(); + } } /* 800D47C0-800D4814 .text checkCreater__9daArrow_cFv */ void daArrow_c::checkCreater() { - /* Nonmatching */ + // Check if this arrow was fired by Princess Zelda (during the Ganondorf fight). + fopAc_ac_c* archer; + if (fopAcM_SearchByID(mParentPcId, &archer)) { + if (fpcM_GetName(archer) == PROC_PZ) { + mbShotByZelda = true; + } + } } /* 800D4814-800D48E8 .text setLightEffect__9daArrow_cFv */ void daArrow_c::setLightEffect() { - /* Nonmatching */ + if (field_0x682 == mArrowType) { + if (mArrowType == NORMAL_ARROWS) { + return; + } + if (!field_0x688) { + field_0x684 = fopAcM_createChild( + PROC_ARROW_LIGHTEFF, fpcM_GetID(this), + mArrowType, &field_0x6a8, + current.roomNo, &shape_angle, NULL, -1, NULL + ); + if (field_0x684 != -1) { + field_0x688 = true; + } + } + } else { + fopAcM_delete(fopAcM_SearchByID(field_0x684)); + field_0x688 = false; + } + field_0x682 = mArrowType; } /* 800D48E8-800D4994 .text setBlur__9daArrow_cFv */ void daArrow_c::setBlur() { - /* Nonmatching */ + JPABaseEmitter* emitter = mPtclFollowCb.getEmitter(); + if (!emitter) { + return; + } + s32 alpha = emitter->getGlobalAlpha(); + if (alpha - 50 <= 0) { + mPtclFollowCb.end(); + } else { + emitter->setGlobalAlpha(alpha - 50); + } + + mDoMtx_stack_c::transS(current.pos); + mDoMtx_stack_c::ZXYrotM(field_0x67c); + emitter->setGlobalRTMatrix(mDoMtx_stack_c::get()); } /* 800D4994-800D4A04 .text createBlur__9daArrow_cFv */ void daArrow_c::createBlur() { - /* Nonmatching */ + if (!mPtclFollowCb.getEmitter()) { + dComIfGp_particle_setToon(0x48, ¤t.pos, NULL, NULL, 0xFF, &mPtclFollowCb, -1, NULL, NULL, NULL); + } } /* 800D4A04-800D4ADC .text setArrowShootSe__9daArrow_cFv */ @@ -63,7 +144,15 @@ void daArrow_c::arrowShooting() { /* 800D4D98-800D4DC0 .text arrowUseMp__9daArrow_cFv */ void daArrow_c::arrowUseMp() { - /* Nonmatching */ + static const s16 use_mp[4] = { + -0, // Normal Arrows + -1, // Fire Arrows + -1, // Ice Arrows + -2, // Light Arrows + }; + + s32 magic = dComIfGp_getItemMagicCount(); + dComIfGp_setItemMagicCount(magic + use_mp[mArrowType]); } /* 800D4DC0-800D50A0 .text ShieldReflect__9daArrow_cFv */ @@ -77,8 +166,9 @@ void daArrow_c::check_water_in() { } /* 800D5388-800D53AC .text changeArrowMp__9daArrow_cFv */ -void daArrow_c::changeArrowMp() { - /* Nonmatching */ +BOOL daArrow_c::changeArrowMp() { + u8 magic = dComIfGs_getMagic(); + return magic >= 1; } /* 800D53AC-800D553C .text changeArrowType__9daArrow_cFv */ @@ -93,17 +183,101 @@ void daArrow_c::changeArrowTypeNotReady() { /* 800D560C-800D56B0 .text setRoomInfo__9daArrow_cFv */ void daArrow_c::setRoomInfo() { - /* Nonmatching */ + u32 roomNo; + + mGndChk.SetPos(¤t.pos); + f32 groundY = dComIfG_Bgsp()->GroundCross(&mGndChk); + if (groundY != -1000000000.0f) { + roomNo = dComIfG_Bgsp()->GetRoomId(mGndChk); + mTevStr.mEnvrIdxOverride = dComIfG_Bgsp()->GetPolyColor(mGndChk); + } else { + roomNo = dComIfGp_roomControl_getStayNo(); + } + + mTevStr.mRoomNo = roomNo; + mStts.SetRoomId(roomNo); + current.roomNo = roomNo; } /* 800D56B0-800D5854 .text setKeepMatrix__9daArrow_cFv */ void daArrow_c::setKeepMatrix() { /* Nonmatching */ + // Transform the arrow onto its archer's hand. + if (mbShotByZelda) { + fopNpc_npc_c* zelda; + fopAcM_SearchByID(mParentPcId, (fopAc_ac_c**)&zelda); + + mDoMtx_stack_c::transS(0.7f, -0.07f, -0.2f); + mDoMtx_stack_c::XYZrotM(0x238E, 0x2CDF, 0x29BE); + + // Copy the matrix of Zelda's hand_R1 joint to the arrow model. + // TODO: After daPz_c is implemented, this should use her daPz_c::getRightHandMatrix() inline method. + MtxP handMtx = zelda->mpMcaMorf->getModel()->mpNodeMtx[0x13]; + cMtx_concat(handMtx, mDoMtx_stack_c::get(), mDoMtx_stack_c::get()); + mpModel->setBaseTRMtx(mDoMtx_stack_c::get()); + + MtxP mtx = mDoMtx_stack_c::get(); + current.pos.set(mtx[0][3], mtx[1][3], mtx[2][3]); + + mDoMtx_MtxToRot(mDoMtx_stack_c::get(), &shape_angle); + current.angle.y = shape_angle.y; + current.angle.x = -shape_angle.x; + } else { + daPy_py_c* player = daPy_getPlayerActorClass(); + + mDoMtx_stack_c::transS(0.7f, -0.07f, -0.2f); + // TODO: How did they pass an unsigned short (0xB0B6) to a function that takes a signed short? + mDoMtx_stack_c::XYZrotM(0xB0B6, 0x238E, -0x6333); + + MtxP handMtx = player->getLeftHandMatrix(); + cMtx_concat(handMtx, mDoMtx_stack_c::get(), mDoMtx_stack_c::get()); + mpModel->setBaseTRMtx(mDoMtx_stack_c::get()); + + MtxP mtx = mDoMtx_stack_c::get(); + current.pos.set(mtx[0][3], mtx[1][3], mtx[2][3]); + + mDoMtx_MtxToRot(mDoMtx_stack_c::get(), &shape_angle); + current.angle.y = shape_angle.y; + current.angle.x = -shape_angle.x; + } } /* 800D5854-800D5A70 .text setStopActorMatrix__9daArrow_cFv */ void daArrow_c::setStopActorMatrix() { - /* Nonmatching */ + s16 xRot = 0; + if (cLib_calcTimer(&field_0x604) != 0) { + f32 temp = (field_0x604 / 40.0f); + xRot = 1024.0f * temp*temp * cM_ssin(field_0x604 * 0x52FB); + } + fopAc_ac_c* hitActor = fopAcM_SearchByID(mHitActorProcID); + if (!hitActor) { + return; + } + JntHit_c* jntHit = fopAcM_GetJntHit(hitActor); + if (!jntHit) { + return; + } + J3DModel* hitModel = jntHit->getModel(); + + static cXyz offset_arrow_pos(0.0f, 0.0f, -50.0f); + + mDoMtx_stack_c::copy(hitModel->mpNodeMtx[mHitJointIndex]); + csXyz hitJointRot; + mDoMtx_MtxToRot(mDoMtx_stack_c::get(), &hitJointRot); + + mDoMtx_stack_c::transM(field_0x618); + mDoMtx_stack_c::ZXYrotM(field_0x6e6); + + cXyz pos(0.0f, 0.0f, 0.0f); + mDoMtx_stack_c::multVecZero(&pos); + current.pos = pos; + + mDoMtx_stack_c::transS(current.pos); + mDoMtx_stack_c::ZXYrotM(hitJointRot); + mDoMtx_stack_c::ZXYrotM(field_0x6e6); + mDoMtx_stack_c::XrotM(xRot); + mDoMtx_stack_c::transM(offset_arrow_pos); + mpModel->setBaseTRMtx(mDoMtx_stack_c::get()); } /* 800D5A70-800D5B20 .text procWait__9daArrow_cFv */ @@ -138,12 +312,23 @@ void daArrow_c::procWater() { /* 800D72BC-800D72EC .text checkRestMp__9daArrow_cFv */ void daArrow_c::checkRestMp() { - /* Nonmatching */ + static const s16 use_mp[4] = { + 0, // Normal Arrows + 1, // Fire Arrows + 1, // Ice Arrows + 2, // Light Arrows + }; + + u8 currMagic = dComIfGs_getMagic(); + if (currMagic < use_mp[m_keep_type]) { + m_keep_type = 0; + } } /* 800D72EC-800D7320 .text setTypeByPlayer__9daArrow_cFv */ void daArrow_c::setTypeByPlayer() { - /* Nonmatching */ + checkRestMp(); + mArrowType = m_keep_type; } /* 800D7320-800D74FC .text createInit__9daArrow_cFv */ @@ -152,207 +337,78 @@ void daArrow_c::createInit() { } /* 800D74FC-800D7820 .text _execute__9daArrow_cFv */ -void daArrow_c::_execute() { +BOOL daArrow_c::_execute() { /* Nonmatching */ } /* 800D7820-800D7960 .text _draw__9daArrow_cFv */ -void daArrow_c::_draw() { +BOOL daArrow_c::_draw() { /* Nonmatching */ } /* 800D7960-800D7A38 .text _create__9daArrow_cFv */ -void daArrow_c::_create() { +s32 daArrow_c::_create() { /* Nonmatching */ } /* 800D7A38-800D7DB4 .text __ct__9daArrow_cFv */ -daArrow_c::daArrow_c() { - /* Nonmatching */ -} - -/* 800D7DB4-800D7E80 .text __dt__8dCcD_SphFv */ -dCcD_Sph::~dCcD_Sph() { - /* Nonmatching */ -} - -/* 800D7E80-800D7F0C .text __dt__12cCcD_SphAttrFv */ -cCcD_SphAttr::~cCcD_SphAttr() { - /* Nonmatching */ -} - -/* 800D7F0C-800D7F54 .text __dt__8cM3dGSphFv */ -cM3dGSph::~cM3dGSph() { - /* Nonmatching */ -} - -/* 800D7F54-800D8034 .text __dt__8dCcD_CpsFv */ -dCcD_Cps::~dCcD_Cps() { - /* Nonmatching */ -} - -/* 800D8034-800D807C .text __dt__9cCcD_SttsFv */ -cCcD_Stts::~cCcD_Stts() { - /* Nonmatching */ -} - -/* 800D807C-800D81D0 .text __dt__16dBgS_ArrowLinChkFv */ -dBgS_ArrowLinChk::~dBgS_ArrowLinChk() { - /* Nonmatching */ -} +daArrow_c::daArrow_c() : mPtclFollowCb(0, 0) {} /* 800D81D0-800D8200 .text _delete__9daArrow_cFv */ -void daArrow_c::_delete() { - /* Nonmatching */ +BOOL daArrow_c::_delete() { + mPtclFollowCb.end(); + return TRUE; } /* 800D8200-800D8220 .text daArrowCreate__FPv */ -void daArrowCreate(void*) { +s32 daArrowCreate(void* i_this) { /* Nonmatching */ + return ((daArrow_c*)i_this)->_create(); } /* 800D8220-800D8240 .text daArrowDelete__FPv */ -void daArrowDelete(void*) { +BOOL daArrowDelete(void* i_this) { /* Nonmatching */ + return ((daArrow_c*)i_this)->_delete(); } /* 800D8240-800D8260 .text daArrowExecute__FPv */ -void daArrowExecute(void*) { +BOOL daArrowExecute(void* i_this) { /* Nonmatching */ + return ((daArrow_c*)i_this)->_execute(); } /* 800D8260-800D8280 .text daArrowDraw__FPv */ -void daArrowDraw(void*) { - /* Nonmatching */ +BOOL daArrowDraw(void* i_this) { + return ((daArrow_c*)i_this)->_draw(); } /* 800D8280-800D8288 .text daArrowIsDelete__FPv */ -void daArrowIsDelete(void*) { - /* Nonmatching */ +BOOL daArrowIsDelete(void* i_this) { + return TRUE; } -/* 800D8288-800D8298 .text GetShapeAttr__8dCcD_SphFv */ -void dCcD_Sph::GetShapeAttr() { - /* Nonmatching */ -} - -/* 800D8298-800D82A0 .text GetCoCP__12cCcD_SphAttrCFv */ -void cCcD_SphAttr::GetCoCP() const { - /* Nonmatching */ -} - -/* 800D82A0-800D82A8 .text CrossAtTg__12cCcD_SphAttrCFRC12cCcD_AabAttrP4cXyz */ -void cCcD_SphAttr::CrossAtTg(const cCcD_AabAttr&, cXyz*) const { - /* Nonmatching */ -} - -/* 800D82A8-800D82B0 .text CrossAtTg__12cCcD_SphAttrCFRC12cCcD_PntAttrP4cXyz */ -void cCcD_SphAttr::CrossAtTg(const cCcD_PntAttr&, cXyz*) const { - /* Nonmatching */ -} - -/* 800D82B0-800D82E8 .text CrossAtTg__12cCcD_SphAttrCFRC14cCcD_ShapeAttrP4cXyz */ -void cCcD_SphAttr::CrossAtTg(const cCcD_ShapeAttr&, cXyz*) const { - /* Nonmatching */ -} - -/* 800D82E8-800D82F0 .text CrossCo__12cCcD_SphAttrCFRC12cCcD_AabAttrPf */ -void cCcD_SphAttr::CrossCo(const cCcD_AabAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D82F0-800D82F8 .text CrossCo__12cCcD_SphAttrCFRC12cCcD_TriAttrPf */ -void cCcD_SphAttr::CrossCo(const cCcD_TriAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D82F8-800D8300 .text CrossCo__12cCcD_SphAttrCFRC12cCcD_PntAttrPf */ -void cCcD_SphAttr::CrossCo(const cCcD_PntAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D8300-800D8338 .text CrossCo__12cCcD_SphAttrCFRC14cCcD_ShapeAttrPf */ -void cCcD_SphAttr::CrossCo(const cCcD_ShapeAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D8338-800D8348 .text GetShapeAttr__8dCcD_CpsFv */ -void dCcD_Cps::GetShapeAttr() { - /* Nonmatching */ -} - -/* 800D8348-800D8350 .text CrossAtTg__12cCcD_CpsAttrCFRC12cCcD_AabAttrP4cXyz */ -void cCcD_CpsAttr::CrossAtTg(const cCcD_AabAttr&, cXyz*) const { - /* Nonmatching */ -} - -/* 800D8350-800D8358 .text CrossAtTg__12cCcD_CpsAttrCFRC12cCcD_PntAttrP4cXyz */ -void cCcD_CpsAttr::CrossAtTg(const cCcD_PntAttr&, cXyz*) const { - /* Nonmatching */ -} - -/* 800D8358-800D8390 .text CrossAtTg__12cCcD_CpsAttrCFRC14cCcD_ShapeAttrP4cXyz */ -void cCcD_CpsAttr::CrossAtTg(const cCcD_ShapeAttr&, cXyz*) const { - /* Nonmatching */ -} - -/* 800D8390-800D8398 .text CrossCo__12cCcD_CpsAttrCFRC12cCcD_AabAttrPf */ -void cCcD_CpsAttr::CrossCo(const cCcD_AabAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D8398-800D83A0 .text CrossCo__12cCcD_CpsAttrCFRC12cCcD_TriAttrPf */ -void cCcD_CpsAttr::CrossCo(const cCcD_TriAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D83A0-800D83A8 .text CrossCo__12cCcD_CpsAttrCFRC12cCcD_PntAttrPf */ -void cCcD_CpsAttr::CrossCo(const cCcD_PntAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D83A8-800D83E0 .text CrossCo__12cCcD_CpsAttrCFRC14cCcD_ShapeAttrPf */ -void cCcD_CpsAttr::CrossCo(const cCcD_ShapeAttr&, float*) const { - /* Nonmatching */ -} - -/* 800D83E0-800D83FC .text cLib_calcTimer__FPs */ -void cLib_calcTimer(short*) { - /* Nonmatching */ -} - -/* 800D83FC-800D8404 .text @20@__dt__16dBgS_ArrowLinChkFv */ -void @20@__dt__16dBgS_ArrowLinChkFv { - /* Nonmatching */ -} - -/* 800D8404-800D840C .text @100@__dt__16dBgS_ArrowLinChkFv */ -void @100@__dt__16dBgS_ArrowLinChkFv { - /* Nonmatching */ -} - -/* 800D840C-800D8414 .text @88@__dt__16dBgS_ArrowLinChkFv */ -void @88@__dt__16dBgS_ArrowLinChkFv { - /* Nonmatching */ -} - -/* 800D8414-800D841C .text @280@__dt__8dCcD_CpsFv */ -void @280@__dt__8dCcD_CpsFv { - /* Nonmatching */ -} - -/* 800D841C-800D8424 .text @248@__dt__8dCcD_CpsFv */ -void @248@__dt__8dCcD_CpsFv { - /* Nonmatching */ -} - -/* 800D8424-800D842C .text @280@__dt__8dCcD_SphFv */ -void @280@__dt__8dCcD_SphFv { - /* Nonmatching */ -} - -/* 800D842C-800D8434 .text @248@__dt__8dCcD_SphFv */ -void @248@__dt__8dCcD_SphFv { - /* Nonmatching */ -} +actor_method_class daArrowMethodTable = { + (process_method_func)daArrowCreate, + (process_method_func)daArrowDelete, + (process_method_func)daArrowExecute, + (process_method_func)daArrowIsDelete, + (process_method_func)daArrowDraw, +}; +extern actor_process_profile_definition g_profile_ARROW = { + /* LayerID */ fpcLy_CURRENT_e, + /* ListID */ 9, + /* ListPrio */ fpcLy_CURRENT_e, + /* ProcName */ PROC_ARROW, + /* Proc SubMtd */ &g_fpcLf_Method.mBase, + /* Size */ sizeof(daArrow_c), + /* SizeOther */ 0, + /* Parameters */ 0, + /* Leaf SubMtd */ &g_fopAc_Method.base, + /* Priority */ 0x01BF, + /* Actor SubMtd */ &daArrowMethodTable, + /* Status */ 0x00044000, + /* Group */ fopAc_ACTOR_e, + /* CullType */ fopAc_CULLBOX_CUSTOM_e, +}; diff --git a/src/d/actor/d_a_branch.cpp b/src/d/actor/d_a_branch.cpp index 0a1387a5f..e70c727a9 100644 --- a/src/d/actor/d_a_branch.cpp +++ b/src/d/actor/d_a_branch.cpp @@ -241,7 +241,7 @@ s32 daBranch_Create(fopAc_ac_c* i_this) { J3DMaterial* mat = modelData->getMaterialNodePointer(j); if (mat) { J3DFog* fog = mat->getPEBlock()->getFog(); - fog->field_0x0 = 2; + fog->mType = 2; } } } diff --git a/src/d/actor/d_a_kaji.cpp b/src/d/actor/d_a_kaji.cpp index 3dd7609fa..84e5dbc90 100644 --- a/src/d/actor/d_a_kaji.cpp +++ b/src/d/actor/d_a_kaji.cpp @@ -65,7 +65,7 @@ s32 daKaji_c::_create() { if (fopAcM_entrySolidHeap(this, (heapCallbackFunc)&CheckCreateHeap, 0x660)) { mDoMtx_stack_c::transS(getPosition()); mDoMtx_stack_c::YrotM(shape_angle.y); - mDoMtx_stack_c::scaleM(mScale.x, mScale.y, mScale.z); + mDoMtx_stack_c::scaleM(mScale); MTXCopy(mDoMtx_stack_c::get(), mMtx); l_p_ship = (daObjPirateship::Act_c*)fopAcM_SearchByID(mParentPcId); @@ -102,7 +102,7 @@ BOOL daKaji_c::_execute() { mpMorf->getModel()->setBaseScale(mScale); mDoMtx_stack_c::transS(current.pos); - mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z); + mDoMtx_stack_c::ZXYrotM(shape_angle); mpMorf->getModel()->setBaseTRMtx(mDoMtx_stack_c::get()); MTXCopy(mDoMtx_stack_c::get(), mMtx); diff --git a/src/d/actor/d_a_nh.cpp b/src/d/actor/d_a_nh.cpp index 92ca30e1d..8a8f0bd6e 100644 --- a/src/d/actor/d_a_nh.cpp +++ b/src/d/actor/d_a_nh.cpp @@ -202,9 +202,9 @@ void daNh_c::setBaseMtx() { glowOffset.y = l_HIO.prm.mGlowOffsetY; cXyz glowPos; cMtx_multVec(mDoMtx_stack_c::get(), &glowOffset, &glowPos); - PSMTXTrans(mDoMtx_stack_c::get(), glowPos.x, glowPos.y, glowPos.z); + mDoMtx_stack_c::transS(glowPos); mDoMtx_stack_c::scaleM(l_HIO.prm.mGlowScale, l_HIO.prm.mGlowScale, l_HIO.prm.mGlowScale); - MTXCopy(mDoMtx_stack_c::get(), mGlowMtx); + cMtx_copy(mDoMtx_stack_c::get(), mGlowMtx); } /* 800F9980-800F9A54 .text createHeap__6daNh_cFv */ @@ -229,12 +229,7 @@ static BOOL checkCreateHeap(fopAc_ac_c* i_this) { /* 800F9A74-800F9C8C .text create__6daNh_cFv */ s32 daNh_c::create() { - static u32 a_heap_size_tbl; - static s8 init; - if (!init) { - a_heap_size_tbl = 0x4000; - init = 1; - } + static u32 a_heap_size_tbl = 0x4000; s32 phase_state = cPhs_COMPLEATE_e; diff --git a/src/d/actor/d_a_obj_movebox.cpp b/src/d/actor/d_a_obj_movebox.cpp index 675152079..1c2e18a68 100644 --- a/src/d/actor/d_a_obj_movebox.cpp +++ b/src/d/actor/d_a_obj_movebox.cpp @@ -467,8 +467,8 @@ namespace daObjMovebox { } daObj::quat_rotBaseY(&temp2, temp3); - - mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z); + mDoMtx_stack_c::quatM(&temp2); + mDoMtx_stack_c::ZXYrotM(shape_angle); if (isFloating) { mDoMtx_stack_c::transM(0.0f, -mUnknown624, 0.0f); } diff --git a/src/d/actor/d_a_obj_paper.cpp b/src/d/actor/d_a_obj_paper.cpp index 0211638e0..7a391fd4e 100644 --- a/src/d/actor/d_a_obj_paper.cpp +++ b/src/d/actor/d_a_obj_paper.cpp @@ -291,7 +291,7 @@ namespace daObjPaper { /* 000008DC-00000948 .text set_mtx__Q210daObjPaper5Act_cFv */ void daObjPaper::Act_c::set_mtx() { mDoMtx_stack_c::transS(getPosition()); - mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z); + mDoMtx_stack_c::ZXYrotM(shape_angle); mpModel->setBaseTRMtx(mDoMtx_stack_c::get()); } diff --git a/src/d/actor/d_a_scene_change.cpp b/src/d/actor/d_a_scene_change.cpp index 1d27e2834..c5c27798f 100644 --- a/src/d/actor/d_a_scene_change.cpp +++ b/src/d/actor/d_a_scene_change.cpp @@ -41,10 +41,10 @@ s32 daSceneChgCreate(void* i_this) { fopAcM_SetupActor(scnChg, d_a_scene_change_c); - MTXTrans(mDoMtx_stack_c::now, scnChg->current.pos.x, scnChg->current.pos.y, scnChg->current.pos.z); - mDoMtx_ZXYrotM(mDoMtx_stack_c::now, scnChg->shape_angle.x, scnChg->shape_angle.y, scnChg->shape_angle.z); + mDoMtx_stack_c::transS(scnChg->current.pos); + mDoMtx_stack_c::ZXYrotM(scnChg->shape_angle); - MTXCopy(mDoMtx_stack_c::now, scnChg->mTransformMtx); + cMtx_copy(mDoMtx_stack_c::get(), scnChg->mTransformMtx); return cPhs_COMPLEATE_e; } diff --git a/src/d/actor/d_a_spotbox.cpp b/src/d/actor/d_a_spotbox.cpp index 87f9773cb..3b8ca1699 100644 --- a/src/d/actor/d_a_spotbox.cpp +++ b/src/d/actor/d_a_spotbox.cpp @@ -41,10 +41,10 @@ int daSpotbox_c::draw() { } int daSpotbox_c::execute() { - PSMTXTrans(mDoMtx_stack_c::now, this->current.pos.x, this->current.pos.y, this->current.pos.z); - mDoMtx_YrotM(mDoMtx_stack_c::now, this->current.angle.y); - mDoMtx_stack_c::scaleM(this->mScale.x, this->mScale.y, this->mScale.z); - PSMTXCopy(mDoMtx_stack_c::now, this->mtx); + mDoMtx_stack_c::transS(current.pos); + mDoMtx_stack_c::YrotM(current.angle.y); + mDoMtx_stack_c::scaleM(mScale); + cMtx_copy(mDoMtx_stack_c::get(), mtx); return TRUE; } From 246da3327b1365a0402856eee7e512b3491115ac Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Thu, 21 Sep 2023 00:10:06 -0400 Subject: [PATCH 4/4] d_a_andsw2 OK (#65) --- configure.py | 2 +- include/d/d_com_inf_game.h | 4 ++ include/d/d_event.h | 1 + src/d/actor/d_a_andsw0.cpp | 86 ++++++++++++++++++++++++-------------- src/d/actor/d_a_andsw2.cpp | 2 +- 5 files changed, 62 insertions(+), 33 deletions(-) diff --git a/configure.py b/configure.py index b670caf99..2d2450c31 100644 --- a/configure.py +++ b/configure.py @@ -1199,7 +1199,7 @@ config.libs = [ }, Rel(Matching, "f_pc_profile_lst", "f_pc/f_pc_profile_lst.cpp"), ActorRel(NonMatching, "d_a_agbsw0"), - ActorRel(NonMatching, "d_a_andsw0"), + ActorRel(Matching, "d_a_andsw0"), ActorRel(Matching, "d_a_andsw2"), ActorRel(NonMatching, "d_a_att"), ActorRel(NonMatching, "d_a_bflower"), diff --git a/include/d/d_com_inf_game.h b/include/d/d_com_inf_game.h index e4c763af9..db841fb1a 100644 --- a/include/d/d_com_inf_game.h +++ b/include/d/d_com_inf_game.h @@ -1018,6 +1018,10 @@ inline void dComIfGp_event_offEventFlag(s16 flag) { return g_dComIfG_gameInfo.play.getEvent().offEventFlag(flag); } +inline void dComIfGp_event_reset() { + g_dComIfG_gameInfo.play.getEvent().reset(); +} + inline u8 dComIfGp_event_getPreItemNo() { return g_dComIfG_gameInfo.play.getEvent().getPreItemNo(); } diff --git a/include/d/d_event.h b/include/d/d_event.h index acf7f1ae8..3d78feba9 100644 --- a/include/d/d_event.h +++ b/include/d/d_event.h @@ -67,6 +67,7 @@ public: u16 chkEventFlag(u16 flag) { return flag & mEventFlag; } void onEventFlag(u16 flag) { mEventFlag |= flag; } void offEventFlag(u16 flag) { mEventFlag &= ~flag; } + void reset() { onEventFlag(8); } bool runCheck() { return mMode != 0; } diff --git a/src/d/actor/d_a_andsw0.cpp b/src/d/actor/d_a_andsw0.cpp index 6daa4fa2a..737644320 100644 --- a/src/d/actor/d_a_andsw0.cpp +++ b/src/d/actor/d_a_andsw0.cpp @@ -31,25 +31,39 @@ public: /* 0x2A3 */ s8 mEventState; }; +// Bokoblin. TODO: Include d_a_bk.h once implemented. +struct bk_class : public fopAc_ac_c { + u8 temp[0x121C - 0x290]; + u8 field_0x121C; +}; + +// Kargaroc. TODO: Include d_a_bb.h once implemented. +struct bb_class : public fopAc_ac_c {}; + static s32 daAndsw0_Draw(andsw0_class*) { return 1; } static void daAndsw0_check(andsw0_class* i_this) { /* Nonmatching */ - u8 numToCheck = i_this->mNumSwitchesToCheck; - u32 switchIdxToCheck = i_this->mFirstSwitchToCheck ? i_this->mFirstSwitchToCheck : i_this->mSwitchToSet + 1; + s32 numToCheck = i_this->mNumSwitchesToCheck; + u32 switchIdxToCheck; + if (i_this->mFirstSwitchToCheck) { + switchIdxToCheck = i_this->mFirstSwitchToCheck; + } else { + switchIdxToCheck = i_this->mSwitchToSet + 1; + } switch(i_this->mAction) { case ACT_ON_ALL: for(int i = 0; i < numToCheck; i++) { - if(dComIfGs_isSwitch(switchIdxToCheck, i_this->current.roomNo) == false) { + if(dComIfGs_isSwitch(switchIdxToCheck, fopAcM_GetRoomNo(i_this)) == false) { break; } if(i == numToCheck - 1) { if(i_this->mBehaviorType != 3) { - dComIfGs_onSwitch(i_this->mSwitchToSet, i_this->current.roomNo); + dComIfGs_onSwitch(i_this->mSwitchToSet, fopAcM_GetRoomNo(i_this)); } switch(i_this->mBehaviorType) { @@ -71,16 +85,16 @@ static void daAndsw0_check(andsw0_class* i_this) { break; case ACT_OFF_ALL: - switchIdxToCheck = i_this->mFirstSwitchToCheck ? i_this->mFirstSwitchToCheck : i_this->mSwitchToSet + 1; + u32 switchIdxToCheck2 = i_this->mFirstSwitchToCheck ? i_this->mFirstSwitchToCheck : i_this->mSwitchToSet + 1; for(int i = 0; i < numToCheck; i++) { - if(dComIfGs_isSwitch(switchIdxToCheck, i_this->current.roomNo) == false) { - dComIfGs_offSwitch(i_this->mSwitchToSet, i_this->current.roomNo); + if(dComIfGs_isSwitch(switchIdxToCheck2, fopAcM_GetRoomNo(i_this)) == false) { + dComIfGs_offSwitch(i_this->mSwitchToSet, fopAcM_GetRoomNo(i_this)); i_this->mAction = ACT_ON_ALL; break; } - switchIdxToCheck += 1; + switchIdxToCheck2 += 1; } break; @@ -147,7 +161,7 @@ static void* ac[7]; static s32 check_count; static void* bk_s_sub1(void* i_this, void*) { - if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == 0xBE && (fopAcM_GetParam(i_this) & 0xF) == 7) { + if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == PROC_BK && (fopAcM_GetParam(i_this) & 0xF) == 7) { s32 count = check_count; //regswaps without this if(count < 2) { ac[check_count] = i_this; @@ -161,7 +175,7 @@ static void* bk_s_sub1(void* i_this, void*) { } static void* bk_s_sub2(void* i_this, void*) { - if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == 0xBE && (fopAcM_GetParam(i_this) & 0xF) == 4) { + if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == PROC_BK && (fopAcM_GetParam(i_this) & 0xF) == 4) { s32 count = check_count; //regswaps without this if(count == 2) { ac[check_count] = i_this; @@ -175,7 +189,7 @@ static void* bk_s_sub2(void* i_this, void*) { } static void* bk_s_sub3(void* i_this, void*) { - if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == 0xBE && (fopAcM_GetParam(i_this) & 0xF) == 5) { + if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == PROC_BK && (fopAcM_GetParam(i_this) & 0xF) == 5) { s32 count = check_count; //regswaps without this if(count < 5) { ac[check_count] = i_this; @@ -189,7 +203,7 @@ static void* bk_s_sub3(void* i_this, void*) { } static void* bb_s_sub(void* i_this, void*) { - if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == 0xB6) { + if(fopAcM_IsActor(i_this) && fopAcM_GetName(i_this) == PROC_BB) { s32 count = check_count; //regswaps without this if(count < 7) { ac[check_count] = i_this; @@ -224,7 +238,7 @@ static s32 hajimari_actor_entry(andsw0_class* i_this) { } static void hajimarinomori_check(andsw0_class* i_this) { - /* Nonmatching */ + fopAc_ac_c* actor = i_this; if (i_this->mBehaviorType == 0) { if (hajimari_actor_entry(i_this)) { i_this->mBehaviorType = 1; @@ -233,52 +247,62 @@ static void hajimarinomori_check(andsw0_class* i_this) { else { for(int i = 0; i < 7; i++) {} - //looks like these have something to do with bk_class and bb_class (based on the 0xB6/0xBE proc names earlier) - //finishing this probably needs some work on those if (dComIfGs_isEventBit(4)) { - fopAcM_delete((fopAc_ac_c*)ac[5]); - fopAcM_delete((fopAc_ac_c*)ac[6]); - //ac[3]->field_0x121C = 1; - //ac[4]->field_0x121C = 1; + bb_class* kargaroc = (bb_class*)ac[5]; + fopAcM_delete(kargaroc); + kargaroc = (bb_class*)ac[6]; + fopAcM_delete(kargaroc); + + bk_class* bokoblin = (bk_class*)ac[3]; + bokoblin->field_0x121C = 1; + bokoblin = (bk_class*)ac[4]; + bokoblin->field_0x121C = 1; if (dComIfGs_isEventBit(0x301)) { - //ac[0]->field_0x121C = 1; + bokoblin = (bk_class*)ac[0]; + bokoblin->field_0x121C = 1; } if (dComIfGs_isEventBit(0x480)) { - //ac[1]->field_0x121C = 1; + bokoblin = (bk_class*)ac[1]; + bokoblin->field_0x121C = 1; } if (dComIfGs_isEventBit(0x301) && dComIfGs_isEventBit(0x480)) { - //ac[2]->field_0x121C = 1; + bokoblin = (bk_class*)ac[2]; + bokoblin->field_0x121C = 1; } } else { - //ac[0]->field_0x121C = 1; - //ac[1]->field_0x121C = 1; + bk_class* bokoblin = (bk_class*)ac[0]; + bokoblin->field_0x121C = 1; + bokoblin = (bk_class*)ac[1]; + bokoblin->field_0x121C = 1; } + + fopAcM_delete(actor); } - - fopAcM_delete(i_this); } static void event_start_check(andsw0_class* i_this) { - /* Nonmatching */ + fopAc_ac_c* actor = i_this; switch (i_this->mEventState) { case 0: - if (i_this->mEventIdx != -1 && fopAcM_isSwitch(i_this, i_this->mSwitchToSet)) { - if (i_this->mEvtInfo.i_checkCommandDemoAccrpt()) { + if (i_this->mEventIdx != -1 && fopAcM_isSwitch(actor, i_this->mSwitchToSet)) { + if (actor->mEvtInfo.checkCommandDemoAccrpt()) { i_this->mEventState++; } else { - fopAcM_orderOtherEventId(i_this, i_this->mEventIdx, i_this->mEventNo, 0xFFFF, 0, 1); + fopAcM_orderOtherEventId(actor, i_this->mEventIdx, i_this->mEventNo, 0xFFFF, 0, 1); } } break; case 1: if (dComIfGp_evmng_endCheck(i_this->mEventIdx)) { - dComIfGp_event_onEventFlag(8); + dComIfGp_event_reset(); i_this->mEventState++; } break; + case 2: + break; } } diff --git a/src/d/actor/d_a_andsw2.cpp b/src/d/actor/d_a_andsw2.cpp index 12dea6235..7c60064f4 100644 --- a/src/d/actor/d_a_andsw2.cpp +++ b/src/d/actor/d_a_andsw2.cpp @@ -170,7 +170,7 @@ static s32 daAndsw2_actionEvent(daAndsw2_c* i_this) { } else { i_this->mAction = ACT_WAIT; } - dComIfGp_event_onEventFlag(8); + dComIfGp_event_reset(); } return 1; }