Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDEAL
- MODEL small
- STACK 100h
- ScreenMiddle = 32160
- HorizontalStep = 4
- VerticalStep = HorizontalStep * 320
- DATASEG
- Snake dw 500 dup(0)
- SnakeLength dw 6
- Direction db 2
- IsDead db 0
- last db 0
- ForRandom db 79
- FoodActive db 1
- MaskVar db 0
- StartMsg db '-------------------------------------------------------------------------------', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| Press any key to start |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '-------------------------------------------------------------------------------$', 13, 10
- GameOverMsg db '-------------------------------------------------------------------------------', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| Game over,Press any key to play again |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '| |', 13, 10
- db '-------------------------------------------------------------------------------$', 13, 10
- CODESEG
- CodeStart:
- proc DirectionTranslation ; Might need to change return method to Register, also maybe this proc is not needed
- cmp al, 17
- jb NoDirection
- jne SecondCheck
- cmp [Direction], 3
- je NoDirection
- mov [Direction], 1
- jmp EndProc
- SecondCheck:
- cmp al, 32
- ja NoDirection
- jne ThirdCheck
- cmp [Direction], 2
- je NoDirection
- mov [Direction], 4
- jmp EndProc
- ThirdCheck:
- cmp al, 31
- ja NoDirection
- jne FourthCheck
- cmp [Direction], 1
- je NoDirection
- mov [Direction], 3
- jmp EndProc
- FourthCheck:
- cmp al, 30
- jne NoDirection
- cmp [direction], 4
- je NoDirection
- mov [direction], 2
- jmp EndProc
- NoDirection:
- mov al, 5
- EndProc:
- ret
- endp DirectionTranslation
- proc Delay
- mov dx, 1200
- DelayLoopOut:
- mov cx, 2500
- DelayLoopIn:
- loop DelayLoopIn
- dec dx
- cmp dx, 0
- ja DelayLoopOut
- ret
- endp Delay
- proc UpdateSnake
- mov bx, [SnakeLength]
- shl bx, 1
- sub bx, 2
- add bx, offset Snake
- mov si, [bx]
- cmp si, 0
- je NoTail
- mov al, 0
- call PrintLimb
- NoTail:
- mov cx, [SnakeLength]
- sub cx, 1
- UpdateLoop:
- mov ax, [bx - 2]
- mov [bx], ax
- sub bx, 2
- loop UpdateLoop
- cmp [direction], 1
- jne SecondUpdate
- sub [word ptr bx], VerticalStep
- mov si, [bx]
- cmp [byte ptr es:si], 0
- je EndProc2
- cmp [byte ptr es:si], 10
- jne PlayerDead
- mov [FoodActive], 0
- jmp EndProc2
- SecondUpdate:
- cmp [direction], 2
- jne ThirdUpdate
- sub [word ptr bx], HorizontalStep
- mov si, [bx]
- cmp [byte ptr es:si], 0
- je EndProc2
- cmp [byte ptr es:si], 10
- jne PlayerDead
- mov [foodactive], 0
- jmp EndProc2
- ThirdUpdate:
- cmp [direction], 3
- jne FourthUpdate
- add [word ptr bx], VerticalStep
- mov si, [bx]
- cmp [byte ptr es:si], 0
- je EndProc2
- cmp [byte ptr es:si], 10
- jne PlayerDead
- mov [foodactive], 0
- jmp EndProc2
- FourthUpdate:
- add [word ptr bx], HorizontalStep
- mov si, [bx]
- cmp [byte ptr es:si], 0
- je EndProc2
- cmp [byte ptr es:si], 10
- jne PlayerDead
- mov [foodactive], 0
- jmp EndProc2
- PlayerDead:
- mov [IsDead], 1
- EndProc2:
- mov al, 4
- call PrintLimb
- mov si, [bx + 2]
- mov al, 3
- call PrintLimb
- ret
- endp UpdateSnake
- proc PrintLimb
- push cx
- mov cx, 4
- mov dx, 4
- PrintLimbLoop:
- mov [byte ptr es:si], al
- inc si
- dec dx
- cmp dx, 0
- jne PrintLimbLoop
- mov dx, 4
- add si, 316
- loop PrintLimbLoop
- pop cx
- ret
- endp PrintLimb
- proc RandomInRange
- push di
- RestartRandom:
- add di, 5
- cmp di, offset exit
- jb Continue
- mov di, offset CodeStart
- Continue:
- mov al, [byte ptr cs:di]
- xor al, [es:06Ch]
- and al, [MaskVar]
- cmp al, [ForRandom]
- jae RestartRandom
- pop di
- ret
- endp RandomInRange
- proc RandomApple
- push ax
- ReRandom:
- push es
- xor ah, ah
- mov ax, 40h
- mov es, ax
- mov [ForRandom], 78
- mov [MaskVar], 01111111b
- call RandomInRange
- add ax, 1
- mov di, ax
- mov [ForRandom], 48
- mov [MaskVar], 00111111b
- call RandomInRange
- add ax, 1
- mov bx, ax
- shl ax, 8
- shl bx, 6
- add ax, bx
- shl ax, 2
- shl di, 2
- add ax, di
- mov si, ax
- pop es
- cmp [byte ptr es:si], 0
- jne ReRandom
- mov al, 10
- call PrintLimb
- pop ax
- ret
- endp RandomApple
- proc InitSnake
- mov bx, offset Snake
- mov ax, ScreenMiddle
- mov cx, [SnakeLength]
- InitLoop:
- mov [bx], ax
- add ax, HorizontalStep
- add bx, 2
- loop InitLoop
- ret
- endp InitSnake
- proc InitGame
- mov [IsDead], 0
- mov [foodactive], 1
- mov [SnakeLength], 6
- mov [direction], 2
- mov bx, offset Snake
- mov cx, 500
- ResetSnake:
- mov [word ptr bx], 0
- add bx, 2
- loop ResetSnake
- ret
- endp InitGame
- proc PrintWalls
- xor si, si
- mov cx, 199
- FirstSide:
- mov [byte ptr es:si], 5
- mov [byte ptr es:si + 1], 5
- mov [byte ptr es:si + 2], 5
- mov [byte ptr es:si + 3], 5
- add si, 320
- loop FirstSide
- mov cx, 319
- SecondSide:
- mov [byte ptr es:si], 5
- mov [byte ptr es:si - 320], 5
- mov [byte ptr es:si - 640], 5
- mov [byte ptr es:si - 960], 5
- inc si
- loop SecondSide
- mov cx, 199
- ThirdSide:
- mov [byte ptr es:si], 5
- mov [byte ptr es:si - 1], 5
- mov [byte ptr es:si - 2], 5
- mov [byte ptr es:si - 3], 5
- sub si, 320
- loop ThirdSide
- mov cx, 319
- FourthSide:
- mov [byte ptr es:si], 5
- mov [byte ptr es:si + 320], 5
- mov [byte ptr es:si + 640], 5
- mov [byte ptr es:si + 960], 5
- dec si
- loop FourthSide
- ret
- endp PrintWalls
- start:
- mov ax, @data
- mov ds, ax
- mov ah, 9h
- mov dx, offset StartMsg
- int 21h
- xor ah, ah
- int 16h
- Restart:
- mov ax, 13h
- int 10h
- mov di, offset CodeStart
- mov ax, 0A000h
- mov es, ax
- call PrintWalls
- call InitSnake
- call RandomApple
- mov cx, [SnakeLength]
- sub cx, 1
- mov bx, offset Snake
- mov si, [bx]
- mov al, 4
- call PrintLimb
- add bx, 2
- mov al, 3
- FirstPrint:
- mov si, [bx]
- call PrintLimb
- add bx, 2
- loop FirstPrint
- WaitForDirection:
- xor ah, ah
- int 16h
- mov al, ah
- call DirectionTranslation
- cmp al, 5
- je WaitForDirection
- GameLoop:
- in al, 64h
- cmp al, 10b
- je NoNewPress
- in al, 60h
- cmp al,[last]
- je NoNewPress
- mov [last],al
- call DirectionTranslation
- NoNewPress:
- call Delay
- call UpdateSnake
- cmp [IsDead], 1
- je GameOver
- ;xor al,al
- cmp [foodactive], 0
- jne GameLoop
- call RandomApple
- mov [foodactive], 1
- inc [SnakeLength]
- jmp GameLoop
- GameOver:
- xor ax, ax
- mov al, 2
- int 10h
- mov dx, offset GameOverMsg
- mov ah, 9h
- int 21h
- mov ah,0ch
- xor al, al
- int 21h
- call Delay
- xor ah, ah
- int 16h
- call InitGame
- jmp Restart
- exit:
- mov ax, 4c00h
- int 21h
- END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement