GBA: Prefix SIO constants with GBA_

This commit is contained in:
Vicki Pfau 2024-05-06 15:35:23 -07:00
parent 1d2b8bf918
commit d9e080b9a9
11 changed files with 69 additions and 69 deletions

View File

@ -21,12 +21,12 @@ enum {
};
enum GBASIOMode {
SIO_NORMAL_8 = 0,
SIO_NORMAL_32 = 1,
SIO_MULTI = 2,
SIO_UART = 3,
SIO_GPIO = 8,
SIO_JOYBUS = 12
GBA_SIO_NORMAL_8 = 0,
GBA_SIO_NORMAL_32 = 1,
GBA_SIO_MULTI = 2,
GBA_SIO_UART = 3,
GBA_SIO_GPIO = 8,
GBA_SIO_JOYBUS = 12
};
enum GBASIOJOYCommand {

View File

@ -525,7 +525,7 @@ void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASer
uint32_t when;
LOAD_32(when, 0, &state->hw.gbpNextEvent);
if (hw->devices & HW_GB_PLAYER) {
GBASIOSetDriver(&hw->p->sio, &hw->p->sio.gbp.d, SIO_NORMAL_32);
GBASIOSetDriver(&hw->p->sio, &hw->p->sio.gbp.d, GBA_SIO_NORMAL_32);
if (hw->p->memory.io[GBA_REG(SIOCNT)] & 0x0080) {
mTimingSchedule(&hw->p->timing, &hw->p->sio.gbp.event, when);
}

View File

@ -891,8 +891,8 @@ static void _GBACoreSetPeripheral(struct mCore* core, int type, void* periph) {
gba->luminanceSource = periph;
break;
case mPERIPH_GBA_BATTLECHIP_GATE:
GBASIOSetDriver(&gba->sio, periph, SIO_MULTI);
GBASIOSetDriver(&gba->sio, periph, SIO_NORMAL_32);
GBASIOSetDriver(&gba->sio, periph, GBA_SIO_MULTI);
GBASIOSetDriver(&gba->sio, periph, GBA_SIO_NORMAL_32);
break;
default:
return;

View File

@ -84,7 +84,7 @@ uint16_t GBASIOBattlechipGateWriteRegister(struct GBASIODriver* driver, uint32_t
void _battlechipTransfer(struct GBASIOBattlechipGate* gate) {
int32_t cycles;
if (gate->d.p->mode == SIO_NORMAL_32) {
if (gate->d.p->mode == GBA_SIO_NORMAL_32) {
cycles = GBA_ARM7TDMI_FREQUENCY / 0x40000;
} else {
cycles = GBASIOCyclesPerTransfer[GBASIOMultiplayerGetBaud(gate->d.p->siocnt)][1];
@ -97,7 +97,7 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle
UNUSED(timing);
struct GBASIOBattlechipGate* gate = user;
if (gate->d.p->mode == SIO_NORMAL_32) {
if (gate->d.p->mode == GBA_SIO_NORMAL_32) {
gate->d.p->p->memory.io[GBA_REG(SIODATA32_LO)] = 0;
gate->d.p->p->memory.io[GBA_REG(SIODATA32_HI)] = 0;
gate->d.p->siocnt = GBASIONormalClearStart(gate->d.p->siocnt);

View File

@ -232,7 +232,7 @@ void GBAReset(struct ARMCore* cpu) {
// GB Player SIO control should not be engaged before detection, even if we already know it's GBP
gba->memory.hw.devices &= ~HW_GB_PLAYER;
if (gba->sio.drivers.normal == &gba->sio.gbp.d) {
GBASIOSetDriver(&gba->sio, NULL, SIO_NORMAL_32);
GBASIOSetDriver(&gba->sio, NULL, GBA_SIO_NORMAL_32);
}
bool isELF = false;

View File

@ -20,12 +20,12 @@ const int GBASIOCyclesPerTransfer[4][MAX_GBAS] = {
static struct GBASIODriver* _lookupDriver(struct GBASIO* sio, enum GBASIOMode mode) {
switch (mode) {
case SIO_NORMAL_8:
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_8:
case GBA_SIO_NORMAL_32:
return sio->drivers.normal;
case SIO_MULTI:
case GBA_SIO_MULTI:
return sio->drivers.multiplayer;
case SIO_JOYBUS:
case GBA_SIO_JOYBUS:
return sio->drivers.joybus;
default:
return 0;
@ -34,15 +34,15 @@ static struct GBASIODriver* _lookupDriver(struct GBASIO* sio, enum GBASIOMode mo
static const char* _modeName(enum GBASIOMode mode) {
switch (mode) {
case SIO_NORMAL_8:
case GBA_SIO_NORMAL_8:
return "NORMAL8";
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_32:
return "NORMAL32";
case SIO_MULTI:
case GBA_SIO_MULTI:
return "MULTI";
case SIO_JOYBUS:
case GBA_SIO_JOYBUS:
return "JOYBUS";
case SIO_GPIO:
case GBA_SIO_GPIO:
return "GPIO";
default:
return "(unknown)";
@ -113,22 +113,22 @@ void GBASIOReset(struct GBASIO* sio) {
}
void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers) {
GBASIOSetDriver(sio, drivers->normal, SIO_NORMAL_8);
GBASIOSetDriver(sio, drivers->multiplayer, SIO_MULTI);
GBASIOSetDriver(sio, drivers->joybus, SIO_JOYBUS);
GBASIOSetDriver(sio, drivers->normal, GBA_SIO_NORMAL_8);
GBASIOSetDriver(sio, drivers->multiplayer, GBA_SIO_MULTI);
GBASIOSetDriver(sio, drivers->joybus, GBA_SIO_JOYBUS);
}
void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode) {
struct GBASIODriver** driverLoc;
switch (mode) {
case SIO_NORMAL_8:
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_8:
case GBA_SIO_NORMAL_32:
driverLoc = &sio->drivers.normal;
break;
case SIO_MULTI:
case GBA_SIO_MULTI:
driverLoc = &sio->drivers.multiplayer;
break;
case SIO_JOYBUS:
case GBA_SIO_JOYBUS:
driverLoc = &sio->drivers.joybus;
break;
default:
@ -182,8 +182,8 @@ void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
} else {
// Dummy drivers
switch (sio->mode) {
case SIO_NORMAL_8:
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_8:
case GBA_SIO_NORMAL_32:
value = GBASIONormalFillSi(value);
if ((value & 0x0081) == 0x0081) {
if (GBASIONormalIsIrq(value)) {
@ -193,7 +193,7 @@ void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
value = GBASIONormalClearStart(value);
}
break;
case SIO_MULTI:
case GBA_SIO_MULTI:
value &= 0xFF83;
value |= 0xC;
break;
@ -211,7 +211,7 @@ uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t valu
}
// Dummy drivers
switch (sio->mode) {
case SIO_JOYBUS:
case GBA_SIO_JOYBUS:
switch (address) {
case GBA_REG_JOYCNT:
return (value & 0x0040) | (sio->p->memory.io[GBA_REG(JOYCNT)] & ~(value & 0x7) & ~0x0040);

View File

@ -56,7 +56,7 @@ void GBASIOPlayerInit(struct GBASIOPlayer* gbp) {
void GBASIOPlayerReset(struct GBASIOPlayer* gbp) {
if (gbp->p->sio.drivers.normal == &gbp->d) {
GBASIOSetDriver(&gbp->p->sio, NULL, SIO_NORMAL_32);
GBASIOSetDriver(&gbp->p->sio, NULL, GBA_SIO_NORMAL_32);
}
}
@ -88,7 +88,7 @@ void GBASIOPlayerUpdate(struct GBA* gba) {
gba->sio.gbp.oldCallback = gba->keyCallback;
gba->keyCallback = &gba->sio.gbp.callback.d;
// TODO: Check if the SIO driver is actually used first
GBASIOSetDriver(&gba->sio, &gba->sio.gbp.d, SIO_NORMAL_32);
GBASIOSetDriver(&gba->sio, &gba->sio.gbp.d, GBA_SIO_NORMAL_32);
}
}

View File

@ -103,7 +103,7 @@ bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver) {
node->mode = driver->p->mode;
switch (node->mode) {
case SIO_MULTI:
case GBA_SIO_MULTI:
node->d.writeRegister = GBASIOLockstepNodeMultiWriteRegister;
node->d.p->rcnt |= 3;
ATOMIC_ADD(node->p->attachedMulti, 1);
@ -125,8 +125,8 @@ bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver) {
node->d.p->siocnt = GBASIOMultiplayerClearSlave(node->d.p->siocnt);
}
break;
case SIO_NORMAL_8:
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_8:
case GBA_SIO_NORMAL_32:
if (ATOMIC_ADD(node->p->attachedNormal, 1) > node->id + 1 && node->id > 0) {
node->d.p->siocnt = GBASIONormalSetSi(node->d.p->siocnt, GBASIONormalGetIdleSo(node->p->players[node->id - 1]->d.p->siocnt));
} else {
@ -154,11 +154,11 @@ bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver) {
node->mode = driver->p->mode;
switch (node->mode) {
case SIO_MULTI:
case GBA_SIO_MULTI:
ATOMIC_SUB(node->p->attachedMulti, 1);
break;
case SIO_NORMAL_8:
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_8:
case GBA_SIO_NORMAL_32:
ATOMIC_SUB(node->p->attachedNormal, 1);
break;
default:
@ -180,7 +180,7 @@ bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver) {
}
// Invalidate SIO mode
node->mode = SIO_GPIO;
node->mode = GBA_SIO_GPIO;
mLockstepUnlock(&node->p->d);
@ -235,7 +235,7 @@ static void _finishTransfer(struct GBASIOLockstepNode* node) {
struct GBASIO* sio = node->d.p;
switch (node->mode) {
case SIO_MULTI:
case GBA_SIO_MULTI:
sio->p->memory.io[GBA_REG(SIOMULTI0)] = node->p->multiRecv[0];
sio->p->memory.io[GBA_REG(SIOMULTI1)] = node->p->multiRecv[1];
sio->p->memory.io[GBA_REG(SIOMULTI2)] = node->p->multiRecv[2];
@ -247,7 +247,7 @@ static void _finishTransfer(struct GBASIOLockstepNode* node) {
GBARaiseIRQ(sio->p, GBA_IRQ_SIO, 0);
}
break;
case SIO_NORMAL_8:
case GBA_SIO_NORMAL_8:
// TODO
sio->siocnt = GBASIONormalClearStart(sio->siocnt);
if (node->id) {
@ -260,7 +260,7 @@ static void _finishTransfer(struct GBASIOLockstepNode* node) {
GBARaiseIRQ(sio->p, GBA_IRQ_SIO, 0);
}
break;
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_32:
// TODO
sio->siocnt = GBASIONormalClearStart(sio->siocnt);
if (node->id) {
@ -299,7 +299,7 @@ static int32_t _masterUpdate(struct GBASIOLockstepNode* node) {
case TRANSFER_IDLE:
// If the master hasn't initiated a transfer, it can keep going.
node->nextEvent += LOCKSTEP_INCREMENT;
if (node->mode == SIO_MULTI) {
if (node->mode == GBA_SIO_MULTI) {
node->d.p->siocnt = GBASIOMultiplayerSetReady(node->d.p->siocnt, attachedMulti == attached);
}
break;
@ -307,7 +307,7 @@ static int32_t _masterUpdate(struct GBASIOLockstepNode* node) {
// Start the transfer, but wait for the other GBAs to catch up
node->transferFinished = false;
switch (node->mode) {
case SIO_MULTI:
case GBA_SIO_MULTI:
node->p->multiRecv[0] = node->d.p->p->memory.io[GBA_REG(SIOMLT_SEND)];
node->d.p->p->memory.io[GBA_REG(SIOMULTI0)] = 0xFFFF;
node->d.p->p->memory.io[GBA_REG(SIOMULTI1)] = 0xFFFF;
@ -317,11 +317,11 @@ static int32_t _masterUpdate(struct GBASIOLockstepNode* node) {
node->p->multiRecv[2] = 0xFFFF;
node->p->multiRecv[3] = 0xFFFF;
break;
case SIO_NORMAL_8:
case GBA_SIO_NORMAL_8:
node->p->multiRecv[0] = 0xFFFF;
node->p->normalRecv[0] = node->d.p->p->memory.io[GBA_REG(SIODATA8)] & 0xFF;
break;
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_32:
node->p->multiRecv[0] = 0xFFFF;
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIODATA32_LO <- %04X", node->id, node->d.p->p->memory.io[GBA_REG(SIODATA32_LO)]);
mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIODATA32_HI <- %04X", node->id, node->d.p->p->memory.io[GBA_REG(SIODATA32_HI)]);
@ -393,7 +393,7 @@ static uint32_t _slaveUpdate(struct GBASIOLockstepNode* node) {
ATOMIC_LOAD(transferActive, node->p->d.transferActive);
ATOMIC_LOAD(attached, node->p->d.attached);
if (node->mode == SIO_MULTI) {
if (node->mode == GBA_SIO_MULTI) {
ATOMIC_LOAD(attachedMode, node->p->attachedMulti);
node->d.p->siocnt = GBASIOMultiplayerSetReady(node->d.p->siocnt, attachedMode == attached);
} else {
@ -415,7 +415,7 @@ static uint32_t _slaveUpdate(struct GBASIOLockstepNode* node) {
}
node->transferFinished = false;
switch (node->mode) {
case SIO_MULTI:
case GBA_SIO_MULTI:
node->d.p->rcnt &= ~1;
node->p->multiRecv[node->id] = node->d.p->p->memory.io[GBA_REG(SIOMLT_SEND)];
node->d.p->p->memory.io[GBA_REG(SIOMULTI0)] = 0xFFFF;
@ -424,11 +424,11 @@ static uint32_t _slaveUpdate(struct GBASIOLockstepNode* node) {
node->d.p->p->memory.io[GBA_REG(SIOMULTI3)] = 0xFFFF;
node->d.p->siocnt = GBASIOMultiplayerFillBusy(node->d.p->siocnt);
break;
case SIO_NORMAL_8:
case GBA_SIO_NORMAL_8:
node->p->multiRecv[node->id] = 0xFFFF;
node->p->normalRecv[node->id] = node->d.p->p->memory.io[GBA_REG(SIODATA8)] & 0xFF;
break;
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_32:
node->p->multiRecv[node->id] = 0xFFFF;
node->p->normalRecv[node->id] = node->d.p->p->memory.io[GBA_REG(SIODATA32_LO)];
node->p->normalRecv[node->id] |= node->d.p->p->memory.io[GBA_REG(SIODATA32_HI)] << 16;
@ -466,11 +466,11 @@ static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* user,
node->eventDiff += cyclesLate;
if (node->p->d.attached < 2) {
switch (node->mode) {
case SIO_MULTI:
case GBA_SIO_MULTI:
cycles = GBASIOCyclesPerTransfer[GBASIOMultiplayerGetBaud(node->d.p->siocnt)][0];
break;
case SIO_NORMAL_8:
case SIO_NORMAL_32:
case GBA_SIO_NORMAL_8:
case GBA_SIO_NORMAL_32:
if (node->nextEvent <= 0) {
cycles = _masterUpdate(node);
node->eventDiff = 0;

View File

@ -23,12 +23,12 @@ class GBA(Core):
KEY_L = lib.GBA_KEY_L
KEY_R = lib.GBA_KEY_R
SIO_NORMAL_8 = lib.SIO_NORMAL_8
SIO_NORMAL_32 = lib.SIO_NORMAL_32
SIO_MULTI = lib.SIO_MULTI
SIO_UART = lib.SIO_UART
SIO_JOYBUS = lib.SIO_JOYBUS
SIO_GPIO = lib.SIO_GPIO
SIO_NORMAL_8 = lib.GBA_SIO_NORMAL_8
SIO_NORMAL_32 = lib.GBA_SIO_NORMAL_32
SIO_MULTI = lib.GBA_SIO_MULTI
SIO_UART = lib.GBA_SIO_UART
SIO_JOYBUS = lib.GBA_SIO_JOYBUS
SIO_GPIO = lib.GBA_SIO_GPIO
def __init__(self, native):
super(GBA, self).__init__(native)
@ -52,7 +52,7 @@ class GBA(Core):
super(GBA, self)._load()
self.memory = GBAMemory(self._core, self._native.memory.romSize)
def attach_sio(self, link, mode=lib.SIO_MULTI):
def attach_sio(self, link, mode=lib.GBA_SIO_MULTI):
self._sio.add(mode)
lib.GBASIOSetDriver(ffi.addressof(self._native.sio), link._native, mode)

View File

@ -424,7 +424,7 @@ bool CoreController::attachDolphin(const Address& address) {
}
if (GBASIODolphinConnect(&m_dolphin, &address, 0, 0)) {
GBA* gba = static_cast<GBA*>(m_threadContext.core->board);
GBASIOSetDriver(&gba->sio, &m_dolphin.d, SIO_JOYBUS);
GBASIOSetDriver(&gba->sio, &m_dolphin.d, GBA_SIO_JOYBUS);
return true;
}
return false;
@ -433,7 +433,7 @@ bool CoreController::attachDolphin(const Address& address) {
void CoreController::detachDolphin() {
if (platform() == mPLATFORM_GBA) {
GBA* gba = static_cast<GBA*>(m_threadContext.core->board);
GBASIOSetDriver(&gba->sio, nullptr, SIO_JOYBUS);
GBASIOSetDriver(&gba->sio, nullptr, GBA_SIO_JOYBUS);
}
GBASIODolphinDestroy(&m_dolphin);
}

View File

@ -92,7 +92,7 @@ MultiplayerController::MultiplayerController() {
if (!id) {
for (int i = 1; i < controller->m_players.count(); ++i) {
player = controller->player(i);
if (player->node.gba->d.p->mode > SIO_MULTI) {
if (player->node.gba->d.p->mode > GBA_SIO_MULTI) {
player->controller->setSync(true);
continue;
}
@ -254,8 +254,8 @@ bool MultiplayerController::attachGame(CoreController* controller) {
GBASIOLockstepAttachNode(&m_gbaLockstep, node);
player.node.gba = node;
GBASIOSetDriver(&gba->sio, &node->d, SIO_MULTI);
GBASIOSetDriver(&gba->sio, &node->d, SIO_NORMAL_32);
GBASIOSetDriver(&gba->sio, &node->d, GBA_SIO_MULTI);
GBASIOSetDriver(&gba->sio, &node->d, GBA_SIO_NORMAL_32);
break;
}
#endif
@ -342,8 +342,8 @@ void MultiplayerController::detachGame(CoreController* controller) {
case mPLATFORM_GBA: {
GBA* gba = static_cast<GBA*>(thread->core->board);
GBASIOLockstepNode* node = reinterpret_cast<GBASIOLockstepNode*>(gba->sio.drivers.multiplayer);
GBASIOSetDriver(&gba->sio, nullptr, SIO_MULTI);
GBASIOSetDriver(&gba->sio, nullptr, SIO_NORMAL_32);
GBASIOSetDriver(&gba->sio, nullptr, GBA_SIO_MULTI);
GBASIOSetDriver(&gba->sio, nullptr, GBA_SIO_NORMAL_32);
if (node) {
GBASIOLockstepDetachNode(&m_gbaLockstep, node);
delete node;