1)ps2 mouse driver(removed from kernel)

2)new 2 modes for ps2-mouse (scrolling mouse and 5-button mouse)
3) added function 37.7 for mouse scrolling data

git-svn-id: svn://kolibrios.org@479 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
kastigar 2007-05-08 11:32:58 +00:00
parent dffe2cce57
commit 510a108c5d
13 changed files with 658 additions and 38 deletions

View File

@ -1,7 +1,7 @@
@echo off
set languages=en ru ge et
set drivers=sound sis infinity ati2d vmode
set drivers=sound sis infinity ati2d vmode ps2mouse
set targets=all kernel drivers skins clean
call :Check_Target %1

View File

@ -227,8 +227,10 @@ MOUSE_PORT equ (OS_BASE+0x000F604)
;unused
PS2_CHUNK equ (OS_BASE+0x000FB00)
MOUSE_SCROLL_H equ (OS_BASE+0x000FB08)
MOUSE_X equ (OS_BASE+0x000FB0A)
MOUSE_Y equ (OS_BASE+0x000FB0C)
MOUSE_SCROLL_V equ (OS_BASE+0x000FB0E)
MOUSE_COLOR_MEM equ (OS_BASE+0x000FB10)
COLOR_TEMP equ (OS_BASE+0x000FB30)

View File

@ -141,6 +141,7 @@ align 16
jz .exit
call ebx
mov [check_idle_semaphore],5
.exit:
restore_ring3_context

View File

@ -58,6 +58,9 @@ iglobal
szLFBAddress db 'LFBAddress',0
szLoadFile db 'LoadFile',0
szSendEvent db 'SendEvent',0
szSetMouseData db 'SetMouseData',0
szSleep db 'Sleep',0
szGetTimerTicks db 'GetTimerTicks',0
align 16
@ -109,6 +112,9 @@ kernel_export:
dd szGetCurrentTask , get_curr_task
dd szLoadFile , load_file
dd szSendEvent , send_event
dd szSetMouseData , set_mouse_data
dd szSleep , delay_ms
dd szGetTimerTicks , get_timer_ticks
exp_lfb:
dd szLFBAddress , 0
dd 0

View File

@ -50,7 +50,7 @@ iglobal
dd irq0 , irq_serv.irq_1, p_irq2 , p_irq3 ;irq_serv.irq_3
dd p_irq4 ,irq_serv.irq_5,p_irq6,irq_serv.irq_7
dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10
dd irq_serv.irq_11,p_irq12,irqD ,p_irq14,p_irq15
dd irq_serv.irq_11,irq_serv.irq_12,irqD ,p_irq14,p_irq15
times 16 dd unknown_interrupt
@ -274,15 +274,6 @@ p_irq4:
restore_ring3_context
iret
p_irq12:
save_ring3_context
mov ax, app_data ;os_data
mov ds, ax
mov es, ax
call check_mouse_data_ps2
restore_ring3_context
iret
p_irq14:
save_ring3_context
mov ax, app_data ;os_data

View File

@ -75,7 +75,8 @@ AMD_str db "AuthenticAMD",0
;szSound db 'SOUND',0
;szInfinity db 'INFINITY',0
szHwMouse db 'ATI2D',0
szHwMouse db 'ATI2D',0
szPS2MDriver db 'PS2MOUSE',0
szSTART db 'START',0
szEXPORTS db 'EXPORTS',0
@ -324,7 +325,6 @@ hd_entries rd 1 ;unused ? 0xfe10
mouse_active rd 1
mouse_pause rd 1
MouseTickCounter rd 1
ps2_mouse_detected rb 1
com1_mouse_detected rb 1
com2_mouse_detected rb 1
;* end code - Mario79

View File

@ -136,6 +136,15 @@ end if
if used SendEvent
extrn SendEvent
end if
if used SetMouseData
extrn SetMouseData
end if
if used Sleep
extrn Sleep
end if
if used GetTimerTicks
extrn GetTimerTicks
end if
if used LFBAddress
extrn LFBAddress
end if

