Skip to content

Commit

Permalink
GBAJoyBoot OK
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Jan 27, 2025
1 parent ffe54e0 commit 02b2132
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 108 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def MatchingFor(*versions):
[
Object(Matching, "dolphin/gba/GBA.c"),
Object(Matching, "dolphin/gba/GBAGetProcessStatus.c"),
Object(NonMatching, "dolphin/gba/GBAJoyBoot.c"),
Object(Matching, "dolphin/gba/GBAJoyBoot.c"),
Object(Matching, "dolphin/gba/GBARead.c"),
Object(Matching, "dolphin/gba/GBAWrite.c"),
Object(Matching, "dolphin/gba/GBAXfer.c"),
Expand Down
51 changes: 25 additions & 26 deletions include/dolphin/dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,31 @@ extern "C" {
typedef void (*DSPCallback)(void* task);

typedef struct STRUCT_DSP_TASK {
vu32 state;
vu32 priority;
vu32 flags;
u16* iram_mmem_addr;
u32 iram_length;
u32 iram_addr;

u16* dram_mmem_addr;
u32 dram_length;
u32 dram_addr;

u16 dsp_init_vector;
u16 dsp_resume_vector;

DSPCallback init_cb;
DSPCallback res_cb;
DSPCallback done_cb;
DSPCallback req_cb;

struct STRUCT_DSP_TASK* next;
struct STRUCT_DSP_TASK* prev;

OSTime t_context;
OSTime t_task;

} DSPTaskInfo;
/* 0x00 */ vu32 state;
/* 0x04 */ vu32 priority;
/* 0x08 */ vu32 flags;
/* 0x0C */ u16* iram_mmem_addr;
/* 0x10 */ u32 iram_length;
/* 0x14 */ u32 iram_addr;

/* 0x18 */ u16* dram_mmem_addr;
/* 0x1C */ u32 dram_length;
/* 0x20 */ u32 dram_addr;

/* 0x24 */ u16 dsp_init_vector;
/* 0x26 */ u16 dsp_resume_vector;

/* 0x28 */ DSPCallback init_cb;
/* 0x2C */ DSPCallback res_cb;
/* 0x30 */ DSPCallback done_cb;
/* 0x34 */ DSPCallback req_cb;

/* 0x38 */ struct STRUCT_DSP_TASK* next;
/* 0x3C */ struct STRUCT_DSP_TASK* prev;

/* 0x40 */ OSTime t_context;
/* 0x48 */ OSTime t_task;
} DSPTaskInfo; // Size: 0x50

extern DSPTaskInfo* __DSP_tmp_task;
extern DSPTaskInfo* __DSP_last_task;
Expand Down
92 changes: 46 additions & 46 deletions include/dolphin/gba/GBAPriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,55 @@ extern "C" {
typedef void (*GBATransferCallback)(s32 chan);

typedef struct GBASecParam {
u8 readbuf[4];
s32 paletteColor;
s32 paletteSpeed;
s32 length;
u32* out;
u8 _padding0[12];
u32 keyA;
s32 keyB;
u8 _padding1[24];
} GBASecParam ALIGN_DECL(32);
/* 0x00 */ u8 readbuf[4];
/* 0x04 */ s32 paletteColor;
/* 0x08 */ s32 paletteSpeed;
/* 0x0C */ s32 length;
/* 0x10 */ u32* out;
/* 0x14 */ u8 _padding0[12];
/* 0x20 */ u32 keyA;
/* 0x24 */ s32 keyB;
/* 0x28 */ u8 _padding1[24];
} GBASecParam ALIGN_DECL(32); // Size: 0x40

typedef struct GBABootInfo {
s32 paletteColor;
s32 paletteSpeed;
u8* programp;
s32 length;
u8* status;
GBACallback callback;
u8 readbuf[4];
u8 writebuf[4];
int i;
OSTick start;
OSTime begin;
int firstXfer;
int curOffset;
u32 crc;
u32 dummyWord[7];
u32 keyA;
s32 keyB;
u32 initialCode;
int realLength;
} GBABootInfo;
/* 0x00 */ s32 paletteColor;
/* 0x04 */ s32 paletteSpeed;
/* 0x08 */ u8* programp;
/* 0x0C */ s32 length;
/* 0x10 */ u8* status;
/* 0x14 */ GBACallback callback;
/* 0x18 */ u8 readbuf[4];
/* 0x1C */ u8 writebuf[4];
/* 0x20 */ int i;
/* 0x24 */ OSTick start;
/* 0x28 */ OSTime begin;
/* 0x30 */ int firstXfer;
/* 0x34 */ int curOffset;
/* 0x38 */ u32 crc;
/* 0x3C */ u32 dummyWord[7];
/* 0x58 */ u32 keyA;
/* 0x5C */ s32 keyB;
/* 0x60 */ u32 initialCode;
/* 0x64 */ int realLength;
} GBABootInfo; // Size: 0x68

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;
GBASecParam* param;
} GBAControl;
/* 0x000 */ u8 output[5];
/* 0x005 */ u8 input[5];
/* 0x00C */ s32 outputBytes;
/* 0x010 */ s32 inputBytes;
/* 0x014 */ u8* status;
/* 0x018 */ u8* ptr;
/* 0x01C */ GBACallback callback;
/* 0x020 */ s32 ret;
/* 0x024 */ OSThreadQueue threadQueue;
/* 0x030 */ OSTime delay;
/* 0x038 */ GBATransferCallback proc;
/* 0x040 */ GBABootInfo bootInfo;
/* 0x0A8 */ DSPTaskInfo task;
/* 0x0F8 */ GBASecParam* param;
} GBAControl; // Size: 0x100

