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