View File

@ -0,0 +1,141 @@
kbd_read:
push ecx edx
mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
kr_loop:
in al,0x64
test al,1
jnz kr_ready
loop kr_loop
mov ah,1
jmp kr_exit
kr_ready:
push ecx
mov ecx,32
kr_delay:
loop kr_delay
pop ecx
in al,0x60
xor ah,ah
kr_exit:
pop edx ecx
ret
kbd_write:
push ecx edx
mov dl,al
in al,0x60
mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
kw_loop:
in al,0x64
test al,2
jz kw_ok
loop kw_loop
mov ah,1
jmp kw_exit
kw_ok:
mov al,dl
out 0x60,al
mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
kw_loop3:
in al,0x64
test al,2
jz kw_ok3
loop kw_loop3
mov ah,1
jmp kw_exit
kw_ok3:
mov ah,8
kw_loop4:
mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
kw_loop5:
in al,0x64
test al,1
jnz kw_ok4
loop kw_loop5
dec ah
jnz kw_loop4
kw_ok4:
xor ah,ah
kw_exit:
pop edx ecx
ret
kbd_cmd:
mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
c_wait:
in al,0x64
test al,2
jz c_send
loop c_wait
jmp c_error
c_send:
mov al,bl
out 0x64,al
mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
c_accept:
in al,0x64
test al,2
jz c_ok
loop c_accept
c_error:
mov ah,1
jmp c_exit
c_ok:
xor ah,ah
c_exit:
ret
mouse_cmd:
mov [mouse_cmd_byte], al
mov [mouse_nr_resends], 5
.resend:
mov bl, 0xd4
call kbd_cmd
cmp ah,1
je .fail
mov al, [mouse_cmd_byte]
call kbd_write
cmp ah, 1
je .fail
call mouse_read
cmp al, 0xFA
jne .noack
clc
ret
.noack:
cmp al, 0xFE ; resend
jne .noresend
dec [mouse_nr_resends]
jnz .resend
.noresend:
.fail:
stc
ret
mouse_read:
mov [mouse_nr_tries], 100
.repeat:
call kbd_read
cmp ah, 1
jne .fin
mov esi, 10
call Sleep
dec [mouse_nr_tries]
jnz .repeat
stc
ret
.fin:
clc
ret

View File

@ -0,0 +1,120 @@
;**************************************
;* ÎÁÐÀÁÎÒ×ÈÊ ÏÐÅÐÛÂÀÍÈß ÎÒ ÌÛØÈ PS/2 *
;**************************************
proc irq_handler
call Wait8042BufferEmpty ;î÷èñòêà áóôåðà
in al,0x60 ;ïîëó÷èòü ñêýí-êîä
cmp [mouse_byte],0
je .byte1
cmp [mouse_byte],1
je .byte2
cmp [mouse_byte],2
je .byte3
cmp [mouse_byte],3
je .byte4
jmp .error
.byte1:
test al,1000b ;ïåðâûé áàéò ïîñûëêè?
jz .error ;ñáîé ñèíõðîíèçàöèè
mov [first_byte],al
inc [mouse_byte]
jmp .exit
.byte2:
mov [second_byte],al
inc [mouse_byte]
jmp .exit
.byte3:
mov [third_byte],al
cmp [MouseType],MT_3B
je .full_packet
inc [mouse_byte]
jmp .exit
.byte4:
mov [fourth_byte],al
.full_packet:
mov [mouse_byte],0
mov al,byte [first_byte]
and eax,7
mov byte [ButtonState],al
cmp [MouseType],MT_3B
je .xy_moving
mov al,[fourth_byte]
cmp [MouseType],MT_3BScroll
je .z_moving
mov ah,al
and ah,00110000b
shr ah,1
or byte [ButtonState],ah
and al,00001111b
bt eax,3
jnc .z_moving
or al,11110000b
.z_moving:
movsx eax,al
mov [ZMoving],eax
.xy_moving:
mov ah,0 ;äóáëèðóåì çíàê âî âñå ðàçðÿäû AH
mov al,[first_byte]
test al,10000b
jz @f
mov ah,0FFh
@@:
mov al,[second_byte]
cwd
mov [XMoving],eax
mov ah,0 ;äóáëèðóåì çíàê âî âñå ðàçðÿäû AH
mov al,[first_byte]
test al,100000b
jz @f
mov ah,0FFh
@@:
mov al,[third_byte]
cwd
@@:
mov [YMoving],eax
stdcall SetMouseData, [ButtonState], [XMoving], [YMoving], [ZMoving], 0
jmp .exit
.error:
mov [mouse_byte],0
.exit:
ret
endp
;***********************************************
;* ÎÆÈÄÀÍÈÅ Î×ÈÑÒÊÈ ÂÕÎÄÍÎÃÎ ÁÓÔÅÐÀ I8042 *
;* Ïðè âûõîäå èç ïðîöåäóðû: *
;* ôëàã ZF óñòàíîâëåí - íîðìàëüíîå çàâåðøåíèå, *
;* ôëàã ZF ñáðîøåí - îøèáêà òàéì-àóòà. *
;***********************************************
Wait8042BufferEmpty:
push ecx
xor ecx,ecx
@@:
in al,64h
test al,00000010b
loopnz @b
pop ecx
ret ;âîçâðàò â ïîäïðîãðàììó

