forked from jonbstanley/Tek405xEmulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TekKeyboard.js
201 lines (167 loc) · 6.52 KB
/
TekKeyboard.js
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
function TekKeyboard(hw, window) {
// *****************************
// *** ***
// *** HandleKeyboardEvent ***
// *** ***
// *****************************
var capsLockFlg = 1; // Always check on first entry
// Check Caps Lock state when flagged (see case 0x0014)
function HandleKeyboardEvent( i, bool, e ) {
if (capsLockFlg) {
hw.KBD_TTY_0 = e.getModifierState("CapsLock") ? 0 : 1; // Caps lock key status 0=on; 1 = off (negative logic sense)
capsLockFlg = 0; // Reset flag
}
//@@@ this.print('Key = '); this.printHex4( i ); this.print(' bool = '); this.print( bool ); this.print(' PC=0x'); this.printHex4( this.last_PC ); this.println('');
// Decide what action to take depending upon the key code in 'i'.
//
switch( i ) {
case 0x0010 : // Left or Right shift keys.
hw.KBD_SHIFT_0 = bool ? 0 : 1; // Shift key down = logical '0' (negative logic sense).
// Shift key up = logical '1'.
i = 0; break;
case 0x0011 : // Left or Right control keys.
hw.KBD_CTRL_0 = bool ? 0 : 1; // Control key down = logical '0' (negative logic sense).
// Control key up = logical '1'.
i = 0; break;
case 0x0014 : // Caps lock key.
// Caps lock key up = logical '1'.
capsLockFlg = 1; // Flag that caps lock pressed - state will be checked on next character received
i = 0; break;
// Letters.
case 0x0041 : // 'A'
case 0x0042 : // 'B'
case 0x0043 : // 'C'
case 0x0044 : // 'D'
case 0x0045 : // 'E'
case 0x0046 : // 'F'
case 0x0047 : // 'G'
case 0x0048 : // 'H'
case 0x0049 : // 'I'
case 0x004A : // 'J'
case 0x004B : // 'K'
case 0x004C : // 'L'
case 0x004D : // 'M'
case 0x004E : // 'N'
case 0x004F : // 'O'
case 0x0050 : // 'P'
case 0x0051 : // 'Q'
case 0x0052 : // 'R'
case 0x0053 : // 'S'
case 0x0054 : // 'T'
case 0x0055 : // 'U'
case 0x0056 : // 'V'
case 0x0057 : // 'W'
case 0x0058 : // 'X'
case 0x0059 : // 'Y'
case 0x005A : // 'Z'
break; // Nothing further to do.
// Numbers.
case 0x0030 : // '0'
case 0x0031 : // '1'
case 0x0032 : // '2'
case 0x0033 : // '3'
case 0x0034 : // '4'
case 0x0035 : // '5'
case 0x0036 : // '6'
case 0x0037 : // '7'
case 0x0038 : // '8'
case 0x0039 : // '9'
break; // Nothing further to do.
// Symbols.
case 0x0008 : // BK SPACE
case 0x0009 : // TAB
case 0x000A : // LF
case 0x000D : // RETURN
case 0x001B : // ESC
break; // Nothing further to do.
case 0x007C : i = 0x6A; break; // <f13> = PAGE
case 0x00DB : i = 0x5B; break; // '['
case 0x00DE : i = 0x3A; break; // ''' = ':'
case 0x00BD : i = 0x3D; break; // '-'
case 0x00DD : i = 0x5D; break; // ']'
case 0x00DF : i = 0x5E; break; // '^'
case 0x00C0 : i = 0x40; break; // '`' = '@'
case 0x00BA : i = 0x3B; break; // ';'
case 0x00BF : i = 0x3F; break; // '/'
case 0x002E : i = 0x5F; break; // <DELETE> = RUBOUT
case 0x00BC : i = 0x3C; break; // ','
case 0x00BE : i = 0x3E; break; // '.'
case 0x00DC : i = 0x5C; break; // '\'
case 0x007D : i = 0x6B; break; // <f14> = BREAK
case 0x0020 : i = 0x10; break; // ' ' = SPACE
// Numeric keypad.
case 0x0060 : i = 0x20; break; // '0'
case 0x006E : i = 0x2E; break; // '.'
case 0x0061 : i = 0x21; break; // '1'
case 0x0062 : i = 0x22; break; // '2'
case 0x0063 : i = 0x23; break; // '3'
case 0x0064 : i = 0x24; break; // '4'
case 0x0065 : i = 0x25; break; // '5'
case 0x0066 : i = 0x26; break; // '6'
case 0x0067 : i = 0x27; break; // '7'
case 0x0068 : i = 0x28; break; // '8'
case 0x0069 : i = 0x29; break; // '9'
// KC '(', 'E', ')' and '^' missing.
case 0x006F : i = 0x2F; break; // '/'
case 0x006A : i = 0x2A; break; // '*'
case 0x006D : i = 0x2D; break; // '-'
case 0x006B : i = 0x2B; break; // '+'
// Function keys. Note - potential error in Tek documentation 0x5X versus 0x6X
case 0x0070 : i = 0x60; break; // FK1
case 0x0071 : i = 0x61; break; // FK2
case 0x0072 : i = 0x62; break; // FK3
case 0x0073 : i = 0x63; break; // FK4
case 0x0074 : i = 0x64; break; // FK5
case 0x0075 : i = 0x65; break; // FK6
case 0x0076 : i = 0x66; break; // FK7
case 0x0077 : i = 0x67; break; // FK8
case 0x0078 : i = 0x68; break; // FK9
case 0x0079 : i = 0x69; break; // FK10
// Line editing keys.
case 0x0090 : i = 0x70; break; // EXPAND
case 0x0091 : i = 0x71; break; // BK SPACE
case 0x0092 : i = 0x72; break; // SPACE
case 0x0093 : i = 0x73; break; // <f15> = CLEAR
case 0x0094 : i = 0x74; break; // RECALL
// Tape control keys.
// case 0x0000 : i = 0x77; break; // AUTO LOAD
// case 0x0000 : i = 0x5C; break; // REWIND
// case 0x0000 : i = 0x5D; break; // MAKE COPY
// Program control keys.
case 0x007F : i = 0x75; break; // <f16> = AUTO NUM
case 0x0080 : i = 0x76; break; // <f17> = STEP PROG
default : i = 0; break; // Ignore the key press if I don't know what to map it to.
} // End switch.
//@@@ this.print( 'KBDDEBUG: i = 0x' ); this.printHex2( i ); this.print( ' bool = ' ); this.printHex2( bool ); this.println( '' );
// Check for a key press or key release.
if( bool ) {
hw.keyboardData('PRESS', i);
} else {
hw.keyboardData('RELEASE');
}
e.returnValue = false;
return false;
} // End of function HandleKeyboardEvent.
// *********************
// *** ***
// *** HandleEvent ***
// *** ***
// *********************
function handleEvent( e ) {
//console.log("You pressed: keyUniCode="+e.keyCode+",type="+e.type);
return HandleKeyboardEvent(e.keyCode, e.type=='keydown', e );
}
// ***************
// *** ***
// *** FcnKey ***
// *** ***
// ***************
this.FcnKey = function(code, press) {
// code - key code for keyboard key
// press - true for keydown, false for key up
var e = {keyCode:code, type:press ? "keydown" : "keyup", returnValue: false};
return handleEvent(e);
}
window.onkeydown = handleEvent;
window.onkeyup = handleEvent;
}