-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.s
271 lines (243 loc) · 6.57 KB
/
player.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
;------------------------------------------------------------------------------------
;
; Please note this was mostly to learn the process
; also note O'Dog of Laxity you and your group can FUCK right off.
; Don't pre-release games for the 4kb compo which technically disqualified my entry
; And killed a lot of my passion for doing C64 titles
;
; Thanks to
; Frantic/Hack'n'Trade player was a point of reference when re-educating myself with SID
; https://cadaver.github.io/rants/music.html this page was useful too
;
;------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------
; Player Reset
; A = song ID
; X = trashed
; Y = trashed
;------------------------------------------------------------------------------------
player_Reset_func
; mul A * 2
asl
tay
; clear the data we need
; overkill
ldx #$00
_clearloop
lda #$20
sta TRACK0,x
lda #$00
sta $d400,x
inx
cpx #3*7
bne _clearloop
; get song pointers and set up VPEEK
lda Songs,y
sta VPEEK
lda Songs+1,y
sta VPEEK+1
; set the voice track pointers from the song def
; 3 words
ldy #$00
lda (VPEEK),y
sta TRACK0.Address
iny
lda (VPEEK),y
sta TRACK0.Address+1
iny
lda (VPEEK),y
sta TRACK1.Address
iny
lda (VPEEK),y
sta TRACK1.Address+1
iny
lda (VPEEK),y
sta TRACK2.Address
iny
lda (VPEEK),y
sta TRACK2.Address+1
; set Clock to zero
lda #$01
sta TRACK0.Clock
sta TRACK1.Clock
sta TRACK2.Clock
; defaults
lda #$03
sta TRACK0.Instrument
lda #$02
sta TRACK1.Instrument
lda #$03
sta TRACK2.Instrument
lda #%01111111 ;Hi-pass + Lo-pass filter on.
sta $d418
rts
player_Update_func:
ldx #$00
; Track 0
sec
dec TRACK0.Clock,x
bne _noupdate0
jsr InitialUpdate
_noupdate0
; Track 1
; X is 7 due to using SID regs,x
; so this is the voice 2
ldx #$07
sec
dec TRACK0.Clock,x
bne _noupdate1
jsr InitialUpdate
_noupdate1
; Track 2
; X is 14 due to using SID regs,x
; so this is the voice 3
ldx #14
sec
dec TRACK0.Clock,x
bne _noupdate2
jsr InitialUpdate
_noupdate2
rts
;------------------------------------------------------------------------------------
; BeginRepeat:
; stored as command byte , count byte
; copies the repeat amount and stores a pointer back to the beginning of the repeat ( skipping the header )
;------------------------------------------------------------------------------------
BeginRepeat:
; move ptr
NextCommand TRACK0
PeekCommand TRACK0
sta TRACK0.RepeatCounter,x
NextCommand TRACK0
; copy Address
lda TRACK0.Address,x
sta TRACK0.RepeatAddress,x
lda TRACK0.Address+1,x
sta TRACK0.RepeatAddress+1,x
jmp updateV0
;------------------------------------------------------------------------------------
; EndRepeat: reset back to repeat point if saved repeat count = 0
; stored as command byte
;------------------------------------------------------------------------------------
EndRepeat:
dec TRACK0.RepeatCounter,x
clc
lda TRACK0.RepeatCounter,x
beq _SkipReptByte
lda TRACK0.RepeatAddress,x
sta TRACK0.Address,x
lda TRACK0.RepeatAddress+1,x
sta TRACK0.Address+1,x
jmp updateV0
_SkipReptByte:
NextCommand TRACK0
jmp updateV0
;------------------------------------------------------------------------------------
; JumpTrack:
; unconditional jump the track pointer to the word after the command byte
;------------------------------------------------------------------------------------
JumpTrack:
; move ptr
NextCommand TRACK0
PeekCommand TRACK0
sta JmpFunc
NextCommand TRACK0
PeekCommand TRACK0
; copy Address
sta TRACK0.Address+1,x
lda JmpFunc
sta TRACK0.Address,x
jmp updateV0
;------------------------------------------------------------------------------------
; Set the track instrument to the next byte
;------------------------------------------------------------------------------------
SetInstrument:
; next instruction
NextCommand TRACK0
PeekCommand TRACK0
; store that number into the current Instrument
sta TRACK0.Instrument,x
; step to next instruction
NextCommand TRACK0
jmp updateV0
;------------------------------------------------------------------------------------
; Command Functions array
;------------------------------------------------------------------------------------
PlayerFunctions:
.word SkipNote,BeginRepeat,EndRepeat,SetInstrument,JumpTrack
;------------------------------------------------------------------------------------
; per track update function
;------------------------------------------------------------------------------------
InitialUpdate:
; note this looks like it's just TRACK0
; but the macro's use
; ARG,x
updateV0
PeekCommand TRACK0
tay
; is it a command ?
and #$80
; no just go play the note
beq _playnote
; it is
tya
stx TempX
; <<1 to get word index
and #$f
asl
tax
; copy function pointers
lda PlayerFunctions,x
sta JmpFunc
lda PlayerFunctions+1,x
sta JmpFunc+1
; jump over
ldx TempX
jmp (JmpFunc)
_playnote
PeekCommand TRACK0
tay
; Set Frequency based on NOTE ID
lda FrequencyLo,y
sta $d400,x
lda FrequencyHi,y
sta $d401,x
; clear gate ?
lda #$00
sta $d404,x
; Set Instrument ADSR and Control values
lda TRACK0.Instrument,x
tay
lda AttackDelayTable,y
sta $d405,x
lda ControlTable,y
sta $d404,x
SkipNote
; no note is played from here on out
lda TRACK0.Instrument,x
tay
; reset the Clock
lda DurationTable,y
sta TRACK0.Clock,x
NextCommand TRACK0
rts
;------------------------------------------------------------------------------------
; This is the PAL table
;------------------------------------------------------------------------------------
FrequencyHi:
; C C# D D# E F F# G G# A A# B
.byte $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$02 ; 1
.byte $02,$02,$02,$02,$02,$02,$03,$03,$03,$03,$03,$04 ; 2
.byte $04,$04,$04,$05,$05,$05,$06,$06,$06,$07,$07,$08 ; 3
.byte $08,$09,$09,$0a,$0a,$0b,$0c,$0d,$0d,$0e,$0f,$10 ; 4
.byte $11,$12,$13,$14,$15,$17,$18,$1a,$1b,$1d,$1f,$20 ; 5
.byte $22,$24,$27,$29,$2b,$2e,$31,$34,$37,$3a,$3e,$41 ; 6
FrequencyLo:
; C C# D D# E F F# G G# A A# B
.byte $17,$27,$39,$4b,$5f,$74,$8a,$a1,$ba,$d4,$f0,$0e ; 1
.byte $2d,$4e,$71,$96,$be,$e8,$14,$43,$74,$a9,$e1,$1c ; 2
.byte $5a,$9c,$e2,$2d,$7c,$cf,$28,$85,$e8,$52,$c1,$37 ; 3
.byte $b4,$39,$c5,$5a,$f7,$9e,$4f,$0a,$d1,$a3,$82,$6e ; 4
.byte $68,$71,$8a,$b3,$ee,$3c,$9e,$15,$a2,$46,$04,$dc ; 5
.byte $d0,$e2,$14,$67,$dd,$79,$3c,$29,$44,$8d,$08,$b8 ; 6
;------------------------------------------------------------------------------------