-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
keypad.lua
executable file
·97 lines (87 loc) · 2.39 KB
/
keypad.lua
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
89
90
91
92
93
94
95
96
97
local keypad = {}
keypad.keys_digitran = {
layout = {
[0]=0x0, 0x1, 0x2, 0x3,
0x4, 0x5, 0x6, 0x7,
0x8, 0x9, 0xA, 0xB,
0xC, 0xD, 0xE, 0xF
},
lines = {
-- The most significant nibble is inverted here from what the
-- actual DREAM keypad sends, but when the PIA A peripheral pins
-- send output to the keypad in the decoding routine, some
-- pullups in the keypad invert the signal for decoding the
-- most significant nibble.
[0]=0xEE, 0xED, 0xEB, 0xE7,
0xDE, 0xDD, 0xDB, 0xD7,
0xBE, 0xBD, 0xBB, 0xB7,
0x7E, 0x7D, 0x7B, 0x77
}
}
keypad.keys_original = {
layout = {
[0]=0xC, 0xD, 0xE, 0xF,
0x8, 0x9, 0xA, 0xB,
0x4, 0x5, 0x6, 0x7,
0x0, 0x1, 0x2, 0x3
},
lines = {
[0]=0x7E, 0x7D, 0x7B, 0x77,
0xBE, 0xBD, 0xBB, 0xB7,
0xDE, 0xDD, 0xDB, 0xD7,
0xEE, 0xED, 0xEB, 0xE7
}
}
keypad.keys_cosmac = {
layout = {
[0]=0x1, 0x2, 0x3, 0xC,
0x4, 0x5, 0x6, 0xD,
0x7, 0x8, 0x9, 0xE,
0xA, 0x0, 0xB, 0xF
},
lines = {
[0]=0xED, 0xEB, 0xE7, 0x7E,
0xDE, 0xDD, 0xDB, 0x7D,
0xD7, 0xBE, 0xBD, 0x7B,
0xBB, 0xEE, 0xB7, 0x77
}
}
keypad.keys_qwerty = {
[0]="1", "2", "3", "4",
"q", "w", "e", "r",
"a", "s", "d", "f",
"z", "x", "c", "v"
}
keypad.key_mapping = {}
keypad.key_status = {}
keypad.button_status = {}
keypad.keys_dream = keypad.keys_digitran
for i = 0, 15 do
keypad.key_mapping[keypad.keys_qwerty[i]] = keypad.keys_dream.layout[i]
keypad.key_status[keypad.keys_dream.layout[i]] = false
end
function keypad:connect(pia_port)
self.pia = pia_port
self.pia.p = 0x0F
end
function keypad:keypressed(key, scancode)
local hexkey = self.key_mapping[scancode]
if hexkey then
self.key_status[hexkey] = true
self.pia.c1 = true
self.pia.p = self.keys_dream.lines[hexkey]
elseif scancode == "lshift" or scancode == "rshift" then
self.pia.c2 = true
end
end
function keypad:keyreleased(key, scancode)
local hexkey = self.key_mapping[scancode]
if hexkey then
self.key_status[hexkey] = false
self.pia.c1 = false
self.pia.p = 0x0F
elseif scancode == "lshift" or scancode == "rshift" then
self.pia.c2 = false
end
end
return keypad