Keyboard Problem...

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
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Keyboard Problem...

Post by ComputerPsi »

I have been trying to get my keyboard to do a self test. By the specifications of a keyboard, to do that, AAh must be sent to port 64h, and then, if successfull, on port 60h, there would be 55h as a reply. For some reason, I don't get the 55h. The keyboards tried work correctly. I have added all the checks and everything that make sure I'm sending the information when it can be sent, but I am still getting an error. The code is in NASM, 16 bits. This was made as a com file, to test. I tried it on two computers. One running windows 2000, the other on dos:

Code: Select all

ORG 100

;http://www.osdever.net/documents/wout_kbd.php?the_id=15
;http://plumeria.vmth.ucdavis.edu/~saintly/newbie/expertcentral/closed/91645.html

KBD_OBF equ 1
KBD_IBF equ 2
KBD_GTO	equ 0x40
KBD_PERR equ 0x80

KBD_DATA_REG equ 0x60
KBD_CNTL_REG equ 0x64
KBD_STATUS_REG equ 0x64
KBD_CMND_SELF_TEST equ 0xAA

start:

	mov ah,9
	mov dx,startMSG
	int 0x21		;Tell the user what this is.

	;I'm testing the kb now, so stop sending any signals making the computer think it's a keyboard stroke
	cli

	;Flush it
	call kbd_wait_for_input

	mov ah,9
	mov dx,KBTesting
	int 0x21

	mov al,KBD_CMND_SELF_TEST
	mov dx,KBD_CNTL_REG
	call kbd_write

	call kbd_wait_for_input
	cmp al,0x55
	jz good
;	mov [BadMSG],al
	mov ah,9
	mov dx,BadMSG
	int 0x21
	jmp short next
good:
	mov ah,9
	mov dx,GoodMSG
	int 0x21
next:

	;The testing is done. The keyboard is ready for sending anything.
	sti

	xor ax,ax
	int 0x16

	int 0x20	;done

kbd_wait_for_input:


	in al,KBD_STATUS_REG
	mov ah,al
	; Wait for input data to become available.  This bit will
	; then be cleared by the following read of the DATA
	; register.
	and al,KBD_OBF
	jnz kbd_wait_for_input
	in al,KBD_DATA_REG
	; Check to see if a timeout error has occurred.  This means
	; that transmission was started but did not complete in the
	; normal time cycle.  PERR is set when a parity error occurred
	; in the last transmission.
	and ah,KBD_GTO | KBD_PERR
	jnz kbd_wait_for_input
	ret

kbd_write:
	push ax
again:
	in al,KBD_STATUS_REG
	and al,KBD_IBF
	jnz again
	pop ax
	out dx,al
	ret

startMSG db "Veniamin's Keyboard Program Thing.. (Direct IO stuff) :)",10,13,"$"
KBTesting db "Keyboard self test...$"
GoodMSG db "Successfull :)",10,13,"$"
BadMSG db "Unsuccessfull :(",10,13,"$"
If you see what's wrong, please tell me.
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Keyboard Problem...

Post by ComputerPsi »

Another note: When I run the program on dos, the keyboard stops working... Anybody know why?
Anything is possible if you put your mind to it.
ComputerPsi
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Keyboard Problem...

Post by earlz »

hmm not a clue
exactly why do u need this if u are in 16bit though(why not use int 16h)
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Keyboard Problem...

Post by ComputerPsi »

Anybody can use int 16. :P This part was made not to use dos or bios, to be later be used for speed and full control over the hardware. After everything is put in and works, the interrupts used (like to print a message) will be removed.
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Keyboard Problem...

Post by ComputerPsi »

Okay, I kinda got it to work (I don't know exact how, but it works).. anway, the problem with the keyboard not working after the test still goes on. Anybody know why?
Anything is possible if you put your mind to it.
ComputerPsi
yetAnotherOS
Posts: 12
Joined: Fri Jul 01, 2005 11:00 pm

Re: Keyboard Problem...

Post by yetAnotherOS »

From experience I have found that the best way to make sure the keyboard will work again is to issue an enable keyboard command (0xf4 to port 0x60) and to make sure that keyboard interrupts are enabled by setting bit 0 to 1 of the mode byte that is sent with 0x60 to port 0x64 followed by the previous value read from port 0x60 after sending 0x20 to port 0x64 ORed with 0x01. Written in pseudocode this would be:

Code: Select all

send 0x20 to port 0x64
read from 0x60
OR the result with 0x01
send 0x60 to port 0x64
send the ORed value to port 0x60
I also find that sending a reset command (0xff) to port 0x60 can be useful. For more information you may wish to consult the linux source code, in particular the file that handles the keyboard and ps2 mouse. (linux/drivers/char/pc_keyb.c)
Enjoy writing code for the keyboard and then have fun decoding scan codes![/code]
Last edited by yetAnotherOS on Sat Jul 09, 2005 11:00 pm, edited 1 time in total.
Post Reply