-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.py
35 lines (32 loc) · 1021 Bytes
/
Input.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
class Input:
def __init__(self):
self.OUT_PORT2 = 0
self.OUT_PORT3 = 0
self.OUT_PORT4LO = 0
self.OUT_PORT4HI = 0
self.OUT_PORT5 = 0
self.IN_PORT1 = 0
self.IN_PORT2 = 0
def OutPutPort(self, port, value):
if port == 2:
self.OUT_PORT2 = value
elif port == 3:
self.OUT_PORT3 = value
elif port == 4:
self.OUT_PORT4LO = self.OUT_PORT4HI
self.OUT_PORT4HI = value
elif port == 5:
self.OUT_PORT5 = value
def InPutPort(self, port):
result = 0
if port == 1:
result = self.IN_PORT1
self.IN_PORT1 &= 0xFE
elif port == 2:
result = (self.IN_PORT2 & 0x8F) | (self.IN_PORT2 & 0x70)
elif port == 3:
result = ((((self.OUT_PORT4HI << 8) | self.OUT_PORT4LO) << self.OUT_PORT2) >> 8) & 0xFF
if result > 255:
print("input error:", result)
exit(1)
return result