src/platform/python/mgba/lr35902.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 LR35902Core:
9 def __init__(self, native):
10 self._native = ffi.cast("struct LR35902Core*", native)
11
12 def __getattr__(self, key):
13 if key == 'a':
14 return self._native.a
15 if key == 'b':
16 return self._native.b
17 if key == 'c':
18 return self._native.c
19 if key == 'd':
20 return self._native.d
21 if key == 'e':
22 return self._native.e
23 if key == 'f':
24 return self._native.f
25 if key == 'h':
26 return self._native.h
27 if key == 'l':
28 return self._native.l
29 if key == 'sp':
30 return self._native.sp
31 if key == 'pc':
32 return self._native.pc
33 raise AttributeError()
34
35 def __setattr__(self, key, value):
36 if key == 'a':
37 self._native.a = value & 0xF0
38 if key == 'b':
39 self._native.b = value
40 if key == 'c':
41 self._native.c = value
42 if key == 'd':
43 self._native.d = value
44 if key == 'e':
45 self._native.e = value
46 if key == 'f':
47 self._native.f = value
48 if key == 'h':
49 self._native.h = value
50 if key == 'l':
51 self._native.l = value
52 if key == 'sp':
53 self._native.sp = value
54 else:
55 self.__dict__[key] = value