Anyway, I found this code on the MikeOS mailing lists, created by a guy known as Dan Barry at http://lists.berlios.de/pipermail/mikeo ... 03137.html. If I run this code I can detect mouse data through port 0x64 and collect it though port 0x60. I successfully created program to detect mouse delta values. However after activating the mouse I ran into the same problem as the creater, I can no longer collect keyboard data through interrupt 16h. I have debugged the code and tried several things such as disable mouse streaming and re-enabling keyboard streaming to no effect. I have read the PS/2 mouse article in the OSDev Wiki but I cannot see what the problem with the driver is.
Can anyone tell me what I am doing wrong?
If necessary I could temporarily switch to the mouse when needed and keep the keyboard running when it is not.
Here is the mouse setup code I am using:
Code: Select all
os_mouse_setup:
call mouse_port_enable
call mouse_activate
call mouse_get_byte ; Get the responce byte of the mouse
ret
mouse_port_enable:
mov al, 0xa8 ; Enable mouse port
out 0x64, al ; Write to keyboardcontroller
call keyboard_check_port ; Check if command is progressed (demand!)
ret
keyboard_check_port:
xor cx, cx
.again:
in al, 0x64 ; Read from keyboardcontroller
test al, 2 ; Check if input buffer is empty
jz .done
jmp .again ; (Demand!) This may cause hanging, use only when sure.
.done:
ret
mouse_write:
mov al, 0xd4 ; Write to mouse device instead of to keyboard
out 0x64, al ; Write to keyboardcontroller
call keyboard_check_port ; Check if command is progressed (demand!)
ret
keyboard_buffer_check:
xor cx, cx
.mn:
in al, 0x64 ; Read from keyboardcontroller
test al, 0x20 ; Check if mouse output buffer is full
jz .mnn
loop .mn
.mnn:
ret
mouse_activate:
call mouse_write
mov al, 0xf4 ; Command to activate mouse itselve (Stream mode)
out 0x60, al ; Write ps/2 controller output port (activate mouse)
call keyboard_check_port ; Check if command is progressed (demand!)
call mouse_check ; Check if a byte is available
ret
mouse_check:
mov bl, 0
xor cx, cx
.vrd:
in al, 0x64 ; Read from keyboardcontroller
test al, 1 ; Check if controller buffer (60h) has data
jnz .yy
loop .vrd
mov bl, 1
.yy:
ret
keyboard_disable:
mov al, 0xad ; Disable Keyboard
out 0x64, al ; Write to keyboardcontroller
call keyboard_check_port ; Check if command is progressed (demand!)
ret
keyboard_enable:
mov al, 0xae ; Enable Keyboard
out 0x64, al ; Write to keyboardcontroller
call keyboard_check_port ; Check if command is progressed (demand!)
ret
mouse_get_byte:
.cagain:
call mouse_check ; Check if a byte is available
or bl, bl
jnz .cagain
call keyboard_disable ; Disable keyboard to read mouse byte
xor ax, ax
in al, 0x60 ; Read ps/2 controller output port (mousebyte)
mov dl, al
call keyboard_enable ; Enable keyboard
mov al, dl
ret