View File

@ -0,0 +1,275 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format MS COFF
include 'proc32.inc'
include 'imports.inc'
struc IOCTL
{ .handle dd ?
.io_code dd ?
.input dd ?
.inp_size dd ?
.output dd ?
.out_size dd ?
}
virtual at 0
IOCTL IOCTL
end virtual
public START
public version
DRV_ENTRY equ 1
DRV_EXIT equ -1
MT_3B equ 0
MT_3BScroll equ 1
MT_5BScroll equ 2
PS2_DRV_VER equ 1
section '.flat' code readable align 16
proc START stdcall, state:dword
cmp [state], DRV_ENTRY
jne .fin
.init:
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
.stop_try:
mov bl, 0x20 ; read command byte
call kbd_cmd
cmp ah,1
je .exit
call kbd_read
cmp ah,1
je .exit
or al, 10b
push eax
mov bl, 0x60 ; write command byte
call kbd_cmd
cmp ah,1
je .exit
pop eax
call kbd_write
cmp ah,1
je .exit
mov al, 0xF4 ; enable data reporting
call mouse_cmd
mov bl, 0xAE ; enable keyboard interface
call kbd_cmd
stdcall AttachIntHandler, 12, irq_handler
stdcall RegService, my_service, service_proc
ret
.fin:
;stdcall DetachIntHandler, 12, irq_handler
mov bl, 0xA7 ; disable mouse interface
call kbd_cmd
xor eax, eax
ret
.exit:
mov bl, 0xA7 ; disable mouse interface
call kbd_cmd
mov bl, 0xAE ; enable keyboard interface
call kbd_cmd
xor eax, eax
ret
endp
proc service_proc stdcall, ioctl:dword
mov edi, [ioctl]
mov eax, [edi+IOCTL.io_code]
test eax, eax
jz .getversion
cmp eax,1
jz .gettype
.err:
or eax, -1
ret
.ok:
xor eax, eax
ret
.getversion:
cmp [edi+IOCTL.out_size], 4
jb .err
mov edi, [edi+IOCTL.output]
mov dword [edi], PS2_DRV_VER ; version of driver
jmp .ok
.gettype:
cmp [edi+IOCTL.out_size], 4
jb .err
mov edi, [edi+IOCTL.output]
mov eax,[MouseType]
mov dword [edi], eax ; mouse type
jmp .ok
endp
detect_mouse:
mov bl, 0xAD ; disable keyboard interface
call kbd_cmd
cmp ah,1
je .fail
mov bl, 0xA8 ; enable mouse interface
call kbd_cmd
cmp ah,1
je .fail
mov al, 0xFF ; reset
call mouse_cmd
jc .fail
call mouse_read
jc .fail
cmp al, 0xAA
jne .fail ; dead mouse
; get device ID
call mouse_read
jc .fail
cmp al, 0x00
jne .fail ; unknown device
xor eax,eax
ret
.fail:
or eax,-1
ret
try_mode_ID3:
mov al, 0xF3 ;Set Sample Rate
call mouse_cmd
jc .fail
mov al, 0xC8 ;200d
call mouse_cmd
jc .fail
mov al, 0xF3 ;Set Sample Rate
call mouse_cmd
jc .fail
mov al, 0x64 ;100d
call mouse_cmd
jc .fail
mov al, 0xF3 ;Set Sample Rate
call mouse_cmd
jc .fail
mov al, 0x50 ;80d
call mouse_cmd
jc .fail
mov al, 0xF2 ;Get device id
call mouse_cmd
jc .fail
call mouse_read
jc .fail
cmp al, 0x03
jne .fail
xor eax,eax
ret
.fail:
or eax,-1
ret
try_mode_ID4:
mov al, 0xF3 ;Set Sample Rate
call mouse_cmd
jc .fail
mov al, 0xC8 ;200d
call mouse_cmd
jc .fail
mov al, 0xF3 ;Set Sample Rate
call mouse_cmd
jc .fail
mov al, 0xC8 ;100d
call mouse_cmd
jc .fail
mov al, 0xF3 ;Set Sample Rate
call mouse_cmd
jc .fail
mov al, 0x50 ;80d
call mouse_cmd
jc .fail
mov al, 0xF2 ;Get device id
call mouse_cmd
jc .fail
call mouse_read
jc .fail
cmp al, 0x04
jne .fail
xor eax,eax
ret
.fail:
or eax,-1
ret
include 'ps2m_iofuncs.inc'
include 'ps2m_irqh.inc'
section '.data' data readable writable align 16
version dd 0x00050005
my_service db 'ps2mouse',0
;iofuncs data
mouse_cmd_byte db 0
mouse_nr_tries db 0
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
MouseType dd 0
XMoving dd 0
YMoving dd 0
ZMoving dd 0
ButtonState dd 0
;timerTicks dd 0

View File

@ -967,8 +967,10 @@ windowactivate:
mov [ebx*2 + WIN_POS], si
jmp waloop2
wacont2:
mov [KEY_COUNT], byte 0 ; empty keyboard buffer
mov [BTN_COUNT], byte 0 ; empty button buffer
mov [KEY_COUNT], byte 0 ; empty keyboard buffer
mov [BTN_COUNT], byte 0 ; empty button buffer
mov [MOUSE_SCROLL_H], word 0 ; zero mouse z-index
mov [MOUSE_SCROLL_V], word 0 ; zero mouse z-index
popad
ret

View File

@ -25,11 +25,11 @@ uglobal
endg
iglobal
mouse_delay dd 10
mouse_speed_factor dw 3
mouse_delay dd 10
mouse_speed_factor: dd 3
mouse_timer_ticks dd 0
endg
include 'm_ps2.inc'
include 'm_com.inc'
@ -388,3 +388,65 @@ nodmp:
popad
ret
proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
mov eax,[BtnState]
mov [BTN_DOWN],eax
mov eax,[XMoving]
call mouse_acceleration
add ax,[MOUSE_X] ;[XCoordinate]
cmp ax,0
jge @@M1
mov eax,0
jmp @@M2
@@M1:
cmp ax,[ScreenWidth] ;ScreenLength
jl @@M2
mov ax,[ScreenWidth] ;ScreenLength-1
@@M2:
mov [MOUSE_X],ax ;[XCoordinate]
mov eax,[YMoving]
neg eax
call mouse_acceleration
add ax,[MOUSE_Y] ;[YCoordinate]
cmp ax,0
jge @@M3
mov ax,0
jmp @@M4
@@M3:
cmp ax,[ScreenHeight] ;ScreenHeigth
jl @@M4
mov ax,[ScreenHeight] ;ScreenHeigth-1
@@M4:
mov [MOUSE_Y],ax ;[YCoordinate]
mov eax,[VScroll]
add [MOUSE_SCROLL_V],ax
mov eax,[HScroll]
add [MOUSE_SCROLL_H],ax
mov [mouse_active],1
mov eax,[timer_ticks]
mov [mouse_timer_ticks],eax
ret
endp
mouse_acceleration:
push eax
mov eax,[timer_ticks]
sub eax,[mouse_timer_ticks]
cmp eax,[mouse_delay]
pop eax
ja @f
;push edx
imul eax,[mouse_speed_factor]
;pop edx
@@:
ret

