From 27516de7f94ec0d1dc99cdfa6ff91036ae97b1ff Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 9 Nov 2022 22:21:25 -0500 Subject: [PATCH] tracker6: make it interrupt-run --- music/tiny_tracker6/Makefile | 5 +- music/tiny_tracker6/d4.s | 35 ++-------- music/tiny_tracker6/interrupt_handler.s | 68 ++++++++++++++++++++ music/tiny_tracker6/mockingboard_constants.s | 21 ++++++ music/tiny_tracker6/mockingboard_init.s | 56 ++++++++++++++-- music/tiny_tracker6/play_frame.s | 30 +++++++-- 6 files changed, 170 insertions(+), 45 deletions(-) create mode 100644 music/tiny_tracker6/interrupt_handler.s create mode 100644 music/tiny_tracker6/mockingboard_constants.s diff --git a/music/tiny_tracker6/Makefile b/music/tiny_tracker6/Makefile index f95d6726..891fec3f 100644 --- a/music/tiny_tracker6/Makefile +++ b/music/tiny_tracker6/Makefile @@ -37,7 +37,8 @@ d4.o: d4.s \ zp.inc hardware.inc \ mA2E_4.s \ mockingboard_init.s play_frame.s \ - tracker_init.s ay3_write_regs.s + tracker_init.s ay3_write_regs.s interrupt_handler.s \ + mockingboard_constants.s ca65 -o d4.o d4.s -l d4.lst @@ -53,4 +54,4 @@ text_to_tiny.o: text_to_tiny.c #### clean: - rm -f *~ *.o *.lst D2 HELLO text_to_tiny mA2E_2.s mA2E_3.s mA2E_4.s + rm -f *~ *.o *.lst D4 HELLO text_to_tiny mA2E_2.s mA2E_3.s mA2E_4.s diff --git a/music/tiny_tracker6/d4.s b/music/tiny_tracker6/d4.s index 84c469a3..a668269b 100644 --- a/music/tiny_tracker6/d4.s +++ b/music/tiny_tracker6/d4.s @@ -6,21 +6,8 @@ .include "zp.inc" .include "hardware.inc" -; for a 256 entry we need to fit in 252 bytes -; 310 bytes -- initial -; 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 -; 247 bytes -- combine note loop. makes song a bit faster -; 245 bytes -- try to optimize writing out volume -; 255 bytes -- add in some visualization -; 252 bytes -- re-arrange decode code -d2: +d4: ;=================== ; music Player Setup @@ -37,26 +24,14 @@ tracker_song = peasant_song jsr SETGR ; enable lo-res graphics + cli ; enable music game_loop: - ; typically A=0, X=FF, Y=0 here - ; play a frame of music -.include "play_frame.s" -.include "ay3_write_regs.s" + jmp game_loop - ; delay 20Hz, or 1/20s = 50ms - - lda #140 - jsr WAIT - - lda #140 - jsr WAIT - - lda #140 - jsr WAIT - - beq game_loop +.include "interrupt_handler.s" +.include "mockingboard_constants.s" ; music .include "mA2E_4.s" diff --git a/music/tiny_tracker6/interrupt_handler.s b/music/tiny_tracker6/interrupt_handler.s new file mode 100644 index 00000000..0197a712 --- /dev/null +++ b/music/tiny_tracker6/interrupt_handler.s @@ -0,0 +1,68 @@ + ;================================ + ;================================ + ; mockingboard interrupt handler + ;================================ + ;================================ + ; On Apple II/6502 the interrupt handler jumps to address in 0xfffe + ; This is in the ROM, which saves the registers + ; on older IIe it saved A to $45 (which could mess with DISK II) + ; newer IIe doesn't do that. + ; It then calculates if it is a BRK or not (which trashes A) + ; Then it sets up the stack like an interrupt and calls 0x3fe + + ; Note: the IIc is much more complicated + ; its firmware tries to decode the proper source + ; based on various things, including screen hole values + ; we bypass that by switching out ROM and replacing the + ; $fffe vector with this, but that does mean we have + ; to be sure status flag and accumulator set properly + +interrupt_handler: + php ; save status flags + cld ; clear decimal mode + pha ; save A ; 3 + ; A is saved in $45 by firmware + txa + pha ; save X + tya + pha ; save Y + + inc $0404 ; debug (flashes char onscreen) + + +ay3_irq_handler: + bit MOCK_6522_T1CL ; clear 6522 interrupt by reading T1C-L ; 4 + + +.include "play_frame.s" +.include "ay3_write_regs.s" + + ;================================= + ; Finally done with this interrupt + ;================================= + +done_ay3_irq_handler: + + pla + tay ; restore Y + pla + tax ; restore X + pla ; restore a ; 4 + + ; on II+/IIe (but not IIc) we need to do this? +interrupt_smc: + lda $45 ; restore A + plp ; restore flags + + rti ; return from interrupt ; 6 + + ;============ + ; typical + ; ???? cycles + + + + + + + diff --git a/music/tiny_tracker6/mockingboard_constants.s b/music/tiny_tracker6/mockingboard_constants.s new file mode 100644 index 00000000..0d70c32f --- /dev/null +++ b/music/tiny_tracker6/mockingboard_constants.s @@ -0,0 +1,21 @@ +init_addresses: + .byte interrupt_handler ; 2 + sta $03ff ; 3 + ;========= + ; 10 + ;========================= + ; Initialize the 6522s + ; Reset Left AY-3-8910 + ;=========================== + + ; entries=10 + ; 14 + 2*entries = 34 bytes + +; assume Y=0 on entry? + + 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: diff --git a/music/tiny_tracker6/play_frame.s b/music/tiny_tracker6/play_frame.s index ec8180c8..c08aa2ff 100644 --- a/music/tiny_tracker6/play_frame.s +++ b/music/tiny_tracker6/play_frame.s @@ -3,6 +3,15 @@ play_frame: ;============================ ; see if still counting down + lda SONG_COUNTDOWN + ; rotate through channel A volume + + tya + and #$7 + tay + lda channel_a_volume,Y + sta AY_REGS+8 + lda SONG_COUNTDOWN bpl done_update_song @@ -17,9 +26,8 @@ set_notes_loop: ;================== ; see if hit end - ; this song only 16 notes so valid notes always positive -; cmp #$80 - bpl not_end + cmp #$ff + bne not_end ;==================================== ; if at end, loop back to beginning @@ -30,14 +38,15 @@ set_notes_loop: not_end: + ; NNNNNNEC -- c=channel, e=end, n=note pha ; save note and #1 - tax - ldy #$0E - sty AY_REGS+8,X ; $08 set volume A,B +; tax +; ldy #$0E +; sty AY_REGS+8,X ; $08 set volume A,B asl tax ; put channel offset in X @@ -46,6 +55,9 @@ not_end: pla ; restore note tay and #$2 + asl + asl + asl sta SONG_COUNTDOWN ; always 2 long? tya @@ -76,3 +88,9 @@ blah_urgh: done_update_song: dec SONG_COUNTDOWN bmi set_notes_loop + bpl skip_data + +channel_a_volume: + .byte 14,14,14,14,11,11,10,10 + +skip_data: