(calc.tal) Optimizations

This commit is contained in:
neauoire 2022-01-26 10:14:18 -08:00
parent 055fa9bcd0
commit 3f94152050
1 changed files with 58 additions and 58 deletions

View File

@ -1,4 +1,4 @@
( (
a simple calculator a simple calculator
uxnasm projects/software/calc.tal bin/calc.rom && uxnemu bin/calc.rom ) uxnasm projects/software/calc.tal bin/calc.rom && uxnemu bin/calc.rom )
@ -49,7 +49,7 @@
|0000 |0000
@input @input
&value $2 &value $2
&mode $1 &mode $1
@stack @stack
&length $1 &length $1
@ -71,9 +71,9 @@
|0100 ( -> ) |0100 ( -> )
( theme ) ( theme )
#0e7d .System/r DEO2 #0e7d .System/r DEO2
#0ec6 .System/g DEO2 #0ec6 .System/g DEO2
#0e95 .System/b DEO2 #0e95 .System/b DEO2
( size ) ( size )
@ -94,9 +94,9 @@
.Screen/width DEI2 2// .center/x STZ2 .Screen/width DEI2 2// .center/x STZ2
.Screen/height DEI2 2// .center/y STZ2 .Screen/height DEI2 2// .center/y STZ2
.center/x LDZ2 #0020 -- .center/x LDZ2 #0020 --
DUP2 .keypad-frame/x STZ2 #0040 ++ .keypad-frame/x2 STZ2 DUP2 .keypad-frame/x STZ2 #0040 ++ .keypad-frame/x2 STZ2
.center/y LDZ2 #0018 -- .center/y LDZ2 #0018 --
DUP2 .keypad-frame/y STZ2 #003f ++ .keypad-frame/y2 STZ2 DUP2 .keypad-frame/y STZ2 #003f ++ .keypad-frame/y2 STZ2
.keypad-frame/x LDZ2 .keypad-frame/x LDZ2
@ -109,9 +109,9 @@
.modpad-frame/y2 LDZ2 #0008 ++ .modpad-frame/y2 LDZ2 #0008 ++
DUP2 .bitpad-frame/y STZ2 #000f ++ .bitpad-frame/y2 STZ2 DUP2 .bitpad-frame/y STZ2 #000f ++ .bitpad-frame/y2 STZ2
.center/x LDZ2 #0020 -- .center/x LDZ2 #0020 --
DUP2 .input-frame/x STZ2 #0040 ++ .input-frame/x2 STZ2 DUP2 .input-frame/x STZ2 #0040 ++ .input-frame/x2 STZ2
.center/y LDZ2 #002a -- .center/y LDZ2 #002a --
DUP2 .input-frame/y STZ2 #0010 ++ .input-frame/y2 STZ2 DUP2 .input-frame/y STZ2 #0010 ++ .input-frame/y2 STZ2
( theme support ) ( theme support )
@ -121,7 +121,7 @@ BRK
@on-button ( -> ) @on-button ( -> )
.Controller/key DEI .Controller/key DEI
( generics ) ( generics )
#00 !~ ,&no-empty JCN ;redraw JSR2 POP BRK &no-empty #00 !~ ,&no-empty JCN ;redraw JSR2 POP BRK &no-empty
#09 !~ ,&no-tab JCN ;toggle-mode JSR2 POP BRK &no-tab #09 !~ ,&no-tab JCN ;toggle-mode JSR2 POP BRK &no-tab
@ -160,11 +160,12 @@ BRK
.Mouse/state DEI .pointer/last LDZ .Mouse/state DEI .pointer/last LDZ
( down ) ( down )
DUP2 #0100 !! ,&no-down JCN DUP2 #0100 !! ,&no-down JCN
.Mouse/x DEI2 .Mouse/y DEI2 .Mouse/x DEI2 .Mouse/y DEI2
OVR2 OVR2 .keypad-frame ;within-rect JSR2 ;click-keypad JCN2 OVR2 OVR2 .keypad-frame ;within-rect JSR2 ;click-keypad JCN2
OVR2 OVR2 .input-frame ;within-rect JSR2 ;click-input JCN2 OVR2 OVR2 .input-frame ;within-rect JSR2 ;click-input JCN2
OVR2 OVR2 .modpad-frame ;within-rect JSR2 ;click-modpad JCN2 OVR2 OVR2 .modpad-frame ;within-rect JSR2 ;click-modpad JCN2
OVR2 OVR2 .bitpad-frame ;within-rect JSR2 ;click-bitpad JCN2 OVR2 OVR2 .bitpad-frame ;within-rect JSR2 ;click-bitpad JCN2
;toggle-mode JSR2
POP2 POP2 POP2 POP2
&no-down &no-down
( up ) ( up )
@ -189,7 +190,7 @@ BRK
@click-modpad ( state* x* y* -> ) @click-modpad ( state* x* y* -> )
( y ) .modpad-frame/y LDZ2 -- #24 SFT2 NIP STH ( y ) .modpad-frame/y LDZ2 -- #24 SFT2 NIP STH
( x ) .modpad-frame/x LDZ2 -- 10// ( x ) .modpad-frame/x LDZ2 -- 10//
( lookup ) STHr + 2** ;keypad/ops ++ LDA2 JSR2 ( lookup ) STHr + 2** ;keypad/ops ++ LDA2 JSR2
;draw-bitpad JSR2 ;draw-bitpad JSR2
RELEASE-MOUSE POP2 RELEASE-MOUSE POP2
@ -212,14 +213,14 @@ BRK
@click-bitpad ( state* x* y* -> ) @click-bitpad ( state* x* y* -> )
( y ) .bitpad-frame/y LDZ2 -- 8// NIP 8* STH ( y ) .bitpad-frame/y LDZ2 -- 8// NIP 8* STH
( x ) .bitpad-frame/x LDZ2 -- 8// NIP ( x ) .bitpad-frame/x LDZ2 -- 8// NIP
( value ) STHr + STHk ( value ) STHr + STHk
#30 + .Audio0/pitch DEO #30 + .Audio0/pitch DEO
( toggle bit ) ( toggle bit )
.input/value LDZ2 #0001 .input/value LDZ2 #0001
[ STHr #0f SWP - ] #40 SFT SFT2 EOR2 [ STHr #0f SWP - ] #40 SFT SFT2 EOR2
.input/value STZ2 .input/value STZ2
;draw-bitpad JSR2 ;draw-bitpad JSR2
@ -263,6 +264,7 @@ RTN
@toggle-mode ( -- ) @toggle-mode ( -- )
.input/mode LDZk #00 = SWP STZ .input/mode LDZk #00 = SWP STZ
#30 .Audio0/pitch DEO
;redraw JSR2 ;redraw JSR2
RTN RTN
@ -412,11 +414,11 @@ RTN
@key-value ( key -- value ) @key-value ( key -- value )
DUP #2f > OVR #3a < #0101 !! ,&no-num JCN DUP #2f > OVR #3a < #0101 !! ,&no-num JCN
#30 - RTN &no-num #30 - RTN &no-num
DUP #60 > OVR #67 < #0101 !! ,&no-lc JCN DUP #60 > OVR #67 < #0101 !! ,&no-lc JCN
#57 - RTN ( #61 - #0a + ) &no-lc #57 - RTN ( #61 - #0a + ) &no-lc
DUP #40 > OVR #47 < #0101 !! ,&no-uc JCN DUP #40 > OVR #47 < #0101 !! ,&no-uc JCN
#37 - RTN ( #41 - #0a + ) &no-uc #37 - RTN ( #41 - #0a + ) &no-uc
POP #00 POP #00
@ -478,9 +480,9 @@ RTN
;stack-icns/pop [ STHkr #01 = ] #03 ;stack-icns/pop [ STHkr #01 = ] #03
;draw-key-thin JSR2 ;draw-key-thin JSR2
( line ) ( line )
.input-frame/x LDZ2 .input-frame/x LDZ2
.input-frame/x2 LDZ2 .input-frame/x2 LDZ2
.input-frame/y LDZ2 #0004 -- #02 .input-frame/y LDZ2 #0004 -- #02
;line-hor-dotted JSR2 ;line-hor-dotted JSR2
POPr POPr
@ -493,11 +495,11 @@ RTN
&loop &loop
( color ) DUP TOS ;keypad/color ++ LDA STH ( color ) DUP TOS ;keypad/color ++ LDA STH
( state ) DUP OVRr STHr = STH ( state ) DUP OVRr STHr = STH
( layout ) DUP TOS ;keypad/layout ++ LDA ( layout ) DUP TOS ;keypad/layout ++ LDA
( layout addr ) TOS 8** ;font-hex ++ STH2 ( layout addr ) TOS 8** ;font-hex ++ STH2
( x ) DUP 4MOD TOS 10** STH2 ( x ) DUP 4MOD TOS 10** STH2
( y ) DUP 4/ TOS 10** ( y ) DUP 4/ TOS 10**
( origin-x ) STH2r .keypad-frame/x LDZ2 ++ SWP2 ( origin-x ) STH2r .keypad-frame/x LDZ2 ++ SWP2
( origin-y ) .keypad-frame/y LDZ2 ++ ( origin-y ) .keypad-frame/y LDZ2 ++
STH2r STHr STHr ;draw-key JSR2 STH2r STHr STHr ;draw-key JSR2
INC GTHk ,&loop JCN INC GTHk ,&loop JCN
@ -528,7 +530,7 @@ RTN
&loop &loop
( y ) DUP 8/ TOS 8** .bitpad-frame/y LDZ2 ++ .Screen/y DEO2 ( y ) DUP 8/ TOS 8** .bitpad-frame/y LDZ2 ++ .Screen/y DEO2
( x ) DUP 8MOD TOS 8** .bitpad-frame/x LDZ2 ++ .Screen/x DEO2 ( x ) DUP 8MOD TOS 8** .bitpad-frame/x LDZ2 ++ .Screen/x DEO2
( state ) DUP #0f SWP - .input/value LDZ2 ROT SFT2 2MOD2 ( state ) DUP #0f SWP - .input/value LDZ2 ROT SFT2 2MOD2
( addr ) 8** ;bit-icns ++ .Screen/addr DEO2 ( addr ) 8** ;bit-icns ++ .Screen/addr DEO2
#01 .Screen/sprite DEO #01 .Screen/sprite DEO
INC GTHk ,&loop JCN INC GTHk ,&loop JCN
@ -538,35 +540,31 @@ RTN
@draw-key ( x* y* glyph* state color -- ) @draw-key ( x* y* glyph* state color -- )
( auto x addr ) AUTO-XADDR STH2
( color ) ,&color STR AUTO-XADDR
( state ) ,&state STR SWP2 .Screen/y DEO2
( glyph ) ,&glyph STR2 SWP2 .Screen/x DEO2
( state ) ;button-icns [ #00 ,&state LDR 20** ++ ] .Screen/addr DEO2 ( bg )
( y ) .Screen/y DEO2 ;button-icns [ #00 OVRr STHr 20** ++ ] .Screen/addr DEO2
( x ) .Screen/x DEO2 STHkr .Screen/sprite DEOk DEO
( draw background ) .Screen/x DEI2k #0010 -- ROT DEO2
,&color LDR .Screen/sprite DEO .Screen/y DEI2k #0008 ++ ROT DEO2
,&color LDR .Screen/sprite DEO STHkr .Screen/sprite DEOk DEO
.Screen/x DEI2 #0010 -- .Screen/x DEO2 ( fg )
.Screen/y DEI2 #0008 ++ .Screen/y DEO2 .Screen/addr DEO2
,&color LDR .Screen/sprite DEOk DEO .Screen/x DEI2k #000c -- ROT DEO2
( glyph ) .Screen/y DEI2k #0005 -- ROT DEO2
,&glyph LDR2 .Screen/addr DEO2 STHr [ STHr #09 MUL + ] .Screen/sprite DEO
.Screen/x DEI2 #000c -- .Screen/x DEO2 AUTO-NONE
.Screen/y DEI2 #0005 -- .Screen/y DEO2
,&color LDR [ ,&state LDR #09 MUL + ] .Screen/sprite DEO
( auto none ) AUTO-NONE
RTN RTN
&color $1 &state $1 &glyph $2
@draw-key-thin ( x* y* glyph* state color -- ) @draw-key-thin ( x* y* glyph* state color -- )
AUTO-YADDR AUTO-YADDR
,&color STR ,&state STR ,&glyph STR2 ,&color STR ,&state STR ,&glyph STR2
( frame ) ( frame )
;button-thin-icns #00 [ LIT &state $1 ] 10** ++ .Screen/addr DEO2 ;button-thin-icns #00 [ LIT &state $1 ] 10** ++ .Screen/addr DEO2
.Screen/y DEO2 .Screen/x DEO2 .Screen/y DEO2 .Screen/x DEO2
[ LIT &color $1 ] .Screen/sprite DEOk DEO [ LIT &color $1 ] .Screen/sprite DEOk DEO
( glyph ) ( glyph )
@ -580,13 +578,13 @@ RTN
@draw-number ( number* color -- ) @draw-number ( number* color -- )
,&color STR ,&color STR
( reset zero pad ) ( reset zero pad )
#00 ;&zero STA #00 ;&zero STA
( hexadecimal ) ( hexadecimal )
.input/mode LDZ ,&decimal JCN .input/mode LDZ ,&decimal JCN
AUTO-X AUTO-X
#00 ,&digit JSR #00 ,&digit JSR
SWP SWP
STHk #04 SFT ,&digit JSR STHk #04 SFT ,&digit JSR
STHr #0f AND ,&digit JSR STHr #0f AND ,&digit JSR
STHk #04 SFT ,&digit JSR STHk #04 SFT ,&digit JSR
@ -594,22 +592,22 @@ RTN
AUTO-NONE AUTO-NONE
RTN RTN
&digit ( num -- ) &digit ( num -- )
,&addr JSR .Screen/addr DEO2 ,&addr JSR .Screen/addr DEO2
LIT &color $1 .Screen/sprite DEO [ LIT &color $1 ] .Screen/sprite DEO
RTN RTN
&decimal ( num* -- ) &decimal ( num* -- )
AUTO-X AUTO-X
#2710 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 #2710 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2
#03e8 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 #03e8 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2
#0064 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 NIP #0064 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 NIP
#0a DIVk DUP ,&digit JSR MUL SUB #0a DIVk DUP ,&digit JSR MUL SUB
,&digit JSR ,&digit JSR
AUTO-NONE AUTO-NONE
RTN RTN
&addr ( num -- addr* ) &addr ( num -- addr* )
,&zero LDR ,&padded JCN ,&zero LDR ,&padded JCN
DUP ,&no-blank JCN DUP ,&no-blank JCN
POP ;blank-icn RTN POP ;blank-icn RTN
&no-blank &no-blank
DUP ,&zero STR DUP ,&zero STR
&padded 8* TOS ;font-hex ++ &padded 8* TOS ;font-hex ++
@ -624,8 +622,8 @@ RTN
@load-theme ( -- ) @load-theme ( -- )
;theme-txt .File/name DEO2 ;theme-txt .File/name DEO2
#0006 .File/length DEO2 #0006 .File/length DEO2
#fffa .File/read DEO2 #fffa .File/read DEO2
.File/success DEI2 #0006 !! ,&ignore JCN .File/success DEI2 #0006 !! ,&ignore JCN
@ -646,8 +644,8 @@ RTN
( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN ( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN
( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN ( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN
POP2 POP2 POPr POP2 POP2 POPr
#01 #01
RTN RTN
&skip POP2 POP2 POPr #00 RTN &skip POP2 POP2 POPr #00 RTN
@line-hor-dotted ( x0* x1* y* color -- ) @line-hor-dotted ( x0* x1* y* color -- )
@ -664,16 +662,18 @@ RTN
@print-hex ( value* -- ) @print-hex ( value* -- )
SWP ,&byte JSR SWP ,&byte JSR
&byte ( byte -- ) &byte ( byte -- )
STHk #04 SFT ,&parse JSR #18 DEO STHk #04 SFT ,&parse JSR #18 DEO
STHr #0f AND ,&parse JSR #18 DEO STHr #0f AND ,&parse JSR #18 DEO
JMP2r JMP2r
&parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r
&above #57 ADD JMP2r &above #57 ADD JMP2r
JMP2r JMP2r
( assets )
@keypad @keypad
&layout &layout
0708 090f 0405 060e 0102 030d 000a 0b0c 0708 090f 0405 060e 0102 030d 000a 0b0c