all repos — mgba @ 3f05b12bc11d152c51516470b763939e05a842cb

mGBA Game Boy Advance Emulator

src/platform/python/mgba/arm.py (view raw)

 1# Copyright (c) 2013-2016 Jeffrey Pfau
 2#
 3# This Source Code Form is subject to the terms of the Mozilla Public
 4# License, v. 2.0. If a copy of the MPL was not distributed with this
 5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
 6from ._pylib import ffi, lib
 7
 8class _ARMRegisters:
 9    def __init__(self, cpu):
10        self._cpu = cpu
11
12    def __getitem__(self, r):
13        if r > lib.ARM_PC:
14            raise IndexError("Register out of range")
15        return self._cpu._native.gprs[r]
16
17    def __setitem__(self, r, value):
18        if r >= lib.ARM_PC:
19            raise IndexError("Register out of range")
20        self._cpu._native.gprs[r] = value
21
22class ARMCore:
23    def __init__(self, native):
24        self._native = ffi.cast("struct ARMCore*", native)
25        self.gprs = _ARMRegisters(self)
26        self.cpsr = self._native.cpsr
27        self.spsr = self._native.spsr
28