diff --git a/kernel/trunk/build.bat b/kernel/trunk/build.bat index 858cfbcc5e..1effb6ee53 100644 --- a/kernel/trunk/build.bat +++ b/kernel/trunk/build.bat @@ -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 diff --git a/kernel/trunk/const.inc b/kernel/trunk/const.inc index fd4b13cb98..64d2074c9f 100644 --- a/kernel/trunk/const.inc +++ b/kernel/trunk/const.inc @@ -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) diff --git a/kernel/trunk/core/dll.inc b/kernel/trunk/core/dll.inc index b6a7a224f0..f1f8783d2c 100644 --- a/kernel/trunk/core/dll.inc +++ b/kernel/trunk/core/dll.inc @@ -141,6 +141,7 @@ align 16 jz .exit call ebx + mov [check_idle_semaphore],5 .exit: restore_ring3_context diff --git a/kernel/trunk/core/exports.inc b/kernel/trunk/core/exports.inc index 60230847c1..8a4e412e24 100644 --- a/kernel/trunk/core/exports.inc +++ b/kernel/trunk/core/exports.inc @@ -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 diff --git a/kernel/trunk/core/sys32.inc b/kernel/trunk/core/sys32.inc index 5ac9c68053..5203a8e2cb 100644 --- a/kernel/trunk/core/sys32.inc +++ b/kernel/trunk/core/sys32.inc @@ -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 diff --git a/kernel/trunk/data32.inc b/kernel/trunk/data32.inc index 0d32603153..6266f19427 100644 --- a/kernel/trunk/data32.inc +++ b/kernel/trunk/data32.inc @@ -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 diff --git a/kernel/trunk/drivers/imports.inc b/kernel/trunk/drivers/imports.inc index affd89511d..c9642c402b 100644 --- a/kernel/trunk/drivers/imports.inc +++ b/kernel/trunk/drivers/imports.inc @@ -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 diff --git a/kernel/trunk/drivers/ps2m_iofuncs.inc b/kernel/trunk/drivers/ps2m_iofuncs.inc new file mode 100644 index 0000000000..5c5d7d144e --- /dev/null +++ b/kernel/trunk/drivers/ps2m_iofuncs.inc @@ -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 diff --git a/kernel/trunk/drivers/ps2m_irqh.inc b/kernel/trunk/drivers/ps2m_irqh.inc new file mode 100644 index 0000000000..511822ebbb --- /dev/null +++ b/kernel/trunk/drivers/ps2m_irqh.inc @@ -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 ;возврат в подпрограмму diff --git a/kernel/trunk/drivers/ps2mouse.asm b/kernel/trunk/drivers/ps2mouse.asm new file mode 100644 index 0000000000..b8805889fb --- /dev/null +++ b/kernel/trunk/drivers/ps2mouse.asm @@ -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 diff --git a/kernel/trunk/gui/window.inc b/kernel/trunk/gui/window.inc index 55e47d790d..b13385c087 100644 --- a/kernel/trunk/gui/window.inc +++ b/kernel/trunk/gui/window.inc @@ -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 diff --git a/kernel/trunk/hid/mousedrv.inc b/kernel/trunk/hid/mousedrv.inc index 1ec31c4964..e4937f52d6 100644 --- a/kernel/trunk/hid/mousedrv.inc +++ b/kernel/trunk/hid/mousedrv.inc @@ -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 + diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 22dafe95be..29d87986af 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -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