audio partly working

This commit is contained in:
Brooke Vibber 2022-11-29 23:59:38 -08:00
commit 6776951aea
7 changed files with 193 additions and 698 deletions

130
dither4.s
View file

@ -1,13 +1,11 @@
SAVMSC = $58
;SDMCTL = $22F
;SDLSTL = $230
;SDLSTH = $231
COLPF0 = $D016
COLPF1 = $D017
COLPF2 = $D018
COLPF3 = $D019
COLBK = $D01A
AUDC1 = $D201
DMACTL = $D400
DLISTL = $D402
DLISTH = $D403
@ -24,10 +22,14 @@ temp1 = temp1l
temp2l = $82
temp2h = $83
temp2 = temp2l
sample_ptrl = $84
sample_ptrh = $85
sample_ptr = sample_ptrl
height = 192
bytes_per_line = 40
pages_per_frame = 32
lines_per_frame = 262
.data
@ -35,6 +37,8 @@ pages_per_frame = 32
.import palette2
.import palette3
.import bitmap
.import audio_samples
.import audio_samples_end
displaylist:
; 24 lines overscan
@ -70,18 +74,24 @@ displaylist:
lda #.hibyte(bitmap)
sta temp1h
lda #.lobyte(framebuffer)
sta temp2h
sta temp2l
lda #.hibyte(framebuffer)
sta temp2h
jsr copy_half_frame
; Second half of bitmap has to be separately aligned
lda #.lobyte(framebuffer2)
sta temp2h
sta temp2l
lda #.hibyte(framebuffer2)
sta temp2h
jsr copy_half_frame
; Set up the audio sample buffer
lda #.lobyte(audio_samples)
sta sample_ptrl
lda #.hibyte(audio_samples)
sta sample_ptrh
; Disable display DMA
lda #$00
sta DMACTL
@ -106,40 +116,102 @@ wait_vblank:
lda #$22
sta DMACTL
wait_loop:
sta WSYNC
; Wait for the next even scanline (VCOUNT is scan line / 2, so look for a change)
wait_start:
lda VCOUNT
cmp #15
bne wait_loop
ldy #0
sta temp1
wait_loop:
lda VCOUNT
cmp temp1
beq wait_loop
each_scanline:
tya
pha
lda palette1,y
pha
ldx palette2,y
lda palette3,y
lda VCOUNT
; Resynchronize the scanline counter
; it'll fire on unused lines, but harmlessly
clc
sbc #15
asl
tay
pla
; Wait for horizontal blank
sta WSYNC
.macro audio_prep
; audio sample; low nybble
ldx #0
lda (sample_ptr,x)
sta temp2
; Update color registers as fast as possible
sta COLPF0
stx COLPF1
sty COLPF2
; high nybble
lsr a
lsr a
lsr a
lsr a
; set the volume-only bit
ora #$10
pha
pla
tay
; low nybble
lda temp2
and #$0f
; set the volume-only bit
ora #$10
pha
.endmacro
.macro audio_inc
; Increment sample ptr
clc
lda sample_ptrl
adc #1
sta sample_ptrl
lda sample_ptrh
adc #0
sta sample_ptrh
lda sample_ptrh
cmp #.hibyte(audio_samples_end)
bne audio_cont
lda sample_ptrl
cmp #.lobyte(audio_samples_end)
bne audio_cont
lda #.lobyte(audio_samples)
sta sample_ptrl
lda #.hibyte(audio_samples)
sta sample_ptrh
audio_cont:
.endmacro
.macro inner_scanline
; Leisurely memory fetches
lda palette1,y
pha
ldx palette2,y
lda palette3,y
tay
pla
; Wait for horizontal blank
sta WSYNC
; Update color registers as fast as possible
sta COLPF0
stx COLPF1
sty COLPF2
; Audio sample
pla
sta AUDC1
.endmacro
audio_prep
inner_scanline
audio_inc
iny
cpy #height
bne each_scanline
inner_scanline
jmp wait_start
;jmp wait_start
jmp each_scanline
.endproc