Results 1 to 5 of 5

Thread: Need some help with keyboard BIOS Services interrupts->

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Need some help with keyboard BIOS Services interrupts->

    Whenever I use INT 16h, 1h (Keyboard BIOS Services - Get Keystroke Status) I only get the status for the first key pressed. When calling the function again I still get the status for the first key pressed while having pressed other keys. Here is the code I am using:

    (I think only the part up to the ".ScanCode db "0000", 13, 10, "$"" line is important here)

    Code:
    ORG 256
    Main:
    	; Get scan code and ASCII character of any key currently being pressed.
    	MOV ah, 1		; Get keyboard status.
    	INT 22			; Keyboard BIOS services.
    
    	; Convert scan code and ASCII character to user readable format.
    	PUSH ax
    	CALL cv256to16
    	POP DWORD [.ScanCode]
    
    	; Displays key scan code and ASCII character.
    	MOV ah, 9		; Print string.
    	MOV dx, .ScanCode	;
    	INT 33			; DOS functions interrupt.
    JMP Main
    
    .ScanCode db "0000", 13, 10, "$"
    
    
    ;+-------------------------------------------------------------------------------+
    ;| Convert Byte to Hexadecimal - Converts byte values to hexadecimal number.     |
    ;| [Parameters in:]                                                 		 |
    ;| Name:	Description:				Type:    		 |
    ;| Number	Byte values to be converted.            2 Byte number (by value) |
    ;| Parameters out:]                                                     	 |
    ;| Name:	Description:				Type:    		 |
    ;| Hexadecimal	Converted hexadecimal number.		4 Byte string (by value) |
    ;+-------------------------------------------------------------------------------+
    
    cv256to16:
    	POP WORD [.ReturnAddress]
    	POP WORD [.ByteVal]
    
    	MOV bx, 0					; Digit = 0
    	MOV cl, 12					; BitShift = 12
    	MOV dx, 64410					; BitMask = 64410
    		.GetHexDigits:
    			MOV ax, [.ByteVal]		;
    			AND ax, dx			; Extract a 4 bit value from the byte values.
    			SHR ax, cl			;
    			MOV si, ax			;
    			MOV al, [.HexDigits + si]	; Get the hexadecimal digit for the 4 bit value.
    			MOV [.HexNumber + bx], al	;
    			SHR dx, 4			; Adjust BitMask
    			SUB cl, 4			; and BitShift.
    			INC bx				; Next digit.
    			CMP bx, 4			; Check for last digit.
    		JNE .GetHexDigits
    
    	PUSH DWORD [.HexNumber]
    	PUSH WORD [.ReturnAddress]
    RET
    
    .ByteVal dw 0
    .HexNumber db "0000"
    .HexDigits db "0123456789ABCDEF"
    .ReturnAddress dw 0
    Do I need to reset something after having called int 16h, 1h before calling the interrupt again?

    Notes:
    1 I have tried using Extended Get Keystroke Status (INT 16h, 11h) supposedly the ZF flag will indicate whether the key is being or was being pressed.
    2 In my code all numbers are written in decimal format which means that in the code int 16h is referred to as int 22.
    3 I looked up all the information about int 22h, 1h using Helppc.

  2. #2
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Need some help with keyboard BIOS Services interrupts->

    Quote Originally Posted by Peter Swinkels
    Whenever I use INT 16h, 1h (Keyboard BIOS Services - Get Keystroke Status) I only get the status for the first key pressed. When calling the function again I still get the status for the first key pressed while having pressed other keys. Here is the code I am using:

    (I think only the part up to the ".ScanCode db "0000", 13, 10, "$"" line is important here)

    Code:
    ORG 256
    Main:
    	; Get scan code and ASCII character of any key currently being pressed.
    	MOV ah, 1		; Get keyboard status.
    	INT 22			; Keyboard BIOS services.
    
    	; Convert scan code and ASCII character to user readable format.
    	PUSH ax
    	CALL cv256to16
    	POP DWORD [.ScanCode]
    
    	; Displays key scan code and ASCII character.
    	MOV ah, 9		; Print string.
    	MOV dx, .ScanCode	;
    	INT 33			; DOS functions interrupt.
    JMP Main
    
    .ScanCode db "0000", 13, 10, "$"
    
    
    ;+-------------------------------------------------------------------------------+
    ;| Convert Byte to Hexadecimal - Converts byte values to hexadecimal number.     |
    ;| [Parameters in:]                                                 		 |
    ;| Name:	Description:				Type:    		 |
    ;| Number	Byte values to be converted.            2 Byte number (by value) |
    ;| Parameters out:]                                                     	 |
    ;| Name:	Description:				Type:    		 |
    ;| Hexadecimal	Converted hexadecimal number.		4 Byte string (by value) |
    ;+-------------------------------------------------------------------------------+
    
    cv256to16:
    	POP WORD [.ReturnAddress]
    	POP WORD [.ByteVal]
    
    	MOV bx, 0					; Digit = 0
    	MOV cl, 12					; BitShift = 12
    	MOV dx, 64410					; BitMask = 64410
    		.GetHexDigits:
    			MOV ax, [.ByteVal]		;
    			AND ax, dx			; Extract a 4 bit value from the byte values.
    			SHR ax, cl			;
    			MOV si, ax			;
    			MOV al, [.HexDigits + si]	; Get the hexadecimal digit for the 4 bit value.
    			MOV [.HexNumber + bx], al	;
    			SHR dx, 4			; Adjust BitMask
    			SUB cl, 4			; and BitShift.
    			INC bx				; Next digit.
    			CMP bx, 4			; Check for last digit.
    		JNE .GetHexDigits
    
    	PUSH DWORD [.HexNumber]
    	PUSH WORD [.ReturnAddress]
    RET
    
    .ByteVal dw 0
    .HexNumber db "0000"
    .HexDigits db "0123456789ABCDEF"
    .ReturnAddress dw 0
    Do I need to reset something after having called int 16h, 1h before calling the interrupt again?

    Notes:
    1 I have tried using Extended Get Keystroke Status (INT 16h, 11h) supposedly the ZF flag will indicate whether the key is being or was being pressed.
    2 In my code all numbers are written in decimal format which means that in the code int 16h is referred to as int 22.
    3 I looked up all the information about int 22h, 1h using Helppc.

    I don't have a 16 bit assembler anywhere so I can't test this... but if memory serves me well, the function you want to call is 10h not 1h.

    IE: mov ah, 10h
    int 16h
    peace.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: Need some help with keyboard BIOS Services interrupts->

    Function 10h makes the program wait for the user to press a key. I want to check if a key is being pressed.

  4. #4
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Need some help with keyboard BIOS Services interrupts->

    doh my bad =P

    on a 122 keyboard, it's al = 21h

    on a enhanced keyboard its 11h

    on some systems the 1st one is an alais for the 2nd one. Also just know that they don't remove things from the buffer, the scan code is in ah and the ascii code is in al.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  5. #5
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Need some help with keyboard BIOS Services interrupts->

    Quote Originally Posted by Maven
    doh my bad =P

    on a 122 keyboard, it's al = 21h

    on a enhanced keyboard its 11h

    on some systems the 1st one is an alais for the 2nd one. Also just know that they don't remove things from the buffer, the scan code is in ah and the ascii code is in al.
    int 16h btw
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

Posting Permissions

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



Click Here to Expand Forum to Full Width