~rabbits/uxn

uxn/projects/demos/drum-rack.usm -rw-r--r-- 19.5 KiB
5294b92eneauoire Added cell count to GOL an hour ago
                                                                                
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
( drum rack 

	TODO
		- When selecting a pad, should highlight note in octave
)

%+  { ADD } %-   { SUB }  %*  { MUL } %/   { DIV }  
%<  { LTH } %>   { GTH }  %=  { EQU } %!   { NEQ } 
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } 
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }  

%TOB { SWP POP } %TOS { #00 SWP }
%RTN { JMP2r }
%MOD { DUP2 / * - }
%LTS2  { #8000 ++ SWP2 #8000 ++ >> } %GTS2  { #8000 ++ SWP2 #8000 ++ << }

%PAD-WIDTH { #0030 }
%PAD-HEIGHT { #0020 }

( devices )

|00 @System     [ &vector $2 &pad      $6 &r      $2 &g     $2 &b      $2 ]
|10 @Console    [ &pad    $8 &char     $1 &byte   $1 &short $2 &string $2 ]
|20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y     $2 &addr   $2 &color $1 ]
|30 @Audio0     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr  $2 &volume $1 &pitch $1 ]
|40 @Audio1     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr  $2 &volume $1 &pitch $1 ]
|50 @Audio2     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr  $2 &volume $1 &pitch $1 ]
|60 @Audio3     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr  $2 &volume $1 &pitch $1 ]
|70 @Midi       [ &vector $2 &channel  $1 &note   $1 &velocity $1 ]
|80 @Controller [ &vector $2 &button   $1 &key    $1 ]
|90 @Mouse      [ &vector $2 &x        $2 &y      $2 &state $1 &chord $1 ]
|a0 @File       [ &vector $2 &success  $2 &offset $2 &pad   $2 &name  $2 &length $2 &load $2 &save $2 ]

( variables )

|0000

@center   [ &x $2 &y $2 ]
@pointer  [ &x $2 &y $2 ]
@piano    [ &last $1 &octave $1 ]
@pads     [ &last $1 ]
@frame    [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@pad-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@mix-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@oct-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@wav-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]

( TODO: remove )
@color $1
@rect        [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]

@modes [ $1 $1 $1 $1 ] ( single/repeat )

( program )

