diff --git a/src/platform/python/mgba/gba.py b/src/platform/python/mgba/gba.py index 109de4d50..0c249cec5 100644 --- a/src/platform/python/mgba/gba.py +++ b/src/platform/python/mgba/gba.py @@ -52,72 +52,6 @@ class GBA(Core): super(GBA, self)._load() self.memory = GBAMemory(self._core, self._native.memory.romSize) - def attach_sio(self, link, mode=lib.GBA_SIO_MULTI): - self._sio.add(mode) - lib.GBASIOSetDriver(ffi.addressof(self._native.sio), link._native, mode) - - def __del__(self): - for mode in self._sio: - lib.GBASIOSetDriver(ffi.addressof(self._native.sio), ffi.NULL, mode) - - -create_callback("GBASIOPythonDriver", "init") -create_callback("GBASIOPythonDriver", "deinit") -create_callback("GBASIOPythonDriver", "load") -create_callback("GBASIOPythonDriver", "unload") -create_callback("GBASIOPythonDriver", "writeRegister") - - -class GBASIODriver(object): - def __init__(self): - super(GBASIODriver, self).__init__() - - self._handle = ffi.new_handle(self) - self._native = ffi.gc(lib.GBASIOPythonDriverCreate(self._handle), lib.free) - - def init(self): - return True - - def deinit(self): - pass - - def load(self): - return True - - def unload(self): - return True - - def write_register(self, address, value): - return value - - -class GBASIOJOYDriver(GBASIODriver): - RESET = lib.JOY_RESET - POLL = lib.JOY_POLL - TRANS = lib.JOY_TRANS - RECV = lib.JOY_RECV - - def __init__(self): - super(GBASIOJOYDriver, self).__init__() - - self._native = ffi.gc(lib.GBASIOJOYPythonDriverCreate(self._handle), lib.free) - - def send_command(self, cmd, data): - buffer = ffi.new('uint8_t[5]') - try: - buffer[0] = data[0] - buffer[1] = data[1] - buffer[2] = data[2] - buffer[3] = data[3] - buffer[4] = data[4] - except IndexError: - pass - - outlen = lib.GBASIOJOYSendCommand(self._native, cmd, buffer) - if outlen > 0 and outlen <= 5: - return bytes(buffer[0:outlen]) - return None - class GBAMemory(Memory): def __init__(self, core, romSize=lib.SIZE_CART0): diff --git a/src/platform/python/sio.c b/src/platform/python/sio.c deleted file mode 100644 index fbb407831..000000000 --- a/src/platform/python/sio.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (c) 2013-2017 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include - -#define CREATE_SHIM(PLAT, NAME, RETURN) \ - RETURN _py ## PLAT ## SIOPythonDriver ## NAME (void* driver); \ - static RETURN _py ## PLAT ## SIOPythonDriver ## NAME ## Shim(struct PLAT ## SIODriver* driver) { \ - struct PLAT ## SIODriver* py = (struct PLAT ## SIODriver*) driver; \ - return _py ## PLAT ## SIOPythonDriver ## NAME(py); \ - } - -#define CREATE_SHIM_ARGS(PLAT, NAME, RETURN, TYPES, ...) \ - RETURN _py ## PLAT ## SIOPythonDriver ## NAME TYPES; \ - static RETURN _py ## PLAT ## SIOPythonDriver ## NAME ## Shim TYPES { \ - struct PLAT ## SIODriver* py = (struct PLAT ## SIODriver*) driver; \ - return _py ## PLAT ## SIOPythonDriver ## NAME(py, __VA_ARGS__); \ - } - -#ifdef M_CORE_GBA - -#include - -struct GBASIOPythonDriver { - struct GBASIODriver d; - void* pyobj; -}; - -CREATE_SHIM(GBA, Init, bool); -CREATE_SHIM(GBA, Deinit, void); -CREATE_SHIM(GBA, Load, bool); -CREATE_SHIM(GBA, Unload, bool); -CREATE_SHIM_ARGS(GBA, WriteRegister, uint16_t, (struct GBASIODriver* driver, uint32_t address, uint16_t value), address, value); - -struct GBASIODriver* GBASIOPythonDriverCreate(void* pyobj) { - struct GBASIOPythonDriver* driver = malloc(sizeof(*driver)); - driver->d.init = _pyGBASIOPythonDriverInitShim; - driver->d.deinit = _pyGBASIOPythonDriverDeinitShim; - driver->d.load = _pyGBASIOPythonDriverLoadShim; - driver->d.unload = _pyGBASIOPythonDriverUnloadShim; - driver->d.writeRegister = _pyGBASIOPythonDriverWriteRegisterShim; - - driver->pyobj = pyobj; - return &driver->d; -} - -struct GBASIODriver* GBASIOJOYPythonDriverCreate(void* pyobj) { - struct GBASIOPythonDriver* driver = malloc(sizeof(*driver)); - GBASIOJOYCreate(&driver->d); - driver->d.init = _pyGBASIOPythonDriverInitShim; - driver->d.deinit = _pyGBASIOPythonDriverDeinitShim; - driver->d.load = _pyGBASIOPythonDriverLoadShim; - driver->d.unload = _pyGBASIOPythonDriverUnloadShim; - - driver->pyobj = pyobj; - return &driver->d; -} - -#endif - -#ifdef M_CORE_GB - -#include - -struct GBSIOPythonDriver { - struct GBSIODriver d; - void* pyobj; -}; - -CREATE_SHIM(GB, Init, bool); -CREATE_SHIM(GB, Deinit, void); -CREATE_SHIM_ARGS(GB, WriteSB, void, (struct GBSIODriver* driver, uint8_t value), value); -CREATE_SHIM_ARGS(GB, WriteSC, uint8_t, (struct GBSIODriver* driver, uint8_t value), value); - -struct GBSIODriver* GBSIOPythonDriverCreate(void* pyobj) { - struct GBSIOPythonDriver* driver = malloc(sizeof(*driver)); - driver->d.init = _pyGBSIOPythonDriverInitShim; - driver->d.deinit = _pyGBSIOPythonDriverDeinitShim; - driver->d.writeSB = _pyGBSIOPythonDriverWriteSBShim; - driver->d.writeSC = _pyGBSIOPythonDriverWriteSCShim; - - driver->pyobj = pyobj; - return &driver->d; -} - -#endif diff --git a/src/platform/python/sio.h b/src/platform/python/sio.h deleted file mode 100644 index 23b059427..000000000 --- a/src/platform/python/sio.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) 2013-2017 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifdef M_CORE_GBA - -#include - -struct GBASIOPythonDriver { - struct GBASIODriver d; - void* pyobj; -}; - -struct GBASIODriver* GBASIOPythonDriverCreate(void* pyobj); -struct GBASIODriver* GBASIOJOYPythonDriverCreate(void* pyobj); - -PYEXPORT bool _pyGBASIOPythonDriverInit(void* driver); -PYEXPORT void _pyGBASIOPythonDriverDeinit(void* driver); -PYEXPORT bool _pyGBASIOPythonDriverLoad(void* driver); -PYEXPORT bool _pyGBASIOPythonDriverUnload(void* driver); -PYEXPORT uint16_t _pyGBASIOPythonDriverWriteRegister(void* driver, uint32_t address, uint16_t value); - -#endif - -#ifdef M_CORE_GB - -#include - -struct GBSIOPythonDriver { - struct GBSIODriver d; - void* pyobj; -}; - -struct GBSIODriver* GBSIOPythonDriverCreate(void* pyobj); - -PYEXPORT bool _pyGBSIOPythonDriverInit(void* driver); -PYEXPORT void _pyGBSIOPythonDriverDeinit(void* driver); -PYEXPORT void _pyGBSIOPythonDriverWriteSB(void* driver, uint8_t value); -PYEXPORT uint8_t _pyGBSIOPythonDriverWriteSC(void* driver, uint8_t value); - -#endif