Match and link GBARead/Write

Former-commit-id: 55fac9eb37
This commit is contained in:
Phillip Stephens 2022-10-15 19:14:54 -07:00
parent 2d138c60bd
commit cb7e35b615
9 changed files with 181 additions and 17 deletions

View File

@ -17,7 +17,8 @@
"types.h": "c", "types.h": "c",
"gba.h": "c", "gba.h": "c",
"gbapriv.h": "c", "gbapriv.h": "c",
"os.h": "c" "os.h": "c",
"sipriv.h": "c"
}, },
"files.autoSave": "onFocusChange", "files.autoSave": "onFocusChange",
"files.insertFinalNewline": true, "files.insertFinalNewline": true,

View File

@ -1007,14 +1007,14 @@ LIBS = [
}, },
{ {
"lib": "gba", "lib": "gba",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"objects": [ "objects": [
["Dolphin/GBA/GBA", True], ["Dolphin/GBA/GBA", True],
"Dolphin/GBA/GBAGetProcessStatus", "Dolphin/GBA/GBAGetProcessStatus",
"Dolphin/GBA/GBAJoyBoot", "Dolphin/GBA/GBAJoyBoot",
"Dolphin/GBA/GBARead", ["Dolphin/GBA/GBARead", True],
"Dolphin/GBA/GBAWrite", ["Dolphin/GBA/GBAWrite", True],
"Dolphin/GBA/GBAXfer", "Dolphin/GBA/GBAXfer",
"Dolphin/GBA/GBAKey", "Dolphin/GBA/GBAKey",
], ],

View File

@ -16,11 +16,8 @@ typedef struct GBASecParams {
typedef struct GBA { typedef struct GBA {
u8 command; u8 command;
u8 src[4]; u8 src[4];
u8 _05; u8 dst[4];
u8 _06; u8 _09;
s8 _07;
s8 _08;
s8 _09;
s8 _0a; s8 _0a;
s8 _0b; s8 _0b;
s32 _0c; s32 _0c;
@ -30,8 +27,9 @@ typedef struct GBA {
GBACallback callback; GBACallback callback;
s32 result; s32 result;
OSThreadQueue thread_queue; OSThreadQueue thread_queue;
OSTime poll_time; OSTime delay;
char data1[0x40u - 0x38u]; GBACallback _38;
s32 _3c;
s32 palette_color; s32 palette_color;
s32 palette_speed; s32 palette_speed;
u8* program; u8* program;
@ -49,8 +47,10 @@ typedef struct GBA {
extern GBA __GBA[4]; extern GBA __GBA[4];
extern BOOL __GBAReset; extern BOOL __GBAReset;
//void __GBAHandler(s32 chan, s32 ret);
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);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -850,10 +850,10 @@ THP_FILES :=\
$(BUILD_DIR)/asm/Dolphin/thp/THPAudio.o $(BUILD_DIR)/asm/Dolphin/thp/THPAudio.o
GBA_FILES :=\ GBA_FILES :=\
$(BUILD_DIR)/src/Dolphin/GBA/GBA.o\ $(BUILD_DIR)/src/Dolphin/GBA/GBA.ep.o\
$(BUILD_DIR)/asm/Dolphin/GBA/GBAGetProcessStatus.o\ $(BUILD_DIR)/asm/Dolphin/GBA/GBAGetProcessStatus.o\
$(BUILD_DIR)/asm/Dolphin/GBA/GBAJoyBoot.o\ $(BUILD_DIR)/asm/Dolphin/GBA/GBAJoyBoot.o\
$(BUILD_DIR)/asm/Dolphin/GBA/GBARead.o\ $(BUILD_DIR)/src/Dolphin/GBA/GBARead.ep.o\
$(BUILD_DIR)/asm/Dolphin/GBA/GBAWrite.o\ $(BUILD_DIR)/src/Dolphin/GBA/GBAWrite.ep.o\
$(BUILD_DIR)/asm/Dolphin/GBA/GBAXfer.o\ $(BUILD_DIR)/asm/Dolphin/GBA/GBAXfer.o\
$(BUILD_DIR)/asm/Dolphin/GBA/GBAKey.o\ $(BUILD_DIR)/asm/Dolphin/GBA/GBAKey.o\

View File

@ -19,12 +19,12 @@ void ShortCommandProc(s32 chan, s32 ret) {
return; return;
} }
if (gba->_05 != 0 || gba->_06 != 4) { if (gba->dst[0] != 0 || gba->dst[1] != 4) {
gba->result = 1; gba->result = 1;
return; return;
} }
gba->status[0] = gba->_07 & 0x3a; gba->status[0] = gba->dst[2] & 0x3a;
} }
void GBAInit() { void GBAInit() {
@ -32,7 +32,7 @@ void GBAInit() {
GBA* gba; GBA* gba;
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
gba = &__GBA[i]; gba = &__GBA[i];
gba->poll_time = OSMicrosecondsToTicks(60); gba->delay = OSMicrosecondsToTicks(60);
OSInitThreadQueue(&gba->thread_queue); OSInitThreadQueue(&gba->thread_queue);
gba->param = &SecParams[i]; gba->param = &SecParams[i];

View File

@ -0,0 +1,25 @@
#include "dolphin/GBAPriv.h"
s32 GBAGetProcessStatus(s32 chan, u8* percentp) {
GBA* gba;
s32 ret;
BOOL enabled;
gba = &__GBA[chan];
enabled = OSDisableInterrupts();
if (gba->jboot_callback == NULL) {
if (gba->callback == NULL) {
ret = 0;
} else {
ret = 2;
}
} else {
ret = 2;
}
OSRestoreInterrupts(enabled);
return ret;
}

42
src/Dolphin/GBA/GBARead.c Normal file
View File

@ -0,0 +1,42 @@
#include "dolphin/GBAPriv.h"
void ReadProc(s32 chan, s32 ret) {
GBA* gba;
gba = &__GBA[chan];
if (gba->result == 0) {
memcpy(gba->buffer, &gba->dst, 4);
gba->status[0] = gba->_09 & 0x3a;
}
}
s32 GBAReadAsync(s32 chan, u8* dst, u8* status, GBACallback callback) {
GBA* gba;
s32 ret;
gba = &__GBA[chan];
if (gba->callback != NULL) {
ret = 2;
} else {
gba->command = 0x14;
gba->buffer = dst;
gba->status = status;
gba->callback = callback;
ret = __GBATransfer(chan, 1, 5, ReadProc);
}
return ret;
}
s32 GBARead(s32 chan, u8* dst, u8* status) {
s32 tmp;
s32 ret;
ret = GBAReadAsync(chan, dst, status, __GBASyncCallback);
if (ret != 0) {
return ret;
}
return __GBASync(chan);
}

View File

@ -0,0 +1,42 @@
#include "dolphin/GBAPriv.h"
void WriteProc(s32 chan, s32 ret) {
GBA* gba;
gba = &__GBA[chan];
if (gba->result != 0) {
return;
}
gba->status[0] = gba->dst[0] & 0x3a;
}
s32 GBAWriteAsync(s32 chan, u8* src, u8* status, GBACallback callback) {
GBA* gba;
s32 ret;
gba = &__GBA[chan];
if (gba->callback != NULL) {
ret = 2;
} else {
gba->command = 0x15;
memcpy(gba->src, src, 4);
gba->buffer = src;
gba->status = status;
gba->callback = callback;
ret = __GBATransfer(chan, 5, 1, WriteProc);
}
return ret;
}
s32 GBAWrite(s32 chan, u8* src, u8* status) {
s32 ret;
s32 tmp;
ret = GBAWriteAsync(chan, src, status, __GBASyncCallback);
if (ret != 0) {
return ret;
}
return __GBASync(chan);
}

54
src/Dolphin/GBA/GBAXfer.c Normal file
View File

@ -0,0 +1,54 @@
#include "dolphin/GBAPriv.h"
#include "dolphin/sipriv.h"
void __GBAHandler() {
}
void __GBASyncCallback(s32 chan, s32 ret) {
OSWakeupThread(&__GBA[chan].thread_queue);
}
s32 __GBASync(s32 chan) {
GBA* gba;
s32 enabled;
s32 ret;
gba = &__GBA[chan];
enabled = OSDisableInterrupts();
while (gba->callback != NULL) {
OSSleepThread(&gba->thread_queue);
}
ret = gba->result;
OSRestoreInterrupts(enabled);
return ret;
}
void TypeAndStatusCallback(s32 chan, u32 type) {
}
s32 __GBATransfer(s32 chan, s32 w1, s32 w2, GBACallback callback) {
s32 enabled;
GBA* gba;
gba = &__GBA[chan];
enabled = OSDisableInterrupts();
gba->_38 = callback;
gba->_0c = w1;
gba->_10 = w2;
SIGetTypeAsync(chan, TypeAndStatusCallback);
OSRestoreInterrupts(enabled);
return 0;
}
OSTime __GBASetDelay(s32 chan, OSTime delay) {
OSTime oldDelay;
GBA* gba;
gba = &__GBA[chan];
oldDelay = gba->delay;
gba->delay = delay;
return oldDelay;
}