mirror of https://github.com/mgba-emu/mgba.git
GBA Periperals: Improve chip gate resync, remove switch table
This commit is contained in:
parent
80c46c5fd8
commit
f00b7fcf55
|
@ -13,6 +13,7 @@ mLOG_DECLARE_CATEGORY(GBA_BATTLECHIP);
|
|||
mLOG_DEFINE_CATEGORY(GBA_BATTLECHIP, "GBA BattleChip Gate", "gba.battlechip");
|
||||
|
||||
enum {
|
||||
BATTLECHIP_STATE_SYNC = -1,
|
||||
BATTLECHIP_STATE_COMMAND = 0,
|
||||
BATTLECHIP_STATE_UNK_0 = 1,
|
||||
BATTLECHIP_STATE_UNK_1 = 2,
|
||||
|
@ -32,7 +33,6 @@ enum {
|
|||
BATTLECHIP_CONTINUE = 0xFFFF,
|
||||
};
|
||||
|
||||
static bool GBASIOBattlechipGateInit(struct GBASIODriver* driver);
|
||||
static bool GBASIOBattlechipGateLoad(struct GBASIODriver* driver);
|
||||
static uint16_t GBASIOBattlechipGateWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value);
|
||||
|
||||
|
@ -40,7 +40,7 @@ static void _battlechipTransfer(struct GBASIOBattlechipGate* gate);
|
|||
static void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cyclesLate);
|
||||
|
||||
void GBASIOBattlechipGateCreate(struct GBASIOBattlechipGate* gate) {
|
||||
gate->d.init = GBASIOBattlechipGateInit;
|
||||
gate->d.init = NULL;
|
||||
gate->d.deinit = NULL;
|
||||
gate->d.load = GBASIOBattlechipGateLoad;
|
||||
gate->d.unload = NULL;
|
||||
|
@ -54,14 +54,9 @@ void GBASIOBattlechipGateCreate(struct GBASIOBattlechipGate* gate) {
|
|||
gate->flavor = GBA_FLAVOR_BATTLECHIP_GATE;
|
||||
}
|
||||
|
||||
bool GBASIOBattlechipGateInit(struct GBASIODriver* driver) {
|
||||
struct GBASIOBattlechipGate* gate = (struct GBASIOBattlechipGate*) driver;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GBASIOBattlechipGateLoad(struct GBASIODriver* driver) {
|
||||
struct GBASIOBattlechipGate* gate = (struct GBASIOBattlechipGate*) driver;
|
||||
gate->state = BATTLECHIP_STATE_COMMAND;
|
||||
gate->state = BATTLECHIP_STATE_SYNC;
|
||||
gate->data[0] = 0x00FE;
|
||||
gate->data[1] = 0xFFFE;
|
||||
return true;
|
||||
|
@ -119,7 +114,7 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle
|
|||
gate->d.p->multiplayerControl.busy = 0;
|
||||
gate->d.p->multiplayerControl.id = 0;
|
||||
|
||||
mLOG(GBA_BATTLECHIP, DEBUG, "> %04X", cmd);
|
||||
mLOG(GBA_BATTLECHIP, DEBUG, "Game: %04X (%i)", cmd, gate->state);
|
||||
|
||||
uint16_t ok;
|
||||
switch (gate->flavor) {
|
||||
|
@ -138,12 +133,9 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle
|
|||
break;
|
||||
}
|
||||
|
||||
switch (gate->state) {
|
||||
case BATTLECHIP_STATE_COMMAND:
|
||||
mLOG(GBA_BATTLECHIP, DEBUG, "C %04X", cmd);
|
||||
if (gate->state != BATTLECHIP_STATE_COMMAND) {
|
||||
// Resync if needed
|
||||
switch (cmd) {
|
||||
case 0x0000:
|
||||
case 0x8FFF:
|
||||
// EXE 5, 6
|
||||
case 0xA380:
|
||||
case 0xA390:
|
||||
|
@ -153,94 +145,20 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle
|
|||
case 0xA3D0:
|
||||
// EXE 4
|
||||
case 0xA6C0:
|
||||
gate->state = -1;
|
||||
// Fall through
|
||||
//
|
||||
case 0x5379:
|
||||
case 0x537A:
|
||||
case 0x537B:
|
||||
case 0x537C:
|
||||
case 0x537D:
|
||||
case 0x537E:
|
||||
// EXE 6
|
||||
case 0x65AF:
|
||||
//
|
||||
case 0x6E8F:
|
||||
//
|
||||
case 0x87D0:
|
||||
case 0x87D1:
|
||||
case 0x87D2:
|
||||
case 0x87D3:
|
||||
case 0x87D4:
|
||||
case 0x87D5:
|
||||
case 0x87DB:
|
||||
case 0xB7D3:
|
||||
case 0xB7D4:
|
||||
case 0xB7D5:
|
||||
case 0xB7D6:
|
||||
case 0xB7D7:
|
||||
case 0xB7D8:
|
||||
//
|
||||
case 0xC4D3:
|
||||
case 0xC4D4:
|
||||
case 0xC4D5:
|
||||
case 0xC4D6:
|
||||
case 0xC4D7:
|
||||
case 0xC4D8:
|
||||
case 0xC4D9:
|
||||
case 0xC4DA:
|
||||
case 0xC4DB:
|
||||
case 0xC4DC:
|
||||
case 0xC4DD:
|
||||
// EXE 4
|
||||
case 0xD979:
|
||||
case 0xD97A:
|
||||
case 0xD97B:
|
||||
case 0xD97C:
|
||||
case 0xD97D:
|
||||
case 0xD97E:
|
||||
case 0xD97F:
|
||||
case 0xD980:
|
||||
case 0xD981:
|
||||
case 0xD982:
|
||||
case 0xD983:
|
||||
case 0xD984:
|
||||
// EXE 5
|
||||
case 0xE49A:
|
||||
case 0xE49B:
|
||||
case 0xE49C:
|
||||
reply = ok;
|
||||
break;
|
||||
//
|
||||
case 0x3545:
|
||||
case 0x3546:
|
||||
case 0x3547:
|
||||
case 0x3548:
|
||||
case 0x3549:
|
||||
case 0x354A:
|
||||
//
|
||||
case 0x424A:
|
||||
case 0x424B:
|
||||
case 0x424C:
|
||||
case 0x424D:
|
||||
case 0x424E:
|
||||
case 0x424F:
|
||||
case 0x4250:
|
||||
//
|
||||
case 0x5745:
|
||||
case 0x5746:
|
||||
case 0x5747:
|
||||
case 0x5748:
|
||||
case 0x5749:
|
||||
case 0x574A:
|
||||
// Resync
|
||||
gate->state = BATTLECHIP_STATE_UNK_0;
|
||||
break;
|
||||
default:
|
||||
mLOG(GBA_BATTLECHIP, STUB, "? %04X", cmd);
|
||||
gate->state = -1;
|
||||
mLOG(GBA_BATTLECHIP, DEBUG, "Resync detected");
|
||||
gate->state = BATTLECHIP_STATE_SYNC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (gate->state) {
|
||||
case BATTLECHIP_STATE_SYNC:
|
||||
if (cmd != 0x8FFF) {
|
||||
--gate->state;
|
||||
}
|
||||
// Fall through
|
||||
case BATTLECHIP_STATE_COMMAND:
|
||||
reply = ok;
|
||||
break;
|
||||
case BATTLECHIP_STATE_UNK_0:
|
||||
case BATTLECHIP_STATE_UNK_1:
|
||||
|
@ -265,12 +183,12 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle
|
|||
break;
|
||||
case BATTLECHIP_STATE_END:
|
||||
reply = ok;
|
||||
gate->state = -1;
|
||||
gate->state = BATTLECHIP_STATE_SYNC;
|
||||
break;
|
||||
}
|
||||
++gate->state;
|
||||
|
||||
mLOG(GBA_BATTLECHIP, DEBUG, "< %04X", reply);
|
||||
mLOG(GBA_BATTLECHIP, DEBUG, "Gate: %04X (%i)", reply, gate->state);
|
||||
++gate->state;
|
||||
|
||||
gate->d.p->p->memory.io[REG_SIOMULTI1 >> 1] = reply;
|
||||
|
||||
|
|
Loading…
Reference in New Issue