If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Trouble with XT keyboard interrupt handler

Hello there,

I have been having trouble while writing a keyboard handler routine in assembly for my DOS program. It works on an AT emulator and my HP Vectra VL 5/100 computer. However, when trying my software on an XT emulator, the keyboard works within my program, but is unresponsive when returned to the DOS prompt. I think this may have to do with the differences between the XT and AT keyboard protocols, but I'm not sure. This section of code is responsible for getting the key:

I'm not sure where you got this from but it won't do anything since port 0x60 is an input port. You do, however, need to acknowledge receipt of the keyboard byte before the keyboard port hardware will be able to receive another. This is done with:

Code:

in al,0x61
or al,0x80
out 0x61,al
and al,0x7f
out 0x61,al

Btw,

Originally Posted by PROSM

Code:

mov al,0x20
out 0x20,al ; This handles AT computers

This is needed for both XT and AT machines - it tells the Programmable Interrupt Controller that we're done with this interrupt so that equal or lower priority interrupts can come in again.

I'm not sure if the keyboard acknowledge problem is what's causing the crash (I think if you don't do that you'll just get another keyboard interrupt again right away) but perhaps there is a bug in the emulator you're using. If that doesn't fix it, take a look at how the interrupt vector is restored to its original value when the program ends.

Note that you'll get two interrupts for every keypress-release sequence. Since the keyboard interrupt is the highest priority one, be as quick as you can so that a keypress doesn't screw up lower-priority interrupts. The big difference between XT and AT sequences is that with the AT, you're dealing with a conversation with two microcontrollers--one in the keyboard and one on the motherboard, so the ballet is a bit more complex. In the case of an XT, you've got the keyboard microcontroller, but a simple shift register on the motherboard. There's not much of a two-way conversation between the keyboard and the motherboard in the XT, whereas, in the AT, it's considerably more complicated.