Browse code

Optimized Piano

neauoire authored on 09/08/2021 18:12:11
Showing 2 changed files
... ...
@@ -54,9 +54,9 @@ then
54 54
 fi
55 55
 
56 56
 echo "Assembling.."
57
-./bin/uxnasm projects/examples/demos/life.tal bin/life.rom
57
+./bin/uxnasm projects/examples/demos/piano.tal bin/piano.rom
58 58
 
59 59
 echo "Running.."
60
-./bin/uxnemu bin/life.rom
60
+./bin/uxnemu bin/piano.rom
61 61
 
62 62
 echo "Done."
... ...
@@ -10,14 +10,11 @@
10 10
 %MOD  { DUP2 / * - }
11 11
 %LTS2 { #8000 ++ SWP2 #8000 ++ >> }
12 12
 %GTS2 { #8000 ++ SWP2 #8000 ++ << }
13
-%INCR { SWP #01 + SWP }
14 13
 %2//  { #01 SFT2 }
15 14
 %4//  { #02 SFT2 }
16 15
 %8//  { #03 SFT2 }
17 16
 %8**  { #30 SFT2 }
18 17
 
19
-%BREAKPOINT { #0101 #0e DEO2 }
20
-
21 18
 ( devices )
22 19
 
23 20
 |00 @System     [ &vector $2 &pad      $6 &r      $2 &g     $2 &b      $2 ]
... ...
@@ -97,15 +94,14 @@ BRK
97 94
 	
98 95
 	.adsr-view/y2 LDZ2 #0020 -- .Screen/y DEO2
99 96
 
100
-	#00 #10
97
+	#10 #00 
101 98
 	&loop
102 99
 		.adsr-view/x2 LDZ2 #003a -- .Screen/x DEO2
103
-		OVR #10 SWP - .Audio0/output DEI #0f AND < .Screen/pixel DEO
100
+		DUP #10 SWP - .Audio0/output DEI #0f AND < .Screen/pixel DEO
104 101
 		.adsr-view/x2 LDZ2 #003a -- #0002 ++ .Screen/x DEO2
105
-		OVR #10 SWP - .Audio0/output DEI #04 SFT < .Screen/pixel DEO
102
+		DUP #10 SWP - .Audio0/output DEI #04 SFT < .Screen/pixel DEO
106 103
 		.Screen/y DEI2 #0002 ++ .Screen/y DEO2
107
-		( incr ) INCR
108
-		LTHk ,&loop JCN
104
+		#01 + GTHk ,&loop JCN
109 105
 	POP2
110 106
 
111 107
 BRK
... ...
@@ -134,9 +130,6 @@ BRK
134 130
 		#3b .octave LDZ #0c * + ;play JSR2 &no-b
135 131
 	DUP #6b ! ,&no-c2 JCN
136 132
 		#3c .octave LDZ #0c * + ;play JSR2 &no-c2
137
-	DUP #1b ! ,&no-esc JCN
138
-		BREAKPOINT
139
-		&no-esc
140 133
 	POP
141 134
 
142 135
 	( release )
... ...
@@ -302,13 +295,12 @@ RTN
302 295
 	STH
303 296
 	.Screen/addr DEO2 
304 297
 	SWP2 .Screen/x DEO2
305
-	DUP2 #0018 ++
298
+	DUP2 #0018 ++ SWP2
306 299
 	&loop
307
-		( move ) OVR2 .Screen/y DEO2
300
+		( move ) DUP2 .Screen/y DEO2
308 301
 		( draw ) STHkr .Screen/sprite DEO
309 302
 		( incr ) .Screen/addr DEI2 #0008 ++ .Screen/addr DEO2  
310
-		( incr ) SWP2 #0008 ++ SWP2
311
-		LTH2k ,&loop JCN
303
+		#0008 ++ GTH2k ,&loop JCN
312 304
 	POP2 POP2 
313 305
 	POPr
314 306
 
... ...
@@ -353,22 +345,21 @@ RTN
353 345
 	.wave-view/x1 LDZ2 .Screen/x DEO2
354 346
 
355 347
 	( waveform )
356
-	#00 #ff
348
+	#ff #00 
357 349
 	&loop
358 350
 		( dotted line )
359
-		OVR #01 AND ,&no-dot JCN 
351
+		DUP #01 AND ,&no-dot JCN 
360 352
 			.wave-view/y1 LDZ2 #0010 ++ .Screen/y DEO2
361 353
 			#03 .Screen/pixel DEO
362 354
 		&no-dot
363
-		OVR TOS .Audio0/addr DEI2 ++ LDA 
355
+		DUP TOS .Audio0/addr DEI2 ++ LDA 
364 356
 		#02 /
365 357
 		TOS 4// .wave-view/y1 LDZ2 ++ .Screen/y DEO2
366 358
 		.Screen/x DEI2 #0001 ++ .Screen/x DEO2
367
-		( draw ) OVR 
359
+		( draw ) DUP 
368 360
 			.Audio0/length DEI2 TOB > 
369 361
 			.Audio0/length DEI2 #0100 !! #0101 == #02 * #01 + .Screen/pixel DEO
370
-		( incr ) INCR
371
-		LTHk ,&loop JCN
362
+		#01 + GTHk ,&loop JCN
372 363
 	POP2
373 364
 
374 365
 	( range )
... ...
@@ -384,12 +375,11 @@ RTN
384 375
 	
385 376
 	STH
386 377
 	.wave-view/x1 LDZ2 .Audio0/length DEI2 ++ .Screen/x DEO2
387
-	.wave-view/y1 LDZ2 DUP2 #0020 ++
378
+	.wave-view/y1 LDZ2 DUP2 #0020 ++ SWP2
388 379
 	&loop
389
-		OVR2 .Screen/y DEO2
380
+		DUP2 .Screen/y DEO2
390 381
 		( draw ) STHkr .Screen/pixel DEO
391
-		( incr ) SWP2 #0001 ++ SWP2
392
-		LTH2k ,&loop JCN
382
+		#0001 ++ GTH2k ,&loop JCN
393 383
 	POP2 POP2
394 384
 	POPr
395 385
 
... ...
@@ -399,24 +389,24 @@ RTN
399 389
 
400 390
 	( load ) STH .Screen/y DEO2  .Screen/x DEO2
401 391
 	;knob-icns .Screen/addr DEO2 
402
-	( draw ) #01 .Screen/sprite DEO
392
+		( draw ) #01 .Screen/sprite DEO
403 393
 	.Screen/x DEI2 #0008 ++ .Screen/x DEO2 
404 394
 	;knob-icns #0008 ++ .Screen/addr DEO2 
405
-	( draw ) #01 .Screen/sprite DEO
395
+		( draw ) #01 .Screen/sprite DEO
406 396
 	.Screen/y DEI2 #0008 ++ .Screen/y DEO2 
407 397
 	;knob-icns #0018 ++ .Screen/addr DEO2 
408
-	( draw ) #01 .Screen/sprite DEO
398
+		( draw ) #01 .Screen/sprite DEO
409 399
 	.Screen/x DEI2 #0008 -- .Screen/x DEO2 
410 400
 	;knob-icns #0010 ++ .Screen/addr DEO2 
411
-	( draw ) #01 .Screen/sprite DEO
401
+		( draw ) #01 .Screen/sprite DEO
412 402
 	.Screen/x DEI2 #0004 ++ .Screen/x DEO2
413 403
 	.Screen/y DEI2 #0008 ++ .Screen/y DEO2
414 404
 	;font-hex #00 STHkr #08 * ++ .Screen/addr DEO2
415
-	( draw ) #01 .Screen/sprite DEO
405
+		( draw ) #01 .Screen/sprite DEO
416 406
 	.Screen/x DEI2 #0004 -- #00 #00 STHkr ;knob-offsetx ++ LDA ++ .Screen/x DEO2
417 407
 	.Screen/y DEI2 #0010 -- #00 #00 STHr ;knob-offsety ++ LDA ++ .Screen/y DEO2
418 408
 	;knob-icns #0020 ++ .Screen/addr DEO2
419
-	( draw ) #05 .Screen/sprite DEO
409
+		( draw ) #05 .Screen/sprite DEO
420 410
 
421 411
 RTN
422 412
 
... ...
@@ -424,37 +414,38 @@ RTN
424 414
 
425 415
 	STH SWP 
426 416
 	DUP #04 SFT TOS 8** ;font-hex ++ .Screen/addr DEO2
427
-	( draw ) STHkr .Screen/sprite DEO
417
+		( draw ) STHkr .Screen/sprite DEO
428 418
 	#0f AND TOS 8** ;font-hex ++ .Screen/addr DEO2
429 419
 	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
430
-	( draw ) STHkr .Screen/sprite DEO
420
+		( draw ) STHkr .Screen/sprite DEO
431 421
 	DUP #04 SFT TOS 8** ;font-hex ++ .Screen/addr DEO2
432 422
 	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
433
-	( draw ) STHkr .Screen/sprite DEO
423
+		( draw ) STHkr .Screen/sprite DEO
434 424
 	#0f AND TOS 8** ;font-hex ++ .Screen/addr DEO2
435 425
 	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
436
-	( draw ) STHr .Screen/sprite DEO
426
+		( draw ) STHr .Screen/sprite DEO
437 427
 
438 428
 RTN
439 429
 
440 430
 @fill-rect ( x1* y1* x2* y2* color -- )
441 431
 	
442
-	.color STZ
443
-	( x1 x2 y1 y2 ) ROT2 SWP2
432
+	,&color STR
433
+	( x1 x2 y1 y2 ) ROT2
444 434
 	&ver
445
-		( save ) OVR2 .Screen/y DEO2
446
-		STH2 STH2 OVR2 OVR2
435
+		( save ) DUP2 .Screen/y DEO2
436
+		STH2 STH2 OVR2 OVR2 SWP2
447 437
 		&hor
448
-			( save ) OVR2 .Screen/x DEO2
449
-			( draw ) .color LDZ .Screen/pixel DEO
450
-			( incr ) SWP2 #0001 ++ SWP2
451
-			OVR2 OVR2 LTS2 ,&hor JCN
438
+			( save ) DUP2 .Screen/x DEO2
439
+			( draw ) ,&color LDR .Screen/pixel DEO
440
+			( incr ) #0001 ++
441
+			OVR2 OVR2 GTS2 ,&hor JCN
452 442
 		POP2 POP2 STH2r STH2r
453
-		( incr ) SWP2 #0001 ++ SWP2
454
-		OVR2 OVR2 LTS2 ,&ver JCN
443
+		( incr ) #0001 ++
444
+		OVR2 OVR2 GTS2 ,&ver JCN
455 445
 	POP2 POP2 POP2 POP2
456 446
 
457 447
 RTN
448
+	&color $1
458 449
 
459 450
 @within-rect ( x* y* rect -- flag )
460 451