Keyboard Driver Craziness.
Posted: Wed Sep 10, 2008 8:29 pm
I've got an issue with my keyboard driver in 32-bit assembly. kbd_readchar reads one character from the keyboard using i/o ports 0x64 and 0x60, echos the character, and returns it in al. So far the kernel is responsible for the loop of getting the input over and over again. But after around 170-ish (I don't feel like counting exactly) characters are inputted, the cursor goes back to the top and keeps moving, but the inputted characters still go to the correct place. At 257, it starts overwriting the previous input.
Help!
Help!
Code: Select all
kbd_readchar:
; OK, I'm going to note a few things here before you read
; any more of the routine. VGA is a slow beast sometimes,
; but the constant calling to move_cursor is a permanent
; fixture. Also, no longer does this thing take characters
; until infinity. It returns one character printed in ah.
in al,64h ; read status byte
and al,01h ; wait for output buffer to be full
jz kbd_readchar
in al,60h ; read scancode byte
cmp al,02h
je near .q
cmp al,03h
je near .w
cmp al,04h
je near .e
cmp al,05h
je near .r
cmp al,06h
je near .t
cmp al,07h
je near .y
cmp al,08h
je near .u
cmp al,09h
je near .i
cmp al,0ah
je near .o
cmp al,0bh
je near .p
cmp al,10h
je near .q
cmp al,11h
je near .w
cmp al,12h
je near .e
cmp al,13h
je near .r
cmp al,14h
je near .t
cmp al,15h
je near .y
cmp al,16h
je near .u
cmp al,17h
je near .i
cmp al,18h
je near .o
cmp al,19h
je near .p
cmp al,1eh
je near .a
cmp al,1fh
je near .s
cmp al,20h
je near .d
cmp al,21h
je near .f
cmp al,22h
je near .g
cmp al,23h
je near .h
cmp al,24h
je near .j
cmp al,25h
je near .k
cmp al,26h
je near .l
cmp al,2ch
je near .z
cmp al,2dh
je near .x
cmp al,2eh
je near .c
cmp al,2fh
je near .v
cmp al,30h
je near .b
cmp al,31h
je near .n
cmp al,32h
je near .m
cmp al,0eh
je near .backspace
cmp al,39h
je near .space
cmp al,1ch
je near .enter
jmp kbd_readchar
.q:
mov bl,'q'
mov al,'q'
call putch32
mov bh, byte [_CurY] ; get current position
mov bl, byte [_CurX]
call move_cursor ; update cursor
ret
.w:
mov bl,'w'
mov al,'w'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.e:
mov bl,'e'
mov al,'e'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.r:
mov bl,'r'
mov al,'r'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.t:
mov bl,'t'
mov al,'t'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.y:
mov bl,'y'
mov al,'y'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.u:
mov bl,'u'
mov al,'u'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.i:
mov bl,'i'
mov al,'i'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.o:
mov bl,'o'
mov al,'o'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.p:
mov bl,'p'
mov al,'p'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.a:
mov bl,'a'
mov al,'a'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.s:
mov bl,'s'
mov al,'s'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.d:
mov bl,'d'
mov al,'d'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.f:
mov bl,'f'
mov al,'f'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.g:
mov bl,'g'
mov al,'g'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.h:
mov bl,'h'
mov al,'h'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.j:
mov bl,'j'
mov al,'j'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.k:
mov bl,'k'
mov al,'k'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.l:
mov bl,'l'
mov al,'l'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.z:
mov bl,'z'
mov al,'z'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.x:
mov bl,'x'
mov al,'x'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.c:
mov bl,'c'
mov al,'c'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.v:
mov bl,'v'
mov al,'v'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.b:
mov bl,'b'
mov al,'b'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.n:
mov bl,'n'
mov al,'n'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.m:
mov bl,'m'
mov al,'m'
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.space:
mov bl,' '
mov al,' '
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.enter:
mov bl,0ah
mov bl,0ah
call putch32
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
ret
.backspace: ; this is a fun little thing
cmp byte [_CurX],0 ; beginning of line?
je .ignbksp ; if yes, ignore backspace
mov ah,[_CurX]
dec ah
mov [_CurX],ah
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
mov bl,20h
call putch32
mov ah,[_CurX]
dec ah
mov [_CurX],ah
mov bh, byte [_CurY]
mov bl, byte [_CurX]
call move_cursor
mov al,08h
ret
.ignbksp:
ret