Advertisement
Guest User

Untitled

a guest
May 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. IDEAL
  2. MODEL small
  3. STACK 100h
  4. DATASEG
  5. Snake dw 32160, 32161, 32162, 32163, 32164, 32165
  6. SnakeLength dw 6
  7. Direction db 2
  8.  
  9. ; --------------------------
  10. ; Your variables here
  11. ; --------------------------
  12. CODESEG
  13.  
  14.  
  15.  
  16.  
  17.  
  18. proc DirectionTranslation ; Might need to change return method to Register, also maybe this proc is not needed
  19. cmp al, 17
  20. jb NoDirection
  21. jne SecondCheck
  22. cmp Direction, 3
  23. je NoDirection
  24. mov Direction, 1
  25. jmp EndProc
  26. SecondCheck:
  27. cmp al, 32
  28. ja NoDirection
  29. jne ThirdCheck
  30. cmp Direction, 2
  31. je NoDirection
  32. mov Direction, 4
  33. jmp EndProc
  34. ThirdCheck:
  35. cmp al, 31
  36. ja NoDirection
  37. jne FourthCheck
  38. cmp Direction, 1
  39. je NoDirection
  40. mov Direction, 3
  41. jmp EndProc
  42. FourthCheck:
  43. cmp al, 30
  44. jne NoDirection
  45. cmp Direction, 4
  46. je NoDirection
  47. mov Direction, 2
  48. jmp EndProc
  49. NoDirection:
  50. mov al, 5
  51. EndProc:
  52. ret
  53. endp DirectionTranslation
  54.  
  55. proc Delay
  56. mov dx, 1000
  57. DelayLoopOut:
  58. mov cx, 2000
  59. DelayLoopIn:
  60. loop DelayLoopIn
  61. dec dx
  62. cmp dx, 0
  63. ja DelayLoopOut
  64. ret
  65. endp Delay
  66.  
  67. 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
  68. mov bx, SnakeLength
  69. shl bx, 1
  70. sub bx, 2
  71. mov si, [bx]
  72. mov es:si, 0
  73. mov cx, SnakeLength
  74. sub cx, 1
  75. UpdateLoop:
  76. mov ax, [bx - 2]
  77. mov [bx], ax
  78. sub bx, 2
  79. loop UpdateLoop
  80. cmp Direction, 1
  81. jne SecondUpdate
  82. sub [bx], 320
  83. mov si, [bx]
  84. cmp es:si, 5
  85. jne EndProc2
  86. SecondUpdate:
  87. cmp Direction, 2
  88. jne ThirdUpdate
  89. sub [bx], 1
  90. mov si, [bx]
  91. cmp es:si, 5
  92. jne EndProc2
  93. ThirdUpdate:
  94. cmp Direction, 3
  95. jne FourthUpdate
  96. add [bx], 320
  97. mov si, [bx]
  98. cmp es:si, 5
  99. jne EndProc2
  100. FourthUpdate:
  101. add [bx], 1
  102. mov si, [bx]
  103. cmp es:si, 5
  104. jne EndProc2
  105. PlayerDead:
  106. mov dl, 1
  107. EndProc2:
  108. mov [byte ptr es:si], 4
  109. mov si, [bx + 2]
  110. mov [byte ptr es:si], 3
  111. ret
  112. endp UpdateSnake
  113.  
  114. proc AliveCheck
  115. mov bx, offset Snake
  116. mov cx, SnakeLength
  117. sub cx, 1
  118. mov ax, [bx]
  119. add bx, 2
  120. AliveCheckLoop:
  121. cmp ax, [bx]
  122. je PlayerDead2
  123. add bx, 2
  124. loop AliveCheckLoop
  125. jmp EndAliveCheck
  126. PlayerDead2:
  127. mov dl, 1
  128. EndAliveCheck:
  129. ret
  130. endp AliveCheck
  131.  
  132. start:
  133. mov ax, @data
  134. mov ds, ax
  135. mov ax, 13h
  136. int 10h
  137. mov cx, SnakeLength
  138. sub cx, 1
  139. mov ax, 0A000h
  140. mov es, ax
  141. mov bx, offset Snake
  142. mov si, [bx]
  143. mov es:si, 4
  144. add bx, 2
  145. FirstPrint:
  146. mov si, [bx]
  147. mov es:si, 3
  148. add bx, 2
  149. loop FirstPrint
  150. WaitForDirection:
  151. xor ah, ah
  152. int 16h
  153. mov al, ah
  154. call DirectionTranslation
  155. cmp al, 5
  156. je WaitForDirection
  157. GameLoop:
  158. in al, 64h
  159. cmp al, 10b
  160. je NoNewPress
  161. in al, 60h
  162. call DirectionTranslation
  163. NoNewPress:
  164. call Delay
  165. call UpdateSnake
  166. call AliveCheck
  167. cmp dl, 1
  168. je GameOver
  169. jmp GameLoop
  170. GameOver:
  171.  
  172.  
  173.  
  174. exit:
  175. mov ax, 4c00h
  176. int 21h
  177. END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement