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)...
Can't understand why...
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm
Can't understand why...
MatÃas Beretta
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.
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.