Clarify some function names and add more essenital SIO architecture
Jeffrey Pfau jeffrey@endrift.com
Wed, 05 Feb 2014 01:03:34 -0800
2 files changed,
46 insertions(+),
15 deletions(-)
M
src/gba/gba-sio.c
→
src/gba/gba-sio.c
@@ -2,6 +2,8 @@ #include "gba-sio.h"
#include "gba-io.h" +#include <limits.h> + static struct GBASIODriver* _lookupDriver(struct GBASIO* sio, enum GBASIOMode mode) { switch (mode) { case SIO_MULTI:@@ -22,12 +24,12 @@ } else {
sio->mode = (enum GBASIOMode) (mode & 0xC); } if (oldMode != mode) { - if (sio->activeDriver && sio->activeDriver->detach) { - sio->activeDriver->detach(sio->activeDriver); + if (sio->activeDriver && sio->activeDriver->unload) { + sio->activeDriver->unload(sio->activeDriver); } sio->activeDriver = _lookupDriver(sio, mode); - if (sio->activeDriver && sio->activeDriver->attach) { - sio->activeDriver->attach(sio->activeDriver); + if (sio->activeDriver && sio->activeDriver->load) { + sio->activeDriver->load(sio->activeDriver); } } }@@ -38,6 +40,15 @@ sio->siocnt = 0;
_switchMode(sio); } +void GBASIODeinit(struct GBASIO* sio) { + if (sio->drivers.multiplayer && sio->drivers.multiplayer->deinit) { + sio->drivers.multiplayer->deinit(sio->drivers.multiplayer); + } + if (sio->drivers.joybus && sio->drivers.joybus->deinit) { + sio->drivers.joybus->deinit(sio->drivers.joybus); + } +} + void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers) { if (drivers->multiplayer) { GBASIOSetDriver(sio, drivers->multiplayer, SIO_MULTI);@@ -61,20 +72,27 @@ GBALog(sio->p, GBA_LOG_ERROR, "Setting an unsupported SIO driver: %x", mode);
return; } if (*driverLoc) { - if ((*driverLoc)->detach) { - (*driverLoc)->detach(*driverLoc); + if ((*driverLoc)->unload) { + (*driverLoc)->unload(*driverLoc); } if ((*driverLoc)->deinit) { (*driverLoc)->deinit(*driverLoc); } } - if (*driverLoc == sio->activeDriver) { - sio->activeDriver = driver; + if (driver) { + driver->p = sio; + + if (driver->init) { + driver->init(driver); + } + if (*driverLoc == sio->activeDriver) { + sio->activeDriver = driver; + if ((*driverLoc)->load) { + (*driverLoc)->load(*driverLoc); + } + } } *driverLoc = driver; - if (driver && driver->init) { - driver->init(driver, sio); - } } void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value) {@@ -98,3 +116,10 @@ if (sio->activeDriver && sio->activeDriver->writeRegister) {
sio->activeDriver->writeRegister(sio->activeDriver, REG_SIOMLT_SEND, value); } } + +int32_t GBASIOProcessEvents(struct GBASIO* sio, int32_t cycles) { + if (sio->activeDriver && sio->activeDriver->processEvents) { + return sio->activeDriver->processEvents(sio->activeDriver, cycles); + } + return INT_MAX; +}
M
src/gba/gba-sio.h
→
src/gba/gba-sio.h
@@ -19,12 +19,14 @@
struct GBASIO; struct GBASIODriver { - void (*init)(struct GBASIODriver* driver, struct GBASIO* sio); - void (*deinit)(struct GBASIODriver* driver); + struct GBASIO* p; - int (*attach)(struct GBASIODriver* driver); - int (*detach)(struct GBASIODriver* driver); + void (*init)(struct GBASIODriver* driver); + void (*deinit)(struct GBASIODriver* driver); + int (*load)(struct GBASIODriver* driver); + int (*unload)(struct GBASIODriver* driver); void (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); + int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles); }; struct GBASIODriverSet {@@ -72,11 +74,15 @@ };
}; void GBASIOInit(struct GBASIO* sio); +void GBASIODeinit(struct GBASIO* sio); + void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers); void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode); void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value); void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value); void GBASIOWriteSIOMLT_SEND(struct GBASIO* sio, uint16_t value); + +int32_t GBASIOProcessEvents(struct GBASIO* sio, int32_t cycles); #endif