[comp.sys.apple] reading seconds from GS clock

AWCTTYPA@UIAMVS.BITNET ("David A. Lyons") (01/21/89)

>Date:         Thu, 19 Jan 89 00:25:58 GMT
>From:         Seymour Joseph <elbereth.rutgers.edu!joseph@RUTGERS.EDU>
>Subject:      Reading real time seconds from GS clock

>I need to be able to read the exact time from the GS clock. I bought
>the firmware reference, hardware reference and programmers
>introduction, but none of these manuals tell me how to read
>hours:minutes:seconds.
>
>Which manual do I need (oh no! not more $$$$$). and If it is easy,
>how do I do it?
>
>Thanks.
>Seymour

Heehee...you never have a complete collection of reference manuals
without the Toolbox References, volumes I and II (Addison-Wesley,
_Apple IIgs Toolbox Reference: Volume I_, etc).  Volume one, page
14-14 (meaning chapter 14, page 14) describes ReadTimeHex, which is
the tool call you need.  I don't know what language you're working
with, but in assembly it looks like the example below.  By the way,
you'll need to switch into native mode to make the tool call if
you don't already have the processor in native mode.  [The _system_
does _not_ have a native vs. emulation mode, but the 65816 does.  It
does a _lot_ of switching back and forth between those modes, too!]

To switch into native mode, use CLC, XCE, REP $30.  To switch back
to emulation mode use SEC XCE.

To make the ReadTimeHex call:

   PHA
   PHA
   PHA
   PHA         ;now we've pushed 8 bytes of room on the stack
   LDX #$0D03  ;code for ReadTimeHex
   JSL $E10000 ;call the tool dispatcher to make the call
   PLA
   STA WeekDay
   PLA
   STA MonthAndDay
   PLA
   STA YearAndHour
   PLA
   STA MinuteAndSecond

That's it.  Note that all of those values are 2 bytes wide, and that
each byte has a meaning.  It's not clear from the diagram I'm
staring at which bytes are which, so I'll let you figure it out
experimentally.  One of the bytes in the WeekDay value is unused,
and the other one has 1-7 for Sunday...Saturday.  The descriptin of
Year says "current year minus 1900," so I guess it's going to be 100
in 2000 instead of just being the last 2 digits of the year.

--David A. Lyons              bitnet: awcttypa@uiamvs
  DAL Systems                 CompuServe:  72177,3233
  P.O. Box 287                GEnie mail:    D.LYONS2
  North Liberty, IA 52317     AppleLinkPE: Dave Lyons