Subversion Repositories Kolibri OS

Rev

Rev 121 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
425 victor 1
$Revision: 425 $
33 mario79 2
MouseSearch_PS2:
121 poddubny 3
	jmp	MouseSearch_PS2_begin
33 mario79 4
 
121 poddubny 5
mouse_error equ MouseSearch_PS2_begin.error
33 mario79 6
 
121 poddubny 7
 kb_cmd_c:
8
	call	kb_cmd
9
	jmp	check_kbd
33 mario79 10
 
121 poddubny 11
 kb_write_c:
12
	call	kb_write
13
	jmp	check_kbd
33 mario79 14
 
121 poddubny 15
 kb_read_c:
16
	call	kb_read
17
	;jmp	check_kbd
33 mario79 18
 
121 poddubny 19
 check_kbd:
20
	cmp	ah, 1
21
	je	mouse_error
22
	ret
33 mario79 23
 
121 poddubny 24
uglobal
25
  mouse_cmd_byte   db 0
26
  mouse_nr_tries   db 0
27
  mouse_nr_resends db 0
116 poddubny 28
 
121 poddubny 29
  mouse_error_esp  dd 0
30
endg
116 poddubny 31
 
32
 
121 poddubny 33
 mouse_cmd:
34
	mov	[mouse_cmd_byte], al
35
	mov	[mouse_nr_resends], 5
36
   .resend:
37
	mov	bl, 0xd4
38
	call	kb_cmd_c
39
	mov	al, [mouse_cmd_byte]
40
	call	kb_write_c
116 poddubny 41
 
121 poddubny 42
	call	mouse_read
116 poddubny 43
 
121 poddubny 44
	cmp	al, 0xFA	; ack
45
	jne	.noack
46
	ret
47
   .noack:
48
	cmp	al, 0xFE	; resend
49
	jne	.noresend
50
	dec	[mouse_nr_resends]
51
	jnz	.resend
52
   .noresend:
53
	jmp	mouse_error
116 poddubny 54
 
55
 
121 poddubny 56
 mouse_read:
57
	mov	[mouse_nr_tries], 100
58
   .repeat:
59
	call	kb_read
60
	cmp	ah, 1
61
	jne	.fin
62
	mov	esi, 10
63
	call	delay_ms
64
	dec	[mouse_nr_tries]
65
	jnz	.repeat
66
	jmp	mouse_error
67
   .fin:
68
	ret
116 poddubny 69
 
70
 
121 poddubny 71
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72
MouseSearch_PS2_begin:
73
	pushad
116 poddubny 74
 
121 poddubny 75
	mov	[mouse_error_esp], esp
116 poddubny 76
 
121 poddubny 77
        mov     bl, 0xAD	; disable keyboard interface
78
        call    kb_cmd_c
79
 
80
        mov     bl, 0xA8	; enable mouse interface
81
        call    kb_cmd_c
116 poddubny 82
 
121 poddubny 83
	mov	al, 0xFF	; reset
84
	call	mouse_cmd
85
 
86
	; now the mouse is in Reset Mode
87
	; get the Basic Assurance Test completion code
88
	call	mouse_read
89
	cmp	al, 0xAA
90
	jne	.error		; dead mouse
91
 
92
	; get device ID
93
	call	mouse_read
94
	cmp	al, 0x00
95
	jne	.error		; unknown device
96
 
97
	; reset completed successfully
98
 
99
	; enable mouse interrupt - IRQ12
100
	mov	bl, 0x20	; read command byte
101
	call	kb_cmd_c
102
	call	kb_read_c
103
	or	al, 10b
104
	push	eax
105
	mov	bl, 0x60	; write command byte
106
	call	kb_cmd_c
107
	pop	eax
108
	call	kb_write_c
109
 
110
	mov	al, 0xF4	; enable data reporting
111
	call	mouse_cmd
112
 
113
	mov	[ps2_mouse_detected], 1
114
	mov     bl, 0xAE	; enable keyboard interface
115
	call	kb_cmd
116
 
117
	mov	esi, boot_setmouse_type
118
	call	boot_log
119
 
120
	jmp	.finish
121
 
122
 
123
.error:
124
	mov	esp, [mouse_error_esp]    ; clear stack frame
125
	mov	[ps2_mouse_detected], 0
126
	mov	bl, 0xA7 ; disable mouse interface
127
	call	kb_cmd
128
  	mov	bl, 0xAE ; enable keyboard interface
129
  	call	kb_cmd
130
 
116 poddubny 131
.finish:
121 poddubny 132
	popad