kolibrios-fun/kernel/trunk/hid/m_ps2.inc
Mihail Semenyako (mike.dld) 92f657f440 Revision numbering fix
git-svn-id: svn://kolibrios.org@593 a494cfbc-eb01-0410-851d-a64ba20cac60
2007-07-27 13:52:03 +00:00

177 lines
5.6 KiB
PHP

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision$
; Íîìåð ïðèíèìàåìîãî îò ìûøè áàéòà
MouseByteNumber_2 DB 0
; Òðåõáàéòîâàÿ ñòðóêòóðà äàííûõ, ïåðåäàâàåìàÿ ìûøüþ
FirstByte_2 DB 0
SecondByte_2 DB 0
ThirdByte_2 DB 0
timer_ticks_ps2 dd 0
;**************************************
;* ÎÁÐÀÁÎÒ×ÈÊ ÏÐÅÐÛÂÀÍÈß ÎÒ ÌÛØÈ PS/2 *
;**************************************
check_mouse_data_ps2:
cmp [ps2_mouse_detected],0
je @@EndMouseInterrupt_2
call Wait8042BufferEmpty ;î÷èñòêà áóôåðà
in AL,0x60 ;ïîëó÷èòü ñêýí-êîä
; Âûáèðàòü ïîðÿäêîâûé íîìåð ïðèíèìàåìîãî áàéòà
cmp [MouseByteNumber_2],0
je @@SaveFirstByte
cmp [MouseByteNumber_2],1
je @@SaveSecondByte
cmp [MouseByteNumber_2],2
je @@SaveThirdByte
jmp @@Error_2
; Çàïèñàòü ïåðâûé áàéò ïîñûëêè
@@SaveFirstByte:
test AL,1000b ;ïåðâûé áàéò ïîñûëêè?
jz @@Error_2 ;ñáîé ñèíõðîíèçàöèè
mov [FirstByte_2],AL
inc [MouseByteNumber_2]
jmp @@EndMouseInterrupt_2
; Çàïèñàòü âòîðîé áàéò ïîñûëêè
@@SaveSecondByte:
mov [SecondByte_2],AL
inc [MouseByteNumber_2]
jmp @@EndMouseInterrupt_2
; Çàïèñàòü òðåòèé áàéò ïîñûëêè
@@SaveThirdByte:
mov [ThirdByte_2],AL
mov [MouseByteNumber_2],0
; (ïàêåò äàííûõ îò ìûøè ïðèíÿò ïîëíîñòüþ)
; Çàïèñàòü íîâîå çíà÷åíèå áàéòà ñîñòîÿíèÿ êíîïîê
mov al,[FirstByte_2] ;[0xfb01]
and eax,3
mov [BTN_DOWN],al
mov [mouse_active],1
; Âû÷èñëèòü íîâóþ X-êîîðäèíàòó êóðñîðà
; Çàíåñòè â AX ïåðåìåùåíèå ïî X
mov AH,0 ;äóáëèðóåì çíàê âî âñå ðàçðÿäû AH
mov AL,[FirstByte_2]
test AL,10000b
jz @@M0
mov AH,0FFh
; Çàíåñòè â AL ìëàäøèé áàéò
@@M0:
mov AL,[SecondByte_2]
call mouse_acceleration_ps2
; Âû÷èñëèòü íîâîå çíà÷åíèå êîîðäèíàòû
; êóðñîðà ïî X
add AX,[MOUSE_X] ;[XCoordinate]
jns @@M1
xor eax, eax
jmp @@M2
@@M1:
cmp AX,[ScreenWidth] ;ScreenLength
jl @@M2
mov AX,[ScreenWidth] ;ScreenLength-1
@@M2:
mov [MOUSE_X],AX ;[XCoordinate]
; Âû÷èñëÿåì íîâóþ Y-êîîðäèíàòó êóðñîðà
; Çàíåñòè â AX ïåðåìåùåíèå ïî Y
mov AH,0 ;äóáëèðóåì çíàê âî âñå ðàçðÿäû AH
mov AL,[FirstByte_2]
test AL,100000b
jz @@M3
mov AH,0FFh
; Çàíåñòè â AL ìëàäøèé áàéò
@@M3:
mov AL,[ThirdByte_2]
call mouse_acceleration_ps2
; Âû÷èñëèòü íîâîå çíà÷åíèå êîîðäèíàòû êóðñîðà
; ïî Y (Y-êîîðäèíàòà ìûøè PS/2 íàïðàâëåíà
; ïðîòèâîïîëîæíî ýêðàííîé)
neg AX
add AX,[MOUSE_Y] ;[YCoordinate]
jns @@M4
xor eax, eax
jmp @@M5
@@M4:
cmp AX,[ScreenHeight] ;ScreenHeigth
jl @@M5
mov AX,[ScreenHeight] ;ScreenHeigth-1
@@M5:
mov [MOUSE_Y],AX ;[YCoordinate]
; Ïîêàçàòü êóðñîð â íîâîé ïîçèöèè
mov eax,[timer_ticks]
mov [timer_ticks_ps2],eax
jmp @@EndMouseInterrupt_2
; Îáíàðóæåí ñáîé â ïîðÿäêå ïåðåäà÷è èíôîðìàöèè îò ìûøè
@@Error_2:
mov [MouseByteNumber_2],0
; Íîðìàëüíîå çàâåðøåíèå ïðåðûâàíè
@@EndMouseInterrupt_2:
call ready_for_next_irq_1
ret
mouse_acceleration_ps2:
push eax
mov eax,[timer_ticks]
sub eax,[timer_ticks_ps2]
cmp eax,[mouse_delay]
pop eax
ja @f
imul ax,[mouse_speed_factor]
@@:
ret
;***********************************************
;* ÎÆÈÄÀÍÈÅ Î×ÈÑÒÊÈ ÂÕÎÄÍÎÃÎ ÁÓÔÅÐÀ I8042 *
;* Ïðè âûõîäå èç ïðîöåäóðû: *
;* ôëàã ZF óñòàíîâëåí - íîðìàëüíîå çàâåðøåíèå, *
;* ôëàã ZF ñáðîøåí - îøèáêà òàéì-àóòà. *
;***********************************************
Wait8042BufferEmpty:
; push CX
; mov CX,0FFFFh ;çàäàòü ÷èñëî öèêëîâ îæèäàíè
;@@kb:
; in AL,64h ;ïîëó÷èòü ñòàòóñ
; test AL,10b ;áóôåð i8042 ñâîáîäåí?
; loopnz @@kb ;åñëè íåò, òî öèêë
; pop CX
push ecx
xor ecx,ecx
@@:
in al,64h
test al,00000010b
loopnz @b
pop ecx
;Åñëè ïðè âûõîäå èç ïîäïðîãðàììû ñáðîøåí
;ôëàã ZF - îøèáêà
ret ;âîçâðàò â ïîäïðîãðàììó
;***************************************
;* ÎÆÈÄÀÍÈÅ ÏÎÑÒÓÏËÅÍÈß ÄÀÍÍÛÕ ÎÒ ÌÛØÈ *
;***************************************
WaitMouseData:
; push CX
; mov CX,0FFFFh ;çàäàòü ÷èñëî öèêëîâ îæèäàíè
;@@mouse:
; in AL,64h ;îïðîñèòü ðåãèñòð ñòàòóñà
; test AL,100000b ;äàííûå ïîñòóïèëè?
; loopz @@mouse ;åñëè íåò, òî öèêë
; pop CX
push ecx
mov ECX,0FFFFh
@@:
in al,64h
test al,100000b
loopz @b
pop ecx
;Åñëè ïðè âûõîäå èç ïîäïðîãðàììû óñòàíîâëåí
;ôëàã ZF - îøèáêà
ret