head     56.3;
access   paws bayes jws quist brad dew jwh;
symbols  ;
locks    ; strict;
comment  @# @;


56.3
date     93.01.27.13.17.00;  author jwh;  state Exp;
branches ;
next     56.2;

56.2
date     93.01.27.11.58.28;  author jwh;  state Exp;
branches ;
next     56.1;

56.1
date     91.11.05.09.54.06;  author jwh;  state Exp;
branches ;
next     55.1;

55.1
date     91.08.25.10.29.28;  author jwh;  state Exp;
branches ;
next     54.3;

54.3
date     91.08.21.10.33.04;  author jwh;  state Exp;
branches ;
next     54.2;

54.2
date     91.08.21.09.38.06;  author jwh;  state Exp;
branches ;
next     54.1;

54.1
date     91.03.18.15.31.37;  author jwh;  state Exp;
branches ;
next     53.1;

53.1
date     91.03.11.19.31.31;  author jwh;  state Exp;
branches ;
next     52.1;

52.1
date     91.02.19.09.16.07;  author jwh;  state Exp;
branches ;
next     51.1;

51.1
date     91.01.30.16.15.40;  author jwh;  state Exp;
branches ;
next     50.1;

50.1
date     90.10.29.16.30.13;  author jwh;  state Exp;
branches ;
next     49.1;

49.1
date     90.08.14.14.14.00;  author jwh;  state Exp;
branches ;
next     48.1;

48.1
date     90.07.26.11.20.18;  author jwh;  state Exp;
branches ;
next     47.1;

47.1
date     90.05.14.11.04.33;  author dew;  state Exp;
branches ;
next     46.1;

46.1
date     90.05.07.08.51.39;  author jwh;  state Exp;
branches ;
next     45.1;

45.1
date     90.04.19.15.59.35;  author jwh;  state Exp;
branches ;
next     44.1;

44.1
date     90.04.01.22.16.40;  author jwh;  state Exp;
branches ;
next     43.1;

43.1
date     90.03.20.14.09.06;  author jwh;  state Exp;
branches ;
next     42.1;

42.1
date     90.01.23.17.53.28;  author jwh;  state Exp;
branches ;
next     41.1;

41.1
date     89.12.22.11.35.43;  author jwh;  state Exp;
branches ;
next     40.1;

40.1
date     89.09.29.11.56.59;  author jwh;  state Exp;
branches ;
next     39.1;

39.1
date     89.09.26.16.41.47;  author dew;  state Exp;
branches ;
next     38.1;

38.1
date     89.08.29.11.33.37;  author jwh;  state Exp;
branches ;
next     37.1;

37.1
date     89.05.12.11.47.23;  author dew;  state Exp;
branches ;
next     36.1;

36.1
date     89.02.06.10.25.06;  author dew;  state Exp;
branches ;
next     35.1;

35.1
date     89.02.02.13.40.23;  author dew;  state Exp;
branches ;
next     34.1;

34.1
date     89.01.23.16.15.37;  author jwh;  state Exp;
branches ;
next     33.1;

33.1
date     89.01.16.11.47.16;  author dew;  state Exp;
branches ;
next     32.1;

32.1
date     89.01.10.11.56.09;  author bayes;  state Exp;
branches ;
next     31.1;

31.1
date     88.12.14.18.17.12;  author bayes;  state Exp;
branches ;
next     30.1;

30.1
date     88.12.09.13.54.15;  author dew;  state Exp;
branches ;
next     29.1;

29.1
date     88.10.31.15.38.54;  author bayes;  state Exp;
branches ;
next     28.1;

28.1
date     88.10.06.11.05.12;  author dew;  state Exp;
branches ;
next     27.1;

27.1
date     88.09.29.11.47.48;  author bayes;  state Exp;
branches ;
next     26.4;

26.4
date     88.09.28.13.29.02;  author bayes;  state Exp;
branches ;
next     26.3;

26.3
date     88.09.28.13.28.51;  author bayes;  state Exp;
branches ;
next     26.2;

26.2
date     88.09.28.13.28.41;  author bayes;  state Exp;
branches ;
next     26.1;

26.1
date     88.09.28.13.28.29;  author bayes;  state Exp;
branches ;
next     24.1;

24.1
date     87.08.31.10.09.26;  author jws;  state Exp;
branches ;
next     23.1;

23.1
date     87.08.26.10.51.09;  author bayes;  state Exp;
branches ;
next     22.1;

22.1
date     87.08.17.11.34.04;  author bayes;  state Exp;
branches ;
next     21.1;

21.1
date     87.08.12.14.17.43;  author bayes;  state Exp;
branches ;
next     20.1;

20.1
date     87.07.30.11.29.45;  author bayes;  state Exp;
branches ;
next     19.1;

19.1
date     87.06.01.08.42.23;  author jws;  state Exp;
branches ;
next     18.1;

18.1
date     87.05.20.15.46.49;  author bayes;  state Exp;
branches ;
next     17.1;

17.1
date     87.04.30.10.53.57;  author jws;  state Exp;
branches ;
next     16.1;

16.1
date     87.04.26.16.04.38;  author jws;  state Exp;
branches ;
next     15.1;

