~rabbits/marabu

marabu/src/main.tal -rw-r--r-- 17.0 KiB
17cdb114neauoire Change speed with d-pad 1 year, 3 months 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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
( marabu )

~src/utils.tal

%WIDTH { #0120 }
%HEIGHT { #0100 }

( devices )

|00 @System     [ &vector $2 &pad     $6 &r      $2 &g     $2 &b     $2 ]
|10 @Console    [ &vector $2 &read    $1 &pad    $5 &write $1 ]
|20 @Screen     [ &vector $2 &width   $2 &height $2 &auto $1 &pad   $1 &x     $2 &y $2 &addr $2 &pixel $1 &sprite $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 ]
|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
	@focus
		&x $1 &y $1
	@frame
		&x $2 &y $2
	@cursor
		&x $2 &y $2 &last $1
	@sequencer
		&x $2 &y $2 &x2 $2 &y2 $2
		&length $1
		&position-hb $1
		&position-lb $1
		&frame $1
		&speed $1
		&play $1
	@tracker
		&x $2 &y $2 &x2 $2 &y2 $2
	@midi
		&active $1 &offset $1

( program )

|0100 ( -> )

	( theme )
	#0f75 .System/r DEO2
	#0fe5 .System/g DEO2
	#0fc5 .System/b DEO2

	;on-button   .Controller/vector DEO2
	;on-frame    .Screen/vector DEO2
	;on-mouse    .Mouse/vector DEO2

	( size )
	WIDTH #0030 ++ .Screen/width DEO2
	HEIGHT #0040 ++ .Screen/height DEO2

	( setup synth )
	#0204 ;sample #1c57 #dd #00 ;set-instrument JSR2
	#0217 ;sample #1c57 #dd #01 ;set-instrument JSR2
	#0277 ;sample #1c57 #ad #02 ;set-instrument JSR2
	#0277 ;sample #1c57 #da #03 ;set-instrument JSR2

	( place frame )
	.Screen/width DEI2 
		2// WIDTH 2// -- #0010 ++ .frame/x STZ2
	.Screen/height DEI2 
		2// HEIGHT 2// -- #0008 ++ .frame/y STZ2

	( place sequencer view )
	.frame/x LDZ2 
		DUP2 .sequencer/x STZ2 
		#0058 ++ .sequencer/x2 STZ2
	.frame/y LDZ2 
		DUP2 .sequencer/y STZ2 
		HEIGHT ++ #0001 -- .sequencer/y2 STZ2

	( place pattern view )
	.frame/x LDZ2 
		#0070 ++ DUP2 .tracker/x STZ2 
		#0098 ++ .tracker/x2 STZ2
	.frame/y LDZ2 
		DUP2 .tracker/y STZ2 
		HEIGHT ++ #0001 -- .tracker/y2 STZ2

	( defaults )
	#01 .sequencer/length STZ
	#04 .sequencer/speed STZ

	#01 #00 #00 ;set-pattern JSR2
	#02 #00 #01 ;set-pattern JSR2
	#03 #00 #02 ;set-pattern JSR2
	#04 #00 #03 ;set-pattern JSR2

	( theme support )
	;load-theme JSR2

BRK

@on-frame ( -> )

	;draw-meters JSR2

	.sequencer/play LDZ ,&play JCN
		BRK
		&play

	.sequencer/frame LDZk INC SWP STZ

	.sequencer/frame LDZ .sequencer/speed LDZ = ,&continue JCN
		BRK
		&continue

	;run JSR2

BRK

@on-mouse ( -> )

	( clear last cursor )
	.cursor/x LDZ2 .Screen/x DEO2
	.cursor/y LDZ2 .Screen/y DEO2
	#40 .Screen/sprite DEO

	( draw new cursor )
	.Mouse/x DEI2 DUP2 .cursor/x STZ2 .Screen/x DEO2
	.Mouse/y DEI2 DUP2 .cursor/y STZ2 .Screen/y DEO2
	;cursor-icn .Screen/addr DEO2
	#41 [ .Mouse/state DEI #00 ! 2* ] + .Screen/sprite DEO

	.Mouse/x DEI2 .Mouse/y DEI2 .sequencer ;within-rect JSR2
		;on-mouse-sequencer JCN2
	.Mouse/x DEI2 .Mouse/y DEI2 .tracker ;within-rect JSR2
		;on-mouse-tracker JCN2

	( release-record ) #0000 .Mouse/state DEO .cursor/last STZ

BRK

@on-mouse-sequencer ( -> )

	.Mouse/state DEI #01 JCN BRK

	.Mouse/y DEI2 .sequencer/y LDZ2 -- 10// NIP 10* .focus/y STZ
	.Mouse/x DEI2 .sequencer/x LDZ2 -- NIP #18 / .focus/x STZ
	;redraw JSR2

BRK

@on-mouse-tracker ( -> )

	.Mouse/state DEI #01 JCN BRK

	.Mouse/y DEI2 .tracker/y LDZ2 -- 10// NIP .focus/y LDZ #44 SFT + .focus/y STZ
	.Mouse/x DEI2 .tracker/x LDZ2 -- NIP #28 / .focus/x STZ
	;redraw JSR2

BRK

@on-button ( -> )

	.Controller/button DEI
	DUP #10 ! ,&no-du JCN .focus/y LDZk #01 - SWP STZ &no-du
	DUP #20 ! ,&no-dd JCN .focus/y LDZk #01 + SWP STZ &no-dd
	DUP #40 ! ,&no-dl JCN .focus/x LDZk #01 - #03 AND SWP STZ &no-dl
	DUP #80 ! ,&no-dr JCN .focus/x LDZk #01 + #03 AND SWP STZ &no-dr
	( ctrl )
	DUP #11 ! ,&no-cU JCN #0c ;mod-note JSR2 &no-cU
	DUP #21 ! ,&no-cD JCN #f4 ;mod-note JSR2 &no-cD
	DUP #41 ! ,&no-cL JCN #ff ;mod-note JSR2 &no-cL
	DUP #81 ! ,&no-cR JCN #01 ;mod-note JSR2 &no-cR
	( alt )
	DUP #12 ! ,&no-aU JCN #10 ;mod-auto JSR2 &no-aU
	DUP #22 ! ,&no-aD JCN #f0 ;mod-auto JSR2 &no-aD
	DUP #42 ! ,&no-aL JCN #ff ;mod-auto JSR2 &no-aL
	DUP #82 ! ,&no-aR JCN #01 ;mod-auto JSR2 &no-aR
	( shift )
	DUP #14 ! ,&no-sU JCN #10 ;mod-pattern JSR2 &no-sU
	DUP #24 ! ,&no-sD JCN #f0 ;mod-pattern JSR2 &no-sD
	DUP #44 ! ,&no-sL JCN #ff ;mod-pattern JSR2 &no-sL
	DUP #84 ! ,&no-sR JCN #01 ;mod-pattern JSR2 &no-sR
	( sequencer )
	DUP #18 ! ,&no-eu JCN .sequencer/length LDZk DEC [ DUP #00 = + ] SWP STZ &no-eu
	DUP #28 ! ,&no-ed JCN .sequencer/length LDZk INC [ DUP #00 = + ] SWP STZ &no-ed
	DUP #48 ! ,&no-el JCN .sequencer/speed LDZk DEC [ DUP #00 = + ] SWP STZ &no-el
	DUP #88 ! ,&no-er JCN .sequencer/speed LDZk INC [ DUP #00 = + ] SWP STZ &no-er
	( generics )
	DUP #08 ! ,&no-play-toggle JCN .sequencer/play TOGGLE &no-play-toggle
	DUP #09 ! ,&no-midi-toggle JCN .midi/active TOGGLE &no-midi-toggle
	DUP #43 ! ,&no-midi-minus JCN .midi/offset LDZk #01 - SWP STZ &no-midi-minus
	DUP #83 ! ,&no-midi-plus JCN .midi/offset LDZk #01 + SWP STZ &no-midi-plus
	POP

	.Controller/key DEI
	DUP LIT 'a ! ,&no-a JCN #30 ;insert-note JSR2 &no-a
	DUP LIT 'w ! ,&no-w JCN #31 ;insert-note JSR2 &no-w
	DUP LIT 's ! ,&no-s JCN #32 ;insert-note JSR2 &no-s
	DUP LIT 'e ! ,&no-e JCN #33 ;insert-note JSR2 &no-e
	DUP LIT 'd ! ,&no-d JCN #34 ;insert-note JSR2 &no-d
	DUP LIT 'f ! ,&no-f JCN #35 ;insert-note JSR2 &no-f
	DUP LIT 't ! ,&no-t JCN #36 ;insert-note JSR2 &no-t
	DUP LIT 'g ! ,&no-g JCN #37 ;insert-note JSR2 &no-g
	DUP LIT 'y ! ,&no-y JCN #38 ;insert-note JSR2 &no-y
	DUP LIT 'h ! ,&no-h JCN #39 ;insert-note JSR2 &no-h
	DUP LIT 'u ! ,&no-u JCN #3a ;insert-note JSR2 &no-u
	DUP LIT 'j ! ,&no-j JCN #3b ;insert-note JSR2 &no-j
	DUP #08 ! ,&no-backspace JCN #00 ;insert-note JSR2 &no-backspace
	POP

	;redraw JSR2

BRK

( helpers )

@mod-pattern ( mod -- )

	STH
	.focus/y LDZ #04 SFT .focus/x LDZ 
		DUP2 ,get-pattern JSR STHr +
		ROT ROT ,set-pattern JSR
	;redraw JSR2

RTN

@set-pattern ( pattern pos ch -- )

	SWP 4* + TOS ;song ++ STA

RTN

@get-pattern ( pos ch -- pattern )

	SWP 4* + TOS ;song ++ LDA

RTN

@insert-note ( note -- )

	STH
	.focus/y LDZ #04 SFT .focus/x LDZ ;get-pattern JSR2
	.focus/y LDZ #0f AND SWP 
		STHr
		ROT ROT ,set-note JSR

RTN

@mod-note ( mod -- )

	STH
	.focus/y LDZ #04 SFT .focus/x LDZ ;get-pattern JSR2
	.focus/y LDZ #0f AND SWP 
		DUP2 ,get-note JSR STHr +
		ROT ROT ,set-note JSR
	;redraw JSR2

RTN

@set-note ( note pos pattern -- )

	TOS 20** ROT TOS 2** ++ ;song/patterns ++ STA

RTN

@get-note ( pos pattern -- note )

	TOS 20** ROT TOS 2** ++ ;song/patterns ++ STH2k LDA

	DUP ,&has-value JCN
		POP2r RTN
		&has-value
	INC2r
	( load mod )
	STH2kr LDA #0f AND ,&has-mod JCN
		POP2r RTN
		&has-mod
	STH2kr LDA #f0 AND ,&has-rate JCN
		POP2r RTN
		&has-rate
	.sequencer/position-lb LDZ #04 SFT 
	STH2kr LDA #04 SFT MOD #00 ! ,&no-hit JCN
		STH2r LDA #0f AND + RTN
		&no-hit
	POP2r

RTN

@mod-auto ( mod -- )

	STH
	.focus/y LDZ #04 SFT .focus/x LDZ ;get-pattern JSR2
	.focus/y LDZ #0f AND SWP 
		DUP2 ,get-auto JSR STHr +
		ROT ROT ,set-auto JSR
	;redraw JSR2

RTN

@set-auto ( auto pos pattern -- )

	TOS 20** ROT TOS 2** ++ ;song/patterns ++ INC2 STA

RTN

@get-auto ( pos pattern -- auto )

	TOS 20** ROT TOS 2** ++ ;song/patterns ++ INC2 LDA

RTN

@set-instrument ( adsr* addr* length* volume ch -- )

	10* STH
	.Audio0/volume STHkr + DEO
	.Audio0/length STHkr + DEO2
	.Audio0/addr STHkr + DEO2
	.Audio0/adsr STHr + DEO2

RTN

@run ( -- )
	
	#00 .sequencer/frame STZ

	.sequencer/position-hb LDZ2k INC2 ROT STZ2

	;redraw JSR2

	( play )
	.sequencer/position-lb LDZ .sequencer/length LDZ 10* MOD DUP #0f AND SWP 10/
		DUP2 #00 ;get-pattern JSR2 ;get-note JSR2 #00 ,play-note JSR
		DUP2 #01 ;get-pattern JSR2 ;get-note JSR2 #01 ,play-note JSR
		DUP2 #02 ;get-pattern JSR2 ;get-note JSR2 #02 ,play-note JSR
		#03 ;get-pattern JSR2 ;get-note JSR2 #03 ,play-note JSR

RTN

@play-note ( pitch ch -- )

	( skip null ) OVR ,&continue JCN POP2 RTN &continue

	.midi/active LDZ ,play-midi JCN
	,play-synth JMP

RTN

@play-midi ( pitch ch -- )

	.midi/offset LDZ + STH2 
	( note on )
	STHkr .Console/write DEO
	OVRr STHr .Console/write DEO
	#7f .Console/write DEO
	( note off )
	STHr .Console/write DEO
	STHr .Console/write DEO
	#00 .Console/write DEO

RTN

@play-synth ( -- )

	STH #80 + .Audio0/pitch STHr 10* + DEO

RTN

@redraw ( -- )

	AUTO-Y-ADDR
	#0400
	&loop
		DUP ;draw-sequencer-channel JSR2
		DUP ;draw-tracker-channel JSR2
		INC GTHk ,&loop JCN
	POP2
	;draw-menu JSR2

	( sequencer timeline )
	.sequencer/x LDZ2 #0010 -- .Screen/x DEO2
	.sequencer/y LDZ2 .Screen/y DEO2
	.sequencer/position-lb LDZ #04 SFT .sequencer/length LDZ MOD ;draw-timeline JSR2

	( tracker timeline )
	.tracker/x LDZ2 #0010 -- .Screen/x DEO2
	.tracker/y LDZ2 .Screen/y DEO2
	.sequencer/position-lb LDZ #0f AND .focus/y LDZ #04 SFT .sequencer/position-lb LDZ #04 SFT .sequencer/length LDZ MOD ! #10 * + ;draw-timeline JSR2

	AUTO-NONE

RTN

@draw-menu ( -- )

	.frame/y LDZ2 #0010 -- .Screen/y DEO2

	( draw length over sequencer )
	.frame/x LDZ2 .Screen/x DEO2
	.focus/y LDZ 10/ #40 SFT .sequencer/length LDZ + #02 ;draw-byte JSR2
	.Screen/x DEI2k #0008 ++ ROT DEO2
	.sequencer/speed LDZ #03 ;draw-byte JSR2
	.Screen/x DEI2k #0008 ++ ROT DEO2
	.sequencer/position-hb LDZ #03 ;draw-byte JSR2
	.Screen/x DEI2k #0008 ++ ROT DEO2
	.sequencer/position-lb LDZ #03 ;draw-byte JSR2

	( draw patterns over pitchview )
	.frame/x LDZ2 #0070 ++ .Screen/x DEO2

	#0400
	&loop
		.focus/y LDZ #04 SFT OVR ;get-pattern JSR2 #03 .midi/active LDZ - ;draw-byte JSR2
		.Screen/x DEI2k #0018 ++ ROT DEO2
		INC GTHk ,&loop JCN
	POP2

RTN

( sequencer )

@draw-sequencer-channel ( id -- )

	STH
	#1000
	&loop
		( x ) STHkr TOS #0018 ** .sequencer/x LDZ2 ++ .Screen/x DEO2
		( y ) DUP TOS 10** .sequencer/y LDZ2 ++ .Screen/y DEO2
		( value ) DUP STHkr ;get-pattern JSR2 
		( color ) OVR STHkr ,get-sequencer-color JSR
			,draw-sequencer-byte JSR
		INC GTHk ,&loop JCN
	POP2
	POPr

RTN

@get-sequencer-color ( y ch -- color )

	SWP #40 SFT +
	DUP #04 SFT .focus/y LDZ 10/ ! ,&no-sight JCN
		DUP #0f AND .focus/x LDZ ! ,&unselected JCN
			POP #0e RTN 
			&unselected
		POP #02 RTN 
		&no-sight
	DUP #04 SFT .sequencer/position-lb LDZ #04 SFT .sequencer/length LDZ MOD ! ,&no-play JCN
	DUP #04 SFT OVR #0f AND ;get-pattern JSR2 #00 = ,&no-play JCN
		POP #04 RTN 
		&no-play
	DUP #04 SFT .sequencer/length LDZ < ,&active JCN
		POP #03 RTN 
		&active
	POP #01

RTN

@draw-sequencer-byte ( byte color -- )

	OVR #00 ! ,&no-null JCN
		STH
		LIT '- STHkr ;draw-char JSR2
		LIT '- STHr ;draw-char JSR2
		POP RTN
		&no-null
	;draw-byte JSR2

RTN

( tracker )

@draw-tracker-channel ( id -- )

	STH
	#1000
	&loop
		( x ) STHkr TOS #0028 ** .tracker/x LDZ2 ++ .Screen/x DEO2
		( y ) DUP TOS 10** .tracker/y LDZ2 ++ .Screen/y DEO2
		( pitch ) 
		DUP STHkr .focus/y LDZ #04 SFT SWP ;get-pattern JSR2 ;get-note JSR2
		OVR STHkr ,get-tracker-note-color JSR
			;draw-note-byte JSR2
		( auto )
		DUP STHkr .focus/y LDZ #04 SFT SWP ;get-pattern JSR2 ;get-auto JSR2
		OVR STHkr ,get-tracker-auto-color JSR
			;draw-auto-byte JSR2
		INC GTHk ,&loop JCN
	POP2
	POPr

RTN

@get-tracker-note-color ( note y ch -- note color )

	DUP .focus/x LDZ ! ,&no-selected JCN
	OVR .focus/y LDZ #0f AND ! ,&no-selected JCN
		POP2 #08 RTN 
		&no-selected
	STH2 DUP STH2r ROT #00 = ,&no-play JCN
	OVR .sequencer/position-lb LDZ #0f AND ! ,&no-play JCN
		POP2 #06 RTN 
		&no-play
	OVR #03 AND #00 ! ,&no-fourth JCN
		POP2 #02 RTN 
		&no-fourth
	POP2 #01

RTN

@get-tracker-auto-color ( auto y ch -- auto color )

	POP2
	DUP #0f AND ,&has-mod JCN
		#03 RTN 
		&has-mod
	DUP #f0 AND ,&has-rate JCN
		#0c RTN 
		&has-rate
	.sequencer/position-lb LDZ #04 SFT 
	OVR #04 SFT MOD #00 ! ,&no-hit JCN
		#04 RTN 
		&no-hit
	#01

RTN

@draw-note-byte ( byte color -- )

	OVR #00 ! ,&no-null JCN
		STH
		LIT '- STHkr ;draw-char JSR2
		LIT '- STHr ;draw-char JSR2
		POP
		RTN
		&no-null
	STH

	( octave ) DUP #0c / #30 + STHkr ;draw-char JSR2
	( note ) #0c MOD TOS ;octave ++ LDA STHr ;draw-char JSR2

RTN

@draw-auto-byte ( byte color -- )

	OVR #00 ! ,&no-null JCN
		STH
		LIT '- STHkr ;draw-char JSR2
		LIT '- STHr ;draw-char JSR2
		POP
		RTN
		&no-null
	;draw-byte JSR2

RTN

@draw-meters ( -- )

	#0400
	&loop
		STHk
		.frame/x LDZ2 #0088 ++ STHkr TOS #0028 ** ++ 
		.frame/y LDZ2 #0019 -- 
		.Audio0/output STHr #10 * + DEI
			,draw-meter JSR
		INC GTHk ,&loop JCN
	POP2

RTN

@draw-meter ( x* y* output -- )

	STH
	#0010 ++ .Screen/y DEO2
	.Screen/x DEO2
	;meter-icn .Screen/addr DEO2

	#1000
	&loop
		DUP STHkr #0f AND < #01 * .Screen/sprite DEO
		.Screen/x DEI2k #0004 -- ROT DEO2
		DUP STHkr #04 SFT < #01 * .Screen/sprite DEO
		.Screen/x DEI2k #0004 ++ ROT DEO2
		.Screen/y DEI2k #0001 -- ROT DEO2
		INC GTHk ,&loop JCN
	POP2
	POPr

RTN

@draw-timeline ( highlight -- )

	STH
	#1000
	&loop
		DUP STHkr = LIT '> SWP ,draw-char JSR
		.Screen/x DEI2k #0008 -- ROT DEO2
		.Screen/y DEI2k #0010 ++ ROT DEO2
		INC GTHk ,&loop JCN
	POP2
	POPr

RTN

@draw-short ( short* color -- )

	ROT OVR ,draw-byte JSR
	,draw-byte JSR

RTN

@draw-byte ( byte color -- )

	STH

	DUP #04 SFT ,&parse JSR STHkr ,draw-char JSR
		#0f AND ,&parse JSR STHr ,draw-char JSR
	RTN
	&parse ( value -- char )
		DUP #09 > ,&above JCN
			#30 + RTN
		&above
			#37 + RTN

RTN

@draw-char ( char color -- )

	SWP
	#20 - TOS 10** ;font ++ .Screen/addr DEO2
	.Screen/sprite DEOk DEO
	.Screen/y DEI2k #0010 -- ROT DEO2
	.Screen/x DEI2k #0008 ++ ROT DEO2

RTN

@print-hex ( value* -- )

	SWP ,&byte JSR
	&byte ( byte -- )
		STHk #04 SFT ,&parse JSR #18 DEO
		STHr #0f AND ,&parse JSR #18 DEO
	RTN
	&parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD RTN
	&above #57 ADD RTN

RTN

@within-rect ( x* y* rect -- flag )

	STH
	( y < rect.y1 ) DUP2 STHkr #02 + LDZ2 << ,&skip JCN
	( y > rect.y2 ) DUP2 STHkr #06 + LDZ2 >> ,&skip JCN
	SWP2
	( x < rect.x1 ) DUP2 STHkr LDZ2 << ,&skip JCN
	( x > rect.x2 ) DUP2 STHkr #04 + LDZ2 >> ,&skip JCN
	POP2 POP2 POPr
	#01
RTN
	&skip
	POP2 POP2 POPr
	#00

RTN

( theme )

@theme-txt ".theme $1

@load-theme ( -- )

	;theme-txt .File/name DEO2
	#0006 .File/length DEO2
	#fffa .File/load DEO2
	.File/success DEI2 #0006 !! ,&ignore JCN
		#fffa LDA2 .System/r DEO2
		#fffc LDA2 .System/g DEO2
		#fffe LDA2 .System/b DEO2
		&ignore
	;redraw JSR2

RTN

@octave 'C 'c 'D 'd 'E 'F 'f 'G 'g 'A 'a 'B

@meter-icn
	0000 0000 0000 000f
@cursor-icn
	80c0 e0f0 f8e0 1000

@sin-pcm
	8083 8689 8c8f 9295 989b 9ea1 a4a7 aaad
	b0b3 b6b9 bbbe c1c3 c6c9 cbce d0d2 d5d7
	d9db dee0 e2e4 e6e7 e9eb ecee f0f1 f2f4
	f5f6 f7f8 f9fa fbfb fcfd fdfe fefe fefe
	fffe fefe fefe fdfd fcfb fbfa f9f8 f7f6
	f5f4 f2f1 f0ee eceb e9e7 e6e4 e2e0 dedb
	d9d7 d5d2 d0ce cbc9 c6c3 c1be bbb9 b6b3
	b0ad aaa7 a4a1 9e9b 9895 928f 8c89 8683
	807d 7a77 7471 6e6b 6865 625f 5c59 5653
	504d 4a47 4542 3f3d 3a37 3532 302e 2b29
	2725 2220 1e1c 1a19 1715 1412 100f 0e0c
	0b0a 0908 0706 0505 0403 0302 0202 0202
	0102 0202 0202 0303 0405 0506 0708 090a
	0b0c 0e0f 1012 1415 1719 1a1c 1e20 2225
	2729 2b2e 3032 3537 3a3d 3f42 4547 4a4d
	5053 5659 5c5f 6265 686b 6e71 7477 7a7d

@tri-pcm
	8082 8486 888a 8c8e 9092 9496 989a 9c9e
	a0a2 a4a6 a8aa acae b0b2 b4b6 b8ba bcbe
	c0c2 c4c6 c8ca ccce d0d2 d4d6 d8da dcde
	e0e2 e4e6 e8ea ecee f0f2 f4f6 f8fa fcfe
	fffd fbf9 f7f5 f3f1 efed ebe9 e7e5 e3e1
	dfdd dbd9 d7d5 d3d1 cfcd cbc9 c7c5 c3c1
	bfbd bbb9 b7b5 b3b1 afad aba9 a7a5 a3a1
	9f9d 9b99 9795 9391 8f8d 8b89 8785 8381
	7f7d 7b79 7775 7371 6f6d 6b69 6765 6361
	5f5d 5b59 5755 5351 4f4d 4b49 4745 4341
	3f3d 3b39 3735 3331 2f2d 2b29 2725 2321
	1f1d 1b19 1715 1311 0f0d 0b09 0705 0301
	0103 0507 090b 0d0f 1113 1517 191b 1d1f
	2123 2527 292b 2d2f 3133 3537 393b 3d3f
	4143 4547 494b 4d4f 5153 5557 595b 5d5f
	6163 6567 696b 6d6f 7173 7577 797b 7d7f

@saw-pcm
	8282 8183 8384 8685 8888 8889 8a8b 8c8c
	8e8e 8f90 9092 9193 9494 9596 9699 9899
	9b9a 9c9c 9c9d 9ea0 a1a0 a2a2 a3a5 a4a6
	a7a7 a9a8 a9aa aaac adad aeae b0b0 b1b3
	b2b4 b5b5 b6b7 b9b8 b9bb babc bdbc bdbe
	bfc1 bfc1 c3c1 c4c5 c5c6 c6c7 c9c7 cbca
	cbcc cdcd cfcf d2d0 d2d2 d2d5 d4d5 d6d7
	d8d8 d9dc d9df dadf dce1 dde5 dce6 dceb
	cb1f 1b1e 1c21 1c21 1f23 2025 2127 2329
	2529 2829 2a2b 2b2e 2d2f 302f 3231 3234
	3334 3536 3836 3939 3a3b 3b3d 3e3d 3f40
	4042 4242 4444 4646 4748 474a 4a4b 4d4c
	4e4e 4f50 5052 5252 5554 5557 5759 5959
	5b5b 5c5d 5d5f 5e60 6160 6264 6365 6566
	6867 6969 6a6c 6c6d 6d6e 706f 7071 7174
	7475 7576 7777 797a 7a7c 7b7c 7e7d 7f7f

@sqr-pcm
	ffff ffff ffff ffff ffff ffff ffff ffff
	ffff ffff ffff ffff ffff ffff ffff ffff
	ffff ffff ffff ffff ffff ffff ffff ffff
	ffff ffff ffff ffff ffff ffff ffff ffff
	ffff ffff ffff ffff ffff ffff ffff ffff
	ffff ffff ffff ffff ffff ffff ffff ffff
	ffff ffff ffff ffff ffff ffff ffff ffff
	ffff ffff ffff ffff ffff ffff ffff ffff
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000


~src/pcm.tal
~src/font.tal

@song $40 &patterns