-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmusicplayer.asc
536 lines (510 loc) · 10.7 KB
/
musicplayer.asc
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
; MSX Block Puzzle game, released as entry for the MSXDev'20
; Created by David Heremans, aka turbor on mrc
;
; My own custom made music/sfx replayer code
; the voice synthesis code was adapted from ARTAG, for more info
; see the thread at https://www.msx.org/forum/msx-talk/development/voice-synthesis-on-isr
;
startsfx1: ; move piece by user
ld e,1
ld hl,musicpiecesfx1_A
jr startsfx
startsfx2: ; switch to next piece
ld e,2
ld hl,musicpiecesfx2_A
jr startsfx
startsfx3: ; drop piece in empty spot
ld e,3
ld hl,musicpiecesfx3_A
jr startsfx
startsfx4: ; drop piece in non-empty spot
ld e,4
ld hl,musicpiecesfx4_A
jr startsfx
startsfx5: ; rows or cols are being removed
ld e,5
ld hl,musicpiecesfx5_A
jr startsfx
startsfx6: ; rows or cols are being removed
ld e,5
ld hl,musicpiecesfx6_A
jr startsfx
startsfx:
ld a,(musicsfxplaying)
cp e
ret nc
;not when ai is moving the pieces!!
ld a,(ai_active)
or a
ret nz
ld a,e
ld (musicsfxplaying),a
ld de,0
ld bc,0
loadmusicpointers1:
di
ld (musicpointer_A),hl
ld (musicpointer_B),de
ld (musicpointer_C),bc
ld a,1
ld (musicwaitint_A),a
ld (musicwaitint_B),a
ld (musicwaitint_C),a
dec a
ld l,a
ld h,a
ld (musicpointer_A_stack),hl
ld (musicpointer_B_stack),hl
ld (musicpointer_C_stack),hl
; prepare voicesynth code
call PSGReplayInitMem
;
ei
ret
startmusic:
ld hl,musicpiece2_A_sheet
ld de,musicpiece2_B_sheet
ld bc,musicpiece2_C_sheet
jr loadmusicpointers2
gameovermusic:
ld hl,musicpiece1_A_sheet
ld de,musicpiece1_B_sheet
ld bc,musicpiece1_C_sheet
loadmusicpointers2:
di
ld (musicpointer_A_stack),hl
ld (musicpointer_B_stack),de
ld (musicpointer_C_stack),bc
;perform first sheet to pointer
push iy
xor a
ld (musicsfxplaying),a
call musicplayercmdFF
ld a,1
call musicplayercmdFF
ld a,2
call musicplayercmdFF
pop iy
startmusic2:
ld hl,257
ld (musicwaitint_A),hl ; both musicwaitint_A and musicwaitint_ini_A
ld (musicwaitint_B),hl
ld (musicwaitint_C),hl
ei
ret
stopmusic:
di
ld hl,musicpieceendvolume
ld (musicpointer_A),hl
ld (musicpointer_B),hl
ld (musicpointer_C),hl
ld hl,0
ld (musicpointer_A_stack),hl
ld (musicpointer_B_stack),hl
ld (musicpointer_C_stack),hl
xor a
ld (musicsfxplaying),a
call startmusic2 ; performes EI
call musicplayer ; force not off
jp musicplayer ; force nextsheet
musicpieceendvolume: db 128 ; special note volume 0
db 255 ; next sheet => stop playing
musicplayer:
ld a,(musicsfxplaying)
and 128
jp nz,ReplayerUpdatePsg ; are we playing an ISR voice synthesis?
ld hl,musicwaitint_A
xor a
call musicplayer1
ld hl,musicwaitint_B
ld a,1
call musicplayer1
ld hl,musicwaitint_C
ld a,2
call musicplayer1
jp oldhook
musicplayer1:
dec (hl)
ret nz
; set musicwaitint_X to musicwaitint_ini_X
inc hl
ld (musicchannelplaying),a
ld a,(hl)
dec hl
ld (hl),a
inc hl
; now load music pointer
inc hl
ld e,(hl)
inc hl
ld a,(hl)
or e
ret z ; music pointer is 0 so stop playing
push hl
ld h,(hl)
ld l,e
musicplayer2:
; now see if we need to play a note on this channel or a command byte is given
musicplayer3: ld a,(hl)
bit 7,a
jr nz,musicplayercmdbyte
; the note we need to set for current channel
ld d,a
ld a,(musicchannelplaying)
call musicplayercmdIY
add a,a
out (#a0),a
push hl
ld a,d
add a,a
ld e,a
ld d,0
ld hl,musicnotes
add hl,de
ld c,#a1
outi
ld a,(musicchannelplaying)
add a,a
inc a
out (#a0),a
nop
outi
; now if previous note was rest we need to set the volume again
ld a,(iy+5)
or a
jp z,musicplayer3a
ld a,(musicchannelplaying)
add a,8
out (#a0),a
ld a,(iy+4)
out (#a1),a
xor a
ld (iy+5),a
musicplayer3a: ; let's mimic basic play command and set the enveloppe form when a note is played
ld a,13
out (#a0),a
ld a,(PSGREG13)
out (#a1),a
pop hl
musicplayer4: inc hl
pop de ; get back to musicpointer_Y
ex de,hl
ld (hl),d
dec hl
ld (hl),e
ret ; played note so get back
musicplayercmdbyte:
cp 128
jp nz,musicplayercmdbyte1
;note 128 is stop channel by volume 0
musicplayercmdbyte0: ld a,(musicchannelplaying)
call musicplayercmdIY
add a,8
out (#a0),a
xor a
out (#a1),a
ld a,1
ld (iy+5),a
jp musicplayer4
musicplayercmdbyte1: cp 129 ; same as 128 but for SFX
jr nz,musicplayercmdbyte10
xor a
ld (musicsfxplaying),a
jr musicplayercmdbyte0
musicplayercmdbyte10:
cp 255
jp nz,musicplayercmdbyte3
;next music sheet
ld a,(musicchannelplaying)
call musicplayercmdFF
ld a,h
or l
jp nz,musicplayer2
pop de ; get back to musicpointer_Y
ret
musicplayercmdIY: ; in A is current channel, out is IY
cp 1
jr c,musicplayercmdIY1
jr z,musicplayercmdIY2
ld iy,musicpointer_C
ret
musicplayercmdIY1:
ld iy,musicpointer_A
ret
musicplayercmdIY2:
ld iy,musicpointer_B
ret
musicplayercmdFF: ; in A is current channel
call musicplayercmdIY
ld l,(iy+2)
ld h,(iy+3)
ld a,l
or h
jr z,musicplayercmdFF8
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,e
or d
ex de,hl
jr z,musicplayercmdFF8
ld (iy+2),e
ld (iy+3),d
musicplayercmdFF8:
ld (iy+0),l
ld (iy+1),h
ret
musicplayercmdbyte3:
; bit 6 => alter musicwaitint_X and musicwaitint_ini_X
ld c,a
bit 6,a
jr z,musicplayercmdbyte4
inc hl
ld a,(hl)
ex de,hl
pop hl
push hl
dec hl
dec hl
ld (hl),a
dec hl
ld (hl),a
ex de,hl
ld a,c
musicplayercmdbyte4:
; bit 5 => set volume next byte
bit 5,a
jr z,musicplayercmdbyte5
inc hl
ld a,(musicchannelplaying)
call musicplayercmdIY
add a,8
out (#a0),a
ld a,(hl)
out (#a1),a
ld (iy+4),a
ld a,c
musicplayercmdbyte5:
; bit 4 => set Envelope Period + Envelope Wave Shape
bit 4,a
inc hl
jp z,musicplayer3
ld a,11
out (#a0),a
ld a,(hl)
out (#a1),a
ld a,12
out (#a0),a
inc hl
ld a,(hl)
out (#a1),a
ld a,13
out (#a0),a
inc hl
ld a,(hl)
ld (PSGREG13),a
out (#a1),a
inc hl
jp musicplayer3
musicnotes: ; {{{
; not used dw #000E ; B octave 8
; not used dw #000F ; A# octave 8
; not used dw #0010 ; A octave 8
; not used dw #0011 ; G# octave 8
; not used dw #0012 ; G octave 8
; not used dw #0013 ; F# octave 8
; not used dw #0014 ; F octave 8
; not used dw #0015 ; E octave 8
; not used dw #0016 ; D# octave 8
; not used dw #0018 ; D octave 8
; not used dw #0019 ; C# octave 8
; not used dw #001B ; C octave 8
; not used dw #001C ; B octave 7
; not used dw #001E ; A# octave 7
; not used dw #0020 ; A octave 7
; not used dw #0022 ; G# octave 7
; not used dw #0024 ; G octave 7
; not used dw #0026 ; F# octave 7
; not used dw #0028 ; F octave 7
; not used dw #002A ; E octave 7
; not used dw #002D ; D# octave 7
; not used dw #0030 ; D octave 7
; not used dw #0032 ; C# octave 7
; not used dw #0035 ; C octave 7
; not used dw #0039 ; B octave 6
; not used dw #003C ; A# octave 6
; not used dw #0040 ; A octave 6
; not used dw #0043 ; G# octave 6
; not used dw #0047 ; G octave 6
; not used dw #004C ; F# octave 6
; not used dw #0050 ; F octave 6
; not used dw #0055 ; E octave 6
; not used dw #005A ; D# octave 6
; not used dw #005F ; D octave 6
; not used dw #0065 ; C# octave 6
dw #006B ; C octave 6 -> note 0
dw #0071 ; B octave 5 -> note 1
dw #0078 ; A# octave 5 -> note 2
dw #007F ; A octave 5 -> note 3
dw #0087 ; G# octave 5 -> note 4
dw #008F ; G octave 5 -> note 5
dw #0097 ; F# octave 5 -> note 6
dw #00A0 ; F octave 5 -> note 7
dw #00AA ; E octave 5 -> note 8
dw #00B4 ; D# octave 5 -> note 9
dw #00BE ; D octave 5 -> note 10
dw #00CA ; C# octave 5 -> note 11
dw #00D6 ; C octave 5 -> note 12
dw #00E3 ; B octave 4 -> note 13
; not used dw #00F0 ; A# octave 4
dw #00FE ; A octave 4 -> note 14
dw #010D ; G# octave 4 -> note 15
dw #011D ; G octave 4 -> note 16
dw #012E ; F# octave 4 -> note 17
dw #0140 ; F octave 4 -> note 18
dw #0153 ; E octave 4 -> note 19
dw #0168 ; D# octave 4 -> note 20
dw #017D ; D octave 4 -> note 21
dw #0194 ; C# octave 4 -> note 22
dw #01AC ; C octave 4 -> note 23
dw #01C5 ; B octave 3 -> note 24
dw #01E0 ; A# octave 3 -> note 25
dw #01FD ; A octave 3 -> note 26
dw #021B ; G# octave 3 -> note 27
dw #023B ; G octave 3 -> note 28
dw #025D ; F# octave 3 -> note 29
dw #0281 ; F octave 3 -> note 30
dw #02A7 ; E octave 3 -> note 31
dw #02CF ; D# octave 3 -> note 32
dw #02FA ; D octave 3 -> note 33
dw #0327 ; C# octave 3 -> note 34
dw #0357 ; C octave 3 -> note 35
dw #038A ; B octave 2 -> note 36
; not used dw #03C0 ; A# octave 2
dw #03F9 ; A octave 2 -> note 37
dw #0436 ; G# octave 2 -> note 38
dw #0476 ; G octave 2 -> note 39
; not used dw #04BA ; F# octave 2
dw #0501 ; F octave 2 -> note 40
dw #054E ; E octave 2 -> note 41
dw #059E ; D# octave 2 -> note 42
dw #05F4 ; D octave 2 -> note 43
; not used dw #064E ; C# octave 2
; not used dw #06AF ; C octave 2
; not used dw #0714 ; B octave 1
; not used dw #0780 ; A# octave 1
; not used dw #07F2 ; A octave 1
; not used dw #086B ; G# octave 1
; not used dw #08EB ; G octave 1
; not used dw #0973 ; F# octave 1
; not used dw #0A02 ; F octave 1
; not used dw #0A9B ; E octave 1
; not used dw #0B3C ; D# octave 1
; not used dw #0BE7 ; D octave 1
; not used dw #0C9C ; C# octave 1
; not used dw #0D5D ; C octave 1
; }}}
ReplayerUpdatePsg: ; voice synthesis on ISR code
ld hl,(PNT_FRAME)
ld a,(hl)
cp 255
jr nz,ReplayerUpdatePsg1
inc hl
cp (hl)
jr z,PSGReplayMute
dec hl
ReplayerUpdatePsg1:
ld de,PSG_REG+0
ld bc,3*2
ldir
inc hl ; skip other channels
inc hl ;
inc hl ; skip other channels
inc hl ;
ld de,PSG_REG+8
call logvol
call logvol
call logvol
inc hl ; skip other channels
inc hl ; skip other channels
ld (PNT_FRAME),hl
Rout:
xor a
ld bc,11*256+0xA1
ld hl,PSG_REG
Lout: out (0xa0),a
inc a
outi
jr nz,Lout
ret
logvol: ; extract psg volumes from the data
ld a,(hl)
rlca
rlca
rlca
rlca
and 15
ld (de),a
inc de
inc hl
ret
PSGReplayMute: call PSGReplayInitMem
xor a
ld (musicsfxplaying),a
jr Rout
PSGReplayInitMem:
xor a
ld hl,PSG_REG
ld de,PSG_REG+1
ld bc,14
ld (hl),a
ldir
ld a,%10111000
ld (PSG_REG+7),a
ld a,31
ld (PSG_REG+6),a
ret
musicpiecesfx1_A:
db 0xf0
db 1 ; new musicwaitinit_A
db 11 ; new volume
db 249,1,157 ; envelope generator
db 9,13
db 129,255
musicpiecesfx2_A:
db 0xf0
db 6 ; new musicwaitinit_A
db 15 ; new volume
db 249,1,157 ; envelope generator
db 10,15,11,16
db 129,255
musicpiecesfx3_A:
db 0xf0
db 4 ; new musicwaitinit_A
db 13 ; new volume
db 249,1,157 ; envelope generator
db 23,20,17
db 129,255
musicpiecesfx4_A:
db 0xf0
db 8 ; new musicwaitinit_A
db 15 ; new volume
db 249,1,157 ; envelope generator
db 30,35
db 129,255
musicpiecesfx5_A:
db 0xf0
db 2 ; new musicwaitinit_A
db 15 ; new volume
db 249,1,157 ; envelope generator
db 19,18,17,16,15,14,13,12,11
db 129,255
musicpiecesfx6_A:
db 0xf0
db 4 ; new musicwaitinit_A
db 16 ; new volume
db 249,1,157 ; envelope generator
db 11,12,13,14,15,16,17,18
db 129,255
; vim:foldmethod=marker:ft=z8a:ts=26