📄 immacro.lib
字号:
;-------------------------------------------
;功能:将AX,BX,CX,DX寄存器入栈
;入口参数:无
;出口参数:无
;-------------------------------------------
pushx macro
push ax
push bx
push cx
push dx
endm
;-------------------------------------------
;功能:将AX,BX,CX,DX寄存器出栈
;入口参数:无
;出口参数:无
;-------------------------------------------
popx macro
pop dx
pop cx
pop bx
pop ax
endm
;-------------------------------------------
;功能:取光标位置
;入口参数:无
;出口参数:DL:光表的列号,DH:光标的行号
;-------------------------------------------
getpos macro
push ax
push bx
mov ah,03h
mov bx,0
int 10h
pop bx
pop ax
endm
;-------------------------------------------
;功能:自动设置光标位置
;入口参数:无
;出口参数:无
;-------------------------------------------
asetpos macro
pushx
mov ah,02h
mov bx,0
int 10h
popx
endm
;-------------------------------------------
;功能:设置光标位置
;入口参数:top:光标行号,left:光标列号
;出口参数:无
;-------------------------------------------
setpos macro top,left
pushx
mov ah,02h
mov bx,0
mov dh,top
mov dl,left
int 10h
popx
endm
;-------------------------------------------
;功能:修改菜单属性
;入口参数:top:光标行号,left:光标列号,
; width:宽度,attr:字符属性
;出口参数:无
;-------------------------------------------
changemenu macro top,left,width,attr
local chg
pushx
mov dl,left
chg:
setpos top,dl
mov bh,0
mov ah,08h
int 10h
mov bl,attr
mov cx,1
mov ah,09h
int 10h
inc dl
mov al,left
add al,width
cmp dl,al
jne chg
setpos top,left
popx
endm
;-------------------------------------------
;功能:绘制窗口
;入口参数:top:左上角行号,left:左上角列号
; bottiom:右下角行号,right:右下角列号
;出口参数:无
;-------------------------------------------
drawwindow macro attr,top,left,bottom,right
pushx
mov ah,06h
mov al,0
mov bh,attr
mov ch,top
mov cl,left
mov dh,bottom
mov dl,right
int 10h
popx
endm
;-------------------------------------------
;功能:绘制窗口上下边框
;入口参数:top:行号,left:列号
; width:长度,attr:字符属性
; l,m,r:要输出的字符
;出口参数:无
;-------------------------------------------
windowtandb macro l,m,r,top,left,width,attr
setpos top,left
outputchar l,attr,1
setpos top,left+1
outputchar m,attr,width-2
setpos top,left+width-1
outputchar r,attr,1
endm
;-------------------------------------------
;功能:绘制窗口左右边框
;入口参数:top:光标行号,left:光标列号
; char:输出的字符,attr:字符的属性
; width:长度
;出口参数:无
;-------------------------------------------
windowlandr macro char,top,left,width,attr
setpos top,left
outputchar char,attr,1
setpos top,left+width-1
outputchar char,attr,1
endm
;-------------------------------------------
;功能:输出字符
;入口参数:char:输出的字符,attr:字符属性
; num:输出的数目
;出口参数:无
;-------------------------------------------
outputchar macro char,attr,num
pushx
mov bh,0
mov ah,09h
mov al,char
mov bl,attr
mov cx,num
int 10h
popx
endm
;-------------------------------------------
;功能:输出字符串
;入口参数:str:输出的字符串,attr:字符串属性
; num:输出的数目,top:行号,left:列号
;出口参数:无
;-------------------------------------------
outputstr macro str,num,top,left,attr
pushx
push bp
mov ah,13h
lea bp,str
mov cx,num
mov dh,top
mov dl,left
mov bh,0
mov al,1
mov bl,attr
int 10h
pop bp
popx
endm
;-------------------------------------------
;功能:绘制子菜单(三个选项)
;入口参数:
;出口参数:无
;-------------------------------------------
submenu3 macro left,menu1,num1,menu2,num2,menu3,num3,width
local menu
drawwindow 70h,1,left,5,left+width
windowtandb 0dah,0c4h,0bfh,1,left,width+1,70h
mov al,2
menu:
windowlandr 0b3h,al,left,width+1,70h
inc al
cmp al,5
jne menu
windowtandb 0c0h,0c4h,0d9h,5,left,width+1,70h
outputstr menu1,num1,2,left+2,0fh
changemenu 2,left+1,8,0fh
outputstr menu2,num2,3,left+2,70h
changemenu 3,left+2,1,74h
outputstr menu3,num3,4,left+2,70h
changemenu 4,left+2,1,74h
setpos 2,left+2
endm
;-------------------------------------------
;功能:绘制子菜单(二个选项)
;入口参数:
;出口参数:无
;-------------------------------------------
submenu2 macro left,menu1,num1,menu2,num2,width
local menu
drawwindow 70h,1,left,4,left+width
windowtandb 0dah,0c4h,0bfh,1,left,width+1,70h
mov al,2
menu:
windowlandr 0b3h,al,left,width+1,70h
inc al
cmp al,4
jne menu
windowtandb 0c0h,0c4h,0d9h,4,left,width+1,70h
outputstr menu1,num1,2,left+2,0fh
changemenu 2,left+1,8,0fh
outputstr menu2,num2,3,left+2,70h
changemenu 3,left+2,1,74h
setpos 2,left+2
endm
;---------------------------------------------
;功能:读取窗口屏幕内容
;入口参数:top:左行号,left:左列号
; button:右行号,right:右列号
; memory:缓存名
;出口参数:无
;---------------------------------------------
readbscr macro top,left,button,right,memory
local incleft,readb
pushx
lea si,memory
add si,scrnum
mov bh,0
mov dh,top
mov dl,left
readb:
asetpos
mov ah,08h
int 10h
mov [si],al
mov [si+1],ah
add si,2
add scrnum,2
inc dl
cmp dl,right
jg incleft
jmp readb
incleft:
inc dh
mov dl,left
cmp dh,button
jng readb
popx
endm
;---------------------------------------------
;功能:写入窗口屏幕内容
;入口参数:top:左行号,left:左列号
; button:右行号,right:右列号
; memory:缓存名
;出口参数:无
;---------------------------------------------
writebscr macro top,left,button,right,memory
local incleft,writeb
pushx
lea si,memory
mov bh,button
mov bl,right
mov dh,top
mov dl,left
sub bl,dl
sub bh,dh
inc bl
inc bh
mov al,bh
mul bl
add ax,ax
mov bx,scrnum
sub bx,ax
add si,bx
writeb:
asetpos
outputchar [si],[si+1],1
add si,2
sub scrnum,2
inc dl
cmp dl,right
jg incleft
jmp writeb
incleft:
inc dh
mov dl,left
cmp dh,button
jng writeb
popx
endm
;---------------------------------------------
;功能:读取窗口屏幕内容
;入口参数:left:左列号
; memory:缓存名
;出口参数:无
;---------------------------------------------
readscr macro left,memory
local read
sub ax,ax
mov si,ax
read:
add ah,left
inc al
inc si
mov ch,ah
setpos al,ch
mov ah,08h
mov bh,0
int 10h
mov memory[si],al
mov memory[si+50],ah
mov ax,si
mov bl,10
div bl
cmp si,50
jne read
endm
;---------------------------------------------
;功能:写入窗口屏幕内容
;入口参数:left:左列号
; memory:缓存名
;出口参数:无
;---------------------------------------------
writescr macro left,memory
local read
sub ax,ax
mov si,ax
read:
add ah,left
inc al
inc si
mov ch,ah
setpos al,ch
mov al,memory[si]
mov ah,memory[si+50]
mov dl,al
mov dh,ah
outputchar dl,dh,1
mov ax,si
mov bl,10
div bl
cmp si,50
jne read
endm
;-------------------------------------------
;功能:设置光标属性
;入口参数:show:光标的开始行号
;出口参数:无
;-------------------------------------------
showcur macro show
push ax
push cx
mov ah,1
mov cl,0
mov ch,show
int 10h
pop cx
pop ax
endm
;------------------------------------------
;功能:初始化位置
;入口参数:posArray:位置数组,
; value:初始化的值
; num:初始化的个数
;出口参数:无
;------------------------------------------
initPos macro posArray,value,num
local init,end
push bx
mov bx,0
init:
cmp bx,num
jnl end
mov posArray[bx],value
inc bx
jmp init
end:
pop bx
endm
;-----------------------------------------
;功能:将ASCLL码转换为数字
;入口参数:ascll:ASCLL码数组
; BL:要转换的位数
; num2:存储转换后的数据的变量
;出口参数:DX为数值
;-----------------------------------------
AscllToNum macro ascll,num2
local continue,end
pushx
push si
push di
mov bh,0
mov dx,0
mov ax,1
lea si,ascll
lea di,num2
add si,bx
mov dl,[si]
cmp dl,0
je end
continue:
cmp bh,bl
jg end
mov dl,[si]
sub dl,48
push ax
mul dx
dec si
inc bh
add [di],ax
pop ax
MulAx 10
jmp short continue
end:
pop di
pop si
popx
endm
;----------------------------------------
;功能:将数值转换成ASCLL
;入口参数:ascll:ASCLL码数组
; num:要转换的数值(五位以内)
;出口参数:无
;----------------------------------------
NumToAscll macro ascll,num
local end,preChange
pushx
push si
lea si,ascll+5
mov ax,1
mov bx,10
mov ax,num
preChange:
cmp ax,0
je end
mov dx,0
div bx
or dl,30h
mov [si],dl
dec si
jmp short preChange
end:
pop si
popx
endm
;----------------------------------
;功能:与AX中的值相乘
;入口参数:num:相乘的倍数
;出口参数:AX:相乘后的值
;----------------------------------
MulAx macro num
local continue
push cx
push bx
mov cx,num-1
mov bx,ax
continue:
add ax,bx
loop continue
pop bx
pop cx
endm
;-----------------------------------
;功能:交换二个数据
;入口参数:INDATA1:数据1
; INDATA2:数据2
; NUM:交换的位数
;出口参数:无
;-----------------------------------
ChangeData macro indata1,indata2,num
local continue,end
push cx
push bx
mov bx,0
continue:
cmp bx,num
jnl end
mov cl,indata1[bx]
mov ch,indata2[bx]
mov indata1[bx],ch
mov indata2[bx],cl
inc bx
jmp continue
end:
pop bx
pop cx
endm
;-----------------------------------
;功能:打开文件
;入口参数:NAME:文件说明
;出口参数:AL=1 成功;AL=0 失败
; FILEHANDLE:存放文件句柄
;-----------------------------------
OpenFile macro name
local error,end
push dx
mov ah,3dh
lea dx,name
mov al,2 ;读写访问
int 21h
jc error
mov filehandle,ax
mov al,1
jmp end
error:
mov al,0
end:
pop dx
endm
;-----------------------------------
;功能:读文件
;入口参数:LENGTH:读的字节数
; BUF:缓冲区地址
; FILEHANDLE:存放文件句柄
;出口参数:AL=1 成功;AL=0 失败
;-----------------------------------
ReadFile macro length,buf
local error,end
push bx
push dx
push cx
lea dx,buf
mov ah,3fh
mov bx,filehandle
mov cx,length
int 21h
jc error
mov al,1
jmp end
error:
mov al,0
end:
pop cx
pop dx
pop bx
endm
;-----------------------------------
;功能:关闭文件
;入口参数:FILEHANDLE:存放文件句柄
;出口参数:AL=1 成功;AL=0 失败
;-----------------------------------
CloseFile macro
local error,end
push bx
push cx
push dx
mov ah,3eh
mov bx,filehandle
int 21h
jc error
mov al,1
jmp end
error:
mov al,0
end:
pop dx
pop cx
pop bx
endm
;-----------------------------------
;功能:写文件
;入口参数:LENGTH:写的字节数
; BUF:缓冲区地址
; FILEHANDLE:存放文件句柄
;出口参数:AL=1 成功;AL=0 失败
;-----------------------------------
WriteFile macro length,buf
local error,end
push bx
push cx
push dx
mov bx,filehandle
mov cx,length
mov ah,40h
lea dx,buf
int 21h
jc error
mov al,1
jmp end
error:
mov al,0
end:
pop dx
pop cx
pop bx
endm
;-----------------------------------
;功能:创建文件
;入口参数:NAME:文件说明
;出口参数:AL=1 成功;AL=0 失败
; FILEHANDLE:存放文件句柄
;-----------------------------------
CreateFile macro name
local error,end
push bx
push cx
push dx
mov ah,3ch
mov cx,0
lea dx,name
int 21h
jc error
mov al,1
jmp end
error:
mov al,0
end:
pop dx
pop cx
pop bx
endm
;---------------------------------
;功能:显示数据
;入口参数:INDATA:数据,
; NUM1:要显示的数据的个数
; NUM2:每页显示的数据个数
;出口参数:无
;---------------------------------
DataDisplay macro indata,num1,num2
local show,showend
pushx
push si
mov bh,num2
mov bl,num1
lea si,indata
initwin
outputstr text,63,3,3,1ah
mov al,4;当前的行
add bl,4
mov bh,num2
add bh,4
show:
cmp al,bl
jnl showend
cmp al,bh
jnl showend
outputstr [si],10,al,3,1eh
add si,10
outputstr [si],6,al,14,1eh
add si,10
outputstr [si],4,al,23,1eh
add si,10
outputstr [si],4,al,33,1eh
add si,10
outputstr [si],4,al,43,1eh
add si,10
outputstr [si],6,al,51,1eh
add si,10
outputstr [si],6,al,60,1eh
add si,22
inc al
jmp show
showend:
pop si
popx
endm
;-----------------------------------
;功能:动态分陪内存
;入口参数:NUM:分配的节数
;出口参数:AX:分配的段地址
; CF=0:调用成功,CF=1:调用失败
;-----------------------------------
Malloc macro num
push bx
mov ah,48h
mov bx,num
int 21h
pop bx
endm
;-----------------------------------
;功能:释放分配的内存
;入口参数:NUM:分配的节数
;出口参数:AX:分配的段地址
; CF=0:调用成功,CF=1:调用失败
;-----------------------------------
Free macro
mov ah,49h
int 21h
endm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -