-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphaser2.asm
567 lines (509 loc) · 8.75 KB
/
phaser2.asm
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
output "phaser2.bin"
OP_INCDE equ $13
OP_DECDE equ $1b
OP_DECHL equ $2b
OP_ANDH equ $a4
OP_XORH equ $ac
OP_ORC equ $b1
OP_ORH equ $b4
; org $4000 ; Aquarius 4k cassette/cartridge
; org $c000 ; Aquarius lower 8k cartridge
org $e000 ; Aquarius upper 8k cartridge
; org $100 ; Microbee
; org $8000 ; VZ
; org $4000 ; ZX Spectrum
db 98, 117, 115, 104
db 121, 156, 50, 176
db 48, 108, 50, 100
db 50, 168, 183, 112
;Phaser2 beeper music engine by Shiru ([email protected]) 03'11
;Two channels of phase synth, per-pattern tempo
;One channel of interrupting drums
;Feel free to do whatever you want with the code, it is PD
begin
ld hl,musicData
call play
jp begin
play
di
exx
push hl
push iy
exx
ld e,(hl)
inc l
ld d,(hl)
inc l
ld (readPos.pos),de
ld e,(hl)
inc l
ld d,(hl)
ld (drumSynth.drumSettings),de
ld a,h
ld (readRow.insList0),a
ld (readRow.insList1),a
ld hl,0
ld (soundInit.ch0cnt0),hl
ld ix,0 ;ch0cnt1
ld (readRow.ch1cnt0),hl
ld iy,0 ;ch1cnt1
ld (soundInit.ch0add0),hl
ld sp,hl ;ch0add1
ld (readRow.ch1add0),hl
ld (readRow.ch1add1),hl
xor a
ld (readRow.ch0int),a
ld (readRow.ch1int),a
ld (readRow.ch0det),a
ld (readRow.ch1det),a
ld a,64
ld (readRow.ch0pha),a
ld (readRow.ch1pha),a
ld a,OP_XORH
ld (soundLoop.op0),a
ld (soundLoop.op1),a
ld hl,1000
ld (soundInit.len),hl
exx
ld hl,0 ;ch1cnt0
ld de,0 ;ch1add1
ld bc,0 ;ch1add0
exx
readPos
.pos=$+1
ld hl,0
.read
ld e,(hl)
inc l
ld d,(hl)
inc hl
ld a,d
or e
jr z,.loop
ld (.pos),hl
ex de,hl
ld e,(hl)
inc l
ld d,(hl)
inc hl
ld (soundInit.len),de
jp readRow.read
.loop
ld e,(hl)
inc l
ld d,(hl)
ex de,hl
jp .read
readRow
.pos=$+1
ld hl,0
.read
ld a,(hl)
cp 246
jp c,.ch0
cp 255
jp z,readPos
inc hl
ld (.pos),hl
sub 246
jp drumSynth
.ch0mute
ld sp,0
ld ix,0
ld (soundInit.ch0cnt0),sp
ld (soundInit.ch0add0),sp
jp .ch1
.ch1mute
exx
ld hl,0
ld d,h
ld e,h
ld b,h
ld c,h
exx
jp .ch1skip
.ch0
inc hl
add a,a
jp z,.ch1
jp nc,.note0 ;bit 7 is not set, it is a note
ex de,hl ;set instrument of channel 0
.insList0=$+1
ld h,0
ld l,a
ld a,(hl)
inc l
ld (.ch0int),a
ld a,(hl)
inc l
ld (.ch0pha),a
ld a,(hl)
ld (.ch0det),a
inc l
ld a,(hl)
ld (soundLoop.op0),a
ex de,hl
ld a,(hl)
inc hl
add a,a
.note0
cp 2
jr z,.ch0mute
ex de,hl ;then read note and check for channel two data
ld l,a
add a,a
jr nc,.ch0pskip
ld ix,(soundInit.ch0cnt0)
.ch0pha=$+1
ld a,0
add a,ixh
ld ixh,a
res 7,l
.ch0pskip
ld h,noteTable/256
ld c,(hl)
inc l
ld b,(hl)
ld (soundInit.ch0add0),bc
.ch0int=$+1
ld a,0
add a,l
ld l,a
ld b,(hl)
dec l
ld c,(hl)
.ch0det=$+1
ld hl,0
add hl,bc
ld sp,hl ;ch0add1
ex de,hl
.ch1
ld a,(hl)
inc hl
add a,a
jp z,.ch1skip
jp nc,.note1
ex de,hl ;set instrument of channel 1
.insList1=$+1
ld h,0
ld l,a
ld a,(hl)
inc l
ld (.ch1int),a
ld a,(hl)
inc l
ld (.ch1pha),a
ld a,(hl)
ld (.ch1det),a
inc l
ld a,(hl)
ld (soundLoop.op1),a
ex de,hl
ld a,(hl)
inc hl
add a,a
.note1
cp 2
jp z,.ch1mute
ex de,hl ;then read note and play a row
ld l,a
add a,a
jr nc,.ch1pskip
ld iy,(.ch1cnt0)
.ch1pha=$+1
ld a,0
add a,iyh
ld iyh,a
res 7,l
.ch1pskip
ld h,noteTable/256
ld c,(hl)
inc l
ld b,(hl)
ld (.ch1add0),bc
.ch1int=$+1
ld a,0
add a,l
ld l,a
ld b,(hl)
dec l
ld c,(hl)
.ch1det=$+1
ld hl,0
add hl,bc
ld (.ch1add1),hl
ex de,hl
exx
.ch1cnt0=$+1
ld hl,0
.ch1add1=$+1
ld de,0
.ch1add0=$+1
ld bc,0
exx
.ch1skip
ld (.pos),hl
soundInit
.skip=$+1
ld hl,0
.len=$+1
ld de,10000
ld a,h
or l
jp z,.noSkip
ld a,h
cp d
jr c,.skipHL
ld a,l
cp e
jr c,.skipHL
and a
sbc hl,de
ld (.skip),hl
jp readRow
.skipHL
ex de,hl
sbc hl,de
ex de,hl
ld hl,0
ld (.skip),hl
.noSkip
.ch0cnt0=$+1
ld hl,0
.ch0add0=$+1
ld bc,200
soundLoop
add hl,bc ;11
ld a,h ;4
add ix,sp ;15
.op0=$+1
xor ixh ;8
rla ;4
sbc a,a ;4
out ($fc),a ;11 ; Aquarius
; out ($fe),a ;11 ; ZX
; AND $21 ; VZ
; ld ($6800), a ; VZ
; out (2),a ;11 ; MICROBEE
exx ;4
add hl,bc ;11
ld a,h ;4
add iy,de ;15
.op1=$+1
xor iyh ;8
rla ;4
sbc a,a ;4
out ($fc),a ;11 ; Aquarius
; out ($fe),a ;11 ; ZX
; AND $21 ; VZ
; ld ($6800), a ; VZ
; out (2),a ;11 ; MICROBEE
exx ;4
dec de ;6
ld a,d ;4
or e ;4
jp nz,soundLoop ;10=160t
ld (soundInit.ch0cnt0),hl
jp readRow
drumSynth
ld (.prevIX),ix
ld (.prevIY),iy
add a,a
ld b,a
add a,a
add a,a
add a,b
ld b,0
ld c,a
.drumSettings=$+1
ld hl,0
add hl,bc
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld (soundInit.skip),bc
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(hl)
inc hl
ld (.toneSFreq),a
ld a,(hl)
inc hl
ld (.toneSlide),a
ld a,(hl)
inc hl
ld (.noiseFrq),a
ld a,(hl)
ld (.noiseEnable),a
ld hl,0
ld ix,$0101 ; Aquarius
; ld ix,$1010 ; ZX spectrum
; ld ix,$2020 ; VZ
; ld ix,$4040 ; microbee
ld iy,0
.l0
add hl,de ;10
ld a,(iy) ;19
dec ixh ;8
jp nz,.l1 ;10
.noiseFrq=$+2
ld ixh,1 ;11
inc iy ;10
jp .l2 ;10
.l1
ld a,(iy) ;19
jr $+2 ;12
.l2
.noiseEnable=$+1
out ($fc),a ;11 ; Aquarius
; out ($fe),a ;11 ; ZX
; AND $21 ; VZ
; ld ($6800), a ; VZ
; out (2),a ;11 ; MICROBEE
dec ixl ;8
jp nz,.l3 ;10
.toneSFreq=$+2
ld ixl,5 ;11
.toneSlide=$
dec hl ;6
jp .l4 ;10
.l3
jp $+3 ;10
jp $+3 ;10
ld a,0 ;7
.l4
ld a,h ;4
rla ;4
sbc a,a ;4
out ($fc),a ;11 ; Aquarius
; out ($fe),a ;11 ; ZX
; AND $21 ; VZ
; ld ($6800), a ; VZ
; out (2),a ;11 ; MICROBEE
dec bc ;6
ld a,b ;4
or c ;4
jp nz,.l0 ;10=195t
.prevIX=$+2
ld ix,0
.prevIY=$+2
ld iy,0
jp readRow
align 256
noteTable
dw $0000,$0000
dw $00c3,$00cf,$00db,$00e9,$00f6,$0105,$0115,$0125,$0137,$0149,$015d,$0171
dw $0187,$019f,$01b7,$01d2,$01ed,$020b,$022a,$024b,$026e,$0293,$02ba,$02e3
dw $030f,$033e,$036f,$03a4,$03db,$0416,$0454,$0496,$04dc,$0526,$0574,$05c7
dw $061f,$067c,$06df,$0748,$07b7,$082c,$08a8,$092c,$09b8,$0a4c,$0ae9,$0b8f
dw $0c3f,$0cf9,$0dbf,$0e90,$0f6e,$1059,$1151,$1259,$1370,$1498,$15d2,$171e
dw $187e,$19f3,$1b7e,$1d20,$1edc,$20b2,$22a3,$24b3,$26e1,$2931,$2ba4,$2e3c
dw $30fc,$33e6,$36fc,$3a41,$3db8,$4164,$4547,$4966,$4dc3,$5263,$5748,$5c79
dw $61f9,$67cc,$6df8,$7483,$7b71,$82c8,$8a8f,$92cc,$9b86,$a4c6,$ae91,$b8f3
dw $0030,$0033,$0036,$003a,$003d,$0041,$0045,$0049,$004d,$0052,$0057,$005c ;lowest octaves
dw $0061,$0067,$006d,$0074,$007b,$0082,$008a,$0092,$009b,$00a4,$00ae,$00b8
musicData
dw .start
dw .drums
.insList
db 0 ;interval (offset from the base in semitones*2)
db 64 ;phase
db 4 ;detune (offset from the base in counter units)
db OP_ORH
db 0
db 0
db 8
db OP_XORH
.drums
;tom
dw 1000*195/160 ;length in tone samples
dw 1000 ;length in drum samples
dw 1800 ;tone div
db 1 ;slide div
db OP_DECDE ;slide direction, dec de,inc de,dec hl
db 0 ;noise div
db 0 ;noise enable
;snare
dw 1500*195/160 ;length in tone samples
dw 1500 ;length in drum samples
dw 1500 ;tone div
db 1 ;slide div
db OP_DECDE ;slide direction, dec de,inc de,dec hl
db 2 ;noise div
db 16 ;noise enable
;kick
dw 600*195/160 ;length in tone samples
dw 600 ;length in drum samples
dw 800 ;tone div
db 1 ;slide div
db OP_DECDE ;slide direction, dec de,inc de,dec hl
db 0 ;noise div
db 0 ;noise enable
;open hat
dw 400*195/160 ;length in tone samples
dw 400 ;length in drum samples
dw 0 ;tone div
db 0 ;slide div
db OP_DECHL ;slide direction, dec de,inc de,dec hl
db 1 ;noise div
db 16 ;noise enable
;closed hat
dw 100*195/160 ;length in tone samples
dw 100 ;length in drum samples
dw 0 ;tone div
db 0 ;slide div
db OP_DECHL ;slide direction, dec de,inc de,dec hl
db 1 ;noise div
db 16 ;noise enable
.start
.loop2
dw .pattern0
dw .pattern0
dw .pattern0
dw .pattern0
dw .pattern1
dw .pattern1
dw .pattern2
dw .pattern3
dw 0
dw .loop2
.pattern0
dw 5000
db 248,128+4,64+26,128+2,64+2
db 249,28,64+14
db 247,30,64+2
db 249,31,64+14
db 255
.pattern1
dw 5000
db 248,128+4,64+26,128+2,64+7
db 249,28,64+19
db 247,30,64+7
db 249,31,64+19
db 255
.pattern2
dw 5000
db 248,128+4,64+26,128+2,64+9
db 249,28,64+21
db 247,30,64+9
db 249,31,64+21
db 255
.pattern3
dw 5000/2
db 246,128+4,64+26,128+2,64+9
db 0,0
db 246,28,64+21
db 0,0
db 247,30,64+9
db 246,0,0
db 246,31,64+21
db 246,0,0
db 255
end