all repos — mgba @ 6f591996a8307bde8d424ab37a0db67956097187

mGBA Game Boy Advance Emulator

Python: Add hook preventing functions that need resets from being called
Jeffrey Pfau jeffrey@endrift.com
Sun, 06 Nov 2016 21:23:18 -0800
commit

6f591996a8307bde8d424ab37a0db67956097187

parent

3310210dc7b7ea79f711dc0e41076c2bf4589c9d

3 files changed, 17 insertions(+), 2 deletions(-)

jump to
M src/platform/python/mgba/core.pysrc/platform/python/mgba/core.py

@@ -31,9 +31,17 @@ if not core or not core.loadROM(vf):

return None return core +def needsReset(f): + def wrapper(self, *args, **kwargs): + if not self._wasReset: + raise RuntimeError("Core must be reset first") + return f(self, *args, **kwargs) + return wrapper + class Core(object): def __init__(self, native): self._core = native + self._wasReset = False @cached_property def tiles(self):

@@ -92,13 +100,17 @@ self._core.setVideoBuffer(self._core, image.buffer, image.stride)

def reset(self): self._core.reset(self._core) + self._wasReset = True + @needsReset def runFrame(self): self._core.runFrame(self._core) + @needsReset def runLoop(self): self._core.runLoop(self._core) + @needsReset def step(self): self._core.step(self._core)

@@ -120,6 +132,7 @@

def clearKeys(self, *args, **kwargs): self._core.clearKeys(self._core, self._keysToInt(*args, **kwargs)) + @needsReset def frameCounter(self): return self._core.frameCounter(self._core)
M src/platform/python/mgba/gb.pysrc/platform/python/mgba/gb.py

@@ -5,7 +5,7 @@ # 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/. from ._pylib import ffi, lib from .lr35902 import LR35902Core -from .core import Core +from .core import Core, needsReset from .memory import Memory from .tile import Sprite

@@ -25,6 +25,7 @@ self._native = ffi.cast("struct GB*", native.board)

self.sprites = GBObjs(self) self.cpu = LR35902Core(self._core.cpu) + @needsReset def _initTileCache(self, cache): lib.GBVideoTileCacheInit(cache) lib.GBVideoTileCacheAssociate(cache, ffi.addressof(self._native.video))
M src/platform/python/mgba/gba.pysrc/platform/python/mgba/gba.py

@@ -5,7 +5,7 @@ # 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/. from ._pylib import ffi, lib from .arm import ARMCore -from .core import Core +from .core import Core, needsReset from .tile import Sprite from .memory import Memory

@@ -28,6 +28,7 @@ self.sprites = GBAObjs(self)

self.cpu = ARMCore(self._core.cpu) self.memory = GBAMemory(self._core) + @needsReset def _initTileCache(self, cache): lib.GBAVideoTileCacheInit(cache) lib.GBAVideoTileCacheAssociate(cache, ffi.addressof(self._native.video))