Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

377 Zeilen
10KB

  1. ; Worn paths (M5.2, R7).
  2. ;
  3. ; Every world cell has a walk count (walk_counts, laid out like world_tiles).
  4. ; A person stepping into a cell adds one (up to 255); every count loses one
  5. ; each 60 seconds (DECAY_CELLS cells every DECAY_FRAMES frames: 4000 cells in
  6. ; 3600 frames). A land, grass or tree cell whose count reaches PATH_ON becomes
  7. ; the matching path tile; a path whose count falls below PATH_OFF turns back.
  8. ;
  9. ; A changed tile is written to world_tiles at once and queued. Each frame the
  10. ; main loop redraws queued cells in the hidden buffer only, so the shown map
  11. ; is never written while it is displayed; a cell waits in the queue until both
  12. ; buffers have it. The redraw keeps the people's dots in the cell (a dot is the
  13. ; only %11 pixel) and updates the saved bytes under them, so restoring a dot
  14. ; later puts back the new tile. If the hidden buffer is in the middle of a
  15. ; rebuild, the rest of the rebuild draws every cell (its skip test compares
  16. ; world tiles, which have changed underneath it) and the changed cells are
  17. ; redrawn when it is ready.
  18. ;
  19. ; The test build (PATH_TEST, tools/run.ps1 -PathTest) uses small thresholds
  20. ; and fast decay so paths can be watched and checked within a minute.
  21. .ifdef PATH_TEST
  22. PATH_ON = 4
  23. PATH_OFF = 2
  24. DECAY_FRAMES = 1
  25. DECAY_CELLS = 10 ; every count loses one each 400 frames
  26. .else
  27. PATH_ON = 128
  28. PATH_OFF = 64
  29. DECAY_FRAMES = 9
  30. DECAY_CELLS = 10 ; every count loses one each 3600 frames
  31. .endif
  32. CHANGE_SLOTS = 8
  33. cnt_ptr = $56 ; walk count row
  34. ; The walk counts live in the free RAM at $C000-$CF9F (no VIC bank uses it):
  35. ; below VIC bank 1 there is no room for them next to the program.
  36. walk_counts = $C000
  37. COUNT_BYTES = WORLD_WIDTH * WORLD_HEIGHT
  38. .export walk_counts
  39. ap_bmp = $58 ; cell being redrawn: bitmap
  40. ap_scr = $5A ; screen RAM
  41. .segment "CODE"
  42. ; New world: all counts 0, no queued changes, decay from the first cell.
  43. reset_paths:
  44. lda #<walk_counts
  45. sta cnt_ptr
  46. lda #>walk_counts
  47. sta cnt_ptr+1
  48. ldx #>COUNT_BYTES ; whole pages
  49. lda #0
  50. tay
  51. @clear: sta (cnt_ptr),y
  52. iny
  53. bne @clear
  54. inc cnt_ptr+1
  55. dex
  56. bne @clear
  57. @rest: sta (cnt_ptr),y ; the last part page: exactly 4,000 bytes, so
  58. iny ; nothing after the counts is touched
  59. cpy #<COUNT_BYTES
  60. bne @rest
  61. sta chg_count
  62. sta decay_cx
  63. sta decay_cy
  64. lda #DECAY_FRAMES
  65. sta decay_wait
  66. rts
  67. ; X = world row. cnt_ptr = that row of walk_counts. Preserves X and Y.
  68. point_counts:
  69. lda world_row_low,x
  70. clc
  71. adc #<(walk_counts - world_tiles)
  72. sta cnt_ptr
  73. lda world_row_high,x
  74. adc #>(walk_counts - world_tiles)
  75. sta cnt_ptr+1
  76. rts
  77. ; X = person: move it to the candidate position; a step into another cell
  78. ; counts for that cell.
  79. store_step:
  80. lda cand_cx
  81. eor people_cx,x
  82. sta new_cell
  83. lda cand_cy
  84. eor people_cy,x
  85. ora new_cell
  86. sta new_cell
  87. lda cand_cx
  88. sta people_cx,x
  89. lda cand_sx
  90. sta people_sx,x
  91. lda cand_cy
  92. sta people_cy,x
  93. lda cand_sy
  94. sta people_sy,x
  95. lda new_cell
  96. bne count_step
  97. rts
  98. ; A person stepped into cell (cand_cx, cand_cy).
  99. count_step:
  100. ldx cand_cy
  101. ldy cand_cx
  102. jsr point_counts
  103. lda (cnt_ptr),y
  104. cmp #255
  105. beq @full
  106. clc
  107. adc #1
  108. sta (cnt_ptr),y
  109. @full: cmp #PATH_ON
  110. bcc @done
  111. jsr point_world_row
  112. lda (world_ptr),y
  113. cmp #STONE ; land, grass or trees (paths are above STONE)
  114. bcs @done
  115. clc
  116. adc #PATH_LAND - LAND
  117. jmp change_tile
  118. @done: rts
  119. ; Main loop, every frame: every DECAY_FRAMES frames, the next DECAY_CELLS
  120. ; counts lose one; a path whose count is below PATH_OFF turns back.
  121. decay_counts:
  122. dec decay_wait
  123. bne @done
  124. lda #DECAY_FRAMES
  125. sta decay_wait
  126. lda #DECAY_CELLS
  127. sta decay_left
  128. @cell: ldx decay_cy
  129. ldy decay_cx
  130. jsr point_counts
  131. lda (cnt_ptr),y
  132. beq @check
  133. sec
  134. sbc #1
  135. sta (cnt_ptr),y
  136. @check: cmp #PATH_OFF
  137. bcs @next
  138. jsr point_world_row
  139. lda (world_ptr),y
  140. cmp #PATH_LAND
  141. bcc @next
  142. cmp #PATH_TREE + 1
  143. bcs @next
  144. sec
  145. sbc #PATH_LAND - LAND
  146. jsr change_tile
  147. @next: inc decay_cx
  148. lda decay_cx
  149. cmp #WORLD_WIDTH
  150. bne @more
  151. lda #0
  152. sta decay_cx
  153. inc decay_cy
  154. lda decay_cy
  155. cmp #WORLD_HEIGHT
  156. bne @more
  157. lda #0
  158. sta decay_cy
  159. @more: dec decay_left
  160. bne @cell
  161. @done: rts
  162. ; A = new tile for the cell at column Y of the world row world_ptr points
  163. ; to, X = its row. Store it and queue the cell for both buffers. If the
  164. ; queue is full nothing changes; the count is checked again next time.
  165. change_tile:
  166. sta chg_tile
  167. stx chg_ty
  168. ldx chg_count
  169. cpx #CHANGE_SLOTS
  170. bcs change_full
  171. lda chg_tile
  172. sta (world_ptr),y
  173. path_changed: ; check hook: A = new tile, Y = column
  174. tya
  175. sta chg_cx,x
  176. lda chg_ty
  177. sta chg_cy,x
  178. lda #0
  179. sta chg_done,x
  180. inc chg_count
  181. change_full:
  182. rts
  183. ; Main loop, before choose_rebuild_target: bring the hidden buffer up to
  184. ; date with the queued cells, then drop cells that both buffers have.
  185. apply_changes:
  186. lda chg_count
  187. bne @some
  188. rts
  189. @some: ldx hidden
  190. stx ap_buf
  191. lda buffer_bit,x
  192. sta ap_bit
  193. lda buf_ready,x
  194. bne @ready
  195. ldy chg_count ; being rebuilt: is a queued cell new to it?
  196. @mark: dey
  197. bmi @drop ; no: the rebuild already allowed for them all
  198. lda chg_done,y
  199. and ap_bit
  200. bne @mark
  201. cpx rb_buf
  202. bne @drop
  203. lda #0 ; yes: the rest of the rebuild draws every cell,
  204. sta rb_diff ; also in the row it is on (its skip test
  205. lda #<no_old_tiles ; compares world tiles, and one changed under
  206. sta rb_old+1 ; it). The cells stay queued for this buffer and
  207. lda #>no_old_tiles ; are redrawn once it is ready, which mends a
  208. sta rb_old+2 ; changed cell the rebuild had already drawn.
  209. jmp @drop ; (Restarting the rebuild cost up to 8 frames.)
  210. @ready: ldy #0
  211. @entry: cpy chg_count
  212. beq @drop
  213. lda chg_done,y
  214. and ap_bit
  215. bne @have
  216. sty ap_index
  217. jsr redraw_cell
  218. ldy ap_index
  219. lda chg_done,y
  220. ora ap_bit
  221. sta chg_done,y
  222. @have: iny
  223. bne @entry
  224. @drop: ldx #0 ; keep the entries one buffer still lacks
  225. ldy #0
  226. @keep: cpx chg_count
  227. beq @kept
  228. lda chg_done,x
  229. cmp #3
  230. beq @gone
  231. lda chg_cx,x
  232. sta chg_cx,y
  233. lda chg_cy,x
  234. sta chg_cy,y
  235. lda chg_done,x
  236. sta chg_done,y
  237. iny
  238. @gone: inx
  239. bne @keep
  240. @kept: sty chg_count
  241. rts
  242. ; Redraw queued cell Y in buffer ap_buf (complete, hidden) if it lies inside
  243. ; the buffer: colour, eight bitmap bytes with the dots kept, and the saved
  244. ; bytes of the dots in the cell.
  245. redraw_cell:
  246. ldx ap_buf
  247. lda chg_cx,y
  248. sec
  249. sbc buf_cx,x
  250. cmp #MAP_COLS_DRAWN
  251. bcs @out
  252. sta ap_col
  253. lda chg_cy,y
  254. sec
  255. sbc buf_cy,x
  256. cmp buf_rows,x
  257. bcc @in
  258. @out: rts
  259. @in: sta ap_row
  260. lda chg_cx,y ; the cell's tile now
  261. sta ap_wx
  262. ldx chg_cy,y
  263. ldy ap_wx
  264. jsr point_world_row
  265. lda (world_ptr),y
  266. sta ap_tile
  267. ldy ap_row ; screen RAM colour
  268. ldx ap_buf
  269. lda screen_row_low,y
  270. clc
  271. adc ap_col
  272. sta ap_scr
  273. lda screen_row_high,y
  274. adc buffer_screen_high,x
  275. sta ap_scr+1
  276. ldx ap_tile
  277. lda tile_colors,x
  278. ldy #0
  279. sta (ap_scr),y
  280. lda tile_times8,x
  281. sta ap_pat
  282. lda #0 ; ap_bmp = row base + col * 8, in buffer ap_buf
  283. sta ap_bmp+1
  284. lda ap_col
  285. asl a
  286. rol ap_bmp+1
  287. asl a
  288. rol ap_bmp+1
  289. asl a
  290. rol ap_bmp+1
  291. ldy ap_row
  292. clc
  293. adc bitmap_row_low,y
  294. sta ap_bmp
  295. lda ap_bmp+1
  296. adc bitmap_row_high,y
  297. ldx ap_buf
  298. clc
  299. adc buffer_bitmap_offsets,x
  300. sta ap_bmp+1
  301. ldy #7
  302. @byte: lda (ap_bmp),y ; dots: the %11 pixels (no tile uses %11)
  303. sta ap_cur
  304. lsr a
  305. and ap_cur
  306. and #$55
  307. sta ap_dots
  308. asl a
  309. ora ap_dots
  310. sta ap_dots
  311. tya
  312. clc
  313. adc ap_pat
  314. tax
  315. lda tile_patterns,x
  316. ora ap_dots
  317. sta (ap_bmp),y
  318. dey
  319. bpl @byte
  320. ldx ap_buf ; saved bytes under dots in this cell
  321. jsr point_lists
  322. ldy drawn_count,x
  323. @saved: tya
  324. beq @done
  325. dey
  326. lda (lst_high),y
  327. cmp ap_bmp+1
  328. bne @saved
  329. lda (lst_low),y
  330. sec
  331. sbc ap_bmp
  332. cmp #8 ; cells never straddle a page
  333. bcs @saved
  334. clc
  335. adc ap_pat
  336. tax
  337. lda tile_patterns,x
  338. sta (lst_byte),y
  339. jmp @saved
  340. @done: rts
  341. .segment "RODATA"
  342. buffer_bit: .byte 1, 2
  343. .segment "BSS"
  344. chg_count: .res 1
  345. new_cell: .res 1
  346. chg_tile: .res 1
  347. chg_ty: .res 1
  348. chg_cx: .res CHANGE_SLOTS
  349. chg_cy: .res CHANGE_SLOTS
  350. chg_done: .res CHANGE_SLOTS ; bit 0: buffer A has it, bit 1: buffer B
  351. decay_cx: .res 1
  352. decay_cy: .res 1
  353. decay_wait: .res 1
  354. decay_left: .res 1
  355. ap_buf: .res 1
  356. ap_bit: .res 1
  357. ap_index: .res 1
  358. ap_col: .res 1
  359. ap_row: .res 1
  360. ap_wx: .res 1
  361. ap_tile: .res 1
  362. ap_pat: .res 1
  363. ap_cur: .res 1
  364. ap_dots: .res 1
  365. .assert * <= SCREEN_A, lderror, "Path data must fit below VIC bank 1"

Powered by TurnKey Linux.