Keyboard problem

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
venk
Posts:14
Joined:Thu Oct 16, 2008 6:49 am
Contact:
Keyboard problem

Post by venk » Thu Oct 16, 2008 7:02 am

I converted to 32bit using the tutorial, (copied
exactly, then I wanted to do something on my own, so I decided to make the OS print whatever was typed in the keyboard. This is the code that I used:

keyPress:
WaitLoop: in al, 64h
and al, 10b
jz WaitLoop
in al, 60h
mov bl,al
call Putch32
jmp keyPress

(Even part of this code is copied), I am using Bochs emulator, and it does nothing when I press the keys. (I included stdio.inc)
Help Me!!
SOS!!

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Tue Oct 21, 2008 2:21 am

For the most part you got it right. A problem is this:

Code: Select all

 WaitLoop: in al, 64h
and al, 10b
jz WaitLoop
You are masking bit 1 (input buffer full) rather then bit 0 (output buffer full) of the status register. You want to test the output buffer.

Try this:

Code: Select all

keyPress:
WaitLoop: in al, 64h
and al, 1
jz WaitLoop
in al, 60h
mov bl,al
call Putch32
jmp keyPress
You should also take note that this will not return a character but rather a scan code. For every character pressed, you will receive two scan codes: one for pressing the key, and one for releasing it.

To get the ASCII character, you would need to convert these scan codes. This is useually done with a lookup table.

This contains the scan codes. So, if the return value is 0x1e, it is ascii 'a'. If its 0x30, the ascii character is 'b', and so on...

---

Also, just to add, most keyboard drivers work by hooking an interrupt handler to ISR 1. This is usually a nicer method then polling the keyboard controller but requires the IDT and PIC properly set up.

Post Reply