I'm trying to come up with a code to play music, and here's what I came up with so far. Any suggestions?
Code:
define sfx_timer($00)
define pitch_slide($01)
define sfx_number($03)
define frame_number($04)
define tempo_delay($05)
str $fa=#$80
str $f1=#$11
str $f2=#$0f
str $f3=#$7f //FIR filter is all pass
str $f2=#$0c
str $f3=#$7f //left volume 100%
str $f2=#$1c
str $f3=#$7f //right volume 100%
str $f2=#$2c
str $f3=#$00 //echo volume 0%
str $f2=#$3c
str $f3=#$00 //echo volume 0%
str $f2=#$6c
str $f3=#$00
str $f2=#$0d
str $f3=#$00 //feedback 0%
str $f2=#$4d
str $f3=#$00 //no channel with echo
str $f2=#$5d
str $f3=#$80 //directory
str $f2=#$6d
str $f3=#$ff //echo buffer
str $f2=#$7d
str $f3=#$00 //shortest delay possible
str $f2=#$00
str $f3=#$7f //channel 0 left volume
str $f2=#$01
str $f3=#$7f //channel 0 right volume
str $f2=#$02
str $f3=#$00
str $f2=#$03
str $f3=#$10 //original pitch
str $f2=#$04
str $f3=#$00 //square
str $f2=#$07
str $f3=#$7f //gain up
str {tempo_delay}=#$08
spc_loop:
lda $fd
beq spc_loop
dec {tempo_delay}
bne spc_loop
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$02
sta $f3
str $f2=#$03
sty $f3
str $f2=#$4c
str $f3=#$01 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$12
sta $f3
str $f2=#$13
sty $f3
str $f2=#$4c
str $f3=#$02 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$22
sta $f3
str $f2=#$23
sty $f3
str $f2=#$4c
str $f3=#$04 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$32
sta $f3
str $f2=#$33
sty $f3
str $f2=#$4c
str $f3=#$08 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$42
sta $f3
str $f2=#$43
sty $f3
str $f2=#$4c
str $f3=#$10 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$52
sta $f3
str $f2=#$53
sty $f3
str $f2=#$4c
str $f3=#$20 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$62
sta $f3
str $f2=#$63
sty $f3
str $f2=#$4c
str $f3=#$40 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$72
sta $f3
str $f2=#$73
sty $f3
str $f2=#$4c
str $f3=#$80 //key on
+;
str {tempo_delay}=#$08
jmp spc_loop
//track format: key on, pitch, octave, sample
track:
db $01,$00,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$02,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$04,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$05,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$07,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$09,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$0b,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$00,$05,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
note_scale:
db 64,68,72,76,81,85,91,96,102,108,114,121
octave_scale:
db 1,2,4,8,16,32,64,128
seek($838000)
directory:
dw square
dw square
square:
db $83,$77,$77,$77,$77,$88,$88,$88,$88
define pitch_slide($01)
define sfx_number($03)
define frame_number($04)
define tempo_delay($05)
str $fa=#$80
str $f1=#$11
str $f2=#$0f
str $f3=#$7f //FIR filter is all pass
str $f2=#$0c
str $f3=#$7f //left volume 100%
str $f2=#$1c
str $f3=#$7f //right volume 100%
str $f2=#$2c
str $f3=#$00 //echo volume 0%
str $f2=#$3c
str $f3=#$00 //echo volume 0%
str $f2=#$6c
str $f3=#$00
str $f2=#$0d
str $f3=#$00 //feedback 0%
str $f2=#$4d
str $f3=#$00 //no channel with echo
str $f2=#$5d
str $f3=#$80 //directory
str $f2=#$6d
str $f3=#$ff //echo buffer
str $f2=#$7d
str $f3=#$00 //shortest delay possible
str $f2=#$00
str $f3=#$7f //channel 0 left volume
str $f2=#$01
str $f3=#$7f //channel 0 right volume
str $f2=#$02
str $f3=#$00
str $f2=#$03
str $f3=#$10 //original pitch
str $f2=#$04
str $f3=#$00 //square
str $f2=#$07
str $f3=#$7f //gain up
str {tempo_delay}=#$08
spc_loop:
lda $fd
beq spc_loop
dec {tempo_delay}
bne spc_loop
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$02
sta $f3
str $f2=#$03
sty $f3
str $f2=#$4c
str $f3=#$01 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$12
sta $f3
str $f2=#$13
sty $f3
str $f2=#$4c
str $f3=#$02 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$22
sta $f3
str $f2=#$23
sty $f3
str $f2=#$4c
str $f3=#$04 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$32
sta $f3
str $f2=#$33
sty $f3
str $f2=#$4c
str $f3=#$08 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$42
sta $f3
str $f2=#$43
sty $f3
str $f2=#$4c
str $f3=#$10 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$52
sta $f3
str $f2=#$53
sty $f3
str $f2=#$4c
str $f3=#$20 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$62
sta $f3
str $f2=#$63
sty $f3
str $f2=#$4c
str $f3=#$40 //key on
+;
ldx {frame_number}
txa
clc
adc #$04
sta {frame_number}
lda track,x
beq +
lda track+1,x
tay
lda note_scale,y
pha
lda track+2,x
tay
lda octave_scale,y
ply
mul
str $f2=#$72
sta $f3
str $f2=#$73
sty $f3
str $f2=#$4c
str $f3=#$80 //key on
+;
str {tempo_delay}=#$08
jmp spc_loop
//track format: key on, pitch, octave, sample
track:
db $01,$00,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$02,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$04,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$05,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$07,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$09,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$0b,$04,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $01,$00,$05,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
note_scale:
db 64,68,72,76,81,85,91,96,102,108,114,121
octave_scale:
db 1,2,4,8,16,32,64,128
seek($838000)
directory:
dw square
dw square
square:
db $83,$77,$77,$77,$77,$88,$88,$88,$88