Minor fixes and cleanup

Former-commit-id: 362dcbcaa40ad64c42fec541fff855d69bc4372a
This commit is contained in:
Phillip Stephens 2023-10-14 10:44:57 -07:00
parent 5538fd2e4e
commit 48bc018adb
6 changed files with 47 additions and 20 deletions

View File

@ -163,7 +163,7 @@ static inline int __fpclassifyd(double x) {
#define isinf(x) (fpclassify(x) == FP_INFINITE)
#define isfinite(x) ((fpclassify(x) > FP_INFINITE))
static inline float sqrtf(float x) {
_MATH_INLINE float sqrtf(float x) {
const double _half = .5;
const double _three = 3.0;
volatile float y;
@ -182,7 +182,7 @@ static inline float sqrtf(float x) {
return x;
}
static inline double sqrt(double x) {
_MATH_INLINE double sqrt(double x) {
if (x > 0.0) {
double guess = __frsqrte(x); /* returns an approximation to */
guess = .5 * guess * (3.0 - guess * guess * x); /* now have 8 sig bits */

View File

@ -177,7 +177,23 @@ void* SMediumAllocPuddle::FindFreeEntry(uint numBlocks) {
return nullptr;
}
void SMediumAllocPuddle::Free(const void* ptr) {}
void SMediumAllocPuddle::Free(const void* ptr) {
uint r28 = 0;
uint r29 = x8_bookKeeping[((uint)ptr - (uint)x0_mainData.get()) / 32];
x14_numBlocks += r29;
x18_numAllocs--;
uchar* bookKeepingStart = x8_bookKeeping;
uchar* block = &x8_bookKeeping[((uint)ptr - (uint)x0_mainData.get()) / 32];
if (xc_cachedBookKeepingAddr == block) {
r28 = 1;
}
if (block > bookKeepingStart) {
if ((block[-1] & 0x80) != 0) {
}
}
}
ushort SMediumAllocPuddle::GetBlockOffset(const void* ptr1, const void* ptr2) {
unsigned char tmp = (uchar*)ptr2 - (uchar*)ptr1 > 1 ? ((uchar*)ptr1)[1] : 0;

View File

@ -64,9 +64,9 @@ bool area_sorter::operator()(const CGameArea* a, const CGameArea* b) const {
class CLightPredicate {
public:
bool operator()(const CLight& a, const CLight& b) const {
if (b.GetPriority() > a.GetPriority()) {
if (a.GetPriority() > b.GetPriority()) {
return true;
} else if (b.GetPriority() == a.GetPriority()) {
} else if (a.GetPriority() == b.GetPriority()) {
return a.GetIntensity() > b.GetIntensity();
} else {
return false;

View File

@ -464,8 +464,14 @@ void hwSaveSample(void* header, void* data) {
void hwSetSaveSampleCallback(ARAMUploadCallback callback, unsigned long chunckSize) { aramSetUploadCallback(callback, chunckSize); }
void hwRemoveSample(void* header, void* data) {
#if MUSY_VERSION <= MUSY_VERSION_CHECK(1, 5, 3)
u32 len = (((u32*)header))[1] & 0xFFFFFF;
u8 type = (((u32*)header))[1] >> 0x18;
len = convert_length(len, type);
#else
u8 type = (((u32*)header))[1] >> 0x18;
u32 len = convert_length((((u32*)header))[1] & 0xFFFFFF, type);
#endif
aramRemoveData(data, len);
}

View File

@ -15,15 +15,14 @@ static volatile OSTick salLastTick = 0;
static volatile u32 salLogicActive = 0;
static volatile u32 salLogicIsWaiting = 0;
static volatile u32 salDspIsDone = 0;
static void* salAIBufferBase = NULL;
void* salAIBufferBase = NULL;
static u8 salAIBufferIndex = 0;
SND_SOME_CALLBACK userCallback = NULL;
static SND_SOME_CALLBACK userCallback = NULL;
#define DMA_BUFFER_LEN 0x280
u32 salGetStartDelay();
void callUserCallback() {
static void callUserCallback() {
if (salLogicActive) {
return;
}
@ -46,6 +45,8 @@ void salCallback() {
}
}
void dspInitCallback() {
salDspIsDone = TRUE;
salDspInitIsDone = TRUE;
@ -89,10 +90,13 @@ u32 salExitAi() {
}
void* salAiGetDest() {
return (void*)((u32)salAIBufferBase + (u8)((salAIBufferIndex + 2) % 4) * DMA_BUFFER_LEN);
u8 index; // r31
index = (salAIBufferIndex + 2) % 4;
return (void*)((u8*)salAIBufferBase + index * DMA_BUFFER_LEN);
}
u32 salInitDsp() {
u8 _[8];
dsp_task.iram_mmem_addr = (u16*)dspSlave;
dsp_task.iram_length = dspSlaveLength;
dsp_task.iram_addr = 0;

View File

@ -218,6 +218,8 @@ bool dataRemoveCurve(u16 sid) {
return 0;
}
#define SDIR(sd) ((SDIR_DATA*)((u8*)sd + 0))
bool dataInsertSDir(SDIR_DATA* sdir, void* smp_data) {
s32 i; // r31
SDIR_DATA* s; // r25
@ -230,25 +232,24 @@ bool dataInsertSDir(SDIR_DATA* sdir, void* smp_data) {
if (i == dataSmpSDirNum) {
if (dataSmpSDirNum < 128) {
n = 0;
for (s = sdir; s->id != 0xffff; ++s) {
for (s = SDIR(sdir); s->id != 0xffff; ++s) {
++n;
}
hwDisableIrq();
for (j = 0; j < n; ++j) {
for (i = 0; i < dataSmpSDirNum; ++i) {
for (k = 0; k < dataSmpSDirs[i].numSmp; ++k) {
if (sdir[j].id == dataSmpSDirs[i].data[k].id)
goto done_loop;
goto found_id;
}
}
}
done_loop:
if (i == dataSmpSDirNum) {
sdir[j].ref_cnt = 0;
} else {
sdir[j].ref_cnt = 0xffff;
found_id:
if (i != dataSmpSDirNum) {
sdir[j].ref_cnt = 0xffff;
} else {
sdir[j].ref_cnt = 0;
}
}
dataSmpSDirs[dataSmpSDirNum].data = sdir;
@ -273,7 +274,7 @@ bool dataRemoveSDir(struct SDIR_DATA* sdir) {
}
bool dataAddSampleReference(u16 sid) {
u32 i; // r29
u32 i; // r29
SAMPLE_HEADER* header; // r1+0xC
SDIR_DATA* data; // r30
SDIR_DATA* sdir; // r31