Skip to content

Commit

Permalink
sLib math, known symbols edition
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Jun 29, 2024
1 parent 25015d8 commit 4afb9d6
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 15 deletions.
7 changes: 7 additions & 0 deletions config/SOUE01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 14 additions & 13 deletions config/SOUE01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<s>__4sLibFPsssss_s = .text:0x802DE8F0; // type:function size:0xB4
addCalcAngle__4sLibFPssss = .text:0x802DE9B0; // type:function size:0x10
addCalcAngleT<s>__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<s>__4sLibFPsss_i = .text:0x802DEC00; // type:function size:0x58
chase__4sLibFPiii = .text:0x802DEC60; // type:function size:0x4
chaseT<i>__4sLibFPiii_i = .text:0x802DEC70; // type:function size:0x50
chase__4sLibFPfff = .text:0x802DECC0; // type:function size:0x4
chaseT<f>__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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ def nw4rLib(lib_name, objects, extra_cflags=[]):
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"),
Expand Down
1 change: 1 addition & 0 deletions include/rvl/OS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions include/rvl/OS/OSCrc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef RVL_SDK_OS_CRC_H
#define RVL_SDK_OS_CRC_H
#include <common.h>
#ifdef __cplusplus
extern "C" {
#endif

u32 OSCalcCRC32(const void *, u32);

#ifdef __cplusplus
}
#endif
#endif
2 changes: 1 addition & 1 deletion include/s/README.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions include/s/s_Crc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef S_CRC_H
#define S_CRC_H

#include <common.h>

namespace sCrc {

u32 calcCRC(const void *ptr, u32 size);

} // namespace sCrc

#endif
18 changes: 18 additions & 0 deletions include/s/s_Math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef S_MATH_H
#define S_MATH_H

#include <common.h>

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
10 changes: 10 additions & 0 deletions src/s/s_Crc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <s/s_Crc.h>
#include <rvl/OS.h>

namespace sCrc {

u32 calcCRC(const void *ptr, u32 size) {
return OSCalcCRC32(ptr, size);
}

} // namespace sCrc
157 changes: 157 additions & 0 deletions src/s/s_Math.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include <s/s_Math.h>
#include <math.h>

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 <typename T>
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 <typename T>
T addCalcAngleT(T *p1, T p2, T p3, T p4, T p5) {}

template <typename T>
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, 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
5 changes: 4 additions & 1 deletion src/toBeSorted/file_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "toBeSorted/file_manager.h"
#include "f/f_base.h"
#include <m/m_heap.h>
#include <s/s_Crc.h>
// clang-format off
#include <sized_string.h>
// clang-format on
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4afb9d6

Please sign in to comment.