You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.6KB

  1. ; Status area: a raster split shows five rows of text below the 20-row map.
  2. ;
  3. ; Each VIC bank holds, at the same offsets, so a flip still changes only $DD00:
  4. ; bank + $0000 map screen RAM (bitmap colours, 21 rows)
  5. ; bank + $0400 text screen 1: status lines in rows 20-24
  6. ; bank + $0800 text screen 2: the same lines in rows 19-23
  7. ; bank + $1000 upper-case font: a RAM copy in bank 1 ($5000); in bank 2 the
  8. ; VIC-II sees the character ROM itself at $9000
  9. ; bank + $2000 map bitmap
  10. ; Colour RAM is light red everywhere, which is also the text colour.
  11. ;
  12. ; Why two text screens: text row 20 starts at line 211 with y-scroll 3. When
  13. ; the map's y-scroll is 4-7, map row 19 is still being shown at line 210 and
  14. ; the VIC-II's row counter has not moved on, so the first text row is fetched
  15. ; from screen row 19. With y-scroll 0-3 it is fetched from row 20.
  16. ;
  17. ; Raster interrupt, two phases per frame:
  18. ; TOP_IRQ_LINE (vertical blank) map registers for this frame's scroll;
  19. ; chooses the text screen and split delay for its y-scroll
  20. ; SPLIT_IRQ_LINE waits for line SPLIT_LINE - 1, the last map pixel line,
  21. ; then switches to text in the border after that line's last
  22. ; pixel and before the first text fetch at SPLIT_LINE.
  23. STATUS_ROW = 20
  24. STATUS_ROWS = 5
  25. TEXT1_OFFSET = $0400
  26. TEXT2_OFFSET = $0800
  27. FONT_OFFSET = $1000
  28. TEXT_A1 = SCREEN_A + TEXT1_OFFSET + STATUS_ROW * 40
  29. TEXT_A2 = SCREEN_A + TEXT2_OFFSET + (STATUS_ROW - 1) * 40
  30. TEXT_B1 = SCREEN_B + TEXT1_OFFSET + STATUS_ROW * 40
  31. TEXT_B2 = SCREEN_B + TEXT2_OFFSET + (STATUS_ROW - 1) * 40
  32. FONT_A = SCREEN_A + FONT_OFFSET
  33. CHAR_ROM = $D000
  34. CPU_PORT_CHARS = $32 ; BASIC out, KERNAL in, character ROM at $D000
  35. VIC_IRQ_FLAGS = $D019
  36. VIC_IRQ_ENABLE = $D01A
  37. IRQ_VECTOR = $0314 ; KERNAL jumps here after saving A, X and Y
  38. KERNAL_IRQ_EXIT = $EA81 ; restores Y, X, A and returns from interrupt
  39. MAP_D011 = $3B ; first frame: bitmap, display on, 25 rows, y-scroll 3
  40. MAP_D016 = $18 ; first frame: multicolour, 40 columns, x-scroll 0
  41. MAP_D018 = $08 ; screen at bank + $0000, bitmap at bank + $2000
  42. TEXT_D011 = $1B ; text, display on, 25 rows, y-scroll 3
  43. TEXT_D016 = $08 ; single colour, 40 columns
  44. TEXT1_D018 = ((TEXT1_OFFSET / $0400) << 4) | ((FONT_OFFSET / $0800) << 1)
  45. TEXT2_D018 = ((TEXT2_OFFSET / $0400) << 4) | ((FONT_OFFSET / $0800) << 1)
  46. FIRST_TEXT_LINE = 51 ; first display line with y-scroll 3
  47. SPLIT_LINE = FIRST_TEXT_LINE + STATUS_ROW * 8 ; 211: first line of row 20
  48. SPLIT_IRQ_LINE = SPLIT_LINE - 3
  49. TOP_IRQ_LINE = 16
  50. SPLIT_DELAY = 9 ; delay loop count; see tools/check-split.ps1
  51. SPLIT_DELAY_BAD = 1 ; y-scroll 2: line 210 is a bad line, whose DMA
  52. ; stalls the CPU until about cycle 55
  53. VIEW_X_DIGITS = 1 * 40 + 7 ; row 21: "VIEW X nn"
  54. VIEW_Y_DIGITS = 1 * 40 + 12 ; row 21: "Y nn"
  55. PEOPLE_DIGITS = 2 * 40 + 15 ; row 22, after "PEOPLE IN VIEW "
  56. .assert ((SCREEN_A + TEXT1_OFFSET) & $03FF) = 0, error, "Text screen must be 1 KB aligned"
  57. .assert (FONT_A & $07FF) = 0, error, "Font must be 2 KB aligned"
  58. .assert SCREEN_B + FONT_OFFSET = $9000, error, "Bank 2 uses the character ROM image at $9000"
  59. .export split_store, split_done, raster_irq
  60. .segment "CODE"
  61. ; Copy the upper-case half of the character ROM into bank 1.
  62. copy_font:
  63. sei
  64. lda #CPU_PORT_CHARS
  65. sta CPU_PORT
  66. ldx #0
  67. @page: lda CHAR_ROM,x
  68. sta FONT_A,x
  69. inx
  70. bne @page
  71. inc @page+2 ; next 256 bytes of source and target
  72. inc @page+5
  73. lda @page+2
  74. cmp #>(CHAR_ROM + $0800)
  75. bne @page
  76. lda #$36
  77. sta CPU_PORT
  78. cli
  79. rts
  80. ; Write the five status lines into all four text screen copies.
  81. write_status_text:
  82. ldx #STATUS_ROWS * 40 - 1
  83. @copy: lda status_text,x
  84. sta TEXT_A1,x
  85. sta TEXT_A2,x
  86. sta TEXT_B1,x
  87. sta TEXT_B2,x
  88. dex
  89. cpx #$FF
  90. bne @copy
  91. rts
  92. ; Show the view's top-left cell and the number of people in view.
  93. update_status:
  94. lda view_cx
  95. ldy #VIEW_X_DIGITS
  96. jsr show_number
  97. lda view_cy
  98. ldy #VIEW_Y_DIGITS
  99. jsr show_number
  100. lda people_in_view
  101. ldy #PEOPLE_DIGITS
  102. ; fall through
  103. ; A = 0-99, Y = offset in the status lines. Text is fetched once per
  104. ; character row, so a change never shows half-drawn.
  105. show_number:
  106. ldx #'0'
  107. @tens: cmp #10
  108. bcc @ones
  109. sbc #10
  110. inx
  111. bne @tens
  112. @ones: ora #'0'
  113. sta TEXT_A1+1,y
  114. sta TEXT_A2+1,y
  115. sta TEXT_B1+1,y
  116. sta TEXT_B2+1,y
  117. txa
  118. sta TEXT_A1,y
  119. sta TEXT_A2,y
  120. sta TEXT_B1,y
  121. sta TEXT_B2,y
  122. rts
  123. install_raster_irq:
  124. sei
  125. lda #<raster_irq
  126. sta IRQ_VECTOR
  127. lda #>raster_irq
  128. sta IRQ_VECTOR+1
  129. cli
  130. rts
  131. ; Start the split with the top-of-frame phase. Call with the map shown.
  132. start_raster_irq:
  133. sei
  134. lda #0
  135. sta irq_phase
  136. lda #TOP_IRQ_LINE
  137. sta VIC_RASTER ; $D011 bit 7 (raster bit 8) is kept clear
  138. lda #1
  139. sta VIC_IRQ_FLAGS ; drop any stale request
  140. sta VIC_IRQ_ENABLE
  141. cli
  142. rts
  143. stop_raster_irq:
  144. lda #0
  145. sta VIC_IRQ_ENABLE
  146. lda #1
  147. sta VIC_IRQ_FLAGS
  148. rts
  149. raster_irq:
  150. .ifdef TIMING_BAR
  151. lda VIC_BORDER
  152. pha
  153. lda #BAR_IRQ
  154. sta VIC_BORDER
  155. .endif
  156. lda #1
  157. sta VIC_IRQ_FLAGS
  158. lda irq_phase
  159. bne @split
  160. lda map_d011 ; top of frame: map with this frame's scroll
  161. sta VIC_CTRL1
  162. lda map_d016
  163. sta VIC_CTRL2
  164. lda #MAP_D018
  165. sta VIC_MEMPTR
  166. lda map_d011 ; patch the split for this y-scroll; immediate
  167. and #7 ; operands keep its timing exact
  168. tax
  169. lda split_d018_for_y,x
  170. sta split_d018+1
  171. lda split_delay_for_y,x
  172. sta split_delay+1
  173. lda #SPLIT_IRQ_LINE
  174. sta VIC_RASTER
  175. inc irq_phase
  176. jmp irq_exit
  177. @split: lda #SPLIT_LINE - 1
  178. @wait: cmp VIC_RASTER ; start of the last map pixel line
  179. bne @wait
  180. split_delay:
  181. ldx #SPLIT_DELAY
  182. @delay: dex
  183. bne @delay
  184. split_d018:
  185. lda #TEXT1_D018
  186. ldx #TEXT_D011
  187. ldy #TEXT_D016
  188. split_store: ; check hook: these three writes must land in
  189. sta VIC_MEMPTR ; the border after the last map pixel
  190. stx VIC_CTRL1
  191. sty VIC_CTRL2
  192. split_done:
  193. lda #TOP_IRQ_LINE
  194. sta VIC_RASTER
  195. lda #0
  196. sta irq_phase
  197. irq_exit:
  198. .ifdef TIMING_BAR
  199. pla
  200. sta VIC_BORDER
  201. .endif
  202. jmp KERNAL_IRQ_EXIT
  203. .segment "RODATA"
  204. split_d018_for_y:
  205. .byte TEXT1_D018, TEXT1_D018, TEXT1_D018, TEXT1_D018
  206. .byte TEXT2_D018, TEXT2_D018, TEXT2_D018, TEXT2_D018
  207. split_delay_for_y:
  208. .byte SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY_BAD, SPLIT_DELAY
  209. .byte SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY
  210. status_text:
  211. .byte "LAND MAP 64 "
  212. .byte "VIEW X 00 Y 00 "
  213. .byte "PEOPLE IN VIEW 00 OF 16 "
  214. .byte " "
  215. .byte "CRSR SCROLL SPACE NEW WORLD "
  216. .assert * - status_text = STATUS_ROWS * 40, error, "Status text size"
  217. .segment "BSS"
  218. irq_phase: .res 1

Powered by TurnKey Linux.