Advertisement
Guest User

Untitled

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