~rabbits/uxn

ref: 993719818a23eaec680548e1e546727ff224c3c2 uxn/projects/software/enfer.usm -rw-r--r-- 12.5 KiB
99371981neauoire Removed LTS/GTS opcodes 4 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
( enfer )

%RTN { JMP2r }
%8+ { #0008 ADD2 }
%8/ { #0008 DIV2 }
%2/ { #0002 DIV2 }
%2* { #0002 MUL2 }
%++ { #0001 ADD2 }
%TOS { #00 SWP }
%MOD { DUP2 DIV MUL SUB }
%LTS2  { #8000 ADD2 SWP2 #8000 ADD2 GTH2 }
%GTS2  { #8000 ADD2 SWP2 #8000 ADD2 LTH2 }

%VIEW-WIDTH { #0110 }
%VIEW-HEIGHT { #0038 }
%PRINT-BYTE { .Console/byte DEO #0d .Console/char DEO }
%PRINT-SHORT { .Console/short DEO2 #0d .Console/char DEO }

( 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 ]
|b0 @DateTime   [ &year   $2 &month    $1 &day    $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]

( variables )

|0000

@addr $2
@color $1
@center      [ &x $2 &y $2 ]
@pointer     [ &x $2 &y $2 ]
@rect        [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@knob        [ &x $2 &y $2 &value $1 ]

@ch0-view    [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &device $1 ]
@ch1-view    [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &device $1 ]
@ch2-view    [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &device $1 ]
@ch3-view    [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &device $1 ]

( program )

|0100 ( -> )

	( theme ) 
	#20fe .System/r DEO2 
	#c0f3 .System/g DEO2 
	#a0f2 .System/b DEO2

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

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

	( place views )
	.center/x PEK2 VIEW-WIDTH 2/ SUB2 .ch0-view/x1 POK2
	.center/y PEK2 VIEW-HEIGHT 2* SUB2 .ch0-view/y1 POK2
	.ch0-view/x1 PEK2 VIEW-WIDTH ADD2 .ch0-view/x2 POK2
	.ch0-view/y1 PEK2 VIEW-HEIGHT ADD2 .ch0-view/y2 POK2

	.ch0-view/x1 PEK2 .ch1-view/x1 POK2
	.ch0-view/y1 PEK2 VIEW-HEIGHT ADD2 .ch1-view/y1 POK2
	.ch0-view/x2 PEK2 .ch1-view/x2 POK2
	.ch0-view/y2 PEK2 VIEW-HEIGHT ADD2 .ch1-view/y2 POK2

	.ch1-view/x1 PEK2 .ch2-view/x1 POK2
	.ch1-view/y1 PEK2 VIEW-HEIGHT ADD2 .ch2-view/y1 POK2
	.ch1-view/x2 PEK2 .ch2-view/x2 POK2
	.ch1-view/y2 PEK2 VIEW-HEIGHT ADD2 .ch2-view/y2 POK2

	.ch2-view/x1 PEK2 .ch3-view/x1 POK2
	.ch2-view/y1 PEK2 VIEW-HEIGHT ADD2 .ch3-view/y1 POK2
	.ch2-view/x2 PEK2 .ch3-view/x2 POK2
	.ch2-view/y2 PEK2 VIEW-HEIGHT ADD2 .ch3-view/y2 POK2

	.Audio0 .ch0-view/device POK
	.Audio1 .ch1-view/device POK
	.Audio2 .ch2-view/device POK
	.Audio3 .ch3-view/device POK

	#88 .Audio0/volume DEO
	#88 .Audio1/volume DEO
	#88 .Audio2/volume DEO
	#88 .Audio3/volume DEO

	( defaults )
	;wave0 .Audio0/addr DEO2
	;wave1 .Audio1/addr DEO2
	;wave2 .Audio2/addr DEO2
	;wave3 .Audio3/addr DEO2

	#00a8 .Audio0/length DEO2
	#00a8 .Audio1/length DEO2
	#00a8 .Audio2/length DEO2
	#00a8 .Audio3/length DEO2

	#012c .Audio0/adsr DEO2
	#012c .Audio1/adsr DEO2
	#0113 .Audio2/adsr DEO2
	#112c .Audio3/adsr DEO2

	;redraw JSR2

BRK

@on-frame ( -> )
	
	.ch0-view ;draw-meter JSR2
	.ch1-view ;draw-meter JSR2
	.ch2-view ;draw-meter JSR2
	.ch3-view ;draw-meter JSR2

BRK

@on-midi ( -> )
		
	.Midi/note DEI #00 NEQ ,&note-on JNZ BRK &note-on
	.Midi/note DEI .Audio0/pitch .Midi/channel DEI #04 MOD #10 MUL ADD DEO

BRK

@on-mouse ( -> )

	;draw-cursor JSR2 

	.Mouse/state DEI #00 NEQ ,&on-touch JNZ BRK &on-touch

	( get channel id )
	.Mouse/y DEI2 .ch0-view/y1 PEK2 SUB2 VIEW-HEIGHT DIV2 SWP POP
	#10 MUL 
	.Audio0/pitch ADD
	#3c SWP DEO

	( release ) #00 .Mouse/state DEO

BRK

@redraw ( -- )
	
	.ch0-view ;draw-view JSR2
	.ch1-view ;draw-view JSR2
	.ch2-view ;draw-view JSR2
	.ch3-view ;draw-view JSR2

RTN

@draw-meter ( view* -- )
		
	STH
	( y1 ) DUPr STHr #02 ADD PEK2 .Screen/y DEO2

	( x1 ) DUPr STHr PEK2
		 #0010 ADD2 .Screen/x DEO2
	( device ) DUPr STHr #08 ADD PEK ( get addr ) #02 ADD DEI #04 SFT TOS #0008 MUL2 ;meter ADD2 .Screen/addr DEO2
		#21 .Screen/color DEO
	( x1 ) DUPr STHr PEK2
		 #0018 ADD2 .Screen/x DEO2
	( device ) DUPr STHr #08 ADD PEK ( get addr ) #02 ADD DEI #04 AND TOS #0008 MUL2 ;meter ADD2 .Screen/addr DEO2
		#21 .Screen/color DEO

	POPr

RTN

@draw-view ( view* -- )

	STH

	( device id )
	( x1 ) DUPr STHr PEK2 .Screen/x DEO2
	( y1 ) DUPr STHr #02 ADD PEK2 .Screen/y DEO2
	( device ) DUPr STHr #08 ADD PEK #23 ;draw-byte JSR2

	( x1 ) DUPr STHr PEK2 #0028 ADD2 .Screen/x DEO2
	;repeat .Screen/addr DEO2
	#23 .Screen/color DEO

	( addr )
	( addr controls )
	( x1 ) DUPr STHr PEK2 #0060 ADD2 .Screen/x DEO2
	( device ) DUPr STHr #08 ADD PEK ( get addr ) #0c ADD DEI #21 ;draw-byte JSR2
	( x1 ) .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
	( device ) DUPr STHr #08 ADD PEK ( get addr ) #0d ADD DEI #21 ;draw-byte JSR2

	( waveform )
	( volume knob )
	( x1 ) DUPr STHr PEK2
	( y1 ) DUPr STHr #02 ADD PEK2 #0010 ADD2
	( device ) DUPr STHr #08 ADD PEK ( get length ) #0e ADD DEI #04 SFT
	;draw-knob JSR2

	( adsr knobs )
	( x1 ) DUPr STHr PEK2 #0018 ADD2 
	( y1 ) DUPr STHr #02 ADD PEK2 #0010 ADD2
	( device ) DUPr STHr #08 ADD PEK ( get length ) #08 ADD DEI #04 SFT
	;draw-knob JSR2
	( x1 ) DUPr STHr PEK2 #0028 ADD2 
	( y1 ) DUPr STHr #02 ADD PEK2 #0010 ADD2
	( device ) DUPr STHr #08 ADD PEK ( get length ) #08 ADD DEI #0f AND
	;draw-knob JSR2
	( x1 ) DUPr STHr PEK2 #0038 ADD2 
	( y1 ) DUPr STHr #02 ADD PEK2 #0010 ADD2
	( device ) DUPr STHr #08 ADD PEK ( get length ) #09 ADD DEI #04 SFT
	;draw-knob JSR2
	( x1 ) DUPr STHr PEK2 #0048 ADD2 
	( y1 ) DUPr STHr #02 ADD PEK2 #0010 ADD2
	( device ) DUPr STHr #08 ADD PEK ( get length ) #09 ADD DEI #0f AND
	;draw-knob JSR2

	( meter )
	( test button )

	( outline )
	( x1 ) DUPr STHr PEK2 #0006 SUB2
	( y1 ) DUPr STHr #02 ADD PEK2 #0006 SUB2
	( x2 ) DUPr STHr #04 ADD PEK2
	( y2 ) DUPr STHr #06 ADD PEK2 #000a SUB2
	#02 ;line-rect JSR2

	( x1 ) DUPr STHr PEK2 #0060 ADD2 .Screen/x DEO2

	( waveform )
	#00 #a8
	&loop
		( dotted line )
		OVR #01 AND ,&no-dot JNZ 
			( y1 ) DUPr STHr #02 ADD PEK2 [ ] #0018 ADD2 .Screen/y DEO2
			#03 .Screen/color DEO
		&no-dot
		OVR TOS ( device ) DUPr STHr #08 ADD PEK ( get addr ) #0c ADD DEI2 ADD2 GET 
		#02 DIV #40 ADD DUP #07 SFT #80 MUL SUB 
		TOS #0004 DIV2 ( y1 ) DUPr STHr #02 ADD PEK2 [ ] ADD2 #0008 ADD2 .Screen/y DEO2
		.Screen/x DEI2 ++ .Screen/x DEO2
		( draw ) #01 .Screen/color DEO
		( incr ) SWP #01 ADD SWP
		DUP2 LTH ,&loop JNZ
	POP2
	( loop button )
	POPr

RTN

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

	( load ) .knob/value POK .knob/y POK2 .knob/x POK2

	.knob/x PEK2 .Screen/x DEO2
	.knob/y PEK2 .Screen/y DEO2 ;knob_icns .Screen/addr DEO2 #21 .Screen/color DEO
	.knob/x PEK2 8+ .Screen/x DEO2 ;knob_icns 8+ .Screen/addr DEO2 #21 .Screen/color DEO
	.knob/y PEK2 8+ .Screen/y DEO2 ;knob_icns #0018 ADD2 .Screen/addr DEO2 #21 .Screen/color DEO
	.knob/x PEK2 .Screen/x DEO2 ;knob_icns #0010 ADD2 .Screen/addr DEO2 #21 .Screen/color DEO
	.knob/x PEK2 #00 #00 .knob/value PEK ;knob-offsetx ADD2 GET ADD2 .Screen/x DEO2
	.knob/y PEK2 #00 #00 .knob/value PEK ;knob-offsety ADD2 GET ADD2 .Screen/y DEO2
	;knob_icns #0020 ADD2 .Screen/addr DEO2
	#25 .Screen/color DEO
	.knob/x PEK2 #0004 ADD2 .Screen/x DEO2
	.knob/y PEK2 #0010 ADD2 .Screen/y DEO2
	;font-hex #00 .knob/value PEK #08 MUL ADD2 .Screen/addr DEO2
	#21 .Screen/color DEO

RTN

@draw-cursor ( -- )
	
	( clear last cursor )
	;clear .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 )
	;cursor .Screen/addr DEO2 
	.pointer/x PEK2 .Screen/x DEO2 
	.pointer/y PEK2 .Screen/y DEO2 
	( colorize on state )
	#31 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/color DEO

RTN

@draw-short ( short color -- )

	.color POK
	.addr POK2
	;font-hex #00 ;addr GET #f0 AND #04 SFT #08 MUL ADD2 .Screen/addr DEO2
	( draw ) DUPr STHr .Screen/color DEO
	.Screen/x DEI2 8+ .Screen/x DEO2
	;font-hex #00 ;addr GET #0f AND #08 MUL ADD2 .Screen/addr DEO2
	( draw ) DUPr STHr .Screen/color DEO
	.Screen/x DEI2 8+ .Screen/x DEO2
	;font-hex #00 ;addr ++ GET #f0 AND #04 SFT #08 MUL ADD2 .Screen/addr DEO2
	( draw ) DUPr STHr .Screen/color DEO
	.Screen/x DEI2 8+ .Screen/x DEO2
	;font-hex STHr ;addr ++ GET #0f AND #08 MUL ADD2 .Screen/addr DEO2
	( draw ) #22 .Screen/color DEO

RTN

@draw-byte ( byte color -- )
	
	.color POK STH
	;font-hex #00 DUPr STHr #f0 AND #04 SFT #08 MUL ADD2 .Screen/addr DEO2
	( draw ) .color PEK .Screen/color DEO
	.Screen/x DEI2 8+ .Screen/x DEO2
	;font-hex #00 STHr #0f AND #08 MUL ADD2 .Screen/addr DEO2
	( draw ) .color PEK .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 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 ++ SWP2
		OVR2 OVR2 LTS2 ,&ver JNZ
	POP2 POP2
	.rect/x1 PEK2 .rect/x2 PEK2
	&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 ++ SWP2
		OVR2 OVR2 ++ LTS2 ,&hor JNZ
	POP2 POP2

RTN

@repeat [
	0038 4482 9282 4438 ]

@clear  [ 
	0000 0000 0000 0000 ]

@cursor [ 
	80c0 e0f0 f8e0 1000 ]

@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 ]

@meter [
	0000 0000 0000 0000
	0000 0000 0000 0070 
	0000 0000 0000 007e
	0000 0000 0000 707e
	0000 0000 0070 7e7e
	0000 0000 007e 7e7e
	0000 0000 707e 7e7e
	0000 0000 7e7e 7e7e
	0000 0070 7e7e 7e7e
	0000 007e 7e7e 7e7e
	0000 707e 7e7e 7e7e
	0000 7e7e 7e7e 7e7e
	0070 7e7e 7e7e 7e7e
	007e 7e7e 7e7e 7e7e
	707e 7e7e 7e7e 7e7e
	7e7e 7e7e 7e7e 7e7e ]

@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 ]

@wave0 ( 0-F )
[
	0004 090e 1217 1c20 2529 2e32 363b 3f43 
	474b 4e52 5659 5c60 6365 686b 6d70 7274 
	7677 797a 7b7c 7d7e 7e7e 7e7e 7e7e 7d7c
	7b7a 7978 7674 7270 6e6b 6966 6360 5d5a 
	5753 4f4c 4844 403c 3833 2f2a 2621 1d18 
	140f 0a05 01fc f7f2 eee9 e4e0 dbd7 d2ce
	cac5 c1bd b9b5 b1ae aaa7 a3a0 9d9a 9795 
	9290 8e8c 8a88 8785 8483 8282 8181 8181 
	8181 8282 8384 8687 898a 8c8e 9193 9598
	9b9e a1a4 a8ab afb2 b6ba bec2 c6cb cfd3 
	d8dc e1e6 eaef f4f8 ]

@wave1 ( 0-F )
[
	0002 0406 080a 0c0e 1012 1416 181a 1c1e 
	2022 2426 282a 2c2e 3032 3436 383a 3c3e 
	4041 4345 4749 4b4d 4f51 5355 5759 5b5d
	5f61 6365 6769 6b6d 6f71 7375 7779 7b7d 
	7f7d 7b79 7775 7371 6f6d 6b69 6765 6361 
	5f5d 5b59 5755 5351 4f4d 4b49 4745 4341
	403e 3c3a 3836 3432 302e 2c2a 2826 2422 
	201e 1c1a 1816 1412 100e 0c0a 0806 0402 
	00fe fcfa f8f6 f4f2 f0ee ecea e8e6 e4e2
	e0de dcda d8d6 d4d2 d0ce ccca c8c6 c4c2 
	c1bf bdbb b9b7 b5b3 ]

@wave2 ( 0-F )
[
	4f4d 4b49 4745 4341 c1bf bdbb b9b7 b5b3
	403e 3c3a 3836 3432 302e 2c2a 2826 2422 
	201e 1c1a 1816 1412 100e 0c0a 0806 0402 
	00fe fcfa f8f6 f4f2 f0ee ecea e8e6 e4e2
	e0de dcda d8d6 d4d2 d0ce ccca c8c6 c4c2 
	7b7a 7978 7674 7270 6e6b 6966 6360 5d5a 
	5753 4f4c 4844 403c 3833 2f2a 2621 1d18 
	140f 0a05 01fc f7f2 eee9 e4e0 dbd7 d2ce
	cac5 c1bd b9b5 b1ae aaa7 a3a0 9d9a 9795 
	9290 8e8c 8a88 8785 8483 8282 8181 8181 
	8181 8282 8384 8687 898a 8c8e 9193 9598
	9b9e a1a4 a8ab afb2 
	 ]

@wave3 ( 0-F )
[
	0004 090e 1217 1c20 2529 2e32 363b 3f43 
	5753 4f4c 4844 403c 3833 2f2a 2621 1d18 
	140f 0a05 01fc f7f2 eee9 e4e0 dbd7 d2ce
	cac5 c1bd b9b5 b1ae aaa7 a3a0 9d9a 9795 
	5753 4f4c 4844 403c 3833 2f2a 2621 1d18 
	140f 0a05 01fc f7f2 eee9 e4e0 dbd7 d2ce
	cac5 c1bd b9b5 b1ae aaa7 a3a0 9d9a 9795 
	9290 8e8c 8a88 8785 8483 8282 8181 8181 
	8181 8282 8384 8687 898a 8c8e 9193 9598
	9b9e a1a4 a8ab afb2 b6ba bec2 c6cb cfd3 
	d8dc e1e6 eaef f4f8 ]