Match but don't link GBAXfer

This commit is contained in:
Phillip Stephens 2022-10-15 22:53:55 -07:00
parent 55fac9eb37
commit 68e2da3ccb
6 changed files with 83 additions and 13 deletions

View File

@ -9,6 +9,9 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef void (*GBATransferCallback)(s32 chan);
typedef struct GBASecParams { typedef struct GBASecParams {
u8 data[0x40]; u8 data[0x40];
} GBASecParams; } GBASecParams;
@ -28,7 +31,7 @@ typedef struct GBA {
s32 result; s32 result;
OSThreadQueue thread_queue; OSThreadQueue thread_queue;
OSTime delay; OSTime delay;
GBACallback _38; GBATransferCallback _38;
s32 _3c; s32 _3c;
s32 palette_color; s32 palette_color;
s32 palette_speed; s32 palette_speed;
@ -43,7 +46,6 @@ typedef struct GBA {
char data4[0x100u - 0xfcu]; char data4[0x100u - 0xfcu];
} GBA; } GBA;
extern GBA __GBA[4]; extern GBA __GBA[4];
extern BOOL __GBAReset; extern BOOL __GBAReset;
@ -51,6 +53,7 @@ extern BOOL __GBAReset;
void __GBASyncCallback(s32 chan, s32 ret); void __GBASyncCallback(s32 chan, s32 ret);
s32 __GBASync(s32 chan); s32 __GBASync(s32 chan);
OSTime __GBASetDelay(s32 chan, OSTime delay); OSTime __GBASetDelay(s32 chan, OSTime delay);
s32 __GBATransfer(s32 chan, s32 w1, s32 w2, GBATransferCallback callback);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -33,6 +33,7 @@ typedef struct OSContext {
void OSSaveContext(OSContext* context); void OSSaveContext(OSContext* context);
void OSClearContext(OSContext* context); void OSClearContext(OSContext* context);
OSContext* OSGetCurrentContext();
void OSSetCurrentContext(OSContext* context); void OSSetCurrentContext(OSContext* context);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -11,7 +11,7 @@ static OSResetFunctionInfo ResetFunctionInfo = {
127 127
}; };
void ShortCommandProc(s32 chan, s32 ret) { void ShortCommandProc(s32 chan) {
GBA* gba; GBA* gba;
gba = &__GBA[chan]; gba = &__GBA[chan];

View File

@ -1,6 +1,6 @@
#include "dolphin/GBAPriv.h" #include "dolphin/GBAPriv.h"
void ReadProc(s32 chan, s32 ret) { void ReadProc(s32 chan) {
GBA* gba; GBA* gba;
gba = &__GBA[chan]; gba = &__GBA[chan];

View File

@ -1,6 +1,6 @@
#include "dolphin/GBAPriv.h" #include "dolphin/GBAPriv.h"
void WriteProc(s32 chan, s32 ret) { void WriteProc(s32 chan) {
GBA* gba; GBA* gba;
gba = &__GBA[chan]; gba = &__GBA[chan];

View File

@ -1,14 +1,44 @@
#include "dolphin/GBAPriv.h" #include "dolphin/GBAPriv.h"
#include "dolphin/sipriv.h" #include "dolphin/sipriv.h"
void __GBAHandler() { void __GBAHandler(s32 chan, u32 sr, OSContext* context) {
int tmp;
GBA* gba;
OSContext tmpCtx;
GBACallback callback;
GBATransferCallback xferCallback;
gba = &__GBA[chan];
if (__GBAReset != 0) {
return;
} }
void __GBASyncCallback(s32 chan, s32 ret) { if ((sr & 0xf)) {
OSWakeupThread(&__GBA[chan].thread_queue); gba->result = 1;
} else {
gba->result = 0;
} }
if (gba->_38 != NULL) {
xferCallback = gba->_38;
gba->_38 = NULL;
xferCallback(chan);
}
if (gba->callback == NULL) {
return;
}
OSClearContext(&tmpCtx);
OSSetCurrentContext(&tmpCtx);
callback = gba->callback;
gba->callback = NULL;
callback(chan, gba->result);
OSClearContext(&tmpCtx);
OSSetCurrentContext(context);
}
void __GBASyncCallback(s32 chan, s32 ret) { OSWakeupThread(&__GBA[chan].thread_queue); }
s32 __GBASync(s32 chan) { s32 __GBASync(s32 chan) {
GBA* gba; GBA* gba;
s32 enabled; s32 enabled;
@ -27,10 +57,46 @@ s32 __GBASync(s32 chan) {
} }
void TypeAndStatusCallback(s32 chan, u32 type) { void TypeAndStatusCallback(s32 chan, u32 type) {
s32 tmp;
GBA* gba;
OSContext* context;
GBACallback callback;
GBATransferCallback xferCallback;
OSContext tmpContext;
gba = &__GBA[chan];
if (__GBAReset != 0) {
return;
} }
s32 __GBATransfer(s32 chan, s32 w1, s32 w2, GBACallback callback) { if ((type & 0xFF) != 0 || (type & 0xffff0000) != 0x40000) {
gba->result = 1;
} else {
if (SITransfer(chan, &gba->command, gba->_0c, gba->dst, gba->_10, __GBAHandler, gba->delay)) {
return;
}
gba->result = 2;
}
if (gba->_38 != NULL) {
xferCallback = gba->_38;
gba->_38 = NULL;
xferCallback(chan);
}
if (gba->callback != NULL) {
context = OSGetCurrentContext();
OSClearContext(&tmpContext);
OSSetCurrentContext(&tmpContext);
callback = gba->callback;
gba->callback = NULL;
callback(chan, gba->result);
OSClearContext(&tmpContext);
OSSetCurrentContext(context);
__OSReschedule();
}
}
s32 __GBATransfer(s32 chan, s32 w1, s32 w2, GBATransferCallback callback) {
s32 enabled; s32 enabled;
GBA* gba; GBA* gba;
gba = &__GBA[chan]; gba = &__GBA[chan];