Python: Add key functions

This commit is contained in:
Jeffrey Pfau 2016-10-26 22:44:42 -07:00
parent adc45c9bdc
commit 572eb40d42
5 changed files with 41 additions and 0 deletions

View File

@ -32,10 +32,12 @@ void free(void*);
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
#include "arm/arm.h" #include "arm/arm.h"
#include "gba/gba.h" #include "gba/gba.h"
#include "gba/input.h"
#include "gba/renderers/tile-cache.h" #include "gba/renderers/tile-cache.h"
#endif #endif
#ifdef M_CORE_GB #ifdef M_CORE_GB
#include "lr35902/lr35902.h" #include "lr35902/lr35902.h"
#include "gb/gb.h" #include "gb/gb.h"
#include "gba/input.h"
#include "gb/renderers/tile-cache.h" #include "gb/renderers/tile-cache.h"
#endif #endif

View File

@ -13,6 +13,7 @@ ffi.set_source("mgba._pylib", """
#include "core/tile-cache.h" #include "core/tile-cache.h"
#include "arm/arm.h" #include "arm/arm.h"
#include "gba/gba.h" #include "gba/gba.h"
#include "gba/input.h"
#include "gba/renderers/tile-cache.h" #include "gba/renderers/tile-cache.h"
#include "lr35902/lr35902.h" #include "lr35902/lr35902.h"
#include "gb/gb.h" #include "gb/gb.h"

View File

@ -102,6 +102,24 @@ class Core(object):
def step(self): def step(self):
self._core.step(self._core) 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): def frameCounter(self):
return self._core.frameCounter(self._core) return self._core.frameCounter(self._core)

View File

@ -9,6 +9,15 @@ from .core import Core
from .tile import Sprite from .tile import Sprite
class GB(Core): 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): def __init__(self, native):
super(GB, self).__init__(native) super(GB, self).__init__(native)
self._native = ffi.cast("struct GB*", native.board) self._native = ffi.cast("struct GB*", native.board)

View File

@ -9,6 +9,17 @@ from .core import Core
from .tile import Sprite from .tile import Sprite
class GBA(Core): 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): def __init__(self, native):
super(GBA, self).__init__(native) super(GBA, self).__init__(native)
self._native = ffi.cast("struct GBA*", native.board) self._native = ffi.cast("struct GBA*", native.board)