⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1024full.asm

📁 DOS下鼠标驱动程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	and ax,0ffh            ;make ax = 00YYh
	add dx,ax              ;获得该点的实际坐标y get the y cord into dx
	
	call mapmemory         ;进行地址映射 计算页号/页内地址
	
	;因为1024x768x真彩模式下,一个像素点占4个字节,所以利用inc si进行4次
	mov ax,0a000h
	mov es,ax
	mov bx,segoffset
	mov al,saveold[si]
	mov es:[bx],al
	inc si
	mov al,saveold[si]
	mov es:[bx+1],al
	inc si
	mov al,saveold[si]
	mov es:[bx+2],al
	inc si
	mov al,saveold[si]
	mov es:[bx+3],al
	inc si
CT:        
	inc di
	inc di      ;di+2  point to next word
	dec mousetypecounter
	jnz restorepixel
	popad
	ret

restore endp


;功能:保存当前鼠标位置的屏幕内容
;与恢复功能类似 restore procedure
save_mouse proc far
	pushad
	mov ebx,0
	mov edx,0
	mov ecx,0
	mov eax,0
	mov ax,mousetypelen
	shr ax,1                ;count/2 (DW)
	mov mousetypecounter,ax
	mov di,0
	mov si,0
savepixel:
	mov bx, xcord
	mov ax,mousetype[di]
	push ax
	mov cl,8
	shr ax,cl
	and ax,0ffh
	add bx,ax             ;get the x cord into bx

	pop ax
	mov dx, ycord
	and ax,0ffh
	add dx,ax             ;get the y cord into dx
	

	call mapmemory        

	
	mov ax,0a000h
	mov es,ax
	mov bx,segoffset
	mov al,es:[bx]
	mov savenew[si],al
	inc si
	mov al,es:[bx+1]
	mov savenew[si],al
	inc si
	mov al,es:[bx+2]
	mov savenew[si],al
	inc si
	mov al,es:[bx+3]
	mov savenew[si],al
	inc si
       
	inc di
	inc di      ;di+2  point to next word
	dec mousetypecounter
	jnz savepixel
	popad
	ret
save_mouse endp

;功能 :显示鼠标
show_mouse proc far
	pushad
	mov eax,0
	mov ebx,0
	mov ecx,0
	mov edx,0
	
	mov ax,mousetypelen
	shr ax,1                ;count/2 (DW)
	mov mousetypecounter,ax
	mov di,0
	mov si,0
lodrmos:
	mov bx, xcord
	mov ax,mousetype[di]
	push ax
	mov cl,8
	shr ax,cl
	and ax,0ffh
	add bx,ax             ;get the x cord into bx

	pop ax
	mov dx, ycord
	and ax,0ffh
	add dx,ax             ;get the y cord into dx
		
	cmp bx,1023
	jnbe cont
	jmp notexceed
notexceed:        
	call mapmemory        

	mov ax,0a000h
	mov es,ax
	mov bx,segoffset
	mov al,byte ptr mousecolor[si]
	mov es:[bx],al
	inc si
	mov al,byte ptr mousecolor[si]
	mov es:[bx+1],al
	inc si
	mov al,byte ptr mousecolor[si]
	mov es:[bx+2],al
	inc si
	mov al,byte ptr mousecolor[si]
	mov es:[bx+3],al
	inc si
cont:        
	inc di
	inc di      ;di+2  point to next word
	dec mousetypecounter
	jnz lodrmos
	popad
	ret
show_mouse endp
;****************************************************************************


;function: 画水平线
;input: 开始点坐标(lineend1x,lineend1y)终结点坐标 (lineend2x,lineend2y) 颜色linecolor(4 byte: use RGB 3 byte)
;note : lineend1y == lineend2y 如果不相等则只使用lineend1y
drawhorline proc far
	pusha
	mov segindexold,0ffffh    ;强制换页
	mov cx,lineend2x
	sub cx,lineend1x
	inc cx
	xor ebx,ebx
	xor edx,edx
	mov bx,lineend1x
	mov dx,lineend1y
horlinedraw:        
	call mapmemory
	mov ax,0a000h
	mov es,ax
	push bx
	mov bx,segoffset
	mov eax,dword ptr linecolor
	mov dword ptr es:[bx],eax
	pop bx
	inc bx
	loop horlinedraw
	popa
	ret
drawhorline endp

;function:画竖直线
;input: 起始点(lineend1x,lineend1y) 终结点 (lineend2x,lineend2y) 颜色linecolor(4 byte: use RGB 3 byte)
;note : lineend1x == lineend2x 如果不等则只使用lineend1x.
drawverline proc far
	pusha
	mov segindexold,0ffffh ;强制换页
	mov cx,lineend2y
	sub cx,lineend1y
	inc cx
	xor ebx, ebx
	xor edx, edx
	mov bx,lineend1x
	mov dx,lineend1y
verlinedraw:
	call mapmemory
	mov ax,0a000h
	mov es,ax
	push bx
	mov bx,segoffset
	mov eax,dword ptr linecolor
	mov dword ptr es:[bx],eax
	pop bx
	inc dx
	loop verlinedraw
	popa
	ret
drawverline endp

;function: 画矩形
; input 左上端点(rectend1x,rectend1y), 右下端点(rectend2x,rectend2y), 颜色rectcolor
drawrect proc far
	pusha
	mov ax,rectend1x
	mov lineend1x,ax
	mov ax,rectend2x
	mov lineend2x,ax
	mov cx,rectend2y
	sub cx,rectend1y
	inc cx
	mov eax,rectcolor
	mov dword ptr linecolor, eax
	mov ax,rectend1y
	mov lineend1y,ax
