Subversion Repositories Kolibri OS

Rev

Rev 116 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 116 Rev 121
Line 1... Line -...
1
; for information on PS2 mouse/keyboard programming
-
 
2
; refer to http://www.computer-engineering.org/ps2mouse/
-
 
3
; and http://www.computer-engineering.org/ps2keyboard/
-
 
4
; respectively
-
 
5
 
-
 
6
MouseSearch_PS2:
1
MouseSearch_PS2:
7
        jmp .begin
2
	jmp	MouseSearch_PS2_begin
-
 
3
 
-
 
4
mouse_error equ MouseSearch_PS2_begin.error
Line 8... Line 5...
8
 
5
 
9
.kb_cmd_c:
6
 kb_cmd_c:
-
 
7
	call	kb_cmd
-
 
8
	jmp	check_kbd
-
 
9
 
-
 
10
 kb_write_c:
-
 
11
	call	kb_write
-
 
12
	jmp	check_kbd
-
 
13
 
-
 
14
 kb_read_c:
-
 
15
	call	kb_read
-
 
16
	;jmp	check_kbd
10
        call    kb_cmd
17
 
11
.check:
18
 check_kbd:
12
        cmp     ah, 1
19
	cmp	ah, 1
13
        je      @f
20
	je	mouse_error
14
        ret
-
 
15
@@:
-
 
16
        add     esp, 4  ; return address
-
 
Line -... Line 21...
-
 
21
	ret
-
 
22
 
-
 
23
uglobal
-
 
24
  mouse_cmd_byte   db 0
-
 
25
  mouse_nr_tries   db 0
-
 
26
  mouse_nr_resends db 0
-
 
27
 
-
 
28
  mouse_error_esp  dd 0
-
 
29
endg
-
 
30
 
-
 
31
 
-
 
32
 mouse_cmd:
-
 
33
	mov	[mouse_cmd_byte], al
-
 
34
	mov	[mouse_nr_resends], 5
-
 
35
   .resend:
-
 
36
	mov	bl, 0xd4
17
        jmp     .DataInputError
37
	call	kb_cmd_c
-
 
38
	mov	al, [mouse_cmd_byte]
18
 
39
	call	kb_write_c
-
 
40
 
-
 
41
	call	mouse_read
-
 
42
 
-
 
43
	cmp	al, 0xFA	; ack
-
 
44
	jne	.noack
19
.kb_write_c:
45
	ret
-
 
46
   .noack:
-
 
47
	cmp	al, 0xFE	; resend
-
 
48
	jne	.noresend
-
 
49
	dec	[mouse_nr_resends]
-
 
50
	jnz	.resend
-
 
51
   .noresend:
Line 20... Line 52...
20
        call    kb_write
52
	jmp	mouse_error
-
 
53
 
-
 
54
 
21
        jmp     .check
55
 mouse_read:
-
 
56
	mov	[mouse_nr_tries], 100
-
 
57
   .repeat:
-
 
58
	call	kb_read
-
 
59
	cmp	ah, 1
22
 
60
	jne	.fin
-
 
61
	mov	esi, 10
-
 
62
	call	delay_ms
-
 
63
	dec	[mouse_nr_tries]
-
 
64
	jnz	.repeat
Line -... Line 65...
-
 
65
	jmp	mouse_error
23
.kb_read_c:
66
   .fin:
24
        call    kb_read
67
	ret
25
        jmp     .check
68
 
Line -... Line 69...
-
 
69
 
-
 
70
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
 
71
MouseSearch_PS2_begin:
27
;--------------------------------------------
72
	pushad
Line 28... Line 73...
28
.begin:
73
 
29
        pushad
74
	mov	[mouse_error_esp], esp
Line 30... Line -...
30
 
-
 
31
        mov     bl, 0xAD        ; disable keyboard interface
-
 
32
        call    .kb_cmd_c
75
 
33
 
-
 
34
        mov     bl, 0xa8        ; enable mouse interface
76
        mov     bl, 0xAD	; disable keyboard interface
35
        call    .kb_cmd_c
-
 
36
 
-
 
Line 37... Line 77...
37
        mov     bl, 0xd4        ; to mouse
77
        call    kb_cmd_c
38
        call    .kb_cmd_c
78
     
39
        mov     al, 0xFF        ; reset
