dither4/dither4.s

160 lines
3.6 KiB
ArmAsm
Raw Normal View History

SAVMSC = $58
2022-12-08 04:37:52 +00:00
VDSLST = $200
VDSLSTL = $200
VDSLSTH = $201
2022-11-25 19:51:27 +00:00
COLPF0 = $D016
COLPF1 = $D017
COLPF2 = $D018
COLPF3 = $D019
COLBK = $D01A
2022-11-30 07:59:38 +00:00
AUDC1 = $D201
2022-11-29 20:59:26 +00:00
DMACTL = $D400
2022-11-29 22:54:02 +00:00
DLISTL = $D402
DLISTH = $D403
2022-11-25 19:51:27 +00:00
WSYNC = $D40A
VCOUNT = $D40B
NMIEN = $D40E
2022-11-26 16:48:01 +00:00
temp1l = $80
temp1h = $81
temp1 = temp1l
temp2l = $82
temp2h = $83
temp2 = temp2l
2022-11-30 07:59:38 +00:00
sample_ptrl = $84
sample_ptrh = $85
sample_ptr = sample_ptrl
2022-11-30 11:04:31 +00:00
scanline = $86
2022-12-08 04:37:52 +00:00
frame_counter = $89
2022-11-26 16:48:01 +00:00
2023-03-26 01:57:09 +00:00
;height = 160
height = 192
2022-11-26 16:48:01 +00:00
bytes_per_line = 40
pages_per_frame = 32
2022-11-30 07:59:38 +00:00
lines_per_frame = 262
2022-11-30 16:53:47 +00:00
;scanline_offset = 31 + (40 - 24) / 2
2023-03-26 03:19:27 +00:00
scanline_offset = 30
2022-11-30 11:04:31 +00:00
scanline_max = (lines_per_frame - scanline_offset) / 2
2022-11-26 16:48:01 +00:00
2022-11-25 19:51:27 +00:00
.data
2022-12-08 02:20:24 +00:00
.import frame1_top
.import frame1_bottom
2022-12-10 21:01:29 +00:00
.import frame1_palette1_even
.import frame1_palette1_odd
.import frame1_palette2_even
.import frame1_palette2_odd
.import frame1_palette3_even
.import frame1_palette3_odd
.import displaylist
2022-12-08 01:11:22 +00:00
.code
.export start
.proc start
2022-11-25 19:51:27 +00:00
; Disable display DMA
lda #$00
2022-11-29 20:59:26 +00:00
sta DMACTL
2022-11-26 16:48:01 +00:00
2022-11-29 22:54:02 +00:00
; Disable VBI and DLI but allow Reset
2022-12-08 02:20:24 +00:00
lda #$20
2022-11-29 22:54:02 +00:00
sta NMIEN
2022-11-25 19:51:27 +00:00
; Set up the display list
2022-11-26 01:35:10 +00:00
lda #.lobyte(displaylist)
2022-11-29 22:54:02 +00:00
sta DLISTL
2022-11-26 01:35:10 +00:00
lda #.hibyte(displaylist)
2022-11-29 22:54:02 +00:00
sta DLISTH
2022-11-25 19:51:27 +00:00
2022-12-08 04:37:52 +00:00
; Set up the DLI handler
lda #.lobyte(dli_handler)
sta VDSLSTL
lda #.hibyte(dli_handler)
sta VDSLSTH
; Disable VBI but allow Reset and DLI
lda #$a0
sta NMIEN
2022-11-25 19:51:27 +00:00
; Manually wait for first scan line
wait_vblank:
2022-11-30 11:04:31 +00:00
sta WSYNC
2022-11-25 19:51:27 +00:00
lda VCOUNT
2022-11-26 01:35:10 +00:00
bne wait_vblank
2022-11-25 19:51:27 +00:00
; Re-enable display DMA
lda #$22
2022-11-29 20:59:26 +00:00
sta DMACTL
2022-11-30 00:32:37 +00:00
wait_start:
2022-11-30 11:04:31 +00:00
; Wait for the vblank
; Resynchronize the scanline counter
2022-11-30 07:59:38 +00:00
wait_loop:
2022-12-11 20:13:25 +00:00
ldy VCOUNT ; 4 cycles
bne wait_loop ; 2 cycles
2022-11-26 03:17:34 +00:00
2022-12-10 21:01:29 +00:00
.macro inner_scanline frame_offset, line_offset
; Y should be VCOUNT at entry
2022-11-30 12:52:40 +00:00
; it'll fire on unused lines, but harmlessly
2022-12-10 21:01:29 +00:00
;ldy scanline ; 3 cyc
;inc scanline ; 5 cyc
2022-11-30 11:04:31 +00:00
2022-12-11 20:13:25 +00:00
; 23-26 cycles before break
2022-11-30 07:59:38 +00:00
; Leisurely memory fetches
2022-12-11 20:13:25 +00:00
lda frame1_palette1_even + frame_offset + line_offset - scanline_offset / 2,y ; 4/5 @FIXME alternate
pha ; 3
ldx frame1_palette2_even + frame_offset + line_offset - scanline_offset / 2,y ; 4/5
lda frame1_palette3_even + frame_offset + line_offset - scanline_offset / 2,y ; 4/5
tay ; 2
pla ; 3
2022-11-30 07:59:38 +00:00
; Wait for horizontal blank
2022-12-11 20:13:25 +00:00
sta WSYNC ; 4
2022-11-30 07:59:38 +00:00
2022-12-11 20:13:25 +00:00
; 12 cycles after break
2022-11-30 07:59:38 +00:00
; Update color registers as fast as possible
2022-12-11 20:13:25 +00:00
sta COLPF0 ; 4
stx COLPF1 ; 4
sty COLPF2 ; 4
2022-11-30 07:59:38 +00:00
.endmacro
2022-12-10 21:01:29 +00:00
.macro run_frame frame_offset
2022-12-08 04:37:52 +00:00
.scope
2022-12-12 00:37:47 +00:00
; each scanline is 228 color clocks
; that's 114 CPU cycles
; minus 41-43 for DMA leaves 71-73 clock cycles per line
2022-12-08 14:29:50 +00:00
each_scanline_pair:
2022-12-11 20:13:25 +00:00
sty scanline ; 3 cycles
inner_scanline frame_offset, 0 ; 23-26 cycles before break, 12 cycles after
2022-12-10 21:01:29 +00:00
2022-12-11 20:13:25 +00:00
ldy scanline ; 3 cycles
inner_scanline frame_offset, 128 ; 23-26 cycles before break, 12 cycles after
2022-12-11 21:09:14 +00:00
2022-12-12 00:37:47 +00:00
; pair cleanup: 6 cycles
2022-12-11 20:13:25 +00:00
ldy VCOUNT ; 4 cycles
bne each_scanline_pair ; 2 cycles
2022-12-12 00:37:47 +00:00
; frame cleanup: 11 cycles
2022-12-11 20:13:25 +00:00
lda frame_counter ; 3 cycles
eor #1 ; 2 cycles
sta frame_counter ; 3 cycles
2022-12-12 01:46:56 +00:00
;jmp wait_start ; 3 cycles
jmp each_frame ; 3 cycles
2022-12-08 04:37:52 +00:00
.endscope
.endmacro
2022-11-26 03:17:34 +00:00
2022-12-12 01:46:56 +00:00
each_frame:
2022-12-08 14:29:50 +00:00
run_frame1:
2022-12-10 21:01:29 +00:00
run_frame 0
2022-11-25 19:51:27 +00:00
.endproc
2022-11-26 03:17:34 +00:00
2022-12-08 04:37:52 +00:00
.proc dli_handler
2022-12-08 13:59:09 +00:00
lda #0
2022-12-08 04:37:52 +00:00
sta frame_counter
rti
2022-11-26 03:17:34 +00:00
.endproc