-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestkb.asm
More file actions
239 lines (206 loc) · 3.57 KB
/
testkb.asm
File metadata and controls
239 lines (206 loc) · 3.57 KB
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
; Copyright 2020 Jerome Shidel
; Released to Public Domain
org 0x100
use16
call InitTraps
mov si, Message
call PrintString
BIOSInputLoop:
; Key keboard status
mov ah, 0x01
int 0x16
jnz BIOSInputLoop
; Check if scan code is available
; test ax, ax
; jz BIOSInputLoop
; pull keystroke from buffer
mov ah, 0
int 0x16
cli
push ax
mov si, ScanCode
call PrintString
mov al, ah
call PrintHexAL
pop ax
push ax
mov si, AsciiValue
call PrintString
call PrintHexAL
push es
mov ax, 0x0040
push ax
pop es
mov al, [es:0x0017]
pop es
mov si, ShiftState
call PrintString
call PrintBinAL
mov si, CountInt1B
call PrintString
mov ax, [DataInt1B]
call PrintHexAX
call PrintCRLF
pop ax
sti
cmp al, 27
jne BIOSInputLoop
Terminate:
call DoneTraps
; Terminate with no error
mov ax, 0x4c00
int 0x21
Vector1B:
dw 0,0
DataInt1B:
dw 0
MyInt1B:
cli
push ax
mov ax, [CS:DataInt1B]
inc ax
mov [CS:DataInt1B], ax
pop ax
iret ; automatic sti with iret/popf
InitTraps:
cli
mov [Vector1B], word MyInt1B
mov [Vector1B+2],ds
mov al, 0x1b
mov di, Vector1B
call SwapVectors
sti
ret
DoneTraps:
cli
mov al, 0x1b
mov di, Vector1B
call SwapVectors
sti
ret
SwapVectors:
; AL = Vector
; [di] = pointer
push bx
push dx
push es
push ds
call GetIntVector
mov dx, [di]
mov ds, [di+2]
call SetIntVector
pop ds
mov [di], bx
mov [di+2], es
pop es
pop dx
pop bx
ret
GetIntVector:
; AL = vector
; Returns ES:BX
push ax
mov ah, 0x35
int 0x21 ; returns es:bx
pop ax
ret
SetIntVector:
; AL = vector
; DS:DX = Pointer
push ax
mov ah, 0x25
int 0x21
pop ax
ret
PrintHexAX:
push ax
push ax
mov al, ah
call PrintHexAL
pop ax
call PrintHexAL
pop ax
ret
PrintHexAL:
push cx
push ax
and al, 0xf0
mov cl, 0x04
shr al, cl
call MapToHex
call PrintAL
pop ax
push ax
and al, 0x0f
call MapToHex
call PrintAL
pop ax
pop cx
ret
PrintBinAL:
push ax
push cx
mov cx, 8
mov ah, al
.Repeat:
test ah, 10000000b
jz .Zero
mov al, '1'
jmp .Display
.Zero:
mov al, '0'
.Display:
shl ah, 1
call PrintAL
loop .Repeat
pop ax
pop cx
ret
MapToHex:
add al, 0x30
cmp al, 0x3a
jb .Done
add al, 0x07
.Done:
ret
PrintAL:
push ax
push bx
mov bx, 0x0007
mov ah, 0x0e
int 0x10
pop bx
pop ax
ret
PrintString:
push ax
push bx
.Repeat:
mov al, [si]
cmp al, 0
je .Done
inc si
call PrintAL
jmp .Repeat
.Done:
pop bx
pop ax
ret
PrintCRLF:
push si
mov si, CRLF
call PrintString
pop si
ret
ScanCode:
db 'Scancode: ',0
AsciiValue:
db ', Ascii: ', 0
ShiftState:
db ', Flags: ', 0
CountInt1B:
db ', Count Int1B: ',0
Message:
db 'Press the ESC key to exit'
CRLF:
db 0xd,0xa,0