Subversion Repositories Kolibri OS

Rev

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

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