GBA SIO: Replace writeRegister with writeSIOCNT

This commit is contained in:
Vicki Pfau 2024-05-22 01:40:01 -07:00
parent 9998de4880
commit 5da4b1fc4d
6 changed files with 88 additions and 120 deletions

View File

@ -117,7 +117,7 @@ struct GBASIODriver {
bool (*handlesMode)(struct GBASIODriver* driver, enum GBASIOMode mode); bool (*handlesMode)(struct GBASIODriver* driver, enum GBASIOMode mode);
int (*connectedDevices)(struct GBASIODriver* driver); int (*connectedDevices)(struct GBASIODriver* driver);
int (*deviceId)(struct GBASIODriver* driver); int (*deviceId)(struct GBASIODriver* driver);
uint16_t (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); uint16_t (*writeSIOCNT)(struct GBASIODriver* driver, uint16_t value);
}; };
enum GBASIOBattleChipGateFlavor { enum GBASIOBattleChipGateFlavor {

View File

@ -34,7 +34,7 @@ enum {
}; };
static bool GBASIOBattlechipGateLoad(struct GBASIODriver* driver); static bool GBASIOBattlechipGateLoad(struct GBASIODriver* driver);
static uint16_t GBASIOBattlechipGateWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); static uint16_t GBASIOBattlechipGateWriteSIOCNT(struct GBASIODriver* driver, uint16_t value);
static bool GBASIOBattlechipGateHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode); static bool GBASIOBattlechipGateHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode);
static int GBASIOBattlechipGateConnectedDevices(struct GBASIODriver* driver); static int GBASIOBattlechipGateConnectedDevices(struct GBASIODriver* driver);
@ -46,7 +46,7 @@ void GBASIOBattlechipGateCreate(struct GBASIOBattlechipGate* gate) {
gate->d.deinit = NULL; gate->d.deinit = NULL;
gate->d.load = GBASIOBattlechipGateLoad; gate->d.load = GBASIOBattlechipGateLoad;
gate->d.unload = NULL; gate->d.unload = NULL;
gate->d.writeRegister = GBASIOBattlechipGateWriteRegister; gate->d.writeSIOCNT = GBASIOBattlechipGateWriteSIOCNT;
gate->d.setMode = NULL; gate->d.setMode = NULL;
gate->d.handlesMode = GBASIOBattlechipGateHandlesMode; gate->d.handlesMode = GBASIOBattlechipGateHandlesMode;
gate->d.connectedDevices = GBASIOBattlechipGateConnectedDevices; gate->d.connectedDevices = GBASIOBattlechipGateConnectedDevices;
@ -68,23 +68,13 @@ bool GBASIOBattlechipGateLoad(struct GBASIODriver* driver) {
return true; return true;
} }
uint16_t GBASIOBattlechipGateWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) { uint16_t GBASIOBattlechipGateWriteSIOCNT(struct GBASIODriver* driver, uint16_t value) {
struct GBASIOBattlechipGate* gate = (struct GBASIOBattlechipGate*) driver; struct GBASIOBattlechipGate* gate = (struct GBASIOBattlechipGate*) driver;
switch (address) {
case GBA_REG_SIOCNT:
value &= ~0xC; value &= ~0xC;
value |= 0x8; value |= 0x8;
if (value & 0x80) { if (value & 0x80) {
_battlechipTransfer(gate); _battlechipTransfer(gate);
} }
break;
case GBA_REG_SIOMLT_SEND:
break;
case GBA_REG_RCNT:
break;
default:
break;
}
return value; return value;
} }

View File

@ -193,9 +193,6 @@ void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value) {
sio->rcnt &= 0xF; sio->rcnt &= 0xF;
sio->rcnt |= value & ~0xF; sio->rcnt |= value & ~0xF;
_switchMode(sio); _switchMode(sio);
if (sio->activeDriver && sio->activeDriver->writeRegister) {
sio->activeDriver->writeRegister(sio->activeDriver, GBA_REG_RCNT, value);
}
} }
void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) { void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
@ -213,7 +210,7 @@ void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
id = sio->activeDriver->deviceId(sio->activeDriver); id = sio->activeDriver->deviceId(sio->activeDriver);
} }
connected = sio->activeDriver->connectedDevices(sio->activeDriver); connected = sio->activeDriver->connectedDevices(sio->activeDriver);
handled = !!sio->activeDriver->writeRegister; handled = !!sio->activeDriver->writeSIOCNT;
} }
} }
@ -229,7 +226,7 @@ void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
break; break;
} }
if (handled) { if (handled) {
value = sio->activeDriver->writeRegister(sio->activeDriver, GBA_REG_SIOCNT, value); value = sio->activeDriver->writeSIOCNT(sio->activeDriver, value);
} else { } else {
// Dummy drivers // Dummy drivers
switch (sio->mode) { switch (sio->mode) {
@ -328,10 +325,6 @@ uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t valu
// TODO // TODO
break; break;
} }
if (sio->activeDriver && sio->activeDriver->writeRegister && sio->activeDriver->handlesMode(sio->activeDriver, sio->mode)) {
sio->activeDriver->writeRegister(sio->activeDriver, address, value);
}
return value; return value;
} }

View File

@ -36,7 +36,7 @@ void GBASIODolphinCreate(struct GBASIODolphin* dol) {
dol->d.init = GBASIODolphinInit; dol->d.init = GBASIODolphinInit;
dol->d.load = GBASIODolphinLoad; dol->d.load = GBASIODolphinLoad;
dol->d.unload = GBASIODolphinUnload; dol->d.unload = GBASIODolphinUnload;
dol->d.writeRegister = NULL; dol->d.writeSIOCNT = NULL;
dol->d.setMode = NULL; dol->d.setMode = NULL;
dol->d.handlesMode = GBASIODolphinHandlesMode; dol->d.handlesMode = GBASIODolphinHandlesMode;
dol->d.connectedDevices = GBASIODolphinConnectedDevices; dol->d.connectedDevices = GBASIODolphinConnectedDevices;

View File

@ -13,7 +13,7 @@
#include <mgba-util/memory.h> #include <mgba-util/memory.h>
static uint16_t _gbpRead(struct mKeyCallback*); static uint16_t _gbpRead(struct mKeyCallback*);
static uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); static uint16_t _gbpSioWriteSIOCNT(struct GBASIODriver* driver, uint16_t value);
static bool _gbpSioHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode); static bool _gbpSioHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode);
static int _gbpSioConnectedDevices(struct GBASIODriver* driver); static int _gbpSioConnectedDevices(struct GBASIODriver* driver);
static void _gbpSioProcessEvents(struct mTiming* timing, void* user, uint32_t cyclesLate); static void _gbpSioProcessEvents(struct mTiming* timing, void* user, uint32_t cyclesLate);
@ -49,7 +49,7 @@ void GBASIOPlayerInit(struct GBASIOPlayer* gbp) {
gbp->d.deinit = NULL; gbp->d.deinit = NULL;
gbp->d.load = NULL; gbp->d.load = NULL;
gbp->d.unload = NULL; gbp->d.unload = NULL;
gbp->d.writeRegister = _gbpSioWriteRegister; gbp->d.writeSIOCNT = _gbpSioWriteSIOCNT;
gbp->d.setMode = NULL; gbp->d.setMode = NULL;
gbp->d.handlesMode = _gbpSioHandlesMode; gbp->d.handlesMode = _gbpSioHandlesMode;
gbp->d.connectedDevices = _gbpSioConnectedDevices; gbp->d.connectedDevices = _gbpSioConnectedDevices;
@ -106,14 +106,14 @@ uint16_t _gbpRead(struct mKeyCallback* callback) {
return 0; return 0;
} }
uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) { uint16_t _gbpSioWriteSIOCNT(struct GBASIODriver* driver, uint16_t value) {
struct GBASIOPlayer* gbp = (struct GBASIOPlayer*) driver; struct GBASIOPlayer* gbp = (struct GBASIOPlayer*) driver;
if (address == GBA_REG_SIOCNT) {
if (value & 0x0080) { if (value & 0x0080) {
uint32_t rx = gbp->p->memory.io[GBA_REG(SIODATA32_LO)] | (gbp->p->memory.io[GBA_REG(SIODATA32_HI)] << 16); uint32_t rx = gbp->p->memory.io[GBA_REG(SIODATA32_LO)] | (gbp->p->memory.io[GBA_REG(SIODATA32_HI)] << 16);
if (gbp->txPosition < 12 && gbp->txPosition > 0) { if (gbp->txPosition < 12 && gbp->txPosition > 0) {
// TODO: Check expected // TODO: Check expected
} else if (gbp->txPosition >= 12) { } else if (gbp->txPosition >= 12) {
uint32_t mask = 0x33;
// 0x00 = Stop // 0x00 = Stop
// 0x11 = Hard Stop // 0x11 = Hard Stop
// 0x22 = Start // 0x22 = Start
@ -127,7 +127,6 @@ uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uin
mTimingSchedule(&gbp->p->timing, &gbp->event, 2048); mTimingSchedule(&gbp->p->timing, &gbp->event, 2048);
} }
value &= 0x78FB; value &= 0x78FB;
}
return value; return value;
} }

View File

@ -19,8 +19,8 @@ static void GBASIOLockstepNodeSetMode(struct GBASIODriver* driver, enum GBASIOMo
static bool GBASIOLockstepNodeHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode); static bool GBASIOLockstepNodeHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode);
static int GBASIOLockstepNodeConnectedDevices(struct GBASIODriver* driver); static int GBASIOLockstepNodeConnectedDevices(struct GBASIODriver* driver);
static int GBASIOLockstepNodeDeviceId(struct GBASIODriver* driver); static int GBASIOLockstepNodeDeviceId(struct GBASIODriver* driver);
static uint16_t GBASIOLockstepNodeMultiWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); static uint16_t GBASIOLockstepNodeMultiWriteSIOCNT(struct GBASIODriver* driver, uint16_t value);
static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); static uint16_t GBASIOLockstepNodeNormalWriteSIOCNT(struct GBASIODriver* driver, uint16_t value);
static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* driver, uint32_t cyclesLate); static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* driver, uint32_t cyclesLate);
static void _finishTransfer(struct GBASIOLockstepNode* node); static void _finishTransfer(struct GBASIOLockstepNode* node);
@ -46,7 +46,7 @@ void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode* node) {
node->d.handlesMode = GBASIOLockstepNodeHandlesMode; node->d.handlesMode = GBASIOLockstepNodeHandlesMode;
node->d.connectedDevices = GBASIOLockstepNodeConnectedDevices; node->d.connectedDevices = GBASIOLockstepNodeConnectedDevices;
node->d.deviceId = GBASIOLockstepNodeDeviceId; node->d.deviceId = GBASIOLockstepNodeDeviceId;
node->d.writeRegister = NULL; node->d.writeSIOCNT = NULL;
} }
bool GBASIOLockstepAttachNode(struct GBASIOLockstep* lockstep, struct GBASIOLockstepNode* node) { bool GBASIOLockstepAttachNode(struct GBASIOLockstep* lockstep, struct GBASIOLockstepNode* node) {
@ -112,7 +112,7 @@ bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver) {
switch (node->mode) { switch (node->mode) {
case GBA_SIO_MULTI: case GBA_SIO_MULTI:
node->d.writeRegister = GBASIOLockstepNodeMultiWriteRegister; node->d.writeSIOCNT = GBASIOLockstepNodeMultiWriteSIOCNT;
ATOMIC_ADD(node->p->attachedMulti, 1); ATOMIC_ADD(node->p->attachedMulti, 1);
node->d.p->siocnt = GBASIOMultiplayerSetReady(node->d.p->siocnt, node->p->attachedMulti == node->p->d.attached); node->d.p->siocnt = GBASIOMultiplayerSetReady(node->d.p->siocnt, node->p->attachedMulti == node->p->d.attached);
if (node->id) { if (node->id) {
@ -134,7 +134,7 @@ bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver) {
} else { } else {
node->d.p->siocnt = GBASIONormalClearSi(node->d.p->siocnt); node->d.p->siocnt = GBASIONormalClearSi(node->d.p->siocnt);
} }
node->d.writeRegister = GBASIOLockstepNodeNormalWriteRegister; node->d.writeSIOCNT = GBASIOLockstepNodeNormalWriteSIOCNT;
break; break;
default: default:
break; break;
@ -231,12 +231,11 @@ static int GBASIOLockstepNodeDeviceId(struct GBASIODriver* driver) {
return node->id; return node->id;
} }
static uint16_t GBASIOLockstepNodeMultiWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) { static uint16_t GBASIOLockstepNodeMultiWriteSIOCNT(struct GBASIODriver* driver, uint16_t value) {
struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver; struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver;
mLockstepLock(&node->p->d); mLockstepLock(&node->p->d);
if (address == GBA_REG_SIOCNT) {
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOCNT <- %04X", node->id, value); mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOCNT <- %04X", node->id, value);
enum mLockstepPhase transferActive; enum mLockstepPhase transferActive;
@ -261,11 +260,6 @@ static uint16_t GBASIOLockstepNodeMultiWriteRegister(struct GBASIODriver* driver
} }
value &= 0xFF83; value &= 0xFF83;
value |= driver->p->siocnt & 0x00FC; value |= driver->p->siocnt & 0x00FC;
} else if (address == GBA_REG_SIOMLT_SEND) {
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOMLT_SEND <- %04X", node->id, value);
} else {
mLOG(GBA_SIO, STUB, "Lockstep %i: Unknown reg %03X <- %04X", node->id, address, value);
}
mLockstepUnlock(&node->p->d); mLockstepUnlock(&node->p->d);
@ -525,12 +519,11 @@ static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* user,
mLockstepUnlock(&node->p->d); mLockstepUnlock(&node->p->d);
} }
static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) { static uint16_t GBASIOLockstepNodeNormalWriteSIOCNT(struct GBASIODriver* driver, uint16_t value) {
struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver; struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver;
mLockstepLock(&node->p->d); mLockstepLock(&node->p->d);
if (address == GBA_REG_SIOCNT) {
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOCNT <- %04X", node->id, value); mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOCNT <- %04X", node->id, value);
int attached; int attached;
ATOMIC_LOAD(attached, node->p->attachedNormal); ATOMIC_LOAD(attached, node->p->attachedNormal);
@ -575,13 +568,6 @@ static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* drive
// TODO // TODO
} }
} }
} else if (address == GBA_REG_SIODATA32_LO) {
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIODATA32_LO <- %04X", node->id, value);
} else if (address == GBA_REG_SIODATA32_HI) {
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIODATA32_HI <- %04X", node->id, value);
} else if (address == GBA_REG_SIODATA8) {
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIODATA8 <- %02X", node->id, value);
}
mLockstepUnlock(&node->p->d); mLockstepUnlock(&node->p->d);