uxn/projects/examples/devices/datetime.tal

86 lines
1.6 KiB
Tal
Raw Normal View History

2023-07-16 14:41:44 -04:00
( usage: uxncli datetime.rom )
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
|0100
2023-07-16 14:41:44 -04:00
@on-reset ( -> )
<print-date>
#0a18 DEO
2023-07-16 14:41:44 -04:00
<print-time>
#0a18 DEO
<print-doty>
#0a18 DEO
#800f DEO
2023-07-16 14:41:44 -04:00
BRK
@<print-date> ( -- )
;dict/date <print-str>
[ LIT2 00 -DateTime/dotw ] DEI #20 SFT ;week-txt ADD2 <print-str>
[ LIT2 20 ", ] #18 DEO
#18 DEO
[ LIT2 00 -DateTime/month ] DEI #20 SFT ;month-txt ADD2 <print-str>
#2018 DEO
[ LIT2 00 -DateTime/day ] DEI <print-dec>
[ LIT2 20 ", ] #18 DEO
#18 DEO
.DateTime/year DEI2 !<print-dec>
@<print-time> ( -- )
;dict/time <print-str>
.DateTime/hour DEIk <print-dec-pad>
[ LIT2 ": 18 ] DEO
INC DEIk <print-dec-pad>
[ LIT2 ": 18 ] DEO
DEI !<print-dec-pad>
@<print-str> ( str* -- )
&w ( -- )
LDAk #18 DEO
INC2 LDAk ?&w
2023-07-16 14:41:44 -04:00
POP2 JMP2r
@<print-doty> ( -- )
;dict/doty <print-str>
.DateTime/doty DEI2
( >> )
@<print-dec> ( short* -- )
#2710 [ LIT2r 00fb ]
&w ( -- )
DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?&>skip
DUP <emit-dec>
INCr &>skip
POP2 #000a DIV2 SWPr INCr STHkr ?&w
POP2r POP2 POP2 JMP2r
@<print-dec-pad> ( byte -- )
#0a DIVk <emit-dec>
DIVk MUL SUB
( >> )
@<emit-dec> ( byte -- )
LIT "0 ADD #18 DEO
2023-07-16 14:41:44 -04:00
JMP2r
(
@|assets )
2023-07-16 14:41:44 -04:00
@week-txt
[
"Sun $1 "Mon $1 "Tue $1 "Wed $1
"Thu $1 "Fri $1 "Sat $1 ]
2023-07-16 14:41:44 -04: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 ]
2023-07-16 14:41:44 -04:00
@dict ( )
&date "The 20 "date 20 "is: 20 $1
&time "The 20 "time 20 "is: 20 $1
2023-04-16 17:51:00 -04:00
&doty "The 20 "day 20 "of 20 "the 20 "year 20 "is: 20 $1