detecting Keyboard in P mode: how do I do it

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.
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

Post by Osbios »

And by the way: You cant detect XT keyboards. Because this keyboards only send "scan codes" but won't react to any input!
crazyos
Posts: 3
Joined: Fri Jan 18, 2008 5:52 am

Post by crazyos »

hi everyone ,
as james told i am able to glow the led on my keyboard but then i am not able to get the keyboards reply.( basically i m tryin to detect the ps/2 keyboard i.e whether keyboard is plugged in or not)

Code: Select all

 
[GLOBAL keybdpre]

[bits 32]
          
     

     

keybdpre:

    call kbd
    mov al,0EDh     ; 8048 command byte to set
    out 60h,al
    call kbd
                            ; b0 is ScrollLock, b1 is NumLock, b2 is CapsLock
    mov al,07h
    out 60h,al
WaitLoop:
     in     al, 64h     ; Read Status byte 
    and    al, 10b     ; Test IBF flag (Status<1>) 
     jz     WaitLoop    ; Wait for IBF = 1 
                           ;problem here does not come out as no		           ;  value is returned by the keyboard.
      in     al, 60h     ; Read input buffer 

      cmp al,0xfa
      je print;
     areho: mov ax,0x00
            ret
    print: mov ax,0x01
           ret         
	   
kbd0:   jmp short $+2
		in al,60h
	kbd:    jmp short $+2
		in al,64h
		test al,1
		jnz kbd0
		test al,2
		jnz kbd
		ret	




i think the keyboard should respond with acknowledgment of [FA] but then my programme is getting into the loop and not coming out as the IBF is not detecting any data. also tell me if am on right track
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

why don't you try reading the System Flag status bit from the Status port?
I think that shows if the self-test was OK or not.
b2 System Flag status: 0=power-up/reset, 1=selftest OK (?)

Code: Select all

#define keyboard_status_port 0x64
#define system_flag_bit 0x04

if(inportb(keyboard_status_port) & system_flag_bit)
{printf("keyboard is on \n");}
else{printf("keyboard is either not on or disconnected \n");}
crazyos
Posts: 3
Joined: Fri Jan 18, 2008 5:52 am

Post by crazyos »

thanks for the reply but the same problem even if i am disconnecting the ps2 port it is showin keyboard is on i need some acknowledgment from the keyboard.
crazyos
Posts: 3
Joined: Fri Jan 18, 2008 5:52 am

Post by crazyos »

well i checked my code on the physical machine and got the acknowlegment it was working fine, but then am not able to get acknowledgment on vmware may be it has got something to do with virtualization. can any one tell me whats the problem using vmware
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post by naiksidd_85 »

thank you all i finally got it done
Learning a lot these days THANKS to OSdev users
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Post by ~ »

Could you give us some hint on how you did it?

It looks like all methods presented here including mine (and probably except the one posted by Osbios) may work in some machines and fail in others.

Have you tested on several machines to make sure that your method is fully reliable?

The acknowledgment from resetting the keyboard seems to fail on some PC's (maybe just needs elaborate...), reading the SYSTEM FLAG is only useful to test the whether it was properly present at POST. If it is set to 0, then RESET the keyboard, then re-read the SYSTEM FLAG, it doesn't seem to change in any of the PC's I have (4 different ones) to indicate BAT OK or BAT ERROR.

Maybe a timer using the PIT is absolutely required, as well as a keyboard interrupt and filtering out PS/2 mouse.
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

Post by Osbios »

Like I already told you: The USB Legacy stuff makes it impossible to tell if there is a keyboard or not. You have to live with it until you have USB drivers. :b
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post by naiksidd_85 »

hi ~,

sorry for the delay in reply.
I have used the same code that is posted by crazyOS on this page as we are working together.

I will surely post the code.
according to your suggestion I am testing it on various platform when I am really sure that its working comletely fine I will post it .
And any ways you are the guys who have helped me in this . else I would have not done it
Learning a lot these days THANKS to OSdev users
Post Reply