Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDEAL
- MODEL small
- STACK 100h
- DATASEG
- Snake dw 32160, 32161, 32162, 32163, 32164, 32165
- SnakeLength dw 6
- Direction db 2
- ; --------------------------
- ; Your variables here
- ; --------------------------
- CODESEG
- 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, 1000
- DelayLoopOut:
- mov cx, 2000
- DelayLoopIn:
- loop DelayLoopIn
- dec dx
- cmp dx, 0
- ja DelayLoopOut
- ret
- endp Delay
- proc UpdateSnake ; can Instead start from the head (so I won't need to calculate the tail offset) and just push at the start of the proc the before value of the head
- mov bx, SnakeLength
- shl bx, 1
- sub bx, 2
- mov si, [bx]
- mov es:si, 0
- 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 [bx], 320
- mov si, [bx]
- cmp es:si, 5
- jne EndProc2
- SecondUpdate:
- cmp Direction, 2
- jne ThirdUpdate
- sub [bx], 1
- mov si, [bx]
- cmp es:si, 5
- jne EndProc2
- ThirdUpdate:
- cmp Direction, 3
- jne FourthUpdate
- add [bx], 320
- mov si, [bx]
- cmp es:si, 5
- jne EndProc2
- FourthUpdate:
- add [bx], 1
- mov si, [bx]
- cmp es:si, 5
- jne EndProc2
- PlayerDead:
- mov dl, 1
- EndProc2:
- mov [byte ptr es:si], 4
- mov si, [bx + 2]
- mov [byte ptr es:si], 3
- ret
- endp UpdateSnake
- proc AliveCheck
- mov bx, offset Snake
- mov cx, SnakeLength
- sub cx, 1
- mov ax, [bx]
- add bx, 2
- AliveCheckLoop:
- cmp ax, [bx]
- je PlayerDead2
- add bx, 2
- loop AliveCheckLoop
- jmp EndAliveCheck
- PlayerDead2:
- mov dl, 1
- EndAliveCheck:
- ret
- endp AliveCheck
- start:
- mov ax, @data
- mov ds, ax
- mov ax, 13h
- int 10h
- mov cx, SnakeLength
- sub cx, 1
- mov ax, 0A000h
- mov es, ax
- mov bx, offset Snake
- mov si, [bx]
- mov es:si, 4
- add bx, 2
- FirstPrint:
- mov si, [bx]
- mov es:si, 3
- 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
- call DirectionTranslation
- NoNewPress:
- call Delay
- call UpdateSnake
- call AliveCheck
- cmp dl, 1
- je GameOver
- jmp GameLoop
- GameOver:
- exit:
- mov ax, 4c00h
- int 21h
- END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement