Path: news.uiowa.edu!chi-news.cic.net!uwm.edu!lll-winken.llnl.gov!enews.sgi.com!news.mathworks.com!newsfeed.internetmci.com!news.uoregon.edu!cie-2.uoregon.edu!nparker From: nparker@cie-2.uoregon.edu (Neil Parker) Newsgroups: comp.sys.apple2 Subject: Re: Clock, BASIC, and IIgs Date: 12 Jun 1996 07:52:02 GMT Organization: University of Oregon Campus Information Exchange Lines: 86 Message-ID: <4plsv2$rml@pith.uoregon.edu> References: <4plje3$2td@news.nevada.edu> NNTP-Posting-Host: cie-2.uoregon.edu 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. The GS clock can provide one-second resolution. The easiest (and only Officially Suppored) way to get it is to call the Miscellaneous Toolset. Again, you need to CALL a machine-language routine: clc ; switch to native mode xce rep #$30 pha ; push space for result pha pha pha ldx #$0D03 ; ReadTimeHex jsl $E10000 sec ; back to emulation mode xce ldx #7 ; pop results and save l1 pla sta $200,X dex bpl l1 rts This routine leave the clock values in the following memory locations: PEEK(512) -- weekday (1..7, 1=Sunday) PEEK(513) -- (not used) PEEK(514) -- month (0..11) PEEK(515) -- day (0..30) PEEK(516) -- year minus 1900 PEEK(517) -- hour (0..23) PEEK(518) -- minute (0..59) PEEK(519) -- second (0..59) (Sorry...no BASIC example this time. I'm not feeling quite ambitious enough to hand-assemble that machine language and convert it to DATA statements.) - Neil Parker -- Neil Parker, nparker@{cie-2,cie}.uoregon.edu, http://cie-2.uoregon.edu/~nparker "Evolution is vastly overrated." -- Ambassador Delenn, _Babylon_5_