-- File: ComSoftImplA.mesa - last edited
-- Bruce	21-Jun-83 18:11:24
-- DonWinter 22-Aug-83 16:27:27
-- JFung.PASA 	  16-Jan-84 13:22:35

DIRECTORY
     Atom USING [ATOM, MakeAtom],
     -- CMsg USING [MsgNumber],
     ComSoftOps,
     DESFace USING [Key],
     Inline USING [LowHalf],
     -- Msg USING [Argument, nullArg, Severity],
     Process,
     System USING [GetClockPulses],
     TIP USING [CreateTable, globalTable, InvalidTable, PushLocal, Table];

ComSoftImplA: PROGRAM
     IMPORTS Atom, Inline, System, TIP 
     EXPORTS ComSoftOps  =
     
     BEGIN
     -- encryption stuff

     key: PUBLIC DESFace.Key;

     -- TIP stuff
     abortAtom, bullShitAtom, diagnosticAtom, lispAtom: PUBLIC Atom.ATOM;
     comTip: PUBLIC TIP.Table ← NIL;

     MakeTIP: PROC = {
          firstTime: BOOLEAN ← TRUE;
          abortAtom ← Atom.MakeAtom["abortAtom"L];
          bullShitAtom ← Atom.MakeAtom["bullShitAtom"L];
          diagnosticAtom ← Atom.MakeAtom["diagnosticAtom"L];
          lispAtom ← Atom.MakeAtom["lispAtom"L];
          comTip ← TIP.CreateTable[
               file: "InstallLispTool.TIP"L,
               contents:
               "--InstallLispTool.TIP
	-- Version of       	16-Jan-84 
	SELECT TRIGGER FROM
	Adjust Down AND Point Down BEFORE 250 =>abortAtom;
	Point Down AND Adjust Down BEFORE 250 =>abortAtom;
	Adjust Down=>diagnosticAtom;
	Point Down=>lispAtom;
	Menu Down=>abortAtom;
 	ENDCASE..."L
               !
               TIP.InvalidTable =>
                    IF firstTime THEN {firstTime ← FALSE; RESUME }]};

     -- random number generator

     Random: PUBLIC PROC [high: CARDINAL] RETURNS [CARDINAL -- IN [0..high] -- ] =
          {seed ← Word[]; RETURN[seed MOD (high + 1)]};

     VectorSize: CARDINAL = 55;
     seed: CARDINAL;
     i1, i2: CARDINAL;

     vector: ARRAY [0..VectorSize) OF CARDINAL ← [
          031575B, 055455B, 147160B, 176745B, 173126B, 117426B, 033612B, 130620B,
          054013B, 167672B, 070252B, 033100B, 015700B, 113523B, 170465B, 024344B,
          175535B, 137325B, 126211B, 010207B, 173547B, 016071B, 056622B, 014433B,
          113225B, 047553B, 103025B, 110174B, 000125B, 173304B, 076700B, 104042B,
          135030B, 126234B, 175154B, 140123B, 167542B, 000405B, 035464B, 166537B,
          050260B, 167655B, 123615B, 175164B, 172206B, 140365B, 074606B, 075656B,
          176163B, 030027B, 022102B, 040051B, 154630B, 017144B, 073372B];

     Word: PROC RETURNS [ret: CARDINAL] = {
          ret ← vector[i1] ← vector[i1] + vector[i2];
          IF (i1 ← i1 + 1) >= VectorSize THEN i1 ← 0;
          IF (i2 ← i2 + 1) >= VectorSize THEN i2 ← 0};

     InitRandom: PROC [seed: CARDINAL] = {
          FOR i: CARDINAL IN [0..VectorSize) DO
               vector[i] ← vector[i] + seed ENDLOOP;
          i1 ← 0;
          i2 ← 24};

     -- message stuff

     -- Fail: PUBLIC ERROR [
     -- level: Msg.Severity, code: CMsg.MsgNumber, arg1: Msg.Argument ← Msg.nullArg]
     -- = CODE;

     StartTrap: PROC = {
          InitRandom[Inline.LowHalf[System.GetClockPulses[]]];
          MakeTIP[];
          TIP.PushLocal[push: comTip, onto: TIP.globalTable[formSW]]};

     StartTrap[];

     END.