The next suggestion might be to learn about arrays and iteration. You don't have to copy paste the same code many times with one thing different, you can put the different parameters in a table array), and then write an interative loop to use them one by one. Here's your song rewritten this way:
Code: Select all
; table of pitches
pitch_low: .byte $F0, $D5, $BD, $B2, $A0, $90, $80, $78, $6C, $87, $00
pitch_high: .byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $05
NDO = 0
NRE = 1
NMI = 2
NFA = 3
NSO = 4
NLA = 5
NSI = 6
NDO1 = 7
NRE1 = 8
NLAD = 9
NSTOP = 10
; plays note from X
Nota:
lda #%00000001
sta $4015
lda #%10100111
sta $4000
lda pitch_low, X
sta $4002
lda pitch_high, X
sta $4003
rts
Timer:
lda #1
sta $0700
lda #0
sta $0701
@loop:
dec $0700
bne loop
dec $0701
bne @loop
rts
classic_song:
.byte NLA, NSO, NLA, NFA, NLA, NMI, NLA, NRE
.byte NRE, NFA, NLA, NRE1, NDO1, NLAD, NLA, NSO
.byte NLDA, NLA, NLAD, NSO, NLAD, NFA, NLAD, NMI
.byte NDO, NMI, NSO, NDO1, NLAD, NLA, NSO, NLA
.byte NSO, NLA, NLAD, NLA, NSO, NFA, NMI, NRE
.byte NSTOP
PlaySong:
; use Y as index to array classic_song
ldy #0
@loop:
; fetch note from classic_song into X and play it with Nota
ldx classic_song, Y
jsr Nota
jsr Timer
; if the last note was NSTOP, finish
lda #NSTOP
cmp classic_song, Y
beq @end
; otherwise advance to the next note
iny
jmp @loop
@end:
rts