uxn/projects/software/clock.tal

324 lines
8.7 KiB
Tal
Raw Permalink Normal View History

2022-05-31 16:25:41 -04:00
( simple graphical clock )
2021-03-26 17:01:51 -04:00
2021-04-23 11:58:58 -04:00
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
2021-09-26 16:33:39 -04:00
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|c0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
|0000
2022-03-25 15:05:11 -04:00
@last
2021-11-19 17:31:15 -05:00
&day $1 &sec $1
2021-09-26 17:06:18 -04:00
@center
&x $2 &y $2
2021-11-19 11:46:28 -05:00
@date
&x $2 &y $2
@time
&x $2 &y $2
2021-11-16 12:10:48 -05:00
@needles
2022-03-25 15:05:11 -04:00
&hx $2 &hy $2
&mx $2 &my $2
2021-11-20 11:12:25 -05:00
&sx $2 &sy $2
2021-11-20 12:18:45 -05:00
&zx $2 &zy $2
2021-11-20 13:12:12 -05:00
@buf
&d $3 &h $2 &s1 $1 &m $2 &s2 $1 &s $3
2021-11-16 12:10:48 -05:00
@line
2022-03-24 16:15:50 -04:00
&x $2 &y $2 &dx $2 &dy $2 &e1 $2
2021-04-02 00:53:41 -04:00
2021-04-29 00:00:39 -04:00
|0100 ( -> )
2022-03-25 15:05:11 -04:00
( theme )
#0ff8 .System/r DEO2
#0f08 .System/g DEO2
2021-11-16 12:10:48 -05:00
#0f08 .System/b DEO2
( resize )
2022-11-12 13:14:13 -05:00
#00d0 .Screen/width DEO2
2021-11-16 12:10:48 -05:00
#0120 .Screen/height DEO2
2022-03-25 15:05:11 -04:00
( vectors )
2021-04-23 11:58:58 -04:00
;on-frame .Screen/vector DEO2
2021-11-16 12:10:48 -05:00
( center )
2022-03-25 15:05:11 -04:00
.Screen/width DEI2 #01 SFT2
2021-11-19 11:46:28 -05:00
DUP2 .center/x STZ2
2022-03-14 13:21:36 -04:00
DUP2 #0028 SUB2 .date/x STZ2
#0020 SUB2 .time/x STZ2
2022-03-25 15:05:11 -04:00
.Screen/height DEI2 #01 SFT2
2021-11-19 11:46:28 -05:00
DUP2 .center/y STZ2
2022-03-14 13:21:36 -04:00
DUP2 #0078 SUB2 .date/y STZ2
#006c ADD2 .time/y STZ2
;draw-watchface JSR2
( time buffer )
2022-08-14 15:06:23 -04:00
LIT ":
2021-11-20 13:12:12 -05:00
DUP .buf/s1 STZ
.buf/s2 STZ
2021-11-20 11:12:25 -05:00
2021-11-20 13:12:12 -05:00
( continue )
2021-03-26 17:01:51 -04:00
2021-04-29 00:00:39 -04:00
@on-frame ( -> )
2021-04-02 00:53:41 -04:00
2021-11-19 17:31:15 -05:00
( once per second )
2022-03-25 15:05:11 -04:00
.DateTime/second DEI
2022-03-14 13:21:36 -04:00
DUP .last/sec LDZ EQU ,&same-sec JCN
2021-11-20 11:12:25 -05:00
( make time )
2021-11-20 13:12:12 -05:00
.DateTime/hour DEI .buf/h ;decimal JSR2
.DateTime/minute DEI .buf/m ;decimal JSR2
DUP .buf/s ;decimal JSR2
2021-11-20 11:12:25 -05:00
( draw label )
2021-11-19 17:31:15 -05:00
.time/x LDZ2 .Screen/x DEO2
.time/y LDZ2 .Screen/y DEO2
2021-11-20 13:12:12 -05:00
;buf/h ;draw-text JSR2
2021-11-20 11:12:25 -05:00
( draw needles )
#00 ;draw-needles JSR2
;make-needles JSR2
#01 ;draw-needles JSR2
2021-11-19 17:31:15 -05:00
DUP .last/sec STZ
&same-sec
POP
( once per day )
2022-03-25 15:05:11 -04:00
.DateTime/day DEI
2022-03-14 13:21:36 -04:00
DUP .last/day LDZ EQU ,&same-day JCN
2021-11-20 11:12:25 -05:00
( make date )
2021-11-20 13:12:12 -05:00
DUP .buf/d ;decimal JSR2
2021-11-20 11:12:25 -05:00
( draw label )
2021-11-19 17:31:15 -05:00
.date/x LDZ2 .Screen/x DEO2
.date/y LDZ2 .Screen/y DEO2
2022-03-14 13:21:36 -04:00
[ #00 .DateTime/dotw DEI #20 SFT ] ;week-txt ADD2 ;draw-text JSR2
[ #00 .DateTime/month DEI #20 SFT ] ;month-txt ADD2 ;draw-text JSR2
2021-11-20 13:12:12 -05:00
;buf/d ;draw-text JSR2
2021-11-19 17:31:15 -05:00
DUP .last/day STZ
&same-day
POP
2021-03-26 17:01:51 -04:00
2021-09-26 16:33:39 -04:00
BRK
2021-11-19 17:31:15 -05:00
@draw-needles ( draw -- )
STH
2022-03-25 15:05:11 -04:00
.center/x LDZ2 .center/y LDZ2
2022-03-24 16:15:50 -04:00
OVR2 OVR2
2022-03-25 15:05:11 -04:00
.needles/mx LDZ2 .needles/my LDZ2 #01 STHkr MUL
2022-03-24 16:15:50 -04:00
;draw-line JSR2
OVR2 OVR2
2022-03-25 15:05:11 -04:00
.needles/hx LDZ2 .needles/hy LDZ2 #01 STHkr MUL
2022-03-24 16:15:50 -04:00
;draw-line JSR2
.needles/sx LDZ2 .needles/sy LDZ2
2022-03-25 15:05:11 -04:00
.needles/zx LDZ2 .needles/zy LDZ2 #02 STHr MUL
2022-03-24 16:15:50 -04:00
;draw-line JSR2
( middle )
2022-03-25 15:05:11 -04:00
#0001 SUB2 .Screen/y DEO2
2022-03-24 16:15:50 -04:00
#0001 SUB2 .Screen/x DEO2
;middle-icn .Screen/addr DEO2
#0a .Screen/sprite DEO
2022-03-14 13:21:36 -04:00
JMP2r
2021-09-26 16:33:39 -04:00
2021-11-19 17:31:15 -05:00
@draw-text ( addr* -- )
2022-03-24 16:15:50 -04:00
( auto addr ) #15 .Screen/auto DEO
2021-11-19 17:31:15 -05:00
&while
LDAk
2022-03-14 13:21:36 -04:00
DUP ;is-lc JSR2 ,&lc JCN
DUP ;is-uc JSR2 ,&uc JCN
DUP ;is-num JSR2 ,&num JCN
2022-08-14 15:06:23 -04:00
DUP LIT "/ EQU ,&slash JCN
DUP LIT ": EQU ,&colon JCN
2021-11-19 17:31:15 -05:00
POP ;font/blank
&end
2021-11-16 14:35:08 -05:00
.Screen/addr DEO2
2022-03-24 16:15:50 -04:00
#03 .Screen/sprite DEO
2021-11-19 17:31:15 -05:00
INC2 LDAk ,&while JCN
POP2
2022-03-24 16:15:50 -04:00
#00 .Screen/sprite DEO
2021-11-19 17:31:15 -05:00
( auto none ) #00 .Screen/auto DEO
2021-11-18 12:47:05 -05:00
2022-03-14 13:21:36 -04:00
JMP2r
&lc #61 SUB #00 SWP #40 SFT2 ;font/lc ADD2 ,&end JMP
&uc #41 SUB #00 SWP #40 SFT2 ;font/uc ADD2 ,&end JMP
&num #30 SUB #00 SWP #40 SFT2 ;font/num ADD2 ,&end JMP
2021-11-19 17:31:15 -05:00
&slash POP ;font/slash ,&end JMP
&colon POP ;font/colon ,&end JMP
2021-11-18 12:47:05 -05:00
2021-11-20 13:12:12 -05:00
@draw-line ( x1* y1* x2* y2* color -- )
2022-03-25 15:05:11 -04:00
2022-03-24 16:15:50 -04:00
( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
,&x LDR2 .line/x LDZ2 SUB2 ;abs2 JSR2 .line/dx STZ2
#0000 ,&y LDR2 .line/y LDZ2 SUB2 ;abs2 JSR2 SUB2 .line/dy STZ2
2022-07-14 17:57:56 -04:00
#ffff #00 .line/x LDZ2 ,&x LDR2 ;lts2 JSR2 DUP2 ADD2 ADD2 ,&sx STR2
#ffff #00 .line/y LDZ2 ,&y LDR2 ;lts2 JSR2 DUP2 ADD2 ADD2 ,&sy STR2
2022-03-14 13:21:36 -04:00
.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
&loop
2022-03-25 15:05:11 -04:00
.line/x LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
.line/y LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
2022-03-24 16:15:50 -04:00
STHkr .Screen/pixel DEO
AND ,&end JCN
2022-07-14 17:57:56 -04:00
.line/e1 LDZ2 DUP2 ADD2 DUP2
2022-03-24 16:15:50 -04:00
.line/dy LDZ2 ;lts2 JSR2 ,&skipy JCN
2022-03-14 13:21:36 -04:00
.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
2022-03-24 16:15:50 -04:00
.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2
&skipy
2022-03-24 16:15:50 -04:00
.line/dx LDZ2 ;gts2 JSR2 ,&skipx JCN
2022-03-14 13:21:36 -04:00
.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2
2022-03-24 16:15:50 -04:00
.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2
&skipx
2022-03-24 16:15:50 -04:00
,&loop JMP
&end
2022-03-24 16:15:50 -04:00
POPr
2022-03-14 13:21:36 -04:00
JMP2r
@draw-watchface ( -- )
2022-03-25 15:05:11 -04:00
#3c00
&loop
( dots )
#00 OVRk ADD2 ;table ADD2 LDA2
#0018 ;circle JSR2
.Screen/x DEO2 .Screen/y DEO2 #01 .Screen/pixel DEO
( markers )
2022-03-14 13:21:36 -04:00
DUP #05 ;mod JSR2 ,&no-marker JCN
#00 OVRk ADD2 ;table ADD2 LDA2
STH2k #0018 ;circle JSR2 SWP2
STH2r #001c ;circle JSR2 SWP2
#01 ;draw-line JSR2
&no-marker
INC GTHk ;&loop JCN2
POP2
2022-03-14 13:21:36 -04:00
JMP2r
2021-11-19 17:31:15 -05:00
@make-needles ( -- )
2022-07-14 17:57:56 -04:00
[ #00 .DateTime/second DEI #1e ADD #3c ;mod JSR2 ] DUP2 ADD2 ;table ADD2 LDA2
2021-11-20 12:18:45 -05:00
#00a0 ,circle JSR .needles/zx STZ2 .needles/zy STZ2
2022-07-14 17:57:56 -04:00
[ #00 .DateTime/second DEI ] DUP2 ADD2 ;table ADD2 LDA2
2022-03-25 15:05:11 -04:00
#0020 ,circle JSR .needles/sx STZ2 .needles/sy STZ2
2022-07-14 17:57:56 -04:00
[ #00 .DateTime/minute DEI ] DUP2 ADD2 ;table ADD2 LDA2
2022-03-25 15:05:11 -04:00
#0022 ,circle JSR .needles/mx STZ2 .needles/my STZ2
2022-03-14 13:21:36 -04:00
[ #00 .DateTime/hour DEI #0c ;mod JSR2 #20 SFTk NIP ADD ]
2022-07-14 17:57:56 -04:00
( minute offset ) [ #00 .DateTime/minute DEI #0f DIV ADD2 ] DUP2 ADD2 ;table ADD2 LDA2
2021-11-20 12:18:45 -05:00
#002a ,circle JSR .needles/hx STZ2 .needles/hy STZ2
2022-03-14 13:21:36 -04:00
JMP2r
2021-11-20 12:18:45 -05:00
2021-11-20 13:12:12 -05:00
@circle ( cx cy radius* -- y* x* )
2021-11-20 12:18:45 -05:00
STH2 SWP
2022-03-14 13:21:36 -04:00
#00 SWP #40 SFT2 STH2kr DIV2 .center/x LDZ2 ADD2 #0800 STH2kr DIV2 SUB2
2021-11-20 12:18:45 -05:00
STH2 SWP2r
2022-03-14 13:21:36 -04:00
#00 SWP #40 SFT2 STH2kr DIV2 .center/y LDZ2 ADD2 #0800 STH2kr DIV2 SUB2
2021-11-20 12:18:45 -05:00
POP2r STH2r
2021-11-19 17:31:15 -05:00
2022-03-14 13:21:36 -04:00
JMP2r
2021-11-19 17:31:15 -05:00
2021-11-20 13:12:12 -05:00
@decimal ( value* zp-label -- )
2021-11-19 17:31:15 -05:00
2021-11-20 11:12:25 -05:00
STH
2022-03-14 13:21:36 -04:00
DUP #0a DIV #30 ADD STHkr STZ
#0a ;mod JSR2 #30 ADD STHr INC STZ
JMP2r
@mod DIVk MUL SUB JMP2r
2022-03-14 13:21:36 -04:00
@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
2022-04-05 19:41:49 -04:00
@lts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 GTH2 JMP2r
@gts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 LTH2 JMP2r
2022-03-14 13:21:36 -04:00
@is-uc DUP #40 GTH SWP #5b LTH AND JMP2r
@is-lc DUP #60 GTH SWP #7b LTH AND JMP2r
@is-num DUP #2f GTH SWP #3a LTH AND JMP2r
2021-11-19 17:31:15 -05:00
@week-txt
2022-03-25 15:05:11 -04:00
"Sun $1 "Mon $1 "Tue $1 "Wed $1 "Thu $1 "Fri $1
2021-11-19 17:31:15 -05:00
"Sat $1
2021-11-20 13:12:12 -05:00
2021-11-19 17:31:15 -05:00
@month-txt
"Jan $1 "Feb $1 "Mar $1 "Apr $1 "May $1 "Jun $1
"Jul $1 "Aug $1 "Sep $1 "Oct $1 "Nov $1 "Dec $1
2021-11-18 12:47:05 -05:00
2021-11-16 12:10:48 -05:00
@table ( 60 positions on a circle )
8000 8d00 9a02 a706 b40b c011 cb18 d520
df2a e734 ee40 f44b f958 fd65 ff72 ff80
ff8d fd9a f9a7 f4b4 eec0 e7cb dfd5 d5df
cbe7 c0ee b4f4 a7f9 9afd 8dff 80ff 72ff
65fd 58f9 4bf4 40ee 34e7 2adf 20d5 18cb
11c0 0bb4 06a7 029a 008d 0080 0072 0265
0658 0b4b 113f 1834 202a 2a20 3418 3f11
2021-04-02 00:44:23 -04:00
4b0b 5806 6502 7200
2021-03-26 17:01:51 -04:00
@middle-icn
40e0 4000 0000 0000
2021-11-16 14:35:08 -05:00
@font
2021-11-19 17:31:15 -05:00
&num
2021-11-16 14:35:08 -05:00
0018 2442 4242 4242 4242 4242 4224 1800
0008 1828 0808 0808 0808 0808 0808 1c00
0018 2442 4202 0202 0408 1020 4040 7e00
0018 2442 0202 0438 0402 0202 0204 7800
000c 0c14 1414 2424 2444 447e 0404 0e00
007e 4040 4040 5864 4202 0202 0204 7800
000c 1020 4040 5864 4242 4242 4224 1800
007e 4202 0204 0404 0808 0810 1010 1000
0018 2442 4242 2418 2442 4242 4224 1800
0018 2442 4242 4242 261a 0202 0408 3000
2021-11-19 17:31:15 -05:00
&uc
2021-11-18 12:47:05 -05:00
0010 1028 2844 4444 8282 fe82 8282 0000
00f8 4442 4242 4478 4442 4242 44f8 0000
003c 4282 8280 8080 8080 8282 423c 0000
00f8 4442 4242 4242 4242 4242 44f8 0000
00fc 4240 4040 4878 4840 4040 42fc 0000
80fe 4240 4040 447c 4440 4040 40e0 0000
003a 4682 8080 8e82 8282 8282 463a 0000
00ee 4444 4444 447c 4444 4444 44ee 0000
0038 1010 1010 1010 1010 1010 1038 0000
000e 0404 0404 0404 0404 4444 2810 0000
00ee 4448 4850 5060 5050 4848 44ee 0000
00e0 4040 4040 4040 4040 4040 42fe 0000
0082 c6c6 c6aa aaaa 9292 9282 8282 0000
00e2 4262 6262 5252 4a4a 4646 42e2 0000
0038 4482 8282 8282 8282 8282 4438 0000
00f8 4442 4242 4244 7840 4040 40f0 0000
0038 4482 8282 8282 8282 829a 643a 0000
00f8 4442 4242 4478 4844 4442 42e2 0000
0010 2844 4440 2010 0804 4444 2810 0000
00fe 9210 1010 1010 1010 1010 1038 0000
00ee 4444 4444 4444 4444 4444 4438 0000
0082 8282 8282 8244 4444 2828 1010 0000
0082 8292 9292 9292 92ba aa44 4444 0000
0042 4242 2424 1818 1824 2442 4242 0000
0082 8282 4444 2828 1010 1010 1038 0000
007e 4204 0408 0810 1020 2040 427e 0000
2021-11-19 17:31:15 -05:00
&lc
2021-11-18 12:47:05 -05:00
0000 0000 0030 0808 3848 4848 4834 0000
0060 2020 202c 3222 2222 2222 322c 0000
0000 0000 001c 2240 4040 4040 221c 0000
000c 0404 0434 4c44 4444 4444 4c36 0000
0000 0000 0018 2424 3c20 2020 2418 0000
000c 1210 1038 1010 1010 1010 1038 0000
0000 0000 0034 4a48 4830 4038 4444 4438
00c0 4040 4058 6444 4444 4444 44ee 0000
0010 0000 0030 1010 1010 1010 1038 0000
0008 0000 0018 0808 0808 0808 0808 2810
0060 2020 2022 2224 2438 2424 2272 0000
0030 1010 1010 1010 1010 1010 1038 0000
0000 0000 00a4 da92 9292 9292 9292 0000
0000 0000 00d8 6444 4444 4444 44ee 0000
0000 0000 0038 4482 8282 8282 4438 0000
0000 0000 00d8 6442 4242 4242 6458 40e0
0000 0000 0034 4c84 8484 8484 4c34 040e
0000 0000 0068 3420 2020 2020 2070 0000
0000 0000 0018 2424 1008 0424 2418 0000
0010 1010 107c 1010 1010 1010 1408 0000
0000 0000 00cc 4444 4444 4444 4c36 0000
0000 0000 00ee 4444 4428 2828 1010 0000
0000 0000 0092 9292 9292 92aa 4444 0000
0000 0000 00ee 4428 1010 1028 44ee 0000
0000 0000 00ee 4444 4448 2828 1010 2040
0000 0000 007c 4408 0810 2020 447c 0000
2021-11-19 17:31:15 -05:00
&colon
0000 0000 0010 1000 0000 0000 1010 0000
&slash
0202 0404 0808 1010 2020 4040 8080 0000
&blank
0000 0000 0000 0000 0000 0000 0000 0000