概述
;design the snake by AJISky
data segment
hang dw 50 dup (0043h,0042h,0041h,0040h)
ram dw 50 dup (000fh,000fh,000fh,000fh)
flag db 0
mid dw 0001h
beanX dw ?
beanY dw ?
Len dw 4
data ends
code segment
assume cs:code,ds:data
main proc far
start: mov ax,data
mov ds,ax
;mov ah,0fh
;mov bh,0
;int 10h
;push ax ;保存原来显示模式
mov ah,00 ;图形模式
mov al,4h
int 10h
mov ah,0bh ;设背景色
mov bh,00
mov bl,00
int 10h
mov ah,0bh ;设调色板0
mov bh,01h
mov bl,1
int 10h
;mov ah,0ch
;mov al,1
;mov beanY,155
;mov dx,beanY
;mov beanX,222
;mov cx,beanX
;int 10h
mov cx,Len
xxx: cmp flag,0
jnz zou
call GetRam
inc flag
zou: mov cx,Len ;恢复蛇身长度
mov si,0
xx: push cx ;begin打印蛇身
mov ah,0ch
mov al,02
mov dx,hang[si]
mov cx,ram[si]
add si,2
inc di
int 10h
pop cx
loop xx ;/begin打印蛇身
call delay
mov ax,hang[0] ;判断是否吃掉
cmp ax,beanY
jnz nequ
mov ax,ram[0]
cmp ax,beanX
jnz nequ
call GetRam ;如果吃掉粒子就再次产生
inc Len
nequ: mov cx,Len
push cx
call x2
mov ah,0ch
mov al,00
mov dx,hang[si-2]
mov cx,ram[si-2]
int 10h
pop cx
dec cx
cir: call x2 ;begin除蛇头外更新堆栈
mov dx,hang[si-2]
mov hang[si],dx
mov dx,ram[si-2]
mov ram[si],dx
loop cir ;/begin
call vary ;更新蛇头
call IsOut?
mov ah,0ch ;清空键盘缓冲区
mov al,02h
int 21h
jmp xxx
;pop ax ;恢复显示器模式
;mov ah,00
;int 10h
;mov ah,4ch ;返回DOS
;int 21h
main endp
LenEn proc near
ret
LenEn endp
x2 proc near
;push bx
;push ax
;push cx
mov ax,cx
mov bl,2
mul bl
mov si,ax
;pop cx
;pop ax
;pop bx
ret
x2 endp
GetRam proc near
;push ax
;push bx
;push cx
;push dx
;mov al,0
;out 70h,al
;in al,71h
;mov bl,al
;mov cl,4
;shr bl,cl
;and bl,0fh
;and al,0fh
;mul bl
;push ax
;mov bl,4
;mul bl
;mov beanY,ax
;pop ax
;mov bl,7
;mul bl
;mov beanX,ax
mov ah,0
int 1ah
mov ax,dx
and ah,0
mov dl,199
div dl
mov al,ah
mov ah,00h
mov beanY,ax
mov ah,0
int 1ah
mov ax,dx
mov dl,255
div dl
mov al,ah
mov ah,00h
mov beanX,ax
mov ah,0ch
mov al,1
mov dx,beanY
mov cx,beanX
int 10h
;pop dx
;pop cx
;pop bx
;pop ax
ret
GetRam endp
vary proc near
;push ax
;push si
;push bx
mov si,0h
mov ah,01h
int 16h
jz judge
cmp ah,4dh ;right->
jnz one
cmp flag,4 ;目的是检测按键是否与运行方向相反
jz one ;禁止方向移动
jmp la
one: cmp ah,4bh ;left<-
jnz two
cmp flag,3 ;目的是检测按键是否与运行方向相反
jz two ;禁止方向移动
jmp ls
two: cmp ah,48h ;up ^
jnz three
cmp flag,1 ;目的是检测按键是否与运行方向相反
jz three ;禁止方向移动
jmp hs
three: cmp ah,50h ;down
jnz judge
cmp flag,2 ;目的是检测按键是否与运行方向相反
jz f1 ;禁止方向移动
jmp ha
judge: cmp flag,1
jnz f1
jmp ha
f1: cmp flag,2
jnz f2
jmp hs
f2: cmp flag,3
jnz ls
jmp la
ha: mov bx,mid
add hang[si],bx
mov flag,1
jmp over
hs: mov bx,mid
sub hang[si],bx
mov flag,2
jmp over
la: mov bx,mid
add ram[si],bx
mov flag,3
jmp over
ls: mov bx,mid
sub ram[si],bx
mov flag,4
over: ;pop bx
;pop si
;pop ax
ret
vary endp
delay proc near
;push si
;push cx
mov si,100h
mov cx,0
circ: loop $
dec si
jnz circ
;pop cx
;pop si
ret
delay endp
IsOut? proc near
cmp ram[0],320
jnz notRO
mov ram[0],0000h
notRO: cmp ram[0],0ffffh
jnz notLO
mov ram[0],319
notLO: cmp hang[0],0ffffh
jnz notUO
mov hang[0],199
notUO: cmp hang[0],200
jnz exo
mov hang[0],0000h
exo: ret
IsOut? endp
code ends
end start;sum of 252row
最后
以上就是疯狂麦片为你收集整理的8086下十六位贪吃蛇小程序 (仅1k)的全部内容,希望文章能够帮你解决8086下十六位贪吃蛇小程序 (仅1k)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复