Hi,
NOTNULL wrote:Here is my code:
Code: Select all
outportb (0x60, 0xF0);
outportb (0x60, 0x00);
scode_set = inportb (0x60);
putint (scode_set); /* Here where, I got 2 */
That'd be the problem then - it takes time for data to be sent (one bit at a time) from the keyboard controller to the keyboard itself, and even more time for a response to come back. Also, the first byte you get back will be an "ACK"
not the scan code set.
This means you need to wait for the keyboard controller to become ready before you send a byte, and give the keyboard time to send a reply. You're doing none of this, so the 0x02 you read was probably left behind from the last key pressed or something.
For waiting until the controller is ready, there's a "status" port containing flags that must be checked. For example:
Code: Select all
%define STATUSPORT 0x64
%define COMMANDPORT 0x64
%define DATAPORT 0x60
;Status Port Bits
%define PS2controllerOutputFull 0x01
%define PS2controllerOutputBfull 0x20
%define PS2controllerInputFull 0x02
sendByte:
push eax
.sd1:
in al,STATUSPORT
test al,PS2controllerInputFull
je .sd2
pop eax
out DATAPORT,al
clc
ret
getByte:
.gb1:
in al,STATUSPORT
test al,PS2controllerOutputFull
jne .gb2
in al,DATAPORT
clc
ret
Of course for these you'd also want to add time-outs, so that if no keybord is present (or if there's a hardware fault) it doesn't loop forever.
Once you've got these, then reading the scancode set would go something like:
Code: Select all
getScanCodeSet:
mov al,0xF0
call sendByte
jc timeOutError
mov al,0x00
call sendByte
jc timeOutError
call getByte
jc timeOutError
cmp al,0xFA ;Is it an "ACK"?
jne unknownError
call getByte ;AL = Scan Code Set
jc timeOutError
ret
Cheers,
Brendan