mirror of https://github.com/mgba-emu/mgba.git
Python: Add key functions
This commit is contained in:
parent
adc45c9bdc
commit
572eb40d42
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue