all repos — mgba @ a0b794364f55cff7d62281fe525ce1a2edd96d41

mGBA Game Boy Advance Emulator

src/platform/python/lr35902.py (view raw)

 1from _pylib import ffi, lib
 2
 3class LR35902Core:
 4    def __init__(self, native):
 5        self._native = ffi.cast("struct LR35902Core*", native)
 6
 7    def __getattr__(self, key):
 8        if key == 'a':
 9            return self._native.a
10        if key == 'b':
11            return self._native.b
12        if key == 'c':
13            return self._native.c
14        if key == 'd':
15            return self._native.d
16        if key == 'e':
17            return self._native.e
18        if key == 'f':
19            return self._native.f
20        if key == 'h':
21            return self._native.h
22        if key == 'l':
23            return self._native.l
24        if key == 'sp':
25            return self._native.sp
26        if key == 'pc':
27            return self._native.pc
28        raise AttributeError()
29
30    def __setattr__(self, key, value):
31        if key == 'a':
32            self._native.a = value & 0xF0
33        if key == 'b':
34            self._native.b = value
35        if key == 'c':
36            self._native.c = value
37        if key == 'd':
38            self._native.d = value
39        if key == 'e':
40            self._native.e = value
41        if key == 'f':
42            self._native.f = value
43        if key == 'h':
44            self._native.h = value
45        if key == 'l':
46            self._native.l = value
47        if key == 'sp':
48            self._native.sp = value
49        else:
50            self.__dict__[key] = value