rectdraw:        
	call drawhorline
	inc lineend1y
	loop rectdraw
	popa
	ret
drawrect endp

;画左键(位置已经固定好)
drawleftbutton proc far
	pusha
	mov rectend1x,380
	mov rectend1y,270
	mov rectend2x,460
	mov rectend2y,380
	call drawrect
	popa
	ret
drawleftbutton  endp

;画右键(位置已经固定好)
drawrightbutton proc far
	pusha
	mov rectend1x,500
	mov rectend1y,270
	mov rectend2x,580
	mov rectend2y,380
	call drawrect
	popa
	ret
drawrightbutton  endp


;---------------------------
;将ax中的数转换为5位十进制,并存放到缓冲

btoasc proc far
	mov si,5
	mov cx,10
btoasc1:
	xor dx,dx
	div cx
	add dl,30h
	dec si
	mov [bx][si],dl
	or si,si
	jnz btoasc1
	ret
btoasc endp

showerror proc far
	cmp ah,01
	jz  e1
	cmp ah,02
	jz e2
	cmp ah,03
	jz e3
	cmp ah,04
	jz e4
	cmp ah,05
	jz e5
	jmp unknow
e1:
	mov bp,offset c200error1
	mov cx,c200error1len
	jmp s1
e2:
	mov bp,offset c200error2
	mov cx,c200error2len
	jmp s1
e3:
	mov bp,offset c200error3
	mov cx,c200error3len
	jmp s1
e4:
	mov bp,offset c200error4
	mov cx,c200error4len
	jmp s1
e5:     
	mov bp,offset c200error5
	mov cx,c200error5len
	jmp s1
unknow:
	mov bp,offset c200errorunknow
	mov cx,c200errunlen

s1:        
	mov dh,5
	mov dl,0
	mov bh,0
	mov al,0
	mov bl,7
	mov ah,13h
	int 10h
	ret
showerror endp

;*************************************************************************
;鼠标的定义:以左上角为基准点,鼠标上各点的坐标都是相对于基准点的相对坐标
;其中坐标轴x左向为正向,y下向为正向
;
;defind the  mouse's look
;Example: The word 070eh say: x=07,y=0e (the top-left point is based point)
mousetype  dw      0000h,0001h,0002h,0003h,0004h,0005h,0006h,0007h,  
		   0008h,0009h,000ah,000bh,000ch                     ;|
	   dw      0101h,0202h,0303h,0404h,0505h,0606h,0707h,0808h,0909h   ;\
	   dw      010bh,020ah,0309h,0409h,0509h,0609h,0709h,0809h         
	   dw      030bh,030ch,040dh,040eh,050fh    
	   dw      060ah,060bh,070ch,070dh,080eh
	   dw      0610h,0710h,0810h
	   ;内部点阵
	   dw      0102h,0103h,0104h,0105h,0106h,0107h,0108h,0109h,010ah,
		   0203h,0204h,0205h,0206h,0207h,0208h,0209h,
		   0304h,0305h,0306h,0307h,0308h,
		   0405h,0406h,0407h,0408h,
		   0506h,0507h,0508h,
		   0607h,0608h,
		   0708h,
		   030ah,040ah,050ah,
		   040bh,050bh,
		   040ch,050ch,060ch,
		   050dh,060dh,
		   050eh,060eh,070eh,
		   060fh,070fh,080fh
mousetypelen equ $-mousetype
mousetypecounter dw ?
saveold db mousetypelen*2 dup (0h)  ;保存鼠标位置的屏幕图象的数组
savenew db mousetypelen*2 dup (0h)  ;用于和saveold交替使用
mousecolor dd 43 dup (0),47 dup(0ffffffh);定义鼠标的颜色
mode dw  0              ;屏幕分辨率状态
segindexold dw 0        ;显存分页段号
segindex dw 0           ;显存分页段号
segoffset dw ?          ;显存分页内偏移地址
STATE DB ?      ;鼠标状态字节
count db 0      ;计数flag
xcord dw 0    ;鼠标左上角的X坐标,初始=0
ycord dw 0    ;鼠标左上角的Y坐标,初始=0
xcordold dw 0   ;前次的鼠标X位置
ycordold dw 0   ;前次的鼠标X位置

tip db 'Press any key to quit...'
tiplen equ $-tip
explainstr db 'Press left/right button of mouse,then you will see...'
explainstrlen equ $-explainstr
show1 db 'X='
showbuffer1 db 0,0,0,0,0
show2 db 'Y='
showbuffer2 db 0,0,0,0,0
c200error1 db 'Invalid function'
c200error1len equ $-c200error1
c200error2 db 'Invalid input'
c200error2len equ $-c200error2
c200error3 db 'Interface error'
c200error3len equ $-c200error3
c200error4 db 'need to resend'
c200error4len equ $-c200error4
c200error5 db 'no device handler installed'
c200error5len equ $-c200error5
c200errorunknow db 'Unknow reason wrong!'
c200errunlen equ $-c200errorunknow
rowcounter dw 0
columncounter dw 0

lineend1x dw 0
lineend1y dw 0
lineend2x dw 0
lineend2y dw 0
rectend1x dw 0
rectend1y dw 0
rectend2x dw 0
rectend2y dw 0
linecolor dd 0ffffffh
rectcolor dd 0ffffffh
code ends
	end begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -