-- File: PtCommand.mesa, Last Edit: HGM November 8, 1979 11:12 PM

DIRECTORY
AltoDisplay: FROM "AltoDisplay" USING [DCBHandle, DCBnil, DCBchainHead],
IODefs: FROM "IODefs" USING [CR, ReadChar, WriteChar, WriteDecimal
, WriteLine, WriteString],
KeyDefs: FROM "KeyDefs" USING [Keys],
MiscDefs: FROM "MiscDefs"
USING [CallDebugger],
ProcessDefs: FROM "ProcessDefs" USING [MsecToTicks, SetTimeout],
StreamDefs: FROM "StreamDefs" USING [StreamHandle, GetDefaultKey],
TrapDefs: FROM "TrapDefs" USING [UnboundProcedure],
StatsDefs: FROM "StatsDefs" USING [StatFinish],
PupDefs: FROM "PupDefs" USING [
PupPackageDestroy, PupPackageMake,
InspectIncomingPups, InspectOutgoingPups, ShowPupBuffer,
SetPupCheckit, SetLocalOnly, SetPupStormy],
PtDefs: FROM "PtDefs" USING [
CursorBits,
PtBSPDoubleSend, PtBSPListen, PtBSPPushPull, PtBSPRecv, PtBSPSend, PtBSPUnListen,
PtOCDoubleSend, PtOCListen, PtOCPushPull, PtOCRecv, PtOCSend, PtOCUnListen,
PtPktDoubleSend, PtPktListen, PtPktPushPull, PtPktRecv, PtPktSend, PtPktUnListen,
PtRejListen, PtRejUnListen,
PtSocEcho, PtSocPushPull, PtSocRecv, PtSocSend, PtSocTurnabout,
PtBuffers, PtDisplay, PtHost, PtInterface, PtLookerSince, PtNames,
PtPrintThings, PtPRThings,
PtFixHostAndNet, PtOnOff, PtSched, PtEchoer,
PtEchoOff, PtEchoOn, PtStatsOff, PtStatsOn];

PtCommand: MONITOR [pt: PtDefs.PtInterface]
IMPORTS
IODefs, MiscDefs, ProcessDefs, StreamDefs, TrapDefs,
StatsDefs, PupDefs, PtDefs
EXPORTS PtDefs =
BEGIN OPEN IODefs, StatsDefs, PupDefs, PtDefs, pt;


LengthMismatch: PUBLIC SIGNAL = CODE;
DataMismatch: PUBLIC SIGNAL = CODE;


firstDCB: AltoDisplay.DCBHandle ← AltoDisplay.DCBchainHead↑;
checkit: BOOLEAN ← TRUE; -- See PupRouter
showit, stormy: BOOLEAN ← FALSE;

-- various diddly routines used by other parts of puptest

-- next random number generator
Random: PUBLIC PROCEDURE [random: CARDINAL] RETURNS [CARDINAL] =
BEGIN
RETURN [(random*1976+3)/2];
END;

