SoftcardToolImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Willie-Sue, March 19, 1987 12:27:49 pm PST
DIRECTORY
BasicTime USING [Now],
Commander USING [CommandProc, Handle, Register],
CommandTool USING [RegistrationDirectory],
IO,
Rope,
Buttons USING [Button, ButtonProc, Create, ReLabel],
Containers USING [ChildXBound, ChildYBound],
Convert USING [CardFromRope, Error, IntFromRope],
FS USING [SetKeep],
ImagerFont USING [Font, Find],
Labels USING [Create, Set],
PopUpSelection USING [Request],
Rules USING [Create],
TypeScript USING [ChangeLooks, Create],
ViewerClasses USING [Viewer, ViewerRec],
ViewerIO USING [CreateViewerStreams],
ViewerOps USING [CreateViewer],
ViewerTools USING [GetContents, MakeNewTextViewer, SetContents, SetSelection],
SoftcardOps,
SoftcardToolPrivate;
SoftcardToolImpl: CEDAR MONITOR
IMPORTS
BasicTime, Commander, CommandTool, Convert, FS, ImagerFont, IO, PopUpSelection, Rope,
Buttons, Containers, Labels, Rules, ViewerIO, ViewerOps, ViewerTools, TypeScript,
SoftcardOps, SoftcardToolPrivate
EXPORTS SoftcardToolPrivate
= BEGIN OPEN IO, SoftcardToolPrivate;
STREAM: TYPE = IO.STREAM;
variables
topViewer: PUBLIC Viewer;
tsViewer: Viewer;
tsOut: PUBLIC STREAM;
runOrStopButton: Viewer;
runChoice: ROPE = " Is running ";
stopChoice: ROPE = " Is stopped ";
unknownChoice: ROPE = " Is unknown ";
dragonState: DragonState ← unknown;
connectionText: Viewer;
phaseAdjustText: Viewer;
delayText: Viewer;
freqSelectLabel: Viewer;
freqSelectChoice: INT ← -1;
freqSelectArray: PUBLIC ARRAY [0..3] OF SelectRecord;
SelectRecord: TYPE = RECORD [name: ROPE, val: CARD16];
activeFont: PUBLIC ImagerFont.Font;
labelFont: PUBLIC ImagerFont.Font;
tinySelectFont: PUBLIC ImagerFont.Font;
selectFont: PUBLIC ImagerFont.Font;
regDir: PUBLIC ROPE;
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MakeControlWindow: PROC[name, tsLogFile: ROPE] RETURNS [STREAM] = {
IF topViewer = NIL OR topViewer.destroyed THEN {
sib: Viewer;
y: INTEGER;
topViewer ← ViewerOps.CreateViewer[
flavor: $Container,
info: [name: name, iconic: FALSE, scrollable: FALSE] ];
line 1 of Buttons
sib ← Buttons.Create[
info: [ name: " EstablishConnection ", parent: topViewer,
 wx: leftEdge, wy: 4, wh: entryHeight, border: TRUE, scrollable: FALSE],
font: activeFont, proc: OpenConnectionProc ];
sib ← Buttons.Create[
info: [ name: " CloseConnection ", parent: topViewer,
 wx: sib.wx+sib.ww+1, wy: sib.wy, wh: entryHeight,
 border: TRUE, scrollable: FALSE],
font: activeFont, proc: CloseConnectionProc ];
sib ← Buttons.Create[
info: [ name: "Host:", parent: topViewer,
 wx: sib.wx+sib.ww+10, wy: sib.wy, wh: entryHeight,
 border: FALSE, scrollable: FALSE],
font: selectFont, proc: ConnectionTextProc ];
sib ← connectionText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy,
 ww: 1000, wh: entryHeight, border: FALSE, scrollable: TRUE]];
Containers.ChildXBound[topViewer, sib];
DragonRunControl
sib ← Labels.Create[
info: [ name: " DragonRunControl ", parent: topViewer,
 wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight,
 border: FALSE, scrollable: FALSE],
font: labelFont ];
sib ← runOrStopButton ← Buttons.Create[
info: [ name: unknownChoice, parent: topViewer,
 wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
 border: TRUE, scrollable: FALSE],
font: activeFont, proc: RunOrStopProc ];
Halting and stepping
sib ← Buttons.Create[
info: [ name: " HaltDragonInPhase ", parent: topViewer,
 wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight,
 border: TRUE, scrollable: FALSE],
font: activeFont, proc: HaltDragonProc ];
sib ← Buttons.Create[
info: [ name: " Current Dragon Phase ", parent: topViewer,
 wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy, wh: entryHeight,
 border: TRUE, scrollable: FALSE],
font: activeFont, proc: CurrentPhaseProc ];
sib ← Labels.Create[
info: [ name: " StepDragon ", parent: topViewer,
 wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy, wh: entryHeight,
 border: FALSE, scrollable: FALSE],
font: labelFont ];
sib ← Buttons.Create[
info: [ name: "quarter", parent: topViewer,
 wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
 border: TRUE, scrollable: FALSE],
font: activeFont, proc: QuarterStepProc ];
sib ← Buttons.Create[
info: [ name: "half", parent: topViewer,
 wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
 border: TRUE, scrollable: FALSE],
font: activeFont, proc: HalfStepProc ];
sib ← Buttons.Create[
info: [ name: "full", parent: topViewer,
 wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
 border: TRUE, scrollable: FALSE],
font: activeFont, proc: FullStepProc ];
ClockControl
sib ← Labels.Create[
info: [ name: " ClockControl ", parent: topViewer,
 wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight,
 border: FALSE, scrollable: FALSE],
font: labelFont ];
sib ← Buttons.Create[
info: [name: "Read", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, scrollable: FALSE ],
font: activeFont, proc: ReadClockControl ];
sib ← Buttons.Create[
info: [name: "Write", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, scrollable: FALSE ],
font: activeFont, proc: WriteClockControl ];
sib ← Buttons.Create[
info: [name: " FreqSelect: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge+5, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE ],
font: tinySelectFont, proc: FreqSelectProc ];
sib ← freqSelectLabel ← Labels.Create[
info: [name: " ", parent: topViewer, wx: sib.wx+sib.ww+xFudge+2, wy: sib.wy,
  wh: entryHeight, border: FALSE, scrollable: FALSE],
font: labelFont ];
sib ← Buttons.Create[
info: [name: "PhaseAdjust [0..7]: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE ],
font: tinySelectFont, proc: PhaseAdjustProc ];
sib ← phaseAdjustText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy,
 ww: 20, wh: entryHeight, border: FALSE, scrollable: FALSE] ];
sib ← Buttons.Create[
info: [name: "Delay [0..7]: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE ],
font: tinySelectFont, proc: DelayProc ];
sib ← delayText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+2, wy: sib.wy,
 ww: 20, wh: entryHeight, border: FALSE, scrollable: FALSE]];
the other buttonss
sib ← BuildVariousButtons[topViewer, sib];
sib ← BuildRegisterButtons[topViewer, sib];
sib ← BuildPeekPokeButtons[topViewer, sib];
sib ← BuildQuadIOButtons[topViewer, sib];
sib ← Rules.Create[
info: [parent: topViewer, wy: sib.wy+sib.wh+2, ww: topViewer.ww, wh: 2]];
Containers.ChildXBound[topViewer, sib];
sib ← BuildMiscButtons[topViewer, sib];
the rest of the viewer - typescript
sib ← Rules.Create[
info: [parent: topViewer, wy: sib.wy+sib.wh+1, ww: topViewer.ww, wh: 2]];
Containers.ChildXBound[topViewer, sib];
y ← sib.wy+sib.wh+4;
tsViewer ← TypeScript.Create[
info: [parent: topViewer, ww: sib.cw, wy: y, wh: topViewer.ch - y, border: FALSE] ];
TypeScript.ChangeLooks[tsViewer, 'f];
Containers.ChildYBound[topViewer, tsViewer];
Containers.ChildXBound[topViewer, tsViewer];
tsOut ← ViewerIO.CreateViewerStreams[NIL, tsViewer, tsLogFile, FALSE].out;
FS.SetKeep[tsLogFile, 6];
TSOutPutF["\tTypescript on file: %g, started at %g\n",
[rope[tsLogFile]], [time[BasicTime.Now[]]] ];
};
topViewer.inhibitDestroy ← TRUE;
RETURN[tsOut];
};
OpenConnectionProc: ClickProc = {
name: ROPE = ViewerTools.GetContents[connectionText];
ok: BOOL = SoftcardOps.EstablishConnection[name];
isRunning: BOOL = SoftcardOps.ReadControlBit[dragonRun];
IF ok THEN {
IF isRunning THEN SetDragonStateLabelButton[running]
ELSE SetDragonStateLabelButton[stopped];
TSOutPutF["Connection to %g has been established\n", IO.rope[name]]
}
ELSE
TSOutPutF["Could not establish connection with %g has \n", IO.rope[name]];
};
CloseConnectionProc: ClickProc = {
SoftcardOps.CloseConnection[];
TSOutPutRope["Connection has been closed\n\n"];
SetDragonStateLabelButton[unknown];
};
ReadClockControl: ClickProc = {
current: SoftcardOps.ClockControl = SoftcardOps.ReadClockControl[];
TSOutPutF[
" Current value of clock control is: [freqSelect: %g, phaseAdjust: %g, delay: %g]\n",
[rope[freqSelectArray[current.freqSelect].name]], [integer[current.phaseAdjust]],
[integer[current.delay]] ];
freqSelectChoice ← current.freqSelect;
Labels.Set[freqSelectLabel, freqSelectArray[freqSelectChoice].name ];
ViewerTools.SetContents[phaseAdjustText, IO.PutFR[NIL, [integer[current.phaseAdjust]]] ];
ViewerTools.SetContents[delayText, IO.PutFR[NIL, [integer[current.delay]]] ];
};
WriteClockControl: ClickProc = {
new: SoftcardOps.ClockControl;
ok: BOOL;
typeIn: CARD32;
IF freqSelectChoice = -1 THEN {
TSOutPutRope[" Please select a frequency first\n"];
RETURN;
};
new.freqSelect ← freqSelectArray[freqSelectChoice].val;
[ok, typeIn] ← CheckedGetAsCard[phaseAdjustText, "PhaseAdjust", 7];
IF ~ok THEN RETURN;
new.phaseAdjust ← typeIn;
[ok, typeIn] ← CheckedGetAsCard[delayText, "Delay", 7];
IF ~ok THEN RETURN;
new.delay ← typeIn;
SoftcardOps.WriteClockControl[new];
TSOutPutRope[" New value of clockControl has been set\n"];
};
RunOrStopProc: ClickProc = {
IF dragonState = unknown THEN {
TSOutPutRope[" Dragon state is unknown - can't change\n"];
RETURN
};
IF dragonState = running THEN {
SoftcardOps.DragonStop[];
SetDragonStateLabelButton[stopped];
}
ELSE {
SoftcardOps.DragonRun[];
SetDragonStateLabelButton[running];
};
};
SetDragonStateLabelButton: PUBLIC PROC[which: DragonState] = {
IF dragonState = which THEN RETURN;  -- nothing to do
SELECT which FROM
running => Buttons.ReLabel[runOrStopButton, runChoice];
stopped => Buttons.ReLabel[runOrStopButton, stopChoice];
unknown => Buttons.ReLabel[runOrStopButton, unknownChoice];
ENDCASE => ERROR;
dragonState ← which;
};
ConnectionTextProc: ClickProc =
{ ViewerTools.SetSelection[connectionText, NIL] };
FreqSelectProc: ClickProc = {
which: INT = PopUpSelection.Request[
header: "Frequency Select",
choice: LIST[freqSelectArray[0].name, freqSelectArray[1].name, freqSelectArray[2].name,
freqSelectArray[3].name]
];
IF which = 0 THEN RETURN;  -- no selection
Labels.Set[freqSelectLabel, freqSelectArray[which - 1].name];
freqSelectChoice ← which - 1;
};
PhaseAdjustProc: ClickProc =
{ ViewerTools.SetSelection[phaseAdjustText, NIL] };
DelayProc: ClickProc =
{ ViewerTools.SetSelection[delayText, NIL] };
HaltDragonProc: ClickProc = {
which: INT = PopUpSelection.Request[
header: "DragonPhase",
choice: LIST["phaseA", "betweenAandB", "phaseB", "betweenBandA"] ];
phase: SoftcardOps.DragonPhase;
name: ROPE;
IF which = 0 THEN RETURN;
SELECT which FROM
1 => { phase ← phaseA; name ← "phaseA" };
2 => { phase ← betweenAandB; name ← "betweenAandB" };
3 => { phase ← phaseB; name ← "phaseB" };
4 => { phase ← betweenBandA; name ← "betweenBandA" };
ENDCASE => ERROR;
SoftcardOps.DragonHaltInPhase[phase];
TSOutPutF[" Dragon has been halted in %g\n", IO.rope[name] ];
SetDragonStateLabelButton[stopped];
};
StepDragonProc: ClickProc = {
which: INT = PopUpSelection.Request[
header: "DragonStep",
choice: LIST["quarter", "half", "full"] ];
step: SoftcardOps.DragonStepSize;
name: ROPE;
IF which = 0 THEN RETURN;
IF dragonState # stopped THEN {
TSOutPutRope["Dragon can only be stepped when halted\n"];
RETURN
};
SELECT which FROM
1 => { step ← quarter; name ← "quarter" };
2 => { step ← half; name ← "half" };
3 => { step ← full; name ← "full" };
ENDCASE => ERROR;
[] ← SoftcardOps.DragonStep[step];
TSOutPutF[" Dragon has been stepped by one %g cycle\n", IO.rope[name] ];
};
QuarterStepProc: ClickProc = { DoStep[quarter, "quarter"] };
HalfStepProc: ClickProc = { DoStep[half, "half"] };
FullStepProc: ClickProc = { DoStep[full, "full"] };
DoStep: PROC[step: SoftcardOps.DragonStepSize, name: ROPE] = {
ok: BOOL = SoftcardOps.DragonStep[step];
IF ~ok THEN {
TSOutPutRope["Dragon can only be stepped when halted\n"];
RETURN
};
TSOutPutF[" Dragon has been stepped by one %g cycle\n", IO.rope[name] ];
};
CurrentPhaseProc: ClickProc = {
phase: SoftcardOps.DragonPhase;
ok: BOOL;
name: ROPE;
IF dragonState # stopped THEN {
TSOutPutRope["Current phase can only be shown when the Dragon is halted\n"];
RETURN
};
[phase, ok] ← SoftcardOps.CurrentDragonPhase[];
IF ~ok THEN {
TSOutPutRope[" Softcard returned not ok - phase not readable\n"];
RETURN
};
SELECT phase FROM
phaseA => name ← "phaseA";
betweenAandB => name ← "betweenAandB";
phaseB => name ← "phaseB";
betweenBandA => name ← "betweenBandA"
ENDCASE => ERROR;
TSOutPutF["Dragon is stopped in %g\n", IO.rope[name] ];
};
GetAsInt: PUBLIC PROC[who: Viewer] RETURNS[val: INT] = {
rope: ROPE = ViewerTools.GetContents[who];
val ← -1;
val ← Convert.IntFromRope[rope ! Convert.Error => CONTINUE];
};
GetAsCard: PUBLIC PROC[who: Viewer] RETURNS[val: CARD32] = {
rope: ROPE = ViewerTools.GetContents[who];
val ← LAST[CARD32];
val ← Convert.CardFromRope[rope ! Convert.Error => CONTINUE];
};
CheckedGetAsCard: PUBLIC PROC[who: Viewer, which: ROPE, max: CARD32]
RETURNS[ok: BOOL, val: CARD32] = {
typeIn: ROPE = ViewerTools.GetContents[who];
val ← LAST[CARD32];
ok ← TRUE;
IF typeIn.Length[] = 0 THEN {
IF which # NIL THEN
TSOutPutF["\n**** Please fill in the %g field\n", [rope[which]] ];
RETURN[FALSE, val ];
};
val ← Convert.CardFromRope[typeIn ! Convert.Error => { ok ← FALSE; CONTINUE}];
IF ~ok THEN {
IF which # NIL THEN
TSOutPutF["\n**** %g is not a number in the %g field\n",
[rope[typeIn]], [rope[which]] ];
RETURN[FALSE, val];
};
IF max # 0 THEN ok ← CheckForValid[val, max, which];
RETURN[ok, val];
};
CheckForValid: PUBLIC PROC[val, max: CARD32, which: ROPE] RETURNS[ok: BOOL] = {
IF val > max THEN {
TSOutPutF["\n*** %g field is restricted to [1..%xH], %g is invalid\n",
[rope[which]], [cardinal[max]], [cardinal[val]] ];
RETURN[FALSE];
};
RETURN[TRUE];
};
tsCount: CARDINAL ← 0;
flushCount: CARDINAL ← 5;
TSOutPutF: PUBLIC PROC[format: ROPENIL, v1, v2, v3, v4, v5: Value ← [null[]]] = {
tsOut.PutF[format, v1, v2, v3, v4, v5];
IF (tsCount ← tsCount + 1) > flushCount THEN {
tsOut.Flush[];
tsCount ← 0;
};
};
TSOutPutRope: PUBLIC PROC[r: ROPE] = {
tsOut.PutRope[r];
IF (tsCount ← tsCount + 1) > flushCount THEN {
tsOut.Flush[];
tsCount ← 0;
};
};
TSOutPutChar: PUBLIC PROC[ch: CHAR] = {
tsOut.PutChar[ch];
IF (tsCount ← tsCount + 1) > flushCount THEN {
tsOut.Flush[];
tsCount ← 0;
};
};
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SoftcardTool: Commander.CommandProc = {
regDir ← CommandTool.RegistrationDirectory[cmd];
[] ← MakeControlWindow["SoftcardTool","///temp/SoftcardTool.log"];
topViewer.inhibitDestroy ← FALSE;
};
Init: PROC = {
freqSelectArray[0] ← ["stopped", 0];
freqSelectArray[1] ← ["6.6 mhz", 1];
freqSelectArray[2] ← ["10 mhz", 2];
freqSelectArray[3] ← ["5 mhz", 3];
activeFont ← ImagerFont.Find["Xerox/TiogaFonts/Tioga10B"];
labelFont ← ImagerFont.Find["Xerox/TiogaFonts/Tioga10I"];
selectFont ← ImagerFont.Find["Xerox/TiogaFonts/Helvetica10"];
tinySelectFont ← ImagerFont.Find["Xerox/TiogaFonts/Helvetica7"];
};
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Init[];
Commander.Register["SoftcardTool", SoftcardTool];
END.