mirror of
https://github.com/izzy2lost/Diddy-Kong-Racing.git
synced 2026-06-19 01:16:26 -07:00
Match 3 libultra funcs + some texture init labels (#383)
* Fix warnings * Update src/thread0_epc.c Co-authored-by: Ryan Myers <ryan.p.myers@gmail.com> * identify some texture init stuff * match _Litob * match cosf * match sinf * formatting * Update math.h * Delete sinf.s * quick fix --------- Co-authored-by: Ryan Myers <ryan.p.myers@gmail.com>
This commit is contained in:
+60
-1
@@ -3,5 +3,64 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "macros.h"
|
||||
#include "guint.h"
|
||||
|
||||
GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/cosf.s")
|
||||
extern du P_cosf[];
|
||||
extern du rpi_cosf;
|
||||
extern du pihi_cosf;
|
||||
extern du pilo_cosf;
|
||||
extern fu zero_cosf;
|
||||
extern fu __libm_qnan_f;
|
||||
|
||||
f32 cosf(f32 x) {
|
||||
f64 dx; // double x
|
||||
f64 xsq; // x squared
|
||||
f64 poly;
|
||||
f64 dn;
|
||||
f32 xabs;
|
||||
s32 n;
|
||||
f64 result;
|
||||
s32 ix; // int x
|
||||
s32 xpt;
|
||||
|
||||
ix = *(s32 *) &x;
|
||||
xpt = (ix >> 22) & 0x1FF;
|
||||
|
||||
if (xpt < 310) {
|
||||
if (0 < x) {
|
||||
xabs = x;
|
||||
} else {
|
||||
xabs = -x;
|
||||
}
|
||||
|
||||
dx = xabs;
|
||||
dn = dx * rpi_cosf.d + 0.5;
|
||||
|
||||
if (0 <= dn) {
|
||||
n = dn + 0.5;
|
||||
} else {
|
||||
n = dn - 0.5;
|
||||
}
|
||||
|
||||
dn = n;
|
||||
dx -= (dn - 0.5) * pihi_cosf.d;
|
||||
dx -= (dn - 0.5) * pilo_cosf.d;
|
||||
xsq = dx * dx;
|
||||
|
||||
poly = (((((P_cosf[4].d * xsq) + P_cosf[3].d) * xsq) + P_cosf[2].d) * xsq) + P_cosf[1].d;
|
||||
|
||||
result = ((dx * xsq) * poly) + dx;
|
||||
|
||||
if ((n & 1) == 0) {
|
||||
return result;
|
||||
} else {
|
||||
return -(f32) result;
|
||||
}
|
||||
}
|
||||
|
||||
if (x != x) {
|
||||
return __libm_qnan_f.f;
|
||||
}
|
||||
|
||||
return zero_cosf.f;
|
||||
}
|
||||
|
||||
+66
-1
@@ -3,5 +3,70 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "macros.h"
|
||||
#include "guint.h"
|
||||
|
||||
GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/sinf.s")
|
||||
extern du P_sinf[];
|
||||
extern du rpi_sinf;
|
||||
extern du pihi_sinf;
|
||||
extern du pilo_sinf;
|
||||
extern fu zero_sinf;
|
||||
extern fu __libm_qnan_f;
|
||||
|
||||
f32 sinf(f32 x) {
|
||||
f64 dx; // double x
|
||||
f64 xsq; // x squared
|
||||
f64 poly;
|
||||
f64 dn;
|
||||
s32 n;
|
||||
f64 result;
|
||||
s32 ix; // int x
|
||||
s32 xpt;
|
||||
|
||||
ix = *(s32 *) &x;
|
||||
xpt = (ix >> 22) & 0x1FF;
|
||||
|
||||
if (xpt < 255) {
|
||||
dx = x;
|
||||
if (xpt >= 230) {
|
||||
xsq = dx * dx;
|
||||
poly = (((((P_sinf[4].d * xsq) + P_sinf[3].d) * xsq) + P_sinf[2].d) * xsq) + P_sinf[1].d;
|
||||
result = ((dx * xsq) * poly) + dx;
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
if (xpt < 310) {
|
||||
dx = x;
|
||||
dn = dx * rpi_sinf.d;
|
||||
|
||||
if (dn >= 0) {
|
||||
n = dn + 0.5;
|
||||
}
|
||||
else {
|
||||
n = dn - 0.5;
|
||||
}
|
||||
|
||||
dn = n;
|
||||
dx -= dn * pihi_sinf.d;
|
||||
dx -= dn * pilo_sinf.d;
|
||||
xsq = dx * dx;
|
||||
poly = (((((P_sinf[4].d * xsq) + P_sinf[3].d) * xsq) + P_sinf[2].d) * xsq) + P_sinf[1].d;
|
||||
result = ((dx * xsq) * poly) + dx;
|
||||
|
||||
if ((n & 1) == 0) {
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return -(f32) result;
|
||||
}
|
||||
}
|
||||
|
||||
if (x != x) {
|
||||
return __libm_qnan_f.f;
|
||||
}
|
||||
|
||||
return zero_sinf.f;
|
||||
}
|
||||
|
||||
+58
-1
@@ -3,5 +3,62 @@
|
||||
/* RAM_POS: 0x800D6700 */
|
||||
|
||||
#include "macros.h"
|
||||
#include "xprintf.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Litob.s")
|
||||
#define BUFF_LEN 0x18
|
||||
|
||||
extern char ldigs[];
|
||||
extern char udigs[];
|
||||
|
||||
void _Litob(printf_struct *args, char type) {
|
||||
char buff[BUFF_LEN];
|
||||
const char *digs;
|
||||
s32 base;
|
||||
s32 i;
|
||||
u64 us64val;
|
||||
|
||||
if (type == 'X') {
|
||||
digs = udigs;
|
||||
} else {
|
||||
digs = ldigs;
|
||||
}
|
||||
|
||||
base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16);
|
||||
i = BUFF_LEN;
|
||||
us64val = args->value.s64;
|
||||
|
||||
if ((type == 'd' || type == 'i') && args->value.s64 < 0) {
|
||||
us64val = -us64val;
|
||||
}
|
||||
|
||||
if (us64val != 0 || args->precision != 0) {
|
||||
buff[--i] = digs[us64val % base];
|
||||
}
|
||||
|
||||
args->value.s64 = us64val / base;
|
||||
|
||||
while (args->value.s64 > 0 && i > 0) {
|
||||
lldiv_t qr = lldiv(args->value.s64, base);
|
||||
|
||||
args->value.s64 = qr.quot;
|
||||
buff[--i] = digs[qr.rem];
|
||||
}
|
||||
|
||||
args->part2_len = BUFF_LEN - i;
|
||||
|
||||
memcpy(args->buff, buff + i, args->part2_len);
|
||||
|
||||
if (args->part2_len < args->precision) {
|
||||
args->num_leading_zeros = args->precision - args->part2_len;
|
||||
}
|
||||
|
||||
if (args->precision < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) {
|
||||
i = args->width - args->n0 - args->num_leading_zeros - args->part2_len;
|
||||
|
||||
if (i > 0) {
|
||||
args->num_leading_zeros += i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,6 @@ typedef struct {
|
||||
#define FLAGS_HASH 8
|
||||
#define FLAGS_ZERO 16
|
||||
s32 _Printf(outfun prout, char *dst, const char *fmt, va_list args);
|
||||
void _Litob(printf_struct *args, u8 type);
|
||||
void _Litob(printf_struct *args, char type);
|
||||
void _Ldtob(printf_struct *args, u8 type);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user