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