kevin81
Well-known member
Hello everyone! I've written a small snippet you can use to speed up a song while it's playing. You could, for example, use it on a timer, for when the player is running out of time (you know, like in that turtle-kicking plumber game). The tempo gets reset to the original speed (by NESMaker/GGsound design) when the game loads a new song.
I have tested this code as an input script and that worked. Also it accounts for DPCM sample usage, although I didn't actually test this with the DPCM channel enabled. Please feel free to let me know what you think! If it works - or doesn't work - as intended, I'd love to hear that too.
Code:
; This constant defines how much the tempo increases.
; A bigger value equals a bigger increase in tempo.
; Change this value to your liking.
MUSIC_SPEED_INCREMENT = #$B0
; Check if the high byte needs decreasing.
; A lower stream_tempo_ value indicates a higher speed,
; so these variables could be considered to be "length"
; rather than "tempo".
LDA stream_tempo_lo
SEC
SBC #MUSIC_SPEED_INCREMENT
BCS +changeLowByte
; Check if speed can be increased further.
; If not, skip changing the tempo altogether.
STA temp
LDA stream_tempo_hi
CMP #$01
BEQ +doNotChange
; Decrease the high byte values.
DEC stream_tempo_hi
DEC stream_tempo_hi+1
DEC stream_tempo_hi+2
DEC stream_tempo_hi+3
; Decrease DPCM channel low byte only if DPCM is enabled
ifdef FEATURE_DPCM
DEC stream_tempo_hi+4
endif
; Change the low byte values.
LDA temp
+changeLowByte:
STA stream_tempo_lo
STA stream_tempo_lo+1
STA stream_tempo_lo+2
STA stream_tempo_lo+3
; Change DPCM channel low byte only if DPCM is enabled
ifdef FEATURE_DPCM
STA stream_tempo_lo+4
endif
; we're done here
+doNotChange:
I have tested this code as an input script and that worked. Also it accounts for DPCM sample usage, although I didn't actually test this with the DPCM channel enabled. Please feel free to let me know what you think! If it works - or doesn't work - as intended, I'd love to hear that too.