|0100 ( -> )
	
	( theme ) 
	#4ff2 .System/r DEO2 
	#2f8c .System/g DEO2 
	#afb6 .System/b DEO2

	( vectors )
	;on-control .Controller/vector DEO2
	;on-mouse   .Mouse/vector DEO2
	;on-frame   .Screen/vector DEO2
	;on-midi    .Midi/vector DEO2

	( channel defaults )
	#dd   .Audio0/volume DEO 
	#0118 .Audio0/adsr DEO2
	#0200 .Audio0/length DEO2
	#ce   .Audio1/volume DEO 
	#0334 .Audio1/adsr DEO2
	#0800 .Audio1/length DEO2
	#ec   .Audio2/volume DEO 
	#0414 .Audio2/adsr DEO2
	#0800 .Audio2/length DEO2
	#ee   .Audio3/volume DEO 
	#022c .Audio3/adsr DEO2
	#1000 .Audio3/length DEO2

	( defaults )
	#01 .modes POK
	#01 .piano/octave POK

	( find center )
	.Screen/width DEI2 #0002 // .center/x POK2
	.Screen/height DEI2 #0002 // .center/y POK2

	( place frame )
	.center/x PEK2 PAD-WIDTH #0003 ** -- #0010 -- .frame/x1 POK2
	.center/y PEK2 #0050 -- .frame/y1 POK2
	.center/x PEK2 PAD-WIDTH #0003 ** ++ #0010 ++ .frame/x2 POK2
	.frame/y1 PEK2 PAD-HEIGHT #0004 ** ++ #0028 ++ .frame/y2 POK2

	( place pad-view )
	.frame/x1 PEK2 .pad-view/x1 POK2
	.frame/y1 PEK2 .pad-view/y1 POK2
	.pad-view/x1 PEK2 #0004 PAD-WIDTH ** ++ .pad-view/x2 POK2
	.pad-view/y1 PEK2 #0004 PAD-HEIGHT ** ++ .pad-view/y2 POK2

	( place mix-view )
	.pad-view/x2 PEK2 #0006 ++ .mix-view/x1 POK2
	.pad-view/y1 PEK2 .mix-view/y1 POK2
	.mix-view/x1 PEK2 #007a ++ .mix-view/x2 POK2
	.pad-view/y2 PEK2 .mix-view/y2 POK2

	( place oct-view )
	.frame/x1 PEK2 .oct-view/x1 POK2
	.mix-view/y2 PEK2 #0004 ++ .oct-view/y1 POK2
	.oct-view/x1 PEK2 #0050 ++ .oct-view/x2 POK2
	.oct-view/y1 PEK2 #0018 ++ .oct-view/y2 POK2

	( place wav-view )
	.oct-view/x2 PEK2 .wav-view/x1 POK2
	.mix-view/y2 PEK2 #0004 ++ .wav-view/y1 POK2
	.frame/x2 PEK2 .wav-view/x2 POK2
	.wav-view/y1 PEK2 #0020 ++ .wav-view/y2 POK2

	( draw outlines )
	.mix-view/x1 PEK2 #0004 -- 
	.mix-view/y1 PEK2 #0000 -- 
	.mix-view/x2 PEK2 #0002 --
	.mix-view/y2 PEK2 #0002 --
	#01 ;line-rect JSR2
	.wav-view/x1 PEK2 #0000 -- 
	.wav-view/y1 PEK2 #0002 -- 
	.wav-view/x2 PEK2 #0002 --
	.wav-view/y2 PEK2 #0002 ++
	#01 ;line-rect JSR2

	( initial draw )
	#00 #10
	&draw-pads
		( load sample )
		OVR TOS #0019 ** ;pad-path ++ .File/name DEO2
		OVR #04 / #10 * .Audio0/length + DEI2 .File/length DEO2
		OVR TOS #0002 ** ;pad-addr ++ LDA2 .File/load DEO2
		( draw pad )
		OVR #01 ;draw-pad JSR2
		( draw mixer )
		OVR #04 / ;draw-mixer JSR2
		( incr ) SWP #01 + SWP
		DUP2 < ,&draw-pads JNZ
	POP2

	;draw-octave JSR2

BRK

@on-frame ( -> )
	
	( update VU monitors )
	#00 #04
	&loop
		OVR STH
		( x ) .mix-view/x1 PEK2 #0074 ++
		( y ) .mix-view/y1 PEK2 PAD-HEIGHT DUPr STHr TOS ** ++ #0002 ++
		( output ) .Audio0/output STHr #10 * + DEI 
		;draw-monitor JSR2
		( incr ) SWP #01 + SWP
		DUP2 < ,&loop JNZ
	POP2

BRK

@on-mouse ( -> )

	;draw-cursor JSR2 

	.Mouse/state DEI #00 ! #01 JNZ [ BRK ]

	.Mouse/x DEI2 DUP2 .pad-view/x1 PEK2 >> ROT ROT .pad-view/x2 PEK2 #0001 ++ << #0101 ==
	.Mouse/y DEI2 DUP2 .pad-view/y1 PEK2 >> ROT ROT .pad-view/y2 PEK2 << #0101 ==
	#0101 == ;on-touch-pad JNZ2

	.Mouse/x DEI2 DUP2 .mix-view/x1 PEK2 >> ROT ROT .mix-view/x2 PEK2 #0001 ++ << #0101 ==
	.Mouse/y DEI2 DUP2 .mix-view/y1 PEK2 >> ROT ROT .mix-view/y2 PEK2 << #0101 ==
	#0101 == ;on-touch-mix JNZ2

	.Mouse/x DEI2 DUP2 .oct-view/x1 PEK2 >> ROT ROT .oct-view/x2 PEK2 #0001 ++ << #0101 ==
	.Mouse/y DEI2 DUP2 .oct-view/y1 PEK2 >> ROT ROT .oct-view/y2 PEK2 << #0101 ==
	#0101 == ;on-touch-oct JNZ2

BRK

@on-midi ( -> )
	
	.Midi/note DEI #00 ! #01 JNZ [ BRK ]

	( drums )
	.Midi/channel DEI #90 ! ,&no-drum JNZ 
		.Midi/note DEI #10 MOD ;play-pad JSR2
		BRK
	&no-drum

	( TODO: synths )
	;pad-addr #0008 ++ LDA2 .Audio0/addr DEO2
	#0008 .Audio0/length DEO2
	.Midi/note DEI .Audio0/pitch DEO

BRK

@on-control ( -> )

	.Controller/key DEI #00 ! #01 JNZ [ BRK ]

	.Controller/key DEI 
	DUP #31 ! ,&no-0 JNZ #00 ;play-pad JSR2 &no-0
	DUP #32 ! ,&no-1 JNZ #01 ;play-pad JSR2 &no-1
	DUP #33 ! ,&no-2 JNZ #02 ;play-pad JSR2 &no-2
	DUP #34 ! ,&no-3 JNZ #03 ;play-pad JSR2 &no-3
	DUP #71 ! ,&no-4 JNZ #04 ;play-pad JSR2 &no-4
	DUP #77 ! ,&no-5 JNZ #05 ;play-pad JSR2 &no-5
	DUP #65 ! ,&no-6 JNZ #06 ;play-pad JSR2 &no-6
	DUP #72 ! ,&no-7 JNZ #07 ;play-pad JSR2 &no-7
	DUP #61 ! ,&no-8 JNZ #08 ;play-pad JSR2 &no-8
	DUP #73 ! ,&no-9 JNZ #09 ;play-pad JSR2 &no-9
	DUP #64 ! ,&no-a JNZ #0a ;play-pad JSR2 &no-a
	DUP #66 ! ,&no-b JNZ #0b ;play-pad JSR2 &no-b
	DUP #7a ! ,&no-c JNZ #0c ;play-pad JSR2 &no-c
	DUP #78 ! ,&no-d JNZ #0d ;play-pad JSR2 &no-d
	DUP #63 ! ,&no-e JNZ #0e ;play-pad JSR2 &no-e
	DUP #76 ! ,&no-f JNZ #0f ;play-pad JSR2 &no-f
	POP

BRK

@on-touch-pad ( -> )
	
	( x ) .Mouse/x DEI2 .pad-view/x1 PEK2 -- PAD-WIDTH // TOB
	( y ) .Mouse/y DEI2 .pad-view/y1 PEK2 -- PAD-HEIGHT // TOB #04 * +
	
	DUP SWP ;play-pad JSR2

	;draw-waveform JSR2

	( release ) #00 .Mouse/state DEO

BRK

@on-touch-mix ( -> )

	( channel ) .Mouse/y DEI2 .mix-view/y1 PEK2 -- PAD-HEIGHT // TOB STH
	( knob ) .Mouse/x DEI2 .mix-view/x1 PEK2 -- #0010 // TOB
	( adsr )
	DUP #00 ! ,&no-a JNZ
		.Audio0/adsr [ DUPr STHr #10 * + ] DEI
		#10 .Mouse/state DEI #10 = #e0 * + +
		.Audio0/adsr [ DUPr STHr #10 * + ] DEO &no-a
	DUP #01 ! ,&no-d JNZ
		.Audio0/adsr [ DUPr STHr #10 * + ] DEI
		DUP #f0 AND STH #01 .Mouse/state DEI #10 = #0e * + + #0f AND STHr +
		.Audio0/adsr [ DUPr STHr #10 * + ] DEO &no-d
	DUP #02 ! ,&no-s JNZ
		.Audio0/adsr [ DUPr STHr #10 * + ] #01 + DEI
		#10 .Mouse/state DEI #10 = #e0 * + +
		.Audio0/adsr [ DUPr STHr #10 * + ] #01 + DEO &no-s
	DUP #03 ! ,&no-r JNZ
		.Audio0/adsr [ DUPr STHr #10 * + ] #01 + DEI
		DUP #f0 AND STH #01 .Mouse/state DEI #10 = #0e * + + #0f AND STHr +
		.Audio0/adsr [ DUPr STHr #10 * + ] #01 + DEO &no-r
	( modes )
	DUP #04 ! ,&no-repeat JNZ
		.modes [ DUPr STHr + ] PEK 
		#00 =
		.modes [ DUPr STHr + ] POK &no-repeat
	( volume )
	DUP #05 ! ,&no-left JNZ
		.Audio0/volume [ DUPr STHr #10 * + ] DEI 
		#10 .Mouse/state DEI #10 = #e0 * + +
		.Audio0/volume [ DUPr STHr #10 * + ] DEO &no-left
	DUP #06 ! ,&no-right JNZ
		.Audio0/volume [ DUPr STHr #10 * + ] DEI
		DUP #f0 AND STH #01 .Mouse/state DEI #10 = #0e * + + #0f AND STHr +
		.Audio0/volume [ DUPr STHr #10 * + ] DEO &no-right
	POP

	( release ) #00 .Mouse/state DEO

	DUPr STHr ;draw-mixer JSR2

	POPr

BRK

@on-touch-oct ( -> )
	
	.Mouse/x DEI2 .oct-view/x1 PEK2 -- #0008 // TOB #08 ! ,&no-mod JNZ
		.Mouse/y DEI2 .oct-view/y1 PEK2 -- #0008 // TOB 
		DUP #00 ! ,&no-incr JNZ
			.piano/octave PEK #01 + .piano/octave POK &no-incr
		DUP #02 ! ,&no-decr JNZ
			.piano/octave PEK #01 - .piano/octave POK &no-decr
		POP
		( release ) #00 .Mouse/state DEO
		;draw-octave JSR2
		BRK
	&no-mod

	.Mouse/x DEI2 .oct-view/x1 PEK2 -- #0008 // TOB #06 GTH ,&no-key JNZ
		.Mouse/x DEI2 .oct-view/x1 PEK2 -- #0008 // 
		( set pitch of pad )
		DUP2 ;notes ++ LDA .pads/last PEK SWP .piano/octave PEK #02 - #0c * + 
		( save ) SWP TOS ;pad-pitch ++ STA 
		( record last note )
		TOB .piano/last POK 
		.pads/last PEK ;play-pad JSR2
		( release ) #00 .Mouse/state DEO
		;draw-octave JSR2
	&no-key

BRK

@play-pad ( note pad -- )
	
	( unselect last )
	.pads/last PEK #01 ;draw-pad JSR2
	DUP .pads/last POK 
	( highlight )
	DUP #02 ;draw-pad JSR2
	( addr )
	DUP TOS #0002 ** ;pad-addr ++ LDA2 STH2
	DUP #04 / #10 * .Audio0/addr + STH2r ROT DEO2
	( pitch )
	DUP TOS ;pad-pitch ++ LDA STH 
	DUP #04 / .modes + PEK #00 = #80 * STH ADDr
	DUP #04 / #10 * .Audio0/pitch + STHr SWP DEO
	#04 / ;draw-mixer JSR2

RTN

@draw-waveform ( pad -- )
	
	( stash address )
	#02 * #00 SWP ;pad-addr ++ LDA2 STH2

	( clear )
	.wav-view/x1 PEK2 #0002 ++
	.wav-view/y1 PEK2
	.wav-view/x2 PEK2 #0002 --
	.wav-view/y2 PEK2
	#00 ;fill-rect JSR2

	.wav-view/x1 PEK2 #0002 ++ .Screen/x DEO2

	( waveform )
	#00 #e8
	&loop
		( dotted line )
		OVR #01 AND ,&no-dot JNZ 
			.wav-view/y1 PEK2 #0010 ++ .Screen/y DEO2
			#01 .Screen/color DEO
		&no-dot
		OVR TOS #0010 ** [ DUP2r STH2r ] ++ LDA 
		#02 /
		TOS #0004 // .wav-view/y1 PEK2 ++ .Screen/y DEO2
		.Screen/x DEI2 #0001 ++ .Screen/x DEO2
		( draw ) #02 .Screen/color DEO
		( incr ) SWP #01 + SWP
		DUP2 < ,&loop JNZ
	POP2
	POP2r

RTN

@draw-mixer ( mixer -- )

	DUP STH #00 SWP PAD-HEIGHT ** .mix-view/y1 PEK2 ++ #0003 ++

	( adsr )
	DUP2 .mix-view/x1 PEK2 SWP2
		.Audio0/adsr [ DUPr STHr #10 * + ] DEI #04 SFT ;draw-knob JSR2
	DUP2 .mix-view/x1 PEK2 #0010 ++ SWP2
		.Audio0/adsr [ DUPr STHr #10 * + ] DEI #0f AND ;draw-knob JSR2
	DUP2 .mix-view/x1 PEK2 #0020 ++ SWP2
		.Audio0/adsr [ DUPr STHr #10 * + ] #01 + DEI #04 SFT ;draw-knob JSR2
	DUP2 .mix-view/x1 PEK2 #0030 ++ SWP2
		.Audio0/adsr [ DUPr STHr #10 * + ] #01 + DEI #0f AND ;draw-knob JSR2
	( once/repeat )
	DUP2 .mix-view/x1 PEK2 #0040 ++ SWP2
		.modes [ DUPr STHr + ] PEK ;draw-switch JSR2
	( volume )
	DUP2 .mix-view/x1 PEK2 #0050 ++ SWP2
		.Audio0/volume [ DUPr STHr #10 * + ] DEI #04 SFT ;draw-knob JSR2
	DUP2 .mix-view/x1 PEK2 #0060 ++ SWP2
		.Audio0/volume [ DUPr STHr #10 * + ] DEI #0f AND ;draw-knob JSR2
	POP2
	POPr

RTN

@draw-pad ( pad color -- )
	
	STH STH

	DUPr STHr 

	DUP #04 / SWP #04 MOD TOS PAD-WIDTH ** ( center ) .pad-view/x1 PEK2 ++ 
	ROT TOS PAD-HEIGHT ** ( center ) .pad-view/y1 PEK2 ++ 

	( draw outline )
	OVR2 OVR2 
	OVR2 PAD-WIDTH #0002 -- ++ 
	OVR2 PAD-HEIGHT #0002 -- ++ 
	OVRr STHr ;line-rect JSR2

	( draw name )
	OVR2 #0002 ++ 
	OVR2 #0002 ++ 
	;pad-name DUPr STHr TOS #0005 ** ++ 
	#20 OVRr STHr + 
	;draw-label JSR2

	( draw note )
	OVR2 #0003 ++ .Screen/x DEO2
	DUP2 #0014 ++ .Screen/y DEO2
	( get pitch ) DUPr STHr TOS ;pad-pitch ++ LDA
	#0c / TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
	#21 .Screen/color DEO

	( draw octave )
	OVR2 #000b ++ .Screen/x DEO2
	DUP2 #0014 ++ .Screen/y DEO2
	( get pitch ) DUPr STHr TOS ;pad-pitch ++ LDA
	#0c MOD TOS #0008 ** ;font-notes ++ .Screen/addr DEO2
	#21 .Screen/color DEO

	POP2 POP2

	POPr POPr

RTN

@draw-octave ( -- )
	
	.oct-view/x1 PEK2 .oct-view/y1 PEK2

	OVR2 OVR2 ;keys-left-icns #21 .piano/last PEK #00 = + ;draw-key JSR2
	OVR2 #0008 ++ OVR2 ;keys-middle-icns #21 .piano/last PEK #01 = + ;draw-key JSR2
	OVR2 #0010 ++ OVR2 ;keys-right-icns #21 .piano/last PEK #02 = + ;draw-key JSR2
	OVR2 #0018 ++ OVR2 ;keys-left-icns #21 .piano/last PEK #03 = + ;draw-key JSR2
	OVR2 #0020 ++ OVR2 ;keys-middle-icns #21 .piano/last PEK #04 = + ;draw-key JSR2
	OVR2 #0028 ++ OVR2 ;keys-middle-icns #21 .piano/last PEK #05 = + ;draw-key JSR2
	SWP2 #0030 ++ SWP2 ;keys-right-icns #21 .piano/last PEK #06 = + ;draw-key JSR2

	.oct-view/x1 PEK2 #0040 ++ .Screen/x DEO2

	;arrow-icns .Screen/addr DEO2
	.oct-view/y1 PEK2 .Screen/y DEO2
	#21 .Screen/color DEO

	;arrow-icns #0008 ++ .Screen/addr DEO2
	.oct-view/y1 PEK2 #0010 ++ .Screen/y DEO2
	#21 .Screen/color DEO

	;font-hex .piano/octave PEK #03 + #00 SWP #0008 ** ++ .Screen/addr DEO2
	.oct-view/y1 PEK2 #0008 ++ .Screen/y DEO2
	#23 .Screen/color DEO

RTN

@draw-monitor ( x* y* stereo -- )

	STH 

	.Screen/y DEO2
	.Screen/x DEO2

	#00 #0f
	&loop
		OVR #10 SWP - DUPr STHr #0f AND < #01 + .Screen/color DEO
		.Screen/x DEI2 #0002 ++ .Screen/x DEO2
		OVR #10 SWP - DUPr STHr #04 SFT < #01 + .Screen/color DEO
		.Screen/x DEI2 #0002 -- .Screen/x DEO2
		.Screen/y DEI2 #0002 ++ .Screen/y DEO2
		( incr ) SWP #01 + SWP
		DUP2 < ,&loop JNZ
	POP2

	POPr

RTN

@draw-key ( x* y* addr* color -- )
		
	STH
	.Screen/addr DEO2 
	SWP2 .Screen/x DEO2
	DUP2 #0018 ++
	&loop
		( move ) OVR2 .Screen/y DEO2
		( draw ) DUPr STHr .Screen/color DEO
		( incr ) .Screen/addr DEI2 #0008 ++ .Screen/addr DEO2  
		( incr ) SWP2 #0008 ++ SWP2
		OVR2 OVR2 << ,&loop JNZ
	POP2 POP2 
	POPr

RTN

@draw-cursor ( -- )
	
	( clear last cursor )
	;cursor-icn .Screen/addr DEO2 
	.pointer/x PEK2 .Screen/x DEO2 
	.pointer/y PEK2 .Screen/y DEO2 
	#30 .Screen/color DEO
	( record pointer positions )
	.Mouse/x DEI2 .pointer/x POK2 
	.Mouse/y DEI2 .pointer/y POK2
	( draw new cursor )
	.pointer/x PEK2 .Screen/x DEO2 
	.pointer/y PEK2 .Screen/y DEO2 
	( colorize on state )
	#33 [ .Mouse/state DEI #00 ! ] - .Screen/color DEO

RTN

@draw-knob ( x* y* value -- )

	( load ) STH .Screen/y DEO2  .Screen/x DEO2
	;knob-icns .Screen/addr DEO2 
	( draw ) #21 .Screen/color DEO
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2 
	;knob-icns #0008 ++ .Screen/addr DEO2 
	( draw ) #21 .Screen/color DEO
	.Screen/y DEI2 #0008 ++ .Screen/y DEO2 
	;knob-icns #0018 ++ .Screen/addr DEO2 
	( draw ) #21 .Screen/color DEO
	.Screen/x DEI2 #0008 -- .Screen/x DEO2 
	;knob-icns #0010 ++ .Screen/addr DEO2 
	( draw ) #21 .Screen/color DEO
	.Screen/x DEI2 #0004 ++ .Screen/x DEO2
	.Screen/y DEI2 #0008 ++ .Screen/y DEO2
	;font-hex #00 DUPr STHr #08 * ++ .Screen/addr DEO2
	( draw ) #21 .Screen/color DEO
	.Screen/x DEI2 #0004 -- #00 #00 DUPr STHr ;knob-offsetx ++ LDA ++ .Screen/x DEO2
	.Screen/y DEI2 #0010 -- #00 #00 STHr ;knob-offsety ++ LDA ++ .Screen/y DEO2
	;knob-icns #0020 ++ .Screen/addr DEO2
	( draw ) #25 .Screen/color DEO

RTN

@draw-switch ( x* y* value -- )
	
	STH .Screen/y DEO2 .Screen/x DEO2
	DUPr STHr #20 * #00 SWP ;switch-icns ++
	DUP2 .Screen/addr DEO2
	( draw ) #21 DUPr STHr + .Screen/color DEO
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	DUP2 #0008 ++ .Screen/addr DEO2
	( draw ) #21 DUPr STHr + .Screen/color DEO
	.Screen/y DEI2 #0008 ++ .Screen/y DEO2
	.Screen/x DEI2 #0008 -- .Screen/x DEO2
	DUP2 #0010 ++ .Screen/addr DEO2
	( draw ) #21 DUPr STHr + .Screen/color DEO
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	#0018 ++ .Screen/addr DEO2
	( draw ) #21 STHr + .Screen/color DEO

RTN

@line-rect ( x1* y1* x2* y2* color -- )

	( load ) .color POK DUP2 STH2 .rect/y2 POK2 .rect/x2 POK2 DUP2 STH2 .rect/y1 POK2 .rect/x1 POK2
	STH2r #0001 ++ STH2r
	&ver
		( save ) OVR2 .Screen/y DEO2
		( draw ) .rect/x1 PEK2 .Screen/x DEO2 .color PEK DUP .Screen/color DEO
		( draw ) .rect/x2 PEK2 .Screen/x DEO2 .Screen/color DEO
		( incr ) SWP2 #0001 ++ SWP2
		OVR2 OVR2 LTS2 ,&ver JNZ
	POP2 POP2
	.rect/x1 PEK2 #0001 ++ .rect/x2 PEK2 #0001 --
	&hor
		( save ) OVR2 .Screen/x DEO2
		( draw ) .rect/y1 PEK2 .Screen/y DEO2 .color PEK DUP .Screen/color DEO
		( draw ) .rect/y2 PEK2 .Screen/y DEO2 .Screen/color DEO
		( incr ) SWP2 #0001 ++ SWP2
		OVR2 OVR2 #0001 ++ LTS2 ,&hor JNZ
	POP2 POP2

RTN

@draw-label ( x* y* addr* color -- )
	
	( load ) STH STH2 .Screen/y DEO2 .Screen/x DEO2
	STH2r
	&loop
		DUP2 LDA #00 SWP #0030 -- #0008 ** ;font-num-uc ++ .Screen/addr DEO2 
		( draw ) DUPr STHr .Screen/color DEO
		( incr ) #0001 ++
		( incr ) .Screen/x DEI2 #0008 ++ .Screen/x DEO2
		DUP2 LDA #00 ! ,&loop JNZ
	POP2
	POPr

RTN

@fill-rect ( x1* y1* x2* y2* color -- )
	
	.color POK
	( x1 x2 y1 y2 ) ROT2 SWP2
	&ver
		( save ) OVR2 .Screen/y DEO2
		STH2 STH2 OVR2 OVR2
		&hor
			( save ) OVR2 .Screen/x DEO2
			( draw ) .color PEK .Screen/color DEO
			( incr ) SWP2 #0001 ++ SWP2
			OVR2 OVR2 LTS2 ,&hor JNZ
		POP2 POP2 STH2r STH2r
		( incr ) SWP2 #0001 ++ SWP2
		OVR2 OVR2 LTS2 ,&ver JNZ
	POP2 POP2 POP2 POP2

RTN

@pad-name [
	"PAD1 $1 "SYN1 $1 "SYN2 $1 "CYM1 $1 ( short )
	"HHAT $1 "OHAT $1 "CHAT $1 "RIDE $1
	"SID1 $1 "SNR1 $1 "SNR2 $1 "SID2 $1 ( long )
	"BDR1 $1 "KCK1 $1 "KCK2 $1 "SUB1 $1 ]

@pad-addr [
	6000 6400 6800 6c00
	7000 7800 8000 8800
	9000 9800 a000 a800
	b000 c000 d000 e000 $2 ]

@pad-pitch [
	30 30 30 30
	30 30 30 30
	30 30 30 30
	30 30 30 30 ]

@pad-path [
	"projects/sounds/pad1.pcm $1 "projects/sounds/syn1.pcm $1 "projects/sounds/syn2.pcm $1 "projects/sounds/pad2.pcm $1
	"projects/sounds/hhat.pcm $1 "projects/sounds/ohat.pcm $1 "projects/sounds/chat.pcm $1 "projects/sounds/ride.pcm $1
	"projects/sounds/sid1.pcm $1 "projects/sounds/snr1.pcm $1 "projects/sounds/snr2.pcm $1 "projects/sounds/sid2.pcm $1
	"projects/sounds/bdr1.pcm $1 "projects/sounds/kck1.pcm $1 "projects/sounds/kck2.pcm $1 "projects/sounds/sub1.pcm $1 ]

@notes [
	3c 3e 40 41 43 45 47
	48 4a 4c 4d 4f 51 53 ]

@cursor-icn [ 
	80c0 e0f0 f8e0 1000 ]

@keys-left-icns [
	7c7c 7c7c 7c7c 7c7c
	7c7c 7c7c 7c7c 7e7f
	7f7f 7f7f 7f7f 3e00 ]

@keys-middle-icns [
	1c1c 1c1c 1c1c 1c1c
	1c1c 1c1c 1c1c 3e7f
	7f7f 7f7f 7f7f 3e00 ]

@keys-right-icns [
	1f1f 1f1f 1f1f 1f1f
	1f1f 1f1f 1f1f 3f7f
	7f7f 7f7f 7f7f 3e00 ]

@arrow-icns [
	0010 387c fe10 1000
	0010 1010 fe7c 3810 ]

@switch-icns [
	001f 2040 4040 4040
	00f8 0402 0202 0202
	404f 5f5f 4f20 1f00
	02f2 fafa f204 f800
	001f 204f 5f5f 4f40
	00f8 04f2 fafa f202
	4040 4040 4020 1f00
	0202 0202 0204 f800 ]

@knob-icns [
	0003 0c10 2020 4040
	00c0 3008 0404 0202
	4040 2020 100c 0300
	0202 0404 0830 c000
	0000 183c 3c18 0000 ]

@knob-offsetx [
	01 00 00 00 00 01 02 03
	05 06 07 08 08 08 08 07 ]

@knob-offsety [
	07 06 05 03 02 01 00 00
	00 00 01 02 03 05 06 07 ]

@font-notes [
	003e 4140 4040 413e 40ae 4100 4040 413e
	007e 4141 4141 417e 40ae 4101 4141 417e
	003e 4140 7c40 413e 003f 4040 7e40 4040
	40af 4000 7e40 4040 003e 4140 5f41 413e
	40ae 4100 5f41 413e 003e 4141 7f41 4141
	40ae 4101 7f41 4141 007e 4141 7e41 417e
]

@font-hex ( 0-F )
[
	007c 8282 8282 827c 0030 1010 1010 1010
	007c 8202 7c80 80fe 007c 8202 1c02 827c
	000c 1424 4484 fe04 00fe 8080 7c02 827c
	007c 8280 fc82 827c 007c 8202 1e02 0202
	007c 8282 7c82 827c 007c 8282 7e02 827c
	007c 8202 7e82 827e 00fc 8282 fc82 82fc
	007c 8280 8080 827c 00fc 8282 8282 82fc
	007c 8280 f080 827c 007c 8280 f080 8080
]

@font-num-uc [
	003e 4141 4141 413e 0018 0808 0808 081c 
	003e 4101 3e40 407f 003e 4101 1f01 413e 
	0011 2141 7f01 0101 007f 4040 7e01 413e 
	003e 4140 7e41 413e 003e 4101 0102 0408 
	003e 4141 3e41 413e 003e 4141 3f01 0102 
	0000 0800 0000 0800 0000 0800 0000 0800 
	0000 0800 0000 0810 0000 0408 1008 0400 
	0000 001c 001c 0000 0000 1008 0408 1000 
	0000 0000 0000 0000 003e 4101 3f41 413f 
	007e 4141 7e41 417e 003e 4140 4040 413e 
	007e 4141 4141 417e 007f 4040 7e40 407f 
	007f 4040 7e40 4040 003e 4140 5e41 413e 
	0041 4141 7f41 4141 0008 0808 0808 0808 
	007f 0101 0101 413e 0041 4244 7844 4241 
	0040 4040 4040 403f 0076 4949 4949 4949 
	005e 6141 4141 4141 003e 4141 4141 413e 
	007e 4141 7e40 4040 003e 4141 4145 423d 
	007e 4141 7e41 4141 003e 4140 3e01 413e 
	007f 0808 0808 0808 0041 4141 4141 433d 
	0041 4141 4122 1408 0049 4949 4949 4976 
	0041 2214 0814 2241 0041 4141 3f01 413e 
	007f 0101 3e40 407f ]