-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint9h.asm
110 lines (103 loc) · 1.58 KB
/
int9h.asm
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
.model tiny, C
.386
.code
public Key_Ini
public Key_Rst
public Key_Is_Esc
public Get_Key
locals
org 5h
Key_Ini proc near
push ax
push bx
push dx
push es
; Получаем старый вектор в old_int9h
mov ax, 3509h ; 35 - код команды получания вектора прерывания. 9 - номер вектора.
int 21h
mov word ptr old_int9h, bx
mov word ptr old_int9h+2, es
; Устанавливаем новый обработчик int9h
mov ax, 2509h
mov dx, offset int9h
int 21h
pop es
pop dx
pop bx
pop ax
ret
Key_Ini endp
Key_Rst proc near
push ax
push dx
push ds
; Возвращаем вектор клавиатуры
mov dx, word ptr cs:[old_int9h]
mov ds, word ptr cs:[old_int9h+2]
mov ax, 2509h
int 21h
pop ds
pop dx
pop ax
ret
Key_Rst endp
Key_Is_Esc proc near
; CF=1 YES
cmp buffer[1], 1h
jne @@no_key
push ax
mov al, buffer[0]
cmp al, 81h
pop ax
je @@is_esc
@@no_key:
clc ; CF=0
ret
@@is_esc:
mov buffer[1], 0
stc ; CF=1
ret
Key_Is_Esc endp
Get_Key proc near
; CF=1 - есть символ, но не esc
; al - код символа
cmp buffer[1], 1h
jne @@no_key
mov al, buffer[0]
cmp al, 81h
je @@is_esc
mov buffer[1], 0
stc ; CF=1
ret
@@is_esc:
@@no_key:
clc ; CF=0
ret
Get_Key endp
int9h proc near
push ax
push di
push es
in al, 60h
push cs
pop es
mov di, offset buffer
stosb
mov al, 1
stosb
pop es
pop di
in al, 61h
mov ah, al
or al, 80h
out 61h, al
xchg ah, al
out 61h, al
mov al, 20h
out 20h, al
pop ax
iret
int9h endp
buffer db 0,0
old_int9h dd ?
end