-
Notifications
You must be signed in to change notification settings - Fork 0
/
devices.py
75 lines (50 loc) · 1.37 KB
/
devices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class ShiftRegister:
def __init__(self):
self._register = 0x0000
self._offset = 0x0
def get_register(self):
return (self._register >> self._offset) & 0xff
def shift(self, val):
self._register = (self._register >> 8) | (val << 7)
def set_offset(self, val):
self._offset = (val ^ 0xff) & 0x07
class Controller:
def __init__(self):
self._p1_reg = 0x08
self._p2_reg = 0x00
def reset(self):
self._p1_reg = 0x08
self._p2_reg = 0x00
def get_p1(self):
return self._p1_reg
def get_p2(self):
return self._p2_reg
def start_p1(self):
self._p1_reg |= 0x04
def start_p2(self):
self._p1_reg |= 0x02
def mv_left_p1(self):
self._p1_reg |= 0x20
def mv_left_p2(self):
self._p2_reg |= 0x20
def mv_right_p1(self):
self._p1_reg |= 0x40
def mv_right_p2(self):
self._p2_reg |= 0x40
def shoot_p1(self):
self._p1_reg |= 0x10
def shoot_p2(self):
self._p2_reg |= 0x10
def add_credit(self):
self._p1_reg |= 0x01
class Display:
def __init__(self):
self.max_cycles = 2000000/60
def refresh(self, cycles):
if cycles >= self.max_cycles:
return 0xcf, 0xd7
devices = {
'shft_reg': ShiftRegister(),
'ctrl': Controller(),
'dspl': Display(),
}