diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index fe294296..68b301b9 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -237,6 +237,13 @@ s/s_StateMethod.cpp: s/s_StateMethodUsr_FI.cpp: .text start:0x802DE540 end:0x802DE6EC +s/s_Crc.cpp: + .text start:0x802DE6F0 end:0x802DE6F4 + +s/s_Math.cpp: + .text start:0x802DE740 end:0x802DEEB0 + .sdata2 start:0x8057CC38 end:0x8057CC40 + s/s_Phase.cpp: .text start:0x802DEEB0 end:0x802DEF74 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 99db08ad..7ae38cd4 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17198,28 +17198,29 @@ initializeStateLocalMethod__20sStateMethodUsr_FI_cFv = .text:0x802DE580; // type executeStateLocalMethod__20sStateMethodUsr_FI_cFv = .text:0x802DE5F0; // type:function size:0x4C finalizeStateLocalMethod__20sStateMethodUsr_FI_cFv = .text:0x802DE640; // type:function size:0x54 changeStateLocalMethod__20sStateMethodUsr_FI_cFRC12sStateIDIf_c = .text:0x802DE6A0; // type:function size:0x4C -fn_802DE6F0 = .text:0x802DE6F0; // type:function size:0x4 +calcCRC__4sCrcFPCvUl = .text:0x802DE6F0; // type:function size:0x4 fn_802DE700 = .text:0x802DE700; // type:function size:0x8 fn_802DE710 = .text:0x802DE710; // type:function size:0x2C fn_802DE740 = .text:0x802DE740; // type:function size:0x24 -fn_802DE770 = .text:0x802DE770; // type:function size:0xC0 +addCalc__4sLibFPfffff = .text:0x802DE770; // type:function size:0xC0 fn_802DE830 = .text:0x802DE830; // type:function size:0x44 fn_802DE880 = .text:0x802DE880; // type:function size:0x38 fn_802DE8C0 = .text:0x802DE8C0; // type:function size:0xC -fn_802DE8D0 = .text:0x802DE8D0; // type:function size:0x14 -fn_802DE8F0 = .text:0x802DE8F0; // type:function size:0xB4 -fn_802DE9B0 = .text:0x802DE9B0; // type:function size:0x5C +addCalcAngle__4sLibFPsssss = .text:0x802DE8D0; // type:function size:0x14 +addCalcAngleT__4sLibFPsssss_s = .text:0x802DE8F0; // type:function size:0xB4 +addCalcAngle__4sLibFPssss = .text:0x802DE9B0; // type:function size:0x10 +addCalcAngleT__4sLibFPssss_v = .text:0x802DE9C0; // type:function size:0x4C fn_802DEA10 = .text:0x802DEA10; // type:function size:0x164 fn_802DEB80 = .text:0x802DEB80; // type:function size:0x6C -fn_802DEBF0 = .text:0x802DEBF0; // type:function size:0xC -fn_802DEC00 = .text:0x802DEC00; // type:function size:0x58 -fn_802DEC60 = .text:0x802DEC60; // type:function size:0x4 -fn_802DEC70 = .text:0x802DEC70; // type:function size:0x50 -fn_802DECC0 = .text:0x802DECC0; // type:function size:0x4 -fn_802DECD0 = .text:0x802DECD0; // type:function size:0x64 +chase__4sLibFPsss = .text:0x802DEBF0; // type:function size:0xC +chaseT__4sLibFPsss_i = .text:0x802DEC00; // type:function size:0x58 +chase__4sLibFPiii = .text:0x802DEC60; // type:function size:0x4 +chaseT__4sLibFPiii_i = .text:0x802DEC70; // type:function size:0x50 +chase__4sLibFPfff = .text:0x802DECC0; // type:function size:0x4 +chaseT__4sLibFPfff_i = .text:0x802DECD0; // type:function size:0x64 fn_802DED40 = .text:0x802DED40; // type:function size:0x4 fn_802DED50 = .text:0x802DED50; // type:function size:0x50 -fn_802DEDA0 = .text:0x802DEDA0; // type:function size:0x64 +chaseAngle__4sLibFPsss = .text:0x802DEDA0; // type:function size:0x64 fn_802DEE10 = .text:0x802DEE10; // type:function size:0x98 __ct__8sPhase_cFPPFPv_Q28sPhase_c15METHOD_RESULT_ei = .text:0x802DEEB0; // type:function size:0x14 callMethod__8sPhase_cFPv = .text:0x802DEED0; // type:function size:0xA4 @@ -22102,7 +22103,7 @@ fn_803AFCD0 = .text:0x803AFCD0; // type:function size:0xEC __OSPlayTimeAlarmExpired = .text:0x803AFDC0; // type:function size:0xA0 scope:local __OSGetPlayTime = .text:0x803AFE60; // type:function size:0x1CC scope:global __OSInitPlayTime = .text:0x803B0030; // type:function size:0x158 scope:global -fn_803B0190 = .text:0x803B0190; // type:function size:0x134 +OSCalcCRC32 = .text:0x803B0190; // type:function size:0x134 fn_803B02D0 = .text:0x803B02D0; // type:function size:0x204 __init_user = .text:0x803B04E0; // type:function size:0x20 scope:global __init_cpp = .text:0x803B0500; // type:function size:0x48 scope:local diff --git a/configure.py b/configure.py index 8c85ecd1..6e94cf01 100644 --- a/configure.py +++ b/configure.py @@ -344,6 +344,8 @@ config.libs = [ Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), Object(Matching, "m/m_pad.cpp"), + Object(Matching, "s/s_Crc.cpp"), + Object(NonMatching, "s/s_Math.cpp"), Object(Matching, "s/s_StateId.cpp"), Object(Matching, "s/s_StateMethod.cpp"), Object(Matching, "s/s_StateMethodUsr_FI.cpp"), diff --git a/include/rvl/OS.h b/include/rvl/OS.h index e2bdbce0..4604c7dd 100644 --- a/include/rvl/OS.h +++ b/include/rvl/OS.h @@ -12,6 +12,7 @@ extern "C" { #include "rvl/OS/OSAudioSystem.h" #include "rvl/OS/OSCache.h" #include "rvl/OS/OSContext.h" +#include "rvl/OS/OSCrc.h" #include "rvl/OS/OSError.h" #include "rvl/OS/OSExec.h" #include "rvl/OS/OSFastCast.h" diff --git a/include/rvl/OS/OSCrc.h b/include/rvl/OS/OSCrc.h new file mode 100644 index 00000000..5a24ef3e --- /dev/null +++ b/include/rvl/OS/OSCrc.h @@ -0,0 +1,13 @@ +#ifndef RVL_SDK_OS_CRC_H +#define RVL_SDK_OS_CRC_H +#include +#ifdef __cplusplus +extern "C" { +#endif + +u32 OSCalcCRC32(const void *, u32); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/s/README.txt b/include/s/README.txt index 5be519ee..00e8279e 100644 --- a/include/s/README.txt +++ b/include/s/README.txt @@ -1,4 +1,4 @@ -This library was ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +The state system in this library was ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib with differences/modifications outlined below: ## No inline destructors diff --git a/include/s/s_Crc.h b/include/s/s_Crc.h new file mode 100644 index 00000000..044e7d99 --- /dev/null +++ b/include/s/s_Crc.h @@ -0,0 +1,12 @@ +#ifndef S_CRC_H +#define S_CRC_H + +#include + +namespace sCrc { + +u32 calcCRC(const void *ptr, u32 size); + +} // namespace sCrc + +#endif diff --git a/include/s/s_Math.h b/include/s/s_Math.h new file mode 100644 index 00000000..668f5056 --- /dev/null +++ b/include/s/s_Math.h @@ -0,0 +1,18 @@ +#ifndef S_MATH_H +#define S_MATH_H + +#include + +namespace sLib { + +float addCalc(float *value, float target, float ratio, float maxStepSize, float minStepSize); + +BOOL chase(short *value, short target, short stepSize); +BOOL chase(int *value, int target, int stepSize); +BOOL chase(float *value, float target, float stepSize); + +BOOL chaseAngle(short *value, short target, short stepSize); + +} // namespace sLib + +#endif diff --git a/src/s/s_Crc.cpp b/src/s/s_Crc.cpp new file mode 100644 index 00000000..3a1ab434 --- /dev/null +++ b/src/s/s_Crc.cpp @@ -0,0 +1,10 @@ +#include +#include + +namespace sCrc { + +u32 calcCRC(const void *ptr, u32 size) { + return OSCalcCRC32(ptr, size); +} + +} // namespace sCrc diff --git a/src/s/s_Math.cpp b/src/s/s_Math.cpp new file mode 100644 index 00000000..47855713 --- /dev/null +++ b/src/s/s_Math.cpp @@ -0,0 +1,157 @@ +#include +#include + +namespace sLib { + +extern "C" float fn_802DE740(float f1, float f2, float f3) { + float diff = f2 - f1; + if (f3 < 1.0f) { + return f2; + } + return f1 + diff / f3; +} + +float addCalc(float *value, float target, float ratio, float maxStepSize, float minStepSize) { + if (*value != target) { + float step = ratio * (target - *value); + if (step >= minStepSize || (step <= -minStepSize)) { + if (step > maxStepSize) { + step = maxStepSize; + } + if (step < -maxStepSize) { + step = -maxStepSize; + } + *value = *value + step; + } else if (step > 0.0f) { + if (step < minStepSize) { + *value = *value + minStepSize; + if (*value > target) { + *value = target; + } + } + } else if (step > -minStepSize) { + *value = *value + (-minStepSize); + if (*value < target) { + *value = target; + } + } + } + + float ret = target - *value; + if (ret > 0.0f) { + return ret; + } else { + return -ret; + } +} + +extern "C" void fn_802DE830(float *value, float target, float ratio, float maxStepSize) { + if (*value == target) { + return; + } + + float step = ratio * (target - *value); + if (step > maxStepSize) { + step = maxStepSize; + } else if (step < -maxStepSize) { + step = -maxStepSize; + } + *value += step; +} + +extern "C" void fn_802DE880(float *value, float p2, float p3) { + float step = *value * p2; + if (step > p3) { + step = p3; + } else if (step < -p3) { + step = -p3; + } + *value -= step; +} + +extern "C" int fn_802DE8C0(short a1, short a2) { + return abs((short)(a1 - a2)); +} + +template +BOOL chaseT(T *value, T target, T stepSize) { + if (*value == target) { + return 1; + } + + if (stepSize != 0) { + if (*value > target) { + stepSize = -stepSize; + } + + T step = *value + stepSize; + *value = step; + if (stepSize * (step - target) >= 0) { + *value = target; + return 1; + } + } + + return 0; +} + +template +T addCalcAngleT(T *p1, T p2, T p3, T p4, T p5) {} + +template +void addCalcAngleT(T *value, T target, T ratio, T maxStepSize) { + T diff = target - *value; + T step = diff / ratio; + if (step > maxStepSize) { + *value += maxStepSize; + } else if (step < -maxStepSize) { + *value -= maxStepSize; + } else { + *value += step; + } +} + +short addCalcAngle(short *a, short b, short c, short d, short e) { + return addCalcAngleT(a, b, c, d, e); +} + +void addCalcAngle(short *value, short target, short ratio, short maxStepSize) { + return addCalcAngleT(value, target, ratio, maxStepSize); +} + +// template BOOL chaseT(char*, char, char); + +BOOL chase(short *value, short target, short stepSize) { + return chaseT(value, target, stepSize); +} + +BOOL chase(int *value, int target, int stepSize) { + return chaseT(value, target, stepSize); +} + +BOOL chase(float *value, float target, float stepSize) { + return chaseT(value, target, stepSize); +} + +BOOL chaseAngle(short *value, short target, short stepSize) { + if (*value == target) { + return 1; + } + + if (stepSize != 0) { + if ((short)(*value - target) > 0) { + stepSize = -stepSize; + } + + short step = *value + stepSize; + *value = step; + if (stepSize * (short)(step - target) >= 0) { + *value = target; + return 1; + } + } + + return 0; +} + +} // namespace sLib diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 1f6ea9e4..630161a5 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -1,6 +1,7 @@ #include "toBeSorted/file_manager.h" #include "f/f_base.h" #include +#include // clang-format off #include // clang-format on @@ -426,7 +427,9 @@ extern "C" void fn_800C01F0(); // todo flag managers /* 80011270 */ SaveFile *FileManager::getFileB() { return &mFileB; } -/* 80011280 */ u32 FileManager::calcFileCRC(const void *data, u32 length) {} +/* 80011280 */ u32 FileManager::calcFileCRC(const void *data, u32 length) { + return sCrc::calcCRC(data, length); +} /* 80011290 */ void FileManager::updateEmptyFiles() { updateEmptyFileFlags(); refreshSaveFileData();