Browse code

(calc.tal) Optimizations

neauoire authored on 26/01/2022 18:14:18
Showing 1 changed files
... ...
@@ -1,4 +1,4 @@
1
-( 
1
+(
2 2
 	a simple calculator
3 3
 	uxnasm projects/software/calc.tal bin/calc.rom && uxnemu bin/calc.rom )
4 4
 
... ...
@@ -49,7 +49,7 @@
49 49
 |0000
50 50
 
51 51
 @input
52
-	&value $2 
52
+	&value $2
53 53
 	&mode $1
54 54
 @stack
55 55
 	&length $1
... ...
@@ -71,9 +71,9 @@
71 71
 
72 72
 |0100 ( -> )
73 73
 
74
-	( theme ) 
75
-	#0e7d .System/r DEO2 
76
-	#0ec6 .System/g DEO2 
74
+	( theme )
75
+	#0e7d .System/r DEO2
76
+	#0ec6 .System/g DEO2
77 77
 	#0e95 .System/b DEO2
78 78
 
79 79
 	( size )
... ...
@@ -94,9 +94,9 @@
94 94
 	.Screen/width DEI2 2// .center/x STZ2
95 95
 	.Screen/height DEI2 2// .center/y STZ2
96 96
 
97
-	.center/x LDZ2 #0020 -- 
97
+	.center/x LDZ2 #0020 --
98 98
 		DUP2 .keypad-frame/x STZ2 #0040 ++ .keypad-frame/x2 STZ2
99
-	.center/y LDZ2 #0018 -- 
99
+	.center/y LDZ2 #0018 --
100 100
 		DUP2 .keypad-frame/y STZ2 #003f ++ .keypad-frame/y2 STZ2
101 101
 
102 102
 	.keypad-frame/x LDZ2
... ...
@@ -109,9 +109,9 @@
109 109
 	.modpad-frame/y2 LDZ2 #0008 ++
110 110
 		DUP2 .bitpad-frame/y STZ2 #000f ++ .bitpad-frame/y2 STZ2
111 111
 
112
-	.center/x LDZ2 #0020 -- 
112
+	.center/x LDZ2 #0020 --
113 113
 		DUP2 .input-frame/x STZ2 #0040 ++ .input-frame/x2 STZ2
114
-	.center/y LDZ2 #002a -- 
114
+	.center/y LDZ2 #002a --
115 115
 		DUP2 .input-frame/y STZ2 #0010 ++ .input-frame/y2 STZ2
116 116
 
117 117
 	( theme support )
... ...
@@ -121,7 +121,7 @@ BRK
121 121
 
122 122
 @on-button ( -> )
123 123
 
124
-	.Controller/key DEI 
124
+	.Controller/key DEI
125 125
 	( generics )
126 126
 	#00 !~ ,&no-empty JCN ;redraw JSR2 POP BRK &no-empty
127 127
 	#09 !~ ,&no-tab JCN ;toggle-mode JSR2 POP BRK &no-tab
... ...
@@ -160,11 +160,12 @@ BRK
160 160
 	.Mouse/state DEI .pointer/last LDZ
161 161
 	( down )
162 162
 	DUP2 #0100 !! ,&no-down JCN
163
-		.Mouse/x DEI2 .Mouse/y DEI2 
163
+		.Mouse/x DEI2 .Mouse/y DEI2
164 164
 		OVR2 OVR2 .keypad-frame ;within-rect JSR2 ;click-keypad JCN2
165 165
 		OVR2 OVR2 .input-frame ;within-rect JSR2 ;click-input JCN2
166 166
 		OVR2 OVR2 .modpad-frame ;within-rect JSR2 ;click-modpad JCN2
167 167
 		OVR2 OVR2 .bitpad-frame ;within-rect JSR2 ;click-bitpad JCN2
168
+		;toggle-mode JSR2
168 169
 		POP2 POP2
169 170
 		&no-down
170 171
 	( up )
... ...
@@ -189,7 +190,7 @@ BRK
189 190
 @click-modpad ( state* x* y* -> )
190 191
 
191 192
 	( y ) .modpad-frame/y LDZ2 -- #24 SFT2 NIP STH
192
-	( x ) .modpad-frame/x LDZ2 -- 10// 
193
+	( x ) .modpad-frame/x LDZ2 -- 10//
193 194
 	( lookup ) STHr + 2** ;keypad/ops ++ LDA2 JSR2
194 195
 	;draw-bitpad JSR2
195 196
 	RELEASE-MOUSE POP2
... ...
@@ -212,14 +213,14 @@ BRK
212 213
 @click-bitpad ( state* x* y* -> )
213 214
 
214 215
 	( y ) .bitpad-frame/y LDZ2 -- 8// NIP 8* STH
215
-	( x ) .bitpad-frame/x LDZ2 -- 8// NIP 
216
+	( x ) .bitpad-frame/x LDZ2 -- 8// NIP
216 217
 	( value ) STHr + STHk
217 218
 
218 219
 	#30 + .Audio0/pitch DEO
219 220
 
220 221
 	( toggle bit )
221
-	.input/value LDZ2 #0001 
222
-		[ STHr #0f SWP - ] #40 SFT SFT2 EOR2 
222
+	.input/value LDZ2 #0001
223
+		[ STHr #0f SWP - ] #40 SFT SFT2 EOR2
223 224
 		.input/value STZ2
224 225
 
225 226
 	;draw-bitpad JSR2
... ...
@@ -263,6 +264,7 @@ RTN
263 264
 @toggle-mode ( -- )
264 265
 
265 266
 	.input/mode LDZk #00 = SWP STZ
267
+	#30 .Audio0/pitch DEO
266 268
 	;redraw JSR2
267 269
 
268 270
 RTN
... ...
@@ -412,11 +414,11 @@ RTN
412 414
 
413 415
 @key-value ( key -- value )
414 416
 
415
-	DUP #2f > OVR #3a < #0101 !! ,&no-num JCN 
417
+	DUP #2f > OVR #3a < #0101 !! ,&no-num JCN
416 418
 		#30 - RTN &no-num
417
-	DUP #60 > OVR #67 < #0101 !! ,&no-lc JCN 
419
+	DUP #60 > OVR #67 < #0101 !! ,&no-lc JCN
418 420
 		#57 - RTN ( #61 - #0a + ) &no-lc
419
-	DUP #40 > OVR #47 < #0101 !! ,&no-uc JCN 
421
+	DUP #40 > OVR #47 < #0101 !! ,&no-uc JCN
420 422
 		#37 - RTN ( #41 - #0a + ) &no-uc
421 423
 	POP #00
422 424
 
... ...
@@ -478,9 +480,9 @@ RTN
478 480
 	;stack-icns/pop [ STHkr #01 = ] #03
479 481
 		;draw-key-thin JSR2
480 482
 	( line )
481
-	.input-frame/x LDZ2 
482
-	.input-frame/x2 LDZ2 
483
-	.input-frame/y LDZ2 #0004 -- #02 
483
+	.input-frame/x LDZ2
484
+	.input-frame/x2 LDZ2
485
+	.input-frame/y LDZ2 #0004 -- #02
484 486
 		;line-hor-dotted JSR2
485 487
 	POPr
486 488
 
... ...
@@ -493,11 +495,11 @@ RTN
493 495
 	&loop
494 496
 		( color ) DUP TOS ;keypad/color ++ LDA STH
495 497
 		( state ) DUP OVRr STHr = STH
496
-		( layout ) DUP TOS ;keypad/layout ++ LDA 
498
+		( layout ) DUP TOS ;keypad/layout ++ LDA
497 499
 			( layout addr ) TOS 8** ;font-hex ++ STH2
498 500
 		( x ) DUP 4MOD TOS 10** STH2
499 501
 		( y ) DUP 4/ TOS 10**
500
-		( origin-x ) STH2r .keypad-frame/x LDZ2 ++ SWP2 
502
+		( origin-x ) STH2r .keypad-frame/x LDZ2 ++ SWP2
501 503
 		( origin-y ) .keypad-frame/y LDZ2 ++
502 504
 			STH2r STHr STHr ;draw-key JSR2
503 505
 		INC GTHk ,&loop JCN
... ...
@@ -528,7 +530,7 @@ RTN
528 530
 	&loop
529 531
 		( y ) DUP 8/ TOS 8** .bitpad-frame/y LDZ2 ++ .Screen/y DEO2
530 532
 		( x ) DUP 8MOD TOS 8** .bitpad-frame/x LDZ2 ++ .Screen/x DEO2
531
-		( state ) DUP #0f SWP - .input/value LDZ2 ROT SFT2 2MOD2 
533
+		( state ) DUP #0f SWP - .input/value LDZ2 ROT SFT2 2MOD2
532 534
 		( addr ) 8** ;bit-icns ++ .Screen/addr DEO2
533 535
 		#01 .Screen/sprite DEO
534 536
 		INC GTHk ,&loop JCN
... ...
@@ -538,35 +540,31 @@ RTN
538 540
 
539 541
 @draw-key ( x* y* glyph* state color -- )
540 542
 
541
-	( auto x addr ) AUTO-XADDR
542
-	( color ) ,&color STR
543
-	( state ) ,&state STR
544
-	( glyph ) ,&glyph STR2
545
-	( state ) ;button-icns [ #00 ,&state LDR 20** ++ ] .Screen/addr DEO2 
546
-	( y ) .Screen/y DEO2
547
-	( x ) .Screen/x DEO2
548
-	( draw background )
549
-	,&color LDR .Screen/sprite DEO
550
-	,&color LDR .Screen/sprite DEO
551
-	.Screen/x DEI2 #0010 -- .Screen/x DEO2
552
-	.Screen/y DEI2 #0008 ++ .Screen/y DEO2
553
-	,&color LDR .Screen/sprite DEOk DEO
554
-	( glyph )
555
-	,&glyph LDR2 .Screen/addr DEO2
556
-	.Screen/x DEI2 #000c -- .Screen/x DEO2
557
-	.Screen/y DEI2 #0005 -- .Screen/y DEO2
558
-	,&color LDR [ ,&state LDR #09 MUL + ] .Screen/sprite DEO
559
-	( auto none ) AUTO-NONE
543
+	STH2
544
+	AUTO-XADDR
545
+	SWP2 .Screen/y DEO2
546
+	SWP2 .Screen/x DEO2
547
+	( bg )
548
+	;button-icns [ #00 OVRr STHr 20** ++ ] .Screen/addr DEO2
549
+	STHkr .Screen/sprite DEOk DEO
550
+	.Screen/x DEI2k #0010 -- ROT DEO2
551
+	.Screen/y DEI2k #0008 ++ ROT DEO2
552
+	STHkr .Screen/sprite DEOk DEO
553
+	( fg )
554
+	.Screen/addr DEO2
555
+	.Screen/x DEI2k #000c -- ROT DEO2
556
+	.Screen/y DEI2k #0005 -- ROT DEO2
557
+	STHr [ STHr #09 MUL + ] .Screen/sprite DEO
558
+	AUTO-NONE
560 559
 
561 560
 RTN
562
-	&color $1 &state $1 &glyph $2
563 561
 
564 562
 @draw-key-thin ( x* y* glyph* state color -- )
565 563
 
566 564
 	AUTO-YADDR
567 565
 	,&color STR ,&state STR ,&glyph STR2
568 566
 	( frame )
569
-	;button-thin-icns #00 [ LIT &state $1 ] 10** ++ .Screen/addr DEO2 
567
+	;button-thin-icns #00 [ LIT &state $1 ] 10** ++ .Screen/addr DEO2
570 568
 	.Screen/y DEO2 .Screen/x DEO2
571 569
 	[ LIT &color $1 ] .Screen/sprite DEOk DEO
572 570
 	( glyph )
... ...
@@ -580,13 +578,13 @@ RTN
580 578
 @draw-number ( number* color -- )
581 579
 
582 580
 	,&color STR
583
-	( reset zero pad ) 
581
+	( reset zero pad )
584 582
 	#00 ;&zero STA
585 583
 	( hexadecimal )
586 584
 	.input/mode LDZ ,&decimal JCN
587 585
 		AUTO-X
588 586
 		#00 ,&digit JSR
589
-		SWP 
587
+		SWP
590 588
 		STHk #04 SFT ,&digit JSR
591 589
 		STHr #0f AND ,&digit JSR
592 590
 		STHk #04 SFT ,&digit JSR
... ...
@@ -594,22 +592,22 @@ RTN
594 592
 		AUTO-NONE
595 593
 	RTN
596 594
 	&digit ( num -- )
597
-		,&addr JSR .Screen/addr DEO2 
598
-		LIT &color $1 .Screen/sprite DEO 
595
+		,&addr JSR .Screen/addr DEO2
596
+		[ LIT &color $1 ] .Screen/sprite DEO
599 597
 	RTN
600 598
 	&decimal ( num* -- )
601 599
 		AUTO-X
602 600
 		#2710 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2
603 601
 		#03e8 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2
604 602
 		#0064 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 NIP
605
-		#0a DIVk DUP ,&digit JSR MUL SUB 
603
+		#0a DIVk DUP ,&digit JSR MUL SUB
606 604
 		,&digit JSR
607 605
 		AUTO-NONE
608 606
 	RTN
609 607
 	&addr ( num -- addr* )
610 608
 		,&zero LDR ,&padded JCN
611
-		DUP ,&no-blank JCN 
612
-			POP ;blank-icn RTN 
609
+		DUP ,&no-blank JCN
610
+			POP ;blank-icn RTN
613 611
 			&no-blank
614 612
 		DUP ,&zero STR
615 613
 		&padded 8* TOS ;font-hex ++
... ...
@@ -624,8 +622,8 @@ RTN
624 622
 
625 623
 @load-theme ( -- )
626 624
 
627
-	;theme-txt .File/name DEO2 
628
-	#0006 .File/length DEO2 
625
+	;theme-txt .File/name DEO2
626
+	#0006 .File/length DEO2
629 627
 	#fffa .File/read DEO2
630 628
 
631 629
 	.File/success DEI2 #0006 !! ,&ignore JCN
... ...
@@ -646,8 +644,8 @@ RTN
646 644
 	( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN
647 645
 	( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN
648 646
 	POP2 POP2 POPr
649
-	#01 
650
-RTN 
647
+	#01
648
+RTN
651 649
 	&skip POP2 POP2 POPr #00 RTN
652 650
 
653 651
 @line-hor-dotted ( x0* x1* y* color -- )
... ...
@@ -664,16 +662,18 @@ RTN
664 662
 
665 663
 @print-hex ( value* -- )
666 664
 
667
-	SWP ,&byte JSR 
665
+	SWP ,&byte JSR
668 666
 	&byte ( byte -- )
669 667
 		STHk #04 SFT ,&parse JSR #18 DEO
670 668
 		STHr #0f AND ,&parse JSR #18 DEO
671 669
 	JMP2r
672
-	&parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r 
670
+	&parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r
673 671
 	&above #57 ADD JMP2r
674 672
 
675 673
 JMP2r
676 674
 
675
+( assets )
676
+
677 677
 @keypad
678 678
 	&layout
679 679
 	0708 090f 0405 060e 0102 030d 000a 0b0c