tiny_tracker: more work

This commit is contained in:
Vince Weaver 2022-01-10 01:20:48 -05:00
parent 489fdb2ac9
commit d909751ed5
4 changed files with 56 additions and 78 deletions

View File

@ -12,16 +12,21 @@
; 426 bytes -- terminate init with $FF rather than extra $00 ; 426 bytes -- terminate init with $FF rather than extra $00
; 424 bytes -- move inits to zero together ; 424 bytes -- move inits to zero together
; 414 bytes -- update ay output to write all registers ; 414 bytes -- update ay output to write all registers
; 405 bytes -- more optimizing the interrupt handler
; 398 bytes -- only put song address one place
; 393 bytes -- don't keep song offset in Y
d2: d2:
;=================== ;===================
; music Player Setup ; music Player Setup
lda #<peasant_song tracker_song = peasant_song
sta SONG_L
lda #>peasant_song ; lda #<peasant_song
sta SONG_H ; sta SONG_L
; lda #>peasant_song
; sta SONG_H
; assume mockingboard in slot#4 ; assume mockingboard in slot#4

View File

@ -19,9 +19,12 @@
interrupt_handler: interrupt_handler:
php ; save status flags php ; save status flags
cld ; clear decimal mode FIXME
pha ; save A ; 3 ; we don't use decimal mode so no need to clear it?
; A is saved in $45 by firmware
; A is saved in $45 by firmware
; we are assuming a II/II+/IIe here
txa txa
pha ; save X pha ; save X
tya tya
@ -31,36 +34,39 @@ interrupt_handler:
ay3_irq_handler: ay3_irq_handler:
bit MOCK_6522_T1CL ; clear 6522 interrupt by reading T1C-L ; 4
;==========================================
; clear 6522 interrupt by reading T1C-L ; 4
bit MOCK_6522_T1CL
;============================
; see if still counting down ; see if still counting down
lda SONG_COUNTDOWN lda SONG_COUNTDOWN
bpl done_update_song bpl done_update_song
try_again:
ldy SONG_OFFSET
set_notes_loop: set_notes_loop:
;==================
; load next byte
ldy SONG_OFFSET
lda tracker_song,Y
;==================
; see if hit end ; see if hit end
lda (SONG_L),Y
cmp #$C0 cmp #$C0
bne all_ok bne all_ok
; if at end, loop ;====================================
; if at end, loop back to beginning
loop_forever: ldy #0 ; reset song offset
; jmp loop_forever sty SONG_OFFSET
beq set_notes_loop ; bra
lda #0
sta SONG_OFFSET
; lda #<peasant_song
; sta SONG_L
; lda #>peasant_song
; sta SONG_H
beq try_again ; bra
all_ok: all_ok:
; see if note ; see if note
@ -79,30 +85,26 @@ note_only:
lsr lsr
lsr lsr
lsr lsr
sta octave_smc+1 sta OCTAVE ; save octave for later
lsr lsr
and #$FE and #$FE ; fine register value, want in X
sta out_smc+1 sta REGISTER
txa
txa ; get note
and #$3F and #$3F
tax tax ; lookup in table
lda frequency_lookup_low,X lda frequency_lookup_low,X
sty y_smc+1 ; backup Y
out_smc: ldx REGISTER
ldx #$00
sta AY_REGS,X sta AY_REGS,X
; jsr ay3_write_regs ; trashes A/Y
; set coarse note A ; set coarse note A
; hack: if octave=0 (C2) then coarse=1 ; hack: if octave=0 (C2) then coarse=1
; else coarse=0 ; else coarse=0
inx inx
octave_smc: lda OCTAVE
lda #$dd
and #$3 ; if 0 then 1 and #$3 ; if 0 then 1
; if 1,2,3 then 0 ; if 1,2,3 then 0
bne blah0 bne blah0
@ -115,13 +117,14 @@ blah_blah:
sta AY_REGS,X sta AY_REGS,X
jsr ay3_write_regs ; trashes A/X/Y jsr ay3_write_regs ; trashes A/X/Y
y_smc:
ldy #0
iny
; bne not_wrap2 ; assume less than 256 bytes ;============================
; inc SONG_H ; point to next
;not_wrap2:
inc SONG_OFFSET
; assume less than 256 bytes
bne set_notes_loop ; bra bne set_notes_loop ; bra
handle_timing: handle_timing:
@ -131,13 +134,7 @@ handle_timing:
and #$3f and #$3f
sta SONG_COUNTDOWN sta SONG_COUNTDOWN
iny inc SONG_OFFSET
sty SONG_OFFSET
bne not_wrap1
inc SONG_H
not_wrap1:
done_update_song: done_update_song:
dec SONG_COUNTDOWN dec SONG_COUNTDOWN
@ -153,10 +150,10 @@ done_ay3_irq_handler:
tay ; restore Y tay ; restore Y
pla pla
tax ; restore X tax ; restore X
pla ; restore a ; 4
; on II+/IIe (but not IIc) we need to do this? ; on II+/IIe the firmware saves A in $45
interrupt_smc: ; this won't work on a IIc/IIgs
lda $45 ; restore A lda $45 ; restore A
plp ; restore flags plp ; restore flags
@ -166,9 +163,3 @@ interrupt_smc:
; typical ; typical
; ???? cycles ; ???? cycles

View File

@ -114,25 +114,5 @@ init_loop:
jsr ay3_write_regs jsr ay3_write_regs
.if 0
; 24 bytes + 13 bytes = 37 bytes
init_loop:
txa
tay
lda (SONG_L),Y
jsr ay3_write_reg ; trashes Y
dex
bne init_loop
; update SONG_L to point past the init
lda SONG_L
clc
adc #14
sta SONG_L
bcc no_oflo
inc SONG_H
no_oflo:
.endif

View File

@ -15,6 +15,8 @@ SONG_L = $80
SONG_H = $81 SONG_H = $81
SONG_OFFSET = $82 SONG_OFFSET = $82
SONG_COUNTDOWN = $83 SONG_COUNTDOWN = $83
OCTAVE = $84
REGISTER = $85
OUR_ROT = $A5 OUR_ROT = $A5