1 ;----------------------------------------------------------;
2 ; BOS 0.04 Christoffer Bubach, 2004-2005. ;
3 ;----------------------------------------------------------;
5 ; Keyboard functions. IRQ, INT's and more. ;
7 ;----------------------------------------------------------;
14 ;--------------------------------------------------------------------------------;
15 ; _______________________ Keyboard buffer system ;
16 ; | | | | | | | | | | | | ;
17 ; +---------------------+ ;
18 ; | +----------> kbd_head, here is where we put new scan-codes. ;
19 ; +--------------------> kbd_tail, where we last read a key. this means ;
20 ; that we have 4 new scan-codes to read before we catch up. ;
21 ;--------------------------------------------------------------------------------;
22 kbd_buffer db ' A 64-byte '
23 db ' keyboard buffer '
24 kbd_head db 1 ; head must be +1 from tail
27 ;-------------------------------------------------------------------------;
28 ; _________________ Flag byte: ;
30 ; +---------------+ 1 = True 0 = False ;
31 ; | | | | | | | +---> shift key ;
32 ; | | | | | | +-----> ctrl key ;
33 ; | | | | | +-------> alt key ;
34 ; | | | | +---------> reserved bit ;
35 ; | | | +-----------> reserved bit ;
36 ; | | +-------------> reserved bit ;
37 ; | +---------------> ctrl + alt + del ;
38 ; +-----------------> key released ;
39 ;-------------------------------------------------------------------------;
40 kbd_flags db 0 ; flag byte
42 ;-------------------------------------------------------------------------;
43 ; _________________ LED status byte: ;
45 ; +---------------+ 1 = True 0 = False ;
46 ; | | +---> scroll lock ;
47 ; | +-----> num lock ;
48 ; +-------> caps lock ;
49 ;-------------------------------------------------------------------------;
50 kbd_status db 0 ; LED statusbyte
53 ;----------------------;
55 ;----------------------;
59 ;-------------------------;
61 ;-------------------------;
65 ;------------------------------;
66 ; check if key was released ;
67 ;------------------------------;
70 and byte [kbd_flags], 01111111b ; key up..
72 cmp al, 42+128 ; left shift up?
74 cmp al, 54+128 ; right shift up?
77 cmp al, 29+128 ; ctrl up?
80 cmp al, 83+128 ; del up?
83 cmp al, 56+128 ; alt up?
87 ;--------------------;
89 ;--------------------;
91 and byte [kbd_flags], 11111110b
98 and byte [kbd_flags], 11111101b ; ctrl off.
102 and byte [kbd_flags], 11111011b ; alt off.
106 test byte [kbd_flags], 01000000b
108 and byte [kbd_flags], 10111111b ; ctrl+alt+del bit off.
112 ;----------------------------------------------;
113 ; a key was pressed, check for special keys ;
114 ;----------------------------------------------;
116 or byte [kbd_flags], 10000000b
121 or byte [kbd_flags], 00000001b
127 or byte [kbd_flags], 00000001b
133 or byte [kbd_flags], 00000010b
139 or byte [kbd_flags], 00000100b
143 test byte [kbd_flags], 00000110b ; check for ctrl+alt
145 cmp al, 83 ; check for delete
147 or byte [kbd_flags], 01000000b ; ctrl+alt+del bit on.
149 ;-------------------------------------;
150 ; toggle caps, num and scroll lock ;
151 ;-------------------------------------;
155 xor byte [kbd_status], 4
162 xor byte [kbd_status], 2
169 xor byte [kbd_status], 1
173 ;-----------------------------------;
174 ; put the scancode in the buffer ;
175 ;-----------------------------------;
184 cmp [kbd_head], 63 ; if we reach the buffer
185 jne .cont1 ; end, go back to 0.
199 call beep ; pc_speaker.inc
200 mov [kbd_head], 1 ; fix it as good
201 mov [kbd_tail], 0 ; as possible.. :S
210 ;------------------------------;
211 ; Update the keyboard LED's ;
212 ;------------------------------;
247 ;-------------------------------------------------------;
248 ; BOS INT to get a char. ;
249 ; out: ah = scan code, al = ascii ;
250 ; bh = flag-byte, bl = led-byte ;
251 ;-------------------------------------------------------;
273 movzx eax, [kbd_tail]
275 mov ah, byte [esi] ; ah = scancode
276 movzx esi, byte [esi] ; esi = scancode
290 ;--------------------------------;
291 ; check for caps, shift & alt ;
292 ;--------------------------------;
293 test [kbd_status], 00000100b
295 test [kbd_flags], 00000001b
301 mov al, [esi+keymap] ; scancode + keymap = ascii
304 ;--------------------;
306 ;--------------------;
308 test [kbd_flags], 00000001b
311 mov al, [esi+keymap_caps]
314 ;--------------------------;
315 ; caps and shift keymap ;
316 ;--------------------------;
318 mov al, [esi+keymap_caps_shift]
325 mov al, [esi+keymap_shift]
328 ;---------------------------;
329 ; set registers and exit ;
330 ;---------------------------;
339 ;------------------------------;
340 ; "press any key to..." ;
341 ;------------------------------;
365 movzx eax, [kbd_tail]
367 mov ah, byte [esi] ; ah = scancode
368 cmp ah, 0xFA ; check for some stuff..