Refresh 1

This commit is contained in:
n64
2019-09-01 15:50:50 -04:00
parent c6102eb802
commit 1ef98ec785
475 changed files with 100280 additions and 97252 deletions

504
lib/rsp.s

File diff suppressed because it is too large Load Diff

View File

@@ -83,8 +83,9 @@ void _Ldtob(printf_struct *args, u8 type) {
nsig = 0;
exp = 0;
} else {
if (val < 0)
if (val < 0) {
val = -val;
}
exp = exp * 30103 / 0x000186A0 - 4;
if (exp < 0) {
n = (3 - exp) & ~3;
@@ -109,8 +110,9 @@ void _Ldtob(printf_struct *args, u8 type) {
}
}
gen = ((type == 'f') ? exp + 10 : 6) + args->precision;
if (gen > 0x13)
if (gen > 0x13) {
gen = 0x13;
}
*ptr++ = '0';
while (gen > 0 && 0 < val) {
lo = val;
@@ -136,13 +138,15 @@ void _Ldtob(printf_struct *args, u8 type) {
}
nsig = ((type == 'f') ? exp + 1 : ((type == 'e' || type == 'E') ? 1 : 0)) + args->precision;
if (gen < nsig)
if (gen < nsig) {
nsig = gen;
}
if (nsig > 0) {
if (nsig < gen && ptr[nsig] > '4')
if (nsig < gen && ptr[nsig] > '4') {
drop = '9';
else
} else {
drop = '0';
}
for (n2 = nsig; ptr[--n2] == drop;) {
nsig--;
@@ -170,9 +174,9 @@ static s16 _Ldunscale(s16 *pex, printf_struct *px) {
*pex = xchar - (_DBIAS - 1);
return (FINITE);
}
if (0 > xchar)
if (0 > xchar) {
return NAN;
else {
} else {
*pex = 0;
return (0);
}
@@ -180,80 +184,94 @@ static s16 _Ldunscale(s16 *pex, printf_struct *px) {
static void _Genld(printf_struct *px, u8 code, u8 *p, s16 nsig, s16 xexp) {
u8 point = '.';
if (nsig <= 0)
if (nsig <= 0) {
nsig = 1,
p = (u8 *) "0";
}
if (code == 'f'
|| ((code == 'g' || code == 'G') && (-4 <= xexp) && (xexp < px->precision))) { /* 'f' format */
++xexp; /* change to leading digit count */
if (code != 'f') { /* fixup for 'g' */
if (!(px->flags & FLAGS_HASH) && nsig < px->precision)
if (!(px->flags & FLAGS_HASH) && nsig < px->precision) {
px->precision = nsig;
if ((px->precision -= xexp) < 0)
}
if ((px->precision -= xexp) < 0) {
px->precision = 0;
}
}
if (xexp <= 0) { /* digits only to right of point */
px->buff[px->part2_len++] = '0';
if (0 < px->precision || px->flags & FLAGS_HASH)
if (0 < px->precision || px->flags & FLAGS_HASH) {
px->buff[px->part2_len++] = point;
if (px->precision < -xexp)
}
if (px->precision < -xexp) {
xexp = -px->precision;
}
px->num_mid_zeros = -xexp;
px->precision += xexp;
if (px->precision < nsig)
if (px->precision < nsig) {
nsig = px->precision;
}
memcpy(&px->buff[px->part2_len], p, px->part3_len = nsig);
px->num_trailing_zeros = px->precision - nsig;
} else if (nsig < xexp) { /* zeros before point */
memcpy(&px->buff[px->part2_len], p, nsig);
px->part2_len += nsig;
px->num_mid_zeros = xexp - nsig;
if (0 < px->precision || px->flags & FLAGS_HASH)
if (0 < px->precision || px->flags & FLAGS_HASH) {
px->buff[px->part2_len] = point, ++px->part3_len;
}
px->num_trailing_zeros = px->precision;
} else { /* enough digits before point */
memcpy(&px->buff[px->part2_len], p, xexp);
px->part2_len += xexp;
nsig -= xexp;
if (0 < px->precision || px->flags & FLAGS_HASH)
if (0 < px->precision || px->flags & FLAGS_HASH) {
px->buff[px->part2_len++] = point;
if (px->precision < nsig)
}
if (px->precision < nsig) {
nsig = px->precision;
}
memcpy(&px->buff[px->part2_len], p + xexp, nsig);
px->part2_len += nsig;
px->num_mid_zeros = px->precision - nsig;
}
} else { /* 'e' format */
if (code == 'g' || code == 'G') { /* fixup for 'g' */
if (nsig < px->precision)
if (nsig < px->precision) {
px->precision = nsig;
if (--px->precision < 0)
}
if (--px->precision < 0) {
px->precision = 0;
}
code = code == 'g' ? 'e' : 'E';
}
px->buff[px->part2_len++] = *p++;
if (0 < px->precision || px->flags & FLAGS_HASH)
if (0 < px->precision || px->flags & FLAGS_HASH) {
px->buff[px->part2_len++] = point;
}
if (0 < px->precision) { /* put fraction digits */
if (px->precision < --nsig)
if (px->precision < --nsig) {
nsig = px->precision;
}
memcpy(&px->buff[px->part2_len], p, nsig);
px->part2_len += nsig;
px->num_mid_zeros = px->precision - nsig;
}
p = (u8 *) &px->buff[px->part2_len]; /* put exponent */
*p++ = code;
if (0 <= xexp)
if (0 <= xexp) {
*p++ = '+';
else { /* negative exponent */
} else { /* negative exponent */
*p++ = '-';
xexp = -xexp;
}
if (100 <= xexp) { /* put oversize exponent */
if (1000 <= xexp)
if (1000 <= xexp) {
*p++ = xexp / 1000 + '0', xexp %= 1000;
}
*p++ = xexp / 100 + '0', xexp %= 100;
}
*p++ = xexp / 10 + '0', xexp %= 10;
@@ -264,7 +282,8 @@ static void _Genld(printf_struct *px, u8 code, u8 *p, s16 nsig, s16 xexp) {
int n =
px->part1_len + px->part2_len + px->num_mid_zeros + px->part3_len + px->num_trailing_zeros;
if (n < px->width)
if (n < px->width) {
px->num_leading_zeros = px->width - n;
}
}
}

View File

@@ -16,20 +16,23 @@ void _Litob(printf_struct *args, u8 type) {
u64 num;
lldiv_t quotrem;
if (type == 'X')
if (type == 'X') {
num_map = D_80334974;
else
} else {
num_map = D_80334960;
}
base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16);
buff_ind = BUFF_LEN;
num = args->value.s64;
if ((type == 'd' || type == 'i') && args->value.s64 < 0)
if ((type == 'd' || type == 'i') && args->value.s64 < 0) {
num = -num;
}
if (num != 0 || args->precision != 0)
if (num != 0 || args->precision != 0) {
buff[--buff_ind] = num_map[num % base];
}
args->value.s64 = num / base;
@@ -43,12 +46,14 @@ void _Litob(printf_struct *args, u8 type) {
memcpy(args->buff, buff + buff_ind, args->part2_len);
if (args->part2_len < args->precision)
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) {
buff_ind = args->width - args->part1_len - args->num_leading_zeros - args->part2_len;
if (buff_ind > 0)
if (buff_ind > 0) {
args->num_leading_zeros += buff_ind;
}
}
}

View File

@@ -50,8 +50,9 @@ s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char
}
}
_PROUT(dst, fmt, fmt_ptr - (u8 *) fmt);
if (c == 0)
if (c == 0) {
return sp78.size;
}
fmt = (char *) ++fmt_ptr;
sp78.flags = 0;
for (; (flag_index = strchr(flags_str, *fmt_ptr)) != NULL; fmt_ptr++) {
@@ -78,10 +79,11 @@ s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char
ATOI(sp78.precision, fmt_ptr);
}
}
if (strchr(length_str, *fmt_ptr) != NULL)
if (strchr(length_str, *fmt_ptr) != NULL) {
sp78.length = *fmt_ptr++;
else
} else {
sp78.length = 0;
}
if (sp78.length == 'l' && *fmt_ptr == 'l') {
sp78.length = 'L';
@@ -114,22 +116,25 @@ static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buff) {
case 'd':
case 'i':
if (a0->length == 'l')
if (a0->length == 'l') {
a0->value.s64 = va_arg(*args, s32);
else if (a0->length == 'L')
} else if (a0->length == 'L') {
a0->value.s64 = va_arg(*args, s64);
else
} else {
a0->value.s64 = va_arg(*args, s32);
}
if (a0->length == 'h')
if (a0->length == 'h') {
a0->value.s64 = (s16) a0->value.s64;
}
if (a0->value.s64 < 0)
if (a0->value.s64 < 0) {
buff[a0->part1_len++] = '-';
else if (a0->flags & FLAGS_PLUS)
} else if (a0->flags & FLAGS_PLUS) {
buff[a0->part1_len++] = '+';
else if (a0->flags & FLAGS_SPACE)
} else if (a0->flags & FLAGS_SPACE) {
buff[a0->part1_len++] = ' ';
}
a0->buff = (char *) &buff[a0->part1_len];
@@ -140,23 +145,26 @@ static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buff) {
case 'X':
case 'u':
case 'o':
if (a0->length == 'l')
if (a0->length == 'l') {
a0->value.s64 = va_arg(*args, s32);
else if (a0->length == 'L')
} else if (a0->length == 'L') {
a0->value.s64 = va_arg(*args, s64);
else
} else {
a0->value.s64 = va_arg(*args, s32);
}
if (a0->length == 'h')
if (a0->length == 'h') {
a0->value.s64 = (u16) a0->value.s64;
else if (a0->length == 0)
} else if (a0->length == 0) {
a0->value.s64 = (u32) a0->value.s64;
}
if (a0->flags & FLAGS_HASH) {
buff[a0->part1_len++] = '0';
if (type == 'x' || type == 'X')
if (type == 'x' || type == 'X') {
buff[a0->part1_len++] = type;
}
}
a0->buff = (char *) &buff[a0->part1_len];
_Litob(a0, type);
@@ -173,10 +181,11 @@ static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buff) {
if (a0->value.u16 & 0x8000) {
buff[a0->part1_len++] = '-';
} else {
if (a0->flags & FLAGS_PLUS)
if (a0->flags & FLAGS_PLUS) {
buff[a0->part1_len++] = '+';
else if (a0->flags & FLAGS_SPACE)
} else if (a0->flags & FLAGS_SPACE) {
buff[a0->part1_len++] = ' ';
}
}
a0->buff = (char *) &buff[a0->part1_len];
@@ -184,14 +193,15 @@ static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buff) {
break;
case 'n':
if (a0->length == 'h')
if (a0->length == 'h') {
*(va_arg(*args, u16 *)) = a0->size;
else if (a0->length == 'l')
} else if (a0->length == 'l') {
*va_arg(*args, u32 *) = a0->size;
else if (a0->length == 'L')
} else if (a0->length == 'L') {
*va_arg(*args, u64 *) = a0->size;
else
} else {
*va_arg(*args, u32 *) = a0->size;
}
break;
case 'p':
@@ -203,8 +213,9 @@ static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buff) {
case 's':
a0->buff = va_arg(*args, char *);
a0->part2_len = strlen((u8 *) a0->buff);
if (a0->precision >= 0 && a0->part2_len > a0->precision)
if (a0->precision >= 0 && a0->part2_len > a0->precision) {
a0->part2_len = a0->precision;
}
break;
case '%':

View File

@@ -3,8 +3,9 @@
s32 __osAiDeviceBusy(void) {
register s32 status = HW_REG(AI_STATUS_REG, u32);
if ((status & AI_STATUS_AI_FULL) != 0)
if ((status & AI_STATUS_AI_FULL) != 0) {
return 1;
else
} else {
return 0;
}
}

View File

@@ -14,8 +14,9 @@ void __osPiCreateAccessQueue() {
void __osPiGetAccess() {
OSMesg sp1c;
if (!gOsPiAccessQueueCreated)
if (!gOsPiAccessQueueCreated) {
__osPiCreateAccessQueue();
}
osRecvMesg(&gOsPiMessageQueue, &sp1c, OS_MESG_BLOCK);
}

View File

@@ -12,8 +12,9 @@ void __osSiCreateAccessQueue() {
void __osSiGetAccess(void) {
OSMesg sp1c;
if (!gOsSiAccessQueueCreated)
if (!gOsSiAccessQueueCreated) {
__osSiCreateAccessQueue();
}
osRecvMesg(&gOsSiMessageQueue, &sp1c, OS_MESG_BLOCK);
}

View File

@@ -1,8 +1,9 @@
#include "libultra_internal.h"
#include "hardware.h"
s32 __osSiRawReadIo(void *a0, u32 *a1) {
if (__osSiDeviceBusy())
if (__osSiDeviceBusy()) {
return -1;
}
*a1 = HW_REG((u32) a0, u32);
return 0;
}

View File

@@ -1,8 +1,9 @@
#include "libultra_internal.h"
#include "hardware.h"
s32 __osSiRawWriteIo(void *a0, u32 a1) {
if (__osSiDeviceBusy())
if (__osSiDeviceBusy()) {
return -1;
}
HW_REG((u32) a0, u32) = a1;
return 0;
}

View File

@@ -3,7 +3,8 @@
s32 __osSpDeviceBusy() {
register u32 status = HW_REG(SP_STATUS_REG, u32);
if (status & (SPSTATUS_IO_FULL | SPSTATUS_DMA_FULL | SPSTATUS_DMA_BUSY))
if (status & (SPSTATUS_IO_FULL | SPSTATUS_DMA_FULL | SPSTATUS_DMA_BUSY)) {
return 1;
}
return 0;
}

View File

@@ -2,13 +2,15 @@
#include "hardware.h"
s32 __osSpRawStartDma(u32 dir, void *sp_ptr, void *dram_ptr, size_t size) {
if (__osSpDeviceBusy())
if (__osSpDeviceBusy()) {
return -1;
}
HW_REG(SP_MEM_ADDR_REG, void *) = sp_ptr;
HW_REG(SP_DRAM_ADDR_REG, void *) = (void *) osVirtualToPhysical(dram_ptr);
if (dir == 0)
if (dir == 0) {
HW_REG(SP_WR_LEN_REG, u32) = size - 1;
else
} else {
HW_REG(SP_RD_LEN_REG, u32) = size - 1;
}
return 0;
}

View File

@@ -20,14 +20,16 @@ void __osSyncPutChars(s32 a0, s32 a1, u8 *a2) {
sp24.unk2[sp20] = a2[sp20];
}
while (!__osAtomicDec(&D_80334A44))
while (!__osAtomicDec(&D_80334A44)) {
;
}
sp1c = __osDisableInt();
*(u32 *) 0xC0000000 = *(u32 *) &sp24;
while (!(__osGetCause() & 0x2000))
while (!(__osGetCause() & 0x2000)) {
;
}
*(u32 *) 0xC000000C = 0;
D_80334A44++;

View File

@@ -42,8 +42,9 @@ void __osViInit(void) {
D_80334914->unk00 = 32;
D_80334914->features = D_80334914->unk08->comRegs.ctrl;
#ifndef VERSION_JP
while (HW_REG(VI_CURRENT_REG, u32) > 0xa)
while (HW_REG(VI_CURRENT_REG, u32) > 0xa) {
;
}
HW_REG(VI_STATUS_REG, u32) = 0;
#endif
__osViSwapContext();

View File

@@ -29,8 +29,9 @@ void __osViSwapContext() {
s1->unk2c = s0->fldRegs[field].yScale;
}
hStart = s0->comRegs.hStart;
if (s1->unk00 & 0x20)
if (s1->unk00 & 0x20) {
hStart = 0;
}
if (s1->unk00 & 0x40) {
s1->unk2c = 0;
origin = osVirtualToPhysical(s1->buffer);

View File

@@ -16,16 +16,18 @@ static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) {
ALWaveTable *wavetable;
u8 *table2;
if (inst->flags)
if (inst->flags) {
return;
}
inst->flags = 1;
for (i = 0; i < inst->soundCount; i++) {
PATCH(inst->soundArray[i], f, ALSound *);
sound = inst->soundArray[i];
if (sound->flags)
if (sound->flags) {
continue;
}
table2 = table;
@@ -34,18 +36,21 @@ static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) {
PATCH(sound->keyMap, f, ALKeyMap *);
PATCH(sound->wavetable, f, ALWaveTable *);
wavetable = sound->wavetable;
if (wavetable->flags)
if (wavetable->flags) {
continue;
}
wavetable->flags = 1;
PATCH(wavetable->base, table2, u8 *);
if (wavetable->type == 0) {
PATCH(wavetable->waveInfo.adpcmWave.book, f, ALADPCMBook *);
if (wavetable->waveInfo.adpcmWave.loop != NULL)
if (wavetable->waveInfo.adpcmWave.loop != NULL) {
PATCH(wavetable->waveInfo.adpcmWave.loop, f, ALADPCMloop *);
}
} else if (wavetable->type == 1) {
if (wavetable->waveInfo.rawWave.loop != NULL)
if (wavetable->waveInfo.rawWave.loop != NULL) {
PATCH(wavetable->waveInfo.rawWave.loop, f, ALRawLoop *);
}
}
}
}
@@ -60,13 +65,15 @@ void alBnkfNew(ALBankFile *f, u8 *table) {
int i;
int j;
unused();
if (f->revision != AL_BANK_VERSION)
if (f->revision != AL_BANK_VERSION) {
return;
}
for (i = 0; i < f->bankCount; i++) {
PATCH(f->bankArray[i], f, ALBank *);
if (f->bankArray[i] == NULL)
if (f->bankArray[i] == NULL) {
continue;
}
bank = f->bankArray[i];
if (bank->flags == 0) {

View File

@@ -40,10 +40,11 @@ void guMtxIdentF(float mf[4][4]) {
int r, c;
for (r = 0; r < 4; r++) {
for (c = 0; c < 4; c++) {
if (r == c)
if (r == c) {
mf[r][c] = 1.0f;
else
} else {
mf[r][c] = 0.0f;
}
}
}
}

View File

@@ -13,8 +13,9 @@ void guOrthoF(float m[4][4], float left, float right, float bottom, float top, f
m[3][2] = -(far + near) / (far - near);
m[3][3] = 1;
for (row = 0; row < 4; row++) {
for (col = 0; col < 4; col++)
for (col = 0; col < 4; col++) {
m[row][col] *= scale;
}
}
}

View File

@@ -24,8 +24,9 @@ void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, fl
*perspNorm = 65535;
} else {
*perspNorm = (double) (1 << 17) / (near + far);
if (*perspNorm <= 0)
if (*perspNorm <= 0) {
*perspNorm = 1;
}
}
}
}

View File

@@ -41,8 +41,9 @@ void send_packet(u8 *a0, s32 a1) {
sp1c.unk2[i] = a0[i];
}
*(volatile u32 *) 0xc0000000 = *(u32 *) &sp1c;
while (!(__osGetCause() & 0x2000))
while (!(__osGetCause() & 0x2000)) {
;
}
*(volatile u32 *) 0xc000000c = 0;
}
@@ -51,8 +52,9 @@ void send(u8 *buff, s32 len) {
s32 end;
s32 rem;
if (!D_80334A44) {
while (!(__osGetCause() & 0x2000))
while (!(__osGetCause() & 0x2000)) {
;
}
*(volatile u32 *) 0xc000000c = 0;
D_80334A44 = 1;
}

View File

@@ -12,12 +12,14 @@ s32 osAiSetFrequency(u32 freq) {
a1 = ftmp;
if (a1 < 0x84)
if (a1 < 0x84) {
return -1;
}
a2 = (a1 / 66) & 0xff;
if (a2 > 16)
if (a2 > 16) {
a2 = 16;
}
HW_REG(AI_DACRATE_REG, u32) = a1 - 1;
HW_REG(AI_BITRATE_REG, u32) = a2 - 1;

Some files were not shown because too many files have changed in this diff Show More