Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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