The game is fucking running

This commit is contained in:
KiritoDv
2024-04-01 23:13:52 -06:00
parent 110e54c562
commit 9e6800d369
18 changed files with 769 additions and 474 deletions
+92 -72
View File
@@ -224,10 +224,12 @@ void Timer_ThreadEntry(void* arg0) {
while (1) {
osRecvMesg(&gTimerTaskMsgQueue, &sp24, OS_MESG_BLOCK);
Timer_CompleteTask(sp24.ptr);
// Timer_CompleteTask(sp24.ptr);
}
}
extern void Graphics_PushFrame(Gfx* masterDL);
void Graphics_ThreadEntry(void* arg0) {
u8 i;
u8 var_v1;
@@ -247,44 +249,66 @@ void Graphics_ThreadEntry(void* arg0) {
gSPEndDisplayList(gMasterDisp++);
}
Graphics_SetTask();
while (1) {
gSysFrameCount++;
Graphics_InitializeTask(gSysFrameCount);
osRecvMesg(&gControllerMsgQueue, NULL, OS_MESG_BLOCK);
osSendMesg(&gSerialThreadMsgQueue, OS_MESG_32(SI_RUMBLE), OS_MESG_PRI_NORMAL);
Controller_UpdateInput();
osSendMesg(&gSerialThreadMsgQueue, OS_MESG_32(SI_READ_CONTROLLER), OS_MESG_PRI_NORMAL);
if (gControllerPress[3].button & U_JPAD) {
Main_SetVIMode();
}
{
gSPSegment(gUnkDisp1++, 0, 0);
gSPDisplayList(gMasterDisp++, gGfxPool->unkDL1);
Game_Update();
if (gStartNMI == 1) {
Graphics_NMIWipe();
}
gSPEndDisplayList(gUnkDisp1++);
gSPEndDisplayList(gUnkDisp2++);
gSPDisplayList(gMasterDisp++, gGfxPool->unkDL2);
gDPFullSync(gMasterDisp++);
gSPEndDisplayList(gMasterDisp++);
}
osRecvMesg(&gGfxTaskMsgQueue, NULL, OS_MESG_BLOCK);
Graphics_SetTask();
if (gFillScreen == 0) {
osViSwapBuffer(&gFrameBuffers[(gSysFrameCount - 1) % 3]);
}
// func_80007FE4(&gFrameBuffers[(gSysFrameCount - 1) % 3], SCREEN_WIDTH, 16);
// while (1) {
var_v1 = MIN(D_80137E78, 4);
var_v2 = MAX(var_v1, gGfxVImsgQueue.validCount + 1);
for (i = 0; i < var_v2; i += 1) { // Can't be ++
osRecvMesg(&gGfxVImsgQueue, NULL, OS_MESG_BLOCK);
}
// }
}
Audio_Update();
void Graphics_ThreadUpdate(){
if (GfxDebuggerIsDebugging()) {
Graphics_PushFrame(gGfxPool->masterDL);
return;
}
gSysFrameCount++;
Graphics_InitializeTask(gSysFrameCount);
osRecvMesg(&gControllerMsgQueue, NULL, OS_MESG_BLOCK);
osSendMesg(&gSerialThreadMsgQueue, OS_MESG_32(SI_RUMBLE), OS_MESG_PRI_NORMAL);
Controller_UpdateInput();
osSendMesg(&gSerialThreadMsgQueue, OS_MESG_32(SI_READ_CONTROLLER), OS_MESG_PRI_NORMAL);
if (gControllerPress[3].button & U_JPAD) {
Main_SetVIMode();
}
{
gSPSegment(gUnkDisp1++, 0, 0);
gSPDisplayList(gMasterDisp++, gGfxPool->unkDL1);
Game_Update();
if (gStartNMI == 1) {
Graphics_NMIWipe();
}
gSPEndDisplayList(gUnkDisp1++);
gSPEndDisplayList(gUnkDisp2++);
gSPDisplayList(gMasterDisp++, gGfxPool->unkDL2);
gDPFullSync(gMasterDisp++);
gSPEndDisplayList(gMasterDisp++);
}
osRecvMesg(&gGfxTaskMsgQueue, NULL, OS_MESG_BLOCK);
Graphics_SetTask();
if(GfxDebuggerIsDebuggingRequested()) {
GfxDebuggerDebugDisplayList(gGfxPool->masterDL);
}
Graphics_PushFrame(gGfxPool->masterDL);
if (gFillScreen == 0) {
osViSwapBuffer(&gFrameBuffers[(gSysFrameCount - 1) % 3]);
}
Controller_ReadData();
// LTODO: FAULT_CRASH
// func_80007FE4(&gFrameBuffers[(gSysFrameCount - 1) % 3], SCREEN_WIDTH, 16);
// LTODO: Figure out what this is
// var_v1 = MIN(D_80137E78, 4);
// var_v2 = MAX(var_v1, gGfxVImsgQueue.validCount + 1);
// for (i = 0; i < var_v2; i += 1) { // Can't be ++
// osRecvMesg(&gGfxVImsgQueue, NULL, OS_MESG_BLOCK);
// }
// LTODO: There is no audio for now :P
// Audio_Update();
}
void Main_InitMesgQueues(void) {
@@ -424,45 +448,41 @@ void Main_ThreadEntry(void* arg0) {
OSMesg ogMsg;
u32 mesg;
// osCreateThread(&gAudioThread, THREAD_ID_AUDIO, Audio_ThreadEntry, arg0,
// gAudioThreadStack + sizeof(gAudioThreadStack), 80);
// osStartThread(&gAudioThread);
// osCreateThread(&gGraphicsThread, THREAD_ID_GRAPHICS, Graphics_ThreadEntry, arg0,
// gGraphicsThreadStack + sizeof(gGraphicsThreadStack), 40);
// osStartThread(&gGraphicsThread);
// osCreateThread(&gTimerThread, THREAD_ID_TIMER, Timer_ThreadEntry, arg0,
// gTimerThreadStack + sizeof(gTimerThreadStack), 60);
// osStartThread(&gTimerThread);
// osCreateThread(&gSerialThread, THREAD_ID_SERIAL, SerialInterface_ThreadEntry, arg0,
// gSerialThreadStack + sizeof(gSerialThreadStack), 20);
// osStartThread(&gSerialThread);
// LTODO: Implement audio
// Audio_ThreadEntry(NULL);
Graphics_ThreadEntry(NULL);
Controller_Init();
Main_InitMesgQueues();
// LTODO: Implement timers
// Timer_ThreadEntry(NULL);
while (true) {
osRecvMesg(&gMainThreadMsgQueue, &ogMsg, OS_MESG_BLOCK);
mesg = ogMsg.data32;
switch (mesg) {
case EVENT_MESG_VI:
osSendMesg(&gAudioVImsgQueue, OS_MESG_32(EVENT_MESG_VI), OS_MESG_PRI_NORMAL);
osSendMesg(&gGfxVImsgQueue, OS_MESG_32(EVENT_MESG_VI), OS_MESG_PRI_NORMAL);
Main_GetNewTasks();
break;
case EVENT_MESG_SP:
Main_HandleRSP();
break;
case EVENT_MESG_DP:
Main_HandleRDP();
break;
case EVENT_MESG_PRENMI:
gStartNMI = 1;
break;
}
if (gStopTasks == 0) {
Main_StartNextTask();
}
}
// N64 Stuff should not be needed
// Main_InitMesgQueues();
// while (true) {
// osRecvMesg(&gMainThreadMsgQueue, &ogMsg, OS_MESG_BLOCK);
// mesg = ogMsg.data32;
// switch (mesg) {
// case EVENT_MESG_VI:
// osSendMesg(&gAudioVImsgQueue, OS_MESG_32(EVENT_MESG_VI), OS_MESG_PRI_NORMAL);
// osSendMesg(&gGfxVImsgQueue, OS_MESG_32(EVENT_MESG_VI), OS_MESG_PRI_NORMAL);
// Main_GetNewTasks();
// break;
// case EVENT_MESG_SP:
// Main_HandleRSP();
// break;
// case EVENT_MESG_DP:
// Main_HandleRDP();
// break;
// case EVENT_MESG_PRENMI:
// gStartNMI = 1;
// break;
// }
// if (gStopTasks == 0) {
// Main_StartNextTask();
// }
// }
}
void Idle_ThreadEntry(void* arg0) {
+506 -313
View File
@@ -1,19 +1,28 @@
#include "sys.h"
Mtx gIdentityMtx = {
.intPart = {
{ 1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 1 },
},
.fracPart = {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
},
};
#define qs1616(e) ((s32)((e)*0x00010000))
#define IPART(x) ((qs1616(x) >> 16) & 0xFFFF)
#define FPART(x) (qs1616(x) & 0xFFFF)
#define gdSPDefMtx(xx, yx, zx, wx, xy, yy, zy, wy, xz, yz, zz, wz, xw, yw, zw, ww) \
{ \
{ \
(IPART(xx) << 0x10) | IPART(xy), (IPART(xz) << 0x10) | IPART(xw), (IPART(yx) << 0x10) | IPART(yy), \
(IPART(yz) << 0x10) | IPART(yw), (IPART(zx) << 0x10) | IPART(zy), (IPART(zz) << 0x10) | IPART(zw), \
(IPART(wx) << 0x10) | IPART(wy), (IPART(wz) << 0x10) | IPART(ww), (FPART(xx) << 0x10) | FPART(xy), \
(FPART(xz) << 0x10) | FPART(xw), (FPART(yx) << 0x10) | FPART(yy), (FPART(yz) << 0x10) | FPART(yw), \
(FPART(zx) << 0x10) | FPART(zy), (FPART(zz) << 0x10) | FPART(zw), (FPART(wx) << 0x10) | FPART(wy), \
(FPART(wz) << 0x10) | FPART(ww), \
} \
}
Mtx gIdentityMtx = gdSPDefMtx(
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
Matrix gIdentityMatrix = { {
{ 1.0f, 0.0f, 0.0f, 0.0f },
@@ -23,9 +32,9 @@ Matrix gIdentityMatrix = { {
} };
Matrix* gGfxMatrix;
Matrix sGfxMatrixStack[0x20];
Matrix sGfxMatrixStack[0x150];
Matrix* gCalcMatrix;
Matrix sCalcMatrixStack[0x20];
Matrix sCalcMatrixStack[0x150];
// Copies src Matrix into dst
void Matrix_Copy(Matrix* dst, Matrix* src) {
@@ -50,375 +59,559 @@ void Matrix_Pop(Matrix** mtxStack) {
*mtxStack -= 1;
}
// Copies tf into mtx (MTXMODE_NEW) or applies it to mtx (MTXMODE_APPLY)
void Matrix_Mult(Matrix* mtx, Matrix* tf, u8 mode) {
void MtxFMtxFMult(MtxF* mfB, MtxF* mfA, MtxF* dest) {
f32 rx;
f32 ry;
f32 rz;
f32 rw;
s32 i0;
s32 i1;
s32 i2;
s32 i3;
//---COL1---
f32 cx = mfB->xx;
f32 cy = mfB->xy;
f32 cz = mfB->xz;
f32 cw = mfB->xw;
//--------
rx = mfA->xx;
ry = mfA->yx;
rz = mfA->zx;
rw = mfA->wx;
dest->xx = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xy;
ry = mfA->yy;
rz = mfA->zy;
rw = mfA->wy;
dest->xy = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xz;
ry = mfA->yz;
rz = mfA->zz;
rw = mfA->wz;
dest->xz = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xw;
ry = mfA->yw;
rz = mfA->zw;
rw = mfA->ww;
dest->xw = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
//---2Col---
cx = mfB->yx;
cy = mfB->yy;
cz = mfB->yz;
cw = mfB->yw;
//--------
rx = mfA->xx;
ry = mfA->yx;
rz = mfA->zx;
rw = mfA->wx;
dest->yx = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xy;
ry = mfA->yy;
rz = mfA->zy;
rw = mfA->wy;
dest->yy = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xz;
ry = mfA->yz;
rz = mfA->zz;
rw = mfA->wz;
dest->yz = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xw;
ry = mfA->yw;
rz = mfA->zw;
rw = mfA->ww;
dest->yw = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
//---3Col---
cx = mfB->zx;
cy = mfB->zy;
cz = mfB->zz;
cw = mfB->zw;
//--------
rx = mfA->xx;
ry = mfA->yx;
rz = mfA->zx;
rw = mfA->wx;
dest->zx = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xy;
ry = mfA->yy;
rz = mfA->zy;
rw = mfA->wy;
dest->zy = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xz;
ry = mfA->yz;
rz = mfA->zz;
rw = mfA->wz;
dest->zz = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xw;
ry = mfA->yw;
rz = mfA->zw;
rw = mfA->ww;
dest->zw = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
//---4Col---
cx = mfB->wx;
cy = mfB->wy;
cz = mfB->wz;
cw = mfB->ww;
//--------
rx = mfA->xx;
ry = mfA->yx;
rz = mfA->zx;
rw = mfA->wx;
dest->wx = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xy;
ry = mfA->yy;
rz = mfA->zy;
rw = mfA->wy;
dest->wy = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xz;
ry = mfA->yz;
rz = mfA->zz;
rw = mfA->wz;
dest->wz = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
rx = mfA->xw;
ry = mfA->yw;
rz = mfA->zw;
rw = mfA->ww;
dest->ww = (cx * rx) + (cy * ry) + (cz * rz) + (cw * rw);
}
void Matrix_MtxFCopy(MtxF* dest, MtxF* src) {
dest->xx = src->xx;
dest->yx = src->yx;
dest->zx = src->zx;
dest->wx = src->wx;
dest->xy = src->xy;
dest->yy = src->yy;
dest->zy = src->zy;
dest->wy = src->wy;
dest->xx = src->xx;
dest->yx = src->yx;
dest->zx = src->zx;
dest->wx = src->wx;
dest->xy = src->xy;
dest->yy = src->yy;
dest->zy = src->zy;
dest->wy = src->wy;
dest->xz = src->xz;
dest->yz = src->yz;
dest->zz = src->zz;
dest->wz = src->wz;
dest->xw = src->xw;
dest->yw = src->yw;
dest->zw = src->zw;
dest->ww = src->ww;
dest->xz = src->xz;
dest->yz = src->yz;
dest->zz = src->zz;
dest->wz = src->wz;
dest->xw = src->xw;
dest->yw = src->yw;
dest->zw = src->zw;
dest->ww = src->ww;
}
// Copies tf into mtx (MTXMODE_NEW) or applies it to mtx (MTXMODE_APPLY)
void Matrix_Mult(Matrix* mtx, Matrix* tf, u8 mode) {
MtxF* cmf = mtx->m;
if (mode == 1) {
rx = mtx->m[0][0];
ry = mtx->m[1][0];
rz = mtx->m[2][0];
rw = mtx->m[3][0];
for (i0 = 0; i0 < 4; i0++) {
mtx->m[i0][0] = (rx * tf->m[i0][0]) + (ry * tf->m[i0][1]) + (rz * tf->m[i0][2]) + (rw * tf->m[i0][3]);
}
rx = mtx->m[0][1];
ry = mtx->m[1][1];
rz = mtx->m[2][1];
rw = mtx->m[3][1];
for (i1 = 0; i1 < 4; i1++) {
mtx->m[i1][1] = (rx * tf->m[i1][0]) + (ry * tf->m[i1][1]) + (rz * tf->m[i1][2]) + (rw * tf->m[i1][3]);
}
rx = mtx->m[0][2];
ry = mtx->m[1][2];
rz = mtx->m[2][2];
rw = mtx->m[3][2];
for (i2 = 0; i2 < 4; i2++) {
mtx->m[i2][2] = (rx * tf->m[i2][0]) + (ry * tf->m[i2][1]) + (rz * tf->m[i2][2]) + (rw * tf->m[i2][3]);
}
rx = mtx->m[0][3];
ry = mtx->m[1][3];
rz = mtx->m[2][3];
rw = mtx->m[3][3];
for (i3 = 0; i3 < 4; i3++) {
mtx->m[i3][3] = (rx * tf->m[i3][0]) + (ry * tf->m[i3][1]) + (rz * tf->m[i3][2]) + (rw * tf->m[i3][3]);
}
MtxFMtxFMult(cmf, tf->m, cmf);
} else {
Matrix_Copy(mtx, tf);
Matrix_MtxFCopy(cmf, tf->m);
}
}
// Creates a translation matrix in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
void Matrix_Translate(Matrix* mtx, f32 x, f32 y, f32 z, u8 mode) {
f32 rx;
f32 ry;
s32 i;
MtxF* cmf = mtx->m;
f32 tempX;
f32 tempY;
if (mode == 1) {
for (i = 0; i < 4; i++) {
rx = mtx->m[0][i];
ry = mtx->m[1][i];
mtx->m[3][i] += (rx * x) + (ry * y) + (mtx->m[2][i] * z);
}
tempX = cmf->xx;
tempY = cmf->xy;
cmf->xw += tempX * x + tempY * y + cmf->xz * z;
tempX = cmf->yx;
tempY = cmf->yy;
cmf->yw += tempX * x + tempY * y + cmf->yz * z;
tempX = cmf->zx;
tempY = cmf->zy;
cmf->zw += tempX * x + tempY * y + cmf->zz * z;
tempX = cmf->wx;
tempY = cmf->wy;
cmf->ww += tempX * x + tempY * y + cmf->wz * z;
} else {
mtx->m[3][0] = x;
mtx->m[3][1] = y;
mtx->m[3][2] = z;
mtx->m[0][1] = mtx->m[0][2] = mtx->m[0][3] = mtx->m[1][0] = mtx->m[1][2] = mtx->m[1][3] = mtx->m[2][0] =
mtx->m[2][1] = mtx->m[2][3] = 0.0f;
mtx->m[0][0] = mtx->m[1][1] = mtx->m[2][2] = mtx->m[3][3] = 1.0f;
cmf->yx = 0.0f;
cmf->zx = 0.0f;
cmf->wx = 0.0f;
cmf->xy = 0.0f;
cmf->zy = 0.0f;
cmf->wy = 0.0f;
cmf->xz = 0.0f;
cmf->yz = 0.0f;
cmf->wz = 0.0f;
cmf->xx = 1.0f;
cmf->yy = 1.0f;
cmf->zz = 1.0f;
cmf->ww = 1.0f;
cmf->xw = x;
cmf->yw = y;
cmf->zw = z;
}
}
// Creates a scale matrix in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
void Matrix_Scale(Matrix* mtx, f32 xScale, f32 yScale, f32 zScale, u8 mode) {
f32 rx;
f32 ry;
s32 i;
void Matrix_Scale(Matrix* mtx, f32 x, f32 y, f32 z, u8 mode) {
MtxF* cmf = mtx->m;
if (mode == 1) {
for (i = 0; i < 4; i++) {
rx = mtx->m[0][i];
ry = mtx->m[1][i];
mtx->m[0][i] = rx * xScale;
mtx->m[1][i] = ry * yScale;
mtx->m[2][i] *= zScale;
}
cmf->xx *= x;
cmf->yx *= x;
cmf->zx *= x;
cmf->xy *= y;
cmf->yy *= y;
cmf->zy *= y;
cmf->xz *= z;
cmf->yz *= z;
cmf->zz *= z;
cmf->wx *= x;
cmf->wy *= y;
cmf->wz *= z;
} else {
mtx->m[0][0] = xScale;
mtx->m[1][1] = yScale;
mtx->m[2][2] = zScale;
mtx->m[0][1] = mtx->m[0][2] = mtx->m[0][3] = mtx->m[1][0] = mtx->m[1][2] = mtx->m[1][3] = mtx->m[2][0] =
mtx->m[2][1] = mtx->m[2][3] = mtx->m[3][0] = mtx->m[3][1] = mtx->m[3][2] = 0.0f;
mtx->m[3][3] = 1.0f;
cmf->yx = 0.0f;
cmf->zx = 0.0f;
cmf->wx = 0.0f;
cmf->xy = 0.0f;
cmf->zy = 0.0f;
cmf->wy = 0.0f;
cmf->xz = 0.0f;
cmf->yz = 0.0f;
cmf->wz = 0.0f;
cmf->xw = 0.0f;
cmf->yw = 0.0f;
cmf->zw = 0.0f;
cmf->ww = 1.0f;
cmf->xx = x;
cmf->yy = y;
cmf->zz = z;
}
}
// Creates rotation matrix about the X axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
void Matrix_RotateX(Matrix* mtx, f32 angle, u8 mode) {
f32 cs;
f32 sn;
f32 ry;
f32 rz;
s32 i;
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;
sn = __sinf(angle);
cs = __cosf(angle);
if (mode == 1) {
for (i = 0; i < 4; i++) {
ry = mtx->m[1][i];
rz = mtx->m[2][i];
if (x != 0) {
cmf = mtx->m;
mtx->m[1][i] = (ry * cs) + (rz * sn);
mtx->m[2][i] = (rz * cs) - (ry * sn);
sin = sinf(x);
cos = cosf(x);
tempY = cmf->xy;
tempZ = cmf->xz;
cmf->xy = tempY * cos + tempZ * sin;
cmf->xz = tempZ * cos - tempY * sin;
tempY = cmf->yy;
tempZ = cmf->yz;
cmf->yy = tempY * cos + tempZ * sin;
cmf->yz = tempZ * cos - tempY * sin;
tempY = cmf->zy;
tempZ = cmf->zz;
cmf->zy = tempY * cos + tempZ * sin;
cmf->zz = tempZ * cos - tempY * sin;
tempY = cmf->wy;
tempZ = cmf->wz;
cmf->wy = tempY * cos + tempZ * sin;
cmf->wz = tempZ * cos - tempY * sin;
}
} else {
mtx->m[1][1] = mtx->m[2][2] = cs;
mtx->m[1][2] = sn;
mtx->m[2][1] = -sn;
mtx->m[0][0] = mtx->m[3][3] = 1.0f;
mtx->m[0][1] = mtx->m[0][2] = mtx->m[0][3] = mtx->m[1][0] = mtx->m[1][3] = mtx->m[2][0] = mtx->m[2][3] =
mtx->m[3][0] = mtx->m[3][1] = mtx->m[3][2] = 0.0f;
cmf = mtx->m;
if (x != 0) {
sin = sinf(x);
cos = cosf(x);
} else {
sin = zero;
cos = one;
}
cmf->xx = one;
cmf->yx = zero;
cmf->zx = zero;
cmf->wx = zero;
cmf->xy = zero;
cmf->yy = cos;
cmf->zy = sin;
cmf->wy = zero;
cmf->xz = zero;
cmf->yz = -sin;
cmf->zz = cos;
cmf->wz = zero;
cmf->xw = zero;
cmf->yw = zero;
cmf->zw = zero;
cmf->ww = one;
}
}
// Creates rotation matrix about the Y axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
void Matrix_RotateY(Matrix* mtx, f32 angle, u8 mode) {
f32 cs;
f32 sn;
f32 rx;
f32 rz;
s32 i;
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;
sn = __sinf(angle);
cs = __cosf(angle);
if (mode == 1) {
for (i = 0; i < 4; i++) {
rx = mtx->m[0][i];
rz = mtx->m[2][i];
if (y != 0.0f) {
cmf = mtx->m;
mtx->m[0][i] = (rx * cs) - (rz * sn);
mtx->m[2][i] = (rx * sn) + (rz * cs);
sin = sinf(y);
cos = cosf(y);
tempX = cmf->xx;
tempZ = cmf->xz;
cmf->xx = tempX * cos - tempZ * sin;
cmf->xz = tempX * sin + tempZ * cos;
tempX = cmf->yx;
tempZ = cmf->yz;
cmf->yx = tempX * cos - tempZ * sin;
cmf->yz = tempX * sin + tempZ * cos;
tempX = cmf->zx;
tempZ = cmf->zz;
cmf->zx = tempX * cos - tempZ * sin;
cmf->zz = tempX * sin + tempZ * cos;
tempX = cmf->wx;
tempZ = cmf->wz;
cmf->wx = tempX * cos - tempZ * sin;
cmf->wz = tempX * sin + tempZ * cos;
}
} else {
mtx->m[0][0] = mtx->m[2][2] = cs;
mtx->m[0][2] = -sn;
mtx->m[2][0] = sn;
mtx->m[1][1] = mtx->m[3][3] = 1.0f;
mtx->m[0][1] = mtx->m[0][3] = mtx->m[1][0] = mtx->m[1][2] = mtx->m[1][3] = mtx->m[2][1] = mtx->m[2][3] =
mtx->m[3][0] = mtx->m[3][1] = mtx->m[3][2] = 0.0f;
cmf = mtx->m;
if (y != 0.0f) {
sin = sinf(y);
cos = cosf(y);
} else {
cos = one;
sin = zero;
}
cmf->yx = zero;
cmf->wx = zero;
cmf->xy = zero;
cmf->zy = zero;
cmf->wy = zero;
cmf->yz = zero;
cmf->wz = zero;
cmf->xw = zero;
cmf->yw = zero;
cmf->zw = zero;
cmf->yy = one;
cmf->ww = one;
cmf->xx = cos;
cmf->zz = cos;
cmf->zx = -sin;
cmf->xz = sin;
}
}
// Creates rotation matrix about the Z axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY)
void Matrix_RotateZ(Matrix* mtx, f32 angle, u8 mode) {
f32 cs;
f32 sn;
f32 rx;
f32 ry;
s32 i;
void Matrix_RotateZ(Matrix* mtx, f32 z, u8 mode) {
MtxF* cmf;
f32 sin;
f32 cos;
f32 tempX;
f32 tempY;
sn = __sinf(angle);
cs = __cosf(angle);
if (mode == 1) {
for (i = 0; i < 4; i++) {
rx = mtx->m[0][i];
ry = mtx->m[1][i];
if (z != 0) {
cmf = mtx->m;
mtx->m[0][i] = (rx * cs) + (ry * sn);
mtx->m[1][i] = (ry * cs) - (rx * sn);
sin = sinf(z);
cos = cosf(z);
tempX = cmf->xx;
tempY = cmf->xy;
cmf->xx = tempX * cos + tempY * sin;
cmf->xy = tempY * cos - tempX * sin;
tempX = cmf->yx;
tempY = cmf->yy;
cmf->yx = tempX * cos + tempY * sin;
cmf->yy = tempY * cos - tempX * sin;
tempX = cmf->zx;
tempY = cmf->zy;
cmf->zx = tempX * cos + tempY * sin;
cmf->zy = tempY * cos - tempX * sin;
tempX = cmf->wx;
tempY = cmf->wy;
cmf->wx = tempX * cos + tempY * sin;
cmf->wy = tempY * cos - tempX * sin;
}
} else {
mtx->m[0][0] = mtx->m[1][1] = cs;
mtx->m[0][1] = sn;
mtx->m[1][0] = -sn;
mtx->m[2][2] = mtx->m[3][3] = 1.0f;
mtx->m[0][2] = mtx->m[0][3] = mtx->m[1][2] = mtx->m[1][3] = mtx->m[2][0] = mtx->m[2][1] = mtx->m[2][3] =
mtx->m[3][0] = mtx->m[3][1] = mtx->m[3][2] = 0.0f;
cmf = mtx->m;
if (z != 0) {
sin = sinf(z);
cos = cosf(z);
} else {
sin = 0.0f;
cos = 1.0f;
}
cmf->zx = 0.0f;
cmf->wx = 0.0f;
cmf->zy = 0.0f;
cmf->wy = 0.0f;
cmf->xz = 0.0f;
cmf->yz = 0.0f;
cmf->wz = 0.0f;
cmf->xw = 0.0f;
cmf->yw = 0.0f;
cmf->zw = 0.0f;
cmf->zz = 1.0f;
cmf->ww = 1.0f;
cmf->xx = cos;
cmf->yy = cos;
cmf->yx = sin;
cmf->xy = -sin;
}
}
// Creates rotation matrix about a given vector axis in mtx (MTXMODE_NEW) or applies one to mtx (MTXMODE_APPLY).
// The vector specifying the axis does not need to be a unit vector.
void Matrix_RotateAxis(Matrix* mtx, f32 angle, f32 axisX, f32 axisY, f32 axisZ, u8 mode) {
f32 rx;
f32 ry;
f32 rz;
f32 norm;
f32 cxx;
f32 cyx;
f32 czx;
f32 cxy;
f32 cyy;
f32 czy;
f32 cxz;
f32 cyz;
f32 czz;
f32 xx;
f32 yy;
f32 zz;
f32 xy;
f32 yz;
f32 xz;
f32 sinA;
f32 cosA;
void Matrix_RotateAxis(Matrix* mtx, f32 angle, f32 x, f32 y, f32 z, u8 mode) {
MtxF* cmf;
f32 sin;
f32 cos;
f32 versin;
f32 temp1;
f32 temp2;
f32 temp3;
f32 temp4;
norm = sqrtf((axisX * axisX) + (axisY * axisY) + (axisZ * axisZ));
if (norm != 0.0) {
axisX /= norm;
axisY /= norm;
axisZ /= norm;
sinA = __sinf(angle);
cosA = __cosf(angle);
xx = axisX * axisX;
yy = axisY * axisY;
zz = axisZ * axisZ;
xy = axisX * axisY;
yz = axisY * axisZ;
xz = axisX * axisZ;
if (mode == 1) {
if (angle != 0) {
cmf = mtx->m;
if (mode == 1) {
cxx = (1.0f - xx) * cosA + xx;
cyx = (1.0f - cosA) * xy + axisZ * sinA;
czx = (1.0f - cosA) * xz - axisY * sinA;
sin = sinf(angle);
cos = cosf(angle);
cxy = (1.0f - cosA) * xy - axisZ * sinA;
cyy = (1.0f - yy) * cosA + yy;
czy = (1.0f - cosA) * yz + axisX * sinA;
temp1 = cmf->xx;
temp2 = cmf->xy;
temp3 = cmf->xz;
temp4 = (x * temp1 + y * temp2 + z * temp3) * (1.0f - cos);
cmf->xx = temp1 * cos + x * temp4 + sin * (temp2 * z - temp3 * y);
cmf->xy = temp2 * cos + y * temp4 + sin * (temp3 * x - temp1 * z);
cmf->xz = temp3 * cos + z * temp4 + sin * (temp1 * y - temp2 * x);
cxz = (1.0f - cosA) * xz + axisY * sinA;
cyz = (1.0f - cosA) * yz - axisX * sinA;
czz = (1.0f - zz) * cosA + zz;
temp1 = cmf->yx;
temp2 = cmf->yy;
temp3 = cmf->yz;
temp4 = (x * temp1 + y * temp2 + z * temp3) * (1.0f - cos);
cmf->yx = temp1 * cos + x * temp4 + sin * (temp2 * z - temp3 * y);
cmf->yy = temp2 * cos + y * temp4 + sin * (temp3 * x - temp1 * z);
cmf->yz = temp3 * cos + z * temp4 + sin * (temp1 * y - temp2 * x);
// loop doesn't seem to work here.
rx = mtx->m[0][0];
ry = mtx->m[0][1];
rz = mtx->m[0][2];
mtx->m[0][0] = (rx * cxx) + (ry * cxy) + (rz * cxz);
mtx->m[0][1] = (rx * cyx) + (ry * cyy) + (rz * cyz);
mtx->m[0][2] = (rx * czx) + (ry * czy) + (rz * czz);
temp1 = cmf->zx;
temp2 = cmf->zy;
temp3 = cmf->zz;
temp4 = (x * temp1 + y * temp2 + z * temp3) * (1.0f - cos);
cmf->zx = temp1 * cos + x * temp4 + sin * (temp2 * z - temp3 * y);
cmf->zy = temp2 * cos + y * temp4 + sin * (temp3 * x - temp1 * z);
cmf->zz = temp3 * cos + z * temp4 + sin * (temp1 * y - temp2 * x);
}
} else {
cmf = mtx->m;
rx = mtx->m[1][0];
ry = mtx->m[1][1];
rz = mtx->m[1][2];
mtx->m[1][0] = (rx * cxx) + (ry * cxy) + (rz * cxz);
mtx->m[1][1] = (rx * cyx) + (ry * cyy) + (rz * cyz);
mtx->m[1][2] = (rx * czx) + (ry * czy) + (rz * czz);
if (angle != 0) {
sin = sinf(angle);
cos = cosf(angle);
versin = 1.0f - cos;
rx = mtx->m[2][0];
ry = mtx->m[2][1];
rz = mtx->m[2][2];
mtx->m[2][0] = (rx * cxx) + (ry * cxy) + (rz * cxz);
mtx->m[2][1] = (rx * cyx) + (ry * cyy) + (rz * cyz);
mtx->m[2][2] = (rx * czx) + (ry * czy) + (rz * czz);
cmf->xx = x * x * versin + cos;
cmf->yy = y * y * versin + cos;
cmf->zz = z * z * versin + cos;
if (0) {}
temp2 = x * versin * y;
temp3 = z * sin;
cmf->yx = temp2 + temp3;
cmf->xy = temp2 - temp3;
temp2 = x * versin * z;
temp3 = y * sin;
cmf->zx = temp2 - temp3;
cmf->xz = temp2 + temp3;
temp2 = y * versin * z;
temp3 = x * sin;
cmf->zy = temp2 + temp3;
cmf->yz = temp2 - temp3;
cmf->wx = cmf->wy = cmf->wz = cmf->xw = cmf->yw = cmf->zw = 0.0f;
cmf->ww = 1.0f;
} else {
mtx->m[0][0] = (1.0f - xx) * cosA + xx;
mtx->m[0][1] = (1.0f - cosA) * xy + axisZ * sinA;
mtx->m[0][2] = (1.0f - cosA) * xz - axisY * sinA;
mtx->m[0][3] = 0.0f;
mtx->m[1][0] = (1.0f - cosA) * xy - axisZ * sinA;
mtx->m[1][1] = (1.0f - yy) * cosA + yy;
mtx->m[1][2] = (1.0f - cosA) * yz + axisX * sinA;
mtx->m[1][3] = 0.0f;
mtx->m[2][0] = (1.0f - cosA) * xz + axisY * sinA;
mtx->m[2][1] = (1.0f - cosA) * yz - axisX * sinA;
mtx->m[2][2] = (1.0f - zz) * cosA + zz;
mtx->m[2][3] = 0.0f;
mtx->m[3][0] = mtx->m[3][1] = mtx->m[3][2] = 0.0f;
mtx->m[3][3] = 1.0f;
cmf->xx = 1.0f;
cmf->yx = 0.0f;
cmf->zx = 0.0f;
cmf->wx = 0.0f;
cmf->xy = 0.0f;
cmf->yy = 1.0f;
cmf->zy = 0.0f;
cmf->wy = 0.0f;
cmf->xz = 0.0f;
cmf->yz = 0.0f;
cmf->zz = 1.0f;
cmf->wz = 0.0f;
cmf->xw = 0.0f;
cmf->yw = 0.0f;
cmf->zw = 0.0f;
cmf->ww = 1.0f;
}
}
}
// Converts the current Gfx matrix to a Mtx
void Matrix_ToMtx(Mtx* dest) {
s32 intVal;
u16(*iPart)[4] = dest->intPart;
u16(*fPart)[4] = dest->fracPart;
Matrix* src = gGfxMatrix;
intVal = src->m[0][0] * 0x10000;
iPart[0][0] = intVal >> 0x10;
fPart[0][0] = intVal % 0x10000U;
intVal = src->m[0][1] * 0x10000;
iPart[0][1] = intVal >> 0x10;
fPart[0][1] = intVal % 0x10000U;
intVal = src->m[0][2] * 0x10000;
iPart[0][2] = intVal >> 0x10;
fPart[0][2] = intVal % 0x10000U;
intVal = src->m[0][3] * 0x10000;
iPart[0][3] = intVal >> 0x10;
fPart[0][3] = intVal % 0x10000U;
intVal = src->m[1][0] * 0x10000;
iPart[1][0] = intVal >> 0x10;
fPart[1][0] = intVal % 0x10000U;
intVal = src->m[1][1] * 0x10000;
iPart[1][1] = intVal >> 0x10;
fPart[1][1] = intVal % 0x10000U;
intVal = src->m[1][2] * 0x10000;
iPart[1][2] = intVal >> 0x10;
fPart[1][2] = intVal % 0x10000U;
intVal = src->m[1][3] * 0x10000;
iPart[1][3] = intVal >> 0x10;
fPart[1][3] = intVal % 0x10000U;
intVal = src->m[2][0] * 0x10000;
iPart[2][0] = intVal >> 0x10;
fPart[2][0] = intVal % 0x10000U;
intVal = src->m[2][1] * 0x10000;
iPart[2][1] = intVal >> 0x10;
fPart[2][1] = intVal % 0x10000U;
intVal = src->m[2][2] * 0x10000;
iPart[2][2] = intVal >> 0x10;
fPart[2][2] = intVal % 0x10000U;
intVal = src->m[2][3] * 0x10000;
iPart[2][3] = intVal >> 0x10;
fPart[2][3] = intVal % 0x10000U;
intVal = src->m[3][0] * 0x10000;
iPart[3][0] = intVal >> 0x10;
fPart[3][0] = intVal % 0x10000U;
intVal = src->m[3][1] * 0x10000;
iPart[3][1] = intVal >> 0x10;
fPart[3][1] = intVal % 0x10000U;
intVal = src->m[3][2] * 0x10000;
iPart[3][2] = intVal >> 0x10;
fPart[3][2] = intVal % 0x10000U;
intVal = src->m[3][3] * 0x10000;
iPart[3][3] = intVal >> 0x10;
fPart[3][3] = intVal % 0x10000U;
// LTODO: We need to validate this
guMtxF2L(gGfxMatrix->m, dest);
}
// Converts the Mtx src to a Matrix, putting the result in dest
void Matrix_FromMtx(Mtx* src, Matrix* dest) {
dest->m[0][0] = ((src->intPart[0][0] << 0x10) | src->fracPart[0][0]) * (1.0f / 0x10000);
dest->m[0][1] = ((src->intPart[0][1] << 0x10) | src->fracPart[0][1]) * (1.0f / 0x10000);
dest->m[0][2] = ((src->intPart[0][2] << 0x10) | src->fracPart[0][2]) * (1.0f / 0x10000);
dest->m[0][3] = ((src->intPart[0][3] << 0x10) | src->fracPart[0][3]) * (1.0f / 0x10000);
dest->m[1][0] = ((src->intPart[1][0] << 0x10) | src->fracPart[1][0]) * (1.0f / 0x10000);
dest->m[1][1] = ((src->intPart[1][1] << 0x10) | src->fracPart[1][1]) * (1.0f / 0x10000);
dest->m[1][2] = ((src->intPart[1][2] << 0x10) | src->fracPart[1][2]) * (1.0f / 0x10000);
dest->m[1][3] = ((src->intPart[1][3] << 0x10) | src->fracPart[1][3]) * (1.0f / 0x10000);
dest->m[2][0] = ((src->intPart[2][0] << 0x10) | src->fracPart[2][0]) * (1.0f / 0x10000);
dest->m[2][1] = ((src->intPart[2][1] << 0x10) | src->fracPart[2][1]) * (1.0f / 0x10000);
dest->m[2][2] = ((src->intPart[2][2] << 0x10) | src->fracPart[2][2]) * (1.0f / 0x10000);
dest->m[2][3] = ((src->intPart[2][3] << 0x10) | src->fracPart[2][3]) * (1.0f / 0x10000);
dest->m[3][0] = ((src->intPart[3][0] << 0x10) | src->fracPart[3][0]) * (1.0f / 0x10000);
dest->m[3][1] = ((src->intPart[3][1] << 0x10) | src->fracPart[3][1]) * (1.0f / 0x10000);
dest->m[3][2] = ((src->intPart[3][2] << 0x10) | src->fracPart[3][2]) * (1.0f / 0x10000);
dest->m[3][3] = ((src->intPart[3][3] << 0x10) | src->fracPart[3][3]) * (1.0f / 0x10000);
guMtxF2L(src->m, dest->m);
}
// Applies the transform matrix mtx to the vector src, putting the result in dest
+1 -1
View File
@@ -19,7 +19,7 @@ s32 Save_WriteBlock(s32 arg0, u8* arg1) {
(void) "EEPROM インターフェース回路反応なし (WRITE)\n";
return -1;
}
Timer_Wait(MSEC_TO_CYCLES(15));
// Timer_Wait(MSEC_TO_CYCLES(15));
(void) "EEPROM WRITE %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n";
return 0;
}
+2 -8
View File
@@ -13,7 +13,7 @@ TimerTask* Timer_AllocateTask(void) {
return NULL;
}
s32 Timer_CreateTask(u64 time, TimerAction action, s32* address, s32 value) {
int32_t Timer_CreateTask(uint64_t time, TimerAction action, s32* address, s32 value) {
TimerTask* task = Timer_AllocateTask();
if (task == NULL) {
@@ -41,10 +41,4 @@ void Timer_CompleteTask(TimerTask* task) {
task->active = false;
}
void Timer_Wait(u64 time) {
OSTimer timer;
OSMesg dummy;
osSetTimer(&timer, time, 0, &gTimerWaitMsgQueue, OS_MESG_PTR(NULL));
osRecvMesg(&gTimerWaitMsgQueue, &dummy, OS_MESG_BLOCK);
}
void