extern GBAControl __GBA[4];
extern BOOL __GBAReset;
Expand All @@ -76,4 +76,4 @@ s32 __GBATransfer(s32 chan, s32 w1, s32 w2, GBATransferCallback callback);
}
#endif

#endif // _DOLPHIN_GBAPRIV
#endif // _DOLPHIN_GBAPRIV
2 changes: 1 addition & 1 deletion src/JSystem/JAudio/JASDSPChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void JASystem::TDSPChannel::updateAll() {
TDSPQueue::checkQueue();
for (u32 i = 0; i < 64; i++) {
if ((i & 0x0f) == 0 && i != 0) {
DSPReleaseHalt2(i - 1 >> 4);
DSPReleaseHalt2((i - 1) >> 4);
}
dspBuffer = DSPCH[i].field_0xc;
TDSPChannel* dspChannel = &DSPCH[i];
Expand Down
2 changes: 1 addition & 1 deletion src/dolphin/gba/GBA.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ s32 GBAReset(s32 chan, u8* status) {
BOOL OnReset(BOOL final) {
__GBAReset = TRUE;
return TRUE;
}
}
90 changes: 61 additions & 29 deletions src/dolphin/gba/GBAJoyBoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,59 +135,91 @@ static void F27(s32 chan, s32 ret) {
gba->ret = ret;
}

// NONMATCHING
static void F29(s32 chan, s32 ret) {
GBAControl* gba = &__GBA[chan];
GBABootInfo* bootInfo = &__GBA[chan].bootInfo;

if (ret == GBA_READY) {
__GBAX02(chan, bootInfo->readbuf);
} else {
F104(chan, ret);
}

gba->ret = ret;
}

void __GBAX01(s32 chan, s32 ret) {
GBAControl* gba = &__GBA[chan];
GBABootInfo* bootInfo = &__GBA[chan].bootInfo;
int val200;

if (ret == GBA_READY) {
bootInfo->keyA = gba->param->keyA;
bootInfo->keyB = gba->param->keyB;
if (bootInfo->readbuf[3] == 0 || bootInfo->readbuf[2] == 0 ||
(bootInfo->keyA & (D54[5] << 9)) == 0 || bootInfo->readbuf[1] == 0 ||
(bootInfo->keyA >> 15) == 0 || bootInfo->readbuf[0] == 0)
{
bootInfo->keyA =
(bootInfo->readbuf[3] ^ D54[28]) << 24 |
(bootInfo->readbuf[2] ^ D54[14]) << 16 |
(bootInfo->readbuf[1] ^ D54[15]) << 8 |
(bootInfo->readbuf[0] ^ D54[25]);

if (
bootInfo->readbuf[3] == 0 ||
bootInfo->readbuf[2] == 0 ||
(bootInfo->keyA & (D54[5] << 9)) == 0 ||
bootInfo->readbuf[1] == 0 ||
(bootInfo->keyA >> 15) == 0 ||
bootInfo->readbuf[0] == 0
) {
ret = GBA_JOYBOOT_UNKNOWN_STATE;
} else {
switch (bootInfo->paletteSpeed) {
case -4:
case -3:
case -2:
case -1:
bootInfo->keyB = (bootInfo->paletteColor << 4 | (3 - bootInfo->paletteSpeed)*2) << 16;
break;
case 0:
bootInfo->keyB = (bootInfo->paletteColor << 1 | 0x70) << 16;
break;
case 1:
case 2:
case 3:
case 4:
bootInfo->keyB = (bootInfo->paletteColor << 4 | (bootInfo->paletteSpeed - 1)*2) << 16;
break;
}

bootInfo->i = ~D54[36] & bootInfo->length + D54[36];
val200 = D54[20] << D54[33];

if (bootInfo->i < val200) {
bootInfo->i = val200;
}

bootInfo->realLength = bootInfo->i;
bootInfo->i -= val200;
bootInfo->i >>= D54[32];
bootInfo->writebuf[0] = (u8)(bootInfo->keyB >> 0);
bootInfo->writebuf[1] = (u8)(bootInfo->keyB >> 8);
bootInfo->writebuf[3] = (u8)(bootInfo->keyB >> 24);
bootInfo->writebuf[2] = (u8)(bootInfo->keyB >> 16);
bootInfo->keyB |=
((bootInfo->i & (D54[3] << D54[36])) << D54[31]) |
((bootInfo->i & (D54[3] | (D54[6] << D54[37]))) << D54[7]) |
bootInfo->i & D54[4];

bootInfo->keyB |=
((bootInfo->keyB + (bootInfo->keyB >> 8) + (bootInfo->keyB >> 16))) << 24 |
D54[3] << 24 |
D54[5] << 17 |
D54[17] << 10 |
D54[3];

if ((bootInfo->keyB & val200) != 0) {
bootInfo->writebuf[3] = (bootInfo->keyB >> 24) ^ D54[13];
bootInfo->writebuf[2] = (bootInfo->keyB >> 16) ^ D54[16];
bootInfo->writebuf[0] = bootInfo->keyB ^ D54[25];
bootInfo->writebuf[1] = (bootInfo->keyB >> 8) ^ D54[26];
} else {
bootInfo->writebuf[0] = bootInfo->keyB ^ D54[21];
bootInfo->writebuf[1] = (bootInfo->keyB >> 8) ^ D54[22];
bootInfo->writebuf[3] = (bootInfo->keyB >> 24) ^ D54[22];
bootInfo->writebuf[2] = (bootInfo->keyB >> 16) ^ D54[23];
}
bootInfo->crc = (D54[38] + 1) << D54[34];
bootInfo->curOffset = D54[8];
bootInfo->begin = OSGetTime();
bootInfo->firstXfer = TRUE;
ret = GBAWriteAsync(chan, bootInfo->writebuf, bootInfo->status, F31);
}
}

if (ret != GBA_READY) {
F104(chan, ret);
}

gba->ret = ret;
}

Expand Down Expand Up @@ -382,4 +414,4 @@ s32 GBAJoyBoot(s32 chan, s32 paletteColor, s32 paletteSpeed, u8* programp, s32 l
}

return __GBASync(chan);
}
}
2 changes: 1 addition & 1 deletion src/dolphin/gba/GBARead.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ s32 GBARead(s32 chan, u8* dst, u8* status) {
}

return __GBASync(chan);
}
}
2 changes: 1 addition & 1 deletion src/dolphin/gba/GBAXfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ OSTime __GBASetDelay(s32 chan, OSTime delay) {
oldDelay = gba->delay;
gba->delay = delay;
return oldDelay;
}
}
1 change: 0 additions & 1 deletion src/f_op/f_op_actor_mng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ static fopAc_cullSizeBox l_cullSizeBox[14] = {
/* fopAc_CULLBOX_11_e */ fopAc_MakeCullSizeBox(cXyz(-75.0f, 0.0f, -75.0f), cXyz(75.0f, 210.0f, 75.0f)),
/* fopAc_CULLBOX_12_e */ fopAc_MakeCullSizeBox(cXyz(-70.0f, -100.0f, -80.0f), cXyz(70.0f, 240.0f, 100.0f)),
/* fopAc_CULLBOX_13_e */ fopAc_MakeCullSizeBox(cXyz(-60.0f, -20.0f, -60.0f), cXyz(60.0f, 160.0f, 60.0f)),

};
static fopAc_cullSizeSphere l_cullSizeSphere[8] = {
/* fopAc_CULLSPHERE_0_e */ fopAc_MakeCullSizeSphere(cXyz(0.0f, 0.0f, 0.0f), 80.0f),
Expand Down
1 change: 0 additions & 1 deletion src/m_Do/m_Do_controller_pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ int mDoCPd_Read() {
}

/* 80007A70-80007BBC .text mDoCPd_Create__Fv */
// NONMATCHING - weird ending
int mDoCPd_Create() {
JUTGamePad::mSuppressPadReset = 1;

Expand Down

0 comments on commit 02b2132

Please sign in to comment.