interlace: split off pt3_set_pattern

This commit is contained in:
Vince Weaver 2019-09-16 21:04:25 -04:00
parent 83b46be19d
commit a2fd3f42b3
3 changed files with 131 additions and 110 deletions

View File

@ -94,6 +94,7 @@ end_vars=$80+(NOTE_STRUCT_SIZE*3)
.include "pt3_lib_sample_ornament.s"
.include "pt3_lib_calculate_note.s"
.include "pt3_lib_decode_note.s"
.include "pt3_lib_set_pattern.s"
.include "pt3_lib_make_frame.s"
.include "pt3_lib_do_frame.s"

View File

@ -2,113 +2,6 @@
; EVERYTHING IS CYCLE COUNTED
;========================================================================
;=====================================
; Set Pattern
;=====================================
pt3_set_pattern:
; Lookup current pattern in pattern table
current_pattern_smc:
ldy #$d1 ; 2
lda PT3_LOC+PT3_PATTERN_TABLE,Y ; 4+
; if value is $FF we are at the end of the song
cmp #$ff ; 2
bne not_done ; 3
is_done:
; done with song, set it to non-zero
sta DONE_SONG ; 3
rts ; 6
;============
; 20 if end
not_done:
; set up the three pattern address pointers
asl ; mul pattern offset by two, as word sized ; 2
tay ; 2
; point PATTERN_H/PATTERN_L to the pattern address table
clc ; 2
lda PT3_LOC+PT3_PATTERN_LOC_L ; 4
sta PATTERN_L ; 3
lda PT3_LOC+PT3_PATTERN_LOC_H ; 4
adc #>PT3_LOC ; assume page boundary ; 2
sta PATTERN_H ; 3
; First 16-bits points to the Channel A address
lda (PATTERN_L),Y ; 5+
sta note_a+NOTE_ADDR_L ; 4
iny ; 2
lda (PATTERN_L),Y ; 5+
adc #>PT3_LOC ; assume page boundary ; 2
sta note_a+NOTE_ADDR_H ; 4
iny ; 2
; Next 16-bits points to the Channel B address
lda (PATTERN_L),Y ; 5+
sta note_b+NOTE_ADDR_L ; 4
iny ; 2
lda (PATTERN_L),Y ; 5+
adc #>PT3_LOC ; assume page boundary ; 2
sta note_b+NOTE_ADDR_H ; 4
iny ; 2
; Next 16-bits points to the Channel C address
lda (PATTERN_L),Y ; 5+
sta note_c+NOTE_ADDR_L ; 4
iny ; 2
lda (PATTERN_L),Y ; 5+
adc #>PT3_LOC ; assume page boundary ; 2
sta note_c+NOTE_ADDR_H ; 4
; clear out the noise channel
lda #0 ; 2
sta pt3_noise_period_smc+1 ; 4
; Set all three channels as active
; FIXME: num_channels, may need to be 6 if doing 6-channel pt3?
lda #3 ; 2
sta pt3_pattern_done_smc+1 ; 4
rts ; 6
;==========================
; pattern done early!
early_end:
; A is pattern_done which is zero at this point
inc current_pattern_smc+1 ; increment pattern ; 6
sta current_line_smc+1 ; 4
sta current_subframe_smc+1 ; 4
; always goes to set_pattern here?
jmp set_pattern ; 3
check_subframe:
lda current_subframe_smc+1 ; 4
bne pattern_good ; 2/3
set_pattern:
; load a new pattern in
jsr pt3_set_pattern ;6+?
lda DONE_SONG ; 3
beq pt3_new_line ; 2/3
rts ; 6
;==========================================
; real entry point
;=====================================
;=====================================
@ -138,13 +31,22 @@ current_line_smc:
beq check_subframe ; 3
; -1
;=============================
; State B
;=============================
;
pattern_good:
; see if we need a new line
current_subframe_smc:
lda #$d1 ; 2
bne line_good ; 2/3
bne line_good ; 3
; -1
;=============================
; State C
;=============================
;
pt3_new_line:
; decode a new line
jsr pt3_decode_line ; 6+?
@ -157,7 +59,11 @@ pt3_pattern_done_smc:
beq early_end ; 2/3
;========================================
;=============================
; State D
;=============================
;
line_good:
; Increment everything
@ -169,7 +75,13 @@ line_good:
pt3_speed_smc:
eor #$d1 ; 2
bne do_frame ; 2/3
bne do_frame ; 3
; -1
;=============================
; State G
;=============================
;
next_line:
sta current_subframe_smc+1 ; reset subframe to 0 ; 4

View File

@ -0,0 +1,108 @@
;========================================================================
; EVERYTHING IS CYCLE COUNTED
;========================================================================
;=====================================
; Set Pattern
;=====================================
pt3_set_pattern:
; Lookup current pattern in pattern table
current_pattern_smc:
ldy #$d1 ; 2
lda PT3_LOC+PT3_PATTERN_TABLE,Y ; 4+
; if value is $FF we are at the end of the song
cmp #$ff ; 2
bne not_done ; 3
is_done:
; done with song, set it to non-zero
sta DONE_SONG ; 3
rts ; 6
;============
; 20 if end
not_done:
; set up the three pattern address pointers
asl ; mul pattern offset by two, as word sized ; 2
tay ; 2
; point PATTERN_H/PATTERN_L to the pattern address table
clc ; 2
lda PT3_LOC+PT3_PATTERN_LOC_L ; 4
sta PATTERN_L ; 3
lda PT3_LOC+PT3_PATTERN_LOC_H ; 4
adc #>PT3_LOC ; assume page boundary ; 2
sta PATTERN_H ; 3
; First 16-bits points to the Channel A address
lda (PATTERN_L),Y ; 5+
sta note_a+NOTE_ADDR_L ; 4
iny ; 2
lda (PATTERN_L),Y ; 5+
adc #>PT3_LOC ; assume page boundary ; 2
sta note_a+NOTE_ADDR_H ; 4
iny ; 2
; Next 16-bits points to the Channel B address
lda (PATTERN_L),Y ; 5+
sta note_b+NOTE_ADDR_L ; 4
iny ; 2
lda (PATTERN_L),Y ; 5+
adc #>PT3_LOC ; assume page boundary ; 2
sta note_b+NOTE_ADDR_H ; 4
iny ; 2
; Next 16-bits points to the Channel C address
lda (PATTERN_L),Y ; 5+
sta note_c+NOTE_ADDR_L ; 4
iny ; 2
lda (PATTERN_L),Y ; 5+
adc #>PT3_LOC ; assume page boundary ; 2
sta note_c+NOTE_ADDR_H ; 4
; clear out the noise channel
lda #0 ; 2
sta pt3_noise_period_smc+1 ; 4
; Set all three channels as active
; FIXME: num_channels, may need to be 6 if doing 6-channel pt3?
lda #3 ; 2
sta pt3_pattern_done_smc+1 ; 4
rts ; 6
;==========================
; pattern done early!
early_end:
; A is pattern_done which is zero at this point
inc current_pattern_smc+1 ; increment pattern ; 6
sta current_line_smc+1 ; 4
sta current_subframe_smc+1 ; 4
; always goes to set_pattern here?
jmp set_pattern ; 3
check_subframe:
lda current_subframe_smc+1 ; 4
bne pattern_good ; 2/3
set_pattern:
; load a new pattern in
jsr pt3_set_pattern ;6+?
lda DONE_SONG ; 3
beq pt3_new_line ; 2/3
rts ; 6