[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Clock, BASIC, and IIgs



nparker@cie-2.uoregon.edu (Neil Parker) writes:
> In article <4plje3$2td@news.nevada.edu> snit@nevada.edu (Snit) writes:
> >Does anybody know how to access the clock from BASIC on a IIgs?  Is
> >there a way of doing something similaron a IIe (obviosly not wth the
> >real time, unless you have a clock added).  Specificly, I am trying to
> >record the times of a photosensor attached to PDL (0) into a text file
> >that can be imported into a spreadsheet or stats program.  Thanks...
> 
> There are no BASIC commands for accessing the clock--the only good way to
> do it is to call a machine-language routine.
> 
> The most portable way to access the clock is through ProDOS.  Your BASIC
> program calls this machine-language routine:
> 
>      JSR $BF00
>      DFB $82     ; GET_TIME
>      DW  0
>      RTS
> 
> Then you can PEEK the time and date out of the ProDOS global page.  The
> minute is PEEK(49042), and the hour is PEEK(49043).  The date is in
> PEEK(49040) and PEEK(49041), but after PEEKing it, you have to unpack it
> before you can use it (see the example below).
> 
>      10  FOR X = 0 TO 6: READ Y: POKE 768 + X,Y: NEXT
>      20  DATA 32,0,191,130,0,0,96: REM Machine code
>      30  CALL 768
>      40 HR =  PEEK (49043): REM Hour (0..23)
>      50 MI =  PEEK (49042): REM Minute (0..59)
>      60 D =  PEEK (49040) + 256 *  PEEK (49041)
>      70 X =  INT (D / 32)
>      80 DA =  D - 32 * X: REM Day (1..31)
>      90 D = X:X = INT (D / 16)
>      100 MO =  D - 16 * X: REM Month (1..12)
>      110 YR = X + 1940: REM Year (1940..2039)
> 
> If the day and the month are both zero, then either no clock is available,
> or ProDOS doesn't have a driver for the clock.
> 
> The drawback of this method, of course, is that you only get one-minute
> resolution.  If you want to time events more accurately than that, you'll
> have to use more complicated methods.
> 
[snip]

if files need not to be kept open there is a purely Basic
solution without installing a machine-language routine.

Some BASIC.SYSTEM commands like CLOSE or FLUSH automatically
do a GET_TIME call. Thus if you replace lines 10 through 30
by, for instance,

        10 PRINT CHR$(4) "CLOSE"

BASIC.SYSTEM will update the ProDOS locations 49040 through
49043 for you, and you can pick up date/time as suggested.

Works for me like a charm in several data-logging applications
also on a IIe with THUNDERCLOCK card.

Kasper Zechel     kzechel@gwdg.de