Index: README_new_time_commands.txt
===================================================================
--- README_new_time_commands.txt	(revision 0)
+++ README_new_time_commands.txt	(revision 0)
@@ -0,0 +1,38 @@
+This is a patch to the 'grand' branch of CHDK, as of 
+2007-08-13 22:48:11 -0700 (Mon, 13 Aug 2007) 
+(according to 'svn info'.)
+
+It adds two commands to uBasic.
+
+'get_day_seconds x' puts the seconds elapsed since midnight
+(in local time) into 'x'.
+
+'get_tick_count y' puts the ms elapsed since the camera was
+turned on into 'y'.
+
+The tick count seems to have 10ms resolution.
+
+get_tick_count p
+get_tick_count q
+print "tick count p is ", p
+print "tick count q is ", q
+
+... prints times 10ms apart.  With a print statement and a
+sleep 5 in between, the times are about 70ms apart.
+
+
+N.B. Although uBasic seems to handle 32-bit integers correctly,
+numeric literals seem to be limited to 6 digits.  so:
+
+rem ms in one hour
+rem this will fail...
+t=3600000
+
+rem but this is OK...
+t=3600
+t=t*1000
+
+
+Enjoy -
+Mike McCabe
+E-mail: nickname-for-michael at-sign mcca dot be
Index: include/platform.h
===================================================================
--- include/platform.h	(revision 200)
+++ include/platform.h	(working copy)
@@ -146,6 +146,9 @@
 
 int shooting_get_real_av();
 
+int shooting_get_day_seconds();
+int shooting_get_tick_count();
+
 extern int circle_of_confusion;
 
 extern const int zoom_points;
Index: platform/generic/shooting.c
===================================================================
--- platform/generic/shooting.c	(revision 200)
+++ platform/generic/shooting.c	(working copy)
@@ -3,6 +3,7 @@
 #include "core.h"
 #include "keyboard.h"
 #include "math.h"
+#include <stdlib.h>
 
 #define SS_SIZE (sizeof(shutter_speeds_table)/sizeof(shutter_speeds_table[0]))
 #define SSID_MIN (shutter_speeds_table[0].id)
@@ -102,6 +103,20 @@
     shooting_set_av(cv+v);
 }
 
+int shooting_get_day_seconds()
+{
+    unsigned long t;
+    struct tm *ttm;
+    t = time(NULL);
+    ttm = localtime(&t);
+    return ttm->tm_hour * 3600 + ttm->tm_min * 60;
+}
+
+int shooting_get_tick_count()
+{
+    return (int)get_tick_count();
+}
+
 int shooting_get_iso()
 {
     short int isov;
Index: version.inc
===================================================================
--- version.inc	(revision 200)
+++ version.inc	(working copy)
@@ -1 +1 @@
-BUILD_NUMBER := 148
+BUILD_NUMBER := 177
Index: lib/ubasic/tokenizer.h
===================================================================
--- lib/ubasic/tokenizer.h	(revision 200)
+++ lib/ubasic/tokenizer.h	(working copy)
@@ -86,6 +86,8 @@
   TOKENIZER_GET_AV,
   TOKENIZER_SET_AV,
   TOKENIZER_SET_AV_REL,
+  TOKENIZER_GET_DAY_SECONDS,
+  TOKENIZER_GET_TICK_COUNT,
   TOKENIZER_GET_ZOOM,
   TOKENIZER_SET_ZOOM,
   TOKENIZER_SET_ZOOM_REL,
Index: lib/ubasic/ubasic.c
===================================================================
--- lib/ubasic/ubasic.c	(revision 200)
+++ lib/ubasic/ubasic.c	(working copy)
@@ -713,6 +713,26 @@
     accept_cr();
 }
 
+static void get_day_seconds_statement()
+{
+    int var;
+    accept(TOKENIZER_GET_DAY_SECONDS);
+    var = tokenizer_variable_num();
+    accept(TOKENIZER_VARIABLE);
+    ubasic_set_variable(var, shooting_get_day_seconds());
+    accept_cr();
+}
+
+static void get_tick_count_statement()
+{
+    int var;
+    accept(TOKENIZER_GET_TICK_COUNT);
+    var = tokenizer_variable_num();
+    accept(TOKENIZER_VARIABLE);
+    ubasic_set_variable(var, shooting_get_tick_count());
+    accept_cr();
+}
+
 /*---------------------------------------------------------------------------*/
 
 static void get_zoom_statement()
@@ -883,6 +903,13 @@
     set_av_rel_statement();
     break;
 
+  case TOKENIZER_GET_DAY_SECONDS:
+    get_day_seconds_statement();
+    break;
+  case TOKENIZER_GET_TICK_COUNT:
+    get_tick_count_statement();
+    break;
+
   case TOKENIZER_GET_ZOOM:
     get_zoom_statement();
     break;
Index: lib/ubasic/tokenizer.c
===================================================================
--- lib/ubasic/tokenizer.c	(revision 200)
+++ lib/ubasic/tokenizer.c	(working copy)
@@ -96,6 +96,9 @@
   {"set_av_rel",    TOKENIZER_SET_AV_REL},
   {"set_av",        TOKENIZER_SET_AV},
 
+  {"get_day_seconds",   TOKENIZER_GET_DAY_SECONDS},
+  {"get_tick_count",    TOKENIZER_GET_TICK_COUNT},
+
   {"get_zoom",      TOKENIZER_GET_ZOOM},
   {"set_zoom_rel",  TOKENIZER_SET_ZOOM_REL},
   {"set_zoom_speed",TOKENIZER_SET_ZOOM_SPEED},
