From af9f796433b991ff2d56223bb30a6863eee281f5 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 15 Oct 2022 14:47:17 -0700 Subject: [PATCH] Properly split GBA library Former-commit-id: f49d43abdc9b12dd7ed66eded45f794fd7473132 --- .vscode/settings.json | 3 ++- asm/Dolphin/GBA/GBAKey.s | 6 ++--- configure.py | 2 ++ include/dolphin/gba.h | 55 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bdd00831..b5aac4f3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,7 +14,8 @@ "stddef.h": "c", "errno.h": "c", "ansi_files.h": "c", - "types.h": "c" + "types.h": "c", + "gba.h": "c" }, "files.autoSave": "onFocusChange", "files.insertFinalNewline": true, diff --git a/asm/Dolphin/GBA/GBAKey.s b/asm/Dolphin/GBA/GBAKey.s index 90c48dd4..5c26c8d3 100644 --- a/asm/Dolphin/GBA/GBAKey.s +++ b/asm/Dolphin/GBA/GBAKey.s @@ -3,7 +3,7 @@ .section .data, "wa" .balign 8 -lbl_803F71A0: +D35: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 2,255, 0, 33 .byte 19, 6, 18, 3, 18, 4, 19, 5, 0,146, 0,255, 0,136,255,255 @@ -216,9 +216,9 @@ __GBAX02: /* 803CB12C 003C808C 38 80 00 20 */ li r4, 0x20 /* 803CB130 003C8090 4B FB 39 81 */ bl DCFlushRange /* 803CB134 003C8094 38 00 00 FF */ li r0, 0xff -/* 803CB138 003C8098 3C 80 80 3F */ lis r4, lbl_803F71A0@ha +/* 803CB138 003C8098 3C 80 80 3F */ lis r4, D35@ha /* 803CB13C 003C809C 90 1F 00 AC */ stw r0, 0xac(r31) -/* 803CB140 003C80A0 38 84 71 A0 */ addi r4, r4, lbl_803F71A0@l +/* 803CB140 003C80A0 38 84 71 A0 */ addi r4, r4, D35@l /* 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 diff --git a/configure.py b/configure.py index 8f273a04..b4f85b38 100755 --- a/configure.py +++ b/configure.py @@ -1011,6 +1011,8 @@ LIBS = [ "cflags": "$cflags_base", "objects": [ "Dolphin/GBA/GBA", + "Dolphin/GBA/GBAGetProcessStatus", + "Dolphin/GBA/GBAJoyBoot", "Dolphin/GBA/GBARead", "Dolphin/GBA/GBAWrite", "Dolphin/GBA/GBAXfer", diff --git a/include/dolphin/gba.h b/include/dolphin/gba.h index 557c5641..692f568f 100644 --- a/include/dolphin/gba.h +++ b/include/dolphin/gba.h @@ -1,10 +1,63 @@ #ifndef _DOLPHIN_GBA #define _DOLPHIN_GBA +#include + #ifdef __cplusplus extern "C" { #endif -void GBAInit(); + +#define GBA_CHAN0 0 +#define GBA_CHAN1 1 +#define GBA_CHAN2 2 +#define GBA_CHAN3 3 +#define GBA_MAX_CHAN 4 + +#define GBA_ALL_KEY_MASK 0x03ff +#define GBA_A_BUTTON 0x0001 +#define GBA_B_BUTTON 0x0002 +#define GBA_SELECT_BUTTON 0x0004 +#define GBA_START_BUTTON 0x0008 +#define GBA_R_KEY 0x0010 +#define GBA_L_KEY 0x0020 +#define GBA_U_KEY 0x0040 +#define GBA_D_KEY 0x0080 +#define GBA_R_BUTTON 0x0100 +#define GBA_L_BUTTON 0x0200 + +#define GBA_JSTAT_MASK 0x3a +#define GBA_JSTAT_FLAGS_SHIFT 4 +#define GBA_JSTAT_FLAGS_MASK 0x30 +#define GBA_JSTAT_PSF1 0x20 +#define GBA_JSTAT_PSF0 0x10 +#define GBA_JSTAT_SEND 0x08 +#define GBA_JSTAT_RECV 0x02 + +#define GBA_READY 0 +#define GBA_NOT_READY 1 +#define GBA_BUSY 2 +#define GBA_JOYBOOT_UNKNOWN_STATE 3 +#define GBA_JOYBOOT_ERR_INVALID 4 + +#define GBA_JOYBOOT_PROGRAM_SIZE_MAX 0x40000 + +#define GBA_JOYBOOT_BOOTPARAM_OFFSET 0xc8 +#define GBA_JOYBOOT_BOOTPARAM_SIZE 0x18 +typedef void (*GBACallback)(s32 chan, s32 ret); +void GBAInit(void); +s32 GBAGetStatus(s32 chan, u8* status); +s32 GBAGetStatusAsync(s32 chan, u8* status, GBACallback callback); +s32 GBAReset(s32 chan, u8* status); +s32 GBAResetAsync(s32 chan, u8* status, GBACallback callback); +s32 GBAGetProcessStatus(s32 chan, u8* percentp); +s32 GBARead(s32 chan, u8* dst, u8* status); +s32 GBAReadAsync(s32 chan, u8* dst, u8* status, GBACallback callback); +s32 GBAWrite(s32 chan, u8* src, u8* status); +s32 GBAWriteAsync(s32 chan, u8* src, u8* status, GBACallback callback); +s32 GBAJoyBoot(s32 chan, s32 palette_color, s32 palette_speed, u8* programp, s32 length, + u8* status); +s32 GBAJoyBootAsync(s32 chan, s32 palette_color, s32 palette_speed, u8* programp, s32 length, + u8* status, GBACallback callback); #ifdef __cplusplus } #endif