uxn-utils/gui/sliderule/sliderule.tal

250 lines
4.9 KiB
Tal

( uxnemu sliderule.rom )
|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2
|10 @Console &vector $2 &read $1 &pad $5 &write $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $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 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|0000
@state &c $2 &d $2 &cursor $2
|0100
@on-reset ( -> )
( | theme )
#af0f .System/r DEO2
#a20f .System/g DEO2
#a20f .System/b DEO2
load-theme
( | size )
#0148 .Screen/width DEO2
#0078 .Screen/height DEO2
( | unlock )
;on-mouse .Mouse/vector DEO2
<redraw>
BRK
(
@|vectors )
@on-mouse ( -> )
[ LIT2 00 -Mouse/state ] DEI NEQ #41 ADD ;pointer-icn <update-pointer>
[ LIT &last $1 ] .Mouse/state DEI DUP ,&last STR
DUP2 #0001 EQU2 ?&down
DUP2 #0101 EQU2 ?&drag
POP2 BRK
&down ( states* -> )
POP2 .Mouse/x DEI2 ,&from STR2
BRK
&drag ( states* -> )
POP2 [ LIT2 &from $2 ] .Mouse/x DEI2 DUP2 ,&from STR2
SWP2 SUB2
@on-drag ( offset* -> )
.Mouse/y DEI2
( ) DUP2 #0020 LTH2 ?&cursor
( ) DUP2 #0038 LTH2 ?&c
( ) DUP2 #0050 LTH2 ?&d
&cursor ( offset* y* -> )
POP2 DUP2 .state/c LDZ2 ADD2 .state/c STZ2
.state/d LDZ2 ADD2 .state/d STZ2
<redraw>
BRK
&c ( offset* y* -> )
POP2 .state/c LDZ2 ADD2 .state/c STZ2
<redraw>
BRK
&d ( offset* y* -> )
POP2 .state/d LDZ2 ADD2 .state/d STZ2
<redraw>
BRK
(
@|core )
(
@|drawing )
@<redraw> ( -- )
#0000 DUP2 .Screen/x DEO2
.Screen/y DEO2
#80 .Screen/pixel DEO
<draw-c>
<draw-d>
<draw-cursor>
JMP2r
@<draw-cursor> ( -- )
#0050 .Screen/x DEO2
#0018 .Screen/y DEO2
#76 .Screen/auto DEO
;cursor-chr .Screen/addr DEO2
#0800
&l ( -- )
#85 .Screen/sprite DEO
INC GTHk ?&l
POP2 JMP2r
@<draw-c> ( -- )
#0020 .state/c LDZ2 ADD2 .Screen/x DEO2
#0020 .Screen/y DEO2
( | cap )
#25 .Screen/auto DEO
;cap-chr .Screen/addr DEO2
#85 .Screen/sprite DEO
<draw-rule>
<draw-rule>
<draw-rule>
( | cap )
#25 .Screen/auto DEO
;cap-end-chr .Screen/addr DEO2
#85 .Screen/sprite DEO
( | numbers )
#05 .Screen/auto DEO
#0024 .state/c LDZ2 ADD2 .Screen/x DEO2
#0028 .Screen/y DEO2
<draw-nums>
JMP2r
@<draw-d> ( -- )
#0030 .state/d LDZ2 ADD2 .Screen/x DEO2
#0037 .Screen/y DEO2
( | cap )
#25 .Screen/auto DEO
;cap-chr .Screen/addr DEO2
#85 .Screen/sprite DEO
<draw-rule-rev>
<draw-rule-rev>
<draw-rule-rev>
( | cap )
#25 .Screen/auto DEO
;cap-end-chr .Screen/addr DEO2
#85 .Screen/sprite DEO
( | numbers )
#05 .Screen/auto DEO
#0034 .state/d LDZ2 ADD2 .Screen/x DEO2
#0041 .Screen/y DEO2
<draw-nums>
JMP2r
@<draw-nums> ( -- )
#01 <draw-num>
( small ) #0900
&l ( -- )
#00 OVR STH2 .Screen/x DEI2k #0016 STH2r SUB2 ADD2 ROT DEO2
INCk <draw-num-small>
INC GTHk ?&l
POP2
( | next )
.Screen/x DEI2k #000d ADD2 ROT DEO2
#02 <draw-num>
.Screen/x DEI2k #0083 ADD2 ROT DEO2
#03 <draw-num>
.Screen/x DEI2k #006b ADD2 ROT DEO2
#04 <draw-num>
.Screen/x DEI2k #0042 ADD2 ROT DEO2
#05 <draw-num>
.Screen/x DEI2k #003a ADD2 ROT DEO2
#06 <draw-num>
.Screen/x DEI2k #0036 ADD2 ROT DEO2
#07 <draw-num>
.Screen/x DEI2k #002d ADD2 ROT DEO2
#08 <draw-num>
.Screen/x DEI2k #0024 ADD2 ROT DEO2
#09 <draw-num>
JMP2r
@<draw-num> ( num -- )
#00 SWP #30 SFT2 ;num-icn ADD2 .Screen/addr DEO2
#0a .Screen/sprite DEO
JMP2r
@<draw-num-small> ( num -- )
#00 SWP #30 SFT2 ;num-icn ADD2 .Screen/addr DEO2
#05 .Screen/sprite DEO
JMP2r
@<draw-rule> ( -- )
#2300
&l ( -- )
( | bg )
#06 .Screen/auto DEO
;bg-chr .Screen/addr DEO2
[ LIT2 85 -Screen/sprite ] DEOk
DEO
( | scale )
#05 .Screen/auto DEO
#00 OVR #40 SFT2 ;rule-chr ADD2 .Screen/addr DEO2
[ LIT2 85 -Screen/sprite ] DEO
( adjust ) .Screen/y DEI2k #0010 SUB2 ROT DEO2
INC GTHk ?&l
POP2
( adjust ) .Screen/x DEI2k #0005 SUB2 ROT DEO2
JMP2r
@<draw-rule-rev> ( -- )
#2300
&l ( -- )
( | scale )
#06 .Screen/auto DEO
#00 OVR #40 SFT2 ;rule-chr ADD2 .Screen/addr DEO2
[ LIT2 a5 -Screen/sprite ] DEO
( | bg )
#15 .Screen/auto DEO
;bg-rev-chr .Screen/addr DEO2
[ LIT2 85 -Screen/sprite ] DEO
( adjust ) .Screen/y DEI2k #0008 SUB2 ROT DEO2
INC GTHk ?&l
POP2
( adjust ) .Screen/x DEI2k #0005 SUB2 ROT DEO2
JMP2r
@<update-pointer> ( color addr* -- )
[ LIT2 00 -Screen/auto ] DEO
#40 <draw-pointer>
.Mouse/x DEI2 ,<draw-pointer>/x STR2
.Mouse/y DEI2 ,<draw-pointer>/y STR2
.Screen/addr DEO2
@<draw-pointer> ( color -- )
[ LIT2 &x $2 ] .Screen/x DEO2
[ LIT2 &y $2 ] .Screen/y DEO2
.Screen/sprite DEO
JMP2r
@<phex> ( short* -- )
SWP <phex>/b
&b ( -- )
DUP #04 SFT <phex>/c
&c ( -- )
#0f AND DUP #09 GTH #27 MUL ADD LIT "0 ADD #18 DEO
JMP2r
(
@|utils )
@load-theme ( -- )
;&path .File/name DEO2
#0002 .File/length DEO2
;&r .File/read DEO2
;&g .File/read DEO2
;&b .File/read DEO2
.File/success DEI2 ORA #01 JCN
JMP2r
LIT2 &r $2
.System/r DEO2
LIT2 &g $2
.System/g DEO2
LIT2 &b $2
.System/b DEO2
JMP2r
&path ".theme $1
(
@|spritesheet )
~assets.tal