mirror of https://github.com/mgba-emu/mgba.git
GBA SIO: Modify GBASIOTransferCycles to not require SIO struct
This commit is contained in:
parent
621eb4d425
commit
0b9cf1270c
|
@ -93,7 +93,7 @@ void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
|
||||||
void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
|
void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
|
||||||
uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value);
|
uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value);
|
||||||
|
|
||||||
int32_t GBASIOTransferCycles(struct GBASIO* sio);
|
int32_t GBASIOTransferCycles(enum GBASIOMode mode, uint16_t siocnt, int connected);
|
||||||
|
|
||||||
void GBASIOMultiplayerFinishTransfer(struct GBASIO* sio, uint16_t data[4], uint32_t cyclesLate);
|
void GBASIOMultiplayerFinishTransfer(struct GBASIO* sio, uint16_t data[4], uint32_t cyclesLate);
|
||||||
void GBASIONormal8FinishTransfer(struct GBASIO* sio, uint8_t data, uint32_t cyclesLate);
|
void GBASIONormal8FinishTransfer(struct GBASIO* sio, uint8_t data, uint32_t cyclesLate);
|
||||||
|
|
|
@ -228,8 +228,12 @@ static void _startTransfer(struct GBASIO* sio) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int connected = 0;
|
||||||
|
if (sio->activeDriver && sio->activeDriver->connectedDevices) {
|
||||||
|
connected = sio->activeDriver->connectedDevices(sio->activeDriver);
|
||||||
|
}
|
||||||
mTimingDeschedule(&sio->p->timing, &sio->completeEvent);
|
mTimingDeschedule(&sio->p->timing, &sio->completeEvent);
|
||||||
mTimingSchedule(&sio->p->timing, &sio->completeEvent, GBASIOTransferCycles(sio));
|
mTimingSchedule(&sio->p->timing, &sio->completeEvent, GBASIOTransferCycles(sio->mode, sio->siocnt, connected));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
|
void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
|
||||||
|
@ -429,26 +433,21 @@ uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t valu
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t GBASIOTransferCycles(struct GBASIO* sio) {
|
int32_t GBASIOTransferCycles(enum GBASIOMode mode, uint16_t siocnt, int connected) {
|
||||||
int connected = 0;
|
|
||||||
if (sio->activeDriver) {
|
|
||||||
connected = sio->activeDriver->connectedDevices(sio->activeDriver);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connected < 0 || connected >= MAX_GBAS) {
|
if (connected < 0 || connected >= MAX_GBAS) {
|
||||||
mLOG(GBA_SIO, ERROR, "SIO driver returned invalid device count %i", connected);
|
mLOG(GBA_SIO, ERROR, "Invalid device count %i", connected);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sio->mode) {
|
switch (mode) {
|
||||||
case GBA_SIO_MULTI:
|
case GBA_SIO_MULTI:
|
||||||
return GBASIOCyclesPerTransfer[GBASIOMultiplayerGetBaud(sio->siocnt)][connected];
|
return GBASIOCyclesPerTransfer[GBASIOMultiplayerGetBaud(siocnt)][connected];
|
||||||
case GBA_SIO_NORMAL_8:
|
case GBA_SIO_NORMAL_8:
|
||||||
return 8 * GBA_ARM7TDMI_FREQUENCY / ((GBASIONormalIsInternalSc(sio->siocnt) ? 2048 : 256) * 1024);
|
return 8 * GBA_ARM7TDMI_FREQUENCY / ((GBASIONormalIsInternalSc(siocnt) ? 2048 : 256) * 1024);
|
||||||
case GBA_SIO_NORMAL_32:
|
case GBA_SIO_NORMAL_32:
|
||||||
return 32 * GBA_ARM7TDMI_FREQUENCY / ((GBASIONormalIsInternalSc(sio->siocnt) ? 2048 : 256) * 1024);
|
return 32 * GBA_ARM7TDMI_FREQUENCY / ((GBASIONormalIsInternalSc(siocnt) ? 2048 : 256) * 1024);
|
||||||
default:
|
default:
|
||||||
mLOG(GBA_SIO, STUB, "No cycle count implemented for mode %s", _modeName(sio->mode));
|
mLOG(GBA_SIO, STUB, "No cycle count implemented for mode %s", _modeName(mode));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -248,7 +248,7 @@ static uint16_t GBASIOLockstepNodeMultiWriteSIOCNT(struct GBASIODriver* driver,
|
||||||
if (!node->id && attached > 1 && GBASIOMultiplayerIsReady(node->d.p->siocnt)) {
|
if (!node->id && attached > 1 && GBASIOMultiplayerIsReady(node->d.p->siocnt)) {
|
||||||
mLOG(GBA_SIO, DEBUG, "Lockstep %i: Transfer initiated", node->id);
|
mLOG(GBA_SIO, DEBUG, "Lockstep %i: Transfer initiated", node->id);
|
||||||
ATOMIC_STORE(node->p->d.transferActive, TRANSFER_STARTING);
|
ATOMIC_STORE(node->p->d.transferActive, TRANSFER_STARTING);
|
||||||
ATOMIC_STORE(node->p->d.transferCycles, GBASIOTransferCycles(node->d.p));
|
ATOMIC_STORE(node->p->d.transferCycles, GBASIOTransferCycles(node->d.p->mode, node->d.p->siocnt, attached));
|
||||||
|
|
||||||
if (mTimingIsScheduled(&driver->p->p->timing, &node->event)) {
|
if (mTimingIsScheduled(&driver->p->p->timing, &node->event)) {
|
||||||
node->eventDiff -= node->event.when - mTimingCurrentTime(&driver->p->p->timing);
|
node->eventDiff -= node->event.when - mTimingCurrentTime(&driver->p->p->timing);
|
||||||
|
@ -479,7 +479,7 @@ static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* user,
|
||||||
if (node->p->d.attached < 2) {
|
if (node->p->d.attached < 2) {
|
||||||
switch (node->mode) {
|
switch (node->mode) {
|
||||||
case GBA_SIO_MULTI:
|
case GBA_SIO_MULTI:
|
||||||
cycles = GBASIOTransferCycles(node->d.p);
|
cycles = GBASIOTransferCycles(node->d.p->mode, node->d.p->siocnt, node->p->d.attached);
|
||||||
break;
|
break;
|
||||||
case GBA_SIO_NORMAL_8:
|
case GBA_SIO_NORMAL_8:
|
||||||
case GBA_SIO_NORMAL_32:
|
case GBA_SIO_NORMAL_32:
|
||||||
|
@ -544,7 +544,7 @@ static uint16_t GBASIOLockstepNodeNormalWriteSIOCNT(struct GBASIODriver* driver,
|
||||||
if ((value & 0x0081) == 0x0081) {
|
if ((value & 0x0081) == 0x0081) {
|
||||||
if (!node->id) {
|
if (!node->id) {
|
||||||
// Frequency
|
// Frequency
|
||||||
int32_t cycles = GBASIOTransferCycles(node->d.p);
|
int32_t cycles = GBASIOTransferCycles(node->d.p->mode, node->d.p->siocnt, attached);
|
||||||
|
|
||||||
if (transferActive == TRANSFER_IDLE) {
|
if (transferActive == TRANSFER_IDLE) {
|
||||||
mLOG(GBA_SIO, DEBUG, "Lockstep %i: Transfer initiated", node->id);
|
mLOG(GBA_SIO, DEBUG, "Lockstep %i: Transfer initiated", node->id);
|
||||||
|
|
Loading…
Reference in New Issue