📄 ss.asm
字号:
mov dh,13
mov dl,16
call showstr
mov si,offset gametxt18
mov dh,13
mov dl,20
call showstr
call delay
mov si,offset gametxt19
mov dh,15
mov dl,10
call showstr
call delay
mov si,offset gametxt20 ;score
mov ax,r1score
call dtoc
mov dh,15
mov dl,23
call showstr
call delay
mov dh,17
mov dl,10
cmp rolehead,1
je r1win
mov si,offset gametxt13
call showstr
jmp short role2show
r1win: mov si,offset gametxt14
call showstr
;--------------------------------------------
role2show:mov si,offset gametxt24
mov dh,5
mov dl,56
call showstr
mov ah,2 ;显示role2头像
mov bh,0
mov dh,5
mov dl,63
int 10h
mov al,2
mov color,4
call showchar
mov si,offset gametxt15
mov dh,7
mov dl,50
call showstr
call delay
mov si,offset gametxt20 ;money
mov ax,r2money
call dtoc
mov dh,9
mov dl,56
call showstr
mov si,offset gametxt16
mov dh,9
mov dl,60
call showstr
call delay
mov si,offset gametxt20 ;flower
mov ax,r2flower
call dtoc
mov dh,11
mov dl,56
call showstr
mov si,offset gametxt17
mov dh,11
mov dl,60
call showstr
call delay
mov si,offset gametxt20 ;step
mov ax,r2step
call dtoc
mov dh,13
mov dl,56
call showstr
mov si,offset gametxt18
mov dh,13
mov dl,60
call showstr
call delay
mov si,offset gametxt19
mov dh,15
mov dl,50
call showstr
call delay
mov si,offset gametxt20 ;score
mov ax,r2score
call dtoc
mov dh,15
mov dl,63
call showstr
call delay
mov dh,17
mov dl,50
cmp rolehead,2
je r2win
mov si,offset gametxt13
call showstr
jmp short showover
r2win: mov si,offset gametxt14
call showstr
;--------------------------------------------
showover:mov dh,20 ;happy new year
mov dl,24
mov si,offset gametxt9
call showstr
call delay
mov si,offset gametxt21 ;over
mov dh,23
mov dl,15
call showstr
mov dh,23 ;光标定位到最后
mov dl,65
mov ah,2
mov bh,0
int 10h
loop3: mov ah,0
int 16h
cmp ah,01
je gameover1
cmp ah,1ch
je gameover2
jmp short loop3
gameover1:mov ax,4c00h
int 21h
gameover2:jmp near ptr gamego
;------------------------------------------------
;名称: addr
;功能: 计算当前dh、dl在内存中的位置,用es:di返回
addr: push dx
push ax
mov ax,0b800h
mov es,ax
mov al,160
mul dh
mov di,ax
mov al,2
mul dl
add di,ax
pop ax
pop dx
ret
;------------------------------------------------
;定义变量
;当前角色的属性
rolehead db 0 ;存储当前要显示的人物头像
color db 0 ;存储当前要使用的前景颜色
step dw 0
flower dw 0
money dw 0
score dw 0
;角色1的属性
role1 dw 0 ;存储角色1当前应在的行列数
r1step dw 0
r1flower dw 0
r1money dw 0
r1score dw 0
;角色2的属性
role2 dw 0 ;存储角色2当前应在的行列数
r2step dw 0
r2flower dw 0
r2money dw 0
r2score dw 0
;----------------------------------------------------------------
;以下是fostest界面要显示的信息
gametxt1:db ' KCSJ',0
gametxt2:db '============',0
gametxt3:db ' ^_^',0
gametxt4:db ' Welcome to Kcsj',0
gametxt5:db ' ==========================',0
gametxt6:db 'Developed by kc 2007.07',0
gametxt7:db ' Puzzle [3.0.0]',0
gametxt8:db ' >GOAL<',0
gametxt9:db ' ^_^ Happy New Year~! ^_^',0
gametxt10:db 'Best Wishes from kcsj~! Now Go --->',0
gametxt11:db 'Play now? (Y/N):',0
gametxt12:db 1,' ',1,' ',1,' ',1,' ',1,' ',1,' ',1,' ',1,0
gametxt13:db ' :( Bad luck, you fail~! ',0
gametxt14:db '^_^ Good luck, you win~! ^_^',0
gametxt15:db 'You got:',0
gametxt16:db 'money',0
gametxt17:db 'flowers',0
gametxt18:db 'steps you walked',0
gametxt19:db 'Final score:',0
gametxt20:db ' ',0
gametxt21:db 'Press esc to exit, press enter to play again......',0
gametxt22:db 'Winner:',0
gametxt23:db 'role1:',0
gametxt24:db 'role2:',0
;-----------------------------------------------------------------
;以下是迷宫图,每行45个字符,均从第18列开始
puzzletxt0: db ' *^$^*^$^*^$^*^$^*^_^*^$^*^$^*^$^*^$^*',0
puzzletxt1: db '---------------------------------------------',0
puzzletxt2: db ' | | | |',0
puzzletxt3: db '| | ----- | ----- | --------- |',0
puzzletxt4: db '| | *^_^* | | | $ | | * | |',0
puzzletxt5: db '| --------- | | | |---| | | |',0
puzzletxt6: db '| | | * | | |',0
puzzletxt7: db '|-----------| | | | | * | |-------|',0
puzzletxt8: db '| $ | | | | | |',0
puzzletxt9: db '| |---| | | * | | * | |-------| |',0
puzzletxt10:db '| | * | | * | $ | | | | | $ |',0
puzzletxt11:db '| | | --------- |---| | | |---|',0
puzzletxt12:db '| | | | | | |',0
puzzletxt13:db '| | ----------------- |---| |---| |',0
puzzletxt14:db '| $$$ | | | $ | |',0
puzzletxt15:db '| |---------------- | | |---| | |',0
puzzletxt16:db '| | * | | | | * |',0
puzzletxt17:db '| |---- |---- | | |---- |---|',0
puzzletxt18:db '| |$ | * | |$ ',0
puzzletxt19:db '---------------------------------------------',0
puzzletxt20:db 'Score = 500 - step + money*50 + flour*100',0
;-----------------------------------------------------------------
;*************************** ****************************
;名称: showstr
;功能: 在指定的位置,显示一个用0结束的字符串圣诞节
;参数: (dh)=行号(取值范围0-24),(dl)=列号(取值范围0-79),
; ds:si指向字符串的首地址
;返回: 用ax返回显示的字符串的长度(包括结束标记0)
; 并根据显示的字符串的长度适当的换行
showstr:push bx
push cx
push di
push es
push si
push dx
mov ax,0b800h ;es:di指向dh行dl列的显示缓冲区
mov es,ax
mov al,160
mul dh
mov di,ax
add dl,dl
mov dh,0
add di,dx
pop dx
mov bx,0
showss: inc bx
cmp byte ptr [si],0
je showstrok
mov ah,[si]
mov es:[di],ah
inc si
add di,2
;call delay ;每打印一个字符,等待一段时间
jmp short showss
showstrok:
;根据输入的字符串适当的换行
push bx ;字符串的长度入栈,返回时出栈到ax
mov ax,bx
add al,dl
adc ah,0
mov bl,80
div bl
inc al
add dh,al
mov dl,0
cmp dh,24 ;若满屏则自动向上滚屏
jna showstrret ;不满屏就跳到返回处
sub dh,24
mov cl,dh
mov ch,0
showrup:mov ah,1
call rollup
loop showrup
mov dh,24 ;滚屏后dh、dl指向最后一行
mov dl,0
showstrret:
pop ax ;字符串的长度出栈到ax
pop si
pop es
pop di
pop cx
pop bx
ret
;************************** showstr end ***************************
;**************************** *****************************
;名称: delay
;功能: 延迟下一个命令的执行
;参数: 无
;------------------------------------------------------------------
delay: push ax
push dx
mov dx,8000
mov ax,0
delays: sub ax,1
sbb dx,0
cmp ax,0
jne delays
cmp dx,0
jne delays
pop dx
pop ax
ret
;*************************** delay end ****************************
;***************************** ******************************
;名称: cls
;功能: 清屏命令
;-------------------------------------------------------
cls: push bx ;清屏
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,0
mov cx,2000
clss: mov byte ptr es:[bx],' '
add bx,2
loop clss
mov dx,0 ;清屏后dh、dl指向0行0列
pop es
pop cx
pop bx
ret
;**************************** cls end ******************************
;**************************** *****************************
;名称: rollup
;功能: 屏幕向上滚动一行命令
;-------------------------------------------------------
rollup: push cx ;向上滚动一行
push si
push di
push es
push ds
mov si,0b800h
mov es,si
mov ds,si
mov si,160
mov di,0
cld
mov cx,24
rollups:push cx
mov cx,160
rep movsb
pop cx
loop rollups
mov cx,80
mov si,3840
rollups1:mov byte ptr [si],' ' ;第25行清空
add si,2
loop rollups1
dec dh ;向上滚动一行后dh减1
pop ds
pop es
pop di
pop si
pop cx
ret
;************************** rollup end *****************************
;************************** ******************************
;Page:285
;名称: setscreen
;参数: ah=0 表示清屏,清屏后dh、dl指向0行0列
; ah=1表示向上滚动一行,滚动后dh减1
; ah=2表示设置前景色,ah=3表示设置背景色
; 对于2、3号功能,用al传递颜色值,(al)->{0,1,2,3,4,5,6,7}
setscreen:jmp short setscreens
setstable:dw 0,0,0,0 ;在系统初始化时会让他们分别指向setsub1、setsub2、
setscreens:push bx ;setsub3、setsub4的偏移地址(即ip地址)
cmp ah,3
ja setscreenret
mov bl,ah
mov bh,0
add bx,bx
call word ptr setstable[bx]
setscreenret:
pop bx
ret
;以下是功能子程序
setsub1:push bx ;清屏
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,0
mov cx,2560
setsub1s:mov byte ptr es:[bx],' '
add bx,2
loop setsub1s
mov dx,0 ;清屏后dh、dl指向0行0列
pop es
pop cx
pop bx
ret
setsub2:push cx ;向上滚动一行
push si
push di
push es
push ds
mov si,0b800h
mov es,si
mov ds,si
mov si,160
mov di,0
cld
mov cx,31
setsub2s:push cx
mov cx,160
rep movsb
pop cx
loop setsub2s
mov cx,80
mov si,4960
setsub2s1:mov byte ptr [si],' ' ;第32行清空
add si,2
loop setsub2s1
dec dh ;向上滚动一行后dh减1
pop ds
pop es
pop di
pop si
pop cx
ret
setsub3:push bx ;设置前景色
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,1
mov cx,2560
setsub3s:and byte ptr es:[bx],11111000b
or es:[bx],al
add bx,2
loop setsub3s
mov cl,es:[bx-2]
pop es
pop cx
pop bx
ret
setsub4:push bx ;设置背景色
push cx
push es
mov cl,4
shl al,cl
mov bx,0b800h
mov es,bx
mov bx,1
mov cx,2560
setsub4s:and byte ptr es:[bx],10001111b
shl al,1
shl al,1
shl al,1
shl al,1
or es:[bx],al
add bx,2
loop setsub4s
mov cl,es:[bx-2]
pop es
pop cx
pop bx
ret
;************************* setscreen end *****************************
;***********************************************
;名称: showchar
;功能: 在当前光标处显示一个字符
;参数: al=要显示的字符
showchar:push ax
push bx
push cx
mov bh,0
mov bl,color ;color
mov cx,1
mov ah,9
int 10h
pop cx
pop bx
pop ax
ret
;*******************************************************
;------------------------------------------------------------------
;名称:dtoc
;功能:将word型数据装化成表示十进制数字的字符串,字符串以0为结尾
;参数:(ax)=word型数据
; ds:si指向字符串的首地址,ax返回字符串长度
dtoc: push bx
push cx
push dx
push si
push bp
mov bp,0
mov bx,10
dtocs: mov dx,0
div bx
add dx,30h
push dx
inc bp
mov cx,ax
jcxz dtocs1
jmp dtocs
dtocs1: mov ax,bp
inc ax ;ax返回字符串长度
mov cx,bp
dtocs2: pop [si]
inc si
loop dtocs2
mov byte ptr [si],0
pop bp
pop si
pop dx
pop cx
pop bx
ret
;************************************************************
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -