From 6896a3e6b7e822f32852b0f798078ef7458f5d7e Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sat, 15 Jan 2022 15:58:47 -0500 Subject: [PATCH] tiny_tracker: optimize some more --- demos/l/d4/Makefile | 15 ++---------- demos/l/d4/ay3_write_regs.s | 5 +--- demos/l/d4/d2.s | 33 +++++++++++++------------- demos/l/d4/mockingboard_init.s | 42 ++++++---------------------------- demos/l/d4/play_frame.s | 26 +++++---------------- demos/l/d4/text_to_tiny.c | 5 +++- demos/l/d4/tracker_init.s | 19 ++++++++------- 7 files changed, 45 insertions(+), 100 deletions(-) diff --git a/demos/l/d4/Makefile b/demos/l/d4/Makefile index 46bc5cb2..80698929 100644 --- a/demos/l/d4/Makefile +++ b/demos/l/d4/Makefile @@ -12,17 +12,6 @@ submit: hgr_d2_1k.zip #### -hgr_d2_1k.zip: D2 d2.s file_id.diz hgr_d2.dsk - mkdir -p demosplash2021_hgr_d2_1k - cp D2 ./demosplash2021_hgr_d2_1k - cp *.s ./demosplash2021_hgr_d2_1k - cp file_id.diz ./demosplash2021_hgr_d2_1k - cp hgr_d2.dsk ./demosplash2021_hgr_d2_1k - cp hgr_d2.webm ./demosplash2021_hgr_d2_1k - zip -r hgr_d2_1k.zip demosplash2021_hgr_d2_1k - -#### - hgr_d2.dsk: HELLO D2 cp $(EMPTY_DISK)/empty.dsk ./hgr_d2.dsk $(DOS33) -y hgr_d2.dsk SAVE A HELLO @@ -57,8 +46,8 @@ D2: d2.o d2.o: d2.s \ zp.inc hardware.inc \ mA2E_2.s mA2E_3.s \ - interrupt_handler.s mockingboard_init.s play_frame.s \ - tracker_init.s mockingboard_constants.s ay3_write_regs.s + mockingboard_init.s play_frame.s \ + tracker_init.s ay3_write_regs.s ca65 -o d2.o d2.s -l d2.lst #### diff --git a/demos/l/d4/ay3_write_regs.s b/demos/l/d4/ay3_write_regs.s index 4015e23c..63eee339 100644 --- a/demos/l/d4/ay3_write_regs.s +++ b/demos/l/d4/ay3_write_regs.s @@ -1,4 +1,3 @@ - ;===================== ;===================== ;===================== @@ -6,9 +5,7 @@ ;===================== ;===================== ;===================== - ; write all 14 registers - ; address in X - ; data in A + ; write all 14 registers at AY_REGS ay3_write_regs: diff --git a/demos/l/d4/d2.s b/demos/l/d4/d2.s index 47001941..66b80c90 100644 --- a/demos/l/d4/d2.s +++ b/demos/l/d4/d2.s @@ -9,11 +9,13 @@ ; aiming for under 256 ; 310 bytes -- initial - - -; if can straddle interrupt vector, save 10 bytes -; if can guarantee Y is 0 on entry, save 2 bytes - +; 268 bytes -- strip out interrupts +; 262 bytes -- simplify init +; 261 bytes -- optimize init more +; 253 bytes -- optimize var init +; 252 bytes -- bne vs jmp +; 250 bytes -- song only has 16 notes so can never be negative +; 249 bytes -- make terminating value $80 instead of $FF d2: @@ -30,24 +32,21 @@ tracker_song = peasant_song .include "tracker_init.s" +game_loop: + ; start the music playing - cli +.include "play_frame.s" -bob: - lda KEYPRESS - bpl bob -quiet: - lda #$3f - sta AY_REGS+7 + ; delay 20Hz, or 1/20s = 50ms -end: - bne end + lda #140 + jsr WAIT + + beq game_loop ; music .include "mA2E_2.s" -.include "interrupt_handler.s" -; must be last -.include "mockingboard_constants.s" + diff --git a/demos/l/d4/mockingboard_init.s b/demos/l/d4/mockingboard_init.s index c78280a8..dfe014a6 100644 --- a/demos/l/d4/mockingboard_init.s +++ b/demos/l/d4/mockingboard_init.s @@ -61,45 +61,17 @@ MOCK_AY_LATCH_ADDR = $7 ; 1 1 1 mockingboard_init: -; sei ; disable interrupts, is this necessary? - - ;========================= - ; Setup Interrupt Handler - ;========================= - - ; NOTE: we don't support IIc as it's a hack - ; traditionally Mockingboard on IIc was rare - - ;======================== - ; set up interrupt - ; Vector address goes to 0x3fe/0x3ff - - ; can save 10 bytes if we load in memory so this - ; is in the right place automatically - - lda #interrupt_handler ; 2 - sta $03ff ; 3 - ;========= - ; 10 ;========================= ; Initialize the 6522s ; Reset Left AY-3-8910 ;=========================== - ; entries=10 - ; 14 + 2*entries = 34 bytes - - ldy #0 ; 2 -init_it_loop: - lda init_values,Y ; 3 - ldx init_addresses,Y ; 3 - bmi doneit ; 2 - iny ; 1 - sta $c400,X ; 3 - bne init_it_loop ; 2 -doneit: - + ldx #$FF + stx MOCK_6522_DDRB1 + stx MOCK_6522_DDRA1 + inx ; #MOCK_AY_RESET $0 + stx MOCK_6522_ORB1 + ldx #MOCK_AY_INACTIVE ; $4 + stx MOCK_6522_ORB1 diff --git a/demos/l/d4/play_frame.s b/demos/l/d4/play_frame.s index 9c3ec3bd..5eaedc59 100644 --- a/demos/l/d4/play_frame.s +++ b/demos/l/d4/play_frame.s @@ -1,16 +1,4 @@ play_frame: - ; drop note down after first -; lda #$C -; sta AY_REGS+8 -; sta AY_REGS+9 -; sta AY_REGS+10 - - lda #$0E - sta AY_REGS+8 ; $08 volume A - lda #$0C - sta AY_REGS+9 ; $09 volume B - sta AY_REGS+10 ; $0A volume C - ;============================ ; see if still counting down @@ -29,18 +17,19 @@ set_notes_loop: ;================== ; see if hit end - cmp #$FF - bne all_ok + ; this song only 16 notes so valid notes always positive +; cmp #$80 + bpl all_ok ;==================================== ; if at end, loop back to beginning - lda #0 ; reset song offset + asl ; reset song offset to 0 sta SONG_OFFSET - beq set_notes_loop ; bra - + beq set_notes_loop all_ok: + note_only: ; NNNNNECC -- c=channel, e=end, n=note @@ -68,9 +57,6 @@ note_only: lda frequencies_high,Y sta AY_REGS+1,X - lda #$F - sta AY_REGS+8 - ;============================ ; point to next diff --git a/demos/l/d4/text_to_tiny.c b/demos/l/d4/text_to_tiny.c index 066d6410..f5f0450e 100644 --- a/demos/l/d4/text_to_tiny.c +++ b/demos/l/d4/text_to_tiny.c @@ -455,7 +455,10 @@ printf("\n"); printf("; last: a=%d c=%d len=%d\n",a_last,c_last,current_length); write_note(&a_last,&b_last,&c_last,&total_len); - printf("\t.byte $FF ; end\n"); +// printf("\t.byte $FF ; end\n"); + + /* assume 16 notes or fewer */ + printf("\t.byte $80 ; end\n"); total_len++; int o,n; diff --git a/demos/l/d4/tracker_init.s b/demos/l/d4/tracker_init.s index b77199a5..1a641c7d 100644 --- a/demos/l/d4/tracker_init.s +++ b/demos/l/d4/tracker_init.s @@ -3,21 +3,20 @@ tracker_init: ; setup initial ay-3-8910 values (this depends on song) init_registers_to_zero: - ldx #13 + ldx #$13 ; zero $70--$83 lda #0 - sta SONG_OFFSET ; also init song stuff - sta SONG_COUNTDOWN +; sta SONG_OFFSET ; also init song stuff +; sta SONG_COUNTDOWN init_loop: sta AY_REGS,X dex bpl init_loop -; jsr ay3_write_regs - lda #$38 sta AY_REGS+7 ; $07 mixer (ABC on) -; lda #$0E -; sta AY_REGS+8 ; $08 volume A -; lda #$0C -; sta AY_REGS+9 ; $09 volume B -; sta AY_REGS+10 ; $0A volume C + lda #$0E + sta AY_REGS+8 ; $08 volume A + lda #$0C + sta AY_REGS+9 ; $09 volume B + sta AY_REGS+10 ; $0A volume C +