-- lightning (debugging hack in router) really slows things down
SeeStorms: PUBLIC PROCEDURE =
BEGIN
IF dataWordsPerPup#266 THEN
BEGIN
WriteDecimal[dataWordsPerPup];
WriteLine[" data words per pup."L];
END;
IF checkit THEN WriteLine["
***** CheckSums on - be patient."L];
IF stormy THEN WriteLine["
***** Beware of lightning storms."L];
IF ~ticking THEN WriteLine["Clock not ticking."L];
IF ~displaying THEN WriteLine["Display is off."L];
END;

UnListen: PUBLIC PROCEDURE =
BEGIN
PtPktUnListen[];
PtBSPUnListen[];
PtOCUnListen[];
PtRejUnListen[];
END;

Confirm: PROCEDURE RETURNS [b: BOOLEAN] =
BEGIN
WriteString[" [Confirm] "L];
IF ReadChar[]=IODefs.CR THEN b←TRUE ELSE b←FALSE;
WriteLine[""L];
END;

SmashCursor: PROCEDURE =
BEGIN
CursorBits↑ ← [177777B,177777B,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
END;



active: CARDINAL;
timer: CONDITION;

Done: PUBLIC ENTRY PROCEDURE =
BEGIN
active ← active-1;
NOTIFY timer;
END;

ks: StreamDefs.StreamHandle = StreamDefs.GetDefaultKey[];
WaitUntilDone: PUBLIC ENTRY PROCEDURE [num: CARDINAL] =
BEGIN
clockInterruptWord: POINTER TO WORD = LOOPHOLE[421B];
oldClockWord: WORD ← clockInterruptWord↑;
active ← num;
ProcessDefs.SetTimeout[@timer,ProcessDefs.MsecToTicks[1000]];
-- leave the timeout ticker on
IF ~ticking THEN clockInterruptWord↑ ← 0000020B; -- this kills ↑Swat
IF ~displaying THEN AltoDisplay.DCBchainHead↑ ← AltoDisplay.DCBnil;
stopFlag ← FALSE;
UNTIL active=0 DO
WAIT timer; -- peek at KBD every second or so
IF ticking THEN
BEGIN
IF ~ks.endof[ks] THEN stopFlag ← TRUE;
END
ELSE
BEGIN
IF KeyDefs.Keys.Space=down THEN stopFlag ← TRUE;
IF KeyDefs.Keys.Ctrl=down AND KeyDefs.Keys.Spare3=down THEN
MiscDefs.CallDebugger["Control Swat."L];
END;
ENDLOOP;
IF ~displaying THEN AltoDisplay.DCBchainHead↑ ← firstDCB;
IF ~ticking THEN clockInterruptWord↑ ← oldClockWord;
WriteLine[""L];
PtLookerSince[];
stopFlag ← FALSE;
END;

PupTestMainLoop: PUBLIC PROCEDURE =
BEGIN
c: CHARACTER;
SeeStorms[];
DO
SmashCursor[];
WriteChar[’*];
SELECT ReadChar[] FROM
’ => WriteLine[""L];
’. => WriteLine["."L];
’- =>
BEGIN
WriteChar[’-]; WriteChar[’-];
UNTIL (c←ReadChar[])=CR DO WriteChar[c]; ENDLOOP;
WriteChar[CR];
END;
’B, ’b =>
BEGIN
WriteString["BSP "L];
SELECT ReadChar[] FROM
’D, ’d => BEGIN WriteLine["DoubleSend."L]; PtBSPDoubleSend[]; END;
’L, ’l =>
BEGIN
WriteLine["Listen."L];
UnListen[];
pullHim.socket ← [0,0];
pushMe.socket ← [0,0];
PtBSPListen[];
END;
’M, ’m =>
BEGIN
WriteString["Mode b"L];
SELECT ReadChar[] FROM
’L, ’l => BEGIN WriteLine["Lock."L]; mode←block; END;
’Y, ’y => BEGIN WriteLine["Yte."L]; mode←byte; END;
’? => WriteLine[" (b)Y(te) or (b)L(ock)."L];
ENDCASE => WriteLine["???"L];
END;
’P, ’p => BEGIN WriteLine["PushPull."L]; PtBSPPushPull[]; END;
’R, ’r => BEGIN WriteLine["Receive."L]; PtBSPRecv[]; END;
’S, ’s => BEGIN WriteLine["Send."L]; PtBSPSend[]; END;
’? => WriteLine[" D(oubleSend), L(isten), M(ode), P(ushPull), R(eceive), or S(end)."L];
ENDCASE => WriteLine["???"L];
END;
’C, ’c =>
BEGIN
WriteString["Contents "L];
SELECT ReadChar[] FROM
’A, ’a => BEGIN WriteLine["Alternating."L]; data←alternating; END;
’C, ’c => BEGIN WriteLine["Cyclic."L]; data←cyclic; END;
’I, ’i => BEGIN WriteLine["Ignore."L]; data←ignore; END;
’O, ’o => BEGIN WriteLine["Ones."L]; data←ones; END;
’R, ’r => BEGIN WriteLine["Random."L]; data←random; END;
’Z, ’z => BEGIN WriteLine["Zeros."L]; data←zeros; END;
’? => WriteLine[" A(lternating), C(yclic), O(nes), Z(eros), R(andom), or I(gnore)."L];
ENDCASE => WriteLine["???"L];
END;
’D, ’d => BEGIN WriteLine["D(ebug)."L]; MiscDefs.CallDebugger["Debug."L]; END;
’E, ’e => BEGIN WriteLine["E(cho)."L]; PtEchoer[]; END;
’H, ’h => BEGIN WriteString["Host: "L]; PtHost[]; END;
’L, ’l =>
BEGIN
WriteString["Length "L];
SELECT ReadChar[] FROM
’C, ’c => BEGIN WriteLine["Cyclic."L]; length←cyclic; END;
’I, ’i => BEGIN WriteLine["Ignore."L]; length←ignore; END;
’L, ’l => BEGIN WriteLine["Long."L]; length←long; END;
’R, ’r => BEGIN WriteLine["Random."L]; length←random; END;
’S, ’s => BEGIN WriteLine["Short."L]; length←short; END;
’? => WriteLine[" L(ong), S(hort), I(gnore), R(andom), or C(yclic)."L];
ENDCASE => WriteLine["???"L];
END;
’M, ’m =>
BEGIN
WriteString["Miscellaneous "L];
SELECT ReadChar[] FROM
’B, ’b => BEGIN WriteLine["Buffers"L]; PtBuffers[]; END;
’D, ’d => BEGIN WriteLine["Display"L]; PtDisplay[]; END;
’N, ’n => BEGIN WriteLine["NameTester"L]; PtNames[]; END;
’O, ’o => BEGIN WriteLine["On-Off tester."L]; PtOnOff[]; END;
’P, ’p => PtPrintThings[]; -- it does the rest of the decoding
’R, ’r =>
BEGIN
PtPRThings[ ! -- Larry Stewart’s Packet Radio Experiments
TrapDefs.UnboundProcedure => GOTO Reject];
EXITS Reject => WriteLine["Packet Radio tester not loaded!"L];
END;
’S, ’s => BEGIN WriteLine["Scheduler timer."L]; PtSched[]; END;
’? => WriteLine[" B(uffers), L(ook), N(ame), O(n-Off), P(rint), R(adio), S(cheduler)."L];
ENDCASE => WriteLine["???"L];
END;
’O, ’o =>
BEGIN
WriteString["OpenClose "L];
SELECT ReadChar[] FROM
’D, ’d => BEGIN WriteLine["DoubleSend."L]; PtOCDoubleSend[]; END;
’L, ’l =>
BEGIN
WriteLine["Listen."L];
UnListen[];
pullHim.socket ← [0,0];
pushMe.socket ← [0,0];
PtOCListen[];
END;
’P, ’p => BEGIN WriteLine["PushPull."L]; PtOCPushPull[]; END;
’R, ’r => BEGIN WriteLine["Receive."L]; PtOCRecv[]; END;
’S, ’s => BEGIN WriteLine["Send."L]; PtOCSend[]; END;
’? => WriteLine[" D(oubleSend), L(isten), P(ushPull), R(eceive), or S(end)."L];
ENDCASE => WriteLine["???"L];
END;
’P, ’p =>
BEGIN
WriteString["Packet "L];
SELECT ReadChar[] FROM
’D, ’d => BEGIN WriteLine["DoubleSend."L]; PtPktDoubleSend[]; END;
’L, ’l =>
BEGIN
WriteLine["Listen."L];
UnListen[];
pullHim.socket ← [0,0];
pushMe.socket ← [0,0];
PtPktListen[];
END;
’P, ’p => BEGIN WriteLine["PushPull."L]; PtPktPushPull[]; END;
’R, ’r => BEGIN WriteLine["Receive."L]; PtPktRecv[]; END;
’S, ’s => BEGIN WriteLine["Send."L]; PtPktSend[]; END;
’? => WriteLine[" D(oubleSend), L(isten), P(ushPull), R(eceive), or S(end)."L];
ENDCASE => WriteLine["???"L];
END;
’Q, ’q =>
BEGIN
WriteString["Quit."L];
IF Confirm[] THEN BEGIN StatFinish[]; RETURN[]; END
ELSE WriteLine[" ???."L];
END;
’R, ’r =>
BEGIN
WriteLine["Rejector listen."L];
PtRejListen[];
END;
’S, ’s =>
BEGIN
WriteString["Socket "L];
SELECT ReadChar[] FROM
’E, ’e => BEGIN WriteLine["Echo."L]; PtSocEcho[]; END;
’P, ’p => BEGIN WriteLine["PushPull."L]; PtSocPushPull[]; END;
’R, ’r => BEGIN WriteLine["Receive."L]; PtSocRecv[]; END;
’S, ’s => BEGIN WriteLine["Send."L]; PtSocSend[]; END;
’T, ’t => BEGIN WriteLine["Turnabout."L]; PtSocTurnabout[]; END;
’? => WriteLine[" E(cho), P(ushPull), R(eceive), S(end), or T(urnabout)."L];
ENDCASE => WriteLine["???"L];
END;
’T, ’t =>
BEGIN
WriteString["Toggle "L];
SELECT ReadChar[] FROM
’C, ’c =>
BEGIN
WriteString["checkIt. "L];
SetPupCheckit[checkit←~checkit];
IF checkit THEN WriteLine["Checksums on."L]
ELSE WriteLine["Checksums off."L];
END;
’D, ’d =>
BEGIN
WriteLine["displaying."L];
displaying ← ~displaying;
IF displaying THEN WriteLine["Display on while testing."L]
ELSE WriteLine["Display off while testing."L];
END;
’I, ’i =>
BEGIN
WriteLine["info."L];
info ← ~info;
IF info THEN WriteLine["Normal info while testing."L]
ELSE WriteLine["No info while testing."L];
END;
’L, ’l =>
BEGIN
WriteLine["localOnly."L];
UnListen[];
PtStatsOff[];
PtEchoOff[];
PupPackageDestroy[];
SetLocalOnly[localOnly←~localOnly];
PupPackageMake[];
PtFixHostAndNet[];
PtStatsOn[];
PtEchoOn[];
IF localOnly THEN WriteLine["It’s quiet in here."L]
ELSE WriteLine["Its noisy outside."L];
END;
’T, ’t =>
BEGIN
WriteLine["ticking."L];
ticking ← ~ticking;
IF ticking THEN WriteLine["Clock will run normally."L]
ELSE WriteLine["No KBD while testing - ↑Swat won’t work."L];
END;
’V, ’v =>
BEGIN
WriteLine["Verbose=showit."L];
showit←~showit;
InspectIncomingPups[showit,ShowPupBuffer];
InspectOutgoingPups[showit,ShowPupBuffer];
IF showit THEN WriteLine["Watch out, you might see a lot of things."L]
ELSE WriteLine["No more Showing packets."L];
END;
’Z, ’z =>
BEGIN
WriteLine["Zappem=stormy."L];
SetPupStormy[stormy←~stormy];
IF stormy THEN WriteLine["Zapping packets."L]
ELSE WriteLine["No more Zapping packets."L];
END;
’? => WriteLine["C(heckit), I(nfo), L(ocalOnly),
V(erbose), or Z(apem)"L];
ENDCASE => WriteLine["???"L];
END;
’U, ’u => BEGIN WriteLine["Unlisten."L]; UnListen[]; END;
’X, ’x => BEGIN WriteLine["Statistics."L]; PtLookerSince[]; END;
’? => WriteLine["?
B(SP), P(acket), S(ocket), O(penClose), U(nListen), E(cho),
C(ontents), H(ost), L(ength),
D(ebug), Q(uit), R(eject), M(isc), T(oggle), X(stats)."L];
ENDCASE => WriteLine["???"L];
ENDLOOP;
END;


END. -- of PtCommand