|
- ; Status area: a raster split shows five rows of text below the 20-row map.
- ;
- ; Each VIC bank holds, at the same offsets, so a flip still changes only $DD00:
- ; bank + $0000 map screen RAM (bitmap colours, 21 rows)
- ; bank + $0400 text screen 1: status lines in rows 20-24
- ; bank + $0800 text screen 2: the same lines in rows 19-23
- ; bank + $1000 upper-case font: a RAM copy in bank 1 ($5000); in bank 2 the
- ; VIC-II sees the character ROM itself at $9000
- ; bank + $2000 map bitmap
- ; Colour RAM is white everywhere, which is also the text colour.
- ;
- ; Why two text screens: text row 20 starts at line 211 with y-scroll 3. When
- ; the map's y-scroll is 4-7, map row 19 is still being shown at line 210 and
- ; the VIC-II's row counter has not moved on, so the first text row is fetched
- ; from screen row 19. With y-scroll 0-3 it is fetched from row 20.
- ;
- ; Raster interrupt, two phases per frame:
- ; TOP_IRQ_LINE (vertical blank) map registers for this frame's scroll;
- ; chooses the text screen and split delay for its y-scroll
- ; SPLIT_IRQ_LINE waits for line SPLIT_LINE - 1, the last map pixel line,
- ; then switches to text in the border after that line's last
- ; pixel and before the first text fetch at SPLIT_LINE.
- STATUS_ROW = 20
- STATUS_ROWS = 5
- TEXT1_OFFSET = $0400
- TEXT2_OFFSET = $0800
- FONT_OFFSET = $1000
- TEXT_A1 = SCREEN_A + TEXT1_OFFSET + STATUS_ROW * 40
- TEXT_A2 = SCREEN_A + TEXT2_OFFSET + (STATUS_ROW - 1) * 40
- TEXT_B1 = SCREEN_B + TEXT1_OFFSET + STATUS_ROW * 40
- TEXT_B2 = SCREEN_B + TEXT2_OFFSET + (STATUS_ROW - 1) * 40
- FONT_A = SCREEN_A + FONT_OFFSET
- CHAR_ROM = $D000
- CPU_PORT_CHARS = $32 ; BASIC out, KERNAL in, character ROM at $D000
-
- VIC_IRQ_FLAGS = $D019
- VIC_IRQ_ENABLE = $D01A
- IRQ_VECTOR = $0314 ; KERNAL jumps here after saving A, X and Y
- KERNAL_IRQ_EXIT = $EA81 ; restores Y, X, A and returns from interrupt
-
- MAP_D011 = $3B ; first frame: bitmap, display on, 25 rows, y-scroll 3
- MAP_D016 = $18 ; first frame: multicolour, 40 columns, x-scroll 0
- MAP_D018 = $08 ; screen at bank + $0000, bitmap at bank + $2000
- TEXT_D011 = $1B ; text, display on, 25 rows, y-scroll 3
- TEXT_D016 = $08 ; single colour, 40 columns
- TEXT1_D018 = ((TEXT1_OFFSET / $0400) << 4) | ((FONT_OFFSET / $0800) << 1)
- TEXT2_D018 = ((TEXT2_OFFSET / $0400) << 4) | ((FONT_OFFSET / $0800) << 1)
-
- FIRST_TEXT_LINE = 51 ; first display line with y-scroll 3
- SPLIT_LINE = FIRST_TEXT_LINE + STATUS_ROW * 8 ; 211: first line of row 20
- SPLIT_IRQ_LINE = SPLIT_LINE - 3
- TOP_IRQ_LINE = 16
- SPLIT_DELAY = 9 ; delay loop count; see tools/check-split.ps1
- SPLIT_DELAY_BAD = 1 ; y-scroll 2: line 210 is a bad line, whose DMA
- ; stalls the CPU until about cycle 55
-
- ; The status area shows only the chosen person (R8, M6.2, M7.3):
- ; row 20 "P001/016 ALDRIC M" number / people count, name (10 letters), M or F
- ; row 21 "STR12 DEX09 CON15 INT10 WIS08 CHA13"
- ; rows 22-24 blank
- PERSON_DIGITS = 1 ; row 20: "Pnnn"
- COUNT_DIGITS = 5 ; row 20: "/nnn"
- NAME_COLUMN = 9 ; row 20: the name
- SEX_COLUMN = 20 ; row 20: M or F
- ATTR_DIGITS = 1 * 40 + 3 ; row 21: "STRnn", then every 6 characters
-
- .assert ((SCREEN_A + TEXT1_OFFSET) & $03FF) = 0, error, "Text screen must be 1 KB aligned"
- .assert (FONT_A & $07FF) = 0, error, "Font must be 2 KB aligned"
- .assert SCREEN_B + FONT_OFFSET = $9000, error, "Bank 2 uses the character ROM image at $9000"
-
- .export split_store, split_done, raster_irq
-
- .segment "CODE"
- ; Copy the upper-case half of the character ROM into bank 1.
- copy_font:
- sei
- lda #CPU_PORT_CHARS
- sta CPU_PORT
- ldx #0
- @page: lda CHAR_ROM,x
- sta FONT_A,x
- inx
- bne @page
- inc @page+2 ; next 256 bytes of source and target
- inc @page+5
- lda @page+2
- cmp #>(CHAR_ROM + $0800)
- bne @page
- lda #$36
- sta CPU_PORT
- cli
- rts
-
- ; Write the five status lines into all four text screen copies.
- write_status_text:
- ldx #STATUS_ROWS * 40 - 1
- @copy: lda status_text,x
- sta TEXT_A1,x
- sta TEXT_A2,x
- sta TEXT_B1,x
- sta TEXT_B2,x
- dex
- cpx #$FF
- bne @copy
- rts
-
- ; A = screen code, Y = offset in the status lines: store it in all four
- ; text screen copies. Keeps X and Y.
- show_char:
- sta TEXT_A1,y
- sta TEXT_A2,y
- sta TEXT_B1,y
- sta TEXT_B2,y
- rts
-
- ; A = 0-255, Y = offset in the status lines: three digits.
- show_number3:
- ldx #'0'
- @hund: cmp #100
- bcc @rest
- sbc #100 ; carry is set
- inx
- bne @hund
- @rest: pha
- txa
- jsr show_char
- pla
- iny
- jsr show_number
- dey
- rts
-
- ; A = 0-99, Y = offset in the status lines. Text is fetched once per
- ; character row, so a change never shows half-drawn.
- show_number:
- ldx #'0'
- @tens: cmp #10
- bcc @ones
- sbc #10
- inx
- bne @tens
- @ones: ora #'0'
- sta TEXT_A1+1,y
- sta TEXT_A2+1,y
- sta TEXT_B1+1,y
- sta TEXT_B2+1,y
- txa
- sta TEXT_A1,y
- sta TEXT_A2,y
- sta TEXT_B1,y
- sta TEXT_B2,y
- rts
-
- ; Status lines: the shown person's number (1-16), name, sex and six scores.
- show_person:
- lda #0
- sta shown_dirty
- lda shown_person
- clc
- adc #1
- ldy #PERSON_DIGITS
- jsr show_number3
- lda people_count
- ldy #COUNT_DIGITS
- jsr show_number3
- lda #0 ; name: one table per letter
- sta tab_ptr
- lda #>people_name
- sta tab_ptr+1
- lda #NAME_COLUMN
- sta attr_pos
- @name: ldy shown_person
- lda (tab_ptr),y
- ldy attr_pos
- jsr show_char
- inc attr_pos
- inc tab_ptr+1
- lda tab_ptr+1
- cmp #>people_name + NAME_LENGTH
- bne @name
- ldx shown_person
- lda people_sex,x
- tax
- lda sex_letters,x
- ldy #SEX_COLUMN
- jsr show_char
- lda #>people_attr ; scores: one table per score
- sta tab_ptr+1
- lda #ATTR_DIGITS
- sta attr_pos
- @score: ldy shown_person
- lda (tab_ptr),y
- ldy attr_pos
- jsr show_number
- inc tab_ptr+1
- lda attr_pos
- clc
- adc #6
- sta attr_pos
- cmp #ATTR_DIGITS + 6 * ATTR_COUNT
- bne @score
- rts
-
- install_raster_irq:
- sei
- lda #<raster_irq
- sta IRQ_VECTOR
- lda #>raster_irq
- sta IRQ_VECTOR+1
- cli
- rts
-
- ; Start the split with the top-of-frame phase. Call with the map shown.
- start_raster_irq:
- sei
- lda #0
- sta irq_phase
- lda #TOP_IRQ_LINE
- sta VIC_RASTER ; $D011 bit 7 (raster bit 8) is kept clear
- lda #1
- sta VIC_IRQ_FLAGS ; drop any stale request
- sta VIC_IRQ_ENABLE
- cli
- rts
-
- stop_raster_irq:
- lda #0
- sta VIC_IRQ_ENABLE
- lda #1
- sta VIC_IRQ_FLAGS
- rts
-
- raster_irq:
- .ifdef TIMING_BAR
- lda VIC_BORDER
- pha
- lda #BAR_IRQ
- sta VIC_BORDER
- .endif
- lda #1
- sta VIC_IRQ_FLAGS
- lda irq_phase
- bne @split
- inc irq_frames ; people keep their speed when frames drop
- lda map_d011 ; top of frame: map with this frame's scroll
- sta VIC_CTRL1
- lda map_d016
- sta VIC_CTRL2
- lda #MAP_D018
- sta VIC_MEMPTR
- lda map_d011 ; patch the split for this y-scroll; immediate
- and #7 ; operands keep its timing exact
- tax
- lda split_d018_for_y,x
- sta split_d018+1
- lda split_delay_for_y,x
- sta split_delay+1
- lda #SPLIT_IRQ_LINE
- sta VIC_RASTER
- inc irq_phase
- jmp irq_exit
- @split: lda #SPLIT_LINE - 1
- @wait: cmp VIC_RASTER ; start of the last map pixel line
- bne @wait
- split_delay:
- ldx #SPLIT_DELAY
- @delay: dex
- bne @delay
- split_d018:
- lda #TEXT1_D018
- ldx #TEXT_D011
- ldy #TEXT_D016
- split_store: ; check hook: these three writes must land in
- sta VIC_MEMPTR ; the border after the last map pixel
- stx VIC_CTRL1
- sty VIC_CTRL2
- split_done:
- lda #TOP_IRQ_LINE
- sta VIC_RASTER
- lda #0
- sta irq_phase
- irq_exit:
- .ifdef TIMING_BAR
- pla
- sta VIC_BORDER
- .endif
- jmp KERNAL_IRQ_EXIT
-
- .segment "RODATA"
- split_d018_for_y:
- .byte TEXT1_D018, TEXT1_D018, TEXT1_D018, TEXT1_D018
- .byte TEXT2_D018, TEXT2_D018, TEXT2_D018, TEXT2_D018
- split_delay_for_y:
- .byte SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY_BAD, SPLIT_DELAY
- .byte SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY, SPLIT_DELAY
- sex_letters: .byte "MF"
- status_text:
- .byte "P001/016 "
- .byte "STR00 DEX00 CON00 INT00 WIS00 CHA00 "
- .byte " "
- .byte " "
- .byte " "
- .assert * - status_text = STATUS_ROWS * 40, error, "Status text size"
-
- .segment "BSS"
- irq_phase: .res 1
- irq_frames: .res 1 ; +1 every frame, at the top-of-frame IRQ (M7.3)
- attr_pos: .res 1
|