-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollers.py
65 lines (40 loc) · 1.12 KB
/
controllers.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
class buttons:
avaible = {
"RIGHT":(0x01, 0x10),
"LEFT" : (0x02, 0x10),
"UP" : (0x04, 0x10),
"DOWN" : (0x08, 0x10),
"A" : (0x01, 0x20),
"B" : (0x02, 0x20),
"SELECT" : (0x04, 0x20),
"START" : (0x08, 0x20)
}
line = 0
mask = 0
def __init__(self):
pass
def getMask(self):
return self.mask
def getLine(self):
return self.line
class joycontrollers:
def __init__(self, interruptManager):
self.interruptManager = interruptManager
self.activeButtons = {}
self.p1 = 0
self.buttonids = buttons()
def buttonPress(self, buttonID):
self.interruptManager.requestInterrupt(self.interruptManager.get("P10_13"))
self.activeButtons[buttonID] = self.buttonids.avaible[buttonID]
def buttonUnPress(self, buttonID):
self.activeButtons.pop(buttonID, None)
def setByte(self, address, value):
self.p1 = value & 0b00110000;
def getByte(self, address):
result = self.p1 | 0b00001111;
for buttonid, buttonvalue in self.activeButtons.items():
if ((buttonvalue[1] & self.p1) == 0):
result &= 0xff & ~buttonvalue[0]
#print(result)
#print("happy")
return result