📄 star1.asm
字号:
;star
;*********************************************************
up equ 48h ;scan code for up arrow
down equ 50h ;scan code for down arrow
right equ 4dh ;scan code for right arrow
left equ 4bh ;scan code for left arrow
esca equ 1bh ;escape key
cls1 equ 4dh ;clear star
cls2 equ 6dh ;clear star
win_ulc equ 10d ;window upper left column
win_ulr equ 8d ;window upper left row
win_lrc equ 80d ;window lower right column
win_lrr equ 16d ;window lower right row
win_width equ 70d ;width of window
exp1 equ 45h ; E expand the star
exp2 equ 65h ; e
con1 equ 43h ; C concentrate the star
con2 equ 63h ; c
help1 equ 48h ; H help information
help2 equ 68h ; h
blank equ 20h ;change the colour
sin0 equ 100d ;assume
sin36 equ 59d ;sin36*100
sin72 equ 95d ;sin72*100
cot36 equ 138d ;cot36*100
cot72 equ 32d ;cot72*100
cot0 equ 99d ;assume cot0=1
;*********************************************************
output macro x
call locate
lea dx,x
mov ah,09h
int 21h
call scroll_up
endm
cover macro
mov ah,0ch
mov al,00h
call generate
endm
get_lenth macro x
mov mema,ax
mov memd,dx
mov bx,x
mov ax,lenth
mul bx
mov bx,100
sub ax,0
div bx
mov bp,ax
mov ax,mema
mov dx,memd
endm
;********************************************************
datasg segment
mus_freq dw 2 dup(262),294,262,349
dw 330,2 dup(262),294
dw 262,392,349,-1
mus_time dw 2 dup(25),3 dup(50),100
dw 2 dup(25),3 dup(50),100
mess1 db ' THIS PROCE DISPLAY A DAYNAMIC STAR !!~~~~',13,10,'$'
mess2 db '*******************INSTRUCTION**********************',13,10,'$'
mess3 db '* --ESC:quit --E/e:expand --C/c:contract *',13,10,'$'
mess4 db '* --M/m:clear --C/c:contract --H/h:help *',13,10,'$'
mess5 db '* --use BLANK to change the color of the star *',13,10,'$'
mess6 db '* --use UP,DOWN,LEFT,and RIGHT to move the star *',13,10,'$'
mess7 db '* --Press any key to generate a star *'
str_len equ $-mess7
mess8 db ' YOU CLEARED THE STAR!',13,10,'$'
mess9 db ' Press ESC to quit.Other key to back',13,10,'$'
colf dw ?
rowf dw ?
mema dw ?
memb dw ?
memc dw ?
memd dw ?
mem1 dw ?
lenth dw 80d
colors db 1d
datasg ends
;**********************************************************************
codesg segment
main proc far
assume cs:codesg,ds:datasg,es:datasg
start: push ds
sub ax,ax
push ax
mov ax,datasg
mov ds,ax
mov es,ax
;
mov dx,80 ;给定起始点行列坐标
mov cx,120
start1: call help ;显示提示信息
mov ah,0 ;按任意键开始画图
int 16h
again0: call set_screen ;置画五角星时的显模式
again: mov ah,0ch ;BIOS 0CH功能调用写像素
mov al,colors ;初始颜色
call generate ;画五角星
call soundf ;乐曲同时响起,有按键则退出乐曲
again1: mov ah,0 ;检测按键
int 16h
;
cmp al,esca ;若为ESC则退出程序
jnz color ;否则判断是否为空格;空格键改变颜色
jmp far ptr exit
color: cmp al,blank
jnz next1
cover ;是空格;则宏调用覆盖程序清除当前图形
mov al,colors ;并让颜色值加一,重新画一个五角星
add al,1 ;当然是在当前的参数值下画
cmp al,16 ;如果颜色值不大于16(04H为16色显示)
jl nonew ;则继续改变颜色值
mov al,01h ;否则重置为初始值
nonew: mov colors,al
jmp again
;
next1: cmp al,exp1 ;不是空格,则继续判断
jz expand ;大E是放大,则放大
cmp al,exp2 ;小 e 放大
jz expand
cmp al,con1 ;大C 缩小
jz contract
cmp al,con2 ;小C 缩小
jz contract
cmp al,help1 ;大H 帮助
jz ishelp
cmp al,help2 ;小H 帮助
jz ishelp
cmp al,cls1
jz iscls ;大M 清屏
cmp al,cls2
jz iscls ;小M 清屏
jmp next ;都不是,则判断时候否移动键
expand:
cover ;放大的过程是先覆盖,再在当前参数下,增大
mov si,lenth ;长度,重画五角星
add si,10d
cmp si,280 ;大于限定长度,则BEEP 然后用户按键等待
jz beep0
mov lenth,si
jmp again
beep0: call beep
jmp again1 ;BEEP 返回等待输入那一步
contract:
cover ;缩小的过程也是先覆盖,再在当前参数下,减小
mov si,lenth ;长度,再画五角星
sub si,10d
cmp si,0 ;小于限定长度,则BEEP然后用户按键等待
jz beep1
mov lenth,si
jmp again
beep1: call beep
jmp again1 ;BEEP 返回等待输入那一步
ishelp: jmp start1 ;为帮助,则回到程序开始,但参数依然不变
iscls: call cls ;清屏并显示清屏信息
call soundf ;显示信息的时候乐曲响起
mov ah,0 ;等待用户输入
int 16h
cmp al,esca ;如果是ESC 则退出
jz exit
call set_screen ;否则返回清除后的屏幕 屏幕空白
mov ah,0
int 16h ;返回后等待用户按键,按下任意键
jmp start1 ;回到程序开始,参数依然不变
;
next: mov al,ah ;上DX+10,覆盖并重画
cmp al,up
jnz not_up
cover
sub dx,10
jmp again
not_up:
cmp al,down ;下DX-10 覆盖并重画
jnz not_down
cover
add dx,10
jmp again
not_down:
cmp al,right ;右 CX+10,覆盖并重画
jnz not_right
cover
add cx,10
jmp again
not_right:
cmp al,left ;左CX-10,覆盖并重画
jnz next2
cover
sub cx,10
next2: jmp again
;
exit: mov ah,0 ;退出时候重新置正常显示文本的屏幕
mov al,3
int 10h
mov ax,4c00h ;退出
int 21h
main endp
;------------------------------------
generate proc near
push ax
push bx
push cx
push dx
push bp
push si
push di
;first line
first: mov bx,1
mov colf,bx
mov bx,0
mov rowf,bx
get_lenth sin0
mov si,cot0
mov bx,0
call draw_line
;second line
mov bx,-1
mov colf,bx
mov bx,1
mov rowf,bx
get_lenth sin36
mov si,cot36
mov bx,0
call draw_line
;third line
mov bx,1
mov colf,bx
mov bx,-1
mov rowf,bx
get_lenth sin72
mov si,cot72
mov bx,0
call draw_line
;fourth line
mov bx,1
mov colf,bx
mov bx,1
mov rowf,bx
get_lenth sin72
mov si,cot72
mov bx,0
call draw_line
;fifth line
mov bx,-1
mov colf,bx
mov bx,-1
mov rowf,bx
get_lenth sin36
mov si,cot36
mov bx,0
call draw_line
pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
generate endp
;-----------------------------
draw_line proc near
mov mema,ax
mov memb,bx
mov memc,cx
mov memd,dx
mov di,bp ;loop times
loop1: mov ax,bp
sub ax,di ;lenth=ax-di
mov bx,ax ;store lenth
cmp rowf,-1
jz subax
cmp rowf,1
jz addax
jmp newdx
subax: sub dx,ax
jmp newdx
addax: add dx,ax
newdx:
mov ax,bx ;return lenth
mov bx,dx ;store new dx
mov mem1,100
sub ax,0
mul si
div mem1
cmp dx,50
jl nochan
add ax,1
nochan:
cmp colf,-1
jz subax1
cmp colf,1
jz addax1
jmp newcx
subax1: sub cx,ax
jmp newcx
addax1: add cx,ax
newcx:
mov dx,bx
mov ax,mema
mov bl,0
mov bh,0
int 10h
dec di
jz nosave
mov cx,memc ;start coloum of next times
mov dx,memd ;start row of next times
jmp loop1
nosave:
ret
draw_line endp
;------------------------------
locate proc near
mov ah,2 ;AH=2 ,BIOS功能调用置光标
mov dh,win_lrr ;设为右下的行,左上的列
mov dl,win_ulc ;既屏幕中心小窗口的左下角
mov bh,0
int 10h
ret
locate endp
;-----------------------------
scroll_up proc near ;上卷子程序
mov ah,6 ;06H BIOS功能调用
mov al,1 ;AL=1表示上卷一行,=0表示清屏
mov ch,win_ulr
mov cl,win_ulc
mov dh,win_lrr
mov dl,win_lrc
mov bh,7
int 10h
ret
scroll_up endp
;----------------------------
beep proc near
push ax
push bx
push cx
push dx
mov cx,1000
mov bx,6000
mov dx,cx
in al,61h
and al,11111100b ;关断定时器通道2的门控
trig:
xor al,2 ;触发61H端口第一位
out 61h,al
mov cx,bx
delay0: loop delay0 ;延时循环
dec dx ;脉冲持续时间
jne trig
pop dx
pop cx
pop bx
pop ax
ret
beep endp
;----------------------------------------
help proc near
push ax
push bx
push cx
push dx
push bp
push si
push di
mov ah,00h
mov al,03h ;设置显示方式为80*25,16色文本
int 10h
output mess1 ;output为宏定义,其中包含了光标定位子程序
output mess2 ;字符串输出以及一行上卷子程序,给定的参数
output mess3 ;就是要输出的字符串的变量名
output mess4 ;定位程序 locate
output mess5 ;上卷程序 scroll_up
output mess6
call locate ;显示闪烁提示字符串时,重新定位
mov bp,seg mess7
mov es,bp
mov bp,offset mess7
mov cx,str_len
mov bl,84h ;BL=84,黑底红字闪烁
mov al,1
mov ah,13h
int 10h
call scroll_up ;BL=84,黑底红字闪烁
output mess2
mov ah,1 ;鼠标不可见
mov cx,0001000000000000b
int 10h
pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
help endp
;-------------------------------------
cls proc near
push ax
push bx
push cx
push dx
push bp
push si
push di
call set_screen
call locate
lea dx,mess8
mov ah,09h
int 21h
lea dx,mess9
mov ah,09h
int 21h
mov ah,1
mov cx,0001000000000000b
int 10h
pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
cls endp
;--------------------------------
set_screen proc near
mov ah,0
mov al,0dh
int 10h
mov ah,0bh
mov bh,00
mov bl,1
int 10h
mov ah,0bh
mov bh,1
mov bl,2
int 10h
ret
set_screen endp
;--------------------------------------------------
soundf proc near ;发声子程序
push ax
push bx
push cx
push dx
push bp
push si
push di
begin: mov si,0 ;声音频率定义在数据段开始SI=0
lea bp,ds:mus_time ;时间
freq:
mov di,[si]
cmp di,-1 ;DI=-1表示所有频率运行完成
jne conti ;没有完成则继续响
jmp begin ;否则回到开始,循环发声
conti: mov bx,ds:[bp]
jmp beepy
beepx:
mov ah,0bh ;检测键盘状态
int 21h
inc al
jz ret1 ;有按键,则退出
add si,2
add bp,2
jmp freq ;否则继续执行下一频率发声
beepy: mov al,0b6h ;发声过程
out 43h,al
mov dx,12h
mov ax,348ch
div di
out 42h,al
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,3
out 61h,al
back:
mov cx,2800 ;延迟过程调用
call waitf
dec bl
jnz back
mov al,ah
out 61h,al
jmp beepx ;当本次声音响了以后才检测键盘
ret1: pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
soundf endp
waitf proc near ;延迟子程序
push ax
waitf1:
in al,61h
and al,10h
cmp al,ah
je waitf1
mov ah,al
loop waitf1
pop ax
ret
waitf endp
;------------------------------------------
codesg ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -