Properly match sndBSearch

This commit is contained in:
Phillip Stephens 2023-02-28 10:49:29 -08:00
parent 4012ec3a16
commit e78182e63c
1 changed files with 14 additions and 16 deletions

View File

@ -95,29 +95,27 @@ s16 sndSin(u16 angle) {
} }
void* sndBSearch(void* key, void* base, s32 num, s32 len, SND_COMPARE cmp) { void* sndBSearch(void* key, void* base, s32 num, s32 len, SND_COMPARE cmp) {
s32 left; long l; // r31
s32 right; long r; // r30
s32 mid; long m; // r29
s32 found; long c; // r28
u8* test; void* ptr; // r27
if (num != 0) { if (num != 0) {
left = 1; l = 1;
right = num; r = num;
do { do {
mid = ((left + right) >> 1); // This is kind of gross....
test = (u8*)(u32)base + (len * (mid - 1)); if ((c = cmp(key, (ptr = (void*)((u32)base + len * ((m = (l + r) >> 1) - 1))))) == 0) {
found = (*cmp)(key, test); return ptr;
if (found == 0) {
return test;
} }
if (found < 0) { if (c < 0) {
right = mid - 1; r = m - 1;
} else { } else {
left = mid + 1; l = m + 1;
} }
} while (left <= right); } while (l <= r);
} }
return NULL; return NULL;
} }