fixed ps2mouse driver

git-svn-id: svn://kolibrios.org@3550 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-05-28 18:04:03 +00:00
parent 8d679dec36
commit aaa25c149d

View File

@ -1,15 +1,17 @@
format MS COFF format MS COFF
DEBUG equ 1
include '../../../proc32.inc' include '../../../proc32.inc'
include '../../../imports.inc' include '../../../imports.inc'
struc IOCTL struc IOCTL
{ .handle dd ? { .handle dd ?
.io_code dd ? .io_code dd ?
.input dd ? .input dd ?
.inp_size dd ? .inp_size dd ?
.output dd ? .output dd ?
.out_size dd ? .out_size dd ?
} }
virtual at 0 virtual at 0
@ -22,7 +24,7 @@ public version
DRV_ENTRY equ 1 DRV_ENTRY equ 1
DRV_EXIT equ -1 DRV_EXIT equ -1
MT_3B equ 0 MT_3B equ 0
MT_3BScroll equ 3 MT_3BScroll equ 3
MT_5BScroll equ 4 MT_5BScroll equ 4
@ -33,85 +35,85 @@ section '.flat' code readable align 16
proc START stdcall, state:dword proc START stdcall, state:dword
cmp [state], DRV_ENTRY cmp [state], DRV_ENTRY
jne .fin jne .fin
.init: .init:
call detect_mouse call detect_mouse
test eax,eax test eax,eax
jnz .exit jnz .exit
mov [MouseType],MT_3B mov [MouseType],MT_3B
call try_mode_ID3 call try_mode_ID3
test eax,eax test eax,eax
jnz .stop_try jnz .stop_try
mov [MouseType],MT_3BScroll mov [MouseType],MT_3BScroll
call try_mode_ID4 call try_mode_ID4
test eax,eax test eax,eax
jnz .stop_try jnz .stop_try
mov [MouseType],MT_5BScroll mov [MouseType],MT_5BScroll
.stop_try: .stop_try:
mov bl, 0x20 ; read command byte mov bl, 0x20 ; read command byte
call kbd_cmd call kbd_cmd
cmp ah,1 cmp ah,1
je .exit je .exit
call kbd_read call kbd_read
cmp ah,1 cmp ah,1
je .exit je .exit
or al, 10b or al, 10b
push eax push eax
mov bl, 0x60 ; write command byte mov bl, 0x60 ; write command byte
call kbd_cmd call kbd_cmd
cmp ah,1 cmp ah,1
je .exit je .exit
pop eax pop eax
call kbd_write call kbd_write
cmp ah,1 cmp ah,1
je .exit je .exit
mov al, 0xF4 ; enable data reporting mov al, 0xF4 ; enable data reporting
call mouse_cmd call mouse_cmd
mov bl, 0xAE ; enable keyboard interface mov bl, 0xAE ; enable keyboard interface
call kbd_cmd call kbd_cmd
stdcall AttachIntHandler, 12, irq_handler, dword 0 stdcall AttachIntHandler, 12, irq_handler, dword 0
stdcall RegService, my_service, service_proc stdcall RegService, my_service, service_proc
ret ret
.fin: .fin:
;stdcall DetachIntHandler, 12, irq_handler ;stdcall DetachIntHandler, 12, irq_handler
mov bl, 0xA7 ; disable mouse interface mov bl, 0xA7 ; disable mouse interface
call kbd_cmd call kbd_cmd
xor eax, eax xor eax, eax
ret ret
.exit: .exit:
mov bl, 0xA7 ; disable mouse interface mov bl, 0xA7 ; disable mouse interface
call kbd_cmd call kbd_cmd
mov bl, 0xAE ; enable keyboard interface mov bl, 0xAE ; enable keyboard interface
call kbd_cmd call kbd_cmd
xor eax, eax xor eax, eax
ret ret
endp endp
proc service_proc stdcall, ioctl:dword proc service_proc stdcall, ioctl:dword
mov edi, [ioctl] mov edi, [ioctl]
mov eax, [edi+IOCTL.io_code] mov eax, [edi+IOCTL.io_code]
test eax, eax test eax, eax
jz .getversion jz .getversion
cmp eax,1 cmp eax,1
jz .gettype jz .gettype
.err: .err:
or eax, -1 or eax, -1
ret ret
.ok: .ok:
@ -120,113 +122,113 @@ proc service_proc stdcall, ioctl:dword
.getversion: .getversion:
cmp [edi+IOCTL.out_size], 4 cmp [edi+IOCTL.out_size], 4
jb .err jb .err
mov edi, [edi+IOCTL.output] mov edi, [edi+IOCTL.output]
mov dword [edi], PS2_DRV_VER ; version of driver mov dword [edi], PS2_DRV_VER ; version of driver
jmp .ok jmp .ok
.gettype: .gettype:
cmp [edi+IOCTL.out_size], 4 cmp [edi+IOCTL.out_size], 4
jb .err jb .err
mov edi, [edi+IOCTL.output] mov edi, [edi+IOCTL.output]
mov eax,[MouseType] mov eax,[MouseType]
mov dword [edi], eax ; mouse type mov dword [edi], eax ; mouse type
jmp .ok jmp .ok
endp endp
detect_mouse: detect_mouse:
mov bl, 0xAD ; disable keyboard interface mov bl, 0xAD ; disable keyboard interface
call kbd_cmd call kbd_cmd
cmp ah,1 cmp ah,1
je .fail je .fail
mov bl, 0xA8 ; enable mouse interface mov bl, 0xA8 ; enable mouse interface
call kbd_cmd call kbd_cmd
cmp ah,1 cmp ah,1
je .fail je .fail
mov al, 0xFF ; reset mov al, 0xFF ; reset
call mouse_cmd call mouse_cmd
jc .fail jc .fail
call mouse_read call mouse_read
jc .fail jc .fail
cmp al, 0xAA cmp al, 0xAA
jne .fail ; dead mouse jne .fail ; dead mouse
; get device ID ; get device ID
call mouse_read call mouse_read
jc .fail jc .fail
cmp al, 0x00 cmp al, 0x00
jne .fail ; unknown device jne .fail ; unknown device
xor eax,eax xor eax,eax
ret ret
.fail: .fail:
or eax,-1 or eax,-1
ret ret
try_mode_ID3: try_mode_ID3:
mov al, 0xF3 ;Set Sample Rate mov al, 0xF3 ;Set Sample Rate
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xC8 ;200d mov al, 0xC8 ;200d
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xF3 ;Set Sample Rate mov al, 0xF3 ;Set Sample Rate
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0x64 ;100d mov al, 0x64 ;100d
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xF3 ;Set Sample Rate mov al, 0xF3 ;Set Sample Rate
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0x50 ;80d mov al, 0x50 ;80d
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xF2 ;Get device id mov al, 0xF2 ;Get device id
call mouse_cmd call mouse_cmd
jc .fail jc .fail
call mouse_read call mouse_read
jc .fail jc .fail
cmp al, 0x03 cmp al, 0x03
jne .fail jne .fail
xor eax,eax xor eax,eax
ret ret
.fail: .fail:
or eax,-1 or eax,-1
ret ret
try_mode_ID4: try_mode_ID4:
mov al, 0xF3 ;Set Sample Rate mov al, 0xF3 ;Set Sample Rate
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xC8 ;200d mov al, 0xC8 ;200d
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xF3 ;Set Sample Rate mov al, 0xF3 ;Set Sample Rate
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xC8 ;100d mov al, 0xC8 ;100d
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xF3 ;Set Sample Rate mov al, 0xF3 ;Set Sample Rate
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0x50 ;80d mov al, 0x50 ;80d
call mouse_cmd call mouse_cmd
jc .fail jc .fail
mov al, 0xF2 ;Get device id mov al, 0xF2 ;Get device id
call mouse_cmd call mouse_cmd
jc .fail jc .fail
call mouse_read call mouse_read
jc .fail jc .fail
cmp al, 0x04 cmp al, 0x04
jne .fail jne .fail
@ -234,7 +236,7 @@ try_mode_ID4:
ret ret
.fail: .fail:
or eax,-1 or eax,-1
ret ret
include 'ps2m_iofuncs.inc' include 'ps2m_iofuncs.inc'
@ -242,12 +244,12 @@ include 'ps2m_irqh.inc'
section '.data' data readable writable align 16 section '.data' data readable writable align 16
version dd 0x00050005 version dd 0x00050005
my_service db 'ps2mouse',0 my_service db 'ps2mouse',0
;iofuncs data ;iofuncs data
mouse_cmd_byte db 0 mouse_cmd_byte db 0
mouse_nr_tries db 0 mouse_nr_tries db 0
mouse_nr_resends db 0 mouse_nr_resends db 0
;hid data ;hid data
@ -259,10 +261,10 @@ third_byte db 0
fourth_byte db 0 fourth_byte db 0
;main data ;main data
MouseType dd 0 MouseType dd 0
XMoving dd 0 XMoving dd 0
YMoving dd 0 YMoving dd 0
ZMoving dd 0 ZMoving dd 0
ButtonState dd 0 ButtonState dd 0
;timerTicks dd 0 ;timerTicks dd 0