2007-05-14 14:57:41 +02:00
|
|
|
format MS COFF
|
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
DEBUG equ 1
|
|
|
|
|
2007-05-14 14:57:41 +02:00
|
|
|
include '../../../proc32.inc'
|
|
|
|
include '../../../imports.inc'
|
|
|
|
|
|
|
|
struc IOCTL
|
2013-05-28 20:04:03 +02:00
|
|
|
{ .handle dd ?
|
|
|
|
.io_code dd ?
|
|
|
|
.input dd ?
|
|
|
|
.inp_size dd ?
|
|
|
|
.output dd ?
|
|
|
|
.out_size dd ?
|
2007-05-14 14:57:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual at 0
|
|
|
|
IOCTL IOCTL
|
|
|
|
end virtual
|
|
|
|
|
|
|
|
public START
|
|
|
|
public version
|
|
|
|
|
|
|
|
DRV_ENTRY equ 1
|
|
|
|
DRV_EXIT equ -1
|
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
MT_3B equ 0
|
2007-05-14 14:57:41 +02:00
|
|
|
MT_3BScroll equ 3
|
|
|
|
MT_5BScroll equ 4
|
|
|
|
|
|
|
|
PS2_DRV_VER equ 1
|
|
|
|
|
|
|
|
section '.flat' code readable align 16
|
|
|
|
|
|
|
|
|
|
|
|
proc START stdcall, state:dword
|
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
cmp [state], DRV_ENTRY
|
2014-08-14 14:17:53 +02:00
|
|
|
jne .nothing
|
2007-05-14 14:57:41 +02:00
|
|
|
.init:
|
2014-08-14 14:17:53 +02:00
|
|
|
; disable keyboard and mouse interrupts
|
|
|
|
; keyboard IRQ handler can interfere badly otherwise
|
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
mov bl, 0x20 ; read command byte
|
|
|
|
call kbd_cmd
|
|
|
|
test ah,ah
|
|
|
|
jnz .fin
|
|
|
|
call kbd_read
|
|
|
|
test ah,ah
|
|
|
|
jnz .fin
|
|
|
|
popf
|
|
|
|
and al, 0xFC ; disable interrupts
|
|
|
|
or al, 0x10 ; disable keyboard
|
|
|
|
push eax
|
|
|
|
mov bl, 0x60 ; write command byte
|
|
|
|
call kbd_cmd
|
|
|
|
pop eax
|
|
|
|
call kbd_write
|
2007-05-14 14:57:41 +02:00
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
call detect_mouse
|
|
|
|
test eax,eax
|
|
|
|
jnz .exit
|
|
|
|
|
|
|
|
mov [MouseType],MT_3B
|
|
|
|
|
|
|
|
call try_mode_ID3
|
|
|
|
test eax,eax
|
|
|
|
jnz .stop_try
|
|
|
|
mov [MouseType],MT_3BScroll
|
|
|
|
|
|
|
|
call try_mode_ID4
|
|
|
|
test eax,eax
|
|
|
|
jnz .stop_try
|
|
|
|
mov [MouseType],MT_5BScroll
|
|
|
|
|
2007-05-14 14:57:41 +02:00
|
|
|
.stop_try:
|
|
|
|
|
2014-08-14 14:17:53 +02:00
|
|
|
mov al, 0xF4 ; enable data reporting
|
|
|
|
call mouse_cmd
|
|
|
|
|
|
|
|
; enable keyboard and mouse interrupts
|
2013-05-28 20:04:03 +02:00
|
|
|
mov bl, 0x20 ; read command byte
|
|
|
|
call kbd_cmd
|
|
|
|
call kbd_read
|
2014-08-14 14:17:53 +02:00
|
|
|
or al, 3 ; enable interrupts
|
|
|
|
and al, not 0x10 ; enable keyboard
|
2013-05-28 20:04:03 +02:00
|
|
|
push eax
|
|
|
|
mov bl, 0x60 ; write command byte
|
|
|
|
call kbd_cmd
|
|
|
|
pop eax
|
|
|
|
call kbd_write
|
|
|
|
|
2014-08-14 14:17:53 +02:00
|
|
|
stdcall AttachIntHandler, 12, irq_handler, 0
|
2013-05-28 20:04:03 +02:00
|
|
|
stdcall RegService, my_service, service_proc
|
|
|
|
ret
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
.fin:
|
2014-08-14 14:17:53 +02:00
|
|
|
popf
|
2013-05-28 20:04:03 +02:00
|
|
|
;stdcall DetachIntHandler, 12, irq_handler
|
|
|
|
mov bl, 0xA7 ; disable mouse interface
|
|
|
|
call kbd_cmd
|
2014-08-14 14:17:53 +02:00
|
|
|
.nothing:
|
2013-05-28 20:04:03 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
.exit:
|
2013-05-28 20:04:03 +02:00
|
|
|
mov bl, 0xA7 ; disable mouse interface
|
|
|
|
call kbd_cmd
|
2014-08-14 14:17:53 +02:00
|
|
|
|
|
|
|
; enable keyboard interrupt, leave mouse interrupt disabled
|
|
|
|
mov bl, 0x20 ; read command byte
|
|
|
|
call kbd_cmd
|
|
|
|
call kbd_read
|
|
|
|
or al, 1 ; enable keyboard interrupt
|
|
|
|
and al, not 0x10 ; enable keyboard
|
|
|
|
push eax
|
|
|
|
mov bl, 0x60 ; write command byte
|
2013-05-28 20:04:03 +02:00
|
|
|
call kbd_cmd
|
2014-08-14 14:17:53 +02:00
|
|
|
pop eax
|
|
|
|
call kbd_write
|
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2007-05-14 14:57:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
|
|
|
mov edi, [ioctl]
|
|
|
|
mov eax, [edi+IOCTL.io_code]
|
|
|
|
test eax, eax
|
2013-05-28 20:04:03 +02:00
|
|
|
jz .getversion
|
2007-05-14 14:57:41 +02:00
|
|
|
cmp eax,1
|
2013-05-28 20:04:03 +02:00
|
|
|
jz .gettype
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
.err:
|
2013-05-28 20:04:03 +02:00
|
|
|
or eax, -1
|
2007-05-14 14:57:41 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.ok:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.getversion:
|
|
|
|
cmp [edi+IOCTL.out_size], 4
|
2013-05-28 20:04:03 +02:00
|
|
|
jb .err
|
2007-05-14 14:57:41 +02:00
|
|
|
mov edi, [edi+IOCTL.output]
|
2013-05-28 20:04:03 +02:00
|
|
|
mov dword [edi], PS2_DRV_VER ; version of driver
|
2007-05-14 14:57:41 +02:00
|
|
|
jmp .ok
|
|
|
|
.gettype:
|
|
|
|
cmp [edi+IOCTL.out_size], 4
|
2013-05-28 20:04:03 +02:00
|
|
|
jb .err
|
2007-05-14 14:57:41 +02:00
|
|
|
mov edi, [edi+IOCTL.output]
|
|
|
|
mov eax,[MouseType]
|
2013-05-28 20:04:03 +02:00
|
|
|
mov dword [edi], eax ; mouse type
|
2007-05-14 14:57:41 +02:00
|
|
|
jmp .ok
|
|
|
|
endp
|
|
|
|
|
|
|
|
detect_mouse:
|
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
mov bl, 0xA8 ; enable mouse interface
|
2007-05-14 14:57:41 +02:00
|
|
|
call kbd_cmd
|
|
|
|
cmp ah,1
|
2013-05-28 20:04:03 +02:00
|
|
|
je .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
mov al, 0xFF ; reset
|
2007-05-14 14:57:41 +02:00
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
call mouse_read
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
cmp al, 0xAA
|
2013-05-28 20:04:03 +02:00
|
|
|
jne .fail ; dead mouse
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
; get device ID
|
|
|
|
call mouse_read
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
cmp al, 0x00
|
2013-05-28 20:04:03 +02:00
|
|
|
jne .fail ; unknown device
|
2014-08-14 14:17:53 +02:00
|
|
|
|
2007-05-14 14:57:41 +02:00
|
|
|
xor eax,eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
2013-05-28 20:04:03 +02:00
|
|
|
or eax,-1
|
2007-05-14 14:57:41 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
try_mode_ID3:
|
|
|
|
mov al, 0xF3 ;Set Sample Rate
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0xC8 ;200d
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0xF3 ;Set Sample Rate
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0x64 ;100d
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0xF3 ;Set Sample Rate
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0x50 ;80d
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
mov al, 0xF2 ;Get device id
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
call mouse_read
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
cmp al, 0x03
|
|
|
|
jne .fail
|
|
|
|
|
|
|
|
xor eax,eax
|
|
|
|
ret
|
|
|
|
.fail:
|
2013-05-28 20:04:03 +02:00
|
|
|
or eax,-1
|
2007-05-14 14:57:41 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
try_mode_ID4:
|
|
|
|
mov al, 0xF3 ;Set Sample Rate
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0xC8 ;200d
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0xF3 ;Set Sample Rate
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0xC8 ;100d
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0xF3 ;Set Sample Rate
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
mov al, 0x50 ;80d
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
mov al, 0xF2 ;Get device id
|
|
|
|
call mouse_cmd
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
call mouse_read
|
2013-05-28 20:04:03 +02:00
|
|
|
jc .fail
|
2007-05-14 14:57:41 +02:00
|
|
|
cmp al, 0x04
|
|
|
|
jne .fail
|
|
|
|
|
|
|
|
xor eax,eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
2013-05-28 20:04:03 +02:00
|
|
|
or eax,-1
|
2007-05-14 14:57:41 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
include 'ps2m_iofuncs.inc'
|
|
|
|
include 'ps2m_irqh.inc'
|
|
|
|
|
|
|
|
section '.data' data readable writable align 16
|
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
version dd 0x00050005
|
|
|
|
my_service db 'ps2mouse',0
|
2007-05-14 14:57:41 +02:00
|
|
|
|
|
|
|
;iofuncs data
|
2013-05-28 20:04:03 +02:00
|
|
|
mouse_cmd_byte db 0
|
|
|
|
mouse_nr_tries db 0
|
2007-05-14 14:57:41 +02:00
|
|
|
mouse_nr_resends db 0
|
|
|
|
|
|
|
|
;hid data
|
|
|
|
mouse_byte dd 0
|
|
|
|
|
|
|
|
first_byte db 0
|
|
|
|
second_byte db 0
|
|
|
|
third_byte db 0
|
|
|
|
fourth_byte db 0
|
|
|
|
|
|
|
|
;main data
|
2013-05-28 20:04:03 +02:00
|
|
|
MouseType dd 0
|
2007-05-14 14:57:41 +02:00
|
|
|
|
2013-05-28 20:04:03 +02:00
|
|
|
XMoving dd 0
|
|
|
|
YMoving dd 0
|
|
|
|
ZMoving dd 0
|
|
|
|
ButtonState dd 0
|
2007-05-14 14:57:41 +02:00
|
|
|
;timerTicks dd 0
|