View File

@ -583,6 +583,7 @@ include 'vmodeld.inc'
mov esi,boot_devices
call boot_log
call detect_devices
stdcall load_driver, szPS2MDriver
; TIMER SET TO 1/100 S
@ -1767,12 +1768,17 @@ sys_getsetup:
mov [esp+36],dword 1
ret
get_timer_ticks:
mov eax,[timer_ticks]
ret
iglobal
align 4
mousefn dd msscreen, mswin, msbutton, msset
dd app_load_cursor
dd app_set_cursor
dd app_delete_cursor
dd msz
endg
readmousepos:
@ -1784,8 +1790,9 @@ readmousepos:
; eax=4 load cursor
; eax=5 set cursor
; eax=6 delete cursor ; reserved
; eax=7 get mouse_z
cmp eax, 6
cmp eax, 7
ja msset
jmp [mousefn+eax*4]
msscreen:
@ -1816,6 +1823,21 @@ msbutton:
movzx eax,byte [BTN_DOWN]
mov [esp+36],eax
ret
msz:
mov edi, [TASK_COUNT]
movzx edi, word [WIN_POS + edi*2]
cmp edi, [CURRENT_TASK]
jne @f
mov ax,[MOUSE_SCROLL_H]
shl eax,16
mov ax,[MOUSE_SCROLL_V]
mov [esp+36],eax
mov [MOUSE_SCROLL_H],word 0
mov [MOUSE_SCROLL_V],word 0
ret
@@:
mov [esp+36],dword 0
ret
msset:
ret
@ -1939,7 +1961,7 @@ sys_midi:
detect_devices:
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
include 'detect/commouse.inc'
include 'detect/ps2mouse.inc'
;include 'detect/ps2mouse.inc'
;include 'detect/dev_fd.inc'
;include 'detect/dev_hdcd.inc'
;include 'detect/sear_par.inc'
@ -2348,8 +2370,7 @@ sys_background:
and edx,0xFF000000 ;255*256*256*256
and ecx,0x00FFFFFF ;255*256*256+255*256+255
add edx,ecx
; mov [ebx+IMG_BACKGROUND],edx
;mov [ebx+IMG_BACKGROUND],edx
push eax
mov eax,[img_background]
mov [ebx+eax],edx
@ -2395,8 +2416,10 @@ draw_background_temp:
.fin:
ret
nosb5:
ret
align 4
sys_getbackground:
@ -3298,24 +3321,12 @@ ret
wrmsr_instr:
;now counter in ecx
;(edx:eax) esi:edi => edx:esi
; Fast Call MSR can't be destroy
; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
cmp ecx, MSR_SYSENTER_CS
je @f
cmp ecx, MSR_SYSENTER_ESP
je @f
cmp ecx, MSR_SYSENTER_EIP
je @f
cmp ecx, MSR_AMD_STAR
je @f
mov eax, esi
wrmsr
@@:
mov eax,esi
wrmsr
mov [esp+36],eax
mov [esp+24],edx ;ret in ebx?
ret
cache_disable:
mov eax,cr0
or eax,01100000000000000000000000000000b