diff --git a/asm/Dolphin/GBA/GBA.s b/asm/Dolphin/GBA/GBA.s index 5cef974d..9108f109 100644 --- a/asm/Dolphin/GBA/GBA.s +++ b/asm/Dolphin/GBA/GBA.s @@ -244,8 +244,9 @@ lbl_803C98C4: /* 803C98D0 003C6830 7C 08 03 A6 */ mtlr r0 /* 803C98D4 003C6834 4E 80 00 20 */ blr -OnReset: +.fn OnReset, local /* 803C98D8 003C6838 38 00 00 01 */ li r0, 1 /* 803C98DC 003C683C 90 0D B1 58 */ stw r0, __GBAReset@sda21(r13) /* 803C98E0 003C6840 38 60 00 01 */ li r3, 1 /* 803C98E4 003C6844 4E 80 00 20 */ blr +.endfn OnReset diff --git a/asm/Dolphin/GBA/GBAKey.s b/asm/Dolphin/GBA/GBAKey.s index 5c26c8d3..59d89e0b 100644 --- a/asm/Dolphin/GBA/GBAKey.s +++ b/asm/Dolphin/GBA/GBAKey.s @@ -70,8 +70,7 @@ lbl_803F752C: .section .text, "ax" -.global __F23 -__F23: +.fn F23, local /* 803CAF40 003C7EA0 7C 08 02 A6 */ mflr r0 /* 803CAF44 003C7EA4 3C 80 80 57 */ lis r4, __GBA@ha /* 803CAF48 003C7EA8 90 01 00 04 */ stw r0, 4(r1) @@ -134,9 +133,9 @@ lbl_803CAFFC: /* 803CB010 003C7F70 38 21 00 20 */ addi r1, r1, 0x20 /* 803CB014 003C7F74 7C 08 03 A6 */ mtlr r0 /* 803CB018 003C7F78 4E 80 00 20 */ blr +.endfn F23 -.global __F25 -__F25: +.fn F25, local /* 803CB01C 003C7F7C 3C 80 80 57 */ lis r4, __GBA@ha /* 803CB020 003C7F80 7C 08 02 A6 */ mflr r0 /* 803CB024 003C7F84 38 84 A1 A0 */ addi r4, r4, __GBA@l @@ -184,9 +183,9 @@ lbl_803CB0A8: /* 803CB0B8 003C8018 38 21 00 08 */ addi r1, r1, 8 /* 803CB0BC 003C801C 7C 08 03 A6 */ mtlr r0 /* 803CB0C0 003C8020 4E 80 00 20 */ blr +.endfn F25 -.global __GBAX02 -__GBAX02: +.fn __GBAX02 /* 803CB0C4 003C8024 7C 08 02 A6 */ mflr r0 /* 803CB0C8 003C8028 3C A0 80 57 */ lis r5, __GBA@ha /* 803CB0CC 003C802C 90 01 00 04 */ stw r0, 4(r1) @@ -222,15 +221,15 @@ __GBAX02: /* 803CB144 003C80A4 3C 04 80 00 */ addis r0, r4, 0x8000 /* 803CB148 003C80A8 90 1F 00 B4 */ stw r0, 0xb4(r31) /* 803CB14C 003C80AC 38 00 03 80 */ li r0, 0x380 -/* 803CB150 003C80B0 3C A0 80 3D */ lis r5, __F23@ha +/* 803CB150 003C80B0 3C A0 80 3D */ lis r5, F23@ha /* 803CB154 003C80B4 90 1F 00 B8 */ stw r0, 0xb8(r31) /* 803CB158 003C80B8 38 C0 00 00 */ li r6, 0 /* 803CB15C 003C80BC 38 00 00 10 */ li r0, 0x10 /* 803CB160 003C80C0 90 DF 00 BC */ stw r6, 0xbc(r31) -/* 803CB164 003C80C4 38 A5 AF 40 */ addi r5, r5, __F23@l -/* 803CB168 003C80C8 3C 80 80 3D */ lis r4, __F25@ha +/* 803CB164 003C80C4 38 A5 AF 40 */ addi r5, r5, F23@l +/* 803CB168 003C80C8 3C 80 80 3D */ lis r4, F25@ha /* 803CB16C 003C80CC B0 1F 00 CC */ sth r0, 0xcc(r31) -/* 803CB170 003C80D0 38 04 B0 1C */ addi r0, r4, __F25@l +/* 803CB170 003C80D0 38 04 B0 1C */ addi r0, r4, F25@l /* 803CB174 003C80D4 38 7F 00 A8 */ addi r3, r31, 0xa8 /* 803CB178 003C80D8 90 BF 00 D0 */ stw r5, 0xd0(r31) /* 803CB17C 003C80DC 90 DF 00 D4 */ stw r6, 0xd4(r31) @@ -244,3 +243,4 @@ __GBAX02: /* 803CB19C 003C80FC 38 21 00 20 */ addi r1, r1, 0x20 /* 803CB1A0 003C8100 7C 08 03 A6 */ mtlr r0 /* 803CB1A4 003C8104 4E 80 00 20 */ blr +.endfn __GBAX02 diff --git a/include/dolphin/GBAPriv.h b/include/dolphin/GBAPriv.h index 43d23e16..db963c0e 100644 --- a/include/dolphin/GBAPriv.h +++ b/include/dolphin/GBAPriv.h @@ -5,6 +5,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -13,43 +14,60 @@ extern "C" { typedef void (*GBATransferCallback)(s32 chan); typedef struct GBASecParams { - u8 data[0x40]; + u8 readbuf[4]; + s32 paletteColor; + s32 paletteSpeed; + s32 length; + u32* out; + u8 _padding0[12]; + u32 keyA; + s32 keyB; + u8 _padding1[24]; } GBASecParams; -typedef struct GBA { - u8 command; - u8 src[4]; - u8 dst[4]; - u8 _09; - s8 _0a; - s8 _0b; - s32 _0c; - s32 _10; +typedef struct GBABootInfo { + s32 paletteColor; + s32 paletteSpeed; + u8* programp; + s32 length; u8* status; - u8* buffer; GBACallback callback; - s32 result; - OSThreadQueue thread_queue; - OSTime delay; - GBATransferCallback _38; - s32 _3c; - s32 palette_color; - s32 palette_speed; - u8* program; - s32 program_length; - s32 jboot_status; - GBACallback jboot_callback; - char data2[0x74u - 0x58u]; - u8* challenge_cipher; - char data3[0xf8 - 0x78u]; - GBASecParams* param; - char data4[0x100u - 0xfcu]; -} GBA; + u8 readbuf[4]; + u8 writebuf[4]; + int i; + OSTick start; + OSTime begin; + int firstXfer; + int curOffset; + u32 crc; + u32 dummyWord[7]; + u32 keyA; + u32 keyB; + u32 initialCode; + int realLength; +} GBABootInfo; -extern GBA __GBA[4]; +typedef struct GBAControl { + u8 output[5]; + u8 input[5]; + s32 outputBytes; + s32 inputBytes; + u8* status; + u8* ptr; + GBACallback callback; + s32 ret; + OSThreadQueue threadQueue; + OSTime delay; + GBATransferCallback proc; + GBABootInfo bootInfo; + DSPTaskInfo task; + GBASecParams* param; +} GBAControl; + +extern GBAControl __GBA[4]; extern BOOL __GBAReset; -void __GBAHandler(s32 chan, u32 sr, OSContext* context); +void __GBAHandler(s32 chan, u32 error, OSContext* context); void __GBASyncCallback(s32 chan, s32 ret); s32 __GBASync(s32 chan); OSTime __GBASetDelay(s32 chan, OSTime delay); diff --git a/include/dolphin/dsp.h b/include/dolphin/dsp.h index f74ac9eb..368138c9 100644 --- a/include/dolphin/dsp.h +++ b/include/dolphin/dsp.h @@ -19,9 +19,7 @@ extern "C" { typedef void (*DSPCallback)(void* task); -typedef struct DSPTaskInfo DSPTaskInfo; - -typedef struct DSPTaskInfo { +typedef struct STRUCT_DSP_TASK { vu32 state; vu32 priority; vu32 flags; @@ -41,8 +39,8 @@ typedef struct DSPTaskInfo { DSPCallback done_cb; DSPCallback req_cb; - struct DSPTaskInfo* next; - struct DSPTaskInfo* prev; + struct STRUCT_DSP_TASK* next; + struct STRUCT_DSP_TASK* prev; OSTime t_context; OSTime t_task; diff --git a/src/Dolphin/GBA/GBA.c b/src/Dolphin/GBA/GBA.c index bb89f2e0..d0016b95 100644 --- a/src/Dolphin/GBA/GBA.c +++ b/src/Dolphin/GBA/GBA.c @@ -1,7 +1,7 @@ #include "dolphin/GBAPriv.h" static GBASecParams SecParams[4]; -GBA __GBA[4]; +GBAControl __GBA[4]; BOOL __GBAReset = FALSE; static BOOL OnReset(BOOL); @@ -12,29 +12,30 @@ static OSResetFunctionInfo ResetFunctionInfo = { }; void ShortCommandProc(s32 chan) { - GBA* gba; + GBAControl* gba; gba = &__GBA[chan]; - if (gba->result != 0) { + if (gba->ret != 0) { return; } - if (gba->dst[0] != 0 || gba->dst[1] != 4) { - gba->result = 1; + if (gba->input[0] != 0 || gba->input[1] != 4) { + gba->ret = 1; return; } - gba->status[0] = gba->dst[2] & GBA_JSTAT_MASK; + gba->status[0] = gba->input[2] & GBA_JSTAT_MASK; } void GBAInit() { - s32 i; - GBA* gba; - for (i = 0; i < 4; ++i) { - gba = &__GBA[i]; + GBAControl* gba; + s32 chan; + + for (chan = 0; chan < 4; ++chan) { + gba = &__GBA[chan]; gba->delay = OSMicrosecondsToTicks(60); - OSInitThreadQueue(&gba->thread_queue); - gba->param = &SecParams[i]; + OSInitThreadQueue(&gba->threadQueue); + gba->param = &SecParams[chan]; // ASSERTMSG((u32) gba->param % 32 == 0) } @@ -47,42 +48,34 @@ void GBAInit() { } s32 GBAGetStatusAsync(s32 chan, u8* status, GBACallback callback) { - GBA* gba; - s32 ret; + GBAControl* gba; gba = &__GBA[chan]; if (gba->callback != NULL) { - ret = GBA_BUSY; - } else { - gba->command = 0; - gba->status = status; - gba->callback = callback; - ret = __GBATransfer(chan, 1, 3, ShortCommandProc); + return GBA_BUSY; } - return ret; + gba->output[0] = 0; + gba->status = status; + gba->callback = callback; + return __GBATransfer(chan, 1, 3, ShortCommandProc); } s32 GBAGetStatus(s32 chan, u8* status) { - s32 ret; - ret = GBAGetStatusAsync(chan, status, __GBASyncCallback); - - if (ret != GBA_READY) { - return ret; - } - - return __GBASync(chan); + GBAControl* gba = &__GBA[chan]; + s32 ret = GBAGetStatusAsync(chan, status, __GBASyncCallback); + return ret != GBA_READY ? ret : __GBASync(chan); } s32 GBAResetAsync(s32 chan, u8* status, GBACallback callback) { - GBA* gba; + GBAControl* gba; s32 ret; gba = &__GBA[chan]; if (gba->callback != NULL) { ret = GBA_BUSY; } else { - gba->command = 0xFF; + gba->output[0] = 0xFF; gba->status = status; gba->callback = callback; ret = __GBATransfer(chan, 1, 3, ShortCommandProc); diff --git a/src/Dolphin/GBA/GBAGetProcessStatus.c b/src/Dolphin/GBA/GBAGetProcessStatus.c index 38d8c388..df8ea7cf 100644 --- a/src/Dolphin/GBA/GBAGetProcessStatus.c +++ b/src/Dolphin/GBA/GBAGetProcessStatus.c @@ -1,22 +1,35 @@ #include "dolphin/GBAPriv.h" s32 GBAGetProcessStatus(s32 chan, u8* percentp) { - GBA* gba; - s32 ret; - BOOL enabled; + BOOL enabled; + s32 ret; // r29 + GBAControl * gba; // r25 + GBABootInfo * bootInfo; // r31 + u8 percent; // r30 + OSTime t; // r27 gba = &__GBA[chan]; + bootInfo = &gba->bootInfo; enabled = OSDisableInterrupts(); - if (gba->jboot_callback == NULL) { - if (gba->callback == NULL) { - ret = 0; - } else { - ret = 2; - } - } else { + if (bootInfo->callback != NULL) { ret = 2; - + percent = (bootInfo->curOffset * 100) / bootInfo->realLength; + if (bootInfo->begin != 0) { + t = OSGetTime(); + + if (t - bootInfo->begin < OSMillisecondsToTicks(5500)) { + percentp = 0; + } + } + + if (percentp != NULL) { + *percentp = percent; + } + } else if (gba->callback != NULL) { + ret = 2; + } else { + ret = 0; } OSRestoreInterrupts(enabled); diff --git a/src/Dolphin/GBA/GBARead.c b/src/Dolphin/GBA/GBARead.c index ab19bbb3..cb0431a7 100644 --- a/src/Dolphin/GBA/GBARead.c +++ b/src/Dolphin/GBA/GBARead.c @@ -1,17 +1,17 @@ #include "dolphin/GBAPriv.h" void ReadProc(s32 chan) { - GBA* gba; + GBAControl* gba; gba = &__GBA[chan]; - if (gba->result == 0) { - memcpy(gba->buffer, &gba->dst, 4); - gba->status[0] = gba->_09 & GBA_JSTAT_MASK; + if (gba->ret == 0) { + memcpy(gba->ptr, gba->input, 4); + gba->status[0] = gba->input[4] & GBA_JSTAT_MASK; } } s32 GBAReadAsync(s32 chan, u8* dst, u8* status, GBACallback callback) { - GBA* gba; + GBAControl* gba; s32 ret; gba = &__GBA[chan]; @@ -19,8 +19,8 @@ s32 GBAReadAsync(s32 chan, u8* dst, u8* status, GBACallback callback) { if (gba->callback != NULL) { ret = 2; } else { - gba->command = 0x14; - gba->buffer = dst; + gba->output[0] = 0x14; + gba->ptr = dst; gba->status = status; gba->callback = callback; ret = __GBATransfer(chan, 1, 5, ReadProc); diff --git a/src/Dolphin/GBA/GBAWrite.c b/src/Dolphin/GBA/GBAWrite.c index f040f922..a4bc9c75 100644 --- a/src/Dolphin/GBA/GBAWrite.c +++ b/src/Dolphin/GBA/GBAWrite.c @@ -1,27 +1,27 @@ #include "dolphin/GBAPriv.h" void WriteProc(s32 chan) { - GBA* gba; + GBAControl* gba; gba = &__GBA[chan]; - if (gba->result != 0) { + if (gba->ret != 0) { return; } - gba->status[0] = gba->dst[0] & GBA_JSTAT_MASK; + gba->status[0] = gba->input[0] & GBA_JSTAT_MASK; } s32 GBAWriteAsync(s32 chan, u8* src, u8* status, GBACallback callback) { - GBA* gba; + GBAControl* gba; s32 ret; gba = &__GBA[chan]; if (gba->callback != NULL) { ret = GBA_BUSY; } else { - gba->command = 0x15; - memcpy(gba->src, src, 4); - gba->buffer = src; + gba->output[0] = 0x15; + memcpy(&gba->output[1], src, 4); + gba->ptr = src; gba->status = status; gba->callback = callback; ret = __GBATransfer(chan, 5, 1, WriteProc); diff --git a/src/Dolphin/GBA/GBAXfer.c b/src/Dolphin/GBA/GBAXfer.c index ec62432e..d6e0b212 100644 --- a/src/Dolphin/GBA/GBAXfer.c +++ b/src/Dolphin/GBA/GBAXfer.c @@ -1,56 +1,56 @@ #include "dolphin/GBAPriv.h" #include "dolphin/sipriv.h" -void __GBAHandler(s32 chan, u32 sr, OSContext* context) { - int tmp; - GBA* gba; - OSContext tmpCtx; +void __GBAHandler(s32 chan, u32 error, OSContext* context) { + GBAControl* gba; + GBATransferCallback proc; GBACallback callback; - GBATransferCallback xferCallback; + OSContext exceptionContext; + gba = &__GBA[chan]; if (__GBAReset != 0) { return; } - if ((sr & 0xf)) { - gba->result = 1; + if ((error & 0xf)) { + gba->ret = 1; } else { - gba->result = 0; + gba->ret = 0; } - if (gba->_38 != NULL) { - xferCallback = gba->_38; - gba->_38 = NULL; - xferCallback(chan); + if (gba->proc != NULL) { + proc = gba->proc; + gba->proc = NULL; + proc(chan); } if (gba->callback == NULL) { return; } - OSClearContext(&tmpCtx); - OSSetCurrentContext(&tmpCtx); + OSClearContext(&exceptionContext); + OSSetCurrentContext(&exceptionContext); callback = gba->callback; gba->callback = NULL; - callback(chan, gba->result); - OSClearContext(&tmpCtx); + callback(chan, gba->ret); + OSClearContext(&exceptionContext); OSSetCurrentContext(context); } -void __GBASyncCallback(s32 chan, s32 ret) { OSWakeupThread(&__GBA[chan].thread_queue); } +void __GBASyncCallback(s32 chan, s32 ret) { OSWakeupThread(&__GBA[chan].threadQueue); } s32 __GBASync(s32 chan) { - GBA* gba; + GBAControl* gba; s32 enabled; s32 ret; gba = &__GBA[chan]; enabled = OSDisableInterrupts(); while (gba->callback != NULL) { - OSSleepThread(&gba->thread_queue); + OSSleepThread(&gba->threadQueue); } - ret = gba->result; + ret = gba->ret; OSRestoreInterrupts(enabled); return ret; @@ -58,7 +58,7 @@ s32 __GBASync(s32 chan) { void TypeAndStatusCallback(s32 chan, u32 type) { s32 tmp; - GBA* gba; + GBAControl* gba; OSContext* context; GBACallback callback; GBATransferCallback xferCallback; @@ -69,17 +69,17 @@ void TypeAndStatusCallback(s32 chan, u32 type) { } if ((type & 0xFF) != 0 || (type & 0xffff0000) != 0x40000) { - gba->result = GBA_NOT_READY; + gba->ret = GBA_NOT_READY; } else { - if (SITransfer(chan, &gba->command, gba->_0c, gba->dst, gba->_10, __GBAHandler, gba->delay)) { + if (SITransfer(chan, gba->output, gba->outputBytes, gba->input, gba->inputBytes, __GBAHandler, gba->delay)) { return; } - gba->result = GBA_BUSY; + gba->ret = GBA_BUSY; } - if (gba->_38 != NULL) { - xferCallback = gba->_38; - gba->_38 = NULL; + if (gba->proc != NULL) { + xferCallback = gba->proc; + gba->proc = NULL; xferCallback(chan); } @@ -89,7 +89,7 @@ void TypeAndStatusCallback(s32 chan, u32 type) { OSSetCurrentContext(&tmpContext); callback = gba->callback; gba->callback = NULL; - callback(chan, gba->result); + callback(chan, gba->ret); OSClearContext(&tmpContext); OSSetCurrentContext(context); __OSReschedule(); @@ -98,12 +98,12 @@ void TypeAndStatusCallback(s32 chan, u32 type) { s32 __GBATransfer(s32 chan, s32 w1, s32 w2, GBATransferCallback callback) { s32 enabled; - GBA* gba; + GBAControl* gba; gba = &__GBA[chan]; enabled = OSDisableInterrupts(); - gba->_38 = callback; - gba->_0c = w1; - gba->_10 = w2; + gba->proc = callback; + gba->outputBytes = w1; + gba->inputBytes = w2; SIGetTypeAsync(chan, TypeAndStatusCallback); OSRestoreInterrupts(enabled); @@ -112,7 +112,7 @@ s32 __GBATransfer(s32 chan, s32 w1, s32 w2, GBATransferCallback callback) { OSTime __GBASetDelay(s32 chan, OSTime delay) { OSTime oldDelay; - GBA* gba; + GBAControl* gba; gba = &__GBA[chan]; oldDelay = gba->delay; gba->delay = delay;