Image Map Image Map
Results 1 to 4 of 4

Thread: Trouble with XT keyboard interrupt handler

  1. #1
    Join Date
    Jun 2017
    Location
    United Kingdom
    Posts
    2

    Default 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:

    Code:
    		push ax
    		push ds
    		mov ax,s_programcode
    		mov ds,ax
    		in al,0x60
    		mov [v_key],al					; Will have to be changed to place value in array
    
    		mov al,0xFA
    		out 0x60,al					; This handles XT computers
    
    		mov al,0x20
    		out 0x20,al					; This handles AT computers
    
    		pop ds
    		pop ax
    		iret						; Return from interrupt
    Does anyone have any opinions on the matter? They would be greatly appreciated.

    Regards,
    PROSM

  2. #2

    Default

    Quote Originally Posted by PROSM View Post
    Code:
    		mov al,0xFA
    		out 0x60,al					; This handles XT computers
    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,

    Quote Originally Posted by PROSM View Post
    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.

  3. #3
    Join Date
    Jun 2017
    Location
    United Kingdom
    Posts
    2

    Default

    Quote Originally Posted by reenigne View Post
    Code:
    		in al,0x61
    		or al,0x80
    		out 0x61,al
    		and al,0x7f
    		out 0x61,al
    After replacing the old 0xFA output with this, the keyboard was recognised when returned to the DOS prompt. Thank you very much for your help, reenigne.

  4. #4
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    25,021
    Blog Entries
    20

    Default

    Many years ago, here's the key-reading routine that I used commercially.

    Code:
    GetKey	proc	near
    	cmp	cs:AT_Keyboard,0	; see if AT
    	je	GetKey8			; if not...
    	push	cx
    	xor	cx,cx
    GetKey2:
    	in	al,pkeystat
    	test	al,2			; see if ready
    	loopnz	GetKey2			; if not
    	mov	al,0adh
    	out	pkeystat,al		; send it
    	xor	cx,cx
    GetKey4:
    	in	al,pkeystat		; get a stroke
    	test	al,2			; see if still full
    	loopnz	GetKey4			; wait...
    	in	al,pkeydata		; get the keystroke
    	push	ax			; save the data
    	xor	cx,cx
    GetKey6:
    	in	al,pkeystat
    	test	al,2
    	loopnz	GetKey6			; wait...
    	mov	al,0aeh
    	out	pkeystat,al		; send enable
    	pop	ax
    	pop	cx
    	ret
    
    ;	PC-XT cases.
    
    GetKey8:
    	in	al,pkeydata
    	push	ax			; save the key
    GetKey10:
    	in	al,pkeyctrl	; reset the latch
    	mov	ah,al
    	or	al,128
    	out	pkeyctrl,al	; toggle
    	mov	al,ah
    	out	pkeyctrl,al	; back to original
    	pop	ax
    	ret
    GetKey	endp
    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.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •