From 7e8b3ec3aab59b91d60b5bae2cb5fdccbd544964 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 28 Oct 2018 21:58:09 -0400 Subject: [PATCH] megademo: add interrupt-driven music during mode7 segment --- megademo/Makefile | 3 ++- megademo/mockingboard.s | 9 ++++++--- megademo/mode7.s | 3 +++ megademo/takeoff.s | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/megademo/Makefile b/megademo/Makefile index 4194a2ca..b7816c17 100644 --- a/megademo/Makefile +++ b/megademo/Makefile @@ -30,6 +30,7 @@ MEGADEMO: megademo.o megademo.o: megademo.s \ zp.inc hardware.inc \ gr_hline.s gr_offsets.s vapor_lock.s delay_a.s wait_keypress.s \ + mockingboard.s \ c64_opener.s c64.img.lz4 \ falling_apple.s apple_40_96.inc \ starring.s starring1.inc starring2.inc starring3.img.lz4\ @@ -61,7 +62,7 @@ megaload.o: megaload.s MUSIC.1000: music_1000.o ld65 -o MUSIC.1000 music_1000.o -C ../linker_scripts/apple2_1000.inc -music_1000.o: music_1000.s +music_1000.o: music_1000.s mockingboard.s ca65 -o music_1000.o music_1000.s -l music_1000.lst #### diff --git a/megademo/mockingboard.s b/megademo/mockingboard.s index 3fbaabb1..a14ddaae 100644 --- a/megademo/mockingboard.s +++ b/megademo/mockingboard.s @@ -101,7 +101,6 @@ reset_ay_right: ; Setup initial conditions ;========================= - ; 7: ENABLE ldx #7 lda #$38 ; noise disabled, ABC enabled @@ -120,7 +119,7 @@ reset_ay_right: sta $03ff ;============================ - ; Enable 50Hz clock on 6522 + ; Enable 60Hz clock on 6522 ;============================ sei ; disable interrupts just in case @@ -134,13 +133,14 @@ reset_ay_right: sta $C40D ; IFR: 1100, enable interrupt on timer one oflow sta $C40E ; IER: 1100, enable timer one interrupt - lda #$1A + lda #$1a sta $C404 ; write into low-order latch lda #$41 sta $C405 ; write into high-order latch, ; load both values into counter ; clear interrupt and start counting + ; 9c40 / 1e6 = .040s, 25Hz ; 4fe7 / 1e6 = .020s, 50Hz ; 411a / 1e6 = .016s, 60Hz @@ -148,6 +148,7 @@ reset_ay_right: interrupt_handler: ; A saved by firmware in $45 + sta $45 txa pha ; save X tya @@ -161,6 +162,8 @@ interrupt_handler: tax ; restore X lda $45 ; restore A + bit $C404 ; clear 6522 interrupt by reading T1C-L ; 4 + rti ; return from interrupt ; 6 diff --git a/megademo/mode7.s b/megademo/mode7.s index dcef48d2..cae88932 100644 --- a/megademo/mode7.s +++ b/megademo/mode7.s @@ -62,6 +62,8 @@ island_flying_directions: mode7_flying: + cli ; enable interrupts (play music) + ;================================ ; one-time setup ;================================ @@ -153,6 +155,7 @@ done_key: done_mode7: bit KEYRESET ; done + sei ; disable interrupts rts check_up: diff --git a/megademo/takeoff.s b/megademo/takeoff.s index e68ef030..b9e16193 100644 --- a/megademo/takeoff.s +++ b/megademo/takeoff.s @@ -140,6 +140,7 @@ to_begin_loop: ; 3116 - 1038 (music) = 2078 + jsr play_music ; Try X=5 Y=67 cycles=2078 ; Try X=11 Y=51 cycles=3112 R4