MODULE TimeSaverSuperTickler;

(** ------------------------------------------------------------------

           This is the MODULA-2 Program Source Code

           TimeSaver for the Commodore Amiga - ClockTickler Module 

           This Program is placed in the Public Domain By its Author

           Written June 2nd, 1987 by E.J. Lippert II, for C Ltd.

    ------------------------------------------------------------------ **)

(** ------------------------------------------------------------------

           NOTE:  This version is modified to update clock on one

                  minute boundaries.

    ------------------------------------------------------------------ **)



(*  ====================================================================
     VERSION FOR COMMODORE AMIGA

     Original Author : E.J. Lippert II for C Ltd.

     Version         : 1.00 - 02-Jun-87 02:33
=====================================================================  *)


FROM SYSTEM IMPORT ADDRESS;
FROM InOut IMPORT Read, Write, WriteString, WriteLn;
FROM DOSCodeLoader IMPORT Execute;


VAR

        ch [12578305] : CHAR;  (* this is the address of the keyboard Port *)
        i : CARDINAL;
        D, DD : ARRAY [0..80] OF CHAR;
        DUMMY : BOOLEAN;

BEGIN

D[0] := CHR(0);

WriteLn;

REPEAT

        DD := D;
        D[0] := CHR(0);
        i:= 0;

(* ==============================================================

        First Send a Value of 64 to the keyboard port and hold
        this value for approx 10 ms. 

        The Value 64 sets the Bit at the port that causes the
        Keyboard Data Line to go HIGH.

        10 ms. is worst case time required for a properly
        operating TimeSaver to sense the HIGH line condition.

============================================================== *)

        ch := CHR(64);

        LOOP
        IF i > 8191 THEN EXIT; END;
        INC(i);
        END;

        ch := CHR(0);

(* ==============================================================

        A properly operating TimeSaver will now respond by
        sending either the normally formatted Amiga DATE
        Command (ie: DATE DD-MON-YY HH:MM) if it is active.

        If however the TimeSaver has been turned off, or the 
        TimeSaver's Screen Echo has been disabled, a properly 
        operating TimeSaver will respond with the date only.
        (ie: DD-MON-YY HH:MM)

============================================================== *)



        Read(D[0]);    (* Read the first character sent by the TimeSaver *)

        IF D[0] = "D" THEN   (* If it is a "D" then assume TimeSaver is
                                active and collect the DATE Command info *)
                i := 1;
                REPEAT
                        Read(D[i]);
                        INC(i);
                UNTIL D[i-1] = CHR(10);
                D[i-1] := CHR(0);
        
        ELSE                 (* Otherwise assume TimeSaver is not active so
                                Collect the RAW DATE and format the command *)
                D[5] := D[0];
                D[0] := "D";
                D[1] := "A";
                D[2] := "T";
                D[3] := "E";
                D[4] := " ";
                i := 6;
                REPEAT
                        Read(D[i]);
                        INC(i);
                UNTIL D[i-1] = CHR(10);
                D[i-1] := CHR(0);

        END;

        IF (DD[0] = CHR(0)) THEN
                DD := D;
        END;

        Write(CHR(155)); Write("A");
                
UNTIL ( DD[i-2] # D[i-2] );


DUMMY := (Execute(D, 0, 0));            (* Execute the DATE Command 
                                           and print notices.       *)
WriteLn;

D := "Correct Time Now Set  -  TimeSaver   by C Ltd.";
D[35] := CHR(169);
WriteString(D);

WriteLn;

D := "                         Tickler by E.J. Lippert";
WriteString(D);

WriteLn;


END TimeSaverSuperTickler.
