[半原创]PS2 Mouse驱动 and 测试程序(DOS)
这是我学习assembly language第一周所写的一份PS/2 for 鼠标测试程序(DOS)。其中Mouse驱动部分我参照网上的一些代码,但已无从知道出处。呵呵,你还能找到这样好的PS/2的代码吗?如能帮助到您,希望您也能共享一些东西让大家分享。。代码很乱,我不重新排版了。 Download回去,你们自己排!这样也好多看看代码:lol;
; Ufoit PS2 Mouse test program Ver 0.9
; By Bini.Yi 易祝兵
; http://www.ufoit.com 计匠网
; 2002/04/06 YYYY/MM/DD
;
;
; This programtest the mouse buttonclick and move.
;
.model tiny
.586
.code
.stack100h
.startup
pusha
mov ax, 3533h
int 21h
mov word ptr cs:,es
mov word ptr cs:,bx
mov ax, 3574h
int 21h
mov word ptr cs:,es
mov word ptr cs:,bx
popa
call memmouse
mov ah, 00
mov al, 03
int 10h
mov ah, 06
mov al, 0
mov cx, 0
mov dh, 24
mov dl, 79
mov bh, 07h
int 10h
mov ax, 0000
mov bx, 0002
int 33h
cmp ax, 0000 ;if no mouse drive install
je errormsg ;show error MSG
mov ah, 02
mov bh, 00
mov dh, 25 ;Move point out screen
mov dl, 79
int 10h
call showmsg ;Show info
mov ax, 0001
int 33h
; mov ax, 000ah
; mov bx, 0000
; mov cl, 0h
; mov ch, 0F0h
; mov dl, 0h
; mov dh, 0F0h
; int 33h
mov ax, 0004h
mov cx, 0319
mov dx, 0103
int 33h
casemo: ;Case button click and point move
mov ax, 000bh ;and keyboard press
int 33h
cmp cx, 00h ;if point move....X
jne xmov
cmp dx, 00h ;if point move....Y
jne ymov
xymovend: ;X.Y move end
mov ax, 0003
int 33h
cmp bx, 0001 ;if left button clickshow ON
mov si, 1828
je listl
mov si, 1828
jne nlistl ;if left no click show OFF
testr:
cmp bx, 0002 ;if right button click show ON
mov si,1842
je listr
mov si,1842 ;if right no click show OFF
jne nlistl
casekey:
mov ah, 01 ;if any key press jump check
int 16h
jne kpress
mov al, ;check x flag
cmp al, 02h
jnb chkok
jmp casemo
xmov: ;if X moved, get the X flag+1
mov al,
inc al
mov , al
call passok
jmp xymovend
ymov: ;if Y moved, get the X flag+1
mov al,
inc al
mov , al
call passok
jmp xymovend
passok proc near
mov al,
cmp al, 1
je let0
jmp passret
let0:
mov , 1
passret:
ret
passok endp
chkok: ;if x flag and y flag>=2 and... then PASS
mov al,
cmp al, 02h
jb casemo
mov al,
cmp al, 1
jne casemo
mov al,
cmp al, 1
jnecasemo
mov , 1
mov al,
cmp al, 1
jnecasemo
mov ax,0002h
int 33h
call cleascr
call oldint
mov ax, 04c00h
int 21h
okexit:
mov ah, 4ch
mov al, 0
int 21h
listl: ;Show ON
pusha
mov ax, 0b800h
moves, ax
mov ah, 47h
mov al, 20h
mov es:, ax
add si, 02
moval, 4fh
mov es:, ax
mov al, 4eh
add si, 02
mov es:, ax
mov , 1
popa
jmp testr
listr: ;Show ON
pusha
mov ax, 0b800h
moves, ax
mov ah, 47h
mov al, 20h
mov es:, ax
add si, 02
moval, 4fh
mov es:, ax
mov al, 4eh
add si, 02
mov es:, ax
mov , 1
popa
jmpcasekey
nlistl: ;Show OFF
pusha
mov ax, 0b800h
moves, ax
mov ah, 17h
mov al, 4fh
mov es:, ax
add si, 02
moval, 46h
mov es:, ax
mov al, 46h
add si, 02
mov es:, ax
popa
cmp si, 1840
jae casekey
jmp testr
kpress: ;Check key press if press<ESC> then EXIT
cmp ah, 01h ;and return a error
je exit1
mov ah, 0ch ;if press other key then clear
mov al, 00 ;keyboard buffer
int 21h
jmp casemo
errormsg: ;if mouse driver no install
call oldint
lea dx, offset emsg
mov ah, 09h
int 21h
mov ah, 4ch
mov al, 2
int21h
exit1: ;error exit
mov ax, 0002h
int 33h
callcleascr
calloldint
mov ah, 4ch
mov al, 01
int 21h
cleascr proc near ;clear screen
pusha
mov ah, 06
mov al, 0
mov cx, 0
mov dh, 24
mov dl, 79
mov bh, 07h
int 10h
mov ah, 02
mov bh, 00
mov dh, 0
mov dl, 0
int 10h
popa
ret
cleascr endp
showmsg proc near ;Show info
pusha
lea di, offset showms
mov ax, 0b800h
mov es, ax
mov si, 0
mov cx, 480
mov ah, 07h
@@:
mov al, 20h
mov es:, ax
add si, 2
loop @b
mov cx,880
@@:
mov al,
inc di
cmp al,20h
je showch1
mov ah, 17h
jmp showch3
showch1:
mov ah, 07h
showch3:
mov es:, ax
add si, 2
loop @b
popa
ret
showmsg endp
oldint proc
pusha
mov ds, word ptr cs:
mov dx, word ptr cs:
mov ax, 2533h
int 21h
mov ds, word ptr cs:
mov dx, word ptr cs:
mov ax, 2574h
int 21h
popa
ret
oldint endp
memmouse proc
xor ax,ax
int 33h
cmp ax,0ffffh
jne not_loaded
mov , 1
ret
not_loaded:
mov ax,2574h
mov dx,offset new_isr
int 21h
mov ax,2533h
mov dx,offset new_33
int 21h
cli
mov bl,0a8h
call keyboard_cmd
mov bl,20h
call keyboard_cmd
call keyboard_read
or al,2
mov bl,60h
push ax
call keyboard_cmd
pop ax
call keyboard_write
mov bl,0d4h
call keyboard_cmd
mov al,0f4h
call keyboard_write
sti
ret
call_user_isr:
db 60h
mov cx,cs:
mov dx,cs:
mov di,0 ;cs:
mov si,0 ;cs:
mov word ptr cs:,0
mov word ptr cs:,0
mov bl,byte ptr cs:
xor bh,bh
call dword ptr cs:
db 61h
ret
new_isr:
pushf
cli
push ax
push bx
push cx
push dx
push di
push si
push es
push ds
push cs
pop ds
mov bl,0adh
call keyboard_cmd
cmp byte ptr ,0
je not_first_time
mov byte ptr ,0
call keyboard_read
call keyboard_read
call keyboard_read
jmp no_show
not_first_time:
mov word ptr ,0
mov cx,
mov dx,
call keyboard_read
and al,7 ;3
mov ah,
mov ,al
cmp al,ah
je no_button_change
and al,3
and ah,3
xor al,ah
xor bx,bx
push ax
test al,2
jz no_right_button_change
and ah,2
jz right_button_pressed
or bx,16
jmp no_right_button_change
right_button_pressed:
or bx,8
no_right_button_change:
pop ax
test al,1
jz no_left_button_change
and ah,1
jz left_button_pressed
or bx,4
jmp no_left_button_change
left_button_pressed:
or bx,2
no_left_button_change:
mov ,bx
no_button_change:
call keyboard_read
cbw
add ,ax
add ,ax
mov ax,
cmp ,ax
jg good_hor1
mov ,ax
good_hor1:
mov ax,
cmp ,ax
jle good_hor2
mov ,ax
good_hor2:
call keyboard_read
neg al
cbw
add ,ax
add ,ax
mov ax,
cmp ,ax
jg good_ver1
mov ,ax
good_ver1:
mov ax,
cmp ,ax
jle good_ver2
mov ,ax
good_ver2:
mov ax,
or ax,
or ax,ax
jz no_change_position
or word ptr ,1
no_change_position:
mov ax,
and ax,
jz no_call_user
call call_user_isr
no_call_user:
cmp byte ptr ,1
jne no_show
shr cx,3
shr dx,3
mov ax,80
mul dl
add ax,cx
shl ax,1
mov di,ax
mov ax,0b800h
mov es,ax
mov ax,
stosw
mov cx,
mov dx,
shr cx,3
shr dx,3
mov ax,80
mul dl
add ax,cx
shl ax,1
mov di,ax
mov ax,0b800h
mov es,ax
mov ax,es:
mov ,ax
not ah
and ah,7fh
stosw
no_show:
mov bl,0aeh
call keyboard_cmd
mov al,20h
out 0a0h,al
out 20h,al
pop ds
pop es
pop si
pop di
pop dx
pop cx
pop bx
pop ax
popf
iret
first_time db 1
buttons db 0
pos_x dw 0
pos_y dw 0
sm_flag dw 0
save_char dw 0
x_move dw 0
y_move dw 0
x_max dw 639
x_min dw 0
y_max dw 199
y_min dw 0
user_subroutine dw 0,0
user_mask dw 0
temp_mask dw 0
keyboard_read:
push cx
push dx
xor cx,cx
key_read_loop:
in al,64h
jmp $+2
jmp $+2
test al,1
jnz key_read_ready
loop key_read_loop
mov ah,1
jmp key_read_exit
key_read_ready:
push cx
mov cx,32
key_read_delay:
jmp $+2
jmp $+2
loop key_read_delay
pop cx
in al,60h
jmp $+2
jmp $+2
xor ah,ah
key_read_exit:
pop dx
pop cx
ret
keyboard_write:
push cx
push dx
mov dl,al
xor cx,cx
kbd_wrt_loop1:
in al,64h
jmp $+2
jmp $+2
test al,20h
jz kbd_wrt_ok1
loop kbd_wrt_loop1
mov ah,1
jmp kbd_wrt_exit
kbd_wrt_ok1:
in al,60h
xor cx,cx
kbd_wrt_loop:
in al,64h
jmp $+2
jmp $+2
test al,2
jz kbd_wrt_ok
loop kbd_wrt_loop
mov ah,1
jmp kbd_wrt_exit
kbd_wrt_ok:
mov al,dl
out 60h,al
jmp $+2
jmp $+2
xor cx,cx
kbd_wrt_loop3:
in al,64h
jmp $+2
jmp $+2
test al,2
jz kbd_wrt_ok3
loop kbd_wrt_loop3
mov ah,1
jmp kbd_wrt_exit
kbd_wrt_ok3:
mov ah,8
kbd_wrt_loop4:
xor cx,cx
kbd_wrt_loop5:
in al,64h
jmp $+2
jmp $+2
test al,1
jnz kbd_wrt_ok4
loop kbd_wrt_loop5
dec ah
jnz kbd_wrt_loop4
kbd_wrt_ok4:
xor ah,ah
kbd_wrt_exit:
pop dx
pop cx
ret
keyboard_cmd:
xor cx,cx
cmd_wait:
in al,64h
jmp $+2
jmp $+2
test al,2
jz cmd_send
loop cmd_wait
jmp cmd_error
cmd_send:
mov al,bl
out 64h,al
jmp $+2
jmp $+2
xor cx,cx
cmd_accept:
in al,64h
jmp $+2
jmp $+2
test al,2
jz cmd_ok
loop cmd_accept
cmd_error:
mov ah,1
jmp cmd_exit
cmd_ok:
xor ah,ah
cmd_exit:
ret
new_33:
cli
cmp al,0
je reset_mouse
cmp al,1
je show_mouse
cmp al,2
je hide_mouse
cmp al,3
je get_pos
cmp al,4
je set_pos
cmp al,7
je set_hor_pos
cmp al,8
je set_ver_pos
cmp al,0bh
je get_mouse_movement
cmp al,0ch
je set_subroutines
cmp al,14h
je swap_subroutines
iret
reset_mouse:
jmp _reset_mouse
show_mouse:
jmp _show_mouse
hide_mouse:
jmp _hide_mouse
get_pos:
jmp _get_pos
set_pos:
jmp _set_pos
set_hor_pos:
jmp _set_hor_pos
set_ver_pos:
jmp _set_ver_pos
get_mouse_movement:
jmp _get_mouse_movement
set_subroutines:
jmp _set_subroutines
swap_subroutines:
jmp _swap_subroutines
_reset_mouse:
mov byte ptr cs:,0
mov word ptr cs:,0
mov word ptr cs:,0
mov word ptr cs:,0
mov word ptr cs:,0
mov word ptr cs:,639
mov word ptr cs:,0
mov word ptr cs:,199
mov word ptr cs:,0
mov word ptr cs:,0
mov word ptr cs:,0
mov word ptr cs:,0
mov ax,0ffffh
mov bx,3
iret
_get_pos:
mov cx,cs:
mov dx,cs:
mov bx,word ptr cs:
xor bh,bh
iret
_get_mouse_movement:
mov cx,cs:
mov dx,cs:
mov word ptr cs:,0
mov word ptr cs:,0
iret
_show_mouse:
push ax
push bx
push di
push es
mov byte ptr cs:,1
mov ax,cs:
shr ax,3
mov bl,80
mul bl
mov bx,
shr bx,3
add ax,bx
shl ax,1
mov di,ax
mov ax,0b800h
mov es,ax
mov ax,es:
mov cs:,ax
not ah
and ah,7fh
mov es:,ax
pop es
pop di
pop bx
pop ax
iret
_hide_mouse:
push ax
push bx
push di
push es
mov byte ptr cs:,0
mov ax,cs:
shr ax,3
mov bl,80
mul bl
mov bx,
shr bx,3
add ax,bx
shl ax,1
mov di,ax
mov ax,0b800h
mov es,ax
mov ax,cs:
mov es:,ax
pop es
pop di
pop bx
pop ax
iret
_set_pos:
mov cx,cs:
mov dx,cs:
mov word ptr cs:,0
mov word ptr cs:,0
iret
_set_hor_pos:
call max_min
mov cs:,cx
mov cs:,dx
cmp cs:,cx
jge good_hor_min
mov cs:,cx
good_hor_min:
cmp cs:,dx
jle good_hor_max
mov cs:,dx
good_hor_max:
iret
_set_ver_pos:
call max_min
mov cs:,cx
mov cs:,dx
cmp cs:,cx
jge good_ver_min
mov cs:,cx
good_ver_min:
cmp cs:,dx
jle good_ver_max
mov cs:,dx
good_ver_max:
iret
max_min:
cmp cx,dx
jle no_swap
xchg cx,dx
no_swap:
ret
_set_subroutines:
mov cs:,dx
mov cs:,es
mov cs:,cx
iret
_swap_subroutines:
push word ptr cs:
push word ptr cs:
push word ptr cs:
mov cs:,dx
mov cs:,es
mov cs:,cx
pop dx
pop es
pop cx
iret
memmouse endp
endof_start:
emsg db 'No mouse driver install error!$'
old331 dw 0
old332 dw 0
old741 dw 0
old742 dw 0
memcopy db 0
okcheck db 0
pass db 0
chkl db 0
lk db 0
chkr db 0
rk db 0
showmsdb ' 赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯? '
db ' ?UfoitmousetestVer0.9Bini.Yi? '
db ' 韧屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯? '
db ' '
db ' 赏屯屯簧屯屯突 '
db ' ?OFF汉OFF? '
db ' 韧屯屯既屯屯图 '
db ' '
db ' 赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯突 '
db ' ?IFFail,Press<Esc>toExit? '
db ' 韧屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯图 '
end 真的是压箱底的东西了, 现在都不好找了!
哪天有空把这个驱动嵌入到我的一些 DOS 工具中来支持 Mouse, 哈哈! 好长...:L
谢谢!
回复 1# 的帖子
好东东,谢谢分享!
页:
[1]