dither4/dither4.s

246 lines
4.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 00:35:07 +00:00
audiotemp = $87
2022-12-08 04:37:52 +00:00
frame_counter = $89
2022-11-26 16:48:01 +00:00
2022-11-30 16:53:47 +00:00
height = 160
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
scanline_offset = 47
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-11-30 07:59:38 +00:00
.import audio_samples
.import audio_samples_end
2022-11-25 19:51:27 +00:00
2022-12-08 02:20:24 +00:00
.import frame1_top
.import frame1_bottom
.import frame1_palette1
.import frame1_palette2
.import frame1_palette3
.import frame2_top
.import frame2_bottom
.import frame2_palette1
.import frame2_palette2
.import frame2_palette3
.import displaylist
2022-12-08 01:11:22 +00:00
2022-12-08 00:35:07 +00:00
audio_high_byte:
.scope
.macro byteseq val
.repeat 16
.byte val | $10
.endrep
.endmacro
byteseq $0
byteseq $1
byteseq $2
byteseq $3
byteseq $4
byteseq $5
byteseq $7
byteseq $8
byteseq $9
byteseq $a
byteseq $b
byteseq $c
byteseq $d
byteseq $e
byteseq $f
.endscope
.code
.export start
.proc start
2022-11-30 07:59:38 +00:00
; Set up the audio sample buffer
lda #.lobyte(audio_samples)
sta sample_ptrl
lda #.hibyte(audio_samples)
sta sample_ptrh
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-08 04:37:52 +00:00
ldy VCOUNT
2022-11-30 11:04:31 +00:00
bne wait_loop
2022-11-26 03:17:34 +00:00
2022-12-08 00:35:07 +00:00
.macro audio_prep
2022-12-08 00:43:45 +00:00
; Y is VCOUNT at entry
2022-12-08 00:35:07 +00:00
lda (sample_ptr),y ; 5/6 cyc
sta audiotemp ; 3 cyc
.endmacro
2022-12-08 04:37:52 +00:00
.macro inner_scanline palette1, palette2, palette3
2022-11-30 12:52:40 +00:00
; it'll fire on unused lines, but harmlessly
ldy scanline ; 3 cyc
inc scanline ; 5 cyc
2022-11-30 11:04:31 +00:00
2022-11-30 07:59:38 +00:00
; Leisurely memory fetches
2022-12-08 04:48:34 +00:00
lda palette1,y ; 5 @FIXME alternate
2022-12-08 02:20:24 +00:00
pha ; ...3?
2022-12-08 04:48:34 +00:00
ldx palette2,y ; 5
lda palette3,y ; 5
2022-11-30 07:59:38 +00:00
tay
pla
; Wait for horizontal blank
sta WSYNC
; Update color registers as fast as possible
sta COLPF0
stx COLPF1
sty COLPF2
.endmacro
2022-12-08 14:33:05 +00:00
.macro audio_play_raw
ldy VCOUNT
lda (sample_ptr),y ; 5/6 cyc
sta AUDC1 ; 4 cyc
.endmacro
2022-12-08 14:29:50 +00:00
.macro audio_play_lo
2022-12-08 00:35:07 +00:00
lda audiotemp ; 3 cyc
2022-12-08 02:20:24 +00:00
and #$0f ; 2 cyc
ora #$10 ; 2 cyc
2022-11-30 12:52:40 +00:00
sta AUDC1 ; 4 cyc
.endmacro
2022-12-08 00:35:07 +00:00
.macro audio_play_hi ; 12 cycles
ldy audiotemp ; 3 cyc
lda audio_high_byte,y ; 5 cyc
sta AUDC1 ; 4 cyc
.endmacro
2022-11-30 07:59:38 +00:00
2022-11-30 11:39:23 +00:00
.macro audio_inc
; Increment sample ptr
2022-11-30 12:52:40 +00:00
clc
lda sample_ptrl
adc #130
sta sample_ptrl
2022-11-30 11:39:23 +00:00
lda sample_ptrh
2022-11-30 12:52:40 +00:00
adc #0
sta sample_ptrh
2022-11-30 11:39:23 +00:00
cmp #.hibyte(audio_samples_end)
2022-12-08 19:47:04 +00:00
bmi audio_cont
2022-11-30 11:39:23 +00:00
2022-12-08 19:47:04 +00:00
lda sample_ptrl
cmp #.lobyte(audio_samples_end)
bmi audio_cont
2022-11-30 11:39:23 +00:00
lda #.lobyte(audio_samples)
sta sample_ptrl
lda #.hibyte(audio_samples)
sta sample_ptrh
2022-11-30 12:01:55 +00:00
audio_cont:
2022-11-30 11:39:23 +00:00
.endmacro
2022-11-30 11:36:25 +00:00
2022-12-08 04:37:52 +00:00
.macro run_frame palette1, palette2, palette3
.scope
2022-12-08 14:29:50 +00:00
each_scanline_pair:
2022-12-08 14:33:05 +00:00
;audio_prep
2022-12-08 04:37:52 +00:00
inner_scanline palette1, palette2, palette3
2022-12-08 14:33:05 +00:00
audio_play_raw
;audio_play_lo
2022-12-08 04:37:52 +00:00
inner_scanline palette1, palette2, palette3
2022-12-08 14:29:50 +00:00
;audio_play_hi ; too slow
2022-12-08 04:37:52 +00:00
ldy VCOUNT ; save for audio lookup
cpy #130
2022-12-08 14:29:50 +00:00
bne each_scanline_pair
2022-12-08 13:57:07 +00:00
2022-12-08 14:29:50 +00:00
audio_inc
2022-12-08 13:57:07 +00:00
lda frame_counter
eor #1
sta frame_counter
2022-12-08 04:37:52 +00:00
jmp wait_start
.endscope
.endmacro
2022-11-26 03:17:34 +00:00
2022-12-08 04:37:52 +00:00
lda #(256 - scanline_offset)
sta scanline
lda frame_counter
2022-12-08 14:29:50 +00:00
beq run_frame1
jmp run_frame2
run_frame1:
2022-12-08 13:57:07 +00:00
run_frame frame1_palette1, frame1_palette2, frame1_palette3
2022-12-08 13:59:09 +00:00
run_frame2:
run_frame frame2_palette1, frame2_palette2, frame2_palette3
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