PROGRAM TIME_PAS;
{*****************************************************************************
*                           PROGRAM TIME.PAS                                 *
*                                                                            *
* WRITTTEN IN TURBO-PASCAL(c) BORLAND INTERNATIONAL 1984                     *
* USEFUL ONLY ON THE KAYPRO IV-84 WITH REAL TIME CLOCK                       *
* COPYRIGHT 1984 BY KEITH REDFIELD                                           *
* USE OF THIS PROGRAM FOR ANY COMMERCIAL PURPOSES IS EXPRESSLY FORBIDDEN     *
* EXCEPT BY THE WRITTEN PERMISSION OF THE AUTHOR                             *
*                                                                            *
* THE CURSOR MAY BE ANNOYING TO SOME, BUT AS FAR AS I KNOW, IF YOU TURN      *
* IT OFF, YOU CANNOT TURN IT BACK ON WITHOUT A HARD RESET                    *
*****************************************************************************}
CONST
  PORTS: ARRAY[1..6] OF INTEGER = (1,2,3,4,6,7);

  {PORT 1 IS HUNDREDTHS,
        2 IS SECONDS,
        3 IS MINUTES,
        4 IS HOURS,
        5 IS DAY OF THE WEEK, AND
        6 IS MONTH. LEAP YEARS CAN BE CHECKED

  (RE: CLOCK.BAS(c) KAYPRO CORP) BUT NOT IMPLEMENTED HERE
  AS THE SAYING GOES...I LEAVE THAT FOR HOMEWORK}
VAR
  I,CLOCK_PORT_VALUE: INTEGER;
  VALUE : ARRAY[1..6] OF INTEGER;

PROCEDURE PIXON(X1,Y1:INTEGER);
          BEGIN
             WRITELN(#27'*',CHR(X1+32),CHR(Y1+32));
          END;

PROCEDURE PIXOFF(X1,Y1:INTEGER);
          BEGIN
             WRITELN(#27' ',CHR(X1+32),CHR(Y1+32));
          END;


PROCEDURE READPORT(I : INTEGER);
  VAR CLOCK_VALUE,TENS,ONES : INTEGER;
  {THE CLOCK RETURNS VALUES IN BINARY CODED DECIMAL FORMAT, SO THIS CONVERTS}
    BEGIN
      PORT[32] := I;{PORT 32 IS THE CLOCK READ PORT}
      CLOCK_VALUE := PORT[36];{36 IS THE OUTPUT PORT}
      TENS := TRUNC(CLOCK_VALUE/16);
      ONES := CLOCK_VALUE-16*TENS;
      CLOCK_PORT_VALUE := 10 *TENS+ONES;
   END;

PROCEDURE DATE;
VAR DATEPORT : INTEGER;
BEGIN
  FOR I := 1 TO 6 DO
    BEGIN
      READPORT(I);
      VALUE[I] := CLOCK_PORT_VALUE;
  PIXON(7,VALUE[1]);
    END;
END;

BEGIN
CLRSCR;
REPEAT
DATE;
  GOTOXY(5,5);WRITE('THE DATE IS ',VALUE[6],'/',VALUE[5],'/84');
  GOTOXY(5,6);WRITE('THE TIME IS ',VALUE[4],':',VALUE[3],':',VALUE[2],' ');
  PIXOFF(7,VALUE[1]);
UNTIL KEYPRESSED = TRUE;

END.

{NOTICE THAT I DID NOT INCLUDE A ROUTINE FOR SETTING THE CLOCK. TWO REASONS,
(1) I AM VERY LAZY
(2) YOU CAN DO THAT WITH CLOCK.BAS(c)

ALSO, THERE SHOULD BE A WAY TO GET THE PROGRAM TO EXIT WITHOUT A WARM-BOOT
ANYONE KNOW HOW?

LEAVE MAIL FOR KEITH REDFIELD IF YOU WANT TO TALK}

