dos33fsprogs/demos/demosplash2022/play_frame.s

162 lines
2.7 KiB
ArmAsm
Raw Normal View History

2022-11-12 19:32:56 +00:00
play_frame:
;============================
; see if still counting down
lda SONG_COUNTDOWN
bpl done_update_song
set_notes_loop:
2022-11-12 23:40:59 +00:00
2022-11-12 19:32:56 +00:00
;==================
; load next byte
2022-11-13 02:22:20 +00:00
; ldy SONG_OFFSET ; Y = offset into song
2022-11-12 19:32:56 +00:00
track_smc:
2022-11-13 02:22:20 +00:00
lda track4;,Y ; get next byte into A
2022-11-12 19:32:56 +00:00
;==================
; see if hit end
2022-11-13 00:24:51 +00:00
cmp #$ff ; FF means we hit end
2022-11-12 19:32:56 +00:00
bne not_end
;====================================
; if at end, loop back to beginning
2022-11-13 00:24:51 +00:00
ldy WHICH_TRACK ; get current track in Y
iny ; increment track
cpy #5 ; see if off end
2022-11-12 19:32:56 +00:00
bne no_wrap
2022-11-13 00:24:51 +00:00
ldy #1 ; loop to track 1
2022-11-12 19:32:56 +00:00
no_wrap:
2022-11-13 00:24:51 +00:00
sty WHICH_TRACK
lda tracks_l,Y ; self-modify track
2022-11-12 19:32:56 +00:00
sta track_smc+1
2022-11-13 00:24:51 +00:00
; lda tracks_h,Y ; enforce in same page
2022-11-13 00:15:57 +00:00
; sta track_smc+2
2022-11-12 19:32:56 +00:00
2022-11-13 00:24:51 +00:00
lda bamps_l,Y ; self modify B-amplitude
2022-11-12 23:40:59 +00:00
sta bamp_smc+1
2022-11-13 00:24:51 +00:00
; lda bamps_h,Y ; enforce in same page
2022-11-13 00:15:57 +00:00
; sta bamp_smc+2
2022-11-12 23:40:59 +00:00
2022-11-13 02:22:20 +00:00
; lda #0 ; reset song offset
; sta SONG_OFFSET
2022-11-12 19:32:56 +00:00
2022-11-13 02:22:20 +00:00
jmp set_notes_loop ; bra ; try again in new track
2022-11-12 19:32:56 +00:00
not_end:
; NNNNNEEC -- c=channel, e=end, n=note
pha ; save note
and #1
asl
2022-11-13 00:24:51 +00:00
tax ; put channel offset*2 in X
2022-11-12 19:32:56 +00:00
pla ; restore note
pha
2022-11-13 00:24:51 +00:00
and #$6 ; get note length
2022-11-12 19:32:56 +00:00
lsr
tay
2022-11-13 00:24:51 +00:00
lda lengths,Y ; lookup in table
2022-11-12 19:32:56 +00:00
sta SONG_COUNTDOWN ;
pla
lsr
lsr
lsr ; get note in A
tay ; lookup in table
2022-11-13 02:22:20 +00:00
lda frequencies_high,Y ; get high frequency
sta AY_REGS+1,X ; put in AY register
2022-11-12 19:32:56 +00:00
2022-11-13 02:22:20 +00:00
lda frequencies_low,Y ; get low frequency
sta AY_REGS,X ; also put in AY register
2022-11-12 19:32:56 +00:00
;============================
; point to next
; assume less than 256 bytes
2022-11-13 02:22:20 +00:00
inc track_smc+1 ; SONG_OFFSET
2022-11-12 19:32:56 +00:00
2022-11-12 23:40:59 +00:00
2022-11-12 19:32:56 +00:00
done_update_song:
2022-11-12 23:40:59 +00:00
;=================================
; coundown song
2022-11-13 02:22:20 +00:00
dec SONG_COUNTDOWN ; if length was 0, means there
; was another note starting at same
; time, so go back and play that too
2022-11-12 19:32:56 +00:00
bmi set_notes_loop
2022-11-13 00:15:57 +00:00
;===============================
;===============================
; things that happen every frame
;===============================
;===============================
2022-11-12 23:40:59 +00:00
2022-11-13 00:15:57 +00:00
;=================================
; rotate through channel A volume
lda FRAME ; repeating 8-long pattern
and #$7
tay
lda channel_a_volume,Y
sta AY_REGS+8 ; A volume
2022-11-12 19:32:56 +00:00
2022-11-12 23:40:59 +00:00
;=================================
; handle channel B volume
chanb:
2022-11-13 00:15:57 +00:00
; lda FRAME
; and #$7
tya
2022-11-12 23:40:59 +00:00
bne bamps_skip
2022-11-13 02:22:20 +00:00
lda BAMP_COUNTDOWN ; b-amp conutdown
2022-11-12 23:40:59 +00:00
bne bamps_good
bamp_smc:
2022-11-13 02:22:20 +00:00
lda bamps4 ; get new value
2022-11-12 23:40:59 +00:00
pha
2022-11-13 02:22:20 +00:00
and #$f ; bottom 4 its is ampllitude
sta AY_REGS+9 ; B volume
2022-11-12 23:40:59 +00:00
pla
2022-11-13 02:22:20 +00:00
lsr ; top 4 bits are length
2022-11-12 23:40:59 +00:00
lsr
lsr
lsr
sta BAMP_COUNTDOWN
2022-11-13 02:22:20 +00:00
inc bamp_smc+1 ; increment to next location
; assumes on same page
; and less than 256
2022-11-12 23:40:59 +00:00
bamps_good:
2022-11-13 02:22:20 +00:00
dec BAMP_COUNTDOWN ; countdown
2022-11-12 23:40:59 +00:00
bamps_skip:
;=================================
; inc frame counter
inc FRAME