-
Notifications
You must be signed in to change notification settings - Fork 1
/
KMINPUT.PAS
385 lines (334 loc) · 9.01 KB
/
KMINPUT.PAS
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
{ MIT License
Copyright (c) 2020 Viacheslav Komenda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. }
{$A+,I-,S-,R-,D+,L+,Q-,F-,G-,O-,B-}
UNIT KMInput;
INTERFACE
{ --- Keyboard ------------------------------------------------------ }
CONST
SCAN_ESC = $01;
SCAN_UP = $48;
SCAN_DOWN = $50;
SCAN_LEFT = $4B;
SCAN_RIGHT = $4D;
SCAN_CTRL_LEFT = $73;
SCAN_CTRL_RIGHT = $74;
SCAN_CTRL_UP = $8D;
SCAN_CTRL_DOWN = $91;
SCAN_INS = $52;
SCAN_HOME = $47;
SCAN_PGUP = $49;
SCAN_DEL = $53;
SCAN_END = $4F;
SCAN_PGDN = $51;
SCAN_CTRL_HOME = $77;
SCAN_CTRL_PGUP = $84;
SCAN_CTRL_END = $75;
SCAN_CTRL_PGDN = $76;
SCAN_F1 = $3B;
SCAN_F2 = $3C;
SCAN_F3 = $3D;
SCAN_F4 = $3E;
SCAN_F5 = $3F;
SCAN_F6 = $40;
SCAN_F7 = $41;
SCAN_F8 = $42;
SCAN_F9 = $43;
SCAN_F10 = $44;
SCAN_F11 = $85;
SCAN_F12 = $86;
SCAN_ALT_F1 = $68;
SCAN_ALT_F2 = $69;
SCAN_ALT_F3 = $6A;
SCAN_ALT_F4 = $6B;
SCAN_ALT_F5 = $6C;
SCAN_ALT_F6 = $6D;
SCAN_ALT_F7 = $6E;
SCAN_ALT_F8 = $6F;
SCAN_ALT_F9 = $70;
SCAN_ALT_F10 = $71;
SCAN_ALT_F11 = $8B;
SCAN_ALT_F12 = $8C;
SCAN_SHIFT_F1 = $54;
SCAN_SHIFT_F2 = $55;
SCAN_SHIFT_F3 = $56;
SCAN_SHIFT_F4 = $57;
SCAN_SHIFT_F5 = $58;
SCAN_SHIFT_F6 = $59;
SCAN_SHIFT_F7 = $5A;
SCAN_SHIFT_F8 = $5B;
SCAN_SHIFT_F9 = $5C;
SCAN_SHIFT_F10 = $5D;
SCAN_SHIFT_F11 = $87;
SCAN_SHIFT_F12 = $88;
SCAN_CTRL_F1 = $5E;
SCAN_CTRL_F2 = $5F;
SCAN_CTRL_F3 = $60;
SCAN_CTRL_F4 = $61;
SCAN_CTRL_F5 = $62;
SCAN_CTRL_F6 = $63;
SCAN_CTRL_F7 = $64;
SCAN_CTRL_F8 = $65;
SCAN_CTRL_F9 = $66;
SCAN_CTRL_F10 = $67;
SCAN_CTRL_F11 = $89;
SCAN_CTRL_F12 = $8A;
{ first row }
SCAN_TILDA = $29;
SCAN_1 = $02;
SCAN_2 = $03;
SCAN_3 = $04;
SCAN_4 = $05;
SCAN_5 = $06;
SCAN_6 = $07;
SCAN_7 = $08;
SCAN_8 = $09;
SCAN_9 = $0A;
SCAN_0 = $0B;
SCAN_MINUS = $0C;
SCAN_EQ = $0D;
SCAN_BS = $0E;
{ second row }
SCAN_TAB = $0F;
SCAN_Q = $10;
SCAN_W = $11;
SCAN_E = $12;
SCAN_R = $13;
SCAN_T = $14;
SCAN_Y = $15;
SCAN_U = $16;
SCAN_I = $17;
SCAN_O = $18;
SCAN_P = $19;
SCAN_LBRAKET = $1A;
SCAN_RBRAKET = $1B;
SCAN_BACK_SLASH = $2B;
{ third row }
SCAN_A = $1E;
SCAN_S = $1F;
SCAN_D = $20;
SCAN_F = $21;
SCAN_G = $22;
SCAN_H = $23;
SCAN_J = $24;
SCAN_K = $25;
SCAN_L = $26;
SCAN_DOTCOMA = $27;
SCAN_QUOTE = $28;
SCAN_ENTER = $1c;
{ fourth row }
SCAN_Z = $2C;
SCAN_X = $2D;
SCAN_C = $2E;
SCAN_V = $2F;
SCAN_B = $30;
SCAN_N = $31;
SCAN_M = $32;
SCAN_COMA = $33;
SCAN_DOT = $34;
SCAN_SLASH = $35;
SCAN_SPACE = $39;
SCAN_GREY_MINUS = $4A;
SCAN_GREY_PLUS = $4E;
FUNCTION kbd_getkey : WORD;
FUNCTION kbd_haskey : BOOLEAN;
FUNCTION kbd_getflags : BYTE;
PROCEDURE kbd_reset;
PROCEDURE kbd_fast;
FUNCTION is_ctrl(flags : BYTE) : BOOLEAN;
FUNCTION is_alt(flags : BYTE) : BOOLEAN;
FUNCTION is_shift(flags : BYTE) : BOOLEAN;
{ --- Mouse ------------------------------------------------------ }
CONST
MOUSE_B1 = 1;
MOUSE_B2 = 2;
PROCEDURE mouse_show;
PROCEDURE mouse_hide;
FUNCTION mouse_visible : BOOLEAN;
FUNCTION mouse_buttons : BYTE;
FUNCTION mouse_getx : INTEGER;
FUNCTION mouse_gety : INTEGER;
FUNCTION mouse_avail : BOOLEAN;
IMPLEMENTATION
VAR have_ext_kb : BOOLEAN;
have_122_kb : BOOLEAN;
mouse_present, mouse_state : BOOLEAN;
{ --- Keyboard ------------------------------------------------------ }
FUNCTION kbd_getkey : WORD;ASSEMBLER;
ASM
cmp BYTE ptr have_122_kb, 0
jne @h122
cmp BYTE ptr have_ext_kb, 0
jne @hext
xor ax, ax
jmp @end
@h122:
mov ah, $20
jmp @end
@hext:
mov ah, $10
@end:
int $16
END;
FUNCTION kbd_haskey : BOOLEAN;ASSEMBLER;
ASM
cmp BYTE ptr have_122_kb, 0
jne @h122
cmp BYTE ptr have_ext_kb, 0
jne @hext
mov ah, 1
jmp @end
@hext:
mov ah, $11
jmp @end
@h122:
mov ah, $21
@end:
int $16
mov cx, 0
jz @nokey
dec cx
@nokey:
mov ax, cx
END;
FUNCTION kbd_getflags : BYTE;ASSEMBLER;
ASM
cmp BYTE ptr have_122_kb, 0
jne @h122
cmp BYTE ptr have_ext_kb, 0
jne @hext
mov ah, 2
jmp @end
@hext:
mov ah, $12
jmp @end
@h122:
mov ah, $22
@end:
int $16
END;
FUNCTION is_ctrl(flags : BYTE) : BOOLEAN;ASSEMBLER;
ASM
mov al, flags
and al, $4
END;
FUNCTION is_alt(flags : BYTE) : BOOLEAN;ASSEMBLER;
ASM
mov al, flags
and al, $8
END;
FUNCTION is_shift(flags : BYTE) : BOOLEAN;ASSEMBLER;
ASM
mov al, flags
and al, $3
END;
PROCEDURE kbd_fast;ASSEMBLER;
ASM
mov ax, $0305
xor bx, bx
int $16
END;
PROCEDURE kbd_reset;
BEGIN
WHILE kbd_haskey DO kbd_getkey;
END;
{ --- Mouse ------------------------------------------------------ }
FUNCTION mouse_avail : BOOLEAN;ASSEMBLER;
ASM
mov al, mouse_present
END;
FUNCTION mouse_visible : BOOLEAN;ASSEMBLER;
ASM
mov al, mouse_present
or al, al
jz @nomouse
mov al, mouse_state
@nomouse:
END;
PROCEDURE mouse_show;ASSEMBLER;
ASM
mov al, mouse_present
or al, al
jz @nomouse
mov ax, 1
int $33
mov al, 1
mov mouse_state, al
@nomouse:
END;
PROCEDURE mouse_hide;ASSEMBLER;
ASM
mov al, mouse_present
or al, al
jz @nomouse
mov ax, 2
xor al, al
mov mouse_state, al
@nomouse:
END;
FUNCTION mouse_buttons : BYTE;ASSEMBLER;
ASM
mov al, mouse_present
or al, al
jz @nomouse
mov ax, 3
int $33
mov al, bl
and al, 3
@nomouse:
END;
FUNCTION mouse_getx : INTEGER;ASSEMBLER;
ASM
mov al, mouse_present
or al, al
jz @nomouse
mov ax, 3
int $33
mov ax, cx
mov cl ,3
shr ax, cl
@nomouse:
END;
FUNCTION mouse_gety : INTEGER;ASSEMBLER;
ASM
mov al, mouse_present
or al, al
jz @nomouse
mov ax, 3
int $33
mov ax, dx
mov cl ,3
shr ax, cl
@nomouse:
END;
BEGIN
ASM
{ check keyboard }
mov ax, $0900
int $16
push ax
and al, $20
mov have_ext_kb, al
pop ax
and al, $40
mov have_122_kb, al
{ check mouse }
xor ax, ax
int $33
mov mouse_present, al
END;
END.