15.1
date     87.04.13.09.43.48;  author jws;  state Exp;
branches ;
next     14.1;

14.1
date     87.04.01.15.51.50;  author jws;  state Exp;
branches ;
next     13.2;

13.2
date     87.03.31.09.33.37;  author jws;  state Exp;
branches ;
next     13.1;

13.1
date     87.02.28.18.48.12;  author jws;  state Exp;
branches ;
next     12.1;

12.1
date     87.02.02.13.40.34;  author jws;  state Exp;
branches ;
next     11.1;

11.1
date     87.01.19.10.07.21;  author jws;  state Exp;
branches ;
next     10.1;

10.1
date     86.12.24.11.21.53;  author jws;  state Exp;
branches ;
next     9.1;

9.1
date     86.12.12.15.04.31;  author bayes;  state Exp;
branches ;
next     8.1;

8.1
date     86.11.27.12.15.54;  author jws;  state Exp;
branches ;
next     7.1;

7.1
date     86.11.20.14.24.11;  author hal;  state Exp;
branches ;
next     6.1;

6.1
date     86.11.04.18.20.04;  author paws;  state Exp;
branches ;
next     5.1;

5.1
date     86.10.28.17.08.13;  author hal;  state Exp;
branches ;
next     4.1;

4.1
date     86.10.13.15.56.07;  author geli;  state Exp;
branches ;
next     3.1;

3.1
date     86.10.13.15.54.44;  author geli;  state Exp;
branches ;
next     2.1;

2.1
date     86.10.13.15.53.25;  author geli;  state Exp;
branches ;
next     1.2;

1.2
date     86.10.13.15.51.32;  author geli;  state Exp;
branches ;
next     1.1;

1.1
date     86.10.13.15.50.05;  author geli;  state tmp;
branches ;
next     ;


desc
@Base file for PWS 3.2 release.

@


56.3
log
@
pws2rcs automatic delta on Wed Jan 27 13:14:25 MST 1993
@
text
@					       (*

 (c) Copyright Hewlett-Packard Company, 1986.
All rights are reserved.  Copying or other
reproduction of this program except for archival
purposes is prohibited without the prior
written consent of Hewlett-Packard Company.


	    RESTRICTED RIGHTS LEGEND

Use, duplication, or disclosure by the Government
is subject to restrictions as set forth in
paragraph (b) (3) (B) of the Rights in Technical
Data and Computer Software clause in
DAR 7-104.9(a).

HEWLETT-PACKARD COMPANY
Fort Collins, Colorado                         *)


$modcal$
$heap_dispose off$
$iocheck off$
$range off$ $ovflcheck off$
$debug off$
$stackcheck off$
$search  'INITLOAD','ASM','INIT','SYSDEVS'$

program clockinit(OUTPUT);

module clock;
import sysglobals, asm, misc, sysdevs;
export procedure initclock;

implement

