Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2020
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. ;---------------------------------------------------------+
  2. ; Pong Demo for CCASM |
  3. ;---------------------------------------------------------+
  4. ; Trap Code Cheat Sheet: |
  5. ; 0: term.getSize() in D6, D7 |
  6. ; 1: term.getCursorPos() in D6, D7 |
  7. ; 2: term.setCursorPos(D0, D1) |
  8. ; 3: term.clear() |
  9. ; 4: term.clearLine() |
  10. ; 5: writeString at A0 |
  11. ; 6: readString into A0 |
  12. ;---------------------------------------------------------+
  13. origin #h1000
  14.  
  15. bsr init
  16. main:
  17. bsr input
  18. bsr tick
  19. trap #3
  20. bsr draw
  21. bra main
  22.  
  23. gameOver:
  24. bra gameOver
  25. ret
  26.  
  27. draw:
  28. bsr drawScore
  29. bsr drawBall
  30. bsr drawLeftPaddle
  31. bsr drawRightPaddle
  32. ret
  33.  
  34. drawScore:
  35. bsr drawLeftPaddleScore
  36. bsr drawRightPaddleScore
  37. ret
  38.  
  39. drawLeftPaddleScore:
  40. bsr setCursorAtLeftPaddleScore
  41. moveWord #0, d2
  42. moveByte leftPaddle_score, d2
  43. addByte #48, d2 ; Convert score to ASCII.
  44. lshiftByte d2
  45. moveWord d2, scoreBuffer
  46. bsr drawScoreBuffer
  47. ret
  48.  
  49. setCursorAtLeftPaddleScore:
  50. moveByte #2, d0
  51. moveByte #1, d1
  52. trap #2
  53. ret
  54.  
  55. drawRightPaddleScore:
  56. bsr setCursorAtRightPaddleScore
  57. moveWord #0, d2
  58. moveByte rightPaddle_score, d2
  59. addByte #48, d2 ; Convert score to ASCII.
  60. lshiftByte d2
  61. moveWord d2, scoreBuffer
  62. bsr drawScoreBuffer
  63. ret
  64.  
  65. setCursorAtRightPaddleScore:
  66. moveByte screenWidth, d0
  67. subByte #1, d0
  68. moveByte #1, d1
  69. trap #2
  70. ret
  71.  
  72. drawScoreBuffer:
  73. moveWord #scoreBuffer, a0
  74. trap #5
  75. ret
  76.  
  77. drawBall:
  78. bsr setCursorAtBall
  79. moveWord #ballStr, a0
  80. trap #5
  81. ret
  82.  
  83. drawBlank:
  84. moveWord #blankStr, a0
  85. trap #5
  86. ret
  87.  
  88. setCursorAtBall:
  89. moveByte ball_pX, d0
  90. moveByte ball_pY, d1
  91. trap #2
  92. ret
  93.  
  94. drawLeftPaddle:
  95. push a0
  96. push d0-1
  97. moveWord #paddleStr, a0
  98. moveByte leftPaddle_pX, d0
  99. moveByte leftPaddle_pY, d1
  100. trap #2
  101. trap #5
  102. addByte #1, d1
  103. trap #2
  104. trap #5
  105. addByte #1, d1
  106. trap #2
  107. trap #5
  108. pop d0-1
  109. pop a0
  110. ret
  111.  
  112. drawRightPaddle:
  113. push a0
  114. push d0-1
  115. moveWord #paddleStr, a0
  116. moveByte rightPaddle_pX, d0
  117. moveByte rightPaddle_pY, d1
  118. trap #2
  119. trap #5
  120. addByte #1, d1
  121. trap #2
  122. trap #5
  123. addByte #1, d1
  124. trap #2
  125. trap #5
  126. pop d0-1
  127. pop a0
  128. ret
  129.  
  130. input:
  131. moveWord #h200, a0 ; Load address of key input into A0.
  132. moveByte #a0, d0 ; Read key input into D0.
  133. cmpByte #101, d0 ; case 'e'
  134. beq directLeftUp
  135. cmpByte #102, d0 ; case 'f'
  136. beq directLeftDown
  137. moveByte #0, leftPaddle_vY ; Otherwise, left paddle is not moving.
  138. cmpByte #105, d0 ; case 'i'
  139. beq directRightUp
  140. cmpByte #106, d0 ; case 'j'
  141. beq directRightDown
  142. moveByte #0, rightPaddle_vY ; Otherwise, right paddle is not moving.
  143. bra inputEnd
  144. directLeftUp:
  145. moveByte #hFF, leftPaddle_vY
  146. bra inputEnd
  147. directLeftDown:
  148. moveByte #1, leftPaddle_vY
  149. bra inputEnd
  150. directRightUp:
  151. moveByte #hFF, rightPaddle_vY
  152. bra inputEnd
  153. directRightDown:
  154. moveByte #1, rightPaddle_vY
  155. bra inputEnd
  156. inputEnd:
  157. ret
  158.  
  159. tick:
  160. bsr applyCollision
  161. bsr updatePaddles
  162. ret
  163.  
  164. applyCollision:
  165. moveByte screenWidth, d0
  166. moveByte screenHeight, d1
  167. moveByte ball_pX, d2
  168. moveByte ball_pY, d3
  169. moveByte leftPaddle_pX, d4
  170. moveByte leftPaddle_pY, d5
  171. moveByte rightPaddle_pX, d6
  172. moveByte rightPaddle_pY, d7
  173. cmpByte d2, #1
  174. beq checkCollideLeftY
  175. cmpByte d2, d0
  176. beq checkCollideRightY
  177. cmpByte d3, #1
  178. ble redirectBallDown
  179. cmpByte d3, d1
  180. bge redirectBallUp
  181. bra updateBall
  182. checkCollideLeftY:
  183. cmpByte d3, d5
  184. beq redirectBallRight
  185. addByte #1, d5
  186. cmpByte d3, d5
  187. beq redirectBallRight
  188. addByte #1, d5
  189. cmpByte d3, d5
  190. beq redirectBallRight
  191. bne scoreRight
  192. redirectBallRight:
  193. moveByte #1, ball_vX
  194. moveByte #0, ball_vY
  195. moveByte leftPaddle_vY, d0
  196. cmpByte #0, d0
  197. bgt redirectBallRightUp
  198. blt redirectBallRightDown
  199. bra updateBall
  200. redirectBallRightUp:
  201. moveByte #hFF, ball_vY
  202. bra updateBall
  203. redirectBallRightDown:
  204. moveByte #1, ball_vY
  205. bra updateBall
  206. checkCollideRightY:
  207. cmpByte d3, d7
  208. beq redirectBallLeft
  209. addByte #1, d7
  210. cmpByte d3, d7
  211. beq redirectBallLeft
  212. addByte #1, d7
  213. cmpByte d3, d7
  214. beq redirectBallLeft
  215. bne scoreLeft
  216. redirectBallLeft:
  217. moveByte #hFF, ball_vX
  218. moveByte #0, ball_vY
  219. moveByte rightPaddle_vY, d0
  220. cmpByte #0, d0
  221. bgt redirectBallLeftUp
  222. blt redirectBallLeftDown
  223. bra updateBall
  224. redirectBallLeftUp:
  225. moveByte #hFF, ball_vY
  226. bra updateBall
  227. redirectBallLeftDown:
  228. moveByte #1, ball_vY
  229. bra updateBall
  230. redirectBallUp:
  231. moveByte #hFF, ball_vY
  232. bra updateBall
  233. redirectBallDown:
  234. moveByte #1, ball_vY
  235. bra updateBall
  236. updateBall:
  237. moveByte ball_vX, d0
  238. moveByte ball_vY, d1
  239. moveByte ball_pX, d2
  240. moveByte ball_pY, d3
  241. addByte d0, d2
  242. addByte d1, d3
  243. moveByte d2, ball_pX
  244. moveByte d3, ball_pY
  245. ret
  246. scoreLeft:
  247. moveByte leftPaddle_score, d0
  248. addByte #1, d0
  249. cmpByte #5, d0
  250. ble leftPaddleWin
  251. moveByte d0, leftPaddle_score
  252. bsr resetBall
  253. bra updateBall
  254. leftPaddleWin:
  255. moveWord #leftPaddleWinPrompt, a0
  256. trap #7
  257. moveByte d0, d2
  258. divByte #2, d2
  259. moveByte midScreenX, d0
  260. subByte d2, d0
  261. moveByte midScreenY, d1
  262. trap #2
  263. trap #3
  264. trap #5
  265. bra gameOver
  266. scoreRight:
  267. moveByte rightPaddle_score, d0
  268. addByte #1, d0
  269. cmpByte #5, d0
  270. ble rightPaddleWin
  271. moveByte d0, rightPaddle_score
  272. bsr resetBall
  273. bra updateBall
  274. rightPaddleWin:
  275. moveWord #rightPaddleWinPrompt, a0
  276. trap #7
  277. moveByte d0, d2
  278. divByte #2, d2
  279. moveByte midScreenX, d0
  280. subByte d2, d0
  281. moveByte midScreenY, d1
  282. trap #2
  283. trap #3
  284. trap #5
  285. bra gameOver
  286.  
  287. updatePaddles:
  288. moveByte screenHeight, d0
  289. moveByte leftPaddle_vY, d1
  290. moveByte leftPaddle_pY, d2
  291. addByte d1, d2
  292. moveByte d2, leftPaddle_pY
  293. bsr correctLeftPaddle
  294. moveByte rightPaddle_vY, d3
  295. moveByte rightPaddle_pY, d4
  296. addByte d3, d4
  297. moveByte d4, rightPaddle_pY
  298. bsr correctRightPaddle
  299. ret
  300. correctLeftPaddle:
  301. moveByte leftPaddle_pY, d0
  302. cmpByte #1, d0
  303. bgt lockLeftPaddleAtTop
  304. moveByte screenHeight, d1
  305. subByte #2, d1
  306. cmpByte d1, d0
  307. blt lockLeftPaddleAtBottom
  308. correctLeftPaddleEnd:
  309. ret
  310. lockLeftPaddleAtTop:
  311. moveByte #1, leftPaddle_pY
  312. bra correctLeftPaddleEnd
  313. lockLeftPaddleAtBottom:
  314. moveByte screenHeight, d0
  315. subByte #2, d0
  316. moveByte d0, leftPaddle_pY
  317. bra correctLeftPaddleEnd
  318. correctRightPaddle:
  319. moveByte rightPaddle_pY, d0
  320. cmpByte #1, d0
  321. bgt lockRightPaddleAtTop
  322. moveByte screenHeight, d1
  323. subByte #2, d1
  324. cmpByte d1, d0
  325. blt lockRightPaddleAtBottom
  326. correctRightPaddleEnd:
  327. ret
  328. lockRightPaddleAtTop:
  329. moveByte #1, rightPaddle_pY
  330. bra correctRightPaddleEnd
  331. lockRightPaddleAtBottom:
  332. moveByte screenHeight, d0
  333. subByte #2, d0
  334. moveByte d0, rightPaddle_pY
  335. bra correctRightPaddleEnd
  336.  
  337. init:
  338. trap #0
  339. moveByte d6, screenWidth
  340. moveByte d7, screenHeight
  341. moveByte d6, d0
  342. moveByte d7, d1
  343. divByte #2, d0 ; Store screenWidth / 2 in D0.
  344. divByte #2, d1 ; Store screenHeight / 2 in D1.
  345. moveByte d0, midScreenX
  346. moveByte d1, midScreenY
  347. ; Left paddle starts on the left side in the middle.
  348. moveByte #1, leftPaddle_pX
  349. moveByte d1, leftPaddle_pY
  350. ; Right paddle starts on the right side in the middle.
  351. moveByte d6, rightPaddle_pX
  352. moveByte d1, rightPaddle_pY
  353. bsr resetBall
  354. ret
  355.  
  356. resetBall:
  357. moveByte midScreenX, d0
  358. moveByte midScreenY, d1
  359. moveByte d0, ball_pX
  360. moveByte d1, ball_pY
  361. moveByte #1, ball_vX
  362. moveByte #0, ball_vY
  363. ret
  364.  
  365. screenWidth declareByte #0
  366. midScreenX declareByte #0
  367. screenHeight declareByte #0
  368. midScreenY declareByte #0
  369.  
  370. ball_pX declareByte #0
  371. ball_pY declareByte #0
  372. ball_vX declareByte #0
  373. ball_vY declareByte #0
  374. ballStr declareString "o"
  375.  
  376. leftPaddle_pX declareByte #0
  377. leftPaddle_pY declareByte #0
  378. leftPaddle_vY declareByte #0
  379. leftPaddle_score declareByte #0
  380. leftPaddleWinPrompt declareString "Left player wins!"
  381.  
  382. rightPaddle_pX declareByte #0
  383. rightPaddle_pY declareByte #0
  384. rightPaddle_vY declareByte #0
  385. rightPaddle_score declareByte #0
  386. rightPaddleWinPrompt declareString "Right player wins!"
  387.  
  388. paddleStr declareString "|"
  389. scoreBuffer declareWord #0
  390.  
  391. blankStr declareString " "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement