From 572eb40d420984f477269200dd7988eba09552bd Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 26 Oct 2016 22:44:42 -0700 Subject: [PATCH] Python: Add key functions --- src/platform/python/_builder.h | 2 ++ src/platform/python/_builder.py | 1 + src/platform/python/mgba/core.py | 18 ++++++++++++++++++ src/platform/python/mgba/gb.py | 9 +++++++++ src/platform/python/mgba/gba.py | 11 +++++++++++ 5 files changed, 41 insertions(+) diff --git a/src/platform/python/_builder.h b/src/platform/python/_builder.h index 97539a639..bb5f8b75c 100644 --- a/src/platform/python/_builder.h +++ b/src/platform/python/_builder.h @@ -32,10 +32,12 @@ void free(void*); #ifdef M_CORE_GBA #include "arm/arm.h" #include "gba/gba.h" +#include "gba/input.h" #include "gba/renderers/tile-cache.h" #endif #ifdef M_CORE_GB #include "lr35902/lr35902.h" #include "gb/gb.h" +#include "gba/input.h" #include "gb/renderers/tile-cache.h" #endif diff --git a/src/platform/python/_builder.py b/src/platform/python/_builder.py index 666aefe33..31cdade94 100644 --- a/src/platform/python/_builder.py +++ b/src/platform/python/_builder.py @@ -13,6 +13,7 @@ ffi.set_source("mgba._pylib", """ #include "core/tile-cache.h" #include "arm/arm.h" #include "gba/gba.h" +#include "gba/input.h" #include "gba/renderers/tile-cache.h" #include "lr35902/lr35902.h" #include "gb/gb.h" diff --git a/src/platform/python/mgba/core.py b/src/platform/python/mgba/core.py index fe1a1f1f2..ad051e33d 100644 --- a/src/platform/python/mgba/core.py +++ b/src/platform/python/mgba/core.py @@ -102,6 +102,24 @@ class Core(object): def step(self): self._core.step(self._core) + @staticmethod + def _keysToInt(*args, **kwargs): + keys = 0 + if 'raw' in kwargs: + keys = kwargs['raw'] + for key in args: + keys |= 1 << key + return keys + + def setKeys(self, *args, **kwargs): + self._core.setKeys(self._core, self._keysToInt(*args, **kwargs)) + + def addKeys(self, *args, **kwargs): + self._core.addKeys(self._core, self._keysToInt(*args, **kwargs)) + + def clearKeys(self, *args, **kwargs): + self._core.clearKeys(self._core, self._keysToInt(*args, **kwargs)) + def frameCounter(self): return self._core.frameCounter(self._core) diff --git a/src/platform/python/mgba/gb.py b/src/platform/python/mgba/gb.py index 33dbc0aae..d8d549cdd 100644 --- a/src/platform/python/mgba/gb.py +++ b/src/platform/python/mgba/gb.py @@ -9,6 +9,15 @@ from .core import Core from .tile import Sprite class GB(Core): + KEY_A = lib.GBA_KEY_A + KEY_B = lib.GBA_KEY_B + KEY_SELECT = lib.GBA_KEY_SELECT + KEY_START = lib.GBA_KEY_START + KEY_DOWN = lib.GBA_KEY_DOWN + KEY_UP = lib.GBA_KEY_UP + KEY_LEFT = lib.GBA_KEY_LEFT + KEY_RIGHT = lib.GBA_KEY_RIGHT + def __init__(self, native): super(GB, self).__init__(native) self._native = ffi.cast("struct GB*", native.board) diff --git a/src/platform/python/mgba/gba.py b/src/platform/python/mgba/gba.py index 6ad761f00..7a664d5e9 100644 --- a/src/platform/python/mgba/gba.py +++ b/src/platform/python/mgba/gba.py @@ -9,6 +9,17 @@ from .core import Core from .tile import Sprite class GBA(Core): + KEY_A = lib.GBA_KEY_A + KEY_B = lib.GBA_KEY_B + KEY_SELECT = lib.GBA_KEY_SELECT + KEY_START = lib.GBA_KEY_START + KEY_DOWN = lib.GBA_KEY_DOWN + KEY_UP = lib.GBA_KEY_UP + KEY_LEFT = lib.GBA_KEY_LEFT + KEY_RIGHT = lib.GBA_KEY_RIGHT + KEY_L = lib.GBA_KEY_L + KEY_R = lib.GBA_KEY_R + def __init__(self, native): super(GBA, self).__init__(native) self._native = ffi.cast("struct GBA*", native.board)