lemm: seamless music playing

way more trouble than it was worth
This commit is contained in:
Vince Weaver 2022-03-09 12:06:34 -05:00
parent 4c16bb0b32
commit 8c6187d5af
3 changed files with 97 additions and 34 deletions

View File

@ -41,7 +41,20 @@ pt3_irq_smc1:
ym_play_music:
; see if need to pre-load next chunk
lda BASE_FRAME_L
cmp #1
bne no_preload_chunk
lda BASE_FRAME_H
and #1
bne no_preload_chunk
inc LOAD_NEXT_CHUNK ; defer this until after interrupt
no_preload_chunk:
lda BASE_FRAME_L ; reset frame pointer to beginning
sta CURRENT_FRAME_L
lda BASE_FRAME_H
sta CURRENT_FRAME_H
@ -56,50 +69,43 @@ frame_loop:
beq go_next_chunk ; if so, end of song, loop
all_good:
jsr update_ay_register
jsr update_ay_register ; output to the AY
clc
lda CURRENT_FRAME_H
lda CURRENT_FRAME_H ; next register set is 2 pages away
adc #$2 ; was 4
sta CURRENT_FRAME_H
inx
cpx #12
cpx #12 ; only output 11 regs
bne frame_loop
inc BASE_FRAME_L
inc BASE_FRAME_L ; increment frame ptr (16bit)
bne not_oflo
inc BASE_FRAME_H
lda BASE_FRAME_H
cmp #$D2 ; was D4
inc BASE_FRAME_H ; wrap to next page
lda BASE_FRAME_H ; if too big, go to next chunk
and #$3
cmp #$2 ; was D4
bne not_oflo
go_next_chunk:
lda CHUNK_NEXT_PLAY ; toggle $D0/$E8
eor #$38
sta CHUNK_NEXT_PLAY
sta BASE_FRAME_H
inc CURRENT_CHUNK
jsr load_song_chunk
; inc LOAD_NEXT_CHUNK ; defer this until after interrupt
; jsr load_song_chunk
not_oflo:
jmp exit_interrupt
;=================================
; Finally done with this interrupt
;=================================
quiet_exit:
stx DONE_PLAYING
jsr clear_ay_both
; mute the sound
ldx #7
lda #$ff
jsr update_ay_register
exit_interrupt:
pla
@ -159,3 +165,21 @@ pt3_irq_smc7:
done_pt3_irq_handler:
disable_music:
sei
ldx #1
stx DONE_PLAYING
jsr clear_ay_both
; mute the sound
ldx #7
lda #$ff
jsr update_ay_register
rts

View File

@ -168,14 +168,26 @@ skip_all_checks:
; actually load it
; set up music
lda #0
sta CURRENT_CHUNK
sta DONE_PLAYING
sta BASE_FRAME_L
lda #$D0
sta CHUNK_NEXT_LOAD ; Load at $D0
jsr load_song_chunk
lda #$D0 ; music starts at $d000
sta CHUNK_NEXT_PLAY
sta BASE_FRAME_H
lda #1
sta LOOP
sta CURRENT_CHUNK
jsr mockingboard_patch ; patch to work in slots other than 4?
@ -259,6 +271,7 @@ zurg:
sta LEVEL_OVER
sta DOOR_OPEN
sta FRAMEL
sta LOAD_NEXT_CHUNK
; set up time
@ -275,6 +288,18 @@ zurg:
;===================
main_loop:
lda LOAD_NEXT_CHUNK ; see if we need to load next chunk
beq no_load_chunk ; outside IRQ to avoid glitch in music
jsr load_song_chunk
lda #0 ; reset
sta LOAD_NEXT_CHUNK
no_load_chunk:
lda DOOR_OPEN
bne door_is_open
@ -298,13 +323,21 @@ door_is_open:
level_over:
jmp level_over
bit SET_TEXT
jsr disable_music
loop_forever:
jmp loop_forever
;========================
; load song chunk
; CURRENT_CHUNK is which one
; CURRENT_CHUNK is which one, 0..N
; CHUNK_DEST is $D0 or $E8
load_song_chunk:
ldx CURRENT_CHUNK
@ -314,19 +347,21 @@ load_song_chunk:
sta getsrc_smc+2 ; LZSA_SRC_HI
bne load_song_chunk_good
; wrapped
; $00 in chunk table means we are off the end, so wrap
lda #$00
sta CURRENT_CHUNK
sta CURRENT_CHUNK ; reset chunk to 0
beq load_song_chunk ; try again
load_song_chunk_good:
lda #$d0
sta BASE_FRAME_H
lda CHUNK_NEXT_LOAD ; decompress to $D0 or $E8
; eor #$38 ; want the opposite of CHUNK_DEST
jsr decompress_lzsa2_fast
lda #0
sta BASE_FRAME_L
lda CHUNK_NEXT_LOAD ; point to next location
eor #$38
sta CHUNK_NEXT_LOAD
rts
@ -349,13 +384,14 @@ load_song_chunk_good:
.include "lc_detect.s"
.include "wait.s"
.include "hgr_tables.s"
.include "hgr_sprite.s"
.include "update_time.s"
.include "intro_level1.s"
.include "draw_flames.s"
.include "draw_door.s"
.include "wait.s"
; pt3 player

View File

@ -56,6 +56,9 @@ DISP_PAGE = $79
DRAW_PAGE = $7A
LEVEL_OVER = $7B
DOOR_OPEN = $7C
CHUNK_NEXT_LOAD = $7D
CHUNK_NEXT_PLAY = $7E
LOAD_NEXT_CHUNK = $7F
APPLEII_MODEL = $8B