summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2024-04-08 18:05:46 -0600
committerSonic Dreamcaster <alejandro.asenjo88@gmail.com>2024-09-17 19:14:09 -0300
commit3892bcefa20e4262a676466050d5810b04454faa (patch)
tree1fb42f12f53d7cdb88afea708c3b1a36ae06da36 /src/sys
parented2a45796b5f0af0c27cc0c304b035cda4bb0099 (diff)
parent0a8c61789e5a04811a6efcd5c6af91637c5d8e57 (diff)
Merge branch 'master' into otr
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/sys_fault.c291
-rw-r--r--src/sys/sys_joybus.c44
-rw-r--r--src/sys/sys_lib.c22
-rw-r--r--src/sys/sys_main.c138
-rw-r--r--src/sys/sys_math.c1
-rw-r--r--src/sys/sys_matrix.c75
-rw-r--r--src/sys/sys_save.c20
-rw-r--r--src/sys/sys_timer.c8
8 files changed, 309 insertions, 290 deletions
diff --git a/src/sys/sys_fault.c b/src/sys/sys_fault.c
index f73e1396..35477807 100644
--- a/src/sys/sys_fault.c
+++ b/src/sys/sys_fault.c
@@ -1,5 +1,6 @@
#include "sys.h"
#include "PR/os_internal.h"
+#include "mods.h"
FaultMgr gFaultMgr;
@@ -49,79 +50,79 @@ const char* sFloatExceptions[6] = {
"Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow", "Inexact operation",
};
-void func_800073C0(s32 arg0, s32 arg1, s32 arg2, s32 arg3) {
- u16* var_v0;
+void Fault_FillRectangle(s32 xPos, s32 yPos, s32 width, s32 height) {
+ u16* pixel;
s32 i;
s32 j;
- var_v0 = gFaultMgr.width * arg1 + gFaultMgr.fb->data + arg0;
- for (i = 0; i < arg3; i++) {
- for (j = 0; j < arg2; j++, var_v0++) {
- *var_v0 = ((*var_v0 & 0xE738) >> 2) | 1;
+ pixel = gFaultMgr.width * yPos + gFaultMgr.fb->data + xPos;
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j++, pixel++) {
+ *pixel = ((*pixel & 0xE738) >> 2) | 1;
}
- var_v0 += gFaultMgr.width - arg2;
+ pixel += gFaultMgr.width - width;
}
}
-void func_800074AC(s32 arg0, s32 arg1, s32 arg2) {
- s32* var_v0;
- u16* var_v1;
+void Fault_DisplayChar(s32 xPos, s32 yPos, s32 index) {
+ s32* charPixelFlags;
+ u16* pixel;
s32 i;
s32 j;
- var_v0 = &sFaultCharPixelFlags[(arg2 / 5) * 7];
- var_v1 = gFaultMgr.width * arg1 + gFaultMgr.fb->data + arg0;
+ charPixelFlags = &sFaultCharPixelFlags[(index / 5) * 7];
+ pixel = gFaultMgr.width * yPos + gFaultMgr.fb->data + xPos;
for (i = 0; i < 7; i++) {
- u32 temp_t1 = 0x80000000 >> ((arg2 % 5) * 6);
- u32 temp_a3 = *var_v0++;
+ u32 bufferPixelFlag = 0x80000000 >> ((index % 5) * 6);
+ u32 charPixelFlag = *charPixelFlags++;
for (j = 0; j < 6; j++) {
- if (temp_t1 & temp_a3) {
- *var_v1 = -1;
+ if (bufferPixelFlag & charPixelFlag) {
+ *pixel = 0xFFFF;
} else {
- *var_v1 = 1;
+ *pixel = 0x0001;
}
- var_v1++;
- temp_t1 >>= 1;
+ pixel++;
+ bufferPixelFlag >>= 1;
}
- var_v1 += gFaultMgr.width - 6;
+ pixel += gFaultMgr.width - 6;
}
}
-void* func_80007604(void* arg0, const char* arg1, size_t arg2) {
- return (char*) memcpy(arg0, arg1, arg2) + arg2;
+char* Fault_PrOut(char* buffer, const char* fmt, size_t size) {
+ return (char*) memcpy(buffer, fmt, size) + size;
}
-void func_8000762C(s32 arg0, s32 arg1, const char* fmt, ...) {
- u8* var_s0;
+void Fault_Printf(s32 xPos, s32 yPos, const char* fmt, ...) {
+ u8* charPtr;
s32 i;
- u8 sp40[0x100];
- s32 temp_a2;
+ u8 buffer[0x100];
+ s32 charIndex;
va_list args;
va_start(args, fmt);
for (i = 0; i < 0x100; i++) {
- sp40[i] = 0;
+ buffer[i] = 0;
}
- if (_Printf((outfun*) func_80007604, sp40, fmt, args) <= 0) {
+ if (_Printf(Fault_PrOut, buffer, fmt, args) <= 0) {
return;
}
- for (var_s0 = sp40; *var_s0 != 0; var_s0++) {
- temp_a2 = sFaultCharIndex[*var_s0 & 0x7F];
+ for (charPtr = buffer; *charPtr != 0; charPtr++) {
+ charIndex = sFaultCharIndex[*charPtr & 0x7F];
- if (temp_a2 != 0xFF) {
- func_800074AC(arg0, arg1, temp_a2);
+ if (charIndex != 0xFF) {
+ Fault_DisplayChar(xPos, yPos, charIndex);
}
- arg0 += 6;
+ xPos += 6;
label:; // fake, probably
}
va_end(args);
}
-void func_8000770C(s32 time) {
- u64 time64 = MSEC_TO_CYCLES(time);
+void Fault_Wait(s32 msec) {
+ u64 time64 = MSEC_TO_CYCLES(msec);
osSetTime(0);
while (osGetTime() < time64) {
@@ -129,25 +130,25 @@ void func_8000770C(s32 time) {
}
}
-void func_800077F8(s32 arg0, s32 arg1, s32 arg2, f32* arg3) {
- u32 temp_v0 = *(u32*) arg3;
- s32 temp_v1 = ((temp_v0 & 0x7F800000) >> 0x17) - 0x7F;
+void Fault_DisplayFloatReg(s32 xPos, s32 yPos, s32 regNum, f32* regValue) {
+ u32 regAsInt = *(u32*) regValue;
+ s32 regExp = ((regAsInt & 0x7F800000) >> 0x17) - 0x7F;
- if (((-0x7F < temp_v1) && (temp_v1 < 0x80)) || (temp_v0 == 0)) {
- func_8000762C(arg0, arg1, "F%02d:%.3e", arg2, *arg3);
+ if (((-0x7F < regExp) && (regExp < 0x80)) || (regAsInt == 0)) {
+ Fault_Printf(xPos, yPos, "F%02d:%.3e", regNum, *regValue);
} else {
- func_8000762C(arg0, arg1, "F%02d:---------", arg2);
+ Fault_Printf(xPos, yPos, "F%02d:---------", regNum);
}
}
-void func_80007880(u32 arg0) {
- s32 var_v0;
- u32 var_v1 = 0x20000;
+void Fault_DisplayFloatException(u32 exceptFlags) {
+ s32 i;
+ u32 flag = 0x20000;
- func_8000762C(0x1E, 0xA0, "FPCSR:%08XH", arg0);
- for (var_v0 = 0; var_v0 < 6; var_v0++, var_v1 >>= 1) {
- if (arg0 & var_v1) {
- func_8000762C(0x84, 0xA0, "(%s)", sFloatExceptions[var_v0]);
+ Fault_Printf(30, 160, "FPCSR:%08XH", exceptFlags);
+ for (i = 0; i < 6; i++, flag >>= 1) {
+ if (exceptFlags & flag) {
+ Fault_Printf(132, 160, "(%s)", sFloatExceptions[i]);
return;
}
}
@@ -155,101 +156,101 @@ void func_80007880(u32 arg0) {
#define CAUSE_INDEX(cause) ((cause >> CAUSE_EXCSHIFT) & (CAUSE_EXCMASK >> CAUSE_EXCSHIFT))
-void func_80007910(OSThread* thread) {
+void Fault_DisplayDebugInfo(OSThread* thread) {
__OSThreadContext* context = &thread->context;
- s16 var_s0 = CAUSE_INDEX(context->cause);
+ s16 causeIndex = CAUSE_INDEX(context->cause);
- if (var_s0 == CAUSE_INDEX(EXC_WATCH)) {
- var_s0 = 16;
+ if (causeIndex == CAUSE_INDEX(EXC_WATCH)) {
+ causeIndex = 16;
}
- if (var_s0 == CAUSE_INDEX(EXC_VCED)) {
- var_s0 = 17;
+ if (causeIndex == CAUSE_INDEX(EXC_VCED)) {
+ causeIndex = 17;
}
- func_8000770C(3000);
- func_800073C0(15, 15, 290, 210);
- func_8000762C(30, 40, "THREAD:%d (%s)", thread->id, sFaultCauses[var_s0]);
- func_8000762C(30, 50, "PC:%08XH SR:%08XH\tVA:%08XH", context->pc, context->sr, context->badvaddr);
+ Fault_Wait(3000);
+ Fault_FillRectangle(15, 15, SCREEN_WIDTH - 30, SCREEN_HEIGHT - 30);
+ Fault_Printf(30, 40, "THREAD:%d (%s)", thread->id, sFaultCauses[causeIndex]);
+ Fault_Printf(30, 50, "PC:%08XH SR:%08XH\tVA:%08XH", context->pc, context->sr, context->badvaddr);
osWritebackDCacheAll();
- func_8000762C(30, 60, "AT:%08XH V0:%08XH\tV1:%08XH", (s32) context->at, (s32) context->v0, (s32) context->v1);
- func_8000762C(30, 70, "A0:%08XH A1:%08XH\tA2:%08XH", (s32) context->a0, (s32) context->a1, (s32) context->a2);
- func_8000762C(30, 80, "A3:%08XH T0:%08XH\tT1:%08XH", (s32) context->a3, (s32) context->t0, (s32) context->t1);
- func_8000762C(30, 90, "T2:%08XH T3:%08XH\tT4:%08XH", (s32) context->t2, (s32) context->t3, (s32) context->t4);
- func_8000762C(30, 100, "T5:%08XH T6:%08XH\tT7:%08XH", (s32) context->t5, (s32) context->t6, (s32) context->t7);
- func_8000762C(30, 110, "S0:%08XH S1:%08XH\tS2:%08XH", (s32) context->s0, (s32) context->s1, (s32) context->s2);
- func_8000762C(30, 120, "S3:%08XH S4:%08XH\tS5:%08XH", (s32) context->s3, (s32) context->s4, (s32) context->s5);
- func_8000762C(30, 130, "S6:%08XH S7:%08XH\tT8:%08XH", (s32) context->s6, (s32) context->s7, (s32) context->t8);
- func_8000762C(30, 140, "T9:%08XH GP:%08XH\tSP:%08XH", (s32) context->t9, (s32) context->gp, (s32) context->sp);
- func_8000762C(30, 150, "S8:%08XH RA:%08XH", (s32) context->s8, (s32) context->ra);
- func_80007880(context->fpcsr);
+ Fault_Printf(30, 60, "AT:%08XH V0:%08XH\tV1:%08XH", (s32) context->at, (s32) context->v0, (s32) context->v1);
+ Fault_Printf(30, 70, "A0:%08XH A1:%08XH\tA2:%08XH", (s32) context->a0, (s32) context->a1, (s32) context->a2);
+ Fault_Printf(30, 80, "A3:%08XH T0:%08XH\tT1:%08XH", (s32) context->a3, (s32) context->t0, (s32) context->t1);
+ Fault_Printf(30, 90, "T2:%08XH T3:%08XH\tT4:%08XH", (s32) context->t2, (s32) context->t3, (s32) context->t4);
+ Fault_Printf(30, 100, "T5:%08XH T6:%08XH\tT7:%08XH", (s32) context->t5, (s32) context->t6, (s32) context->t7);
+ Fault_Printf(30, 110, "S0:%08XH S1:%08XH\tS2:%08XH", (s32) context->s0, (s32) context->s1, (s32) context->s2);
+ Fault_Printf(30, 120, "S3:%08XH S4:%08XH\tS5:%08XH", (s32) context->s3, (s32) context->s4, (s32) context->s5);
+ Fault_Printf(30, 130, "S6:%08XH S7:%08XH\tT8:%08XH", (s32) context->s6, (s32) context->s7, (s32) context->t8);
+ Fault_Printf(30, 140, "T9:%08XH GP:%08XH\tSP:%08XH", (s32) context->t9, (s32) context->gp, (s32) context->sp);
+ Fault_Printf(30, 150, "S8:%08XH RA:%08XH", (s32) context->s8, (s32) context->ra);
+ Fault_DisplayFloatException(context->fpcsr);
osWritebackDCacheAll();
- func_800077F8(30, 170, 0, &context->fp0.f.f_even);
- func_800077F8(120, 170, 2, &context->fp2.f.f_even);
- func_800077F8(210, 170, 4, &context->fp4.f.f_even);
- func_800077F8(30, 180, 6, &context->fp6.f.f_even);
- func_800077F8(120, 180, 8, &context->fp8.f.f_even);
- func_800077F8(210, 180, 10, &context->fp10.f.f_even);
- func_800077F8(30, 190, 12, &context->fp12.f.f_even);
- func_800077F8(120, 190, 14, &context->fp14.f.f_even);
- func_800077F8(210, 190, 16, &context->fp16.f.f_even);
- func_800077F8(30, 200, 18, &context->fp18.f.f_even);
- func_800077F8(120, 200, 20, &context->fp20.f.f_even);
- func_800077F8(210, 200, 22, &context->fp22.f.f_even);
- func_800077F8(30, 210, 24, &context->fp24.f.f_even);
- func_800077F8(120, 210, 26, &context->fp26.f.f_even);
- func_800077F8(210, 210, 28, &context->fp28.f.f_even);
- func_800077F8(30, 220, 30, &context->fp30.f.f_even);
+ Fault_DisplayFloatReg(30, 170, 0, &context->fp0.f.f_even);
+ Fault_DisplayFloatReg(120, 170, 2, &context->fp2.f.f_even);
+ Fault_DisplayFloatReg(210, 170, 4, &context->fp4.f.f_even);
+ Fault_DisplayFloatReg(30, 180, 6, &context->fp6.f.f_even);
+ Fault_DisplayFloatReg(120, 180, 8, &context->fp8.f.f_even);
+ Fault_DisplayFloatReg(210, 180, 10, &context->fp10.f.f_even);
+ Fault_DisplayFloatReg(30, 190, 12, &context->fp12.f.f_even);
+ Fault_DisplayFloatReg(120, 190, 14, &context->fp14.f.f_even);
+ Fault_DisplayFloatReg(210, 190, 16, &context->fp16.f.f_even);
+ Fault_DisplayFloatReg(30, 200, 18, &context->fp18.f.f_even);
+ Fault_DisplayFloatReg(120, 200, 20, &context->fp20.f.f_even);
+ Fault_DisplayFloatReg(210, 200, 22, &context->fp22.f.f_even);
+ Fault_DisplayFloatReg(30, 210, 24, &context->fp24.f.f_even);
+ Fault_DisplayFloatReg(120, 210, 26, &context->fp26.f.f_even);
+ Fault_DisplayFloatReg(210, 210, 28, &context->fp28.f.f_even);
+ Fault_DisplayFloatReg(30, 220, 30, &context->fp30.f.f_even);
osWritebackDCacheAll();
- osViBlack(0);
- osViRepeatLine(0);
+ osViBlack(false);
+ osViRepeatLine(false);
osViSwapBuffer(gFaultMgr.fb);
}
OSThread* func_80007CEC(void) {
- OSThread* var_v1;
-
- var_v1 = __osGetActiveQueue();
+ OSThread* queue = __osGetActiveQueue();
- while (var_v1->priority != -1) {
- if ((var_v1->priority > 0) && (var_v1->priority < 0x7F) && (var_v1->flags & 3)) {
- return var_v1;
+ while (queue->priority != -1) {
+ if ((queue->priority > 0) && (queue->priority < 0x7F) && (queue->flags & 3)) {
+ return queue;
}
- var_v1 = var_v1->tlnext;
+ queue = queue->tlnext;
}
return NULL;
}
-void Fault_ThreadEntry(void* arg0) {
- OSMesg sp44;
- OSThread* sp40;
- s32 var_s2;
- s32 var_s5;
- u32 var_s0;
-
- sp44 = NULL;
- var_s5 = 0;
- var_s0 = 0;
- var_s2 = 0;
-
- osSetEventMesg(OS_EVENT_CPU_BREAK, &gFaultMgr.msgQueue, (OSMesg) FAULT_MESG_BREAK);
- osSetEventMesg(OS_EVENT_FAULT, &gFaultMgr.msgQueue, (OSMesg) FAULT_MESG_FAULT);
-
- sp40 = NULL;
- while (sp40 == NULL) {
- osRecvMesg(&gFaultMgr.msgQueue, &sp44, OS_MESG_BLOCK);
- sp40 = func_80007CEC();
+void Fault_ThreadEntry(void* arg) {
+ OSMesg dummy;
+ OSThread* faultedThread;
+ s32 codeTimer;
+ s32 codeComplete;
+ u32 codeInput;
+
+ dummy = NULL;
+ codeComplete = 0;
+ codeInput = 0;
+ codeTimer = 0;
+
+ osSetEventMesg(OS_EVENT_CPU_BREAK, &gFaultMgr.mesgQueue, (OSMesg) FAULT_MESG_BREAK);
+ osSetEventMesg(OS_EVENT_FAULT, &gFaultMgr.mesgQueue, (OSMesg) FAULT_MESG_FAULT);
+
+ faultedThread = NULL;
+ while (faultedThread == NULL) {
+ MQ_WAIT_FOR_MESG(&gFaultMgr.mesgQueue, &dummy);
+ faultedThread = func_80007CEC();
}
- func_8000762C(300, 10, "-");
- gControllerPlugged[0] = 1;
- while (var_s5 == 0) {
- osSendMesg(&gSerialThreadMsgQueue, OS_MESG_32(SI_READ_CONTROLLER), OS_MESG_PRI_NORMAL);
- osRecvMesg(&gControllerMsgQueue, NULL, OS_MESG_BLOCK);
+ Fault_Printf(300, 10, "-");
+ gControllerPlugged[0] = true;
+
+#if MODS_AUTO_DEBUGGER == 0 // Instant crash debugger (no button combination needed)
+ while (!codeComplete) {
+ osSendMesg(&gSerialThreadMesgQueue, (OSMesg) SI_READ_CONTROLLER, OS_MESG_NOBLOCK);
+ MQ_WAIT_FOR_MESG(&gControllerMesgQueue, NULL);
Controller_UpdateInput();
- switch (var_s0) {
+ switch (codeInput) {
case 0:
if (gControllerHold[0].button == (R_TRIG | D_CBUTTONS | L_CBUTTONS)) {
- var_s0++;
- var_s2 = 4000;
+ codeInput++;
+ codeTimer = 4000;
}
break;
case 1:
@@ -257,10 +258,10 @@ void Fault_ThreadEntry(void* arg0) {
case 7:
if (gControllerHold[0].button & R_TRIG) {
if (gControllerPress[0].button == A_BUTTON) {
- var_s0++;
- var_s2 = 3000;
+ codeInput++;
+ codeTimer = 3000;
} else if (gControllerPress[0].button != 0) {
- var_s0 = 0;
+ codeInput = 0;
}
}
break;
@@ -269,10 +270,10 @@ void Fault_ThreadEntry(void* arg0) {
case 8:
if (gControllerHold[0].button & R_TRIG) {
if (gControllerPress[0].button == B_BUTTON) {
- var_s0++;
- var_s2 = 3000;
+ codeInput++;
+ codeTimer = 3000;
} else if (gControllerPress[0].button != 0) {
- var_s0 = 0;
+ codeInput = 0;
}
}
break;
@@ -285,50 +286,52 @@ void Fault_ThreadEntry(void* arg0) {
case 13:
if (gControllerHold[0].button & R_TRIG) {
if (gControllerPress[0].button == L_CBUTTONS) {
- var_s0++;
- var_s2 = 3000;
+ codeInput++;
+ codeTimer = 3000;
} else if (gControllerPress[0].button != 0) {
- var_s0 = 0;
+ codeInput = 0;
}
}
break;
case 14:
if (gControllerHold[0].button & R_TRIG) {
if (gControllerPress[0].button == START_BUTTON) {
- var_s0++;
- var_s2 = 3000;
+ codeInput++;
+ codeTimer = 3000;
} else if (gControllerPress[0].button != 0) {
- var_s0 = 0;
+ codeInput = 0;
}
}
break;
case 15:
- var_s5 = 1;
+ codeComplete = true;
break;
}
- if (var_s2 != 0) {
- var_s2 -= 1;
+ if (codeTimer != 0) {
+ codeTimer--;
} else {
- var_s0 = 0;
+ codeInput = 0;
}
}
- func_80007910(sp40);
- while (1) {
+#endif
+
+ Fault_DisplayDebugInfo(faultedThread);
+ while (true) {
;
}
}
-void func_80007FE4(FrameBuffer* arg0, u16 arg1, u16 arg2) {
- gFaultMgr.fb = arg0;
- gFaultMgr.width = arg1;
- gFaultMgr.height = arg2;
+void Fault_SetFrameBuffer(FrameBuffer* buffer, u16 width, u16 height) {
+ gFaultMgr.fb = buffer;
+ gFaultMgr.width = width;
+ gFaultMgr.height = height;
}
void Fault_Init(void) {
gFaultMgr.fb = (FrameBuffer*) (PHYS_TO_K0(osMemSize) - sizeof(FrameBuffer));
gFaultMgr.width = SCREEN_WIDTH;
gFaultMgr.height = SCREEN_HEIGHT;
- osCreateMesgQueue(&gFaultMgr.msgQueue, &gFaultMgr.msg, 1);
+ osCreateMesgQueue(&gFaultMgr.mesgQueue, &gFaultMgr.msg, 1);
osCreateThread(&gFaultMgr.thread, THREAD_ID_FAULT, Fault_ThreadEntry, 0, gFaultMgr.stack + sizeof(gFaultMgr.stack),
127);
osStartThread(&gFaultMgr.thread);
diff --git a/src/sys/sys_joybus.c b/src/sys/sys_joybus.c
index 720f5b9e..c52cb8b9 100644
--- a/src/sys/sys_joybus.c
+++ b/src/sys/sys_joybus.c
@@ -4,11 +4,11 @@ OSContPad gControllerHold[4];
OSContPad gControllerPress[4];
u8 gControllerPlugged[4];
u32 gControllerLock;
-u8 gControllerRumble[4];
-OSContPad sNextController[4]; //
-OSContPad sPrevController[4]; //
-OSContStatus sControllerStatus[4]; //
-OSPfs sControllerMotor[4]; //
+u8 gControllerRumbleEnabled[4];
+OSContPad sNextController[4];
+OSContPad sPrevController[4];
+OSContStatus sControllerStatus[4];
+OSPfs sControllerMotor[4];
void Controller_AddDeadZone(s32 contrNum) {
s32 temp_v0 = gControllerHold[contrNum].stick_x;
@@ -55,7 +55,7 @@ void Controller_Init(void) {
osContInit(&gSerialEventQueue, &sp1F, sControllerStatus);
for (i = 0; i < 4; i++) {
gControllerPlugged[i] = (sp1F >> i) & 1;
- gControllerRumble[i] = 0;
+ gControllerRumbleEnabled[i] = 0;
}
}
@@ -63,7 +63,7 @@ void Controller_UpdateInput(void) {
s32 i;
for (i = 0; i < 4; i++) {
- if (gControllerPlugged[i] == 1 && sNextController[i].err_no == 0) {
+ if ((gControllerPlugged[i] == 1) && (sNextController[i].errno == 0)) {
sPrevController[i] = gControllerHold[i];
gControllerHold[i] = sNextController[i];
gControllerPress[i].button =
@@ -88,26 +88,26 @@ void Controller_ReadData(void) {
}
} else {
osContStartReadData(&gSerialEventQueue);
- osRecvMesg(&gSerialEventQueue, NULL, OS_MESG_NOBLOCK);
+ MQ_WAIT_FOR_MESG(&gSerialEventQueue, NULL);
osContGetReadData(sNextController);
}
- osSendMesg(&gControllerMsgQueue, OS_MESG_32(SI_CONT_READ_DONE), OS_MESG_PRI_NORMAL);
+ osSendMesg(&gControllerMesgQueue, OS_MESG_32(SI_CONT_READ_DONE), OS_MESG_PRI_NORMAL);
}
void Save_ReadData(void) {
if ((gStartNMI == 0) && (Save_ReadEeprom(&gSaveIOBuffer) == 0)) {
- osSendMesg(&gSaveMsgQueue, OS_MESG_32(SI_SAVE_SUCCESS), OS_MESG_PRI_NORMAL);
+ osSendMesg(&gSaveMesgQueue, (OSMesg) SI_SAVE_SUCCESS, OS_MESG_NOBLOCK);
return;
}
- osSendMesg(&gSaveMsgQueue, OS_MESG_32(SI_SAVE_FAILED), OS_MESG_PRI_NORMAL);
+ osSendMesg(&gSaveMesgQueue, OS_MESG_32(SI_SAVE_FAILED), OS_MESG_PRI_NORMAL);
}
void Save_WriteData(void) {
if ((gStartNMI == 0) && (Save_WriteEeprom(&gSaveIOBuffer) == 0)) {
- osSendMesg(&gSaveMsgQueue, OS_MESG_32(SI_SAVE_SUCCESS), OS_MESG_PRI_NORMAL);
+ osSendMesg(&gSaveMesgQueue, (OSMesg) SI_SAVE_SUCCESS, OS_MESG_NOBLOCK);
return;
}
- osSendMesg(&gSaveMsgQueue, OS_MESG_32(SI_SAVE_FAILED), OS_MESG_PRI_NORMAL);
+ osSendMesg(&gSaveMesgQueue, OS_MESG_32(SI_SAVE_FAILED), OS_MESG_PRI_NORMAL);
}
void Controller_Rumble(void) {
@@ -116,30 +116,30 @@ void Controller_Rumble(void) {
for (i = 0; i < 4; i++) {
if ((gControllerPlugged[i] != 0) && (sControllerStatus[i].err_no == 0)) {
if (sControllerStatus[i].status & 1) {
- if (gControllerRumble[i] == 0) {
+ if (gControllerRumbleEnabled[i] == 0) {
if (osMotorInit(&gSerialEventQueue, &sControllerMotor[i], i)) {
- gControllerRumble[i] = 0;
+ gControllerRumbleEnabled[i] = 0;
} else {
- gControllerRumble[i] = 1;
+ gControllerRumbleEnabled[i] = 1;
}
}
- if (gControllerRumble[i] == 1) {
- if (D_80137E84[i] != 0) {
+ if (gControllerRumbleEnabled[i] == 1) {
+ if (gControllerRumbleFlags[i] != 0) {
if (osMotorStart(&sControllerMotor[i])) {
- gControllerRumble[i] = 0;
+ gControllerRumbleEnabled[i] = 0;
}
} else {
if (osMotorStop(&sControllerMotor[i])) {
- gControllerRumble[i] = 0;
+ gControllerRumbleEnabled[i] = 0;
}
}
}
} else {
- gControllerRumble[i] = 0;
+ gControllerRumbleEnabled[i] = 0;
}
}
}
for (i = 0; i < 4; i++) {
- D_80137E84[i] = 0;
+ gControllerRumbleFlags[i] = 0;
}
}
diff --git a/src/sys/sys_lib.c b/src/sys/sys_lib.c
index 1f528aa0..a0f0bb2f 100644
--- a/src/sys/sys_lib.c
+++ b/src/sys/sys_lib.c
@@ -27,7 +27,7 @@ void Lib_QuickSort(u8* first, u32 length, u32 size, CompareFunc cFunc) {
u8* right;
u8* left;
- while (1) {
+ while (true) {
last = first + (length - 1) * size;
if (length == 2) {
@@ -40,7 +40,7 @@ void Lib_QuickSort(u8* first, u32 length, u32 size, CompareFunc cFunc) {
left = first;
right = last - size;
- while (1) {
+ while (true) {
while (cFunc(left, last) < 0) {
left += size;
}
@@ -81,11 +81,10 @@ void Lib_QuickSort(u8* first, u32 length, u32 size, CompareFunc cFunc) {
}
}
-void Lib_Perspective(Gfx** dList) {
+void Lib_InitPerspective(Gfx** dList) {
u16 norm;
- guPerspective(gGfxMtx, &norm, D_game_80161A3C, (f32) SCREEN_WIDTH / SCREEN_HEIGHT, D_game_80161A40, D_game_80161A44,
- 1.0f);
+ guPerspective(gGfxMtx, &norm, gFovY, (f32) SCREEN_WIDTH / SCREEN_HEIGHT, gProjectNear, gProjectFar, 1.0f);
gSPPerspNormalize((*dList)++, norm);
gSPMatrix((*dList)++, gGfxMtx++, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
guLookAt(gGfxMtx, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -12800.0f, 0.0f, 1.0f, 0.0f);
@@ -93,8 +92,9 @@ void Lib_Perspective(Gfx** dList) {
Matrix_Copy(gGfxMatrix, &gIdentityMatrix);
}
-void Lib_Ortho(Gfx** dList) {
- guOrtho(gGfxMtx, -160.0f, 160.0f, -120.0f, 120.0f, D_game_80161A40, D_game_80161A44, 1.0f);
+void Lib_InitOrtho(Gfx** dList) {
+ guOrtho(gGfxMtx, -SCREEN_WIDTH / 2, SCREEN_WIDTH / 2, -SCREEN_HEIGHT / 2, SCREEN_HEIGHT / 2, gProjectNear,
+ gProjectFar, 1.0f);
gSPMatrix((*dList)++, gGfxMtx++, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
guLookAt(gGfxMtx, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -12800.0f, 0.0f, 1.0f, 0.0f);
gSPMatrix((*dList)++, gGfxMtx++, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
@@ -105,15 +105,15 @@ void Lib_DmaRead(void* src, void* dst, ptrdiff_t size) {
osInvalICache(dst, size);
osInvalDCache(dst, size);
while (size > 0x100) {
- osPiStartDma(&gDmaIOMsg, 0, 0, (uintptr_t) src, dst, 0x100, &gDmaMsgQueue);
+ osPiStartDma(&gDmaIOMsg, 0, 0, (uintptr_t) src, dst, 0x100, &gDmaMesgQueue);
size -= 0x100;
src = (void*) ((uintptr_t) src + 0x100);
dst = (void*) ((uintptr_t) dst + 0x100);
- osRecvMesg(&gDmaMsgQueue, NULL, OS_MESG_BLOCK);
+ MQ_WAIT_FOR_MESG(&gDmaMesgQueue, NULL);
}
if (size != 0) {
- osPiStartDma(&gDmaIOMsg, 0, 0, (uintptr_t) src, dst, size, &gDmaMsgQueue);
- osRecvMesg(&gDmaMsgQueue, NULL, OS_MESG_BLOCK);
+ osPiStartDma(&gDmaIOMsg, 0, 0, (uintptr_t) src, dst, size, &gDmaMesgQueue);
+ MQ_WAIT_FOR_MESG(&gDmaMesgQueue, NULL);
}
}
diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c
index 615fc714..31ca2913 100644
--- a/src/sys/sys_main.c
+++ b/src/sys/sys_main.c
@@ -14,32 +14,32 @@ u32 gSegments[16]; // 800E1FD0
OSMesgQueue gPiMgrCmdQueue; // 800E2010
OSMesg sPiMgrCmdBuff[50]; // 800E2028
-OSMesgQueue gDmaMsgQueue;
+OSMesgQueue gDmaMesgQueue;
void* sDmaMsgBuff[1];
OSIoMesg gDmaIOMsg;
OSMesgQueue gSerialEventQueue;
void* sSerialEventBuff[1];
-OSMesgQueue gMainThreadMsgQueue;
+OSMesgQueue gMainThreadMesgQueue;
void* sMainThreadMsgBuff[32];
-OSMesgQueue gTaskMsgQueue;
+OSMesgQueue gTaskMesgQueue;
void* sTaskMsgBuff[16];
-OSMesgQueue gAudioVImsgQueue;
+OSMesgQueue gAudioVImesgQueue;
void* sAudioVImsgBuff[1];
-OSMesgQueue gAudioTaskMsgQueue;
+OSMesgQueue gAudioTaskMesgQueue;
void* sAudioTaskMsgBuff[1];
-OSMesgQueue gGfxVImsgQueue;
+OSMesgQueue gGfxVImesgQueue;
void* sGfxVImsgBuff[4];
-OSMesgQueue gGfxTaskMsgQueue;
+OSMesgQueue gGfxTaskMesgQueue;
void* sGfxTaskMsgBuff[2];
-OSMesgQueue gSerialThreadMsgQueue;
+OSMesgQueue gSerialThreadMesgQueue;
void* sSerialThreadMsgBuff[8];
-OSMesgQueue gControllerMsgQueue;
+OSMesgQueue gControllerMesgQueue;
void* sControllerMsgBuff[1];
-OSMesgQueue gSaveMsgQueue;
+OSMesgQueue gSaveMesgQueue;
void* sSaveMsgBuff[1];
-OSMesgQueue gTimerTaskMsgQueue;
+OSMesgQueue gTimerTaskMesgQueue;
void* sTimerTaskMsgBuff[16];
-OSMesgQueue gTimerWaitMsgQueue;
+OSMesgQueue gTimerWaitMesgQueue;
void* sTimerWaitMsgBuff[1];
GfxPool gGfxPools[2];
@@ -55,11 +55,11 @@ Lightsn* gLight;
FrameBuffer* gFrameBuffer;
u16* gTextureRender;
-u8 D_80137E78;
+u8 gVIsPerFrame;
u32 gSysFrameCount;
u8 gStartNMI;
u8 gStopTasks;
-u8 D_80137E84[4];
+u8 gControllerRumbleFlags[4];
u16 gFillScreenColor;
u16 gFillScreen;
@@ -80,7 +80,7 @@ u8 gSerialThreadStack[0x1000]; // 800E0FB0
void Main_Initialize(void) {
u8 i;
- D_80137E78 = 0;
+ gVIsPerFrame = 0;
gSysFrameCount = 0;
gStartNMI = false;
gStopTasks = false;
@@ -107,25 +107,28 @@ void Audio_ThreadEntry(void* arg0) {
AudioLoad_Init();
Audio_InitSounds();
+
task = AudioThread_CreateTask();
if (task != NULL) {
- task->msgQueue = &gAudioTaskMsgQueue;
+ task->mesgQueue = &gAudioTaskMesgQueue;
task->msg = OS_MESG_32(TASK_MESG_1);
osWritebackDCacheAll();
- osSendMesg(&gTaskMsgQueue, OS_MESG_PTR(task), OS_MESG_PRI_NORMAL);
+ osSendMesg(&gTaskMesgQueue, OS_MESG_PTR(task), OS_MESG_PRI_NORMAL);
}
- while (1) {
+
+ while (true) {
task = AudioThread_CreateTask();
if (task != NULL) {
task->msgQueue = &gAudioTaskMsgQueue;
task->msg = OS_MESG_32(TASK_MESG_1);
osWritebackDCacheAll();
}
- osRecvMesg(&gAudioTaskMsgQueue, NULL, OS_MESG_NOBLOCK);
+ MQ_GET_MESG(&gAudioTaskMesgQueue, NULL);
+
if (task != NULL) {
osSendMesg(&gTaskMsgQueue, OS_MESG_PTR(task), OS_MESG_PRI_NORMAL);
}
- osRecvMesg(&gAudioVImsgQueue, NULL, OS_MESG_BLOCK);
+ MQ_WAIT_FOR_MESG(&gAudioVImesgQueue, NULL);
}
}
@@ -212,9 +215,9 @@ void SerialInterface_ThreadUpdate() {
void Timer_ThreadEntry(void* arg0) {
OSMesg sp24;
- while (1) {
- osRecvMesg(&gTimerTaskMsgQueue, &sp24, OS_MESG_BLOCK);
- // Timer_CompleteTask(sp24.ptr);
+ while (true) {
+ MQ_WAIT_FOR_MESG(&gTimerTaskMesgQueue, &sp24);
+ // Timer_CompleteTask(sp24);
}
}
@@ -222,8 +225,8 @@ extern void Graphics_PushFrame(Gfx* masterDL);
void Graphics_ThreadEntry(void* arg0) {
u8 i;
- u8 var_v1;
- u8 var_v2;
+ u8 visPerFrame;
+ u8 validVIsPerFrame;
Game_Initialize();
osSendMesg(&gSerialThreadMsgQueue, OS_MESG_32(SI_READ_CONTROLLER), OS_MESG_PRI_NORMAL);
@@ -302,12 +305,12 @@ void Graphics_ThreadUpdate(){
}
void Main_InitMesgQueues(void) {
- osCreateMesgQueue(&gDmaMsgQueue, sDmaMsgBuff, ARRAY_COUNT(sDmaMsgBuff));
- osCreateMesgQueue(&gTaskMsgQueue, sTaskMsgBuff, ARRAY_COUNT(sTaskMsgBuff));
- osCreateMesgQueue(&gAudioVImsgQueue, sAudioVImsgBuff, ARRAY_COUNT(sAudioVImsgBuff));
- osCreateMesgQueue(&gAudioTaskMsgQueue, sAudioTaskMsgBuff, ARRAY_COUNT(sAudioTaskMsgBuff));
- osCreateMesgQueue(&gGfxVImsgQueue, sGfxVImsgBuff, ARRAY_COUNT(sGfxVImsgBuff));
- osCreateMesgQueue(&gGfxTaskMsgQueue, sGfxTaskMsgBuff, ARRAY_COUNT(sGfxTaskMsgBuff));
+ osCreateMesgQueue(&gDmaMesgQueue, sDmaMsgBuff, ARRAY_COUNT(sDmaMsgBuff));
+ osCreateMesgQueue(&gTaskMesgQueue, sTaskMsgBuff, ARRAY_COUNT(sTaskMsgBuff));
+ osCreateMesgQueue(&gAudioVImesgQueue, sAudioVImsgBuff, ARRAY_COUNT(sAudioVImsgBuff));
+ osCreateMesgQueue(&gAudioTaskMesgQueue, sAudioTaskMsgBuff, ARRAY_COUNT(sAudioTaskMsgBuff));
+ osCreateMesgQueue(&gGfxVImesgQueue, sGfxVImsgBuff, ARRAY_COUNT(sGfxVImsgBuff));
+ osCreateMesgQueue(&gGfxTaskMesgQueue, sGfxTaskMsgBuff, ARRAY_COUNT(sGfxTaskMsgBuff));
osCreateMesgQueue(&gSerialEventQueue, sSerialEventBuff, ARRAY_COUNT(sSerialEventBuff));
osSetEventMesg(OS_EVENT_SI, &gSerialEventQueue, OS_MESG_PTR(NULL));
osCreateMesgQueue(&gMainThreadMsgQueue, sMainThreadMsgBuff, ARRAY_COUNT(sMainThreadMsgBuff));
@@ -323,17 +326,18 @@ void Main_InitMesgQueues(void) {
}
void Main_HandleRDP(void) {
- SPTask** var_v1 = sGfxTasks;
+ SPTask** task = sGfxTasks;
u8 i;
- if ((*var_v1)->msgQueue != NULL) {
- osSendMesg((*var_v1)->msgQueue, (*var_v1)->msg, OS_MESG_PRI_NORMAL);
+ if ((*task)->mesgQueue != NULL) {
+ osSendMesg((*task)->mesgQueue, (*task)->msg, OS_MESG_NOBLOCK);
}
- (*var_v1)->state = SPTASK_STATE_FINISHED_DP;
- for (i = 0; i < ARRAY_COUNT(sGfxTasks) - 1; i += 1, var_v1++) {
- *var_v1 = *(var_v1 + 1);
+ (*task)->state = SPTASK_STATE_FINISHED_DP;
+
+ for (i = 0; i < ARRAY_COUNT(sGfxTasks) - 1; i += 1, task++) {
+ *task = *(task + 1);
}
- *var_v1 = NULL;
+ *task = NULL;
}
void Main_HandleRSP(void) {
@@ -357,58 +361,58 @@ void Main_HandleRSP(void) {
void Main_GetNewTasks(void) {
u8 i;
- SPTask** var_a0;
- SPTask** var_a1;
- SPTask** var_s0_2;
- SPTask** var_s1_2;
- OSMesg sp40;
- SPTask* sp3C;
-
- var_s0_2 = sNewAudioTasks;
- var_s1_2 = sNewGfxTasks;
+ SPTask** audioTask;
+ SPTask** gfxTask;
+ SPTask** newAudioTask;
+ SPTask** newGfxTask;
+ OSMesg spTaskMsg;
+ SPTask* newTask;
+
+ newAudioTask = sNewAudioTasks;
+ newGfxTask = sNewGfxTasks;
for (i = 0; i < ARRAY_COUNT(sNewAudioTasks); i += 1) {
- *(var_s0_2++) = NULL;
+ *(newAudioTask++) = NULL;
}
for (i = 0; i < ARRAY_COUNT(sNewGfxTasks); i += 1) {
- *(var_s1_2++) = NULL;
+ *(newGfxTask++) = NULL;
}
- var_s0_2 = sNewAudioTasks;
- var_s1_2 = sNewGfxTasks;
- while (osRecvMesg(&gTaskMsgQueue, &sp40, OS_MESG_NOBLOCK) != MSG_QUEUE_EMPTY) {
- sp3C = (SPTask*) sp40.ptr;
- sp3C->state = SPTASK_STATE_NOT_STARTED;
+ newAudioTask = sNewAudioTasks;
+ newGfxTask = sNewGfxTasks;
+ while (MQ_GET_MESG(&gTaskMesgQueue, &spTaskMsg)) {
+ newTask = (SPTask*) spTaskMsg.ptr;
+ newTask->state = SPTASK_STATE_NOT_STARTED;
- switch (sp3C->task.t.type) {
+ switch (newTask->task.t.type) {
case M_AUDTASK:
- *(var_s0_2++) = sp3C;
+ *(newAudioTask++) = newTask;
break;
case M_GFXTASK:
- *(var_s1_2++) = sp3C;
+ *(newGfxTask++) = newTask;
break;
}
}
- var_s0_2 = sNewAudioTasks;
- var_s1_2 = sNewGfxTasks;
- var_a0 = sAudioTasks;
- var_a1 = sGfxTasks;
+ newAudioTask = sNewAudioTasks;
+ newGfxTask = sNewGfxTasks;
+ audioTask = sAudioTasks;
+ gfxTask = sGfxTasks;
- for (i = 0; i < ARRAY_COUNT(sAudioTasks); i += 1, var_a0++) {
- if (*var_a0 == NULL) {
+ for (i = 0; i < ARRAY_COUNT(sAudioTasks); i += 1, audioTask++) {
+ if (*audioTask == NULL) {
break;
}
}
for (i; i < ARRAY_COUNT(sAudioTasks); i += 1) {
- *(var_a0++) = *(var_s0_2++);
+ *(audioTask++) = *(newAudioTask++);
}
- for (i = 0; i < ARRAY_COUNT(sGfxTasks); i += 1, var_a1++) {
- if (*var_a1 == NULL) {
+ for (i = 0; i < ARRAY_COUNT(sGfxTasks); i += 1, gfxTask++) {
+ if (*gfxTask == NULL) {
break;
}
}
for (i; i < ARRAY_COUNT(sGfxTasks); i += 1) {
- *(var_a1++) = *(var_s1_2++);
+ *(gfxTask++) = *(newGfxTask++);
}
}
diff --git a/src/sys/sys_math.c b/src/sys/sys_math.c
index 5e9c8591..a4ff84d9 100644
--- a/src/sys/sys_math.c
+++ b/src/sys/sys_math.c
@@ -1,4 +1,5 @@
#include "sys.h"
+#include "prevent_bss_reordering.h"
s32 sSeededRandSeed3;
s32 sRandSeed1;
diff --git a/src/sys/sys_matrix.c b/src/sys/sys_matrix.c
index b04c8bf4..5426b040 100644
--- a/src/sys/sys_matrix.c
+++ b/src/sys/sys_matrix.c
@@ -51,15 +51,16 @@ void Matrix_Copy(Matrix* dst, Matrix* src) {
// Makes a copy of the stack's current matrix and puts it on the top of the stack
void Matrix_Push(Matrix** mtxStack) {
Matrix_Copy(*mtxStack + 1, *mtxStack);
- *mtxStack += 1;
+ (*mtxStack)++;
}
// Removes the top matrix of the stack
void Matrix_Pop(Matrix** mtxStack) {
- *mtxStack -= 1;
+ (*mtxStack)--;
}
-void MtxFMtxFMult(MtxF* mfB, MtxF* mfA, MtxF* dest) {
+// Copies tf into mtx (MTXF_NEW) or applies it to mtx (MTXF_APPLY)
+void Matrix_Mult(Matrix* mtx, Matrix* tf, u8 mode) {
f32 rx;
f32 ry;
f32 rz;
@@ -233,7 +234,7 @@ void Matrix_Mult(Matrix* mtx, Matrix* tf, u8 mode) {
}
}
-// Creates a translation matrix in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
+// Creates a translation matrix in mtx (MTXF_NEW) or applies one to mtx (MTXF_APPLY)
void Matrix_Translate(Matrix* mtx, f32 x, f32 y, f32 z, u8 mode) {
MtxF* cmf = mtx->m;
f32 tempX;
@@ -272,9 +273,11 @@ void Matrix_Translate(Matrix* mtx, f32 x, f32 y, f32 z, u8 mode) {
}
}
-// Creates a scale matrix in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
-void Matrix_Scale(Matrix* mtx, f32 x, f32 y, f32 z, u8 mode) {
- MtxF* cmf = mtx->m;
+// Creates a scale matrix in mtx (MTXF_NEW) or applies one to mtx (MTXF_APPLY)
+void Matrix_Scale(Matrix* mtx, f32 xScale, f32 yScale, f32 zScale, u8 mode) {
+ f32 rx;
+ f32 ry;
+ s32 i;
if (mode == 1) {
cmf->xx *= x;
@@ -309,15 +312,13 @@ void Matrix_Scale(Matrix* mtx, f32 x, f32 y, f32 z, u8 mode) {
}
}
-// Creates rotation matrix about the X axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
-void Matrix_RotateX(Matrix* mtx, f32 x, u8 mode) {
- MtxF* cmf;
- f32 sin;
- f32 cos;
- f32 tempY;
- f32 tempZ;
- f32 zero = 0.0;
- f32 one = 1.0;
+// Creates rotation matrix about the X axis in mtx (MTXF_NEW) or applies one to mtx (MTXF_APPLY)
+void Matrix_RotateX(Matrix* mtx, f32 angle, u8 mode) {
+ f32 cs;
+ f32 sn;
+ f32 ry;
+ f32 rz;
+ s32 i;
if (mode == 1) {
if (x != 0) {
@@ -376,15 +377,13 @@ void Matrix_RotateX(Matrix* mtx, f32 x, u8 mode) {
}
}
-// Creates rotation matrix about the Y axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
-void Matrix_RotateY(Matrix* mtx, f32 y, u8 mode) {
- MtxF* cmf;
- f32 sin;
- f32 cos;
- f32 tempX;
- f32 tempZ;
- f32 zero = 0.0;
- f32 one = 1.0;
+// Creates rotation matrix about the Y axis in mtx (MTXF_NEW) or applies one to mtx (MTXF_APPLY)
+void Matrix_RotateY(Matrix* mtx, f32 angle, u8 mode) {
+ f32 cs;
+ f32 sn;
+ f32 rx;
+ f32 rz;
+ s32 i;
if (mode == 1) {
if (y != 0.0f) {
@@ -443,13 +442,13 @@ void Matrix_RotateY(Matrix* mtx, f32 y, u8 mode) {
}
}
-// Creates rotation matrix about the Z axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
-void Matrix_RotateZ(Matrix* mtx, f32 z, u8 mode) {
- MtxF* cmf;
- f32 sin;
- f32 cos;
- f32 tempX;
- f32 tempY;
+// Creates rotation matrix about the Z axis in mtx (MTXF_NEW) or applies one to mtx (MTXF_APPLY)
+void Matrix_RotateZ(Matrix* mtx, f32 angle, u8 mode) {
+ f32 cs;
+ f32 sn;
+ f32 rx;
+ f32 ry;
+ s32 i;
if (mode == 1) {
if (z != 0) {
@@ -508,7 +507,7 @@ void Matrix_RotateZ(Matrix* mtx, f32 z, u8 mode) {
}
}
-// Creates rotation matrix about a given vector axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY).
+// Creates rotation matrix about a given vector axis in mtx (MTXF_NEW) or applies one to mtx (MTXF_APPLY).
// The vector specifying the axis does not need to be a unit vector.
void Matrix_RotateAxis(Matrix* mtx, f32 angle, f32 x, f32 y, f32 z, u8 mode) {
MtxF* cmf;
@@ -651,8 +650,8 @@ void Matrix_GetYRPAngles(Matrix* mtx, Vec3f* rot) {
xHatP.z -= originP.z;
rot->y = Math_Atan2F(zHatP.x, zHatP.z);
rot->x = -Math_Atan2F(zHatP.y, sqrtf(SQ(zHatP.x) + SQ(zHatP.z)));
- Matrix_RotateX(&invYP, -rot->x, 0);
- Matrix_RotateY(&invYP, -rot->y, 1);
+ Matrix_RotateX(&invYP, -rot->x, MTXF_NEW);
+ Matrix_RotateY(&invYP, -rot->y, MTXF_APPLY);
Matrix_MultVec3fNoTranslate(&invYP, &xHatP, &xHat);
rot->x *= M_RTOD;
rot->y *= M_RTOD;
@@ -681,15 +680,15 @@ void Matrix_GetXYZAngles(Matrix* mtx, Vec3f* rot) {
yHatP.z -= originP.z;
rot->z = Math_Atan2F(xHatP.y, xHatP.x);
rot->y = -Math_Atan2F(xHatP.z, sqrtf(SQ(xHatP.x) + SQ(xHatP.y)));
- Matrix_RotateY(&invYZ, -rot->y, 0);
- Matrix_RotateZ(&invYZ, -rot->z, 1);
+ Matrix_RotateY(&invYZ, -rot->y, MTXF_NEW);
+ Matrix_RotateZ(&invYZ, -rot->z, MTXF_APPLY);
Matrix_MultVec3fNoTranslate(&invYZ, &yHatP, &yHat);
rot->x = Math_Atan2F(yHat.z, yHat.y) * M_RTOD;
rot->y *= M_RTOD;
rot->z *= M_RTOD;
}
-// Creates a look-at matrix from Eye, At, and Up in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY).
+// Creates a look-at matrix from Eye, At, and Up in mtx (MTXF_NEW) or applies one to mtx (MTXF_APPLY).
// A look-at matrix is a rotation-translation matrix that maps y to Up, z to (At - Eye), and translates to Eye
void Matrix_LookAt(Matrix* mtx, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp,
u8 mode) {
diff --git a/src/sys/sys_save.c b/src/sys/sys_save.c
index 17afd829..6e5fc6e0 100644
--- a/src/sys/sys_save.c
+++ b/src/sys/sys_save.c
@@ -7,20 +7,25 @@ SaveFile sPrevSaveData;
s32 Save_ReadBlock(s32 arg0, u8* arg1) {
if (osEepromRead(&gSerialEventQueue, arg0, arg1)) {
- (void) "EEPROM インターフェース回路反応なし (READ)\n";
+ PRINTF("EEPROM インターフェース回路反応なし (READ)\n");
return -1;
+ } else {
+ PRINTF("EEPROM READ %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n");
+ return 0;
}
- (void) "EEPROM READ %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n";
- return 0;
}
s32 Save_WriteBlock(s32 arg0, u8* arg1) {
if (osEepromWrite(&gSerialEventQueue, arg0, arg1)) {
- (void) "EEPROM インターフェース回路反応なし (WRITE)\n";
+ PRINTF("EEPROM インターフェース回路反応なし (WRITE)\n");
return -1;
+ } else {
+ Timer_Wait(MSEC_TO_CYCLES(15));
+ PRINTF("EEPROM WRITE %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n");
+ return 0;
}
// Timer_Wait(MSEC_TO_CYCLES(15));
- (void) "EEPROM WRITE %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n";
+ PRINTF("EEPROM WRITE %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n");
return 0;
}
@@ -30,9 +35,10 @@ s32 Save_WriteEeprom(SaveFile* arg0) {
s32 j;
if (osEepromProbe(&gSerialEventQueue) != 1) {
- (void) "EEPROM が ありません\n";
+ PRINTF("EEPROM が ありません\n");
return -1;
}
+
for (i = 0; i < EEPROM_MAXBLOCKS; i++) {
var_a2 = 0;
for (j = 0; j < EEPROM_BLOCK_SIZE; j++) {
@@ -52,7 +58,7 @@ s32 Save_ReadEeprom(SaveFile* arg0) {
s32 i;
if (osEepromProbe(&gSerialEventQueue) != 1) {
- (void) "EEPROM が ありません\n";
+ PRINTF("EEPROM が ありません\n");
return -1;
}
for (i = 0; i < EEPROM_MAXBLOCKS; i++) {
diff --git a/src/sys/sys_timer.c b/src/sys/sys_timer.c
index f84577fe..b00fbc9c 100644
--- a/src/sys/sys_timer.c
+++ b/src/sys/sys_timer.c
@@ -41,4 +41,10 @@ void Timer_CompleteTask(TimerTask* task) {
task->active = false;
}
-void \ No newline at end of file
+void Timer_Wait(u64 time) {
+ OSTimer timer;
+ OSMesg dummy;
+
+ osSetTimer(&timer, time, 0, &gTimerWaitMesgQueue, NULL);
+ MQ_WAIT_FOR_MESG(&gTimerWaitMesgQueue, &dummy);
+}