-
Notifications
You must be signed in to change notification settings - Fork 1
/
KEYBOARD.PAS
131 lines (100 loc) · 2.13 KB
/
KEYBOARD.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
{$G-,N-,E-}
{Added compiler directives for compiling TNDY Tracker}
{*******************************************************
keyboard unit
Version 1.2 - 18.03.2021
Author: Jan Knipperts
***********************************************************1
}
Unit Keyboard;
interface
var
key_code : byte;
key_ascii : char;
Procedure Get_Key;
Function Is_Key_pressed :boolean;
Procedure Wait_for_keypress;
Procedure Clear_Keypress;
Function R_Shift_State : Boolean;
function L_Shift_State : Boolean;
function CTRL_State : Boolean;
function ALT_State : Boolean;
function NUM_State : Boolean;
implementation
Procedure Clear_Keypress;
begin
memw[$40:$1A] := memw[$40:$1C]; {Clears Bios key buffer}
key_code := 0;
key_ascii := #0;
asm {Pre PC AT machines need an additional controler reset}
in al,61h
mov ah,al
or al,80h
out 61h,al
mov al,ah
out 61h,al
end;
end;
Procedure Get_Key;
{Gets last pressed key codes from Bios
Scan code and Ascii code}
assembler;
asm
xor ax,ax
int $16
mov key_code,ah
mov key_ascii,al
end;
Function Is_Key_Pressed :boolean;
assembler;
asm
xor ax,ax
mov ah,1
int 16h
mov al,0
je @Quit
mov al,1
@Quit:
end;
Procedure Wait_for_keypress;
begin
while is_key_pressed do get_key;
repeat until is_key_pressed;
while is_key_pressed do get_key;
end;
function R_Shift_State : Boolean;
begin
if mem[$40:$17] and not $F0 = 1 then
R_Shift_State := true
else
R_Shift_State := false;
end;
function L_Shift_State : Boolean;
begin
if (mem[$40:$17] and not $F0) shr 1 = 1 then
L_Shift_State := true
else
L_Shift_State := false;
end;
function CTRL_State : Boolean;
begin
if (mem[$40:$17] and not $F0) shr 2 = 1 then
CTRL_State := true
else
CTRL_State := false;
end;
function ALT_State : Boolean;
begin
if (mem[$40:$17] and not $F0) shr 3 = 1 then
ALT_State := true
else
ALT_State := false;
end;
function NUM_State : Boolean;
begin
if (mem[$40:$17] and not $E0) shr 5 = 1 then
NUM_State := true
else
NUM_State := false;
end;
end.