Can't understand why...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Can't understand why...

Post by matias_beretta »

i am doing a keyboard driver, but i can't make this code work

; INPUT: NOTHING
; OUTPUT: AL = KEY SCAN CODE

NoKey:
in al, 60h
cmp al, 0
je NoKey
ret

I'm working in real mode... A member of the forum told me to setup an IRQ, but I don't know what is and how to do it (i am not used to working with protected mode)...
Matías Beretta
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

When you input from port 0x60, you get a SCANCODE. The value of the scancode is never 0 -- that's an illegal value (although, I'm not sure what happens if you read a scancode, ack it, and then try to read again).

If you want to know if you've got a key or not, you need to read port 0x64, and test the bottom bit (bit 0, with a value of 1) -- if THAT bit is 0, then there is no key. If you HAVE a key, then you read its scancode from port 0x60.

Alternately, as was said, if you set up an IRQ1 handler -- then when the machine actually gets an IRQ1 you know for a fact that there is a scancode waiting to be read on port 0x60 and you can just go read it. Setting up an IRQ1 handler takes some work -- but you will have to do it eventually anyway. If you do not use SOME kind of IRQ1 handler, you will probably only get one key before the keyboard locks up, because you need to ACK the receipt of the key and the IRQ.
mohammed
Member
Member
Posts: 93
Joined: Mon Jan 30, 2006 12:00 am
Location: Mansoura, Egypt

Post by mohammed »

Post Reply