Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lda #0
  2. sta $0
  3. lda #2
  4. sta $1
  5. ;debug screen pointer
  6. lda #0
  7. sta $12
  8. lda #2
  9. sta $13
  10.  
  11. lda $fe
  12. sta $14
  13.  
  14. ;====================================================
  15. loopOne:
  16. lda $FE
  17. and #1
  18. sta ($0),y
  19.  
  20. clc
  21. lda $0
  22. adc #1
  23. sta $0
  24. lda $1
  25. adc #0
  26. sta $1
  27. cmp #6
  28. beq memoryFilled
  29. jmp loopOne
  30.  
  31.  
  32. ;====================================================
  33. memoryFilled:
  34. jsr resetEverything
  35. notDoneYet:
  36. jsr countLife ;count life around cell
  37. lda ($0),y
  38. cmp #1
  39. beq cellWasAlive
  40. ;otherwise, the cell is NOT living
  41. jsr currentCellDead
  42. jmp cellChecked
  43.  
  44. cellWasAlive:
  45. jsr currentCellAlive
  46. jmp cellChecked
  47.  
  48.  
  49. cellChecked:
  50. sta ($4),y ;Store final cell checked value in the buffer
  51.  
  52. jsr incrementPointers
  53. lda $1
  54. cmp #6
  55. beq doneNow
  56. ;it was not equal, jump back
  57. jmp notDoneYet
  58.  
  59. doneNow: ;here lies the rub, done now is not jumping here properly
  60. jsr resetEverything
  61. jsr copyNewBuffer
  62. jmp memoryFilled
  63.  
  64.  
  65. ;reset stuff, including $10
  66.  
  67. ;====================================================
  68. resetEverything:
  69. lda #0 ;screen pointer
  70. sta $0
  71. lda #2
  72. sta $1
  73.  
  74. lda #0 ;screen reading pointer
  75. sta $2
  76. lda #2
  77. sta $3
  78.  
  79. lda #0 ;buffer pointer
  80. sta $4
  81. lda #$10
  82. sta $5
  83.  
  84.  
  85. lda #0 ;life count
  86. sta $10
  87. rts
  88.  
  89.  
  90.  
  91. ;====================================================
  92. countLife:
  93. ;center screen reading pointer
  94. lda $0
  95. sta $2
  96. lda $1
  97. sta $3
  98.  
  99. ;TODO!!
  100. ;since the data is all in one stream, we need to account for the fact that
  101. ;the map is 2d, and wraps around every 32 pixels.
  102. ;if cell is far left, don't calculate up left, left, or down left
  103. ;if cell is far right, don't calculate up right, right, or down right
  104. ldx #0
  105.  
  106. ;x--
  107. ;---
  108. ;---
  109. sec
  110. lda $2
  111. sbc #33 ;move up one row, left a column
  112. sta $2
  113. lda $3
  114. sbc #0 ;carry subtract
  115. sta $3
  116. jsr addLife
  117.  
  118. ;-x-
  119. ;---
  120. ;---
  121. clc
  122. lda $2
  123. adc #1 ;move right one
  124. sta $2
  125. lda $3
  126. adc #0
  127. sta $3
  128. jsr addLife
  129.  
  130. ;--x
  131. ;---
  132. ;---
  133. clc
  134. lda $2
  135. adc #1 ;move right one
  136. sta $2
  137. lda $3
  138. adc #0
  139. sta $3
  140. jsr addLife
  141.  
  142. ;center screen reading pointer
  143. lda $0
  144. sta $2
  145. lda $1
  146. sta $2
  147.  
  148. ;---
  149. ;x--
  150. ;---
  151. sec
  152. lda $2
  153. sbc #1 ;move left one
  154. sta $2
  155. lda $3
  156. sbc #0 ;carry subtract
  157. sta $3
  158. jsr addLife
  159.  
  160. ;---
  161. ;--x
  162. ;---
  163. clc
  164. lda $2
  165. adc #2 ;move right two
  166. sta $2
  167. lda $3
  168. adc #0
  169. sta $3
  170. jsr addLife
  171.  
  172.  
  173. ;center screen reading pointer
  174. lda $0
  175. sta $2
  176. lda $1
  177. sta $2
  178.  
  179. ;---
  180. ;---
  181. ;x--
  182. clc
  183. lda $2
  184. adc #31 ;move down one, left one
  185. sta $2
  186. lda $3
  187. adc #0
  188. sta $3
  189. jsr addLife
  190.  
  191. ;---
  192. ;---
  193. ;-x-
  194. clc
  195. lda $2
  196. adc #1 ;move right one
  197. sta $2
  198. lda $3
  199. adc #0
  200. sta $3
  201. jsr addLife
  202.  
  203. ;---
  204. ;---
  205. ;--x
  206. clc
  207. lda $2
  208. adc #1 ;move right one
  209. sta $2
  210. lda $3
  211. adc #0
  212. sta $3
  213. jsr addLife
  214.  
  215. rts
  216.  
  217.  
  218.  
  219. ;====================================================
  220. addLife:
  221. lda ($2),y
  222. cmp #1
  223. bne noLife
  224. inc $10
  225. noLife:
  226. rts
  227.  
  228.  
  229.  
  230. ;====================================================
  231. currentCellDead:
  232. ; If there are 3 neighboring cells, it is alive
  233. ; Any other case, it is dead.
  234. lda $10
  235. rts ;return surround cell amount - debug
  236. cmp #3
  237. beq deadCellAlive
  238. ;no? then it's dead.
  239. lda #0
  240. jmp currentCellDeadEnd
  241.  
  242. deadCellAlive:
  243. lda #1
  244. jmp currentCellDeadEnd
  245.  
  246. currentCellDeadEnd:
  247. rts
  248.  
  249.  
  250.  
  251. ;====================================================
  252. currentCellAlive:
  253.  
  254. lda $10
  255. rts ;return surround cell amount - debug
  256.  
  257. ;useless notes - cmp actually compares and sets flags as if
  258. ;subtract had taken place... so if it's equal, carry flag will
  259. ;be set, and the equal flag will be set. If it's more than,
  260. ;just the carry flag will be set. If it's less than, none
  261. ;of the flags will be set.
  262.  
  263. ; Any live cell with fewer than two live neighbours dies,
  264. ; Any live cell with two or three live neighbours lives
  265. ; Any live cell with more than three live neighbours dies
  266.  
  267. cmp #2
  268. bcs cellEQGT2
  269. ;less than 2, cell dies
  270. lda #0
  271. jmp currentCellAliveEnd
  272.  
  273. cellEQGT2:
  274. BNE cellGT2
  275. ;equal to 2, cell lives
  276. lda #1
  277. jmp currentCellAliveEnd
  278.  
  279. cellGT2:
  280. cmp #3
  281. bne cellGT3
  282. ;equal to 3, cell lives
  283. lda #1
  284. jmp currentCellAliveEnd
  285.  
  286. cellGT3:
  287. ;greater than 3, cell dies
  288. lda #0
  289. jmp currentCellAliveEnd
  290.  
  291. currentCellAliveEnd:
  292. rts
  293.  
  294.  
  295.  
  296. ;====================================================
  297. incrementPointers:
  298. clc
  299. lda $0 ;increment screen pointer
  300. adc #1
  301. sta $0
  302. lda $1
  303. adc #0
  304. sta $1
  305.  
  306. clc
  307. lda $4 ;increment buffer pointer
  308. adc #1
  309. sta $4
  310. lda $5
  311. adc #0
  312. sta $5
  313. rts
  314.  
  315.  
  316. ;====================================================
  317. copyNewBuffer:
  318. lda ($4),y
  319. sta ($0),y
  320. jsr incrementPointers
  321. lda $1
  322. cmp #6
  323. bne copyNewBuffer
  324. rts
  325.  
  326. debug:
  327. lda $14
  328. sta ($12),y
  329.  
  330. clc
  331. lda #1
  332. adc $12
  333. sta $12
  334. lda #0
  335. adc $13
  336. sta $13
  337.  
  338. lda #6
  339. cmp $13
  340. bne dontResetDebug
  341. lda #0
  342. sta $12
  343. lda #2
  344. sta $13
  345. lda $fe
  346. sta $14
  347.  
  348. dontResetDebug:
  349. rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement