annotate cycles

This commit is contained in:
Brooke Vibber 2022-12-11 12:13:25 -08:00
parent 4361b4054d
commit 539ecdc5ae

102
dither4.s
View file

@ -133,13 +133,13 @@ wait_start:
; Wait for the vblank
; Resynchronize the scanline counter
wait_loop:
ldy VCOUNT
bne wait_loop
ldy VCOUNT ; 4 cycles
bne wait_loop ; 2 cycles
.macro audio_prep
; Y is VCOUNT at entry
lda (sample_ptr),y ; 5/6 cyc
sta audiotemp ; 3 cyc
sta audiotemp ; 3 cyc
.endmacro
.macro inner_scanline frame_offset, line_offset
@ -148,27 +148,28 @@ wait_loop:
;ldy scanline ; 3 cyc
;inc scanline ; 5 cyc
; 23-26 cycles before break
; Leisurely memory fetches
lda frame1_palette1_even + frame_offset + line_offset - scanline_offset / 2,y ; 5 @FIXME alternate
pha ; ...3?
ldx frame1_palette2_even + frame_offset + line_offset - scanline_offset / 2,y ; 5
lda frame1_palette3_even + frame_offset + line_offset - scanline_offset / 2,y ; 5
tay
pla
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
; Wait for horizontal blank
sta WSYNC
sta WSYNC ; 4
; 12 cycles after break
; Update color registers as fast as possible
sta COLPF0
stx COLPF1
sty COLPF2
sta COLPF0 ; 4
stx COLPF1 ; 4
sty COLPF2 ; 4
.endmacro
.macro audio_play_raw
;ldy VCOUNT ; set on entry
lda (sample_ptr),y ; 5/6 cyc
sta AUDC1 ; 4 cyc
sta AUDC1 ; 4 cyc
.endmacro
.macro audio_play_lo
@ -186,25 +187,29 @@ wait_loop:
.macro audio_inc
; Increment sample ptr
clc
lda sample_ptrl
adc #131
sta sample_ptrl
lda sample_ptrh
adc #0
sta sample_ptrh
; 18 cycles
clc ; 2
lda sample_ptrl ; 3
adc #131 ; 2
sta sample_ptrl ; 3
lda sample_ptrh ; 3
adc #0 ; 2
sta sample_ptrh ; 3
cmp #.hibyte(audio_samples_end)
bmi audio_cont
; 4 cycles
cmp #.hibyte(audio_samples_end) ; 2
bmi audio_cont ; 2
lda sample_ptrl
cmp #.lobyte(audio_samples_end)
bmi audio_cont
; 7 cycles, optional
lda sample_ptrl ; 3
cmp #.lobyte(audio_samples_end) ; 2
bmi audio_cont ; 2
lda #.lobyte(audio_samples)
sta sample_ptrl
lda #.hibyte(audio_samples)
sta sample_ptrh
; 10 cycles, optional
lda #.lobyte(audio_samples) ; 2
sta sample_ptrl ; 3
lda #.hibyte(audio_samples) ; 2
sta sample_ptrh ; 3
audio_cont:
.endmacro
@ -213,32 +218,35 @@ wait_loop:
.scope
each_scanline_pair:
;audio_prep
sty scanline
inner_scanline frame_offset, 0
sty scanline ; 3 cycles
inner_scanline frame_offset, 0 ; 23-26 cycles before break, 12 cycles after
ldy scanline
audio_play_raw
ldy scanline ; 3 cycles
audio_play_raw ; 9-10 cycles
;audio_play_lo
inner_scanline frame_offset, 128
inner_scanline frame_offset, 128 ; 23-26 cycles before break, 12 cycles after
;audio_play_raw
;audio_play_hi ; too slow
ldy VCOUNT ; save for audio lookup
cpy #0
bne each_scanline_pair
; save for audio lookup
ldy VCOUNT ; 4 cycles
cpy #0 ; 2 cycles
bne each_scanline_pair ; 2 cycles
audio_inc ; @FIXME
lda frame_counter
eor #1
sta frame_counter
; only once when we hit scanline 0:
audio_inc ; 22-39 cycles
jmp wait_start
lda frame_counter ; 3 cycles
eor #1 ; 2 cycles
sta frame_counter ; 3 cycles
jmp wait_start ; 3 cycles
.endscope
.endmacro
lda frame_counter
beq run_frame1
jmp run_frame2
lda frame_counter ; 3 cycles
beq run_frame1 ; 2 cycles
jmp run_frame2 ; 3 cycles
run_frame1:
run_frame 0
run_frame2: