25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

309 satır
9.5KB

  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 white 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. ; The status area shows only the chosen person (R8, M6.2, M7.3):
  54. ; row 20 "P001/016 ALDRIC M" number / people count, name (10 letters), M or F
  55. ; row 21 "STR12 DEX09 CON15 INT10 WIS08 CHA13"
  56. ; rows 22-24 blank
  57. PERSON_DIGITS = 1 ; row 20: "Pnnn"
  58. COUNT_DIGITS = 5 ; row 20: "/nnn"
  59. NAME_COLUMN = 9 ; row 20: the name
  60. SEX_COLUMN = 20 ; row 20: M or F
  61. ATTR_DIGITS = 1 * 40 + 3 ; row 21: "STRnn", then every 6 characters
  62. .assert ((SCREEN_A + TEXT1_OFFSET) & $03FF) = 0, error, "Text screen must be 1 KB aligned"
  63. .assert (FONT_A & $07FF) = 0, error, "Font must be 2 KB aligned"
  64. .assert SCREEN_B + FONT_OFFSET = $9000, error, "Bank 2 uses the character ROM image at $9000"
  65. .export split_store, split_done, raster_irq
  66. .segment "CODE"
  67. ; Copy the upper-case half of the character ROM into bank 1.
  68. copy_font:
  69. sei
  70. lda #CPU_PORT_CHARS
  71. sta CPU_PORT
  72. ldx #0
  73. @page: lda CHAR_ROM,x
  74. sta FONT_A,x
  75. inx
  76. bne @page
  77. inc @page+2 ; next 256 bytes of source and target
  78. inc @page+5
  79. lda @page+2
  80. cmp #>(CHAR_ROM + $0800)
  81. bne @page
  82. lda #$36
  83. sta CPU_PORT
  84. cli
  85. rts
  86. ; Write the five status lines into all four text screen copies.
  87. write_status_text:
  88. ldx #STATUS_ROWS * 40 - 1
  89. @copy: lda status_text,x
  90. sta TEXT_A1,x
  91. sta TEXT_A2,x
  92. sta TEXT_B1,x
  93. sta TEXT_B2,x
  94. dex
  95. cpx #$FF
  96. bne @copy
  97. rts
  98. ; A = screen code, Y = offset in the status lines: store it in all four
  99. ; text screen copies. Keeps X and Y.
  100. show_char:
  101. sta TEXT_A1,y
  102. sta TEXT_A2,y
  103. sta TEXT_B1,y
  104. sta TEXT_B2,y
  105. rts
  106. ; A = 0-255, Y = offset in the status lines: three digits.
  107. show_number3:
  108. ldx #'0'
  109. @hund: cmp #100
  110. bcc @rest
  111. sbc #100 ; carry is set
  112. inx
  113. bne @hund
  114. @rest: pha
  115. txa
  116. jsr show_char
  117. pla
  118. iny
  119. jsr show_number
  120. dey
  121. rts
  122. ; A = 0-99, Y = offset in the status lines. Text is fetched once per
  123. ; character row, so a change never shows half-drawn.
  124. show_number:
  125. ldx #'0'
  126. @tens: cmp #10
  127. bcc @ones
  128. sbc #10
  129. inx
  130. bne @tens
  131. @ones: ora #'0'
  132. sta TEXT_A1+1,y
  133. sta TEXT_A2+1,y
  134. sta TEXT_B1+1,y
  135. sta TEXT_B2+1,y
  136. txa
  137. sta TEXT_A1,y
  138. sta TEXT_A2,y
  139. sta TEXT_B1,y
  140. sta TEXT_B2,y
  141. rts
  142. ; Status lines: the shown person's number (1-16), name, sex and six scores.
  143. show_person:
  144. lda #0
  145. sta shown_dirty
  146. lda shown_person
  147. clc
  148. adc #1
  149. ldy #PERSON_DIGITS
  150. jsr show_number3
  151. lda people_count
  152. ldy #COUNT_DIGITS
  153. jsr show_number3
  154. lda #0 ; name: one table per letter
  155. sta tab_ptr
  156. lda #>people_name
  157. sta tab_ptr+1
  158. lda #NAME_COLUMN
  159. sta attr_pos
  160. @name: ldy shown_person
  161. lda (tab_ptr),y
  162. ldy attr_pos
  163. jsr show_char
  164. inc attr_pos
  165. inc tab_ptr+1
  166. lda tab_ptr+1
  167. cmp #>people_name + NAME_LENGTH
  168. bne @name
  169. ldx shown_person
  170. lda people_sex,x
  171. tax
  172. lda sex_letters,x
  173. ldy #SEX_COLUMN
  174. jsr show_char
  175. lda #>people_attr ; scores: one table per score
  176. sta tab_ptr+1
  177. lda #ATTR_DIGITS
  178. sta attr_pos
  179. @score: ldy shown_person
  180. lda (tab_ptr),y
  181. ldy attr_pos
  182. jsr show_number
  183. inc tab_ptr+1
  184. lda attr_pos
  185. clc
  186. adc #6
  187. sta attr_pos
  188. cmp #ATTR_DIGITS + 6 * ATTR_COUNT
  189. bne @score
  190. rts
  191. install_raster_irq:
  192. sei
  193. lda #<raster_irq
  194. sta IRQ_VECTOR
  195. lda #>raster_irq
  196. sta IRQ_VECTOR+1
  197. cli
  198. rts
  199. ; Start the split with the top-of-frame phase. Call with the map shown.
  200. start_raster_irq:
  201. sei
  202. lda #0
  203. sta irq_phase
  204. lda #TOP_IRQ_LINE
  205. sta VIC_RASTER ; $D011 bit 7 (raster bit 8) is kept clear
  206. lda #1
  207. sta VIC_IRQ_FLAGS ; drop any stale request
  208. sta VIC_IRQ_ENABLE
  209. cli
  210. rts
  211. stop_raster_irq:
  212. lda #0
  213. sta VIC_IRQ_ENABLE
  214. lda #1
  215. sta VIC_IRQ_FLAGS
  216. rts
  217. raster_irq:
  218. .ifdef TIMING_BAR
  219. lda VIC_BORDER
  220. pha
  221. lda #BAR_IRQ
  222. sta VIC_BORDER
  223. .endif
  224. lda #1
  225. sta VIC_IRQ_FLAGS
  226. lda irq_phase
  227. bne @split
  228. inc irq_frames ; people keep their speed when frames drop
  229. lda map_d011 ; top of frame: map with this frame's scroll
  230. sta VIC_CTRL1
  231. lda map_d016
  232. sta VIC_CTRL2
  233. lda #MAP_D018
  234. sta VIC_MEMPTR
  235. lda map_d011 ; patch the split for this y-scroll; immediate
  236. and #7 ; operands keep its timing exact
  237. tax
  238. lda split_d018_for_y,x
  239. sta split_d018+1
  240. lda split_delay_for_y,x
  241. sta split_delay+1
  242. lda #SPLIT_IRQ_LINE
  243. sta VIC_RASTER
  244. inc irq_phase
  245. jmp irq_exit
  246. @split: lda #SPLIT_LINE - 1
  247. @wait: cmp VIC_RASTER ; start of the last map pixel line
  248. bne @wait
  249. split_delay:
  250. ldx #SPLIT_DELAY
  251. @delay: dex
  252. bne @delay
  253. split_d018:
  254. lda #TEXT1_D018
  255. ldx #TEXT_D011
  256. ldy #TEXT_D016
  257. split_store: ; check hook: these three writes must land in
  258. sta VIC_MEMPTR ; the border after the last map pixel
  259. stx VIC_CTRL1
  260. sty VIC_CTRL2
  261. split_done:
  262. lda #TOP_IRQ_LINE
  263. sta VIC_RASTER
  264. lda #0
  265. sta irq_phase
  266. irq_exit:
  267. .ifdef TIMING_BAR
  268. pla
  269. sta VIC_BORDER
  270. .endif
  271. jmp KERNAL_IRQ_EXIT
  272. .segment "RODATA"
  273. split_d018_for_y:
  274. .byte TEXT1_D018, TEXT1_D018, TEXT1_D018, TEXT1_D018
  275. .byte TEXT2_D018, TEXT2_D018, TEXT2_D018, TEXT2_D018
  276. split_delay_for_y:
  277. .byte SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY_BAD, SPLIT_DELAY
  278. .byte SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY
  279. sex_letters: .byte "MF"
  280. status_text:
  281. .byte "P001/016 "
  282. .byte "STR00 DEX00 CON00 INT00 WIS00 CHA00 "
  283. .byte " "
  284. .byte " "
  285. .byte " "
  286. .assert * - status_text = STATUS_ROWS * 40, error, "Status text size"
  287. .segment "BSS"
  288. irq_phase: .res 1
  289. irq_frames: .res 1 ; +1 every frame, at the top-of-frame IRQ (M7.3)
  290. attr_pos: .res 1

Powered by TurnKey Linux.