-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.8o
345 lines (299 loc) · 10.1 KB
/
music.8o
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#####################
# "Stand alone" version of the music player for writing songs.
# The code is identical, except for the main loop.
:alias music-delay vE
: main
:unpack 0 knee-deep-in-trouble
select-song
loop
play-music
delay := music-delay
loop
v0 := delay
if v0 != 0 then
again
again
#####################
# Musical accompaniment
:const c-note 0
:const c-repeat 1
:const c-da-capo 2
:const c-stop 3
# Convenience macros
:macro note ADDRESS DURATION {
:byte { ADDRESS >> 8 }
:byte { ADDRESS }
:byte c-note
:byte { DURATION }
}
:macro rest DURATION {
:byte { --- >> 8 }
:byte { --- }
:byte c-note
:byte { DURATION }
}
:macro repeat TIMES LABEL {
:byte { TIMES - 1 }
:byte { TIMES - 1 }
:byte c-repeat
:byte { ( ( HERE - LABEL ) / 4 ) + 1 }
}
:macro da-capo {
:byte 0
:byte 0
:byte c-da-capo
:byte 0
}
:macro stop {
:byte 0
:byte 0
:byte c-stop
:byte 0
}
# Available samples
: A$1 0xFF 0xFF 0xFF 0xFF 0xE0 0x00 0x00 0x00 0x07 0xFF 0xFF 0xFF 0xFE 0x00 0x00 0x00
: A-2 0xFF 0xFF 0xE0 0x00 0x07 0xFF 0xFE 0x00 0x00 0x7F 0xFF 0xE0 0x00 0x03 0xFF 0xFF
: B-2 0xFF 0xFF 0x80 0x00 0x7F 0xFF 0x80 0x00 0x7F 0xFF 0x80 0x00 0x3F 0xFF 0xC0 0x00
: C-2 0xFF 0xFF 0xFF 0xFE 0x00 0x00 0x00 0x03 0xFF 0xFF 0xFF 0xF0 0x00 0x00 0x00 0x1F
: C$2 0xFF 0xFF 0xFF 0xF8 0x00 0x00 0x00 0x3F 0xFF 0xFF 0xFE 0x00 0x00 0x00 0x0F 0xFF
: D-2 0xFF 0xFF 0xFF 0xF0 0x00 0x00 0x01 0xFF 0xFF 0xFF 0xC0 0x00 0x00 0x07 0xFF 0xFF
: D$2 0xFF 0xFF 0xFF 0xC0 0x00 0x00 0x0F 0xFF 0xFF 0xFC 0x00 0x00 0x01 0xFF 0xFF 0xFF
: E-2 0xFF 0xFF 0xFF 0x80 0x00 0x00 0x7F 0xFF 0xFF 0x80 0x00 0x00 0x3F 0xFF 0xFF 0xC0
: F-2 0xFF 0xFF 0xFE 0x00 0x00 0x03 0xFF 0xFF 0xF8 0x00 0x00 0x0F 0xFF 0xFF 0xE0 0x00
: F$2 0xFF 0xFF 0xFC 0x00 0x00 0x0F 0xFF 0xFF 0x80 0x00 0x01 0xFF 0xFF 0xF8 0x00 0x00
: G-2 0xFF 0xFF 0xF8 0x00 0x00 0x7F 0xFF 0xFC 0x00 0x00 0x3F 0x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 0x3C 0x70 0xE1 0xC3 0x8F 0x1E
: C-5 0xF0 0xF0 0xF1 0xE1 0xE1 0xE3 0xC3 0xC3 0xC7 0x87 0x87 0x0F 0x0F 0x0E 0x1E 0x1E
: B-4 0xF8 0x78 0x78 0x78 0x78 0x78 0x78 0x78 0x78 0x78 0x7C 0x3C 0x3C 0x3C 0x3C 0x3C # 494hz
: A$4 0xF8 0x78 0x3C 0x3E 0x1E 0x1F 0x0F 0x07 0x87 0x83 0xC3 0xE1 0xE0 0xF0 0xF0 0x78 # 466hz
: G$4 0xF8 0x3E 0x0F 0x87 0xC1 0xF0 0x7C 0x3E 0x0F 0x83 0xC1 0xF0 0x7C 0x1E 0x0F 0x83 # 415hz
: D$4 0xFE 0x07 0xF0 0x3F 0x81 0xFC 0x0F 0xC0 0x7E 0x03 0xF0 0x1F 0x81 0xFC 0x0F 0xE0 # 311hz
: D-4 0xFE 0x03 0xF8 0x0F 0xE0 0x7F 0x01 0xFC 0x07 0xF0 0x3F 0x80 0xFE 0x03 0xF8 0x1F # 293hz
: C$4 0xFF 0x01 0xFC 0x07 0xF8 0x0F 0xE0 0x3F 0x80 0x7F 0x01 0xFC 0x03 0xF8 0x0F 0xE0 # 277hz
: C-4 0xFF 0x00 0xFE 0x01 0xFE 0x03 0xFC 0x03 0xF8 0x07 0xF0 0x0F 0xF0 0x1F 0xE0 0x1F # 262hz
: F-4 0xFC 0x0F 0xC1 0xF8 0x1F 0x83 0xF0 0x3F 0x07 0xE0 0x7C 0x0F 0xC0 0xF8 0x1F 0x81
: D-6 0xCD 0x93 0x26 0xC9 0x93 0x64 0xC9 0xB2 0x64 0xD9 0x32 0x6C 0xD9 0x36 0x6C 0x9B
: --- 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 # silence
: click 0x02 0xCD 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
# Songs
: knee-deep-in-trouble
: kdt1 note C-2 10 rest 10 note G-2 10 rest 10 note A$1 10 rest 10 note F-2 10 rest 10 repeat 4 kdt1
: kdt2 note C-2 10 rest 10 note D$2 10 rest 10 note G-2 10 rest 10 note C-3 10 rest 10 repeat 2 kdt2
: kdt3 note A$1 10 rest 10 note D-2 10 rest 10 note F-2 10 rest 10 note A$2 10 rest 10 repeat 2 kdt3
: kdt4 note C-2 10 rest 10 note G-2 10 rest 10 note A$1 10 rest 10 note F-2 10 rest 10 repeat 4 kdt4
: kdt5 note C-2 10 rest 10 note C-2 10 rest 10 rest 120 repeat 2 kdt5
: kdt6 note C-2 10 rest 10 note G-2 10 rest 10 note A$1 10 rest 10 note F-2 10 rest 10 repeat 4 kdt6
: kdt7 note C-3 10 rest 10 note G-2 10 rest 10 note D$2 10 rest 10 note C-2 10 rest 10 repeat 2 kdt7
: kdt8 note A$2 10 rest 10 note F-2 10 rest 10 note D-2 10 rest 10 note A$1 10 rest 10 repeat 2 kdt8
: kdt9 note C-2 10 rest 10 note G-2 10 rest 10 note A$1 10 rest 10 note F-2 10 rest 10 repeat 4 kdt9
: kdt10 note C-2 10 rest 10 note C-2 10 rest 10 rest 120 repeat 2 kdt10
da-capo
: im-too-young-to-vipe
: tytv1
note C-3 16 rest 2
note C-4 16 note B-3 10 rest 2 note C-4 10 rest 2 note G-3 16 rest 2
note C-3 16 rest 2
note A$3 16 rest 2 note C-4 16 rest 26
note C-3 16 rest 2
note A$3 16 note A-3 10 rest 2 note A$3 10 rest 2 note G-3 16 rest 2
note C-3 16 rest 2
note A-3 16 rest 2 note G-3 16 rest 26
repeat 2 tytv1
: tytv2
note C-3 16 rest 2
note C-4 15 rest 1 note C-4 10 rest 2 note A$3 10 rest 2 note G-3 16 rest 2
note C-3 16 rest 2
note G-3 16 rest 2 note A$3 16 rest 26
note C-3 16 rest 2
note G-3 16 note G-3 10 rest 2 note F-3 10 rest 2 note D$3 16 rest 2
note C-3 16 rest 2
note D-3 16 rest 2 note C-3 16 rest 26
repeat 2 tytv2
: tytv3
note C-2 16 rest 2 note C-3 16 note B-2 10 rest 2 note C-3 10 rest 2
note G-2 16 rest 2 note C-2 16 rest 2 note A$2 16 rest 2 note C-3 16 rest 26
note C-2 16 rest 2 note A$2 16 note A-2 10 rest 2 note A$2 10 rest 2
note G-2 16 rest 2 note C-2 16 rest 2 note A-2 16 rest 2 note G-2 16 rest 26
repeat 2 tytv3
: tytv4
note C-2 16 rest 2
note C-3 15 rest 1 note C-2 10 rest 2 note A$2 10 rest 2 note G-2 16 rest 2
note C-2 16 rest 2
note G-2 16 rest 2 note A$2 16 rest 26
note C-2 16 rest 2
note G-2 16 note G-2 10 rest 2 note F-2 10 rest 2 note D$2 16 rest 2
note C-2 16 rest 2
note D-2 16 rest 2 note C-2 16 rest 26
repeat 2 tytv4
da-capo
: coin
note F-4 5 rest 5 note D-6 5 rest 1 note D-6 20 rest 5
stop
: victory-1
note D-4 4 rest 4 note G$4 4 rest 4 note A$4 4 rest 4
note E-5 5 note F-5 5 note E-5 5 note F-5 5 note E-5 5 rest 15
note F-4 4 rest 4 note C-5 4 rest 4 note D-5 4 rest 4
note F-5 5 note G-5 5 note F-5 5 note G-5 5 note F-5 5 rest 15
note G-5 10 rest 10 note G-5 12 rest 10 note F-5 14 rest 10
note G-5 40 rest 10
stop
: victory-2
note D-4 10 rest 4 note G$4 4 rest 4 note B-4 20 rest 8
stop
#####################
# A non-blocking music player
# `play-music` needs to be called again after 'music-delay' timer ticks.
# Input: none
: play-click
i := long click
v0 := 5
audio
buzzer := v0
return
# Input: 'unpacked' address of song in v0 and v1
: select-song # and return to position 0
i := long current-song
v2 := 0
save v2
# Clear any old backup songs
v0 := 0
v1 := 0
i := long current-song-backup
save v1
return
# Input: 'unpacked' address of song in v0 and v1
: interject-song # and resume playing afterwards
v3 := v0
v4 := v1
# Check if we're already in an interjected song (can't do two)
i := long current-song-backup
load v1
v0 |= v1
if v0 != 0 then jump interject-song-leave-backup-untouched
# Swap current song to backup and new song to current
i := long current-song
load v2
i := long current-song-backup
save v2
: interject-song-leave-backup-untouched
v0 := v3
v1 := v4
v2 := 0
i := long current-song
save v2
# Force `play-music` to start the new song right away
music-delay := 1
return
# Input: none
# Destroys: v0 - v4
: play-music
# Load and update our position in the song
i := long music-position
load v0
v4 := v0
v0 += 1
i := long music-position
save v0
# Load the next music instruction
music-pointer
load v3
if v2 == c-note then jump music-note
if v2 == c-repeat then jump music-repeat
if v2 == c-stop then jump music-stop
# Else, it's a da capo
: music-da-capo
v0 := 0
i := long music-position
save v0
jump play-music
: music-note
i := music-smc
save v1
0xF0 0x00 # i := long ...
: music-smc
0 0
# Play the sound!
audio
music-delay := v3
vf := 255
buzzer := vf
return
: music-repeat
v5 := v0
v6 := v1
music-pointer
if v5 == 0 begin
# We've done all the repetitions, reset for the next playthrough
v0 := v6
save v0
else
# Decrease the loop counter
v0 := v5
v0 -= 1
save v0
# Move the position back as many steps as the instruction dictates
i := long music-position
load v0
v0 -= v3
i := long music-position
save v0
end
jump play-music
: music-stop
# Do we have anything left in backup to play?
i := long current-song-backup
load v2
v3 := v0
v3 |= v1
if v3 != 0 begin
i := long current-song
save v2
v0 := 0
v1 := 0
i := long current-song-backup
save v1
jump play-music
else
# Step back one position so we don't play anything anymore
i := long music-position
load v0
v0 -= 1
i := long music-position
save v0
music-delay := 255
return
end
: music-pointer
i := long current-song
load v1
i := music-pointer-smc
save v1
0xF0 0x00 # i := long ...
: music-pointer-smc
0 0
i += v4
i += v4
i += v4
i += v4
return
: current-song
0 0
: music-position
0
: current-song-backup
0 0
: music-position-backup
0
# That's all folks!