mirror of https://github.com/mgba-emu/mgba.git
Clarify some function names and add more essenital SIO architecture
This commit is contained in:
parent
e5ee1aa07f
commit
924c6cf5a6
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "gba-io.h"
|
#include "gba-io.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
static struct GBASIODriver* _lookupDriver(struct GBASIO* sio, enum GBASIOMode mode) {
|
static struct GBASIODriver* _lookupDriver(struct GBASIO* sio, enum GBASIOMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case SIO_MULTI:
|
case SIO_MULTI:
|
||||||
|
@ -22,12 +24,12 @@ static void _switchMode(struct GBASIO* sio) {
|
||||||
sio->mode = (enum GBASIOMode) (mode & 0xC);
|
sio->mode = (enum GBASIOMode) (mode & 0xC);
|
||||||
}
|
}
|
||||||
if (oldMode != mode) {
|
if (oldMode != mode) {
|
||||||
if (sio->activeDriver && sio->activeDriver->detach) {
|
if (sio->activeDriver && sio->activeDriver->unload) {
|
||||||
sio->activeDriver->detach(sio->activeDriver);
|
sio->activeDriver->unload(sio->activeDriver);
|
||||||
}
|
}
|
||||||
sio->activeDriver = _lookupDriver(sio, mode);
|
sio->activeDriver = _lookupDriver(sio, mode);
|
||||||
if (sio->activeDriver && sio->activeDriver->attach) {
|
if (sio->activeDriver && sio->activeDriver->load) {
|
||||||
sio->activeDriver->attach(sio->activeDriver);
|
sio->activeDriver->load(sio->activeDriver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +40,15 @@ void GBASIOInit(struct GBASIO* sio) {
|
||||||
_switchMode(sio);
|
_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) {
|
void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers) {
|
||||||
if (drivers->multiplayer) {
|
if (drivers->multiplayer) {
|
||||||
GBASIOSetDriver(sio, drivers->multiplayer, SIO_MULTI);
|
GBASIOSetDriver(sio, drivers->multiplayer, SIO_MULTI);
|
||||||
|
@ -61,20 +72,27 @@ void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (*driverLoc) {
|
if (*driverLoc) {
|
||||||
if ((*driverLoc)->detach) {
|
if ((*driverLoc)->unload) {
|
||||||
(*driverLoc)->detach(*driverLoc);
|
(*driverLoc)->unload(*driverLoc);
|
||||||
}
|
}
|
||||||
if ((*driverLoc)->deinit) {
|
if ((*driverLoc)->deinit) {
|
||||||
(*driverLoc)->deinit(*driverLoc);
|
(*driverLoc)->deinit(*driverLoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*driverLoc == sio->activeDriver) {
|
if (driver) {
|
||||||
sio->activeDriver = 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;
|
*driverLoc = driver;
|
||||||
if (driver && driver->init) {
|
|
||||||
driver->init(driver, sio);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value) {
|
void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value) {
|
||||||
|
@ -98,3 +116,10 @@ void GBASIOWriteSIOMLT_SEND(struct GBASIO* sio, uint16_t value) {
|
||||||
sio->activeDriver->writeRegister(sio->activeDriver, REG_SIOMLT_SEND, value);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -19,12 +19,14 @@ enum {
|
||||||
struct GBASIO;
|
struct GBASIO;
|
||||||
|
|
||||||
struct GBASIODriver {
|
struct GBASIODriver {
|
||||||
void (*init)(struct GBASIODriver* driver, struct GBASIO* sio);
|
struct GBASIO* p;
|
||||||
void (*deinit)(struct GBASIODriver* driver);
|
|
||||||
|
|
||||||
int (*attach)(struct GBASIODriver* driver);
|
void (*init)(struct GBASIODriver* driver);
|
||||||
int (*detach)(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);
|
void (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value);
|
||||||
|
int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GBASIODriverSet {
|
struct GBASIODriverSet {
|
||||||
|
@ -72,6 +74,8 @@ struct GBASIO {
|
||||||
};
|
};
|
||||||
|
|
||||||
void GBASIOInit(struct GBASIO* sio);
|
void GBASIOInit(struct GBASIO* sio);
|
||||||
|
void GBASIODeinit(struct GBASIO* sio);
|
||||||
|
|
||||||
void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
|
void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
|
||||||
void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
|
void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
|
||||||
|
|
||||||
|
@ -79,4 +83,6 @@ void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
|
||||||
void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
|
void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
|
||||||
void GBASIOWriteSIOMLT_SEND(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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue