Subversion Repositories Kolibri OS

Rev

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

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