Advertisement
nadavs2310

Untitled

Feb 27th, 2020
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.04 KB | None | 0 0
  1. IDEAL
  2. MODEL small
  3. STACK 100h
  4. ScreenMiddle = 32160
  5. HorizontalStep = 4
  6. VerticalStep = HorizontalStep * 320
  7. DATASEG
  8. Snake dw 500 dup(0)
  9. SnakeLength dw 6
  10. Direction db 2
  11. IsDead db 0
  12. last db 0
  13. ForRandom db 79
  14. FoodActive db 1
  15. MaskVar db 0
  16. StartMsg db '-------------------------------------------------------------------------------', 13, 10
  17. db '| |', 13, 10
  18. db '| |', 13, 10
  19. db '| |', 13, 10
  20. db '| |', 13, 10
  21. db '| |', 13, 10
  22. db '| |', 13, 10
  23. db '| |', 13, 10
  24. db '| |', 13, 10
  25. db '| |', 13, 10
  26. db '| |', 13, 10
  27. db '| |', 13, 10
  28. db '| Press any key to start |', 13, 10
  29. db '| |', 13, 10
  30. db '| |', 13, 10
  31. db '| |', 13, 10
  32. db '| |', 13, 10
  33. db '| |', 13, 10
  34. db '| |', 13, 10
  35. db '| |', 13, 10
  36. db '| |', 13, 10
  37. db '| |', 13, 10
  38. db '| |', 13, 10
  39. db '| |', 13, 10
  40. db '-------------------------------------------------------------------------------$', 13, 10
  41. GameOverMsg db '-------------------------------------------------------------------------------', 13, 10
  42. db '| |', 13, 10
  43. db '| |', 13, 10
  44. db '| |', 13, 10
  45. db '| |', 13, 10
  46. db '| |', 13, 10
  47. db '| |', 13, 10
  48. db '| |', 13, 10
  49. db '| |', 13, 10
  50. db '| |', 13, 10
  51. db '| |', 13, 10
  52. db '| |', 13, 10
  53. db '| Game over,Press any key to play again |', 13, 10
  54. db '| |', 13, 10
  55. db '| |', 13, 10
  56. db '| |', 13, 10
  57. db '| |', 13, 10
  58. db '| |', 13, 10
  59. db '| |', 13, 10
  60. db '| |', 13, 10
  61. db '| |', 13, 10
  62. db '| |', 13, 10
  63. db '| |', 13, 10
  64. db '| |', 13, 10
  65. db '-------------------------------------------------------------------------------$', 13, 10
  66. CODESEG
  67.  
  68.  
  69. CodeStart:
  70.  
  71. proc DirectionTranslation ; Might need to change return method to Register, also maybe this proc is not needed
  72. cmp al, 17
  73. jb NoDirection
  74. jne SecondCheck
  75. cmp [Direction], 3
  76. je NoDirection
  77. mov [Direction], 1
  78. jmp EndProc
  79. SecondCheck:
  80. cmp al, 32
  81. ja NoDirection
  82. jne ThirdCheck
  83. cmp [Direction], 2
  84. je NoDirection
  85. mov [Direction], 4
  86. jmp EndProc
  87. ThirdCheck:
  88. cmp al, 31
  89. ja NoDirection
  90. jne FourthCheck
  91. cmp [Direction], 1
  92. je NoDirection
  93. mov [Direction], 3
  94. jmp EndProc
  95. FourthCheck:
  96. cmp al, 30
  97. jne NoDirection
  98. cmp [direction], 4
  99. je NoDirection
  100. mov [direction], 2
  101. jmp EndProc
  102. NoDirection:
  103. mov al, 5
  104. EndProc:
  105. ret
  106. endp DirectionTranslation
  107.  
  108. proc Delay
  109. mov dx, 1200
  110. DelayLoopOut:
  111. mov cx, 2500
  112. DelayLoopIn:
  113. loop DelayLoopIn
  114. dec dx
  115. cmp dx, 0
  116. ja DelayLoopOut
  117. ret
  118. endp Delay
  119.  
  120. proc UpdateSnake
  121. mov bx, [SnakeLength]
  122. shl bx, 1
  123. sub bx, 2
  124. add bx, offset Snake
  125. mov si, [bx]
  126. cmp si, 0
  127. je NoTail
  128. mov al, 0
  129. call PrintLimb
  130.  
  131. NoTail:
  132. mov cx, [SnakeLength]
  133. sub cx, 1
  134. UpdateLoop:
  135. mov ax, [bx - 2]
  136. mov [bx], ax
  137. sub bx, 2
  138. loop UpdateLoop
  139.  
  140. cmp [direction], 1
  141. jne SecondUpdate
  142. sub [word ptr bx], VerticalStep
  143. mov si, [bx]
  144. cmp [byte ptr es:si], 0
  145. je EndProc2
  146. cmp [byte ptr es:si], 10
  147. jne PlayerDead
  148. mov [FoodActive], 0
  149. jmp EndProc2
  150. SecondUpdate:
  151. cmp [direction], 2
  152. jne ThirdUpdate
  153. sub [word ptr bx], HorizontalStep
  154. mov si, [bx]
  155. cmp [byte ptr es:si], 0
  156. je EndProc2
  157. cmp [byte ptr es:si], 10
  158. jne PlayerDead
  159. mov [foodactive], 0
  160. jmp EndProc2
  161. ThirdUpdate:
  162. cmp [direction], 3
  163. jne FourthUpdate
  164. add [word ptr bx], VerticalStep
  165. mov si, [bx]
  166. cmp [byte ptr es:si], 0
  167. je EndProc2
  168. cmp [byte ptr es:si], 10
  169. jne PlayerDead
  170. mov [foodactive], 0
  171. jmp EndProc2
  172. FourthUpdate:
  173. add [word ptr bx], HorizontalStep
  174. mov si, [bx]
  175. cmp [byte ptr es:si], 0
  176. je EndProc2
  177. cmp [byte ptr es:si], 10
  178. jne PlayerDead
  179. mov [foodactive], 0
  180. jmp EndProc2
  181. PlayerDead:
  182. mov [IsDead], 1
  183. EndProc2:
  184. mov al, 4
  185. call PrintLimb
  186. mov si, [bx + 2]
  187. mov al, 3
  188. call PrintLimb
  189. ret
  190. endp UpdateSnake
  191.  
  192. proc PrintLimb
  193. push cx
  194. mov cx, 4
  195. mov dx, 4
  196. PrintLimbLoop:
  197. mov [byte ptr es:si], al
  198. inc si
  199. dec dx
  200. cmp dx, 0
  201. jne PrintLimbLoop
  202. mov dx, 4
  203. add si, 316
  204. loop PrintLimbLoop
  205. pop cx
  206. ret
  207. endp PrintLimb
  208.  
  209.  
  210.  
  211. proc RandomInRange
  212. push di
  213. RestartRandom:
  214. add di, 5
  215. cmp di, offset exit
  216. jb Continue
  217. mov di, offset CodeStart
  218. Continue:
  219. mov al, [byte ptr cs:di]
  220. xor al, [es:06Ch]
  221. and al, [MaskVar]
  222. cmp al, [ForRandom]
  223. jae RestartRandom
  224. pop di
  225. ret
  226. endp RandomInRange
  227.  
  228. proc RandomApple
  229. push ax
  230. ReRandom:
  231. push es
  232. xor ah, ah
  233. mov ax, 40h
  234. mov es, ax
  235. mov [ForRandom], 78
  236. mov [MaskVar], 01111111b
  237. call RandomInRange
  238. add ax, 1
  239. mov di, ax
  240. mov [ForRandom], 48
  241. mov [MaskVar], 00111111b
  242. call RandomInRange
  243. add ax, 1
  244. mov bx, ax
  245. shl ax, 8
  246. shl bx, 6
  247. add ax, bx
  248. shl ax, 2
  249. shl di, 2
  250. add ax, di
  251. mov si, ax
  252. pop es
  253. cmp [byte ptr es:si], 0
  254. jne ReRandom
  255. mov al, 10
  256. call PrintLimb
  257. pop ax
  258. ret
  259. endp RandomApple
  260.  
  261. proc InitSnake
  262. mov bx, offset Snake
  263. mov ax, ScreenMiddle
  264. mov cx, [SnakeLength]
  265. InitLoop:
  266. mov [bx], ax
  267. add ax, HorizontalStep
  268. add bx, 2
  269. loop InitLoop
  270. ret
  271. endp InitSnake
  272.  
  273. proc InitGame
  274. mov [IsDead], 0
  275. mov [foodactive], 1
  276. mov [SnakeLength], 6
  277. mov [direction], 2
  278. mov bx, offset Snake
  279. mov cx, 500
  280. ResetSnake:
  281. mov [word ptr bx], 0
  282. add bx, 2
  283. loop ResetSnake
  284. ret
  285. endp InitGame
  286.  
  287.  
  288. proc PrintWalls
  289. xor si, si
  290. mov cx, 199
  291. FirstSide:
  292. mov [byte ptr es:si], 5
  293. mov [byte ptr es:si + 1], 5
  294. mov [byte ptr es:si + 2], 5
  295. mov [byte ptr es:si + 3], 5
  296. add si, 320
  297. loop FirstSide
  298. mov cx, 319
  299. SecondSide:
  300. mov [byte ptr es:si], 5
  301. mov [byte ptr es:si - 320], 5
  302. mov [byte ptr es:si - 640], 5
  303. mov [byte ptr es:si - 960], 5
  304. inc si
  305. loop SecondSide
  306. mov cx, 199
  307. ThirdSide:
  308. mov [byte ptr es:si], 5
  309. mov [byte ptr es:si - 1], 5
  310. mov [byte ptr es:si - 2], 5
  311. mov [byte ptr es:si - 3], 5
  312. sub si, 320
  313. loop ThirdSide
  314. mov cx, 319
  315. FourthSide:
  316. mov [byte ptr es:si], 5
  317. mov [byte ptr es:si + 320], 5
  318. mov [byte ptr es:si + 640], 5
  319. mov [byte ptr es:si + 960], 5
  320. dec si
  321. loop FourthSide
  322. ret
  323. endp PrintWalls
  324.  
  325. start:
  326. mov ax, @data
  327. mov ds, ax
  328. mov ah, 9h
  329. mov dx, offset StartMsg
  330. int 21h
  331. xor ah, ah
  332. int 16h
  333.  
  334. Restart:
  335. mov ax, 13h
  336. int 10h
  337. mov di, offset CodeStart
  338. mov ax, 0A000h
  339. mov es, ax
  340. call PrintWalls
  341. call InitSnake
  342. call RandomApple
  343. mov cx, [SnakeLength]
  344. sub cx, 1
  345. mov bx, offset Snake
  346. mov si, [bx]
  347. mov al, 4
  348. call PrintLimb
  349. add bx, 2
  350. mov al, 3
  351. FirstPrint:
  352. mov si, [bx]
  353. call PrintLimb
  354. add bx, 2
  355. loop FirstPrint
  356. WaitForDirection:
  357. xor ah, ah
  358. int 16h
  359. mov al, ah
  360. call DirectionTranslation
  361. cmp al, 5
  362. je WaitForDirection
  363. GameLoop:
  364. in al, 64h
  365. cmp al, 10b
  366. je NoNewPress
  367. in al, 60h
  368. cmp al,[last]
  369. je NoNewPress
  370. mov [last],al
  371. call DirectionTranslation
  372. NoNewPress:
  373. call Delay
  374. call UpdateSnake
  375. cmp [IsDead], 1
  376. je GameOver
  377. ;xor al,al
  378. cmp [foodactive], 0
  379. jne GameLoop
  380. call RandomApple
  381. mov [foodactive], 1
  382. inc [SnakeLength]
  383. jmp GameLoop
  384. GameOver:
  385. xor ax, ax
  386. mov al, 2
  387. int 10h
  388. mov dx, offset GameOverMsg
  389. mov ah, 9h
  390. int 21h
  391. mov ah,0ch
  392. xor al, al
  393. int 21h
  394. call Delay
  395. xor ah, ah
  396. int 16h
  397. call InitGame
  398. jmp Restart
  399.  
  400. exit:
  401. mov ax, 4c00h
  402. int 21h
  403. END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement