aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/common/lib/forth2012/facility/time-and-date.frt
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-08-19 12:15:28 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-08-19 12:15:28 +0200
commit67d25d837ac55f28a366c0a3b262e439a6e75fc3 (patch)
treedf7715c7724c5935ab87c807f3b8b4ef529315e3 /amforth-6.5/common/lib/forth2012/facility/time-and-date.frt
parente0d6784e89dba33226c0edb815bb974486fa7c48 (diff)
Add AmForth
Diffstat (limited to 'amforth-6.5/common/lib/forth2012/facility/time-and-date.frt')
-rw-r--r--amforth-6.5/common/lib/forth2012/facility/time-and-date.frt33
1 files changed, 33 insertions, 0 deletions
diff --git a/amforth-6.5/common/lib/forth2012/facility/time-and-date.frt b/amforth-6.5/common/lib/forth2012/facility/time-and-date.frt
new file mode 100644
index 0000000..aecbeff
--- /dev/null
+++ b/amforth-6.5/common/lib/forth2012/facility/time-and-date.frt
@@ -0,0 +1,33 @@
+
+
+\ common words for date&time
+
+\ uses timer interrrupt module to call
+\ a background task every second.
+
+\ holds the ever increasing time ticks
+\ unfortunatly, a day has more seconds
+\ a 16bit variable can store.
+2variable time \ the seconds of the current day
+2variable date \ a day number
+
+\ a background task
+: next-second
+ time 2@ 1. d+ 2dup
+ 86399. d> if
+ 2drop 0.
+ 1. date d+!
+ then
+ time 2!
+;
+
+: dateinit
+ 0. time 2!
+ 0. date 2!
+;
+
+\ simple world. Every month has 30 days
+: time&date ( -- sec min hour day month year )
+ date 2@ 365 um/mod 30 /mod ( -- day month year )
+ time 2@ 24 um/mod 60 /mod ( -- sec min hour )
+;