src/platform/python/mgba/arm.py (view raw)
1from _pylib import ffi, lib
2
3class _ARMRegisters:
4 def __init__(self, cpu):
5 self._cpu = cpu
6
7 def __getitem__(self, r):
8 if r > lib.ARM_PC:
9 raise IndexError("Register out of range")
10 return self._cpu._native.gprs[r]
11
12 def __setitem__(self, r, value):
13 if r >= lib.ARM_PC:
14 raise IndexError("Register out of range")
15 self._cpu._native.gprs[r] = value
16
17class ARMCore:
18 def __init__(self, native):
19 self._native = ffi.cast("struct ARMCore*", native)
20 self.gprs = _ARMRegisters(self)
21 self.cpsr = self._native.cpsr
22 self.spsr = self._native.spsr
23