I'm trying to code a program that recognizes the keyboard and print a letter (not the one I pressed) in the screen when a key is pressed. I managed to make a program that recognizes the keyboard and print the letter, however, it prints the letter more than once, depending on the key it generates more than two (for example printscreen key and delete). I suspect that it might be the keyboard buffer, already tried to clean it but without any success. My code right now is that one:
.code16
.text
.globl _start;
_start:
# prints "X" -> Just to know that the application started
movb $'X' , %al
movb $0x0e, %ah
int $0x10
# Ensure we are starting from the beginning of the interrupt vector
movw $0x0, %ax # Putting the value 0 in ax to store in Data Segment Register (ds)
movw %ax, %ds # Putting 0 in Data Segment Register(ds)
movw $0x204,%bx # Going to address 0x204 -> 512 in the interruput vector 200 <- 80 * 4bytes, 204 <- 200 + 4bytes
movw $0x7d00, (%bx) # Putting the address 0x7d00 in the %bx addres, 0x7d00 = = _start addres + 256
# First PIC (master)
movb $0x11, %al
outb %al, $0x20 # Sending ICW1 in the first PIC -> 0001 0001: ICW4 is required
movb $0x80, %al
outb %al, $0x21 # Sending ICW2 in the first PIC -> 1000 0000: defines the interrupt that will be called (80)
movb $0x04, %al
outb %al, $0x21 # Sending ICW3 in the first PIC -> 0000 0100: has a skave
movb $0x01, %al
outb %al, $0x21 # Sending ICW4 in the first PIC -> 0000 0001: 8086/8088 mode
movb $0xfd, %al
outb %al, $0x21 # Inhibiting all interrupts except keyboard (OCW1)
# Second PIC (slave)
movb $0x11, %al
outb %al, $0xa0 # Sending ICW1 in the second PIC -> 0001 0001: ICW4 is required
movb $0x80, %al
outb %al, $0xa1 # Sending ICW2 in the second PIC -> 1000 0000: defines the interrupt that will be called (80)
movb $0x02, %al
outb %al, $0xa1 # Sending ICW3 in the second PIC -> 0000 0010:
movb $0x01, %al
outb %al, $0xa1 # Sending ICW4 in the second PIC -> 0000 0001: 8086/8088 mode
movb $0xff, %al
outb %al, $0xa1 # Inibindo todas as interrupções, exceto teclado (OCW1)
movb $0xfd, %al # Sending OCW1 in the first PIC
outb %al, $0x21
movb $0xff, %al # Sending OCW1 in the second PIC
outb %al, $0xa1
# Loop to get interrupt
mov $0x0, %cl
_loop: #infinity loop
cmp $0x0, %cl
je _loop
hlt
intKBD:
. = _start + 256
movb $0x20, %al # Sending OCW2 in the first PIC -> EOI
outb %al, $0x20
.checkKeyboard:
in $0x64, %al
and $0x1, %al
jz .emptyKeyboard
in $0x60, %al
jmp .fullKeyboard
#If keyboard is mepty -> Prints V
.emptyKeyboard:
movb $'V', %al
movb $0x0e, %ah
int $0x10
#If keyboard is full -> Prints K
.fullKeyboard:
movb $'K', %al
movb $0x0e, %ah
int $0x10
iret
_end: #Signature boot
. = _start + 510
.byte 0x55
.byte 0xaa
Any piece of code or directions are very appreciated