From d711118601dad11244eb8a2de79727ae9756cf9f Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 24 May 2024 10:47:51 +0200 Subject: [PATCH 01/11] db_assert --- config/SOUE01/splits.txt | 4 ++++ config/SOUE01/symbols.txt | 2 +- configure.py | 1 + include/nw4r/db/db_assert.h | 20 ++++++++++++++++++++ src/nw4r/db/db_assert.cpp | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 include/nw4r/db/db_assert.h create mode 100644 src/nw4r/db/db_assert.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index fdd52647..5dbd2c35 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -338,6 +338,10 @@ nw4r/db/db_directPrint.cpp: .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 +nw4r/db/db_assert.cpp: + .text start:0x804373C0 end:0x804373D0 + .sbss start:0x80576610 end:0x80576618 + egg/core/eggArchive.cpp: .text start:0x80493510 end:0x80494254 .data start:0x8056E820 end:0x8056E830 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 5250ad05..30c5841e 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -40838,7 +40838,7 @@ lbl_805765F8 = .sbss:0x805765F8; // type:object size:0x8 lbl_80576600 = .sbss:0x80576600; // type:object size:0x4 data:4byte lbl_80576604 = .sbss:0x80576604; // type:object size:0x4 data:4byte lbl_80576608 = .sbss:0x80576608; // type:object size:0x8 data:4byte -lbl_80576610 = .sbss:0x80576610; // type:object size:0x8 data:4byte +sConsoleHandle__Q24nw4r2db = .sbss:0x80576610; // type:object size:0x4 scope:local data:4byte lbl_80576618 = .sbss:0x80576618; // type:object size:0x4 data:4byte lbl_8057661C = .sbss:0x8057661C; // type:object size:0x4 data:4byte lbl_80576620 = .sbss:0x80576620; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 38b302df..8ee3f7e1 100644 --- a/configure.py +++ b/configure.py @@ -327,6 +327,7 @@ config.libs = [ nw4rLib( "db", [ + Object(Matching, "nw4r/db/db_assert.cpp"), Object(Matching, "nw4r/db/db_directPrint.cpp"), ], ), diff --git a/include/nw4r/db/db_assert.h b/include/nw4r/db/db_assert.h new file mode 100644 index 00000000..a7ff8de5 --- /dev/null +++ b/include/nw4r/db/db_assert.h @@ -0,0 +1,20 @@ +#ifndef DB_ASSERT_H +#define DB_ASSERT_H + +namespace nw4r { +namespace db { + +namespace detail { + struct ConsoleHead { + + }; +} + +typedef detail::ConsoleHead* ConsoleHandle; + +ConsoleHandle Assertion_SetConsole(ConsoleHandle handle); + +} // namespace db +} // namespace nw4r + +#endif diff --git a/src/nw4r/db/db_assert.cpp b/src/nw4r/db/db_assert.cpp new file mode 100644 index 00000000..d466a61f --- /dev/null +++ b/src/nw4r/db/db_assert.cpp @@ -0,0 +1,16 @@ +#include +#include + +namespace nw4r { +namespace db { + +static ConsoleHandle sConsoleHandle = nullptr; + +ConsoleHandle Assertion_SetConsole(ConsoleHandle handle) { + ConsoleHandle oldHandle = sConsoleHandle; + sConsoleHandle = handle; + return oldHandle; +} + +} // namespace db +} // namespace nw4r From d9e22fe76db024e8f6b9ecddf174892147ad493a Mon Sep 17 00:00:00 2001 From: CovenEsme <84377742+CovenEsme@users.noreply.github.com> Date: Fri, 24 May 2024 14:37:17 +0100 Subject: [PATCH 02/11] Expand dAcBase work --- config/SOUE01/splits.txt | 4 + config/SOUE01/symbols.txt | 50 +- configure.py | 1 + include/MSL_C/math.h | 1 + include/UnknownTypeBelongings.h | 2 +- include/d/a/d_a_base.h | 49 +- include/d/a/obj/d_a_obj_base.h | 15 + include/d/d_player.h | 12 + include/m/m_angle.h | 2 + include/toBeSorted/event.h | 22 + include/toBeSorted/file_manager.h | 2 +- include/toBeSorted/misc_flag_managers.h | 79 ++++ include/toBeSorted/room_manager.h | 86 +++- include/toBeSorted/scgame.h | 25 + include/toBeSorted/special_item_drop_mgr.h | 20 + src/d/a/d_a_base.cpp | 503 ++++++++++++++++++--- src/d/d_player.cpp | 3 + src/toBeSorted/file_manager.cpp | 2 +- src/toBeSorted/misc_flag_managers.cpp | 72 +-- src/toBeSorted/scgame.cpp | 5 + src/toBeSorted/special_item_drop_mgr.cpp | 114 +++++ 21 files changed, 882 insertions(+), 187 deletions(-) create mode 100644 include/d/d_player.h create mode 100644 include/toBeSorted/event.h create mode 100644 include/toBeSorted/misc_flag_managers.h create mode 100644 include/toBeSorted/scgame.h create mode 100644 include/toBeSorted/special_item_drop_mgr.h create mode 100644 src/d/d_player.cpp create mode 100644 src/toBeSorted/scgame.cpp create mode 100644 src/toBeSorted/special_item_drop_mgr.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index fdd52647..12e7156d 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -145,6 +145,10 @@ toBeSorted/skipflag_manager.cpp: .sbss start:0x80575408 end:0x8057540C .bss start:0x805A9C68 end:0x805A9C88 +toBeSorted/special_item_drop_mgr.cpp: + .text start:0x800C7B60 end:0x800C82B0 + .sbss start:0x80575438 end:0x80575440 + toBeSorted/counters/counter.cpp: .text start:0x8016CC40 end:0x8016CD94 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 5250ad05..dfe6eb41 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -1030,12 +1030,12 @@ createHeap__9dAcBase_cFv = .text:0x8002C3A0; // type:function size:0x8 __ct__9dAcBase_cFv = .text:0x8002C3B0; // type:function size:0x178 __dt__7dBase_cFv = .text:0x8002C530; // type:function size:0x58 __dt__9dAcBase_cFv = .text:0x8002C590; // type:function size:0xB4 -setTempCreateParams__9dAcBase_cFP7mVec3_cP7mAng3_cP7mVec3_ciUlP9dAcBase_cUcsUcP7ObjInfo = .text:0x8002C650; // type:function size:0x34 +setTempCreateParams__9dAcBase_cFP7mVec3_cP7mAng3_cP7mVec3_clUlP9dAcBase_cUcsUcP7ObjInfo = .text:0x8002C650; // type:function size:0x34 FUN_8002c690__9dAcBase_cFv = .text:0x8002C690; // type:function size:0x78 initAllocatorWork1Heap__9dAcBase_cFiPci = .text:0x8002C710; // type:function size:0xC initAllocator__9dAcBase_cFiPcPQ23EGG4Heapi = .text:0x8002C720; // type:function size:0x8C -addActorToRoom__9dAcBase_cFi = .text:0x8002C7B0; // type:function size:0x88 -setBit_field_0xE8__9dAcBase_cFi = .text:0x8002C840; // type:function size:0x18 +addActorToRoom__9dAcBase_cFl = .text:0x8002C7B0; // type:function size:0x88 +setBit_field_0xE8__9dAcBase_cFl = .text:0x8002C840; // type:function size:0x18 actorCreate__9dAcBase_cFv = .text:0x8002C860; // type:function size:0x8 actorPostCreate__9dAcBase_cFv = .text:0x8002C870; // type:function size:0x8 create__9dAcBase_cFv = .text:0x8002C880; // type:function size:0x70 @@ -1049,20 +1049,20 @@ postExecute__9dAcBase_cFQ27fBase_c12MAIN_STATE_e = .text:0x8002CCC0; // type:fun unkVirtFunc_0x5C__9dAcBase_cFv = .text:0x8002CE90; // type:function size:0x4 unkVirtFunc_0x60__9dAcBase_cFv = .text:0x8002CEA0; // type:function size:0x4 restorePosRotFromCopy__9dAcBase_cFv = .text:0x8002CEB0; // type:function size:0x58 -itemDroppingAndGivingRelated__9dAcBase_cFP5Vec3fi = .text:0x8002CF10; // type:function size:0x80 +itemDroppingAndGivingRelated__9dAcBase_cFP7mVec3_ci = .text:0x8002CF10; // type:function size:0x80 fillUpperParams2Byte__9dAcBase_cFv = .text:0x8002CF90; // type:function size:0x10 getParams2_ignoreLower__9dAcBase_cFv = .text:0x8002CFA0; // type:function size:0xC setParams2Upper_ignoreLower__9dAcBase_cFUl = .text:0x8002CFB0; // type:function size:0xC getParams2UpperByte__9dAcBase_cFv = .text:0x8002CFC0; // type:function size:0xC setParams2UpperByte__9dAcBase_cFUl = .text:0x8002CFD0; // type:function size:0x14 -buildParams2__9dAcBase_cFUlUc = .text:0x8002CFF0; // type:function size:0x1C +buildParams2__9dAcBase_cFUlUl = .text:0x8002CFF0; // type:function size:0x1C getParams2Lower__9dAcBase_cFv = .text:0x8002D010; // type:function size:0xC findActor__9dAcBase_cFPcP9dAcBase_c = .text:0x8002D020; // type:function size:0x74 -searchActor__9dAcBase_cFR9dAcBase_c = .text:0x8002D0A0; // type:function size:0x88 -forEachActor__9dAcBase_cFPvR9dAcBase_c = .text:0x8002D130; // type:function size:0x5C -getXZAngleToPlayer__9dAcBase_cFv = .text:0x8002D190; // type:function size:0x3C -getDistanceToActor__9dAcBase_cFR9dAcBase_cfPf = .text:0x8002D1D0; // type:function size:0xB8 -getDistanceAndAngleToActor__9dAcBase_cFR9dAcBase_cfssPfPsPs = .text:0x8002D290; // type:function size:0x148 +searchActor__9dAcBase_cFP9dAcBase_c = .text:0x8002D0A0; // type:function size:0x88 +forEveryActor__9dAcBase_cFPFP9dAcBase_cP9dAcBase_c_PvP9dAcBase_c = .text:0x8002D130; // type:function size:0x5C +getXZAngleToPlayer__9dAcBase_cFPs = .text:0x8002D190; // type:function size:0x3C +getDistanceToActor__9dAcBase_cFP9dAcBase_cfPf = .text:0x8002D1D0; // type:function size:0xB8 +getDistanceAndAngleToActor__9dAcBase_cFP9dAcBase_cfssPfPsPs = .text:0x8002D290; // type:function size:0x148 isWithinPlayerRadius__9dAcBase_cFf = .text:0x8002D3E0; // type:function size:0x5C getDistanceAndAngleToPlayer__9dAcBase_cFfssPfPsPs = .text:0x8002D440; // type:function size:0x2C getDistToPlayer__9dAcBase_cFv = .text:0x8002D470; // type:function size:0x30 @@ -1084,17 +1084,17 @@ FUN_8002d7f0__9dAcBase_cFv = .text:0x8002D7F0; // type:function size:0x20 FUN_8002d810__9dAcBase_cFv = .text:0x8002D810; // type:function size:0x20 FUN_8002d830__9dAcBase_cFv = .text:0x8002D830; // type:function size:0x28 FUN_8002d860__9dAcBase_cFv = .text:0x8002D860; // type:function size:0x20 -FUN_8002d880__9dAcBase_cFv = .text:0x8002D880; // type:function size:0x8 +getSoundSource__9dAcBase_cFv = .text:0x8002D880; // type:function size:0x8 FUN_8002d890__9dAcBase_cFv = .text:0x8002D890; // type:function size:0x88 setActorRef__9dAcBase_cFP7dBase_c = .text:0x8002D920; // type:function size:0x8 -setUnkFlag__9dAcBase_cFv = .text:0x8002D930; // type:function size:0x10 -FUN_8002d940__9dAcBase_cFv = .text:0x8002D940; // type:function size:0x14 -FUN_8002d960__9dAcBase_cFv = .text:0x8002D960; // type:function size:0x14 -createActor__9dAcBase_cFUsUlP5Vec3fP5Vec3sP5Vec3fUliP7dBase_c = .text:0x8002D980; // type:function size:0xF4 -createActorUnkGroup3__9dAcBase_cFUsUlP5Vec3fP5Vec3sP5Vec3fUliP7dBase_c = .text:0x8002DA80; // type:function size:0xF4 +setEnemyDefeatFlag__9dAcBase_cFv = .text:0x8002D930; // type:function size:0x10 +changeLoadedEntitiesWithSet__9dAcBase_cFv = .text:0x8002D940; // type:function size:0x14 +changeLoadedEntitiesNoSet__9dAcBase_cFv = .text:0x8002D960; // type:function size:0x14 +createActor__9dAcBase_cFUsUlP7mVec3_cP7mAng3_cP7mVec3_cUllP7dBase_c = .text:0x8002D980; // type:function size:0xF4 +createActorStage__9dAcBase_cFUsUlP7mVec3_cP7mAng3_cP7mVec3_cUllP7dBase_c = .text:0x8002DA80; // type:function size:0xF4 getCurrentEventActor__9dAcBase_cFv = .text:0x8002DB80; // type:function size:0x4 unkVirtFunc_0x6C__9dAcBase_cFv = .text:0x8002DB90; // type:function size:0x4 -doInteraction__9dAcBase_cFi = .text:0x8002DBA0; // type:function size:0x80 +doInteraction__9dAcBase_cFl = .text:0x8002DBA0; // type:function size:0x80 FUN_8002dc20__9dAcBase_cFPsPs = .text:0x8002DC20; // type:function size:0x28 incrementKillCounter__9dAcBase_cFv = .text:0x8002DC50; // type:function size:0x7C FUN_8002dcd0__9dAcBase_cFv = .text:0x8002DCD0; // type:function size:0x3C @@ -4413,15 +4413,15 @@ fn_800C7A00 = .text:0x800C7A00; // type:function size:0x8 fn_800C7A10 = .text:0x800C7A10; // type:function size:0x8 fn_800C7A20 = .text:0x800C7A20; // type:function size:0x130 fn_800C7B50 = .text:0x800C7B50; // type:function size:0x8 -fn_800C7B60 = .text:0x800C7B60; // type:function size:0x14 +__ct__18SpecialItemDropMgrFv = .text:0x800C7B60; // type:function size:0x14 fn_800C7B80 = .text:0x800C7B80; // type:function size:0x30 -fn_800C7BB0 = .text:0x800C7BB0; // type:function size:0x150 -fn_800C7D00 = .text:0x800C7D00; // type:function size:0x1C -fn_800C7D20 = .text:0x800C7D20; // type:function size:0x1C -fn_800C7D40 = .text:0x800C7D40; // type:function size:0x1A8 -fn_800C7EF0 = .text:0x800C7EF0; // type:function size:0x2D8 -fn_800C81D0 = .text:0x800C81D0; // type:function size:0x98 -fn_800C8270 = .text:0x800C8270; // type:function size:0x40 +fn_800C7BB0__FP18SpecialItemDropMgri = .text:0x800C7BB0; // type:function size:0x150 +fn_800C7D00__FP18SpecialItemDropMgri = .text:0x800C7D00; // type:function size:0x1C +fn_800C7D20__FP18SpecialItemDropMgri = .text:0x800C7D20; // type:function size:0x1C +giveSpecialDropItem__FP18SpecialItemDropMgriiP7mVec3_ciPsi = .text:0x800C7D40; // type:function size:0x1A8 +spawnSpecialDropItem__FP18SpecialItemDropMgriiP7mVec3_ciPs = .text:0x800C7EF0; // type:function size:0x2D8 +fn_800C81D0__Fsss = .text:0x800C81D0; // type:function size:0x98 +__dt__18SpecialItemDropMgrFv = .text:0x800C8270; // type:function size:0x40 fn_800C82B0 = .text:0x800C82B0; // type:function size:0x18 fn_800C82D0 = .text:0x800C82D0; // type:function size:0x18 fn_800C82F0 = .text:0x800C82F0; // type:function size:0xB0 diff --git a/configure.py b/configure.py index 38b302df..f423f3f7 100644 --- a/configure.py +++ b/configure.py @@ -278,6 +278,7 @@ config.libs = [ Object(NonMatching, "toBeSorted/misc_flag_managers.cpp"), Object(Matching, "toBeSorted/dungeonflag_manager.cpp"), Object(Matching, "toBeSorted/skipflag_manager.cpp"), + Object(NonMatching, "toBeSorted/special_item_drop_mgr.cpp"), Object(Matching, "c/c_list.cpp"), Object(Matching, "c/c_tree.cpp"), Object(Matching, "d/d_base.cpp"), diff --git a/include/MSL_C/math.h b/include/MSL_C/math.h index ca14879f..f09c6fdd 100644 --- a/include/MSL_C/math.h +++ b/include/MSL_C/math.h @@ -15,6 +15,7 @@ extern "C" { #endif int abs(int); +int labs(int); double acos(double); float acosf(float); double asin(double); diff --git a/include/UnknownTypeBelongings.h b/include/UnknownTypeBelongings.h index 58fcd52a..572059c0 100644 --- a/include/UnknownTypeBelongings.h +++ b/include/UnknownTypeBelongings.h @@ -21,7 +21,7 @@ struct ObjInfo { /* 0x04 */ u16 obj_id; /* 0x06 */ u16 obj_id2; /* 0x08 */ u16 fiTextEntryId; - /* 0x0A */ u8 unk_0xA; + /* 0x0A */ s8 unk_0xA; /* 0x0B */ u8 subtype; }; diff --git a/include/d/a/d_a_base.h b/include/d/a/d_a_base.h index 5ae0efe0..66333274 100644 --- a/include/d/a/d_a_base.h +++ b/include/d/a/d_a_base.h @@ -12,9 +12,14 @@ #include "toBeSorted/room_manager.h" class dAcBase_c; + +struct SoundSource { + // TODO +}; + struct SoundInfo { dAcBase_c *actor; - void *obj_sound; + SoundSource *sound_source; mVec3_c *obj_pos; SoundInfo *next; SoundInfo *prev; @@ -29,13 +34,13 @@ public: /* 0x88 */ void *sound_info_tail; /* 0x8c */ void *sound_info_next; /* 0x90 */ int count; - /* 0x94 */ void *obj_sound; + /* 0x94 */ SoundSource *sound_source; /* 0x9C */ mVec3_c *obj_pos; /* 0x9c */ mVec3_c pos_copy; /* 0xa8 */ u32 params2; /* 0xAC */ mAng3_c rot_copy; /* 0xB2 */ u16 obj_id; // enemydefeat flag / id on obj-map - /* 0xB4 */ u8 room_id_copy; + /* 0xB4 */ s8 room_id_copy; /* 0xB5 */ u8 viewclip_index; /* 0xB6 */ u8 subtype; /* 0xB8 */ mAng3_c rotation; @@ -44,7 +49,7 @@ public: /* 0xD8 */ u32 actor_properties; /* 0xDC */ fLiNdBa_c actor_node; /* 0xE8 */ u32 field_0xe8; - /* 0xEC */ u8 roomid; + /* 0xEC */ s8 roomid; /* 0xED */ u8 actor_subtype; /* 0xF0 */ u32 JStudio_actor; /* 0xF4 */ char someStr[4]; @@ -101,29 +106,29 @@ public: /* 8002c650 */ static void setTempCreateParams(mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, s32 roomId, u32 params2, dAcBase_c *parent, u8 subtype, s16 unkFlag, u8 viewClipIdx, ObjInfo *objInfo); - /* 8002c690 */ void *FUN_8002c690(); + /* 8002c690 */ SoundSource *FUN_8002c690(); /* 8002c710 */ int initAllocatorWork1Heap(int size, char *name, int align); /* 8002c720 */ int initAllocator(int size, char *name, EGG::Heap *heap, int align); /* 8002c7b0 */ bool addActorToRoom(s32 roomId); /* 8002c840 */ void setBit_field_0xE8(s32); - /* 8002cf10 */ u32 itemDroppingAndGivingRelated(Vec3f *spawnPos, int subtype); + /* 8002cf10 */ u32 itemDroppingAndGivingRelated(mVec3_c *spawnPos, int subtype); /* 8002cf90 */ void fillUpperParams2Byte(); /* 8002cfa0 */ u32 getParams2_ignoreLower(); /* 8002cfb0 */ void setParams2Upper_ignoreLower(u32 val); /* 8002cfc0 */ u8 getParams2UpperByte(); /* 8002cfd0 */ void setParams2UpperByte(u32 val); - /* 8002cff0 */ static u32 buildParams2(u32 lower, u8 upper); + /* 8002cff0 */ static u32 buildParams2(u32 lower, u32 upper); /* 8002d010 */ u32 getParams2Lower(); /* 8002d020 */ static dAcBase_c *findActor(char *objName, dAcBase_c *parent); - /* 8002d0a0 */ static dAcBase_c *searchActor(dAcBase_c &optionalParent); + /* 8002d0a0 */ static dAcBase_c *searchActor(dAcBase_c *parent); // Kinda performs the code of the first param on every actor (second param is optional parent) - /* 8002d130 */ static void forEachActor(void *, dAcBase_c &); + /* 8002d130 */ static void forEveryActor(void *func(dAcBase_c *, dAcBase_c *), dAcBase_c *parent); // Not really static, but we currently dont have a type for the return (not just simply a s16) - /* 8002d190 */ mAng getXZAngleToPlayer(); + /* 8002d190 */ void getXZAngleToPlayer(s16 *angle); // returns true if under the distThresh, False if not. the actual distance is returned in outDist - /* 8002d1d0 */ bool getDistanceToActor(dAcBase_c &actor, f32 distThresh, f32 *outDist); + /* 8002d1d0 */ bool getDistanceToActor(dAcBase_c *actor, f32 distThresh, f32 *outDist); // same concept as above - /* 8002d290 */ bool getDistanceAndAngleToActor(dAcBase_c &actor, f32 distThresh, s16 yAngle, s16 xAngle, + /* 8002d290 */ bool getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, s16 *outDiffAngleX); /* 8002d3e0 */ bool isWithinPlayerRadius(f32 radius); /* 8002d440 */ bool getDistanceAndAngleToPlayer(f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, @@ -132,7 +137,8 @@ public: /* 8002d4a0 */ f32 getSquareDistToPlayer(); /* 8002d4b0 */ void updateRoomId(f32 yOffs); /* 8002d540 */ bool isRoomFlags_0x6_Set(); - // Begin Sound Effect Related + + // Start of SoundSource stuff /* 8002d590 */ void FUN_8002d590(); /* 8002d5b0 */ void FUN_8002d5b0(); /* 8002d5d0 */ void playSound(); @@ -148,20 +154,19 @@ public: /* 8002d810 */ void FUN_8002d810(); /* 8002d830 */ void FUN_8002d830(); /* 8002d860 */ void FUN_8002d860(); - /* 8002d880 */ void FUN_8002d880(); - // End Sound Effect Related + /* 8002d880 */ SoundSource *getSoundSource(); + // End of SoundSource stuff + /* 8002d890 */ void FUN_8002d890(); /* 8002d920 */ void setActorRef(dBase_c *); // next three funcs are related - /* 8002d930 */ void setUnkFlag(); - /* 8002d940 */ void FUN_8002d940(); - /* 8002d960 */ void FUN_8002d960(); + /* 8002d930 */ void setEnemyDefeatFlag(); + /* 8002d940 */ void changeLoadedEntitiesWithSet(); + /* 8002d960 */ void changeLoadedEntitiesNoSet(); - /* 8002d980 */ static dAcBase_c createActor(ProfileName actorId, u32 params1, Vec3f *pos, Vec3s *rot, Vec3f *scale, - u32 params2, s32 roomId, dBase_c *ref); + /* 8002d980 */ dAcBase_c *createActor(ProfileName actorId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, s32 roomId, dBase_c *ref); - /* 8002da80 */ static dAcBase_c createActorUnkGroup3(ProfileName actorId, u32 params1, Vec3f *pos, Vec3s *rot, - Vec3f *scale, u32 params2, s32 roomId, dBase_c *ref); + /* 8002da80 */ dAcBase_c *createActorStage(ProfileName actorId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, s32 roomId, dBase_c *ref); /* 8002dc20 */ void FUN_8002dc20(s16 *, s16 *); /* 8002dc50 */ void incrementKillCounter(); diff --git a/include/d/a/obj/d_a_obj_base.h b/include/d/a/obj/d_a_obj_base.h index c4467825..37153e07 100644 --- a/include/d/a/obj/d_a_obj_base.h +++ b/include/d/a/obj/d_a_obj_base.h @@ -11,6 +11,20 @@ class dAcObjBase_c : public dAcBase_c { public: // Data Members + f32 yoffset; + char _0[4]; + f32 unkfloat; + char _1[12]; + s16 targetFiTextId; + u8 unkByteTargetFiRelated; + mVec3_c poscopy1; + mVec3_c poscopy2; + mVec3_c poscopy3; + mAng3_c rotcopy1; + f32 forwardSpeed; + f32 forwardAccel; + f32 forwardMaxSpeed; + // TODO: add the rest public: // could be their own thing? @@ -72,4 +86,5 @@ public: /* 8002f260 */ static dAcBase_c createActorUnkGroup3(char *name, u32 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, u16 id, u8 viewclipId); }; + #endif diff --git a/include/d/d_player.h b/include/d/d_player.h new file mode 100644 index 00000000..28f737b0 --- /dev/null +++ b/include/d/d_player.h @@ -0,0 +1,12 @@ +#ifndef D_PLAYER_H +#define D_PLAYER_H + +#include +#include "d/a/obj/d_a_obj_base.h" + +class dPlayer: public dAcObjBase_c { +public: + static dPlayer *LINK; +}; + +#endif diff --git a/include/m/m_angle.h b/include/m/m_angle.h index 37fca394..832800a8 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -14,6 +14,8 @@ struct mAng { class mAng3_c { public: + mAng3_c() {} + s16 x, y, z; mAng3_c(s16 fx, s16 fy, s16 fz) : x(fx), y(fy), z(fz) {} diff --git a/include/toBeSorted/event.h b/include/toBeSorted/event.h new file mode 100644 index 00000000..0260693c --- /dev/null +++ b/include/toBeSorted/event.h @@ -0,0 +1,22 @@ +#ifndef EVENT_H +#define EVENT_H + +#include + +class Event { +public: + void *unk; + u32 eventFlags; + s32 roomid; + s32 toolDataid; + char eventName[32]; + void *eventZevData; + void *callback1; + void *callback2; + +public: + Event(char *eventName, u32 unk, u32 eventFlags, void *callback1, void *callback2); + virtual ~Event(); +}; + +#endif diff --git a/include/toBeSorted/file_manager.h b/include/toBeSorted/file_manager.h index 282cfc4b..858de5a4 100644 --- a/include/toBeSorted/file_manager.h +++ b/include/toBeSorted/file_manager.h @@ -163,7 +163,7 @@ public: /* 8000BA70 */ void setBeaconPos(u32 beaconArea, u32 beaconNum, mVec3_c *pos); /* 8000BB80 */ mVec3_c *getBeaconPos(u32 beaconArea, u32 beaconNum); /* 8000BC70 */ void setEnemyKillCount(u32 enemy, u16 killCount); - /* 8000BCE0 */ u16 getEnemyKillCount(u32 enemy); + /* 8000BCE0 */ s16 getEnemyKillCount(u32 enemy); /* 8000BD60 */ void setHitCountFromEnemy(u32 enemy, u16 hitCount); /* 8000BDD0 */ u16 getHitCountFromEnemy(u32 enemy); diff --git a/include/toBeSorted/misc_flag_managers.h b/include/toBeSorted/misc_flag_managers.h new file mode 100644 index 00000000..0904c13b --- /dev/null +++ b/include/toBeSorted/misc_flag_managers.h @@ -0,0 +1,79 @@ +#ifndef MISC_FLAG_MANAGERS_H +#define MISC_FLAG_MANAGERS_H + +#include +#include +#include + +class CommittableFlagManager { +public: + bool mNeedsCommit; + + virtual void doCommit() = 0; + bool commitIfNecessary(); + void setNeedsCommit(bool commit) { + mNeedsCommit = commit; + } + CommittableFlagManager() { + mNeedsCommit = false; + } + CommittableFlagManager(bool commit) { + mNeedsCommit = commit; + } +}; + +class TBoxFlagManager : public CommittableFlagManager { +public: + FlagSpace mFlagSpace; + u16 mSceneIndex; + BitwiseFlagHelper mFlagHelper; + + static u16 sTBoxFlags[2]; + + static TBoxFlagManager *sInstance; + + virtual void doCommit() override; + bool checkUncommittedFlag(u16 flag); + TBoxFlagManager(); + virtual ~TBoxFlagManager() {} + void init(); + void copyFromSave(s16 sceneIndex); + bool checkFlag(u16 sceneIndex, u16 flag); + virtual u16 getFlagCount() const; + void setFlag(u16 flag); + bool checkUncommittedFlag(u16 sceneIndex, u16 flag); + u16 checkUncommittedFlag2(u16 flag) { + return checkUncommittedFlag(flag); + } +}; + +// NOTE: Not actually Enemy Defeat. +// This is a little more than that, it keeps track of live objects based on their id as a whole +class EnemyDefeatManager : public CommittableFlagManager { +public: + FlagSpace mFlagSpace; + BitwiseFlagHelper mFlagHelper; + u16 mSceneIndex; + + static u16 sEnemyDefeatFlags[4096]; + + static EnemyDefeatManager *sInstance; + + void clearSavedFlags(); + bool checkUncommittedFlag(u16 flag); + u16 checkUncommittedFlag2(u16 flag) { + return checkUncommittedFlag(flag); + } + EnemyDefeatManager(); + void init(); + void copyFromSave(u16 sceneIndex); + void updateFlagIndex(u16 sceneIndex); + void clearAll(); + bool checkIsValidFlag(u16 flag); + bool checkFlag(u16 flag); + virtual ~EnemyDefeatManager() {} + virtual u16 getFlagCount() const; + void setFlag(u16 flag); +}; + +#endif diff --git a/include/toBeSorted/room_manager.h b/include/toBeSorted/room_manager.h index a010d185..fb7a0f66 100644 --- a/include/toBeSorted/room_manager.h +++ b/include/toBeSorted/room_manager.h @@ -3,16 +3,80 @@ #include "d/d_base.h" #include +#include "m/m_allocator.h" +#include "m/types_m.h" #define MAX_ROOM_NUMBER 64 -class dRoom; -class RoomTable { - RoomTable(); - virtual ~RoomTable(); +class dRoomModel { + char mainModel[28]; // Actually smdl_c + nw4r::math::AABB *roomBounds; + m3d::anmMatClr_c *anmMatClr; + m3d::anmTexPat_c *anmTexPat; + m3d::anmTexSrt_c *anmTexSrt; + m3d::anmVis_c *anmVis; +}; + +class dRoomCollision { + char todo[352]; +}; + +class dRoom : dBase_c { +public: + mAllocator_c allocator; + nw4r::g3d::ResFile *roomRes; + char unkWithWater[24]; + dRoomModel roomModels[8]; + dRoomCollision roomCollisions[2]; + char stateMgr[60]; + char _0[4]; + void *SCEN; + void *PLY; + void *CAM; + void *EVNT; + void *PATH; + void *PNT; + void *BPNT; + void *SPTH; + void *_1; + void *_2; + void *AREA; + char _3[4]; + short plyCount; + short camCount; + short evntCount; + short pathCount; + short pntCount; + short bpntCount; + short spthCount; + short _4; + short _5; + short areaCount; + char _6[4]; + u8 flags; + void *BZS; + s8 roomid; + char _7[3]; + bool hasAnmTexPat; + bool didAlreadyInit; +}; + +class dRoomTable { + /* 801b4670 */ dRoomTable(dRoomTable *roomTable); + virtual ~dRoomTable(); dRoom *rooms[MAX_ROOM_NUMBER - 1]; }; +class MapRelated { +public: + mAllocator_c allocator; + char unk[472]; + +public: + /* 801b4780 */ void init(MapRelated *); + /* 801b4900 */ void fn_801b4900(); +}; + // OBJ NAME: STAGE // Ghidra: RoomManager // size: 0x239c @@ -20,9 +84,9 @@ class RoomTable { class RoomManager : public dBase_c { public: /* 0068 */ char field_0x68[0x7C - 0x68]; - /* 007C */ RoomTable rooms; - /* 017c */ char fader[0x1a0 - 0x17c]; // size unk - /* 01a0 */ char mapRelated[0x39c - 0x1a0]; // size unk + /* 007C */ dRoomTable rooms; + /* 017c */ char fader[0x1a0 - 0x174]; // size unk + /* 01a0 */ MapRelated mapRelated; /* 039c */ u32 loaded_entities[2047]; /* 2398 */ u8 curr_room_id; @@ -31,6 +95,14 @@ public: public: /* 801b42b0 */ static dBase_c *getRoom(int roomid); + /* 801b42d0 */ static void bindStageResToFile(nw4r::g3d::ResFile *); + /* 801b4320 */ static void bindSkyCmnToResFile(nw4r::g3d::ResFile *); + /* 801b4380 */ static bool getMA0AnmTexSrt(nw4r::g3d::ResAnmTexSrt *, char *); + /* 801b4420 */ static bool getMA0IndirectSrt(nw4r::g3d::ResAnmTexSrt *, char *); + /* 801b44c0 */ static void changeLoadedEntities(RoomManager *mgr, u32 index_shift, bool set); + /* 801b4510 */ static u32 checkRoomFlag(RoomManager *mgr, u32 flag); + /* 801b4550 */ static bool checkEnemyDefeatFlag(RoomManager *mgr, u32 flag); + /* 801b45c0 */ static bool fn_801B45C0(RoomManager *mgr /* plus others */); }; #endif diff --git a/include/toBeSorted/scgame.h b/include/toBeSorted/scgame.h new file mode 100644 index 00000000..aa465d4a --- /dev/null +++ b/include/toBeSorted/scgame.h @@ -0,0 +1,25 @@ +#ifndef SCGAME_H +#define SCGAME_H + +#include + +struct SpawnInfo { + /* 0x00 */ char stageName[32]; + /* 0x20 */ s16 transitionFadeFrames; + /* 0x22 */ s8 room; + /* 0x23 */ s8 layer; + /* 0x24 */ s8 entrance; + /* 0x25 */ s8 night; + /* 0x26 */ s8 trial; + /* 0x27 */ s8 transitionType; + /* 0x28 */ s32 unk; +}; + +class ScGame { +public: + static SpawnInfo currentSpawnInfo; + static SpawnInfo nextSpawnInfo; + static ScGame *sInstance; +}; + +#endif diff --git a/include/toBeSorted/special_item_drop_mgr.h b/include/toBeSorted/special_item_drop_mgr.h new file mode 100644 index 00000000..3fc1c7d8 --- /dev/null +++ b/include/toBeSorted/special_item_drop_mgr.h @@ -0,0 +1,20 @@ +#ifndef SPECIAL_ITEM_DROP_MGR_H +#define SPECIAL_ITEM_DROP_MGR_H + +#include + +class SpecialItemDropMgr { +public: + static SpecialItemDropMgr *sInstance; + + SpecialItemDropMgr(); + static int fn_800C7BB0(SpecialItemDropMgr *mgr, int specialItemId); + static short fn_800C7D00(SpecialItemDropMgr *mgr, int specialItemId); + static short fn_800C7D20(SpecialItemDropMgr *mgr, int specialItemId); + static int giveSpecialDropItem(SpecialItemDropMgr *mgr, int specialItemId, int roomid, mVec3_c *pos, int subtype, s16 *rot, s32 unused); + static bool spawnSpecialDropItem(SpecialItemDropMgr *mgr, int specialItemId, int roomid, mVec3_c *pos, int subtype, s16 *rot); + static void fn_800C81D0(s16, s16, s16); + ~SpecialItemDropMgr(); +}; + +#endif diff --git a/src/d/a/d_a_base.cpp b/src/d/a/d_a_base.cpp index 51705bd2..f103ca01 100644 --- a/src/d/a/d_a_base.cpp +++ b/src/d/a/d_a_base.cpp @@ -1,6 +1,13 @@ #include "d/a/d_a_base.h" +#include "m/m_vec.h" +#include "d/d_player.h" +#include "f/f_list_nd.h" +#include "toBeSorted/misc_flag_managers.h" +#include "toBeSorted/special_item_drop_mgr.h" +#include "toBeSorted/scgame.h" +#include "toBeSorted/event.h" +#include "toBeSorted/file_manager.h" -// RoomManager* RoomManager::m_Instance; // .sdata u32 dAcBase_c::s_Create_RoomId = -1; @@ -17,8 +24,15 @@ ObjInfo *dAcBase_c::s_Create_ObjInfo; u8 dAcBase_c::s_Create_Subtype; extern "C" ObjInfo *getObjByActorIdAndSubtype_unkNamespace(ProfileName, u8); +extern "C" ObjInfo *getObjByActorName_unkNamespace(char *name); extern "C" char *getObjectName_8006a730(ObjInfo *); -extern "C" void *soundForActorInitRelated_803889c0(s8, fBase_c *, char *, u8); +extern "C" SoundSource *soundForActorInitRelated_803889c0(s8, fBase_c *, char *, u8); +extern "C" short targetAngleY(mVec3_c *, mVec3_c *); +extern "C" short targetAngleX(mVec3_c *, mVec3_c *); +extern "C" bool checkCollision(mVec3_c *pos); +extern "C" s8 collisionCheckGetRoom(); +extern "C" dRoom *getRoomByIndex(RoomManager *mgr, s8 roomid); +extern "C" bool alsoSetAsCurrentEvent(dAcBase_c*, Event*, void *); bool dAcBase_c::createHeap() { return true; @@ -27,27 +41,30 @@ bool dAcBase_c::createHeap() { // Doesnt Match Yet dAcBase_c::dAcBase_c() : heap_allocator(), obj_info(s_Create_ObjInfo), sound_info_tail(&heap_allocator.mHeap), - sound_info_next(&heap_allocator.mHeap), count(0), obj_sound(nullptr), obj_pos(&position), - params2(s_Create_Params2), obj_id(s_Create_UnkFlags), viewclip_index(s_Create_ViewClipIdx), actor_node(), + sound_info_next(&heap_allocator.mHeap), count(0), sound_source(nullptr), obj_pos(&position), + params2(s_Create_Params2), obj_id(s_Create_UnkFlags), viewclip_index(s_Create_ViewClipIdx), actor_node(nullptr), roomid(s_Create_RoomId), actor_subtype(s_Create_Subtype) { JStudio_actor = 0; someStr[0] = 0; + if (s_Create_Position != nullptr) { - // void set(f32 fx, f32 fy, f32 fz) { x = fx; y = fy; z = fz; } position.set(s_Create_Position->x, s_Create_Position->y, s_Create_Position->z); - // position = *s_Create_Position; } - if (s_Create_Rotation != 0) { + + if (s_Create_Rotation != nullptr) { rotation = *(s_Create_Rotation); } - if (s_Create_Scale != 0) { + + if (s_Create_Scale != nullptr) { setScale(s_Create_Scale->x, s_Create_Scale->y, s_Create_Scale->z); } else { setScale(1.0, 1.0, 1.0); } - if (s_Create_Parent != 0) { + + if (s_Create_Parent != nullptr) { setActorRef(s_Create_Parent); } + fProfile::fActorProfile_c *profile = (fProfile::fActorProfile_c *)((*fProfile::sProfileList)[profile_name]); actor_properties = profile->mActorProperties; if (obj_info == nullptr) { @@ -56,9 +73,14 @@ dAcBase_c::dAcBase_c() someStr[0] = '\0'; } -/* 8002c530 */ dBase_c::~dBase_c() {} +// 8002c530 +dBase_c::~dBase_c() {} -dAcBase_c::~dAcBase_c() {} +dAcBase_c::~dAcBase_c() { + if (sound_source != nullptr) { + // call obj_sound dtor once defined + } +} void dAcBase_c::setTempCreateParams(mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, s32 roomId, u32 params2, dAcBase_c *parent, u8 subtype, s16 unkFlag, u8 viewClipIdx, ObjInfo *objInfo) { @@ -75,14 +97,16 @@ void dAcBase_c::setTempCreateParams(mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, } // has regswap -void *dAcBase_c::FUN_8002c690() { +SoundSource *dAcBase_c::FUN_8002c690() { if (obj_info == nullptr) { return nullptr; } - s8 unk_val = obj_info->unk_0xA; + + s32 unk_val = obj_info->unk_0xA; if (unk_val == -1) { return nullptr; } + char *objName = getObjectName_8006a730(obj_info); return soundForActorInitRelated_803889c0(unk_val, this, objName, subtype); } @@ -96,7 +120,7 @@ int dAcBase_c::initAllocator(int size, char *name, EGG::Heap *heap, int align) { if (fn_802EE510(&heap_allocator, size, heap, name, 0x20, 0) == 0) { return 0; } - obj_sound = FUN_8002c690(); + sound_source = FUN_8002c690(); int success = createHeap(); heap_allocator.adjustFrmHeapRestoreCurrent(); return success; @@ -117,15 +141,19 @@ bool dAcBase_c::addActorToRoom(s32 roomId) { } return false; } + void dAcBase_c::setBit_field_0xE8(s32 shift) { field_0xe8 |= (1 << shift); } + int dAcBase_c::actorCreate() { return SUCCEEDED; } + int dAcBase_c::actorPostCreate() { return SUCCEEDED; } + int dAcBase_c::create() { if (actor_properties & 0x8000000) { return actorPostCreate(); @@ -138,6 +166,8 @@ int dAcBase_c::create() { return success; } +// 8002c8f0 +// loads f2 before f0 instead of f0 then f2 void dAcBase_c::postCreate(fBase_c::MAIN_STATE_e state) { if (state == SUCCESS) { pos_copy = position; @@ -147,8 +177,10 @@ void dAcBase_c::postCreate(fBase_c::MAIN_STATE_e state) { dBase_c::postCreate(state); } +// 8002c940 int dAcBase_c::preDelete() {} +// 8002cb10 int dAcBase_c::preExecute() { if (dBase_c::preExecute() == NOT_READY) { return NOT_READY; @@ -161,44 +193,260 @@ int dAcBase_c::preExecute() { } return SUCCEEDED; } + +// 8002cc10 int dAcBase_c::execute() {} -int dAcBase_c::actorExecute() {} -int dAcBase_c::actorExecuteInEvent() {} + +// 8002cca0 +int dAcBase_c::actorExecute() { + return 1; +} + +// 8002ccb0 +int dAcBase_c::actorExecuteInEvent() { + return actorExecute(); +} + +// 8002ccc0 void dAcBase_c::postExecute(fBase_c::MAIN_STATE_e state) {} + +// 8002ce90 void dAcBase_c::unkVirtFunc_0x5C() { return; } + +// 8002cea0 void dAcBase_c::unkVirtFunc_0x60() { return; } -bool dAcBase_c::restorePosRotFromCopy() {} -u32 dAcBase_c::itemDroppingAndGivingRelated(Vec3f *spawnPos, int subtype) {} -void dAcBase_c::fillUpperParams2Byte() {} -u32 dAcBase_c::getParams2_ignoreLower() {} -void dAcBase_c::setParams2Upper_ignoreLower(u32 val) {} -u8 dAcBase_c::getParams2UpperByte() {} -void dAcBase_c::setParams2UpperByte(u32 val) {} -u32 dAcBase_c::buildParams2(u32 lower, u8 upper) {} -u32 dAcBase_c::getParams2Lower() {} -dAcBase_c *dAcBase_c::findActor(char *objName, dAcBase_c *parent) {} -// searches for actor based on groupType -dAcBase_c *dAcBase_c::searchActor(dAcBase_c &optionalParent) {} -void dAcBase_c::forEachActor(void *, dAcBase_c &) {} -mAng dAcBase_c::getXZAngleToPlayer() {} -bool dAcBase_c::getDistanceToActor(dAcBase_c &actor, f32 distThresh, f32 *outDist) {} -bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c &actor, f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, - s16 *outDiffAngleY, s16 *outDiffAngleX) {} -bool dAcBase_c::isWithinPlayerRadius(f32 radius) {} -bool dAcBase_c::getDistanceAndAngleToPlayer(f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, - s16 *outDiffAngleX) { - // return getDistanceAndAngleToActor(PLAYER, distThresh, yAngle, xAngle, outDist, outDiffAngleY, outDiffAngleX); +// 8002ceb0 +// loads f2 before f0 instead of f0 then f2 +bool dAcBase_c::restorePosRotFromCopy() { + if (roomid != room_id_copy) { + return 0; + } + position = pos_copy; + rotation = rot_copy; + return 1; } -f32 dAcBase_c::getDistToPlayer() {} -f32 dAcBase_c::getSquareDistToPlayer() {} -void dAcBase_c::updateRoomId(f32 yOffs) {} -bool dAcBase_c::isRoomFlags_0x6_Set() {} +// 8002cf10 +u32 dAcBase_c::itemDroppingAndGivingRelated(mVec3_c *spawnPos, int subtype) { + if (ScGame::currentSpawnInfo.trial == 1) { + return 0; + } + + if (spawnPos == nullptr) { + spawnPos = &position; + } + + u32 param2Copy = params2; + params2 = param2Copy | 0xFF000000; + // mAng3_c rot = {}; + s16 rot = 0; + return SpecialItemDropMgr::giveSpecialDropItem(SpecialItemDropMgr::sInstance, param2Copy >> 0x18, roomid, spawnPos, subtype, &rot, -1); +} + +// 8002cf90 +void dAcBase_c::fillUpperParams2Byte() { + params2 |= 0xFF000000; +} + +// 8002cfa0 +u32 dAcBase_c::getParams2_ignoreLower() { + return params2 | 0xFFFF; +} + +// 8002cfb0 +void dAcBase_c::setParams2Upper_ignoreLower(u32 val) { + params2 = val | 0xFFFF; +} + +// 8002cfc0 +u8 dAcBase_c::getParams2UpperByte() { + return params2 >> 0x18; +} + +// 8002cfd0 +void dAcBase_c::setParams2UpperByte(u32 val) { + params2 = (params2 & 0xFFFFFF) | val << 0x18; +} + +// 8002cff0 +u32 dAcBase_c::buildParams2(u32 lower, u32 upper) { + return ((upper & 0xFFFF) | 0xFFFF0000) & ((lower << 0x18) | 0xFFFFFF); +} + +// 8002d010 +u32 dAcBase_c::getParams2Lower() { + return params2 & 0xFFFF; +} + +// 8002d020 +dAcBase_c *dAcBase_c::findActor(char *objName, dAcBase_c *parent) { + ObjInfo *objInfo = getObjByActorName_unkNamespace(objName); + if (objInfo == nullptr) { + return nullptr; + } else { + do { + parent = (dAcBase_c *)fManager_c::searchBaseByProfName(objInfo->obj_id, parent); + if (parent == nullptr) { + break; + } + } while (parent->actor_subtype != objInfo->subtype); + } + return parent; +} + +// searches for actor based on groupType +// 8002d0a0 +dAcBase_c *dAcBase_c::searchActor(dAcBase_c *parent) { + dAcBase_c *foundActor = nullptr; + + if (parent == nullptr) { + foundActor = (dAcBase_c *)fManager_c::searchBaseByGroupType(ACTOR, nullptr); + } else if (parent->group_type == 2) { + foundActor = (dAcBase_c *)fManager_c::searchBaseByGroupType(ACTOR, parent); + parent = foundActor; + } + + if (foundActor == nullptr) { + return (dAcBase_c *)fManager_c::searchBaseByGroupType(STAGE, parent); + } + + return foundActor; +} + +// 8002d130 +void dAcBase_c::forEveryActor(void *func(dAcBase_c *, dAcBase_c *), dAcBase_c *parent) { + dAcBase_c *foundActor = searchActor(nullptr); + + while (foundActor != nullptr) { + dAcBase_c *nextActor = (dAcBase_c *)func(foundActor, parent); + foundActor = searchActor(nextActor); + } +} + +// 8002d190 +void dAcBase_c::getXZAngleToPlayer(s16 *angle) { + *angle = targetAngleY(&this->position, &dPlayer::LINK->position); +} + +// The "distSquared > dist" bit is misbehaving. +// Trying different operators doesn't work so I'm leaving it as the most simple wrong choice. +// 8002d1d0 +bool dAcBase_c::getDistanceToActor(dAcBase_c *actor, f32 distThresh, f32 *outDist) { + f32 distSquared = 3.402823e+38; + bool isWithinThreshhold = false; + + if (actor != nullptr) { + distSquared = PSVECSquareDistance(position, actor->position); + + if (distSquared <= distThresh*distThresh) { + isWithinThreshhold = true; + } + } + + if (outDist != nullptr) { + f32 dist = 0.0; + // TODO: make this not sad :( + if (distSquared <= dist) { + dist = nw4r::math::FrSqrt(distSquared) * distSquared; + } + *outDist = dist; + } + return isWithinThreshhold; +} + +// Similar weirdness as the above function. Also, r29->31 are initted in the wrong order? +// 8002d290 +bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, s16 *outDiffAngleX) { + f32 distSquared = 3.402823e+38; + s16 angleToActorY = 0; + s16 angleToActorX = 0; + bool isWithinRange = false; + + if (actor != nullptr) { + distSquared = PSVECSquareDistance(position, actor->position); + angleToActorY = targetAngleY(&position, &actor->position); + angleToActorX = targetAngleX(&position, &actor->position); + + if ((distSquared <= distThresh*distThresh) + && (labs(rotation.y - angleToActorY) <= yAngle) + && (labs(rotation.x - angleToActorX) <= xAngle) + ) { + isWithinRange = true; + } + } + + if (outDist != nullptr) { + f32 dist = 0.0; + if (distSquared <= dist) { + dist = nw4r::math::FrSqrt(distSquared); + dist *= distSquared; + } + *outDist = dist; + } + + if (outDiffAngleY != nullptr) { + *outDiffAngleY = angleToActorY; + } + + if (outDiffAngleX != nullptr) { + *outDiffAngleX = angleToActorX; + } + + return isWithinRange; +} + +// Very notmatching +// 8002d3e0 +bool dAcBase_c::isWithinPlayerRadius(f32 radius) { + f32 zDist = position.z - dPlayer::LINK->position.z; + f32 xDist = position.x - dPlayer::LINK->position.x; + return (xDist*xDist + zDist*zDist) < radius*radius; +} + +// 8002d440 +bool dAcBase_c::getDistanceAndAngleToPlayer(f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, s16 *outDiffAngleX) { + return getDistanceAndAngleToActor(dPlayer::LINK, distThresh, yAngle, xAngle, outDist, outDiffAngleY, outDiffAngleX); +} + +// 8002d470 +f32 dAcBase_c::getDistToPlayer() { + return EGG::Math::sqrt(PSVECSquareDistance(position, dPlayer::LINK->position)); +} + +// 8002d4a0 +f32 dAcBase_c::getSquareDistToPlayer() { + return PSVECSquareDistance(position, dPlayer::LINK->position); +} + +// Some weirdness with the float registers being used +// 8002d4b0 +void dAcBase_c::updateRoomId(f32 yOffset) { + if (getConnectParent()->profile_name != 701 /* fProfile::PROFILE_NAME_e::ROOM */) { + mVec3_c actorPos; + actorPos.x = position.x; + actorPos.y = position.y + yOffset; + actorPos.z = position.z; + + if (checkCollision(&actorPos)) { + roomid = collisionCheckGetRoom(); + } else { + roomid = RoomManager::m_Instance->curr_room_id; + } + } +} + +// 8002d540 +bool dAcBase_c::isRoomFlags_0x6_Set() { + dRoom *room = getRoomByIndex(RoomManager::m_Instance, roomid); + return (room->flags & 6) != 0; +} + +// Start of SoundSource stuff void dAcBase_c::FUN_8002d590() {} void dAcBase_c::FUN_8002d5b0() {} void dAcBase_c::playSound() {} @@ -215,31 +463,168 @@ void dAcBase_c::FUN_8002d7f0() {} void dAcBase_c::FUN_8002d810() {} void dAcBase_c::FUN_8002d830() {} void dAcBase_c::FUN_8002d860() {} -void dAcBase_c::FUN_8002d880() {} + +// 8002d880 +SoundSource *dAcBase_c::getSoundSource() { + return sound_source; +} +// End of SoundSource stuff + // first param is not dAcBase_c +// 8002d890 void dAcBase_c::FUN_8002d890() {} + // current name is Global__setActorRef -void dAcBase_c::setActorRef(dBase_c *) {} +void dAcBase_c::setActorRef(dBase_c *ref) { + actor_node.link(ref); +} + // May not be only purpose -void dAcBase_c::setUnkFlag() {} -void dAcBase_c::FUN_8002d940() {} -void dAcBase_c::FUN_8002d960() {} +void dAcBase_c::setEnemyDefeatFlag() { + EnemyDefeatManager::sInstance->setFlag(obj_id); +} + +// 8002d940 +void dAcBase_c::changeLoadedEntitiesWithSet() { + RoomManager::m_Instance->changeLoadedEntities(RoomManager::m_Instance, obj_id, true); +} + +// 8002d960 +void dAcBase_c::changeLoadedEntitiesNoSet() { + RoomManager::m_Instance->changeLoadedEntities(RoomManager::m_Instance, obj_id, false); +} // spawns GroupType2 (ACTOR) -dAcBase_c dAcBase_c::createActor(ProfileName actorId, u32 params1, Vec3f *pos, Vec3s *rot, Vec3f *scale, u32 params2, - s32 roomId, dBase_c *ref) {} +// 8002d980 +dAcBase_c *dAcBase_c::createActor(ProfileName actorId, u32 actorParams1, mVec3_c *actorPosition, mAng3_c *actorRotation, mVec3_c *actorScale, u32 actorParams2, s32 actorRoomid, dBase_c *actorRef) { + if (actorPosition == nullptr) { + actorPosition = &position; + } -dAcBase_c dAcBase_c::createActorUnkGroup3(ProfileName actorId, u32 params1, Vec3f *pos, Vec3s *rot, Vec3f *scale, - u32 params2, s32 roomId, dBase_c *ref) {} + if (actorRotation == nullptr) { + actorRotation = &rotation; + } + if (actorScale == nullptr) { + actorScale = &scale; + } + + if (actorRoomid == 63) { + actorRoomid = roomid; + } + + u32 newParams2 = -1; + if (actorParams2 != 0) { + newParams2 = getParams2_ignoreLower(); + } + + setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, 0xFF, nullptr); + dBase_c *room = RoomManager::getRoom(roomid); + return (dAcBase_c *)dBase_c::createBase(actorId, room, actorParams1, ACTOR); +} + +// spawns GroupType2 (STAGE) +// 8002da80 +dAcBase_c *dAcBase_c::createActorStage(ProfileName actorId, u32 actorParams1, mVec3_c *actorPosition, mAng3_c *actorRotation, mVec3_c *actorScale, u32 actorParams2, s32 actorRoomid, dBase_c *actorRef) { + if (actorPosition == nullptr) { + actorPosition = &position; + } + + if (actorRotation == nullptr) { + actorRotation = &rotation; + } + + if (actorScale == nullptr) { + actorScale = &scale; + } + + if (actorRoomid == 63) { + actorRoomid = roomid; + } + + u32 newParams2 = -1; + if (actorParams2 != 0) { + newParams2 = getParams2_ignoreLower(); + } + + setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, 0xFF, nullptr); + dBase_c *room = RoomManager::getRoom(roomid); + return (dAcBase_c *)dBase_c::createBase(actorId, room, actorParams1, STAGE); +} + +// 8002db80 void *dAcBase_c::getCurrentEventActor() {} + +// 8002db90 void dAcBase_c::unkVirtFunc_0x6C() {} -void dAcBase_c::doInteraction(s32) {} -void dAcBase_c::FUN_8002dc20(s16 *, s16 *) {} -void dAcBase_c::incrementKillCounter() {} -void dAcBase_c::FUN_8002dcd0() {} -void dAcBase_c::FUN_8002dd10() {} -void dAcBase_c::FUN_8002dd50() {} -void dAcBase_c::FUN_8002dd90() {} -void dAcBase_c::FUN_8002ddd0() {} -void dAcBase_c::FUN_8002de30() {} + +// 8002dba0 +void dAcBase_c::doInteraction(s32 param) { + if (param == 4 || param == 5 || param == 12) { + Event *event = &Event("DefaultTalk", 400, 0x100001, nullptr, nullptr); + alsoSetAsCurrentEvent(this, event, nullptr); + event->~Event(); + } +} + +// Only called by dPlayer::dig and that function fails to decomp in ghidra? +// 8002dc20 +void dAcBase_c::FUN_8002dc20(s16 *, s16 *) { + +} + +// This whole function gets compiled to just a `blr` +// Not sure how to make this work as expected +// 8002dc50 +void dAcBase_c::incrementKillCounter() { + dAcObjBase_c *object = (dAcObjBase_c *)this; // Probably wrong + + FileManager *fileMgr = FileManager::sInstance; + + if (group_type == ACTOR && object->unkByteTargetFiRelated == 1) { + s16 killCounterId = object->targetFiTextId; + + if (killCounterId < 91 && killCounterId & 0x300 == 0) { + s16 killCount = fileMgr->getEnemyKillCount(killCounterId & 0xFF); + fileMgr->setEnemyKillCount(killCounterId, killCount); + } + } +} + +// 8002dcd0 +void dAcBase_c::FUN_8002dcd0() { + fillUpperParams2Byte(); + fBase_c::deleteRequest(); + incrementKillCounter(); +} + +// 8002dd10 +void dAcBase_c::FUN_8002dd10() { + setEnemyDefeatFlag(); + fBase_c::deleteRequest(); + incrementKillCounter(); +} + +// 8002dd50 +void dAcBase_c::FUN_8002dd50() { + fillUpperParams2Byte(); + FUN_8002dd10(); +} + +// 8002dd90 +void dAcBase_c::FUN_8002dd90() { + fillUpperParams2Byte(); + setEnemyDefeatFlag(); + fBase_c::deleteRequest(); +} + +// Some collision related thing +// 8002ddd0 +void dAcBase_c::FUN_8002ddd0() { + +} + +// 8002de30 +void dAcBase_c::FUN_8002de30() { + FUN_8002ddd0(); +} diff --git a/src/d/d_player.cpp b/src/d/d_player.cpp new file mode 100644 index 00000000..a2aebf0c --- /dev/null +++ b/src/d/d_player.cpp @@ -0,0 +1,3 @@ +#include "d/d_player.h"; + +dPlayer* dPlayer::LINK; diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 84bd84b4..d027a931 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -211,7 +211,7 @@ inline void strnsth(char *dest, const char *src, size_t max_len) { /* 8000BA70 */ void FileManager::setBeaconPos(u32 beaconArea, u32 beaconNum, mVec3_c *pos) {} /* 8000BB80 */ mVec3_c *FileManager::getBeaconPos(u32 beaconArea, u32 beaconNum) {} /* 8000BC70 */ void FileManager::setEnemyKillCount(u32 enemy, u16 killCount) {} -/* 8000BCE0 */ u16 FileManager::getEnemyKillCount(u32 enemy) {} +/* 8000BCE0 */ s16 FileManager::getEnemyKillCount(u32 enemy) {} /* 8000BD60 */ void FileManager::setHitCountFromEnemy(u32 enemy, u16 hitCount) {} /* 8000BDD0 */ u16 FileManager::getHitCountFromEnemy(u32 enemy) {} diff --git a/src/toBeSorted/misc_flag_managers.cpp b/src/toBeSorted/misc_flag_managers.cpp index a3e8f264..1d941aa2 100644 --- a/src/toBeSorted/misc_flag_managers.cpp +++ b/src/toBeSorted/misc_flag_managers.cpp @@ -1,26 +1,10 @@ #include #include +#include #include #include #include -class CommittableFlagManager { -public: - bool mNeedsCommit; - - virtual void doCommit() = 0; - bool commitIfNecessary(); - void setNeedsCommit(bool commit) { - mNeedsCommit = commit; - } - CommittableFlagManager() { - mNeedsCommit = false; - } - CommittableFlagManager(bool commit) { - mNeedsCommit = commit; - } -}; - /* 0x800BE7B0 */ bool CommittableFlagManager::commitIfNecessary() { if (mNeedsCommit) { @@ -32,31 +16,6 @@ bool CommittableFlagManager::commitIfNecessary() { } } -class TBoxFlagManager : public CommittableFlagManager { -public: - FlagSpace mFlagSpace; - u16 mSceneIndex; - BitwiseFlagHelper mFlagHelper; - - static u16 sTBoxFlags[2]; - - static TBoxFlagManager *sInstance; - - virtual void doCommit() override; - bool checkUncommittedFlag(u16 flag); - TBoxFlagManager(); - virtual ~TBoxFlagManager() {} - void init(); - void copyFromSave(s16 sceneIndex); - bool checkFlag(u16 sceneIndex, u16 flag); - virtual u16 getFlagCount() const; - void setFlag(u16 flag); - bool checkUncommittedFlag(u16 sceneIndex, u16 flag); - u16 checkUncommittedFlag2(u16 flag) { - return checkUncommittedFlag(flag); - } -}; - TBoxFlagManager *TBoxFlagManager::sInstance = nullptr; u16 TBoxFlagManager::sTBoxFlags[2] = {}; @@ -108,35 +67,6 @@ void TBoxFlagManager::setFlag(u16 flag) { } } -// NOTE: Not actually Enemy Defeat. -// This is a little more than that, it keeps track of live objects based on their id as a whole -class EnemyDefeatManager : public CommittableFlagManager { -public: - FlagSpace mFlagSpace; - BitwiseFlagHelper mFlagHelper; - u16 mSceneIndex; - - static u16 sEnemyDefeatFlags[4096]; - - static EnemyDefeatManager *sInstance; - - void clearSavedFlags(); - bool checkUncommittedFlag(u16 flag); - u16 checkUncommittedFlag2(u16 flag) { - return checkUncommittedFlag(flag); - } - EnemyDefeatManager(); - void init(); - void copyFromSave(u16 sceneIndex); - void updateFlagIndex(u16 sceneIndex); - void clearAll(); - bool checkIsValidFlag(u16 flag); - bool checkFlag(u16 flag); - virtual ~EnemyDefeatManager() {} - virtual u16 getFlagCount() const; - void setFlag(u16 flag); -}; - EnemyDefeatManager *EnemyDefeatManager::sInstance = nullptr; u16 EnemyDefeatManager::sEnemyDefeatFlags[4096] = {}; diff --git a/src/toBeSorted/scgame.cpp b/src/toBeSorted/scgame.cpp new file mode 100644 index 00000000..47c8875e --- /dev/null +++ b/src/toBeSorted/scgame.cpp @@ -0,0 +1,5 @@ +#include "toBeSorted/scgame.h" + +SpawnInfo ScGame::currentSpawnInfo = {}; +SpawnInfo ScGame::nextSpawnInfo = {}; +ScGame* ScGame::sInstance = nullptr; diff --git a/src/toBeSorted/special_item_drop_mgr.cpp b/src/toBeSorted/special_item_drop_mgr.cpp new file mode 100644 index 00000000..b73b8839 --- /dev/null +++ b/src/toBeSorted/special_item_drop_mgr.cpp @@ -0,0 +1,114 @@ +#include "m/m_vec.h" +#include "m/m_Angle.h" +#include "d/d_player.h" +#include "toBeSorted/special_item_drop_mgr.h" + +SpecialItemDropMgr* SpecialItemDropMgr::sInstance = nullptr; + +extern "C" short targetAngleY(mVec3_c *, mVec3_c *); +extern "C" int rndInt(int); +extern "C" void spawnItem1(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem2(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem3(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem4(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem5(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem6(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem7(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem8(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); +extern "C" void spawnItem9(s16 itemid, u32 roomid, mVec3_c *pos, mAng3_c *rot, u32 param2, u32 unk); + +// 800c7b80 +SpecialItemDropMgr::SpecialItemDropMgr() { + SpecialItemDropMgr::sInstance = this; +} + +// TODO: Convert to enum once work on items has started +int SPECIAL_ITEM_ARRAY[28] = {0, 6, 6, 2, 3, 4, 0x2b, 0x28, 0x29, 7, 8, 0x39, 0, 0, 0x1c, 0xa5, 58, 59, 183, 184, 185, 72, 72, 1, 34, 0, 0, 0}; +int RAND_RUPEE_ARRAY[4] = {2, 3, 4, 0}; + +// 800c7bb0 +int fn_800C7BB0(SpecialItemDropMgr *mgr, int specialItemId) {} + +// 800c7d00 +short fn_800C7D00(SpecialItemDropMgr *mgr, int specialItemId) {} + +// 800c7d20 +short fn_800C7D20(SpecialItemDropMgr *mgr, int specialItemId) {} + +// 800c7d40 +int giveSpecialDropItem(SpecialItemDropMgr *mgr, int specialItemId, int roomid, mVec3_c *pos, int subtype, s16 *rot, s32 unused) {} + +// 800c7ef0 +// Very unmatching. Just here as a starting point +bool spawnSpecialDropItem(SpecialItemDropMgr *mgr, int specialItemId, int roomid, mVec3_c *pos, int subtype, s16 *rot) { + u32 unk = fn_800C7BB0(mgr, specialItemId); + if (unk == 0) { + return false; + } + + s8 itemCount = 1; + if (unk == 2) { + itemCount = 3; + } else if (unk == 12) { + itemCount = 10; + } else if (unk == 13) { + itemCount = 5; + } else if (unk == 22) { + itemCount = 2; + } + + s16 currentRot; + s16 tempOther; + u16 itemid = SPECIAL_ITEM_ARRAY[unk]; + mAng3_c itemRot = {0, 0, 0}; + + if (subtype == 2 || subtype == 6) { + currentRot = *rot; + tempOther = -0xe39; + } else { + currentRot = targetAngleY(&(dPlayer::LINK->position), pos); + tempOther = -0x8000; + currentRot += 0x4000; + } + s16 angleDecrement = tempOther / itemCount; + tempOther = angleDecrement / 2; + currentRot += tempOther; + tempOther /= 2; + + for (s8 currentItemIndex = 0; currentItemIndex < itemCount; currentItemIndex++) { + s16 out; + SpecialItemDropMgr::fn_800C81D0(out, tempOther, -tempOther); + + itemRot.y = currentRot + out; + if (unk < 15) { + itemid = RAND_RUPEE_ARRAY[rndInt(3)]; + spawnItem1(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else if (subtype == 2) { + spawnItem2(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else { + if (subtype == 1) { + spawnItem3(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else if (subtype == 4) { + spawnItem4(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else if (subtype == 3) { + spawnItem5(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else if (subtype == 5) { + spawnItem6(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else if (subtype == 6) { + spawnItem7(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else if (subtype == 7) { + spawnItem8(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } else { + spawnItem9(itemid, roomid, pos, &itemRot, 0xFFFFFFFF, 0); + } + } + currentRot -= angleDecrement; + } + return true; +} + +// 800c81d0 +void fn_800C81D0(s16, s16, s16) {}; + +// 800c8270 +SpecialItemDropMgr::~SpecialItemDropMgr() {} From b2d728089e500e463d7596867ba11e34cf6586f0 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 24 May 2024 16:41:33 +0200 Subject: [PATCH 03/11] db_mapFile --- config/SOUE01/splits.txt | 7 + config/SOUE01/symbols.txt | 20 +- configure.py | 1 + include/DynamicLink.h | 11 +- include/MSL_C/MSL_Common/Src/printf.h | 4 +- include/nw4r/db/db_mapFile.h | 26 ++ include/rvl/OS/OSLink.h | 1 + src/DynamicLink.cpp | 24 +- src/egg/prim/eggAssert.cpp | 11 +- src/nw4r/db/db_mapFile.cpp | 343 ++++++++++++++++++++++++++ 10 files changed, 403 insertions(+), 45 deletions(-) create mode 100644 include/nw4r/db/db_mapFile.h create mode 100644 src/nw4r/db/db_mapFile.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 5dbd2c35..c4892f16 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -338,6 +338,13 @@ nw4r/db/db_directPrint.cpp: .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 +nw4r/db/db_mapFile.cpp: + .text start:0x80436A50 end:0x804373B4 + .data start:0x8056C5F0 end:0x8056C600 + .sdata start:0x80574E10 end:0x80574E24 + .sbss start:0x80576600 end:0x8057660C + .bss start:0x8063B320 end:0x8063B560 + nw4r/db/db_assert.cpp: .text start:0x804373C0 end:0x804373D0 .sbss start:0x80576610 end:0x80576618 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 30c5841e..430c679a 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -21975,7 +21975,7 @@ OSLinkFixed = .text:0x803A9AF0; // type:function size:0x1C fn_803A9B10 = .text:0x803A9B10; // type:function size:0x240 OSUnlink = .text:0x803A9D50; // type:function size:0x1D4 __OSModuleInit = .text:0x803A9F30; // type:function size:0x18 scope:global -fn_803A9F50 = .text:0x803A9F50; // type:function size:0xA4 +OSSearchModule = .text:0x803A9F50; // type:function size:0xA4 OSInitMessageQueue = .text:0x803AA000; // type:function size:0x60 OSSendMessage = .text:0x803AA060; // type:function size:0xC8 OSReceiveMessage = .text:0x803AA130; // type:function size:0xDC @@ -24179,10 +24179,10 @@ GetCharOnMem___Q24nw4r2dbFPCUc = .text:0x80436B40; // type:function size:0x8 GetCharOnDvd___Q24nw4r2dbFPCUc = .text:0x80436B50; // type:function size:0xFC SearchParam___Q24nw4r2dbFPUcUlUc = .text:0x80436C50; // type:function size:0xC4 XStrToU32___Q24nw4r2dbFPCUc = .text:0x80436D20; // type:function size:0xCC -CopySymbol___Q24nw4r2dbFPCUcPUcUlUc = .text:0x80436DF0; // type:function size:0x2DC -QuerySymbolToMapFile___Q24nw4r2dbFPUcPC12OSModuleInfoUlPUcUl = .text:0x804370D0; // type:function size:0xD8 +QuerySymbolToMapFile___Q24nw4r2dbFPUcPC12OSModuleInfoUlPUcUl = .text:0x80436DF0; // type:function size:0x2DC +UnkFunction___Q24nw4r2dbFPC12OSModuleInfoUlPUcUl = .text:0x804370D0; // type:function size:0xD8 QuerySymbolToSingleMapFile___Q24nw4r2dbFPQ34nw4r2db7MapFileUlPUcUl = .text:0x804371B0; // type:function size:0xF8 -MapFile_QuerySymbol__Q24nw4r2dbFPvPcUl = .text:0x804372B0; // type:function size:0x104 +MapFile_QuerySymbol__Q24nw4r2dbFUlPUcUl = .text:0x804372B0; // type:function size:0x104 Assertion_SetConsole__Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHead = .text:0x804373C0; // type:function size:0x10 FExp__Q34nw4r4math6detailFf = .text:0x804373D0; // type:function size:0xAC FLog__Q34nw4r4math6detailFf = .text:0x80437480; // type:function size:0xA4 @@ -36971,7 +36971,7 @@ lbl_8056C0B4 = .data:0x8056C0B4; // type:object size:0xC data:string lbl_8056C0C0 = .data:0x8056C0C0; // type:object size:0x14 lbl_8056C0D4 = .data:0x8056C0D4; // type:object size:0x14 lbl_8056C0E8 = .data:0x8056C0E8; // type:object size:0x508 -lbl_8056C5F0 = .data:0x8056C5F0; // type:object size:0x10 +lbl_8056C5F0 = .data:0x8056C5F0; // type:object size:0xD data:string lbl_8056C600 = .data:0x8056C600; // type:object size:0x108 lbl_8056C708 = .data:0x8056C708; // type:object size:0x808 lbl_8056CF10 = .data:0x8056CF10; // type:object size:0x110 @@ -39563,7 +39563,7 @@ lbl_80574E08 = .sdata:0x80574E08; // type:object size:0x8 lbl_80574E10 = .sdata:0x80574E10; // type:object size:0x4 data:4byte lbl_80574E14 = .sdata:0x80574E14; // type:object size:0x4 data:4byte lbl_80574E18 = .sdata:0x80574E18; // type:object size:0x4 data:4byte -lbl_80574E1C = .sdata:0x80574E1C; // type:object size:0xC +lbl_80574E1C = .sdata:0x80574E1C; // type:object size:0x5 data:string lbl_80574E28 = .sdata:0x80574E28; // type:object size:0x8 data:float lbl_80574E30 = .sdata:0x80574E30; // type:object size:0x8 data:string lbl_80574E38 = .sdata:0x80574E38; // type:object size:0x8 @@ -40835,9 +40835,9 @@ sInitialized__Q24nw4r2db = .sbss:0x805765E8; // type:object size:0x4 scope:local lbl_805765F0 = .sbss:0x805765F0; // type:object size:0x4 data:4byte lbl_805765F4 = .sbss:0x805765F4; // type:object size:0x1 data:byte lbl_805765F8 = .sbss:0x805765F8; // type:object size:0x8 -lbl_80576600 = .sbss:0x80576600; // type:object size:0x4 data:4byte -lbl_80576604 = .sbss:0x80576604; // type:object size:0x4 data:4byte -lbl_80576608 = .sbss:0x80576608; // type:object size:0x8 data:4byte +sFileLength__Q24nw4r2db = .sbss:0x80576600; // type:object size:0x4 scope:local data:4byte +sMapFileList__Q24nw4r2db = .sbss:0x80576604; // type:object size:0x4 scope:local data:4byte +GetCharPtr___Q24nw4r2db = .sbss:0x80576608; // type:object size:0x4 scope:local data:4byte sConsoleHandle__Q24nw4r2db = .sbss:0x80576610; // type:object size:0x4 scope:local data:4byte lbl_80576618 = .sbss:0x80576618; // type:object size:0x4 data:4byte lbl_8057661C = .sbss:0x8057661C; // type:object size:0x4 data:4byte @@ -49311,7 +49311,7 @@ lbl_80636BC0 = .bss:0x80636BC0; // type:object size:0x400 lbl_80636FC0 = .bss:0x80636FC0; // type:object size:0x360 lbl_80637320 = .bss:0x80637320; // type:object size:0x4000 lbl_8063B320 = .bss:0x8063B320; // type:object size:0x200 -lbl_8063B520 = .bss:0x8063B520; // type:object size:0x40 +lbl_8063B520 = .bss:0x8063B520; // type:object size:0x3C lbl_8063B560 = .bss:0x8063B560; // type:object size:0x300 lbl_8063B860 = .bss:0x8063B860; // type:object size:0x140 lbl_8063B9A0 = .bss:0x8063B9A0; // type:object size:0xC data:byte diff --git a/configure.py b/configure.py index 8ee3f7e1..7a62a83e 100644 --- a/configure.py +++ b/configure.py @@ -329,6 +329,7 @@ config.libs = [ [ Object(Matching, "nw4r/db/db_assert.cpp"), Object(Matching, "nw4r/db/db_directPrint.cpp"), + Object(Matching, "nw4r/db/db_mapFile.cpp"), ], ), nw4rLib( diff --git a/include/DynamicLink.h b/include/DynamicLink.h index 1e9e3319..da4a5a21 100644 --- a/include/DynamicLink.h +++ b/include/DynamicLink.h @@ -3,17 +3,19 @@ #include #include +#include #include class DbMapFile { public: - DbMapFile(): unk_0(0) {} + DbMapFile(): mMapFileHandle(nullptr) {} ~DbMapFile(); void RegisterOnDvd(const char *, const OSModuleInfo *); void Unregister(); private: - UNKWORD unk_0; + nw4r::db::MapFileHandle mMapFileHandle; + nw4r::db::MapFile mMapFile; }; // https://github.com/zeldaret/tp/blob/main/include/DynamicLink.h @@ -75,11 +77,6 @@ struct DynamicModuleControl : DynamicModuleControlBase { /* 0x2C */ mDvd_callback_c *mDvdCallbackRequest; /* 0x30 */ EGG::ExpHeap *mHeap; /* 0x34 */ DbMapFile mpRelMapFile; - // Some of these might be members of DbMapFile - UNKWORD unk1; - UNKWORD unk2; - UNKWORD unk3; - UNKWORD unk4; static u32 sAllocBytes; static mDvd_toMainRam_base_c *sDvdFile; diff --git a/include/MSL_C/MSL_Common/Src/printf.h b/include/MSL_C/MSL_Common/Src/printf.h index 5b1a7ccd..5e35c0f4 100644 --- a/include/MSL_C/MSL_Common/Src/printf.h +++ b/include/MSL_C/MSL_Common/Src/printf.h @@ -10,8 +10,8 @@ extern "C" { int fprintf(FILE* stream, const char* format, ...); int printf(const char* format, ...); -int sprintf(const char* str, const char* format, ...); -int snprintf(const char* str, size_t n, const char* format, ...); +int sprintf(char* str, const char* format, ...); +int snprintf(char* str, size_t n, const char* format, ...); int vsnprintf(char* str, size_t n, const char* format, va_list arg); int vprintf(const char* format, va_list arg); diff --git a/include/nw4r/db/db_mapFile.h b/include/nw4r/db/db_mapFile.h new file mode 100644 index 00000000..2eb2aac6 --- /dev/null +++ b/include/nw4r/db/db_mapFile.h @@ -0,0 +1,26 @@ +#ifndef DB_MAPFILE_H +#define DB_MAPFILE_H + +#include + +namespace nw4r { +namespace db { + +typedef struct MapFile { + u8 *mapBuf; + const OSModuleInfo *moduleInfo; + s32 fileEntry; + MapFile *next; +} MapFile; + +typedef MapFile* MapFileHandle; + +MapFileHandle MapFile_RegistOnDvd(void*, const char*, const OSModuleInfo*); +void MapFile_Unregist(MapFileHandle); +void MapFile_UnregistAll(); +bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize); + +} // namespace db +} // namespace nw4r + +#endif diff --git a/include/rvl/OS/OSLink.h b/include/rvl/OS/OSLink.h index 8f6df8b0..0bc13dc3 100644 --- a/include/rvl/OS/OSLink.h +++ b/include/rvl/OS/OSLink.h @@ -105,6 +105,7 @@ BOOL OSLinkFixed(OSModuleInfo* newModule, void* bss); BOOL OSUnlink(OSModuleInfo* module); void OSSetStringTable(void* string_table); void __OSModuleInit(void); +OSModuleInfo* OSSearchModule(void* ptr, u32* section, u32* offset); #ifdef __cplusplus }; diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index 2c7947c0..ec9fd045 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -320,35 +320,25 @@ const char *DynamicModuleControl::getModuleTypeString() const { } DbMapFile::~DbMapFile() { - if (unk_0) { + if (mMapFileHandle != nullptr) { Unregister(); } } -namespace nw4r { -namespace db { -// TODO -typedef struct MapFile { -} MapFile; -extern MapFile *MapFile_RegistOnDvd(void *arg, const char *buf, const OSModuleInfo *info); -extern void *MapFile_Unregist(MapFile *); -} // namespace db -} // namespace nw4r - void DbMapFile::RegisterOnDvd(const char *path, const OSModuleInfo *info) { if (mDvd::IsExistPath(path)) { - unk_0 = (UNKWORD)nw4r::db::MapFile_RegistOnDvd(((int *)this) + 1, path, info); + mMapFileHandle = nw4r::db::MapFile_RegistOnDvd(&mMapFile, path, info); } else { - unk_0 = 0xffffffff; + mMapFileHandle = (nw4r::db::MapFileHandle)0xffffffff; } } void DbMapFile::Unregister() { - if (unk_0 != 0) { - if (unk_0 != 0xffffffff) { - nw4r::db::MapFile_Unregist((nw4r::db::MapFile *)unk_0); + if (mMapFileHandle != nullptr) { + if ((u32)mMapFileHandle != 0xffffffff) { + nw4r::db::MapFile_Unregist(mMapFileHandle); } - unk_0 = 0; + mMapFileHandle = nullptr; } } diff --git a/src/egg/prim/eggAssert.cpp b/src/egg/prim/eggAssert.cpp index dc9e44a3..bde46ca9 100644 --- a/src/egg/prim/eggAssert.cpp +++ b/src/egg/prim/eggAssert.cpp @@ -3,18 +3,11 @@ #include #include #include +#include #include #include #include - -namespace nw4r { -namespace db { -// TODO -extern s32 MapFile_QuerySymbol(void *arg, char *buf, u32 buf_size); -} // namespace db -} // namespace nw4r - namespace EGG { namespace Assert { @@ -62,7 +55,7 @@ bool sAssertOccurred; /* 80674c60 */ char buf[260]; /* 8049c100 */ const char *getMapSymbol(void *arg) { - u32 success = nw4r::db::MapFile_QuerySymbol(arg, buf, sizeof(buf)); + bool success = nw4r::db::MapFile_QuerySymbol((u32)arg, (u8*)buf, sizeof(buf)); return success ? buf : nullptr; } diff --git a/src/nw4r/db/db_mapFile.cpp b/src/nw4r/db/db_mapFile.cpp new file mode 100644 index 00000000..d8e0e24b --- /dev/null +++ b/src/nw4r/db/db_mapFile.cpp @@ -0,0 +1,343 @@ +#include +#include +#include +#include + +namespace nw4r { +namespace db { + +static u32 sFileLength; +static MapFile *sMapFileList = nullptr; +static u8 (*GetCharPtr_)(const u8 *) = nullptr; + +static u8 dvdReadBuf[512] ALIGN(32); +static DVDFileInfo sFileInfo; + +s32 unk_80574e10 = 0x200; +u8 *dvdReadPtr = dvdReadBuf; +s32 unk_80574e18 = -1; + +static void MapFile_Append(MapFile *file) { + if (sMapFileList == nullptr) { + sMapFileList = file; + return; + } + + if (file->moduleInfo != nullptr) { + file->next = sMapFileList->next; + sMapFileList->next = file; + } else { + file->next = sMapFileList; + sMapFileList = file; + } +} + +/** 80436a50 */ +MapFileHandle MapFile_RegistOnDvd(void *buf, const char *path, const OSModuleInfo *info) { + MapFile *file = (MapFile *)buf; + file->mapBuf = nullptr; + file->moduleInfo = info; + file->fileEntry = DVDConvertPathToEntrynum(path); + file->next = nullptr; + + MapFile_Append(file); + return file; +} + +/** 80436ae0 */ +void MapFile_Unregist(MapFileHandle file) { + if (file == sMapFileList) { + sMapFileList = sMapFileList->next; + return; + } + + MapFile *cursor = sMapFileList; + for (; cursor != nullptr; cursor = cursor->next) { + if (cursor->next == file) { + cursor->next = file->next; + return; + } + } +} + +/** 80436b30 */ +void MapFile_UnregistAll() { + sMapFileList = nullptr; +} + +/** 80436b40 */ +static u8 GetCharOnMem_(const u8 *arg) { + return *arg; +} + +/** 80436b50 */ +static u8 GetCharOnDvd_(const u8 *arg) { + s32 cleared = (s32)arg & 0x7fffffff; + s32 unoffset = cleared - unk_80574e18; + if (cleared >= sFileLength) { + return 0; + } + + if (unk_80574e18 < 0 || unoffset < 0 || unoffset >= unk_80574e10) { + unk_80574e18 = ROUND_DOWN(cleared, 32); + unoffset = cleared - unk_80574e18; + cleared = unk_80574e10; + if (unk_80574e18 + unk_80574e10 >= sFileLength) { + cleared = ROUND_UP(sFileLength - unk_80574e18, 32); + } + BOOL interrupts = OSEnableInterrupts(); + BOOL read = DVDReadAsyncPrio(&sFileInfo, dvdReadPtr, cleared, unk_80574e18, nullptr, 2); + while (DVDGetCommandBlockStatus(&sFileInfo.block)) {} + + OSRestoreInterrupts(interrupts); + if (read <= 0) { + return 0; + } + } + return *(dvdReadPtr + unoffset); +} + +static u8 *SearchNextLine_(u8 *buf, s32 lines) { + u8 c; + + if (buf == nullptr) { + return nullptr; + } + + while ((c = (GetCharPtr_)(buf)) != '\0') { + if (c == '\n') { + if (--lines <= 0) { + return buf + 1; + } + } + buf++; + } + + return nullptr; +} + +static u8 *SearchNextSection_(u8 *buf) { + do { + buf = SearchNextLine_(buf, 1); + if (buf == nullptr) { + return nullptr; + } + } while ((GetCharPtr_)(buf) != '.'); + return buf; +} + +static u8 *SearchParam_(u8 *lineTop, u32 argNum, u8 splitter) { + bool inArg = false; + u8 *buf = lineTop; + + if (buf == nullptr) { + return nullptr; + } + while (true) { + u8 c = (GetCharPtr_)(buf); + if (c == '\0' || c == '\n') { + return 0; + } + if (inArg) { + if (c == splitter) { + inArg = false; + } + } else if (c != splitter) { + if (argNum-- == 0) { + return buf; + } + inArg = true; + } + buf += 1; + } +} + +static u32 XStrToU32_(const u8 *str) { + u32 val = 0; + + while (true) { + u32 num; + u8 c = (GetCharPtr_)(str); + if ('0' <= c && c <= '9') { + num = c - '0'; + } else if ('a' <= c && c <= 'z') { + num = c - 'a' + 10; + } else if ('A' <= c && c <= 'Z') { + num = c - 'A' + 10; + } else { + return val; + } + + if (val >= 0x10000000) { + return 0; + } + val = num + val * 16; + str++; + } +} + +static u32 CopySymbol_(const u8 *buf, u8 *str, u32 strLenMax, u8 splitter) { + u32 cnt = 0; + + while (true) { + u8 c = (GetCharPtr_)(buf++); + if (c == splitter || c == '\0' || c == '\n') { + *str = '\0'; + return cnt; + } + *str++ = c; + if (++cnt >= strLenMax - 1) { + *str = '\0'; + return cnt; + } + } +} + +bool QuerySymbolToMapFile_(u8 *buf, const OSModuleInfo *moduleInfo, u32 address, u8 *strBuf, u32 strBufSize) { + OSSectionInfo *sectionInfo = nullptr; + u32 sectionCnt; + + if (moduleInfo != nullptr) { + sectionInfo = OSGetSectionInfo(moduleInfo); + sectionCnt = moduleInfo->numSections; + } + + while (true) { + u32 offset = 0; + buf = SearchNextSection_(buf); + buf = SearchNextLine_(buf, 3); + if (sectionInfo != nullptr) { + offset = ROUND_DOWN(sectionInfo->offset, 2); + if (address < offset || address >= offset + sectionInfo->size) { + goto next; + } + } + + while (true) { + u8 *param; + u32 startAddr; + u32 size; + buf = SearchNextLine_(buf, 1); + if (buf == nullptr) { + return false; + } + param = SearchParam_(buf, 1, ' '); + if (param == nullptr) { + goto next; + } + size = XStrToU32_(param); + param = SearchParam_(buf, 2, ' '); + if (param == nullptr) { + goto next; + } + startAddr = XStrToU32_(param); + if (startAddr == 0) { + continue; + } + startAddr += offset; + if (address < startAddr || startAddr + size <= address) { + continue; + } + + param = SearchParam_(buf, 5, ' '); + if (param == nullptr) { + strBuf[0] = '\0'; + return true; + } + if ((GetCharPtr_)(param) == '.') { + continue; + } + + CopySymbol_(param, strBuf, strBufSize, '\t'); + return true; + } + next: + if (sectionInfo != nullptr) { + if (--sectionCnt == 0) { + return 0; + } + sectionInfo++; + } + } +} + +// No idea, doesn't appear in the DWARF +/** 804370d0 */ +bool UnkFunction_(const OSModuleInfo *moduleInfo, u32 address, u8 *strBuf, u32 strBufSize) { + if (moduleInfo == nullptr) { + if (address < (u32)_stack_end) { + snprintf((char *)strBuf, strBufSize, "[%p]", address); + return true; + } else { + return false; + } + } else { + u32 sectionIdx = 0; + OSSectionInfo *sectionInfo = OSGetSectionInfo(moduleInfo); + for (u32 sectionCnt = 0; sectionCnt < moduleInfo->numSections; sectionCnt++) { + u32 offset = ROUND_DOWN(sectionInfo->offset, 2); + if (offset <= address && address < offset + sectionInfo->size) { + snprintf((char *)strBuf, strBufSize, "[%d:%d:%06x]", moduleInfo->id, sectionIdx, address - offset); + return true; + } + sectionInfo++; + sectionIdx++; + } + return false; + } +} + +bool QuerySymbolToSingleMapFile_(MapFileHandle pMapFile, u32 address, u8 *strBuf, u32 strBufSize) { + if (pMapFile->mapBuf != nullptr) { + GetCharPtr_ = GetCharOnMem_; + return QuerySymbolToMapFile_(pMapFile->mapBuf, pMapFile->moduleInfo, address, strBuf, strBufSize); + } else if (pMapFile->fileEntry >= 0) { + u8 *buf = (u8 *)0x80000000; + bool ret; + if (!DVDFastOpen(pMapFile->fileEntry, &sFileInfo)) { + goto err; + } + unk_80574e18 = -1; + sFileLength = sFileInfo.size; + GetCharPtr_ = GetCharOnDvd_; + ret = QuerySymbolToMapFile_(buf, pMapFile->moduleInfo, address, strBuf, strBufSize); + DVDClose(&sFileInfo); + return ret; + } else { + return UnkFunction_(pMapFile->moduleInfo, address, strBuf, strBufSize); + } + +err: + strBuf[0] = '\0'; + return false; +} + +bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize) { + MapFile *pMap = sMapFileList; + if (sMapFileList == nullptr) { + if (address < (u32)_stack_end) { + snprintf((char *)strBuf, strBufSize, "[%p]", address); + return true; + } else { + u32 offset; + u32 section; + OSModuleInfo *info = OSSearchModule((void *)address, §ion, &offset); + if (info) { + snprintf((char *)strBuf, strBufSize, "[%d:%d:%06x]", info->id, section, offset); + return true; + } + return false; + } + } else { + for (; pMap != nullptr; pMap = pMap->next) { + if (QuerySymbolToSingleMapFile_(pMap, address, strBuf, strBufSize)) { + return true; + } + } + + return false; + } +} + +} // namespace db +} // namespace nw4r From 101f0140787220d37dc0b5f29e192ba91a091d28 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Fri, 24 May 2024 18:10:55 -0400 Subject: [PATCH 04/11] cleanup and try to give unk vars a name (roughly based on DWARF) sMapBufMaxSize -> guess sMapBuf -> why is this split?? --- include/nw4r/db/db_assert.h | 14 ++++------- include/nw4r/db/db_console.h | 14 +++++++++++ include/nw4r/db/db_directPrint.h | 4 ++-- include/nw4r/db/db_mapFile.h | 8 +++---- src/nw4r/db/db_mapFile.cpp | 41 ++++++++++++++++---------------- 5 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 include/nw4r/db/db_console.h diff --git a/include/nw4r/db/db_assert.h b/include/nw4r/db/db_assert.h index a7ff8de5..ecc21922 100644 --- a/include/nw4r/db/db_assert.h +++ b/include/nw4r/db/db_assert.h @@ -1,16 +1,12 @@ -#ifndef DB_ASSERT_H -#define DB_ASSERT_H +#ifndef NW4R_DB_ASSERT_H +#define NW4R_DB_ASSERT_H + +#include namespace nw4r { namespace db { -namespace detail { - struct ConsoleHead { - - }; -} - -typedef detail::ConsoleHead* ConsoleHandle; +typedef detail::ConsoleHead *ConsoleHandle; ConsoleHandle Assertion_SetConsole(ConsoleHandle handle); diff --git a/include/nw4r/db/db_console.h b/include/nw4r/db/db_console.h new file mode 100644 index 00000000..90515fb2 --- /dev/null +++ b/include/nw4r/db/db_console.h @@ -0,0 +1,14 @@ +#ifndef NW4R_DB_CONSOLE_H +#define NW4R_DB_CONSOLE_H + +namespace nw4r { +namespace db { + +namespace detail { +struct ConsoleHead {}; +} // namespace detail + +} // namespace db +} // namespace nw4r + +#endif diff --git a/include/nw4r/db/db_directPrint.h b/include/nw4r/db/db_directPrint.h index c3e682ec..cd78ceac 100644 --- a/include/nw4r/db/db_directPrint.h +++ b/include/nw4r/db/db_directPrint.h @@ -1,5 +1,5 @@ -#ifndef DB_DIRECT_PRINT_H -#define DB_DIRECT_PRINT_H +#ifndef NW4R_DB_DIRECT_PRINT_H +#define NW4R_DB_DIRECT_PRINT_H #include #include diff --git a/include/nw4r/db/db_mapFile.h b/include/nw4r/db/db_mapFile.h index 2eb2aac6..1576109f 100644 --- a/include/nw4r/db/db_mapFile.h +++ b/include/nw4r/db/db_mapFile.h @@ -1,5 +1,5 @@ -#ifndef DB_MAPFILE_H -#define DB_MAPFILE_H +#ifndef NW4R_DB_MAPFILE_H +#define NW4R_DB_MAPFILE_H #include @@ -13,9 +13,9 @@ typedef struct MapFile { MapFile *next; } MapFile; -typedef MapFile* MapFileHandle; +typedef MapFile *MapFileHandle; -MapFileHandle MapFile_RegistOnDvd(void*, const char*, const OSModuleInfo*); +MapFileHandle MapFile_RegistOnDvd(void *, const char *, const OSModuleInfo *); void MapFile_Unregist(MapFileHandle); void MapFile_UnregistAll(); bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize); diff --git a/src/nw4r/db/db_mapFile.cpp b/src/nw4r/db/db_mapFile.cpp index d8e0e24b..ad52c4fa 100644 --- a/src/nw4r/db/db_mapFile.cpp +++ b/src/nw4r/db/db_mapFile.cpp @@ -13,9 +13,9 @@ static u8 (*GetCharPtr_)(const u8 *) = nullptr; static u8 dvdReadBuf[512] ALIGN(32); static DVDFileInfo sFileInfo; -s32 unk_80574e10 = 0x200; -u8 *dvdReadPtr = dvdReadBuf; -s32 unk_80574e18 = -1; +static s32 sMapBufMaxSize = 0x200; +static u8 *sMapBuf = dvdReadBuf; +static s32 sMapBufOffset = -1; static void MapFile_Append(MapFile *file) { if (sMapFileList == nullptr) { @@ -71,30 +71,30 @@ static u8 GetCharOnMem_(const u8 *arg) { } /** 80436b50 */ -static u8 GetCharOnDvd_(const u8 *arg) { - s32 cleared = (s32)arg & 0x7fffffff; - s32 unoffset = cleared - unk_80574e18; - if (cleared >= sFileLength) { +static u8 GetCharOnDvd_(const u8 *buf) { + s32 address = (u32)buf & 0x7fffffff; + s32 offset = address - sMapBufOffset; + if (address >= sFileLength) { return 0; } - if (unk_80574e18 < 0 || unoffset < 0 || unoffset >= unk_80574e10) { - unk_80574e18 = ROUND_DOWN(cleared, 32); - unoffset = cleared - unk_80574e18; - cleared = unk_80574e10; - if (unk_80574e18 + unk_80574e10 >= sFileLength) { - cleared = ROUND_UP(sFileLength - unk_80574e18, 32); + if (sMapBufOffset < 0 || offset < 0 || offset >= sMapBufMaxSize) { + sMapBufOffset = ROUND_DOWN(address, 32); + offset = address - sMapBufOffset; + address = sMapBufMaxSize; + if (sMapBufOffset + sMapBufMaxSize >= sFileLength) { + address = ROUND_UP(sFileLength - sMapBufOffset, 32); } - BOOL interrupts = OSEnableInterrupts(); - BOOL read = DVDReadAsyncPrio(&sFileInfo, dvdReadPtr, cleared, unk_80574e18, nullptr, 2); + BOOL enabled = OSEnableInterrupts(); + BOOL read = DVDReadAsyncPrio(&sFileInfo, sMapBuf, address, sMapBufOffset, nullptr, 2); while (DVDGetCommandBlockStatus(&sFileInfo.block)) {} - OSRestoreInterrupts(interrupts); + OSRestoreInterrupts(enabled); if (read <= 0) { return 0; } } - return *(dvdReadPtr + unoffset); + return *(sMapBuf + offset); } static u8 *SearchNextLine_(u8 *buf, s32 lines) { @@ -148,7 +148,7 @@ static u8 *SearchParam_(u8 *lineTop, u32 argNum, u8 splitter) { } inArg = true; } - buf += 1; + buf++; } } @@ -297,7 +297,7 @@ bool QuerySymbolToSingleMapFile_(MapFileHandle pMapFile, u32 address, u8 *strBuf if (!DVDFastOpen(pMapFile->fileEntry, &sFileInfo)) { goto err; } - unk_80574e18 = -1; + sMapBufOffset = -1; sFileLength = sFileInfo.size; GetCharPtr_ = GetCharOnDvd_; ret = QuerySymbolToMapFile_(buf, pMapFile->moduleInfo, address, strBuf, strBufSize); @@ -313,7 +313,6 @@ err: } bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize) { - MapFile *pMap = sMapFileList; if (sMapFileList == nullptr) { if (address < (u32)_stack_end) { snprintf((char *)strBuf, strBufSize, "[%p]", address); @@ -329,7 +328,7 @@ bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize) { return false; } } else { - for (; pMap != nullptr; pMap = pMap->next) { + for (MapFile *pMap = sMapFileList; pMap != nullptr; pMap = pMap->next) { if (QuerySymbolToSingleMapFile_(pMap, address, strBuf, strBufSize)) { return true; } From 51dae63c9a6bbdf38fd060597dfca2037d9e4a6d Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 25 May 2024 03:42:13 -0400 Subject: [PATCH 05/11] fix some of the floating point stuff --- configure.py | 1 + include/d/a/d_a_base.h | 28 +++++-- include/egg/prim/eggList.h | 0 include/toBeSorted/room_manager.h | 3 +- src/d/a/d_a_base.cpp | 121 +++++++++++++----------------- 5 files changed, 79 insertions(+), 74 deletions(-) create mode 100644 include/egg/prim/eggList.h diff --git a/configure.py b/configure.py index f423f3f7..93590ebd 100644 --- a/configure.py +++ b/configure.py @@ -186,6 +186,7 @@ cflags_framework = [ *cflags_base, "-inline noauto", "-str reuse", + "-fp_contract off", "-ipa file", ] diff --git a/include/d/a/d_a_base.h b/include/d/a/d_a_base.h index 66333274..796b669c 100644 --- a/include/d/a/d_a_base.h +++ b/include/d/a/d_a_base.h @@ -24,6 +24,22 @@ struct SoundInfo { SoundInfo *next; SoundInfo *prev; }; + +template +struct TList { + T *GetOffset() { + return (T *)((u8 *)this - offset); + } + TList() { + sound_info_next = GetOffset(); + sound_info_tail = GetOffset(); + count = 0; + } + T *sound_info_tail; + T *sound_info_next; + s32 count; +}; + // Ghidra: ActorBase // size: 0xFC // non-official name @@ -31,9 +47,7 @@ class dAcBase_c : public dBase_c { public: /* 0x68 */ mHeapAllocator_c heap_allocator; /* 0x84 */ ObjInfo *obj_info; - /* 0x88 */ void *sound_info_tail; - /* 0x8c */ void *sound_info_next; - /* 0x90 */ int count; + /* 0x88 */ TList sound_list; /* 0x94 */ SoundSource *sound_source; /* 0x9C */ mVec3_c *obj_pos; /* 0x9c */ mVec3_c pos_copy; @@ -124,7 +138,7 @@ public: // Kinda performs the code of the first param on every actor (second param is optional parent) /* 8002d130 */ static void forEveryActor(void *func(dAcBase_c *, dAcBase_c *), dAcBase_c *parent); // Not really static, but we currently dont have a type for the return (not just simply a s16) - /* 8002d190 */ void getXZAngleToPlayer(s16 *angle); + /* 8002d190 */ mAng getXZAngleToPlayer(s16 *angle); // returns true if under the distThresh, False if not. the actual distance is returned in outDist /* 8002d1d0 */ bool getDistanceToActor(dAcBase_c *actor, f32 distThresh, f32 *outDist); // same concept as above @@ -164,9 +178,11 @@ public: /* 8002d940 */ void changeLoadedEntitiesWithSet(); /* 8002d960 */ void changeLoadedEntitiesNoSet(); - /* 8002d980 */ dAcBase_c *createActor(ProfileName actorId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, s32 roomId, dBase_c *ref); + /* 8002d980 */ dAcBase_c *createActor(ProfileName actorId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, + u32 params2, s32 roomId, dBase_c *ref); - /* 8002da80 */ dAcBase_c *createActorStage(ProfileName actorId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, s32 roomId, dBase_c *ref); + /* 8002da80 */ dAcBase_c *createActorStage(ProfileName actorId, u32 params1, mVec3_c *pos, mAng3_c *rot, + mVec3_c *scale, u32 params2, s32 roomId, dBase_c *ref); /* 8002dc20 */ void FUN_8002dc20(s16 *, s16 *); /* 8002dc50 */ void incrementKillCounter(); diff --git a/include/egg/prim/eggList.h b/include/egg/prim/eggList.h new file mode 100644 index 00000000..e69de29b diff --git a/include/toBeSorted/room_manager.h b/include/toBeSorted/room_manager.h index fb7a0f66..c4c19821 100644 --- a/include/toBeSorted/room_manager.h +++ b/include/toBeSorted/room_manager.h @@ -2,9 +2,9 @@ #define ROOM_MANAGER_H #include "d/d_base.h" -#include #include "m/m_allocator.h" #include "m/types_m.h" +#include #define MAX_ROOM_NUMBER 64 @@ -94,6 +94,7 @@ public: /* 80575760 */ static RoomManager *m_Instance; public: + dRoom *GetRoomByIndex(int roomid); /* 801b42b0 */ static dBase_c *getRoom(int roomid); /* 801b42d0 */ static void bindStageResToFile(nw4r::g3d::ResFile *); /* 801b4320 */ static void bindSkyCmnToResFile(nw4r::g3d::ResFile *); diff --git a/src/d/a/d_a_base.cpp b/src/d/a/d_a_base.cpp index f103ca01..51e2096f 100644 --- a/src/d/a/d_a_base.cpp +++ b/src/d/a/d_a_base.cpp @@ -1,13 +1,12 @@ #include "d/a/d_a_base.h" -#include "m/m_vec.h" #include "d/d_player.h" #include "f/f_list_nd.h" -#include "toBeSorted/misc_flag_managers.h" -#include "toBeSorted/special_item_drop_mgr.h" -#include "toBeSorted/scgame.h" +#include "m/m_vec.h" #include "toBeSorted/event.h" #include "toBeSorted/file_manager.h" - +#include "toBeSorted/misc_flag_managers.h" +#include "toBeSorted/scgame.h" +#include "toBeSorted/special_item_drop_mgr.h" // .sdata u32 dAcBase_c::s_Create_RoomId = -1; @@ -27,12 +26,12 @@ extern "C" ObjInfo *getObjByActorIdAndSubtype_unkNamespace(ProfileName, u8); extern "C" ObjInfo *getObjByActorName_unkNamespace(char *name); extern "C" char *getObjectName_8006a730(ObjInfo *); extern "C" SoundSource *soundForActorInitRelated_803889c0(s8, fBase_c *, char *, u8); -extern "C" short targetAngleY(mVec3_c *, mVec3_c *); -extern "C" short targetAngleX(mVec3_c *, mVec3_c *); +extern "C" s16 targetAngleY(mVec3_c *, mVec3_c *); +extern "C" s16 targetAngleX(mVec3_c *, mVec3_c *); extern "C" bool checkCollision(mVec3_c *pos); extern "C" s8 collisionCheckGetRoom(); extern "C" dRoom *getRoomByIndex(RoomManager *mgr, s8 roomid); -extern "C" bool alsoSetAsCurrentEvent(dAcBase_c*, Event*, void *); +extern "C" bool alsoSetAsCurrentEvent(dAcBase_c *, Event *, void *); bool dAcBase_c::createHeap() { return true; @@ -40,8 +39,7 @@ bool dAcBase_c::createHeap() { // Doesnt Match Yet dAcBase_c::dAcBase_c() - : heap_allocator(), obj_info(s_Create_ObjInfo), sound_info_tail(&heap_allocator.mHeap), - sound_info_next(&heap_allocator.mHeap), count(0), sound_source(nullptr), obj_pos(&position), + : heap_allocator(), obj_info(s_Create_ObjInfo), sound_source(nullptr), sound_list(), obj_pos(&position), params2(s_Create_Params2), obj_id(s_Create_UnkFlags), viewclip_index(s_Create_ViewClipIdx), actor_node(nullptr), roomid(s_Create_RoomId), actor_subtype(s_Create_Subtype) { JStudio_actor = 0; @@ -241,11 +239,12 @@ u32 dAcBase_c::itemDroppingAndGivingRelated(mVec3_c *spawnPos, int subtype) { spawnPos = &position; } - u32 param2Copy = params2; + u32 param2Copy = params2; params2 = param2Copy | 0xFF000000; // mAng3_c rot = {}; s16 rot = 0; - return SpecialItemDropMgr::giveSpecialDropItem(SpecialItemDropMgr::sInstance, param2Copy >> 0x18, roomid, spawnPos, subtype, &rot, -1); + return SpecialItemDropMgr::giveSpecialDropItem(SpecialItemDropMgr::sInstance, param2Copy >> 0x18, roomid, spawnPos, + subtype, &rot, -1); } // 8002cf90 @@ -301,21 +300,24 @@ dAcBase_c *dAcBase_c::findActor(char *objName, dAcBase_c *parent) { // searches for actor based on groupType // 8002d0a0 -dAcBase_c *dAcBase_c::searchActor(dAcBase_c *parent) { - dAcBase_c *foundActor = nullptr; - - if (parent == nullptr) { - foundActor = (dAcBase_c *)fManager_c::searchBaseByGroupType(ACTOR, nullptr); - } else if (parent->group_type == 2) { - foundActor = (dAcBase_c *)fManager_c::searchBaseByGroupType(ACTOR, parent); - parent = foundActor; +DECOMP_INLINE dAcBase_c *findActor(dAcBase_c *parent) { + if (!parent) { + return (dAcBase_c *)fManager_c::searchBaseByGroupType(2, nullptr); } + if (parent->group_type == 2) { + return (dAcBase_c *)fManager_c::searchBaseByGroupType(2, parent); + } + return nullptr; +} - if (foundActor == nullptr) { +dAcBase_c *dAcBase_c::searchActor(dAcBase_c *parent) { + dAcBase_c *foundActor = ::findActor(parent); + + if (foundActor) { + return foundActor; + } else { return (dAcBase_c *)fManager_c::searchBaseByGroupType(STAGE, parent); } - - return foundActor; } // 8002d130 @@ -329,12 +331,10 @@ void dAcBase_c::forEveryActor(void *func(dAcBase_c *, dAcBase_c *), dAcBase_c *p } // 8002d190 -void dAcBase_c::getXZAngleToPlayer(s16 *angle) { - *angle = targetAngleY(&this->position, &dPlayer::LINK->position); +mAng dAcBase_c::getXZAngleToPlayer(s16 *angle) { + return targetAngleY(&this->position, &dPlayer::LINK->position); } -// The "distSquared > dist" bit is misbehaving. -// Trying different operators doesn't work so I'm leaving it as the most simple wrong choice. // 8002d1d0 bool dAcBase_c::getDistanceToActor(dAcBase_c *actor, f32 distThresh, f32 *outDist) { f32 distSquared = 3.402823e+38; @@ -343,26 +343,23 @@ bool dAcBase_c::getDistanceToActor(dAcBase_c *actor, f32 distThresh, f32 *outDis if (actor != nullptr) { distSquared = PSVECSquareDistance(position, actor->position); - if (distSquared <= distThresh*distThresh) { + if (distSquared <= distThresh * distThresh) { isWithinThreshhold = true; } } if (outDist != nullptr) { - f32 dist = 0.0; - // TODO: make this not sad :( - if (distSquared <= dist) { - dist = nw4r::math::FrSqrt(distSquared) * distSquared; - } - *outDist = dist; + *outDist = distSquared <= 0.0f ? 0.0f : nw4r::math::FrSqrt(distSquared) * distSquared; } + return isWithinThreshhold; } // Similar weirdness as the above function. Also, r29->31 are initted in the wrong order? // 8002d290 -bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, s16 *outDiffAngleX) { - f32 distSquared = 3.402823e+38; +bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, + s16 *outDiffAngleY, s16 *outDiffAngleX) { + f32 distSquared = 3.402823e+38f; s16 angleToActorY = 0; s16 angleToActorX = 0; bool isWithinRange = false; @@ -372,21 +369,14 @@ bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 angleToActorY = targetAngleY(&position, &actor->position); angleToActorX = targetAngleX(&position, &actor->position); - if ((distSquared <= distThresh*distThresh) - && (labs(rotation.y - angleToActorY) <= yAngle) - && (labs(rotation.x - angleToActorX) <= xAngle) - ) { + if ((distSquared <= distThresh * distThresh) && (labs(rotation.y - angleToActorY) <= yAngle) && + (labs(rotation.x - angleToActorX) <= xAngle)) { isWithinRange = true; } } if (outDist != nullptr) { - f32 dist = 0.0; - if (distSquared <= dist) { - dist = nw4r::math::FrSqrt(distSquared); - dist *= distSquared; - } - *outDist = dist; + *outDist = distSquared <= 0.0f ? 0.0f : nw4r::math::FrSqrt(distSquared) * distSquared; } if (outDiffAngleY != nullptr) { @@ -400,16 +390,16 @@ bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 return isWithinRange; } -// Very notmatching // 8002d3e0 bool dAcBase_c::isWithinPlayerRadius(f32 radius) { - f32 zDist = position.z - dPlayer::LINK->position.z; - f32 xDist = position.x - dPlayer::LINK->position.x; - return (xDist*xDist + zDist*zDist) < radius*radius; + mVec3_c dist_diff = position - dPlayer::LINK->position; + + return dist_diff.x * dist_diff.x + dist_diff.z * dist_diff.z < radius * radius; } // 8002d440 -bool dAcBase_c::getDistanceAndAngleToPlayer(f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, s16 *outDiffAngleX) { +bool dAcBase_c::getDistanceAndAngleToPlayer(f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, + s16 *outDiffAngleX) { return getDistanceAndAngleToActor(dPlayer::LINK, distThresh, yAngle, xAngle, outDist, outDiffAngleY, outDiffAngleX); } @@ -427,10 +417,7 @@ f32 dAcBase_c::getSquareDistToPlayer() { // 8002d4b0 void dAcBase_c::updateRoomId(f32 yOffset) { if (getConnectParent()->profile_name != 701 /* fProfile::PROFILE_NAME_e::ROOM */) { - mVec3_c actorPos; - actorPos.x = position.x; - actorPos.y = position.y + yOffset; - actorPos.z = position.z; + mVec3_c actorPos(position.x, position.y + yOffset, position.z); if (checkCollision(&actorPos)) { roomid = collisionCheckGetRoom(); @@ -442,8 +429,8 @@ void dAcBase_c::updateRoomId(f32 yOffset) { // 8002d540 bool dAcBase_c::isRoomFlags_0x6_Set() { - dRoom *room = getRoomByIndex(RoomManager::m_Instance, roomid); - return (room->flags & 6) != 0; + dRoom *room = RoomManager::m_Instance->GetRoomByIndex(roomid); + return (room->flags & 6); } // Start of SoundSource stuff @@ -496,7 +483,8 @@ void dAcBase_c::changeLoadedEntitiesNoSet() { // spawns GroupType2 (ACTOR) // 8002d980 -dAcBase_c *dAcBase_c::createActor(ProfileName actorId, u32 actorParams1, mVec3_c *actorPosition, mAng3_c *actorRotation, mVec3_c *actorScale, u32 actorParams2, s32 actorRoomid, dBase_c *actorRef) { +dAcBase_c *dAcBase_c::createActor(ProfileName actorId, u32 actorParams1, mVec3_c *actorPosition, mAng3_c *actorRotation, + mVec3_c *actorScale, u32 actorParams2, s32 actorRoomid, dBase_c *actorRef) { if (actorPosition == nullptr) { actorPosition = &position; } @@ -518,14 +506,16 @@ dAcBase_c *dAcBase_c::createActor(ProfileName actorId, u32 actorParams1, mVec3_c newParams2 = getParams2_ignoreLower(); } - setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, 0xFF, nullptr); + setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, + 0xFF, nullptr); dBase_c *room = RoomManager::getRoom(roomid); return (dAcBase_c *)dBase_c::createBase(actorId, room, actorParams1, ACTOR); } // spawns GroupType2 (STAGE) // 8002da80 -dAcBase_c *dAcBase_c::createActorStage(ProfileName actorId, u32 actorParams1, mVec3_c *actorPosition, mAng3_c *actorRotation, mVec3_c *actorScale, u32 actorParams2, s32 actorRoomid, dBase_c *actorRef) { +dAcBase_c *dAcBase_c::createActorStage(ProfileName actorId, u32 actorParams1, mVec3_c *actorPosition, + mAng3_c *actorRotation, mVec3_c *actorScale, u32 actorParams2, s32 actorRoomid, dBase_c *actorRef) { if (actorPosition == nullptr) { actorPosition = &position; } @@ -547,7 +537,8 @@ dAcBase_c *dAcBase_c::createActorStage(ProfileName actorId, u32 actorParams1, mV newParams2 = getParams2_ignoreLower(); } - setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, 0xFF, nullptr); + setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, + 0xFF, nullptr); dBase_c *room = RoomManager::getRoom(roomid); return (dAcBase_c *)dBase_c::createBase(actorId, room, actorParams1, STAGE); } @@ -569,9 +560,7 @@ void dAcBase_c::doInteraction(s32 param) { // Only called by dPlayer::dig and that function fails to decomp in ghidra? // 8002dc20 -void dAcBase_c::FUN_8002dc20(s16 *, s16 *) { - -} +void dAcBase_c::FUN_8002dc20(s16 *, s16 *) {} // This whole function gets compiled to just a `blr` // Not sure how to make this work as expected @@ -620,9 +609,7 @@ void dAcBase_c::FUN_8002dd90() { // Some collision related thing // 8002ddd0 -void dAcBase_c::FUN_8002ddd0() { - -} +void dAcBase_c::FUN_8002ddd0() {} // 8002de30 void dAcBase_c::FUN_8002de30() { From 09eebc77b3cee1a28fb85d2f094ae6d581857b56 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 25 May 2024 12:48:53 +0200 Subject: [PATCH 06/11] db_exception --- config/SOUE01/splits.txt | 15 + config/SOUE01/symbols.txt | 89 ++++-- configure.py | 2 + include/nw4r/db/db_console.h | 40 ++- include/nw4r/db/db_exception.h | 26 ++ include/rvl/OS/OSError.h | 2 +- src/nw4r/db/db_console.cpp | 380 +++++++++++++++++++++++++ src/nw4r/db/db_exception.cpp | 498 +++++++++++++++++++++++++++++++++ src/nw4r/db/db_mapFile.cpp | 4 +- 9 files changed, 1030 insertions(+), 26 deletions(-) create mode 100644 include/nw4r/db/db_exception.h create mode 100644 src/nw4r/db/db_console.cpp create mode 100644 src/nw4r/db/db_exception.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index c4892f16..980752e4 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -338,6 +338,21 @@ nw4r/db/db_directPrint.cpp: .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 +nw4r/db/db_console.cpp: + .text start:0x80434EA0 end:0x8043598C + .data start:0x8056C010 end:0x8056C038 + .sdata start:0x80574DC8 end:0x80574DD0 + .sbss start:0x805765F0 end:0x805765F8 + .bss start:0x80636BA8 end:0x80636FC0 + +nw4r/db/db_exception.cpp: + .text start:0x80435990 end:0x80436A48 + .data start:0x8056C038 end:0x8056C5F0 + .sdata start:0x80574DD0 end:0x80574E10 + .sbss start:0x805765F8 end:0x80576600 + .sdata2 start:0x8057EBA8 end:0x8057EBAC + .bss start:0x80636FC0 end:0x8063B320 + nw4r/db/db_mapFile.cpp: .text start:0x80436A50 end:0x804373B4 .data start:0x8056C5F0 end:0x8056C600 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 430c679a..a825c204 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -21979,7 +21979,7 @@ OSSearchModule = .text:0x803A9F50; // type:function size:0xA4 OSInitMessageQueue = .text:0x803AA000; // type:function size:0x60 OSSendMessage = .text:0x803AA060; // type:function size:0xC8 OSReceiveMessage = .text:0x803AA130; // type:function size:0xDC -fn_803AA210 = .text:0x803AA210; // type:function size:0xC +OSGetPhysicalMem1Size = .text:0x803AA210; // type:function size:0xC OSGetPhysicalMem2Size = .text:0x803AA220; // type:function size:0xC scope:global OSGetConsoleSimulatedMem1Size = .text:0x803AA230; // type:function size:0xC scope:global OSGetConsoleSimulatedMem2Size = .text:0x803AA240; // type:function size:0xC scope:global @@ -24153,7 +24153,7 @@ DirectPrint_SetupFB__Q34nw4r2db6detailFPC16_GXRenderModeObj = .text:0x80434CB0; RemoveConsoleFromList___Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHead = .text:0x80434EA0; // type:function size:0xB0 Console_Create__Q24nw4r2dbFPvUsUsUsUsUs = .text:0x80434F50; // type:function size:0x1B0 Console_Destroy__Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHead = .text:0x80435100; // type:function size:0x30 -DoDrawConsole___Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHeadPQ34nw4r2ut17TextWriterBase = .text:0x80435130; // type:function size:0x1A4 +DoDrawConsole___Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHeadPQ34nw4r2ut17TextWriterBase = .text:0x80435130; // type:function size:0x1A4 Console_DrawDirect__Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHead = .text:0x804352E0; // type:function size:0x7C PrintToBuffer___Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHeadPCUc = .text:0x80435360; // type:function size:0x3B8 Console_VFPrintf__Q24nw4r2dbFQ34nw4r2db17ConsoleOutputTypePQ44nw4r2db6detail11ConsoleHeadPCcP16__va_list_struct = .text:0x80435720; // type:function size:0xD8 @@ -27471,7 +27471,7 @@ _restgpr_29 = .text:0x804C6BE0; // type:label scope:global _restgpr_30 = .text:0x804C6BE4; // type:label scope:global _restgpr_31 = .text:0x804C6BE8; // type:label scope:global __div2u = .text:0x804C6BF0; // type:function size:0xEC scope:global -fn_804C6CDC = .text:0x804C6CDC; // type:function size:0x138 +__div2i = .text:0x804C6CDC; // type:function size:0x138 __mod2u = .text:0x804C6E14; // type:function size:0xE4 scope:global fn_804C6EF8 = .text:0x804C6EF8; // type:function size:0x10C fn_804C7004 = .text:0x804C7004; // type:function size:0x24 @@ -36957,20 +36957,65 @@ __vt__Q34nw4r2ut4Font = .data:0x8056BED8; // type:object size:0x5C scope:weak __vt__Q44nw4r2ut6detail11ResFontBase = .data:0x8056BF44; // type:object size:0x5C __vt__Q34nw4r2ut7ResFont = .data:0x8056BFA0; // type:object size:0x5C twiceBit__Q24nw4r2db = .data:0x8056C000; // type:object size:0x10 scope:local -lbl_8056C010 = .data:0x8056C010; // type:object size:0x10 -lbl_8056C020 = .data:0x8056C020; // type:object size:0x18 -lbl_8056C038 = .data:0x8056C038; // type:object size:0x10 -lbl_8056C048 = .data:0x8056C048; // type:object size:0x10 -lbl_8056C058 = .data:0x8056C058; // type:object size:0x14 -lbl_8056C06C = .data:0x8056C06C; // type:object size:0xC -lbl_8056C078 = .data:0x8056C078; // type:object size:0x10 +lbl_8056C010 = .data:0x8056C010; // type:object size:0xF data:string +lbl_8056C020 = .data:0x8056C020; // type:object size:0x17 data:string +lbl_8056C038 = .data:0x8056C038; // type:object size:0xD data:string +lbl_8056C048 = .data:0x8056C048; // type:object size:0xE data:string +lbl_8056C058 = .data:0x8056C058; // type:object size:0x13 data:string +lbl_8056C06C = .data:0x8056C06C; // type:object size:0xA data:string +lbl_8056C078 = .data:0x8056C078; // type:object size:0xF data:string lbl_8056C088 = .data:0x8056C088; // type:object size:0xC data:string lbl_8056C094 = .data:0x8056C094; // type:object size:0xC data:string -lbl_8056C0A0 = .data:0x8056C0A0; // type:object size:0x14 +lbl_8056C0A0 = .data:0x8056C0A0; // type:object size:0x13 data:string lbl_8056C0B4 = .data:0x8056C0B4; // type:object size:0xC data:string -lbl_8056C0C0 = .data:0x8056C0C0; // type:object size:0x14 -lbl_8056C0D4 = .data:0x8056C0D4; // type:object size:0x14 -lbl_8056C0E8 = .data:0x8056C0E8; // type:object size:0x508 +lbl_8056C0C0 = .data:0x8056C0C0; // type:object size:0x11 data:string +lbl_8056C0D4 = .data:0x8056C0D4; // type:object size:0x12 data:string +lbl_8056C0E8 = .data:0x8056C0E8; // type:object size:0xB data:string +lbl_8056C0F4 = .data:0x8056C0F4; // type:object size:0x44 +lbl_8056C138 = .data:0x8056C138; // type:object size:0x37 data:string +lbl_8056C170 = .data:0x8056C170; // type:object size:0x2D data:string +lbl_8056C1A0 = .data:0x8056C1A0; // type:object size:0x10 data:string +lbl_8056C1B0 = .data:0x8056C1B0; // type:object size:0x1A data:string +lbl_8056C1CC = .data:0x8056C1CC; // type:object size:0x26 data:string +lbl_8056C1F4 = .data:0x8056C1F4; // type:object size:0x27 data:string +lbl_8056C21C = .data:0x8056C21C; // type:object size:0x1A data:string +lbl_8056C238 = .data:0x8056C238; // type:object size:0x1E data:string +lbl_8056C258 = .data:0x8056C258; // type:object size:0x2A data:string +lbl_8056C284 = .data:0x8056C284; // type:object size:0xD data:string +lbl_8056C294 = .data:0x8056C294; // type:object size:0x11 data:string +lbl_8056C2A8 = .data:0x8056C2A8; // type:object size:0x1D data:string +lbl_8056C2C8 = .data:0x8056C2C8; // type:object size:0x1A data:string +lbl_8056C2E4 = .data:0x8056C2E4; // type:object size:0x1C data:string +lbl_8056C300 = .data:0x8056C300; // type:object size:0x1C data:string +lbl_8056C320 = .data:0x8056C320; // type:object size:0x28 data:string +lbl_8056C348 = .data:0x8056C348; // type:object size:0x15 data:string +lbl_8056C360 = .data:0x8056C360; // type:object size:0x9 data:string +lbl_8056C36C = .data:0x8056C36C; // type:object size:0x22 data:string +lbl_8056C390 = .data:0x8056C390; // type:object size:0x1F data:string +lbl_8056C3B0 = .data:0x8056C3B0; // type:object size:0xF data:string +lbl_8056C3C0 = .data:0x8056C3C0; // type:object size:0x19 data:string +lbl_8056C3DC = .data:0x8056C3DC; // type:object size:0x16 data:string +lbl_8056C3F4 = .data:0x8056C3F4; // type:object size:0x16 data:string +lbl_8056C40C = .data:0x8056C40C; // type:object size:0xF data:string +lbl_8056C41C = .data:0x8056C41C; // type:object size:0x12 data:string +lbl_8056C430 = .data:0x8056C430; // type:object size:0x13 data:string +lbl_8056C444 = .data:0x8056C444; // type:object size:0x16 data:string +lbl_8056C45C = .data:0x8056C45C; // type:object size:0x1A data:string +lbl_8056C478 = .data:0x8056C478; // type:object size:0x10 data:string +lbl_8056C488 = .data:0x8056C488; // type:object size:0x11 data:string +lbl_8056C49C = .data:0x8056C49C; // type:object size:0x15 data:string +lbl_8056C4B4 = .data:0x8056C4B4; // type:object size:0x16 data:string +lbl_8056C4CC = .data:0x8056C4CC; // type:object size:0x1C data:string +lbl_8056C4E8 = .data:0x8056C4E8; // type:object size:0x1C data:string +lbl_8056C504 = .data:0x8056C504; // type:object size:0x29 data:string +lbl_8056C530 = .data:0x8056C530; // type:object size:0xE data:string +lbl_8056C540 = .data:0x8056C540; // type:object size:0x26 data:string +lbl_8056C568 = .data:0x8056C568; // type:object size:0x26 data:string +lbl_8056C590 = .data:0x8056C590; // type:object size:0x11 data:string +lbl_8056C5A4 = .data:0x8056C5A4; // type:object size:0x11 data:string +lbl_8056C5B8 = .data:0x8056C5B8; // type:object size:0x11 data:string +lbl_8056C5CC = .data:0x8056C5CC; // type:object size:0x11 data:string +lbl_8056C5E0 = .data:0x8056C5E0; // type:object size:0xC data:string lbl_8056C5F0 = .data:0x8056C5F0; // type:object size:0xD data:string lbl_8056C600 = .data:0x8056C600; // type:object size:0x108 lbl_8056C708 = .data:0x8056C708; // type:object size:0x808 @@ -39549,17 +39594,17 @@ lbl_80574DB8 = .sdata:0x80574DB8; // type:object size:0x8 data:byte mFormatBufferSize__Q34nw4r2ut17TextWriterBase = .sdata:0x80574DC0; // type:object size:0x4 scope:weak data:4byte mFormatBufferSize__Q34nw4r2ut17TextWriterBase = .sdata:0x80574DC4; // type:object size:0x4 scope:weak data:4byte lbl_80574DC8 = .sdata:0x80574DC8; // type:object size:0x4 data:string -lbl_80574DCC = .sdata:0x80574DCC; // type:object size:0x4 +lbl_80574DCC = .sdata:0x80574DCC; // type:object size:0x3 data:string lbl_80574DD0 = .sdata:0x80574DD0; // type:object size:0x4 data:string lbl_80574DD4 = .sdata:0x80574DD4; // type:object size:0x4 data:string lbl_80574DD8 = .sdata:0x80574DD8; // type:object size:0x8 data:string -lbl_80574DE0 = .sdata:0x80574DE0; // type:object size:0x8 +lbl_80574DE0 = .sdata:0x80574DE0; // type:object size:0x6 data:string lbl_80574DE8 = .sdata:0x80574DE8; // type:object size:0x4 data:string -lbl_80574DEC = .sdata:0x80574DEC; // type:object size:0x8 -lbl_80574DF4 = .sdata:0x80574DF4; // type:object size:0x4 -lbl_80574DF8 = .sdata:0x80574DF8; // type:object size:0x8 +lbl_80574DEC = .sdata:0x80574DEC; // type:object size:0x6 data:string +lbl_80574DF4 = .sdata:0x80574DF4; // type:object size:0x2 data:string +lbl_80574DF8 = .sdata:0x80574DF8; // type:object size:0x7 data:string lbl_80574E00 = .sdata:0x80574E00; // type:object size:0x8 data:string -lbl_80574E08 = .sdata:0x80574E08; // type:object size:0x8 +lbl_80574E08 = .sdata:0x80574E08; // type:object size:0x2 data:string lbl_80574E10 = .sdata:0x80574E10; // type:object size:0x4 data:4byte lbl_80574E14 = .sdata:0x80574E14; // type:object size:0x4 data:4byte lbl_80574E18 = .sdata:0x80574E18; // type:object size:0x4 data:4byte @@ -40834,7 +40879,7 @@ mDefaultTagProcessor__Q34nw4r2ut17TextWriterBase = .sbss:0x805765DC; // type: sInitialized__Q24nw4r2db = .sbss:0x805765E8; // type:object size:0x4 scope:local data:4byte lbl_805765F0 = .sbss:0x805765F0; // type:object size:0x4 data:4byte lbl_805765F4 = .sbss:0x805765F4; // type:object size:0x1 data:byte -lbl_805765F8 = .sbss:0x805765F8; // type:object size:0x8 +sMessageBuffer__Q24nw4r2db = .sbss:0x805765F8; // type:object size:0x8 sFileLength__Q24nw4r2db = .sbss:0x80576600; // type:object size:0x4 scope:local data:4byte sMapFileList__Q24nw4r2db = .sbss:0x80576604; // type:object size:0x4 scope:local data:4byte GetCharPtr___Q24nw4r2db = .sbss:0x80576608; // type:object size:0x4 scope:local data:4byte @@ -47248,7 +47293,7 @@ lbl_8057EB90 = .sdata2:0x8057EB90; // type:object size:0x4 scope:local data:floa lbl_8057EB94 = .sdata2:0x8057EB94; // type:object size:0x4 scope:local data:float lbl_8057EB98 = .sdata2:0x8057EB98; // type:object size:0x8 scope:local data:double lbl_8057EBA0 = .sdata2:0x8057EBA0; // type:object size:0x4 scope:local data:float -lbl_8057EBA8 = .sdata2:0x8057EBA8; // type:object size:0x8 data:float +lbl_8057EBA8 = .sdata2:0x8057EBA8; // type:object size:0x4 data:float lbl_8057EBB0 = .sdata2:0x8057EBB0; // type:object size:0x4 data:float lbl_8057EBB4 = .sdata2:0x8057EBB4; // type:object size:0x4 data:float lbl_8057EBB8 = .sdata2:0x8057EBB8; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index 7a62a83e..25588915 100644 --- a/configure.py +++ b/configure.py @@ -329,6 +329,8 @@ config.libs = [ [ Object(Matching, "nw4r/db/db_assert.cpp"), Object(Matching, "nw4r/db/db_directPrint.cpp"), + Object(Matching, "nw4r/db/db_console.cpp"), + Object(Matching, "nw4r/db/db_exception.cpp"), Object(Matching, "nw4r/db/db_mapFile.cpp"), ], ), diff --git a/include/nw4r/db/db_console.h b/include/nw4r/db/db_console.h index 90515fb2..01921110 100644 --- a/include/nw4r/db/db_console.h +++ b/include/nw4r/db/db_console.h @@ -1,14 +1,52 @@ #ifndef NW4R_DB_CONSOLE_H #define NW4R_DB_CONSOLE_H +#include +#include + namespace nw4r { namespace db { namespace detail { -struct ConsoleHead {}; +typedef struct ConsoleHead { + u8 *textBuf; + u16 width; + u16 height; + u16 priority; + u16 attr; + u16 printTop; + u16 printXPos; + u16 ringTop; + u32 ringTopLineCnt; + s32 viewTopLine; + s16 viewPosX; + s16 viewPosY; + u16 viewLines; + bool isVisible; + nw4r::ut::TextWriterBase *writer; + ConsoleHead *next; +} ConsoleHead; + } // namespace detail +typedef detail::ConsoleHead *ConsoleHandle; + +enum ConsoleOutputType { + CONSOLE_OUTPUT_NONE = 0, + CONSOLE_OUTPUT_DISPLAY = 1, + CONSOLE_OUTPUT_TERMINAL = 2, + CONSOLE_OUTPUT_ALL = CONSOLE_OUTPUT_DISPLAY | CONSOLE_OUTPUT_TERMINAL, +}; + +ConsoleHandle Console_Create(void *arg, u16, u16, u16, u16, u16); +ConsoleHandle Console_Destroy(ConsoleHandle console); +void Console_DrawDirect(ConsoleHandle console); +void Console_VFPrintf(ConsoleOutputType type, ConsoleHandle console, const char* format, va_list vlist); +void Console_Printf(ConsoleHandle console, const char* format, ...); +s32 Console_GetTotalLines(ConsoleHandle console); + } // namespace db } // namespace nw4r + #endif diff --git a/include/nw4r/db/db_exception.h b/include/nw4r/db/db_exception.h new file mode 100644 index 00000000..34bc646d --- /dev/null +++ b/include/nw4r/db/db_exception.h @@ -0,0 +1,26 @@ +#ifndef NW4R_DB_EXCEPTION_H +#define NW4R_DB_EXCEPTION_H + +#include +#include + + +namespace nw4r { +namespace db { + +typedef struct { + u16 error; + OSContext *ctx; + u32 dsisr; + u32 dar; +} ExceptionCallbackParam; + +void Exception_Init(); +ConsoleHandle Exception_SetConsole(ConsoleHandle, const _GXRenderModeObj *); +ConsoleHandle Exception_GetConsole(); +void Exception_SetUserCallback(bool (*)(ConsoleHandle, void *), void *); + +} // namespace db +} // namespace nw4r + +#endif diff --git a/include/rvl/OS/OSError.h b/include/rvl/OS/OSError.h index ac9ece4b..76b5463f 100644 --- a/include/rvl/OS/OSError.h +++ b/include/rvl/OS/OSError.h @@ -36,7 +36,7 @@ typedef enum { OS_ERR_MAX } OSErrorType; -typedef void (*OSErrorHandler)(u8 error, OSContext *ctx, u32 dsisr, u32 dar, ...); +typedef void (*OSErrorHandler)(u16 error, OSContext *ctx, u32 dsisr, u32 dar); extern OSErrorHandler __OSErrorTable[OS_ERR_MAX]; extern u32 __OSFpscrEnableBits; diff --git a/src/nw4r/db/db_console.cpp b/src/nw4r/db/db_console.cpp new file mode 100644 index 00000000..8f1a4c8d --- /dev/null +++ b/src/nw4r/db/db_console.cpp @@ -0,0 +1,380 @@ +#include +#include +#include +#include +#include + +namespace nw4r { +namespace db { + +static ConsoleHandle sConsoleList; +static OSMutex sMutex; +static u8 buf[0x400]; +bool sInited; + +static ConsoleHandle FindInsertionPosition_(u16 priority) { + ConsoleHandle cursor = sConsoleList; + + if (cursor == nullptr || cursor->priority < priority) { + return nullptr; + } + + while (cursor->next != nullptr) { + if (cursor->next->priority < priority) { + return cursor; + } + cursor = cursor->next; + } + return cursor; +} + +static void Console_Append_(ConsoleHandle console) { + OSLockMutex(&sMutex); + + ConsoleHandle cursor = FindInsertionPosition_(console->priority); + + if (cursor == nullptr) { + console->next = sConsoleList; + sConsoleList = console; + } else { + console->next = cursor->next; + cursor->next = console; + } + OSUnlockMutex(&sMutex); +} + +void RemoveConsoleFromList_(ConsoleHandle console) { + OSLockMutex(&sMutex); + + if (sConsoleList == console) { + sConsoleList = console->next; + console->next = nullptr; + } else { + ConsoleHandle cursor = sConsoleList; + while (cursor->next != nullptr) { + if (cursor->next == console) { + cursor->next = console->next; + console->next = nullptr; + goto end; + } + cursor = cursor->next; + } +#line 386 + OSError("illegal console handle"); + } + +end: + OSUnlockMutex(&sMutex); +} + +static bool TryLockMutex_(OSMutex *mutex) { + if (OSGetCurrentThread() != nullptr) { + OSLockMutex(&sMutex); + return true; + } + + if (mutex->thread == nullptr) { + return true; + } + + return false; +} + +static void UnlockMutex_(OSMutex *mutex) { + if (OSGetCurrentThread() != nullptr) { + OSUnlockMutex(&sMutex); + } +} + +ConsoleHandle Console_Create(void *arg, u16 width, u16 height, u16 viewLines, u16 priority, u16 attr) { + ConsoleHandle console = (ConsoleHandle)arg; + if (!sInited) { + OSInitMutex(&sMutex); + sInited = true; + } + console->textBuf = (u8 *)(console + 1); + console->width = width; + console->height = height; + console->priority = priority; + console->attr = attr; + console->isVisible = false; + console->printTop = 0; + console->printXPos = 0; + console->ringTop = 0; + console->ringTopLineCnt = 0; + console->viewTopLine = 0; + console->viewPosX = 0x1e; + console->viewPosY = 0x32; + console->viewLines = viewLines; + console->writer = nullptr; + + if (TryLockMutex_(&sMutex)) { + BOOL intr = OSDisableInterrupts(); + console->printTop = 0; + console->printXPos = 0; + console->ringTop = 0; + console->ringTopLineCnt = 0; + console->viewTopLine = 0; + OSRestoreInterrupts(intr); + UnlockMutex_(&sMutex); + } + + Console_Append_(console); + return console; +} + +ConsoleHandle Console_Destroy(ConsoleHandle console) { + RemoveConsoleFromList_(console); + return console; +} + + +static u8 *GetTextPtr_(ConsoleHandle console, u16 line, u16 xPos) { + return &console->textBuf[(console->width + 1) * line + xPos]; +} + +static u16 GetRingUsedLines_(ConsoleHandle console) { + s32 lines = console->printTop - console->ringTop; + if (lines < 0) { + lines += console->height; + } + return lines; +} + +static u16 GetActiveLines_(ConsoleHandle console) { + u16 lines = GetRingUsedLines_(console); + if (console->printXPos != 0) { + lines += 1; + } + + return lines; +} + +static void DoDrawString_(ConsoleHandle console, u32 printLine, const u8 *str, nw4r::ut::TextWriterBase *writer) { + if (writer != nullptr) { + writer->Printf("%s\n", str); + } else { + s32 height = console->viewPosY + printLine * 10; + db::DirectPrint_DrawString(console->viewPosX, height, false, "%s\n", + str); + } +} + + +static void DoDrawConsole_(ConsoleHandle console, nw4r::ut::TextWriterBase *writer) { + // I guess we don't care if locking the mutex fails?? + TryLockMutex_(&sMutex); + + s32 viewOffset = console->viewTopLine - console->ringTopLineCnt; + u16 line; + u16 printLines = 0; + u16 topLine; + + if (viewOffset < 0) { + viewOffset = 0; + } else if (viewOffset > GetActiveLines_(console)) { + goto err; + } + + line = console->ringTop + viewOffset; + if ( line >= console->height ) + { + line -= console->height; + } + + topLine = console->printTop + ((console->printXPos > 0) ? 1 : 0); + if (topLine == console->height) { + topLine = 0; + } + + while (line != topLine) { + DoDrawString_(console, printLines, GetTextPtr_(console, line, 0), writer); + printLines++; + line++; + if (line == console->height) { + if ((console->attr & 2) != 0) { + break; + } + line = 0; + } + if (printLines >= console->viewLines) { + break; + } + } + +err: + UnlockMutex_(&sMutex); +} + +void Console_DrawDirect(ConsoleHandle console) { + if (DirectPrint_IsActive() && console->isVisible) { + DirectPrint_EraseXfb(console->viewPosX - 6, console->viewPosY - 3, console->width * 6 + 12, + console->viewLines * 10 + 4); + DoDrawConsole_(console, nullptr); + DirectPrint_StoreCache(); + } +} + + +static void TerminateLine_(ConsoleHandle console) { + *GetTextPtr_(console, console->printTop, console->printXPos) = '\0'; +} + +static u32 GetTabSize_(ConsoleHandle console) { + s32 tab = (console->attr & 12) >> 2; + return 2 << tab; +} + +static u32 CodeWidth_(const u8 *p) { + return (*p >= 0x81) ? 2 : 1; +} + +static u32 PutChar_(ConsoleHandle console, const u8 *str, u8 *dstPtr) { + u32 codeWidth; + u32 count; + + codeWidth = CodeWidth_(str); + if (console->printXPos + codeWidth > console->width) { + return 0; + } else { + console->printXPos += codeWidth; + for (count = codeWidth; count > 0; count--) { + *dstPtr++ = *str++; + } + return codeWidth; + } +} + +static u8 *PutTab_(ConsoleHandle console, u8 *dstPtr) { + u32 tabWidth = GetTabSize_(console); + do { + *dstPtr++ = ' '; + console->printXPos++; + if (console->printXPos >= console->width) { + break; + } + } while ((console->printXPos & (tabWidth - 1)) != 0); + return dstPtr; +} + +static u8 *SearchEndOfLine_(const u8 *str) { + while (*str != '\n' && *str != '\0') { + str++; + } + return (u8 *)str; +} + +static u8 *NextLine_(ConsoleHandle console) { + *GetTextPtr_(console, console->printTop, console->printXPos) = '\0'; + console->printXPos = 0; + console->printTop++; + if (console->printTop == console->height && (console->attr & 2) == 0) { + console->printTop = 0; + } + + if (console->printTop == console->ringTop) { + console->ringTopLineCnt++; + if (++console->ringTop == console->height) { + console->ringTop = 0; + } + } + + return GetTextPtr_(console, console->printTop, 0); +} + +static void PrintToBuffer_(ConsoleHandle console, const u8 *str) { + BOOL enabled = OSDisableInterrupts(); + u8 *storePtr = GetTextPtr_(console, console->printTop, console->printXPos); + + while (*str != '\0') { + if ((console->attr & 2) && console->printTop == console->height) { + break; + } + + while (*str != '\0') { + bool newLineFlag = false; + if (*str == '\n') { + str++; + storePtr = NextLine_(console); + break; + } else if (*str == '\t') { + str++; + storePtr = PutTab_(console, storePtr); + } else { + u32 bytes = PutChar_(console, str, storePtr); + if (bytes > 0) { + str += bytes; + storePtr += bytes; + } else { + newLineFlag = true; + } + } + + if (console->printXPos >= console->width) { + newLineFlag = true; + } + + if (newLineFlag) { + if ((console->attr & 1) != 0) { + str = SearchEndOfLine_(str); + } else { + if (*str == '\n') { + str++; + } + storePtr = NextLine_(console); + } + break; + } + + if (*str == '\0') { + TerminateLine_(console); + } + } + } + + OSRestoreInterrupts(enabled); +} + +static void Console_PrintString_(ConsoleOutputType type, ConsoleHandle console, const u8 *str) { + if ((type & CONSOLE_OUTPUT_TERMINAL) != 0) { + OSReport("%s", str); + } + if ((type & CONSOLE_OUTPUT_DISPLAY) != 0) { + PrintToBuffer_(console, str); + } +} + +void Console_VFPrintf(ConsoleOutputType type, ConsoleHandle console, const char *format, va_list vlist) { + if (TryLockMutex_(&sMutex)) { + vsnprintf((char *)buf, sizeof(buf), format, vlist); + Console_PrintString_(type, console, buf); + + UnlockMutex_(&sMutex); + } +} +void Console_Printf(ConsoleHandle console, const char *format, ...) { + va_list args; + va_start(args, format); + + if (TryLockMutex_(&sMutex)) { + vsnprintf((char *)buf, sizeof(buf), format, args); + OSReport("%s", buf); + PrintToBuffer_(console, buf); + + UnlockMutex_(&sMutex); + } +} + +s32 Console_GetTotalLines(ConsoleHandle console) { + s32 count; + BOOL enabled = OSDisableInterrupts(); + + count = console->ringTopLineCnt + GetActiveLines_(console); + + OSRestoreInterrupts(enabled); + + return count; +} + +} // namespace db +} // namespace nw4r diff --git a/src/nw4r/db/db_exception.cpp b/src/nw4r/db/db_exception.cpp new file mode 100644 index 00000000..2a2b77ae --- /dev/null +++ b/src/nw4r/db/db_exception.cpp @@ -0,0 +1,498 @@ +#include +#include +#include +#include +#include +#include + +namespace nw4r { +namespace db { + +struct ExceptionStruct { + OSThread thread; + OSMessageQueue queue; + void *frameMemory; + u32 stackAddress; + ConsoleHandle consoleHandle; + const GXRenderModeObj *exceptionRenderObj; + bool (*exceptionCallback)(detail::ConsoleHead *, void *); + void *exceptionCallbackArgs; + u32 MSR_COPY; + u32 FPCSR_COPY; + u16 exceptionDisplayInfo; +}; + +static OSMessage sMessageBuffer[1]; +static struct ExceptionStruct sException; + +static u8 sThreadBuffer[0x4000] ALIGN(0x20); + +extern "C" u32 lbl_80574960; + +const char *CPU_EXP_NAME[] = { + "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", +}; + + + +void *RunThread_(void *); +// TODO u8 vs u16 +void ErrorHandler_(u16, OSContext *, u32, u32); + +void Exception_Init() { + memset(&sException, 0, sizeof(struct ExceptionStruct)); + sException.exceptionCallback = nullptr; + sException.consoleHandle = nullptr; + sException.exceptionDisplayInfo = 0x21; + sException.frameMemory = nullptr; + sException.exceptionRenderObj = nullptr; + OSCreateThread(&sException.thread, RunThread_, nullptr, sThreadBuffer + 0x4000, 0x4000, 0, 1); + OSInitMessageQueue(&sException.queue, sMessageBuffer, 1); + OSResumeThread(&sException.thread); + OSSetErrorHandler(2, ErrorHandler_); + OSSetErrorHandler(3, ErrorHandler_); + OSSetErrorHandler(5, ErrorHandler_); + OSSetErrorHandler(15, ErrorHandler_); + lbl_80574960 = 0; + OSSetErrorHandler(16, nullptr); +} +extern "C" u32 PPCMfmsr(); +extern "C" void PPCMtmsr(u32); +extern "C" void OSFillFPUContext(OSContext *ctx); +extern "C" void fn_803AA2E0(u32, u32, u32, u32); + +static void DumpException_(const ExceptionCallbackParam *); + +void ErrorHandler_(u16 error, OSContext *ctx, u32 dsisr, u32 dar) { + sException.MSR_COPY = PPCMfmsr(); + sException.FPCSR_COPY = ctx->fpscr; + OSFillFPUContext(ctx); + OSSetErrorHandler(error, nullptr); + if (error == 0xf) { + fn_803AA2E0(0, 0, 0, 3); + fn_803AA2E0(1, 0, 0, 3); + fn_803AA2E0(2, 0, 0, 3); + fn_803AA2E0(3, 0, 0, 3); + } + ExceptionCallbackParam param; + + param.error = error; + param.ctx = ctx; + param.dsisr = dsisr; + param.dar = dar; + OSSendMessage(&sException.queue, ¶m, 1); + if (OSGetCurrentThread() == nullptr) { + VISetPreRetraceCallback(nullptr); + VISetPostRetraceCallback(nullptr); + PPCMtmsr(PPCMfmsr() | 2); + DumpException_(¶m); + } + while (OSEnableScheduler() > 0) {} + OSYieldThread(); + OSDisableScheduler(); +} + +void *RunThread_(void *) { + OSMessage message; + + u32 msr = PPCMfmsr(); + PPCMtmsr(msr & ~(0x800 | 0x100)); + OSReceiveMessage(&sException.queue, &message, 1); + OSDisableInterrupts(); + VISetPreRetraceCallback(nullptr); + VISetPostRetraceCallback(nullptr); + if (sException.consoleHandle != nullptr) { + VISetBlack(false); + VIFlush(); + } + DumpException_((const ExceptionCallbackParam *)message); + return nullptr; +} + +static void PrintContext_(u16, const OSContext *, u32, u32); +static void WaitTime_(s32 time); +static void Console_SetVisible(ConsoleHandle, bool); +static void Console_SetViewBaseLine(ConsoleHandle, s32); +static u32 Console_GetBufferHeadLine(ConsoleHandle); + +static void DrawConsoleEndless_(ConsoleHandle console) { + s32 lineCnt = Console_GetBufferHeadLine(console); + while (true) { + if (lineCnt >= Console_GetTotalLines(console)) { + lineCnt = console->ringTopLineCnt; + } + Console_SetViewBaseLine(sException.consoleHandle, lineCnt); + Console_DrawDirect(console); + + WaitTime_(200); + + lineCnt++; + } +} + + + +static void DumpException_(const ExceptionCallbackParam *param) { + u16 error = param->error; + OSContext *ctx = param->ctx; + u32 dsisr = param->dsisr; + u32 dar = param->dar; + + if (error < 0x11) { + sException.stackAddress = ctx->gprs[1]; + } + if (sException.consoleHandle != nullptr) { + sException.frameMemory = detail::DirectPrint_SetupFB(sException.exceptionRenderObj); + } + + while (true) { + PrintContext_(error, ctx, dsisr, dar); + if (sException.consoleHandle != nullptr && DirectPrint_IsActive()) { + Console_DrawDirect(sException.consoleHandle); + } + + if (sException.exceptionCallback != nullptr) { + u16 info = sException.exceptionDisplayInfo; + do { + if (!(sException.exceptionCallback)(sException.consoleHandle, sException.exceptionCallbackArgs)) { + return; + } + } while (info == sException.exceptionDisplayInfo); + } else if (sException.consoleHandle != nullptr) { + DrawConsoleEndless_(sException.consoleHandle); + } else { + break; + } + } +} + +static void Exception_Printf_(const char *format, ...) { + const GXRenderModeObj *obj = sException.exceptionRenderObj; + + va_list args; + va_start(args, fmt); + OSVReport(format, args); + va_end(args); + + if (sException.consoleHandle != nullptr) { + void *frameBuf = VIGetCurrentFrameBuffer(); + DirectPrint_ChangeXfb(frameBuf, obj->fbWidth, obj->xfbHeight); + + va_list args; + va_start(args, fmt); + Console_VFPrintf(CONSOLE_OUTPUT_DISPLAY, sException.consoleHandle, format, args); + va_end(args); + } +} + +static void ShowStackTrace_(u32); +static void ShowMainInfo_(u16, const OSContext *, u32, u32); +static void ShowGPR_(const OSContext *); +static void ShowSRR0Map_(const OSContext *); +static void ShowGPRMap_(const OSContext *); +static void ShowFloat_(const OSContext *); +static bool ShowMapInfoSubroutine_(u32 address, bool arg); + +static void PrintContext_(u16 error, const OSContext *context, u32 dsisr, u32 dar) { + if (error < 0x11) { + Exception_Printf_("******** EXCEPTION OCCURRED! ********\nFrameMemory:%XH\n", sException.frameMemory); + } else { + Exception_Printf_("******** USER HALT ********\nFrameMemory:%XH\n", sException.frameMemory); + } + + if (sException.exceptionDisplayInfo & 0x1) { + Exception_Printf_("---MainInfo---\n"); + ShowMainInfo_(error, context, dsisr, dar); + } + + if (sException.exceptionDisplayInfo & 0x2) { + Exception_Printf_("---EXCEPTION_INFO_GPR---\n"); + ShowGPR_(context); + } + + if (sException.exceptionDisplayInfo & 0x8) { + Exception_Printf_("---EXCEPTION_INFO_SRR0MAP---\n"); + ShowSRR0Map_(context); + } + + if (sException.exceptionDisplayInfo & 0x4) { + Exception_Printf_("---EXCEPTION_INFO_GPRMAP---\n"); + ShowGPRMap_(context); + } + + if (sException.exceptionDisplayInfo & 0x10) { + Exception_Printf_("---EXCEPTION_INFO_FPR---\n"); + ShowFloat_(context); + Exception_Printf_(" MSR:%08XH FPSCR:%08XH\n", sException.MSR_COPY, sException.FPCSR_COPY); + } + + if (sException.exceptionDisplayInfo & 0x20) { + Exception_Printf_("---EXCEPTION_INFO_TRACE---\n"); + ShowStackTrace_(sException.stackAddress); + } + + Exception_Printf_("--------------------------------\n"); +} + +static bool IsValidStackAddr_(u32 stackAddress) { + if (stackAddress == 0 || stackAddress == 0xFFFFFFFF) { + return false; + } else if (OS_MEM_IS_MEM1(stackAddress)) { + if ((stackAddress & 0x0fffffff) >= OSGetPhysicalMem1Size()) { + return false; + } + } else if (OS_MEM_IS_MEM2(stackAddress)) { + if ((stackAddress & 0x0fffffff) >= OSGetPhysicalMem2Size()) { + return false; + } + } else { + return false; + } + + return true; +} + +static void ShowStackTrace_(u32 stackAddress) { + Exception_Printf_("-------------------------------- TRACE\n"); + Exception_Printf_("Stack Address: %08X\n", stackAddress); + Exception_Printf_("LR save\n"); + + u32 i; + u32 *ptr = (u32 *)stackAddress; + for (i = 0; i < 16; i++) { + if (!IsValidStackAddr_((u32)ptr)) { + break; + } + Exception_Printf_("%08X ", ptr[1]); + u32 fp = ptr[1]; + // TODO arg + if (!ShowMapInfoSubroutine_(fp, true)) { + Exception_Printf_("\n"); + } + ptr = (u32 *)*ptr; + } +} + +void ShowMainInfo_(u16 error, const OSContext *context, u32 dsisr, u32 dar) { + if (error < 0x11) { + Exception_Printf_("CONTEXT:%08XH (%s EXCEPTION)\n", context, CPU_EXP_NAME[error]); + } else { + Exception_Printf_("CONTEXT:%08XH\n", context); + } + /* floating point error */ + if (error == 0x10) { + u32 uVar1 = sException.FPCSR_COPY; + uVar1 &= (((uVar1 & 0xf8) << 0x16) | 0x01f80700); + if ((uVar1 & 0x20000000) != 0) { + Exception_Printf_(" FPE: Invalid operation\n"); + if ((sException.FPCSR_COPY & 0x1000000) != 0) { + Exception_Printf_(" SNaN\n"); + } + if ((sException.FPCSR_COPY & 0x800000) != 0) { + Exception_Printf_(" Infinity - Infinity\n"); + } + if ((sException.FPCSR_COPY & 0x400000) != 0) { + Exception_Printf_(" Infinity / Infinity\n"); + } + if ((sException.FPCSR_COPY & 0x200000) != 0) { + Exception_Printf_(" 0 / 0\n"); + } + if ((sException.FPCSR_COPY & 0x100000) != 0) { + Exception_Printf_(" Infinity * 0\n"); + } + if ((sException.FPCSR_COPY & 0x80000) != 0) { + Exception_Printf_(" Invalid compare\n"); + } + if ((sException.FPCSR_COPY & 0x400) != 0) { + Exception_Printf_(" Software request\n"); + } + if ((sException.FPCSR_COPY & 0x200) != 0) { + Exception_Printf_(" Invalid square root\n"); + } + if ((sException.FPCSR_COPY & 0x100) != 0) { + Exception_Printf_(" Invalid integer convert\n"); + } + } + if ((uVar1 & 0x10000000) != 0) { + Exception_Printf_(" FPE: Overflow\n"); + } + if ((uVar1 & 0x8000000) != 0) { + Exception_Printf_(" FPE: Underflow\n"); + } + if ((uVar1 & 0x4000000) != 0) { + Exception_Printf_(" FPE: Zero division\n"); + } + if ((uVar1 & 0x2000000) != 0) { + Exception_Printf_(" FPE: Inexact result\n"); + } + } + Exception_Printf_("SRR0: %08XH SRR1:%08XH\n", context->srr0, context->srr1); + Exception_Printf_("DSISR: %08XH DAR: %08XH\n", dsisr, dar); +} + +void ShowGPR_(const OSContext *ctx) { + Exception_Printf_("-------------------------------- GPR\n"); + for (int i = 0; i < 10; i++) { + Exception_Printf_("R%02d:%08XH R%02d:%08XH R%02d:%08XH\n", i, ctx->gprs[i], i + 11, ctx->gprs[i + 11], i + 22, + ctx->gprs[i + 22]); + } + Exception_Printf_("R%02d:%08XH R%02d:%08XH\n", 10, ctx->gprs[10], 21, ctx->gprs[21]); +} + +void ShowGPRMap_(const OSContext *ctx) { + bool shownAny = false; + Exception_Printf_("-------------------------------- GPRMAP\n"); + for (int i = 0; i <= 31; i++) { + u32 address = ctx->gprs[i]; + if ((address < 0x80000000) || (0x82ffffff < address)) { + continue; + } + shownAny = true; + Exception_Printf_("R%02d: %08XH ", i, address); + // TODO arg + if (!ShowMapInfoSubroutine_(address, true)) { + Exception_Printf_(" no information\n"); + } + } + + if (!shownAny) { + Exception_Printf_(" no register which seem to address.\n"); + } +} + +void ShowSRR0Map_(const OSContext *ctx) { + Exception_Printf_("-------------------------------- SRR0MAP\n"); + u32 address = ctx->srr0; + if (!((address < 0x80000000) || (0x82ffffff < address))) { + Exception_Printf_("SRR0: %08XH ", address); + // TODO arg + if (!ShowMapInfoSubroutine_(address, true)) { + Exception_Printf_(" no information\n"); + } + } +} + +// 804ca0e4 +extern "C" int __fpclassifyf(float val); + +static void ShowFloatSub_(s32 reg, f32 val); + +void ShowFloat_(const OSContext *ctx) { + Exception_Printf_("-------------------------------- FPR\n"); + for (int i = 0; i < 10; i++) { + ShowFloatSub_(i, ctx->fprs[i]); + Exception_Printf_(" "); + ShowFloatSub_(i + 11, ctx->fprs[i + 11]); + Exception_Printf_(" "); + ShowFloatSub_(i + 22, ctx->fprs[i + 22]); + Exception_Printf_("\n"); + } + ShowFloatSub_(10, ctx->fprs[10]); + Exception_Printf_(" "); + ShowFloatSub_(21, ctx->fprs[21]); + + Exception_Printf_("\n"); +} + +void ShowFloatSub_(s32 reg, f32 val) { + if (__fpclassifyf(val) == 1) { + Exception_Printf_("F%02d: Nan ", reg); + } else { + if (__fpclassifyf(val) == 2) { + if ((reinterpret_cast(val) & 0x80) != 0) { + Exception_Printf_("F%02d:+Inf ", reg); + } else { + Exception_Printf_("F%02d:-Inf ", reg); + } + } else if (val == 0.0f) { + Exception_Printf_("F%02d: 0.0 ", reg); + } else { + Exception_Printf_("F%02d:%+.3E", reg, val); + } + } +} + +static void SetFPException_(u32) { + // TODO +} + +bool ShowMapInfoSubroutine_(u32 address, bool arg) { + if ((address < 0x80000000) || (0x82ffffff < address)) { + return false; + } else { + u8 acStack_124[260]; + if (nw4r::db::MapFile_QuerySymbol(address, acStack_124, sizeof(acStack_124))) { + Exception_Printf_("%s\n", acStack_124); + return true; + } else { + return false; + } + } +} + +ConsoleHandle Exception_SetConsole(ConsoleHandle console, const GXRenderModeObj *renderObj) { + ConsoleHandle old = sException.consoleHandle; + sException.exceptionRenderObj = renderObj; + sException.consoleHandle = console; + return old; +} + +ConsoleHandle Exception_GetConsole() { + return sException.consoleHandle; +} + +void Exception_SetUserCallback(bool (*callback)(detail::ConsoleHead *, void *), void *args) { + sException.exceptionCallback = callback; + sException.exceptionCallbackArgs = args; +} + + +u16 Exception_SetDisplayInfo(u16 newInfo) { + u16 old = sException.exceptionDisplayInfo; + sException.exceptionDisplayInfo = newInfo; + return old; +} + + +static void WaitTime_(s32 time) { + s64 t1 = OSGetTime(); + s64 t2; + do { + t2 = OSGetTime(); + } while ((t2 - t1) / ((OS_BUS_CLOCK_SPEED / 4) / 1000) < time); +} +/* +void DrawConsoleEndless_(detail::ConsoleHead *) { + // TODO +} +*/ +static void Console_SetVisible(detail::ConsoleHead *, bool) { + // TODO +} + +static void Console_SetViewBaseLine(detail::ConsoleHead *console, s32 line) { + console->viewTopLine = line; +} + +static u32 Console_GetBufferHeadLine(detail::ConsoleHead *console) { + return console->ringTopLineCnt; +} + +} // namespace db +} // namespace nw4r diff --git a/src/nw4r/db/db_mapFile.cpp b/src/nw4r/db/db_mapFile.cpp index ad52c4fa..4546487d 100644 --- a/src/nw4r/db/db_mapFile.cpp +++ b/src/nw4r/db/db_mapFile.cpp @@ -17,7 +17,7 @@ static s32 sMapBufMaxSize = 0x200; static u8 *sMapBuf = dvdReadBuf; static s32 sMapBufOffset = -1; -static void MapFile_Append(MapFile *file) { +static void MapFile_Append_(MapFile *file) { if (sMapFileList == nullptr) { sMapFileList = file; return; @@ -40,7 +40,7 @@ MapFileHandle MapFile_RegistOnDvd(void *buf, const char *path, const OSModuleInf file->fileEntry = DVDConvertPathToEntrynum(path); file->next = nullptr; - MapFile_Append(file); + MapFile_Append_(file); return file; } From 419097a1923e49258c1586d47dc2c76ba1a2c54d Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 25 May 2024 14:04:37 +0200 Subject: [PATCH 07/11] Event RAII --- config/SOUE01/splits.txt | 2 +- config/SOUE01/symbols.txt | 6 +++--- include/toBeSorted/event.h | 2 ++ src/d/a/d_a_base.cpp | 5 ++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 12e7156d..ba439c09 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -29,7 +29,7 @@ toBeSorted/save_manager.cpp: d/a/d_a_base.cpp: .text start:0x8002C3A0 end:0x8002DE40 - .data start:0x80501544 end:0x805015B8 + .data start:0x80501538 end:0x805015B8 .sdata start:0x80571920 end:0x80571930 .sbss start:0x80575080 end:0x80575098 .sdata2 start:0x80576C88 end:0x80576C8C diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index dfe6eb41..66176267 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -3562,7 +3562,7 @@ fn_8009EB10 = .text:0x8009EB10; // type:function size:0xC fn_8009EB20 = .text:0x8009EB20; // type:function size:0x8 fn_8009EB30 = .text:0x8009EB30; // type:function size:0x36C fn_8009EEA0 = .text:0x8009EEA0; // type:function size:0x53C -fn_8009F3E0 = .text:0x8009F3E0; // type:function size:0x470 +alsoSetAsCurrentEvent = .text:0x8009F3E0; // type:function size:0x470 fn_8009F850 = .text:0x8009F850; // type:function size:0x134 fn_8009F990 = .text:0x8009F990; // type:function size:0x80 fn_8009FA10 = .text:0x8009FA10; // type:function size:0x8 @@ -3596,11 +3596,11 @@ fn_800A09B0 = .text:0x800A09B0; // type:function size:0x1D0 fn_800A0B80 = .text:0x800A0B80; // type:function size:0x10 fn_800A0B90 = .text:0x800A0B90; // type:function size:0x10 fn_800A0BA0 = .text:0x800A0BA0; // type:function size:0x94 -fn_800A0C40 = .text:0x800A0C40; // type:function size:0xEC +__ct__5EventFPcUlUlPvPv = .text:0x800A0C40; // type:function size:0xEC fn_800A0D30 = .text:0x800A0D30; // type:function size:0xEC fn_800A0E20 = .text:0x800A0E20; // type:function size:0x208 fn_800A1030 = .text:0x800A1030; // type:function size:0x208 -fn_800A1240 = .text:0x800A1240; // type:function size:0x40 +__dt__5EventFv = .text:0x800A1240; // type:function size:0x40 fn_800A1280 = .text:0x800A1280; // type:function size:0x2E4 fn_800A1570 = .text:0x800A1570; // type:function size:0x84 fn_800A1600 = .text:0x800A1600; // type:function size:0x5C diff --git a/include/toBeSorted/event.h b/include/toBeSorted/event.h index 0260693c..e87958a2 100644 --- a/include/toBeSorted/event.h +++ b/include/toBeSorted/event.h @@ -15,7 +15,9 @@ public: void *callback2; public: + /** 0x800A0C40 */ Event(char *eventName, u32 unk, u32 eventFlags, void *callback1, void *callback2); + /** 0x800A1240 */ virtual ~Event(); }; diff --git a/src/d/a/d_a_base.cpp b/src/d/a/d_a_base.cpp index 51e2096f..2f74cb93 100644 --- a/src/d/a/d_a_base.cpp +++ b/src/d/a/d_a_base.cpp @@ -552,9 +552,8 @@ void dAcBase_c::unkVirtFunc_0x6C() {} // 8002dba0 void dAcBase_c::doInteraction(s32 param) { if (param == 4 || param == 5 || param == 12) { - Event *event = &Event("DefaultTalk", 400, 0x100001, nullptr, nullptr); - alsoSetAsCurrentEvent(this, event, nullptr); - event->~Event(); + Event event = Event("DefaultTalk", 400, 0x100001, nullptr, nullptr); + alsoSetAsCurrentEvent(this, &event, nullptr); } } From ed2f569a891fe0885b5d4d0b36b0ff19affb8031 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 25 May 2024 14:26:56 +0200 Subject: [PATCH 08/11] Small type improvements --- config/SOUE01/symbols.txt | 14 +++++++------- include/d/a/obj/d_a_obj_base.h | 2 +- include/toBeSorted/file_manager.h | 8 ++++---- src/d/a/d_a_base.cpp | 20 ++++++-------------- src/toBeSorted/file_manager.cpp | 8 ++++---- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 66176267..51806392 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -343,10 +343,10 @@ setDowsingSlotIdx__11FileManagerFUc = .text:0x8000B9F0; // type:function size:0x getDowsingSlotIdx__11FileManagerFv = .text:0x8000BA20; // type:function size:0x44 setBeaconPos__11FileManagerFUlUlP7mVec3_c = .text:0x8000BA70; // type:function size:0x104 getBeaconPos__11FileManagerFUlUl = .text:0x8000BB80; // type:function size:0xEC -setEnemyKillCount__11FileManagerFUlUs = .text:0x8000BC70; // type:function size:0x70 -getEnemyKillCount__11FileManagerFUl = .text:0x8000BCE0; // type:function size:0x80 -setHitCountFromEnemy__11FileManagerFUlUs = .text:0x8000BD60; // type:function size:0x70 -getHitCountFromEnemy__11FileManagerFUl = .text:0x8000BDD0; // type:function size:0x80 +setEnemyKillCount__11FileManagerFUcUs = .text:0x8000BC70; // type:function size:0x70 +getEnemyKillCount__11FileManagerFUc = .text:0x8000BCE0; // type:function size:0x80 +setHitCountFromEnemy__11FileManagerFUcUs = .text:0x8000BD60; // type:function size:0x70 +getHitCountFromEnemy__11FileManagerFUc = .text:0x8000BDD0; // type:function size:0x80 setLoadRoomT1_FileB__11FileManagerFs = .text:0x8000BE50; // type:function size:0x30 getLoadRoomT1_FileB__11FileManagerFv = .text:0x8000BE80; // type:function size:0xC setEntranceT1_FileB__11FileManagerFUc = .text:0x8000BE90; // type:function size:0x30 @@ -10963,7 +10963,7 @@ fn_801B3720 = .text:0x801B3720; // type:function size:0x4 fn_801B3730 = .text:0x801B3730; // type:function size:0x200 fn_801B3930 = .text:0x801B3930; // type:function size:0x30 fn_801B3960 = .text:0x801B3960; // type:function size:0x10 -fn_801B3970 = .text:0x801B3970; // type:function size:0x10 +GetRoomByIndex__11RoomManagerFi = .text:0x801B3970; // type:function size:0x10 fn_801B3980 = .text:0x801B3980; // type:function size:0x114 fn_801B3AA0 = .text:0x801B3AA0; // type:function size:0x134 fn_801B3BE0 = .text:0x801B3BE0; // type:function size:0x78 @@ -10987,7 +10987,7 @@ fn_801B42D0 = .text:0x801B42D0; // type:function size:0x50 fn_801B4320 = .text:0x801B4320; // type:function size:0x54 fn_801B4380 = .text:0x801B4380; // type:function size:0xA0 fn_801B4420 = .text:0x801B4420; // type:function size:0x9C -fn_801B44C0 = .text:0x801B44C0; // type:function size:0x50 +changeLoadedEntities__11RoomManagerFP11RoomManagerUlb = .text:0x801B44C0; // type:function size:0x50 fn_801B4510 = .text:0x801B4510; // type:function size:0x3C fn_801B4550 = .text:0x801B4550; // type:function size:0x6C fn_801B45C0 = .text:0x801B45C0; // type:function size:0xAC @@ -40024,7 +40024,7 @@ lbl_80575785 = .sbss:0x80575785; // type:object size:0x1 lbl_80575786 = .sbss:0x80575786; // type:object size:0x1 data:byte lbl_80575787 = .sbss:0x80575787; // type:object size:0x1 data:byte lbl_80575788 = .sbss:0x80575788; // type:object size:0x4 data:4byte -lbl_8057578C = .sbss:0x8057578C; // type:object size:0x4 data:4byte +LINK__7dPlayer = .sbss:0x8057578C; // type:object size:0x4 data:4byte lbl_80575790 = .sbss:0x80575790; // type:object size:0x4 data:4byte lbl_80575794 = .sbss:0x80575794; // type:object size:0x4 data:4byte lbl_80575798 = .sbss:0x80575798; // type:object size:0x4 data:4byte diff --git a/include/d/a/obj/d_a_obj_base.h b/include/d/a/obj/d_a_obj_base.h index 37153e07..ed6d5abd 100644 --- a/include/d/a/obj/d_a_obj_base.h +++ b/include/d/a/obj/d_a_obj_base.h @@ -15,7 +15,7 @@ public: char _0[4]; f32 unkfloat; char _1[12]; - s16 targetFiTextId; + u16 targetFiTextId; u8 unkByteTargetFiRelated; mVec3_c poscopy1; mVec3_c poscopy2; diff --git a/include/toBeSorted/file_manager.h b/include/toBeSorted/file_manager.h index 858de5a4..ee134f89 100644 --- a/include/toBeSorted/file_manager.h +++ b/include/toBeSorted/file_manager.h @@ -162,10 +162,10 @@ public: /* 8000BA70 */ void setBeaconPos(u32 beaconArea, u32 beaconNum, mVec3_c *pos); /* 8000BB80 */ mVec3_c *getBeaconPos(u32 beaconArea, u32 beaconNum); - /* 8000BC70 */ void setEnemyKillCount(u32 enemy, u16 killCount); - /* 8000BCE0 */ s16 getEnemyKillCount(u32 enemy); - /* 8000BD60 */ void setHitCountFromEnemy(u32 enemy, u16 hitCount); - /* 8000BDD0 */ u16 getHitCountFromEnemy(u32 enemy); + /* 8000BC70 */ void setEnemyKillCount(u8 enemy, u16 killCount); + /* 8000BCE0 */ u16 getEnemyKillCount(u8 enemy); + /* 8000BD60 */ void setHitCountFromEnemy(u8 enemy, u16 hitCount); + /* 8000BDD0 */ u16 getHitCountFromEnemy(u8 enemy); /* 8000BE50 */ void setLoadRoomT1_FileB(s16 roomId); /* 8000BE80 */ s16 getLoadRoomT1_FileB(); diff --git a/src/d/a/d_a_base.cpp b/src/d/a/d_a_base.cpp index 2f74cb93..87367333 100644 --- a/src/d/a/d_a_base.cpp +++ b/src/d/a/d_a_base.cpp @@ -501,10 +501,7 @@ dAcBase_c *dAcBase_c::createActor(ProfileName actorId, u32 actorParams1, mVec3_c actorRoomid = roomid; } - u32 newParams2 = -1; - if (actorParams2 != 0) { - newParams2 = getParams2_ignoreLower(); - } + u32 newParams2 = actorParams2 != 0 ? getParams2_ignoreLower() : -1; setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, 0xFF, nullptr); @@ -532,10 +529,7 @@ dAcBase_c *dAcBase_c::createActorStage(ProfileName actorId, u32 actorParams1, mV actorRoomid = roomid; } - u32 newParams2 = -1; - if (actorParams2 != 0) { - newParams2 = getParams2_ignoreLower(); - } + u32 newParams2 = actorParams2 != 0 ? getParams2_ignoreLower() : -1; setTempCreateParams(actorPosition, actorRotation, actorScale, actorRoomid, newParams2, (dAcBase_c *)actorRef, 0, -1, 0xFF, nullptr); @@ -561,19 +555,17 @@ void dAcBase_c::doInteraction(s32 param) { // 8002dc20 void dAcBase_c::FUN_8002dc20(s16 *, s16 *) {} -// This whole function gets compiled to just a `blr` -// Not sure how to make this work as expected // 8002dc50 void dAcBase_c::incrementKillCounter() { dAcObjBase_c *object = (dAcObjBase_c *)this; // Probably wrong - FileManager *fileMgr = FileManager::sInstance; if (group_type == ACTOR && object->unkByteTargetFiRelated == 1) { - s16 killCounterId = object->targetFiTextId; + int killCounterId = object->targetFiTextId; - if (killCounterId < 91 && killCounterId & 0x300 == 0) { - s16 killCount = fileMgr->getEnemyKillCount(killCounterId & 0xFF); + if (killCounterId < 91 && (killCounterId & 0x300) == 0) { + FileManager *fileMgr = FileManager::sInstance; + u16 killCount = fileMgr->getEnemyKillCount(killCounterId) + 1; fileMgr->setEnemyKillCount(killCounterId, killCount); } } diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index d027a931..d6bbd9a9 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -210,10 +210,10 @@ inline void strnsth(char *dest, const char *src, size_t max_len) { /* 8000BA70 */ void FileManager::setBeaconPos(u32 beaconArea, u32 beaconNum, mVec3_c *pos) {} /* 8000BB80 */ mVec3_c *FileManager::getBeaconPos(u32 beaconArea, u32 beaconNum) {} -/* 8000BC70 */ void FileManager::setEnemyKillCount(u32 enemy, u16 killCount) {} -/* 8000BCE0 */ s16 FileManager::getEnemyKillCount(u32 enemy) {} -/* 8000BD60 */ void FileManager::setHitCountFromEnemy(u32 enemy, u16 hitCount) {} -/* 8000BDD0 */ u16 FileManager::getHitCountFromEnemy(u32 enemy) {} +/* 8000BC70 */ void FileManager::setEnemyKillCount(u8 enemy, u16 killCount) {} +/* 8000BCE0 */ u16 FileManager::getEnemyKillCount(u8 enemy) {} +/* 8000BD60 */ void FileManager::setHitCountFromEnemy(u8 enemy, u16 hitCount) {} +/* 8000BDD0 */ u16 FileManager::getHitCountFromEnemy(u8 enemy) {} /* 8000BE50 */ void FileManager::setLoadRoomT1_FileB(s16 roomId) {} /* 8000BE80 */ s16 FileManager::getLoadRoomT1_FileB() {} From 8ebf6d024b2bb739fdc7e1b54595d9b8d82e5c24 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 25 May 2024 16:33:37 -0400 Subject: [PATCH 09/11] mVec3_c rework to get copy working --- include/d/a/d_a_base.h | 26 ++++++++++++++------------ include/m/m_vec.h | 20 +++----------------- src/d/a/d_a_base.cpp | 26 ++++++++++---------------- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/include/d/a/d_a_base.h b/include/d/a/d_a_base.h index 796b669c..b705940e 100644 --- a/include/d/a/d_a_base.h +++ b/include/d/a/d_a_base.h @@ -93,27 +93,29 @@ protected: public: /* 8002c3b0 */ dAcBase_c(); - void setPostion(mVec3_c *r) { - position.set(r->x, r->y, r->z); + void setPostion(mVec3_c &r) { + position = r; } - void setScale(f32 x, f32 y, f32 z) { - scale.set(x, y, z); + void SetScale(mVec3_c &r) { + scale = r; } - void setScale(mVec3_c *r) { - scale.set(r->x, r->y, r->z); - } - void setRotation(mAng3_c *r) { - rotation = *r; + void SetRotation(mAng3_c &r) { + rotation = r; } void copyPosition() { - pos_copy.x = position.x; - pos_copy.y = position.y; - pos_copy.z = position.z; + pos_copy = position; + } + + const mVec3_c &GetPostion() const { + return position; } void copyRotation() { rot_copy = rotation; } + mVec3_c GetPostionDifference(const dAcBase_c *other) { + return position - other->position; + } public: // funcs found in TU diff --git a/include/m/m_vec.h b/include/m/m_vec.h index b182642e..1ea23afb 100644 --- a/include/m/m_vec.h +++ b/include/m/m_vec.h @@ -9,7 +9,7 @@ class mVec3_c : public EGG::Vector3f { public: /// @brief Constructs an empty vector. /* 80009ee0 */ mVec3_c() {} - /* 80007460 */ ~mVec3_c() {} + // /* 80007460 */ ~mVec3_c() {} /// @brief Constructs a vector from a float array. mVec3_c(const f32 *p) { @@ -17,6 +17,7 @@ public: y = p[1]; z = p[2]; } + mVec3_c(const mVec3_c &other) { x = other.x; y = other.y; @@ -30,15 +31,8 @@ public: z = fz; } - void set(f32 fx, f32 fy, f32 fz) { - x = fx; - y = fy; - z = fz; - } mVec3_c &operator=(const mVec3_c &r) { - x = r.x; - y = r.y; - z = r.z; + set(r.x, r.y, r.z); return *this; } @@ -86,14 +80,6 @@ public: return (const nw4r::math::VEC3 *)&x; } - /// @brief Augmented addition operator. - mVec3_c &operator+=(const mVec3_c &v) { - x += v.x; - y += v.y; - z += v.z; - return *this; - } - /// @brief Augmented subtraction operator. mVec3_c &operator-=(const mVec3_c &v) { x -= v.x; diff --git a/src/d/a/d_a_base.cpp b/src/d/a/d_a_base.cpp index 87367333..e61b938a 100644 --- a/src/d/a/d_a_base.cpp +++ b/src/d/a/d_a_base.cpp @@ -45,18 +45,18 @@ dAcBase_c::dAcBase_c() JStudio_actor = 0; someStr[0] = 0; - if (s_Create_Position != nullptr) { - position.set(s_Create_Position->x, s_Create_Position->y, s_Create_Position->z); + if (s_Create_Position) { + setPostion(*s_Create_Position); } - if (s_Create_Rotation != nullptr) { - rotation = *(s_Create_Rotation); + if (s_Create_Rotation) { + SetRotation(*s_Create_Rotation); } - if (s_Create_Scale != nullptr) { - setScale(s_Create_Scale->x, s_Create_Scale->y, s_Create_Scale->z); + if (s_Create_Scale) { + SetScale(*s_Create_Scale); } else { - setScale(1.0, 1.0, 1.0); + scale.set(1.0f, 1.0f, 1.0f); } if (s_Create_Parent != nullptr) { @@ -74,11 +74,7 @@ dAcBase_c::dAcBase_c() // 8002c530 dBase_c::~dBase_c() {} -dAcBase_c::~dAcBase_c() { - if (sound_source != nullptr) { - // call obj_sound dtor once defined - } -} +dAcBase_c::~dAcBase_c() {} void dAcBase_c::setTempCreateParams(mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, s32 roomId, u32 params2, dAcBase_c *parent, u8 subtype, s16 unkFlag, u8 viewClipIdx, ObjInfo *objInfo) { @@ -392,8 +388,7 @@ bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 // 8002d3e0 bool dAcBase_c::isWithinPlayerRadius(f32 radius) { - mVec3_c dist_diff = position - dPlayer::LINK->position; - + mVec3_c dist_diff = GetPostionDifference(dPlayer::LINK); return dist_diff.x * dist_diff.x + dist_diff.z * dist_diff.z < radius * radius; } @@ -559,12 +554,11 @@ void dAcBase_c::FUN_8002dc20(s16 *, s16 *) {} void dAcBase_c::incrementKillCounter() { dAcObjBase_c *object = (dAcObjBase_c *)this; // Probably wrong - if (group_type == ACTOR && object->unkByteTargetFiRelated == 1) { int killCounterId = object->targetFiTextId; if (killCounterId < 91 && (killCounterId & 0x300) == 0) { - FileManager *fileMgr = FileManager::sInstance; + FileManager *fileMgr = FileManager::sInstance; u16 killCount = fileMgr->getEnemyKillCount(killCounterId) + 1; fileMgr->setEnemyKillCount(killCounterId, killCount); } From 5029ef8dcf6b5fb09365a949a59895d93501557d Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 26 May 2024 05:06:11 -0400 Subject: [PATCH 10/11] getDistanceAndAngleToActor match with weird inline --- src/d/a/d_a_base.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/d/a/d_a_base.cpp b/src/d/a/d_a_base.cpp index e61b938a..770ce347 100644 --- a/src/d/a/d_a_base.cpp +++ b/src/d/a/d_a_base.cpp @@ -351,22 +351,27 @@ bool dAcBase_c::getDistanceToActor(dAcBase_c *actor, f32 distThresh, f32 *outDis return isWithinThreshhold; } +s32 doAbs(s16 val) { + return labs(val); +} // Similar weirdness as the above function. Also, r29->31 are initted in the wrong order? // 8002d290 bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist, s16 *outDiffAngleY, s16 *outDiffAngleX) { f32 distSquared = 3.402823e+38f; - s16 angleToActorY = 0; - s16 angleToActorX = 0; + s16 angleToActorY, angleToActorX; bool isWithinRange = false; + angleToActorY = 0; + angleToActorX = 0; + if (actor != nullptr) { distSquared = PSVECSquareDistance(position, actor->position); angleToActorY = targetAngleY(&position, &actor->position); angleToActorX = targetAngleX(&position, &actor->position); - if ((distSquared <= distThresh * distThresh) && (labs(rotation.y - angleToActorY) <= yAngle) && - (labs(rotation.x - angleToActorX) <= xAngle)) { + if ((distSquared <= distThresh * distThresh) && (doAbs(s32(rotation.y - angleToActorY)) <= yAngle) && + (doAbs(s32(rotation.x - angleToActorX)) <= xAngle)) { isWithinRange = true; } } From f612e9902fc8b7aacab368757d0d7efc9164006f Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Fri, 31 May 2024 19:30:35 -0400 Subject: [PATCH 11/11] name some data symbols --- config/SOUE01/symbols.txt | 16 ++++++++-------- src/nw4r/db/db_console.cpp | 29 ++++++++++++----------------- src/nw4r/db/db_exception.cpp | 6 ------ src/nw4r/db/db_mapFile.cpp | 8 ++++---- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index a825c204..b2398833 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -40877,8 +40877,8 @@ mDefaultTagProcessor__Q34nw4r2ut17TextWriterBase = .sbss:0x805765DC; // type: @GUARD@mDefaultTagProcessor__Q34nw4r2ut17TextWriterBase = .sbss:0x805765E0; // type:object size:0x1 scope:weak data:byte @GUARD@mDefaultTagProcessor__Q34nw4r2ut17TextWriterBase = .sbss:0x805765E1; // type:object size:0x1 scope:weak data:byte sInitialized__Q24nw4r2db = .sbss:0x805765E8; // type:object size:0x4 scope:local data:4byte -lbl_805765F0 = .sbss:0x805765F0; // type:object size:0x4 data:4byte -lbl_805765F4 = .sbss:0x805765F4; // type:object size:0x1 data:byte +sConsoleList__Q24nw4r2db = .sbss:0x805765F0; // type:object size:0x4 scope:local data:4byte +sInited__Q24nw4r2db = .sbss:0x805765F4; // type:object size:0x1 data:byte sMessageBuffer__Q24nw4r2db = .sbss:0x805765F8; // type:object size:0x8 sFileLength__Q24nw4r2db = .sbss:0x80576600; // type:object size:0x4 scope:local data:4byte sMapFileList__Q24nw4r2db = .sbss:0x80576604; // type:object size:0x4 scope:local data:4byte @@ -49351,12 +49351,12 @@ mLoadingTexture__Q34nw4r2ut10CharWriter = .bss:0x80636B58; // type:object size:0 @3896 = .bss:0x80636B74; // type:object size:0xC scope:local sFrameBufferInfo__Q24nw4r2db = .bss:0x80636B80; // type:object size:0x10 data:4byte sFrameBufferColor__Q24nw4r2db = .bss:0x80636B90; // type:object size:0x14 data:byte -lbl_80636BA8 = .bss:0x80636BA8; // type:object size:0x18 -lbl_80636BC0 = .bss:0x80636BC0; // type:object size:0x400 -lbl_80636FC0 = .bss:0x80636FC0; // type:object size:0x360 -lbl_80637320 = .bss:0x80637320; // type:object size:0x4000 -lbl_8063B320 = .bss:0x8063B320; // type:object size:0x200 -lbl_8063B520 = .bss:0x8063B520; // type:object size:0x3C +sMutex__Q24nw4r2db = .bss:0x80636BA8; // type:object size:0x18 +sStrBuf__Q24nw4r2db = .bss:0x80636BC0; // type:object size:0x400 +sException__Q24nw4r2db = .bss:0x80636FC0; // type:object size:0x360 +sThreadBuffer__Q24nw4r2db = .bss:0x80637320; // type:object size:0x4000 +sMapBuf__Q24nw4r2db = .bss:0x8063B320; // type:object size:0x200 scope:local +sFileInfo__Q24nw4r2db = .bss:0x8063B520; // type:object size:0x3C scope:local lbl_8063B560 = .bss:0x8063B560; // type:object size:0x300 lbl_8063B860 = .bss:0x8063B860; // type:object size:0x140 lbl_8063B9A0 = .bss:0x8063B9A0; // type:object size:0xC data:byte diff --git a/src/nw4r/db/db_console.cpp b/src/nw4r/db/db_console.cpp index 8f1a4c8d..cb1a3126 100644 --- a/src/nw4r/db/db_console.cpp +++ b/src/nw4r/db/db_console.cpp @@ -9,7 +9,7 @@ namespace db { static ConsoleHandle sConsoleList; static OSMutex sMutex; -static u8 buf[0x400]; +static u8 sStrBuf[0x400]; bool sInited; static ConsoleHandle FindInsertionPosition_(u16 priority) { @@ -128,7 +128,6 @@ ConsoleHandle Console_Destroy(ConsoleHandle console) { return console; } - static u8 *GetTextPtr_(ConsoleHandle console, u16 line, u16 xPos) { return &console->textBuf[(console->width + 1) * line + xPos]; } @@ -152,15 +151,13 @@ static u16 GetActiveLines_(ConsoleHandle console) { static void DoDrawString_(ConsoleHandle console, u32 printLine, const u8 *str, nw4r::ut::TextWriterBase *writer) { if (writer != nullptr) { - writer->Printf("%s\n", str); - } else { - s32 height = console->viewPosY + printLine * 10; - db::DirectPrint_DrawString(console->viewPosX, height, false, "%s\n", - str); - } + writer->Printf("%s\n", str); + } else { + s32 height = console->viewPosY + printLine * 10; + db::DirectPrint_DrawString(console->viewPosX, height, false, "%s\n", str); + } } - static void DoDrawConsole_(ConsoleHandle console, nw4r::ut::TextWriterBase *writer) { // I guess we don't care if locking the mutex fails?? TryLockMutex_(&sMutex); @@ -177,8 +174,7 @@ static void DoDrawConsole_(ConsoleHandle console, nw4r::ut::TextWriterBase } line = console->ringTop + viewOffset; - if ( line >= console->height ) - { + if (line >= console->height) { line -= console->height; } @@ -215,7 +211,6 @@ void Console_DrawDirect(ConsoleHandle console) { } } - static void TerminateLine_(ConsoleHandle console) { *GetTextPtr_(console, console->printTop, console->printXPos) = '\0'; } @@ -346,8 +341,8 @@ static void Console_PrintString_(ConsoleOutputType type, ConsoleHandle console, void Console_VFPrintf(ConsoleOutputType type, ConsoleHandle console, const char *format, va_list vlist) { if (TryLockMutex_(&sMutex)) { - vsnprintf((char *)buf, sizeof(buf), format, vlist); - Console_PrintString_(type, console, buf); + vsnprintf((char *)sStrBuf, sizeof(sStrBuf), format, vlist); + Console_PrintString_(type, console, sStrBuf); UnlockMutex_(&sMutex); } @@ -357,9 +352,9 @@ void Console_Printf(ConsoleHandle console, const char *format, ...) { va_start(args, format); if (TryLockMutex_(&sMutex)) { - vsnprintf((char *)buf, sizeof(buf), format, args); - OSReport("%s", buf); - PrintToBuffer_(console, buf); + vsnprintf((char *)sStrBuf, sizeof(sStrBuf), format, args); + OSReport("%s", sStrBuf); + PrintToBuffer_(console, sStrBuf); UnlockMutex_(&sMutex); } diff --git a/src/nw4r/db/db_exception.cpp b/src/nw4r/db/db_exception.cpp index 2a2b77ae..6485f0a3 100644 --- a/src/nw4r/db/db_exception.cpp +++ b/src/nw4r/db/db_exception.cpp @@ -49,8 +49,6 @@ const char *CPU_EXP_NAME[] = { "FLOATING POINT", }; - - void *RunThread_(void *); // TODO u8 vs u16 void ErrorHandler_(u16, OSContext *, u32, u32); @@ -146,8 +144,6 @@ static void DrawConsoleEndless_(ConsoleHandle console) { } } - - static void DumpException_(const ExceptionCallbackParam *param) { u16 error = param->error; OSContext *ctx = param->ctx; @@ -462,14 +458,12 @@ void Exception_SetUserCallback(bool (*callback)(detail::ConsoleHead *, void *), sException.exceptionCallbackArgs = args; } - u16 Exception_SetDisplayInfo(u16 newInfo) { u16 old = sException.exceptionDisplayInfo; sException.exceptionDisplayInfo = newInfo; return old; } - static void WaitTime_(s32 time) { s64 t1 = OSGetTime(); s64 t2; diff --git a/src/nw4r/db/db_mapFile.cpp b/src/nw4r/db/db_mapFile.cpp index 4546487d..6b73fbc0 100644 --- a/src/nw4r/db/db_mapFile.cpp +++ b/src/nw4r/db/db_mapFile.cpp @@ -10,11 +10,11 @@ static u32 sFileLength; static MapFile *sMapFileList = nullptr; static u8 (*GetCharPtr_)(const u8 *) = nullptr; -static u8 dvdReadBuf[512] ALIGN(32); +static u8 sMapBuf[512] ALIGN(32); static DVDFileInfo sFileInfo; static s32 sMapBufMaxSize = 0x200; -static u8 *sMapBuf = dvdReadBuf; +static u8 *sDvdBuf = sMapBuf; static s32 sMapBufOffset = -1; static void MapFile_Append_(MapFile *file) { @@ -86,7 +86,7 @@ static u8 GetCharOnDvd_(const u8 *buf) { address = ROUND_UP(sFileLength - sMapBufOffset, 32); } BOOL enabled = OSEnableInterrupts(); - BOOL read = DVDReadAsyncPrio(&sFileInfo, sMapBuf, address, sMapBufOffset, nullptr, 2); + BOOL read = DVDReadAsyncPrio(&sFileInfo, sDvdBuf, address, sMapBufOffset, nullptr, 2); while (DVDGetCommandBlockStatus(&sFileInfo.block)) {} OSRestoreInterrupts(enabled); @@ -94,7 +94,7 @@ static u8 GetCharOnDvd_(const u8 *buf) { return 0; } } - return *(sMapBuf + offset); + return *(sDvdBuf + offset); } static u8 *SearchNextLine_(u8 *buf, s32 lines) {