const
  {LAF 870310}
  date_base_offset =    { days between 1-Mar-00 and 1-Jan-70 }
    (365*4+1)*17        { add 68 years:     we're at 1-Mar-68 }
    +365*2              { add 2 more years: we're at 1-Mar-70 }
    -31-28;             { subtract January and February 1970:
					    we're at 1-Jan-70 }

type trickint = packed record
		   case integer of
		0: ( ipart: integer );
		1: ( byte3: byte;
		     byte2: byte;
		     byte1: byte;
		     byte0: byte  )
	       end;

var  boottype[-576]: shortint;

procedure dosysdate(var thedate: daterec);
var yr,dd,mm,k,k1,k2: integer;
    ltime:  rtctime;

type
  day_month = array[0..12] of integer;
const
  day_tab = day_month[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


var days: integer;
    daysinmonth: integer;
    daysinyear: integer;
    done: boolean;

begin
  CALL(CLOCKIOHOOK,CGET,LTIME);

  with thedate do begin
    days:= ltime.packeddate;

    {Generate the year from date number}
    {RDQ 14MAR88 recoded to use isleap function and
	 to correct 1 JAN two years after leap year bug}
    year:=70;
    daysinyear := 365 + isleap(year);
    while days>=daysinyear do
    begin
      days:=days-daysinyear;
      year:=year+1;
      daysinyear := 365 + isleap(year);
    end;

    {LAF 880101 proper range is now 0..127}
    {year:=year mod 100; {get it into proper range}

    {Generate month from remaining days}
    {RDQ 14MAR88 recoded to use isleap function}
    month:=0;
    done:=false;
    repeat
      daysinmonth:=day_tab[month];
      if (month=2) then daysinmonth:=daysinmonth + isleap(year);
      if days>=daysinmonth then
      begin
	days:=days-daysinmonth;
	month:=month+1
      end
      else done:=true;
    until done;

    {days is now offset into month}
    day:=days+1;
  end; {of with}
end;

procedure dosystime(var thetime: timerec);
var t: integer;
begin
  t:=sysclock mod (24*360000);
  with thetime do
    begin
      hour := t div 360000;
      minute := (t-(hour*360000)) div 6000;
      centisecond := t mod 6000;
    end;
end;

procedure setrtctime(thetime: rtctime);
const
  cmmdb7=183;
  cmmd40=64;
var
  t1,t2: trickint;
  TTIME: RTCTIME;
begin
  TTIME:=THETIME; CALL(CLOCKIOHOOK,CSET,TTIME);
    {LAF 870310 3.2G   The following adjustment converts the time
     from 1-Jan-70 base in the 8042 RTC
       to 1-Mar-00 base in the battery backed clock}
  t1.ipart := thetime.packeddate+date_base_offset;
  t2.ipart := thetime.packedtime;
  batcommand(cmmdb7,5,t1.byte1,t1.byte0,t2.byte2,t2.byte1,t2.byte0);
  batcommand(cmmd40,0,0,0,0,0,0);
end;    { setrtctime }

procedure dosetsysdate(thedate: daterec);

type
  day_month = array [0..12] of integer;
  table = array[0..1] of day_month;
const
 day_tab = table[ day_month[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
		 day_month[0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]];

var   ltime: rtctime;
      i : integer;
{RDQ 14MAR88 import isleap from SYSDEVS }
begin
  CALL(CLOCKIOHOOK,CGET,LTIME);
  ltime.packeddate:=0; {default value}
  with ltime, thedate do begin
    if ( month <> 0 ) and ( year >= 70 ) then begin
      for i:=70 to (year-1) do
      begin
	packeddate:= packeddate + 365 + isleap(i);
      end;
      for i:=1 to (month-1) do
      begin
	 packeddate:= packeddate + day_tab[isleap(year)][i];
      end;
      packeddate:= packeddate + day-1;
    end;
  end; {with}
  setrtctime(ltime);
end;

procedure dosetsystime(thetime: timerec);
var   ltime: rtctime;  hr,min,ctsec: integer;
begin
  CALL(CLOCKIOHOOK,CGET,LTIME);
  with ltime, thetime do
    begin
      hr := hour;  min := minute;  ctsec := centisecond;
      packedtime:=((hr*3600)+min*60)*100+ctsec;
    end;
  setrtctime(ltime);
end;

{added for 3.2}
procedure dosetzone(thezone: timerec);
var
  ltime: rtctime;
  negative: boolean; {kludge for negative tz}
begin
  if (thezone.centisecond mod 100)<>0 then begin
    negative:=true;
    thezone.centisecond:=(thezone.centisecond div 100)*100;
  end
  else
    negative:=false;
  ltime.packedtime:=thezone.hour*3600 + thezone.minute*60
		    +thezone.centisecond div 100;
  if negative then ltime.packedtime:=-ltime.packedtime;
  timezone:=ltime.packedtime;
  call(clockiohook, ctz, ltime);
  call(clockiohook, cget, ltime);
  setrtctime(ltime); {because local time may have changed}
end;

procedure inittime;
var thetime:rtctime;
const
  cmmd41=65;                    {65 hex to load timer output buffer with time}
  cmmdf7=247;                   {F7 hex to load data buffer with first byte}
  cmmdf6=246;                   {F6 hex to load data buffer with second byte}
  cmmdf5=245;                   {F5 hex to load data buffer with third  byte}
  cmmdf4=244;                   {F4 hex to load data buffer with fourth byte}
  cmmdf3=243;                   {F3 hex to load data buffer with fifth  byte}
  cmmdf2=242;                   {F2 hex to load a letter 'B',or'P', or'H' for
					 Basic, or Pascal, or HPL respectively}
var  t: trickint;
begin {inittime}
  thetime.packedtime := 0;
  thetime.packeddate := 0;
  if batterypresent then
   with t do
    begin
    setintlevel(2);

    ipart := 0;
    batcommand(cmmd41,0,0,0,0,0,0);
    batcommand(cmmdf7,0,0,0,0,0,0);   byte1 := batbytereceived;
    batcommand(cmmdf6,0,0,0,0,0,0);   byte0 := batbytereceived;
      {LAF 870310 3.2G   The following adjustment converts the time
       from 1-Mar-00 base in the battery backed clock
	 to 1-Jan-70 base in the 8042 RTC}
    thetime.packeddate := ipart-date_base_offset;

    ipart := 0;
    batcommand(cmmdf5,0,0,0,0,0,0);   byte2 := batbytereceived;
    batcommand(cmmdf4,0,0,0,0,0,0);   byte1 := batbytereceived;
    batcommand(cmmdf3,0,0,0,0,0,0);   byte0 := batbytereceived;
    thetime.packedtime := ipart;

    setintlevel(0);{lower cpu int level}
    end
   else
    call(clockiohook, cupdate, thetime);       {SFB 4/11/85}

  setrtctime(thetime);
end;    { inittime }

PROCEDURE DOCLOCKOPS(CMD:CLOCKFUNC; ANYVAR DATA: CLOCKDATA);
BEGIN
  CASE CMD OF
  CGETDATE: DOSYSDATE(DATA.DATETYPE);
  CGETTIME: DOSYSTIME(DATA.TIMETYPE);
  CSETDATE: DOSETSYSDATE(DATA.DATETYPE);
  CSETTIME: DOSETSYSTIME(DATA.TIMETYPE);
  CSETZONE: DOSETZONE(DATA.TIMETYPE);
  END;
END;

procedure initclock;
begin
  inittime;
  CLOCKREQHOOK:=DOCLOCKOPS;
end;

end; { module clock }

import clock, loader;

begin
  initclock;
  markuser;
end.

@


56.2
log
@
pws2rcs automatic delta on Wed Jan 27 11:57:27 MST 1993
@
text
@d1 275
@


56.1
log
@Automatic bump of revision number for PWS version 3.25
@
text
@a0 275
					       (*

 (c) Copyright Hewlett-Packard Company, 1986.
All rights are reserved.  Copying or other
reproduction of this program except for archival
purposes is prohibited without the prior
written consent of Hewlett-Packard Company.


	    RESTRICTED RIGHTS LEGEND

Use, duplication, or disclosure by the Government
is subject to restrictions as set forth in
paragraph (b) (3) (B) of the Rights in Technical
Data and Computer Software clause in
DAR 7-104.9(a).

HEWLETT-PACKARD COMPANY
Fort Collins, Colorado                         *)


$modcal$
$heap_dispose off$
$iocheck off$
$range off$ $ovflcheck off$
$debug off$
$stackcheck off$
$search  'INITLOAD','ASM','INIT','SYSDEVS'$

program clockinit(OUTPUT);

module clock;
import sysglobals, asm, misc, sysdevs;
export procedure initclock;

implement

const
  {LAF 870310}
  date_base_offset =    { days between 1-Mar-00 and 1-Jan-70 }
    (365*4+1)*17        { add 68 years:     we're at 1-Mar-68 }
    +365*2              { add 2 more years: we're at 1-Mar-70 }
    -31-28;             { subtract January and February 1970:
					    we're at 1-Jan-70 }

type trickint = packed record
		   case integer of
		0: ( ipart: integer );
		1: ( byte3: byte;
		     byte2: byte;
		     byte1: byte;
		     byte0: byte  )
	       end;

var  boottype[-576]: shortint;

procedure dosysdate(var thedate: daterec);
var yr,dd,mm,k,k1,k2: integer;
    ltime:  rtctime;

type
  day_month = array[0..12] of integer;
const
  day_tab = day_month[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


var days: integer;
    daysinmonth: integer;
    daysinyear: integer;
    done: boolean;

begin
  CALL(CLOCKIOHOOK,CGET,LTIME);

  with thedate do begin
    days:= ltime.packeddate;

    {Generate the year from date number}
    {RDQ 14MAR88 recoded to use isleap function and
	 to correct 1 JAN two years after leap year bug}
    year:=70;
    daysinyear := 365 + isleap(year);
    while days>=daysinyear do
    begin
      days:=days-daysinyear;
      year:=year+1;
      daysinyear := 365 + isleap(year);
    end;

    {LAF 880101 proper range is now 0..127}
    {year:=year mod 100; {get it into proper range}

    {Generate month from remaining days}
    {RDQ 14MAR88 recoded to use isleap function}
    month:=0;
    done:=false;
    repeat
      daysinmonth:=day_tab[month];
      if (month=2) then daysinmonth:=daysinmonth + isleap(year);
      if days>=daysinmonth then
      begin
	days:=days-daysinmonth;
	month:=month+1
      end
      else done:=true;
    until done;

    {days is now offset into month}
    day:=days+1;
  end; {of with}
end;

procedure dosystime(var thetime: timerec);
var t: integer;
begin
  t:=sysclock mod (24*360000);
  with thetime do
    begin
      hour := t div 360000;
      minute := (t-(hour*360000)) div 6000;
      centisecond := t mod 6000;
    end;
end;

procedure setrtctime(thetime: rtctime);
const
  cmmdb7=183;
  cmmd40=64;
var
  t1,t2: trickint;
  TTIME: RTCTIME;
begin
  TTIME:=THETIME; CALL(CLOCKIOHOOK,CSET,TTIME);
    {LAF 870310 3.2G   The following adjustment converts the time
     from 1-Jan-70 base in the 8042 RTC
       to 1-Mar-00 base in the battery backed clock}
  t1.ipart := thetime.packeddate+date_base_offset;
  t2.ipart := thetime.packedtime;
  batcommand(cmmdb7,5,t1.byte1,t1.byte0,t2.byte2,t2.byte1,t2.byte0);
  batcommand(cmmd40,0,0,0,0,0,0);
end;    { setrtctime }

procedure dosetsysdate(thedate: daterec);

type
  day_month = array [0..12] of integer;
  table = array[0..1] of day_month;
const
 day_tab = table[ day_month[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
		 day_month[0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]];

var   ltime: rtctime;
      i : integer;
{RDQ 14MAR88 import isleap from SYSDEVS }
begin
  CALL(CLOCKIOHOOK,CGET,LTIME);
  ltime.packeddate:=0; {default value}
  with ltime, thedate do begin
    if ( month <> 0 ) and ( year >= 70 ) then begin
      for i:=70 to (year-1) do
      begin
	packeddate:= packeddate + 365 + isleap(i);
      end;
      for i:=1 to (month-1) do
      begin
	 packeddate:= packeddate + day_tab[isleap(year)][i];
      end;
      packeddate:= packeddate + day-1;
    end;
  end; {with}
  setrtctime(ltime);
end;

procedure dosetsystime(thetime: timerec);
var   ltime: rtctime;  hr,min,ctsec: integer;
begin
  CALL(CLOCKIOHOOK,CGET,LTIME);
  with ltime, thetime do
    begin
      hr := hour;  min := minute;  ctsec := centisecond;
      packedtime:=((hr*3600)+min*60)*100+ctsec;
    end;
  setrtctime(ltime);
end;

{added for 3.2}
procedure dosetzone(thezone: timerec);
var
  ltime: rtctime;
  negative: boolean; {kludge for negative tz}
begin
  if (thezone.centisecond mod 100)<>0 then begin
    negative:=true;
    thezone.centisecond:=(thezone.centisecond div 100)*100;
  end
  else
    negative:=false;
  ltime.packedtime:=thezone.hour*3600 + thezone.minute*60
		    +thezone.centisecond div 100;
  if negative then ltime.packedtime:=-ltime.packedtime;
  timezone:=ltime.packedtime;
  call(clockiohook, ctz, ltime);
  call(clockiohook, cget, ltime);
  setrtctime(ltime); {because local time may have changed}
end;

procedure inittime;
var thetime:rtctime;
const
  cmmd41=65;                    {65 hex to load timer output buffer with time}
  cmmdf7=247;                   {F7 hex to load data buffer with first byte}
  cmmdf6=246;                   {F6 hex to load data buffer with second byte}
  cmmdf5=245;                   {F5 hex to load data buffer with third  byte}
  cmmdf4=244;                   {F4 hex to load data buffer with fourth byte}
  cmmdf3=243;                   {F3 hex to load data buffer with fifth  byte}
  cmmdf2=242;                   {F2 hex to load a letter 'B',or'P', or'H' for
					 Basic, or Pascal, or HPL respectively}
var  t: trickint;
begin {inittime}
  thetime.packedtime := 0;
  thetime.packeddate := 0;
  if batterypresent then
   with t do
    begin
    setintlevel(2);

    ipart := 0;
    batcommand(cmmd41,0,0,0,0,0,0);
    batcommand(cmmdf7,0,0,0,0,0,0);   byte1 := batbytereceived;
    batcommand(cmmdf6,0,0,0,0,0,0);   byte0 := batbytereceived;
      {LAF 870310 3.2G   The following adjustment converts the time
       from 1-Mar-00 base in the battery backed clock
	 to 1-Jan-70 base in the 8042 RTC}
    thetime.packeddate := ipart-date_base_offset;

    ipart := 0;
    batcommand(cmmdf5,0,0,0,0,0,0);   byte2 := batbytereceived;
    batcommand(cmmdf4,0,0,0,0,0,0);   byte1 := batbytereceived;
    batcommand(cmmdf3,0,0,0,0,0,0);   byte0 := batbytereceived;
    thetime.packedtime := ipart;

    setintlevel(0);{lower cpu int level}
    end
   else
    call(clockiohook, cupdate, thetime);       {SFB 4/11/85}

  setrtctime(thetime);
end;    { inittime }

PROCEDURE DOCLOCKOPS(CMD:CLOCKFUNC; ANYVAR DATA: CLOCKDATA);
BEGIN
  CASE CMD OF
  CGETDATE: DOSYSDATE(DATA.DATETYPE);
  CGETTIME: DOSYSTIME(DATA.TIMETYPE);
  CSETDATE: DOSETSYSDATE(DATA.DATETYPE);
  CSETTIME: DOSETSYSTIME(DATA.TIMETYPE);
  CSETZONE: DOSETZONE(DATA.TIMETYPE);
  END;
END;

procedure initclock;
begin
  inittime;
  CLOCKREQHOOK:=DOCLOCKOPS;
end;

end; { module clock }

import clock, loader;

begin
  initclock;
  markuser;
end.

@


55.1
log
@Automatic bump of revision number for PWS version 3.25A
@
text
@@


54.3
log
@
pws2rcs automatic delta on Wed Aug 21 10:27:27 MDT 1991
@
text
@@


54.2
log
@
pws2rcs automatic delta on Wed Aug 21 09:35:48 MDT 1991
@
text
@d1 275
@


54.1
log
@Automatic bump of revision number for PWS version 3.24
@
text
@a0 275
					       (*

 (c) Copyright Hewlett-Packard Company, 1986.
All rights are reserved.  Copying or other
reproduction of this program except for archival
purposes is prohibited without the prior
written consent of Hewlett-Packard Company.


	    RESTRICTED RIGHTS LEGEND

Use, duplication, or disclosure by the Government
is subject to restrictions as set forth in
paragraph (b) (3) (B) of the Rights in Technical
Data and Computer Software clause in
DAR 7-104.9(a).

HEWLETT-PACKARD COMPANY
Fort Collins, Colorado                         *)


$modcal$
$heap_dispose off$
$iocheck off$
$range off$ $ovflcheck off$
$debug off$
$stackcheck off$
$search  'INITLOAD','ASM','INIT','SYSDEVS'$

program clockinit(OUTPUT);

module clock;
import sysglobals, asm, misc, sysdevs;
export procedure initclock;

implement

const
  {LAF 870310}
  date_base_offset =    { days between 1-Mar-00 and 1-Jan-70 }
    (365*4+1)*17        { add 68 years:     we're at 1-Mar-68 }
    +365*2              { add 2 more years: we're at 1-Mar-70 }
    -31-28;             { subtract January and February 1970:
					    we're at 1-Jan-70 }

type trickint = packed record
		   case integer of
		0: ( ipart: integer );
		1: ( byte3: byte;
		     byte2: byte;
		     byte1: byte;
		     byte0: byte  )
	       end;

var  boottype[-576]: shortint;

procedure dosysdate(var thedate: daterec);
var yr,dd,mm,k,k1,k2: integer;
    ltime:  rtctime;

type
  day_month = array[0..12] of integer;
const
  day_tab = day_month[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


var days: integer;
    daysinmonth: integer;
    daysinyear: integer;
    done: boolean;

begin
  CALL(CLOCKIOHOOK,CGET,LTIME);

  with thedate do begin
    days:= ltime.packeddate;

    {Generate the year from date number}
    {RDQ 14MAR88 recoded to use isleap function and
	 to correct 1 JAN two years after leap year bug}
    year:=70;
    daysinyear := 365 + isleap(year);
    while days>=daysinyear do
    begin
      days:=days-daysinyear;
      year:=year+1;
      daysinyear := 365 + isleap(year);
    end;

    {LAF 880101 proper range is now 0..127}
    {year:=year mod 100; {get it into proper range}

    {Generate month from remaining days}
    {RDQ 14MAR88 recoded to use isleap function}
    month:=0;
    done:=false;
    repeat
      daysinmonth:=day_tab[month];
      if (month=2) then daysinmonth:=daysinmonth + isleap(year);
      if days>=daysinmonth then
      begin
	days:=days-daysinmonth;
	month:=month+1
      end
      else done:=true;
    until done;

    {days is now offset into month}
    day:=days+1;
  end; {of with}
end;

procedure dosystime(var thetime: timerec);
var t: integer;
begin
  t:=sysclock mod (24*360000);
  with thetime do
    begin
      hour := t div 360000;
      minute := (t-(hour*360000)) div 6000;
      centisecond := t mod 6000;
    end;
end;

procedure setrtctime(thetime: rtctime);
const
  cmmdb7=183;
  cmmd40=64;
var
  t1,t2: trickint;
  TTIME: RTCTIME;
begin
  TTIME:=THETIME; CALL(CLOCKIOHOOK,CSET,TTIME);
    {LAF 870310 3.2G   The following adjustment converts the time
     from 1-Jan-70 base in the 8042 RTC
       to 1-Mar-00 base in the battery backed clock}
  t1.ipart := thetime.packeddate+date_base_offset;
  t2.ipart := thetime.packedtime;
  batcommand(cmmdb7,5,t1.byte1,t1.byte0,t2.byte2,t2.byte1,t2.byte0);
  batcommand(cmmd40,0,0,0,0,0,0);
end;    { setrtctime }

procedure dosetsysdate(thedate: daterec);

type
  day_month = array [0..12] of integer;
  table = array[0..1] of day_month;
const
 day_tab = table[ day_month[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
		 day_month[0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]];

var   ltime: rtctime;
      i : integer;
{RDQ 14MAR88 import isleap from SYSDEVS }
begin
  CALL(CLOCKIOHOOK,CGET,LTIME);
  ltime.packeddate:=0; {default value}
  with ltime, thedate do begin
    if ( month <> 0 ) and ( year >= 70 ) then begin
      for i:=70 to (year-1) do
      begin
	packeddate:= packeddate + 365 + isleap(i);
      end;
      for i:=1 to (month-1) do
      begin
	 packeddate:= packeddate + day_tab[isleap(year)][i];
      end;
      packeddate:= packeddate + day-1;
    end;
  end; {with}
  setrtctime(ltime);
end;

procedure dosetsystime(thetime: timerec);
var   ltime: rtctime;  hr,min,ctsec: integer;
begin
  CALL(CLOCKIOHOOK,CGET,LTIME);
  with ltime, thetime do
    begin
      hr := hour;  min := minute;  ctsec := centisecond;
      packedtime:=((hr*3600)+min*60)*100+ctsec;
    end;
  setrtctime(ltime);
end;

{added for 3.2}
procedure dosetzone(thezone: timerec);
var
  ltime: rtctime;
  negative: boolean; {kludge for negative tz}
begin
  if (thezone.centisecond mod 100)<>0 then begin
    negative:=true;
    thezone.centisecond:=(thezone.centisecond div 100)*100;
  end
  else
    negative:=false;
  ltime.packedtime:=thezone.hour*3600 + thezone.minute*60
		    +thezone.centisecond div 100;
  if negative then ltime.packedtime:=-ltime.packedtime;
  timezone:=ltime.packedtime;
  call(clockiohook, ctz, ltime);
  call(clockiohook, cget, ltime);
  setrtctime(ltime); {because local time may have changed}
end;

procedure inittime;
var thetime:rtctime;
const
  cmmd41=65;                    {65 hex to load timer output buffer with time}
  cmmdf7=247;                   {F7 hex to load data buffer with first byte}
  cmmdf6=246;                   {F6 hex to load data buffer with second byte}
  cmmdf5=245;                   {F5 hex to load data buffer with third  byte}
  cmmdf4=244;                   {F4 hex to load data buffer with fourth byte}
  cmmdf3=243;                   {F3 hex to load data buffer with fifth  byte}
  cmmdf2=242;                   {F2 hex to load a letter 'B',or'P', or'H' for
					 Basic, or Pascal, or HPL respectively}
var  t: trickint;
begin {inittime}
  thetime.packedtime := 0;
  thetime.packeddate := 0;
  if batterypresent then
   with t do
    begin
    setintlevel(2);

    ipart := 0;
    batcommand(cmmd41,0,0,0,0,0,0);
    batcommand(cmmdf7,0,0,0,0,0,0);   byte1 := batbytereceived;
    batcommand(cmmdf6,0,0,0,0,0,0);   byte0 := batbytereceived;
      {LAF 870310 3.2G   The following adjustment converts the time
       from 1-Mar-00 base in the battery backed clock
	 to 1-Jan-70 base in the 8042 RTC}
    thetime.packeddate := ipart-date_base_offset;

    ipart := 0;
    batcommand(cmmdf5,0,0,0,0,0,0);   byte2 := batbytereceived;
    batcommand(cmmdf4,0,0,0,0,0,0);   byte1 := batbytereceived;
    batcommand(cmmdf3,0,0,0,0,0,0);   byte0 := batbytereceived;
    thetime.packedtime := ipart;

    setintlevel(0);{lower cpu int level}
    end
   else
    call(clockiohook, cupdate, thetime);       {SFB 4/11/85}

  setrtctime(thetime);
end;    { inittime }

PROCEDURE DOCLOCKOPS(CMD:CLOCKFUNC; ANYVAR DATA: CLOCKDATA);
BEGIN
  CASE CMD OF
  CGETDATE: DOSYSDATE(DATA.DATETYPE);
  CGETTIME: DOSYSTIME(DATA.TIMETYPE);
  CSETDATE: DOSETSYSDATE(DATA.DATETYPE);
  CSETTIME: DOSETSYSTIME(DATA.TIMETYPE);
  CSETZONE: DOSETZONE(DATA.TIMETYPE);
  END;
END;

procedure initclock;
begin
  inittime;
  CLOCKREQHOOK:=DOCLOCKOPS;
end;

end; { module clock }

import clock, loader;

begin
  initclock;
  markuser;
end.

@


53.1
log
@Automatic bump of revision number for PWS version 3.24B
@
text
@@


52.1
log
@Automatic bump of revision number for PWS version 3.24A
@
text
@@


51.1
log
@Automatic bump of revision number for PWS version 3.24d
@
text
@@


50.1
log
@Automatic bump of revision number for PWS version 3.23c
@
text
@@


49.1
log
@Automatic bump of revision number for PWS version 3.24b
@
text
@@


48.1
log
@Automatic bump of revision number for PWS version 3.24a
@
text
@@


47.1
log
@Automatic bump of revision number for PWS version 3.23
@
text
@@


46.1
log
@Automatic bump of revision number for PWS version 3.23
@
text
@@


45.1
log
@Automatic bump of revision number for PWS version 3.23C
@
text
@@


44.1
log
@Automatic bump of revision number for PWS version 3.23B
@
text
@@


43.1
log
@Automatic bump of revision number for PWS version 3.23aA
@
text
@@


42.1
log
@Automatic bump of revision number for PWS version 3.23e
@
text
@@


41.1
log
@Automatic bump of revision number for PWS version 3.23d
@
text
@@


40.1
log
@Automatic bump of revision number for PWS version 3.23c
@
text
@@


39.1
log
@Automatic bump of revision number for PWS version 3.23b
@
text
@@


38.1
log
@Automatic bump of revision number for PWS version 3.23a
@
text
@@


37.1
log
@Automatic bump of revision number for PWS version 3.3a
@
text
@@


36.1
log
@Automatic bump of revision number for PWS version 3.22
@
text
@@


35.1
log
@Automatic bump of revision number for PWS version 3.22
@
text
@@


34.1
log
@Automatic bump of revision number for PWS version 3.22
@
text
@@


33.1
log
@Automatic bump of revision number for PWS version 3.22D
@
text
@@


32.1
log
@Automatic bump of revision number for PWS version 3.22C
@
text
@@


31.1
log
@Automatic bump of revision number for PWS version 3.22B
@
text
@@


30.1
log
@Automatic bump of revision number for PWS version 3.22A
@
text
@@


29.1
log
@Automatic bump of revision number for PWS version 3.22b
@
text
@@


28.1
log
@Automatic bump of revision number for PWS version 3.3b
@
text
@@


27.1
log
@Automatic bump of revision number for PWS version 3.3a
@
text
@@


26.4
log
@
Comment from auto synch of clock fix:
date: 88/03/15 14:16:13;  author: quist;  state: Exp;  lines added/del: 15/21
leap year fix
@
text
@@


26.3
log
@
Comment from auto synch of clock fix:
date: 88/03/02 17:13:28;  author: quist;  state: Exp;  lines added/del: 2/1
SYSDATE fixes. RDQ
@
text
@d79 2
d82 7
a88 10
    repeat
      if (year mod 4)=0  then
	daysinyear:=366
      else
	daysinyear:=365;
      if days>=daysinyear then begin
	days:=days-daysinyear;
	year:=year+1
      end;
    until days<daysinyear;
d94 1
d99 3
a101 2
      if ((year mod 4)=0) and (month=2) then daysinmonth:=29;
      if days>= daysinmonth then begin
d105 1
a105 2
      else
	done:=true;
d154 1
a154 7

  function isleap(y: integer): integer;
  begin
    if (y mod 4 = 0) then isleap := 1
		      else isleap := 0;
  end;

@


26.2
log
@
Comment from auto synch of clock fix:
date: 88/03/02 09:41:00;  author: bayes;  state: Exp;  lines added/del: 0/0
Automatic bump of revision number for PWS version 3.2Y
@
text
@d91 2
a92 1
    year:=year mod 100; {get it into proper range}
@


26.1
log
@Automatic bump of revision number for PWS version 3.3 Synch
@
text
@@


24.1
log
@Automatic bump of revision number for PWS version 3.2
@
text
@@


23.1
log
@Automatic bump of revision number for PWS version 3.2P
@
text
@@


22.1
log
@Automatic bump of revision number for PWS version 3.2N
@
text
@@


21.1
log
@Automatic bump of revision number for PWS version 3.2M
@
text
@@


20.1
log
@Automatic bump of revision number for PWS version 3.2L
@
text
@@


19.1
log
@Automatic bump of revision number for PWS version 3.2K
@
text
@@


18.1
log
@Automatic bump of revision number for PWS version 3.2J
@
text
@@


17.1
log
@Automatic bump of revision number for PWS version 3.2I+
@
text
@@


16.1
log
@Automatic bump of revision number for PWS version 3.2I
@
text
@@


15.1
log
@Automatic bump of revision number for PWS version 3.2H
@
text
@@


14.1
log
@Automatic bump of revision number for PWS version 3.2G
@
text
@@


13.2
log
@Fix to set 26/36 powerfail clock to 1 mar 1900 base date
Also does inittime for all boots
@
text
@@


13.1
log
@Automatic bump of revision number for PWS version 3.2F
@
text
@d38 8
d133 4
a136 1
  t1.ipart := thetime.packeddate;
d236 4
a239 1
    thetime.packeddate := ipart;
d268 1
a268 2
  if boottype = 0 {powerup} then inittime;
  boottype := 18;
@


12.1
log
@Automatic bump of revision number for PWS version 3.2E
@
text
@@


11.1
log
@Automatic bump of revision number for PWS version 3.2D
@
text
@@


10.1
log
@Automatic bump of revision number for PWS version 3.2C
@
text
@@


9.1
log
@Automatic bump of revision number for PWS version 3.2B
@
text
@@


8.1
log
@Automatic bump of revision number for PWS version 3.2A
@
text
@@


7.1
log
@Automatic bump of revision number for PWS version 3.2l
@
text
@@


6.1
log
@Automatic bump of revision number for PWS version 3.2k
@
text
@@


5.1
log
@Automatic bump of revision number for PWS version 3.2j
@
text
@@


4.1
log
@actual check in:
date: 86/09/30 20:04:48; author: hal; state: Exp;
Automatic bump of revision number for PWS revision 3.2i
@
text
@@


3.1
log
@actual check in:
date: 86/09/01 12:15:10; author: hal; state: Exp;
Automatic bump of revision number for PWS 3.2h
@
text
@@


2.1
log
@actual check in:
date: 86/07/30 15:03:16; author: hal; state: Exp;
Auto bumbp rev number to 2.1 for sys 3.2e
@
text
@@


1.2
log
@actual check in:
date: 86/06/30 16:19:49; author: danm; state: tmp;
Changes made by John Schmidt; timezone and time converting routines.
@
text
@@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
 (c) Copyright Hewlett-Packard Company, 1983.
d52 12
d66 36
a101 17
  k:=ltime.packeddate+1;
  k1:= k*4-1;
  yr:= k1 div 1461;
  dd:= (k1-(1461*yr)+4) div 4;
  k2:=(5*dd-3);
  mm:=k2 div 153;
  dd:=k2-153*mm;
  dd:=(dd+5) div 5;
  if  mm<10 then mm:=mm+3
  else
    begin mm:=mm-9;yr:=yr+1; end;
  with thedate do
    begin
      year:=yr mod 100;{to protect our file}
      month:=mm;
      day:=dd;
    end;
d132 17
a148 1
var   ltime: rtctime;  yr,mth,dy: integer;
d151 12
a162 6
  with ltime,thedate do
    begin
      yr := year;  mth := month;  dy := day;
      if mth>2 then mth:=mth-3
	       else begin  mth:=mth+9; yr:=yr-1; end;
      packeddate:=((1461* yr) div 4 +(153*mth+2) div 5)+dy-1;
d164 1
d180 21
d248 1
@
