[OpenBIOS] [PATCH] Adds the get-time word to the dictionary. Used to obtain the current time.

Tarl Neustaedter tarl-b2 at tarl.net
Sun Sep 23 19:53:27 CEST 2012


On 2012-Sep-23 13:26 , Programmingkid wrote:
> +
> +\ Returns the time  ( -- second minute hour day month year )
> +: get-time
> +   " get-time"           ( addr len )
> +   " rtc" open-dev   ( addr len device )
> +   dup	                   ( addr len device device )
> +
> +   0=  if   \ if the real-time clock isn't available
> +      cr
> +      3drop               ( )
> +      true                   ( flag )
> +      abort" Sorry but get-time isn't available for your system. "
> +   then
> +
> +   dup                      ( addr len device device )
> +   >R                        ( addr len device )          ( R: device )
> +   $call-method      ( addr len device -- )      ( R: device )
> +   R>                        ( device )                          ( R: )
> +   close-dev            ( device -- )
> +;
> +

Coding comments...

  * Rather than using "addr len" on the stack to represent the pointer
    to " get-time", for short strings, we might actually put the string
    itself in the comments. E.g., rather than ( addr len device ), you
    might see ( "get-time" device ). Alternatively, $xxxx by convention
    represents the two-cell pointer to a text string, so you might see (
    $get-time device ) as the stack comment.
  * But even better, rather than putting " get-time" on the stack at the
    top of the routine and having to carry it all the way down and play
    games with the stack, don't put it on the stack until you use it.
    Something like:


: get-time
    " rtc" open-dev                   ( ihandle )
    ?dup 0= if
       cr abort" Sorry but no rtc node is present on this system"
    then                              ( ihandle )
    >r " get-time" r@ $call-method    ( <returned args - 6 of em? Yikes > )
    r> close-dev                      ( <returned args> )
;




More information about the OpenBIOS mailing list