📄 macro.lib
字号:
P_COPY EQU 1
P_AND EQU 2
P_OR EQU 3
P_XOR EQU 4
ENTERKEY EQU 0DH
ESCKEY EQU 27
BACKSPACE EQU 8
PAUSE macro
push ax
mov ah,8
int 21h
pop ax
endm
;响铃
alarm macro
push ax
push dx
mov dl, 7
mov ah, 2
int 21h
pop dx
pop ax
endm
;===========================================================
;显示汉字串
out_hz macro x, y, string, color
pusha
mov ax,x
mov bx,y
lea di,string
mov si, P_COPY
color
call printf
popa
endm
;显示汉字串
out_hz1 macro x, y, color
pusha
mov ax,x
mov bx,y
mov si, P_COPY
color
call printf
popa
endm
;延迟显示汉字
quick_zi macro x, y, string, color
mov ax,x
mov bx,y
lea di, string
color
call printf3
endm
slow_zi macro x, y, string, color
mov ax,x
mov bx,y
lea di, string
color
call printf2
endm
;显示ASCII码
out_asc macro x, y, string,color
mov ax,x
mov bx,y
lea di,string
mov si,P_COPY
color
call printf1
endm
;===========================================================
;中断的设置与恢复
;new_intr :要是中断子程序,old_intr是双字存储区
setintr macro new_intr, old_intr
pusha
mov al,1ch
mov ah,35h
int 21h
mov old_intr, es
mov old_intr+2, bx
push ds
mov dx,offset new_intr
mov ax,seg new_intr
mov ds,ax
mov al,1ch
mov ah,25h
int 21h
pop ds
popa
endm
res_oldintr macro oldintr
push ax
push dx
push ds
mov dx, oldintr+2
mov ds, oldintr
mov al,1ch
mov ah,25h
int 21h
pop ds
pop dx
pop ax
endm
;==========================================================
;颜色转换
;R,G,B 表示颜色
;bp返回压缩后的颜色值
RGB MACRO Blue,Green,Red
PUSH AX
XOR BP,BP
MOV AL,Red ; SET THE BLUE VALUE
SHR AL,3
AND AX,11111B
OR BP,AX
MOV AL,Green ; SET THE GREEN VALUE
SHL AX,3
AND AX,11111100000B
OR BP,AX
MOV AL,Blue ; SET THE RED VALUE
SHL AX,8
AND AX,1111100000000000B
OR BP,AX
POP AX
ENDM
;=============================================================
;新建dx指向的文件
create macro newfile
lea dx, newfile
mov ah,3ch
mov cx,0
int 21h
endm
;打开dx指向的文件
;openway中为文件属性
openfile macro filename,openway
lea dx,filename
mov ah,3dh
mov al,openway
int 21h
endm
;读文件
;filecode中为文件代号
;buf为目标缓冲区
;number中为字节数
readfile macro filecode ,buf,number
push bx
push cx
push dx
mov ah,3fh
mov bx,filecode
lea dx,buf
mov cx,number
int 21h
pop dx
pop cx
pop bx
endm
;写文件
;filecode中为文件代号
;number中为字节数
;buf为源缓冲区
writefile macro filecode,buf ,number
push bx
push cx
push dx
mov ah,40h
mov bx,filecode
lea dx,buf
mov cx,number
int 21h
pop dx
pop cx
pop bx
endm
;关闭文件
;filecode中为文件代号
closefile macro filecode
push ax
push bx
mov ah,3eh
mov bx,filecode
int 21h
pop bx
pop ax
endm
openpicture macro pic_x,pic_y,filename,writeway
pusha
mov ax,pic_y
mov bx,pic_x
mov si,writeway
lea dx,filename
call showbmp
popa
endm
;============================================================
;设置坐标
setxy macro x1,y1,x2,y2
mov bx,x1
mov ax,y1
mov dx,x2
mov cx,y2
endm
;=====================================================
;写屏幕区域
;x1,y1,x2,y2为起始点和结束点的坐标
;color设置颜色,为P_COPY方式
background macro x1,y1,x2,y2,color
pusha
setxy x1,y1,x2,y2
mov si, P_COPY
color
call fill
popa
endm
;highlight one line
highlightground macro num_line,color
pusha
mov ax,num_line
mov bx,20
mul bx
add ax,100
mov cx,ax
add cx,20
mov bx,120
mov dx,730
mov si, P_XOR
color
call fill
popa
endm
deleteline macro num_line
pusha
mov ax,num_line
mov bx,20
mul bx
add ax,100
mov cx,ax
add cx,20
mov bx,120
mov dx,730
mov si, P_COPY
RGB 0,0,0
call fill
popa
endm
;画框
;x1,y1,x2,y2为起始点和结束点的坐标,color为颜色
rect macro x1,y1,x2,y2,color
setxy x1,y1,x2,y2
mov si, P_COPY
color
call rectangle
endm
;画带倒角的框
box_jiao macro x1, y1, x2, y2, color
setxy x1,y1,x2,y2
mov si, P_COPY
color
call box
endm
;===========================================================
;延迟时间为100毫秒
delay macro second
local dl0
local dl500
local dl10ms
push cx
push dx
push ax
mov ax,second
dl0:
mov dx,100
dl500:
mov cx,2801
dl10ms:
loop dl10ms
dec dx
jnz dl500
dec ax
jnz dl0
pop ax
pop dx
pop cx
endm
;===========================================================
;接受字符
getchar macro x,y,zifu
mov ax,x
mov bx,y
lea di,temp
mov dx,2
call getstring
mov al,temp
mov zifu,al
endm
;得到用户输入的字符串
gets macro x,y,buf,length
mov ax,x
mov bx,y
lea di,buf
mov dx,length
call getstring
endm
;得到用户输入的密码
getpass macro x,y,buf,length
mov ax,x
mov bx,y
lea di,buf
mov dx,length
call getpassword
endm
;得到用户输入的数字字符串
getnums macro x,y,buf,length
mov ax,x
mov bx,y
lea di,buf
mov dx,length
call getstring_num
endm
getgrade macro x,y,num,length
local go_up
local next
local exit
go_up:
mov ax,x
mov bx,y
mov dx,length
call getinterage
cmp cx, 100
jbe next
background x,y, %x+30,%y+18,<RGB 0,0,0>
jmp go_up
next: mov num,cl
endm
;比较buf和buf1两个字符串
;num为字符串的最大长度,若相等
cmpstr macro buf,buf1,num
local lopa
local finish
local exit
pusha
lea si,buf
lea di,buf1
mov cx,num
lopa: mov al,[si]
mov bl,[di]
cmp al,0
je finish
cmp bl,0
je finish
cmp al,bl
jne exit
inc si
inc di
loop lopa
finish:
cmp al,bl
exit: popa
endm
;字符拷贝buf1为原串;buf为目的串
;num为长度
copystr macro buf,buf1,num
local lopa
local finish
pusha
lea di,buf
lea si,buf1
mov cx,num
lopa: mov ax,[si]
mov [di],ax
inc si
inc di
loop lopa
finish:popa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -