forked from Q-Master/PyZX
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ports.py
88 lines (73 loc) · 2.65 KB
/
ports.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
76
77
78
79
80
81
82
83
84
85
86
87
88
from keyboard import Keyboard
class Ports:
def __init__(self, keyboard: Keyboard):
self.keyboard = keyboard
self.current_border = 0
self.PORTMAP = [
(0x0001, 0x00fe, 2, 2, 2, self.xInFE, self.xOutFE), # keyboard
# (0xc002, 0xfffd, 2, 2, 2, xInFFFD, xOutFFFD),
# (0xc002, 0xbffd, 2, 2, 2, None, xOutBFFD), # AYdataW
# (0x0320, 0xfadf, 2, 2, 2, xInFADF, None), # K-MOUSEturboB
# (0x0720, 0xfbdf, 2, 2, 2, xInFBDF, None), # K-MOUSE_X
# (0x0720, 0xffdf, 2, 2, 2, xInFFDF, None), # K-MOUSE_Y
(0x0021, 0x001f, 0, 2, 2, self.spIn1F, None), # kempston joystick
(0x0000, 0x0000, 0, 2, 2, self.spInFF, None), # all unknown ports is FF (nodos)
(0x0000, 0x0000, 2, 2, 2, self.spInFF, None)
]
def xInFE(self, port: int) -> int:
res = 0xff
k = self.keyboard.keyboard
if (port & 0x8000) == 0:
res &= k[0] # _B_SPC
if (port & 0x4000) == 0:
res &= k[1] # _H_ENT
if (port & 0x2000) == 0:
res &= k[2] # _Y_P
if (port & 0x1000) == 0:
res &= k[3] # _6_0
if (port & 0x0800) == 0:
res &= k[4] # _1_5
if (port & 0x0400) == 0:
res &= k[5] # _Q_T
if (port & 0x0200) == 0:
res &= k[6] # _A_G
if (port & 0x0100) == 0:
res &= k[7] # _CAPS_V
return res
def xOutFE(self, _port: int, value: int):
self.current_border = value & 0x07
@staticmethod
def xInFFFD(_port: int) -> int:
return 0xff
@staticmethod
def xOutFFFD(_port: int, _value: int):
return 0xff
@staticmethod
def xOutBFFD(_port: int, _value: int):
return 0xff
@staticmethod
def xInFADF(_port: int) -> int:
return 0xff
@staticmethod
def xInFBDF(_port: int) -> int:
return 0xff
@staticmethod
def xInFFDF(_port: int) -> int:
return 0xff
def spIn1F(self, _port: int) -> int:
return self.keyboard.joy[0]
@staticmethod
def spInFF(_port: int) -> int:
return 0xff
def in_port(self, portnum: int) -> int:
# print('port: ', portnum, type(portnum))
for mask, value, _, _, _, fin, _ in self.PORTMAP:
if portnum & mask == value & mask:
return fin(portnum) if fin else 0xff
return 0xff
def out_port(self, portnum: int, data: int):
for mask, value, _, _, _, _, fout in self.PORTMAP:
if portnum & mask == value & mask:
if fout:
fout(portnum, data)
break