aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/common/lib/forth2012/facility/time-and-date.frt
diff options
context:
space:
mode:
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 )
+;