diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index ebd3baeb..523e8e25 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -127,6 +127,9 @@ toBeSorted/skipflag_manager.cpp: .sbss start:0x80575408 end:0x8057540C .bss start:0x805A9C68 end:0x805A9C88 +toBeSorted/counters/counter.cpp: + .text start:0x8016CC40 end:0x8016CD94 + toBeSorted/counters/rupee_counter.cpp: .text start:0x8016DE10 end:0x8016DF98 .ctors start:0x804DB7BC end:0x804DB7C0 diff --git a/configure.py b/configure.py index 67462de3..ae51b22b 100644 --- a/configure.py +++ b/configure.py @@ -285,6 +285,7 @@ config.libs = [ Object(NonMatching, "d/a/d_a_base.cpp"), Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), + Object(Matching, "toBeSorted/counters/counter.cpp"), Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), Object(Matching, "toBeSorted/counters/arrow_counter.cpp"), Object(Matching, "toBeSorted/counters/bomb_counter.cpp"), diff --git a/include/toBeSorted/counters/counter.h b/include/toBeSorted/counters/counter.h index 9747dd49..0741b0d3 100644 --- a/include/toBeSorted/counters/counter.h +++ b/include/toBeSorted/counters/counter.h @@ -6,36 +6,12 @@ class Counter { public: Counter(u16 id): counterId(id) {} - // No vtable, this class appears to be header-only virtual ~Counter() {}; - /* 8016cc40 */ virtual s32 checkedAdd(s32 num) { - s32 uncommitted = getUncommittedValue(); - s32 max = getMax(); - s32 result = uncommitted + num; - if (result < 0) { - setValue(0); - } else if (result < max) { - setValue(result); - } else { - setValue(max); - } - - if (result < 0) { - return result; - } - - return result <= max ? 0 : (result - max); - } - virtual u16 getCommittedValue() { - return 0; - } + virtual s32 checkedAdd(s32 num); + virtual u16 getCommittedValue(); virtual u16 getMax() = 0; - virtual u16 getUncommittedValue() { - return 0; - } - virtual void setValue(u16 num) { - return; - } + virtual u16 getUncommittedValue(); + virtual void setValue(u16 num); u16 counterId; }; diff --git a/src/toBeSorted/counters/counter.cpp b/src/toBeSorted/counters/counter.cpp new file mode 100644 index 00000000..2c388e44 --- /dev/null +++ b/src/toBeSorted/counters/counter.cpp @@ -0,0 +1,55 @@ +#include + +// TODO use the item flag manager once it exists +class ItemFlagManager { +public: + ItemFlagManager() {} + /** 0x08 */ virtual ~ItemFlagManager(); + /** 0x0C */ virtual void setFlagszptr(); + /** 0x10 */ virtual void onDirty(); + /** 0x14 */ virtual void copyFlagsFromSave() = 0; + /** 0x18 */ virtual void setupUnkFlagsStuff() = 0; + /** 0x1C */ virtual bool doCommit() = 0; + /** 0x20 */ virtual void setFlag(u16 flag); + /** 0x24 */ virtual void unsetFlag(u16 flag); + /** 0x28 */ virtual void setFlagOrCounterToValue(u16 flag, u16 value); + /** 0x2C */ virtual u16 getCounterOrFlag(u16 flag); + /** 0x30 */ virtual u16 getUncommittedValue(u16 flag); + /** 0x34 */ virtual void unk3(); + /** 0x38 */ virtual u16 *getSaveFlagSpace() = 0; +}; + +// TODO set up item flag manager +extern "C" ItemFlagManager *lbl_80575400; + + +/* 8016cc40 */ s32 Counter::checkedAdd(s32 num) { + s32 uncommitted = getUncommittedValue(); + s32 max = getMax(); + s32 result = uncommitted + num; + if (result < 0) { + setValue(0); + } else if (result < max) { + setValue(result); + } else { + setValue(max); + } + + if (result < 0) { + return result; + } + + return result <= max ? 0 : (result - max); +} + +/* 8016cd30 */ u16 Counter::getCommittedValue() { + return lbl_80575400->getCounterOrFlag(counterId | 0x4000); +} + +/* 8016cd50 */ u16 Counter::getUncommittedValue() { + return lbl_80575400->getUncommittedValue(counterId | 0x4000); +} + +/* 8016cd70 */ void Counter::setValue(u16 num) { + lbl_80575400->setFlagOrCounterToValue(counterId | 0x4000, num); +}