79
        mov     bl, 0xA8	; enable mouse interface
40
        call    .kb_write_c
80
        call    kb_cmd_c
41
        call    .kb_read_c
81
 
-
 
82
	mov	al, 0xFF	; reset
42
        cmp     al, 0xFA        ; ack
83
	call	mouse_cmd
43
        jne     .no_ack
84
 
44
 
85
	; now the mouse is in Reset Mode
45
        ; now the mouse is in Reset Mode
86
	; get the Basic Assurance Test completion code
Line 46... Line 87...
46
        ; get the Basic Assurance Test completion code
87
	call	mouse_read
Line 47... Line 88...
47
        call    .kb_read_c
88
	cmp	al, 0xAA
48
        cmp     al, 0xAA
89
	jne	.error		; dead mouse
49
        jne     .dead_mouse
90
 
50
        ; get device ID
91
	; get device ID
51
        call    .kb_read_c
92
	call	mouse_read
52
        cmp     al, 0x00
93
	cmp	al, 0x00
53
        jne     .unknown_device
94
	jne	.error		; unknown device
54
 
95
 
55
        ; reset completed successfully
96
	; reset completed successfully
56
 
97
 
Line 57... Line -...
57
        ; enable mouse interrupt - IRQ12
-
 
58
        mov     bl, 0x20        ; read command byte
-
 
59
        call    .kb_cmd_c
98
	; enable mouse interrupt - IRQ12
60
        call    .kb_read_c
-
 
61
        or      al, 10b         ; set mouse IRQ bit
-
 
62
        push    eax
-
 
63
        mov     bl, 0x60        ; write command byte
-
 
64
        call    .kb_cmd_c
-
 
65
        pop     eax
-
 
66
        call    .kb_write_c
-
 
67
 
-
 
68
        mov     bl, 0xd4        ; to mouse
-
 
69
        call    .kb_cmd_c
-
 
70
        mov     al, 0xf4        ; enable data reporting
-
 
71
        call    .kb_write_c
-
 
72
        call    .kb_read_c
-
 
73
        cmp     al, 0xFA
-
 
74
        jne     .no_ack
-
 
75
 
-
 
76
;       jmp     @f
-
 
77
;.set_sample_rate:
-
 
78
;       push    eax
-
 
79
;       mov     bl, 0xd4        ; to mouse
-
 
80
;       call    .kb_cmd_c
-
 
81
;       mov     al, 0xF3        ; set sample rate
-
 
82
;       call    .kb_write_c
-
 
83
;       call    .kb_read_c      ; ack
-
 
84
;       pop     eax
99
	mov	bl, 0x20	; read command byte
85
;       call    .kb_write_c
-
 
86
;       call    .kb_read_c      ; ack
-
 
87
; @@:
-
 
88
;       mov     eax, 200
-
 
89
;       call    .set_sample_rate
-
 
90
;       mov     eax, 100
-
 
91
;       call    .set_sample_rate
-
 
92
;       mov     eax, 80
-
 
93
;       call    .set_sample_rate
-
 
94
;       mov     bl, 0xd4
-
 
Line 95... Line 100...
95
;       call    .kb_cmd_c
100
	call	kb_cmd_c
96
;       mov     al, 0xF2        ; read device type
101
	call	kb_read_c
97
;       call    .kb_write_c
102
	or	al, 10b
Line 98... Line 103...
98
;       call    .kb_read_c      ; ack
103
	push	eax
99
;       call    .kb_read_c      ; mouse ID
104
	mov	bl, 0x60	; write command byte
Line 100... Line 105...
100
;       cmp     al, 0x03
105
	call	kb_cmd_c
Line 101... Line -...
101
;       jne     .no_scroll
-
 
102
;       mov     [ps2_mouse_scroll], 1
106
	pop	eax
103
;       ; it'll send 4-byte packets instead of 3-byte ones
-
 
104
;       ; the last byte of a packet represents z-axis movement
107
	call	kb_write_c
105
; .no_scroll:
108
 
106
 
109
	mov	al, 0xF4	; enable data reporting
107
        mov     [ps2_mouse_detected], 1
110
	call	mouse_cmd
108
        mov     bl, 0xAE        ; enable keyboard interface
111
 
109
        call    .kb_cmd_c
112
	mov	[ps2_mouse_detected], 1