diff --git a/src/gba/gba-sio.c b/src/gba/gba-sio.c index e320169ba..a5f917000 100644 --- a/src/gba/gba-sio.c +++ b/src/gba/gba-sio.c @@ -83,9 +83,13 @@ void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASI driver->p = sio; if (driver->init) { - driver->init(driver); + if (!driver->init(driver)) { + driver->deinit(driver); + GBALog(sio->p, GBA_LOG_ERROR, "Could not initialize SIO driver"); + return; + } } - if (*driverLoc == sio->activeDriver) { + if (*driverLoc && *driverLoc == sio->activeDriver) { sio->activeDriver = driver; if ((*driverLoc)->load) { (*driverLoc)->load(*driverLoc); diff --git a/src/gba/gba-sio.h b/src/gba/gba-sio.h index 9e1fed346..6ada65f9c 100644 --- a/src/gba/gba-sio.h +++ b/src/gba/gba-sio.h @@ -21,11 +21,11 @@ struct GBASIO; struct GBASIODriver { struct GBASIO* p; - void (*init)(struct GBASIODriver* driver); + int (*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); + int (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles); };