model small .data ; . snake dw 0000h dw 0001h dw 0002h dw 0003h dw 0004h dw 7CCh dup('?') .stack 100h .code ; delay proc push cx mov ah,0 int 1Ah add dx,3 mov bx,dx repeat: int 1Ah cmp dx,bx jl repeat pop cx ret delay endp start: mov ax,@data mov ds,ax mov es,ax mov ax,0003h int 10h ; mov cx,5 mov ax,0A2Ah int 10h ; 5 "*" mov si,8 ; xor di,di ; mov cx,0001h ; cx . cx x y main: ; call delay xor bh,bh mov ax,[snake+si] ; add ax,cx ; x inc si inc si mov [snake+si],ax ; mov dx,ax mov ax,0200h int 10h ; . mov ah,02h mov dl,002Ah int 21h ; '*' mov ax,0200h mov dx,[snake+di] int 10h mov ax,0200h mov dl,0020h int 21h ; , inc di inc di jmp main end start
key_press proc mov ax, 0100h int 16h jz en ; xor ah, ah int 16h cmp ah, 50h jne up cmp cx,0FF00h ; je en mov cx,0100h jmp en up: cmp ah,48h jne left cmp cx,0100h je en mov cx,0FF00h jmp en left: cmp ah,4Bh jne right cmp cx,0001h je en mov cx,0FFFFh jmp en right: cmp cx,0FFFFh je en mov cx,0001h en: ret key_press endp
main: call delay call key_press
add_food proc sc: inc bl ; BL cmp bx,50h ; jng ex shr bl,1 ; , 2 jmp sc ex: mov dl,bl ; sc2: cmp bx,19h jng ex2 shr bl,2 jmp sc2 ex2: mov dh,bl ; mov ax,0200h int 10h mov ax,0800h int 10h cmp al,2Ah ; je sc cmp al,40h je sc ; mov ax,0200h mov dl,0024h int 21h ret add_food endp
mov bl,51h call add_food main:
mov ah,02h int 10h ; . mov ax,0800h int 10h ; mov dh,al mov ah,02h mov dl,002Ah int 21h ; '*' cmp dh,24h jne next call add_food jmp main next:
; .data tick dw 0 ; -------------------------------------------------------------------- cmp dh,24h jne next push cx ; mov cx,[tick] inc cx cmp cx,5 jne exl xor cx,cx mov ax,0200h mov dx,[snake+di-2] int 10h mov ax,0200h mov dl,0040h int 21h exl:mov [tick],cx pop cx call add_food jmp main next:
game_over proc ; cmp dl,50h je exit cmp dl,0 jl exit cmp dh,0 jl exit cmp dh,19h je exit ; cmp al,2Ah je exit cmp al,40h je exit jmp good exit: mov ax,4c00h int 21h good: ret game_over endp
mov ax,0800h int 10h ; call game_over mov dh,al
inc si inc si cmp si,7CAh jne nex xor si,si nex: --------------------------------------------------------------------- inc di inc di cmp di,7CCh jne main xor di,di
Source: https://habr.com/ru/post/236831/
All Articles