TamPortsImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
April 10, 1987 1:19:17 pm PST
Last Edited by: Krivacic April 6, 1987 4:08:37 pm PDT
DIRECTORY
BitOps, TamDefs, TamPorts, Core, CoreClasses, CoreCreate, CoreProperties, Ports, Rosemary, RosemaryUser, Rope;
TamPortsImpl: CEDAR PROGRAM
IMPORTS Ports, TamDefs, Rope
EXPORTS TamPorts
= BEGIN
Word: TYPE = TamDefs.Word;
CharToLevel: PUBLIC PROC [ch: CHAR] RETURNS [level: Ports.Level] = {
level ← (
SELECT ch FROM
'0 => L,
'1 => H,
ENDCASE => X);
};
SetPVal: PUBLIC PROC [p: Ports.Port, port: NAT, value: CARD] = {
SELECT p[port].levelType FROM
l => p[port].l ← IF value=0 THEN L ELSE H;
ls => Ports.LCToLS[value, p[port].ls];
c => p[port].c ← value;
lc => p[port].lc ← value;
b =>
SELECT value FROM
0 => p[port].b ← FALSE;
1 => p[port].b ← TRUE;
ENDCASE => ERROR;
ENDCASE => ERROR;
};
GetPVal: PUBLIC PROC [p: Ports.Port, port: NAT] RETURNS [value: CARD] = {
value ←
SELECT p[port].levelType FROM
l => IF p[port].l = H THEN 1 ELSE 0,
ls => Ports.LSToLC[p[port].ls],
c => p[port].c,
lc => p[port].lc,
b => IF p[port].b THEN 1 ELSE 0,
ENDCASE => ERROR;
};
HasXs: PUBLIC PROC [p: Ports.Port, port: NAT] RETURNS [xval: BOOL] = {
SELECT p[port].levelType FROM
l => RETURN[p[port].l = X];
ls => FOR bit: NAT IN [0..p[port].ls.size) DO
IF p[port].ls[bit] = X THEN RETURN[TRUE];
ENDLOOP;
c => RETURN[FALSE];
lc => RETURN[FALSE];
b => RETURN[FALSE];
ENDCASE => ERROR;
RETURN[FALSE];
};
SetP: PUBLIC PROC [p: Ports.Port, port: NAT, value: CARD] = {
SetPVal[p, port, value];
p[port].d ← force;
};
SetPWord: PUBLIC PROC [p: Ports.Port, port: NAT, value: Word] = {
SetP[p, port, TamDefs.WordToCard[value]];
};
ClrP: PUBLIC PROC [p: Ports.Port, port: NAT, xit: BOOLFALSE] = {
IF xit THEN
SELECT p[port].levelType FROM
l => p[port].l ← X;
ls => Ports.SetLS[p[port].ls, X];
c => p[port].c ← 0;
lc => p[port].lc ← 0;
b => p[port].b ← FALSE;
ENDCASE => ERROR;
p[port].d ← none;
};
CheckP: PUBLIC PROC [p: Ports.Port, port: NAT, value: CARD] = {
SetPVal[p, port, value];
p[port].d ← expect;
};
SetX: PUBLIC PROC [p: Ports.Port, port: NAT] = {
ClrP[p, port];
p[port].d ← force;
};
PortToBool: PUBLIC PROC [p: Ports.Port, port: NAT] RETURNS [BOOL] = {
RETURN[GetPVal[p, port] = 1];
};
PortToNat: PUBLIC PROC [p: Ports.Port, port: NAT] RETURNS [NAT] = {
RETURN[GetPVal[p, port]];
};
PortToCard: PUBLIC PROC [p: Ports.Port, port: NAT] RETURNS [CARD] = {
RETURN[GetPVal[p, port]];
};
PortToWord: PUBLIC PROC [p: Ports.Port, port: NAT] RETURNS [Word] = {
RETURN[TamDefs.CardToWord[GetPVal[p, port]]];
};
GoClock: PUBLIC PROC [p: Ports.Port, clock: NAT, eval: PROC [memory: BOOLTRUE], cycles: NAT ← 1, extraEval: BOOLFALSE] = {
saveddrives: ARRAY [0..50] OF Ports.Drive;
ExpectsOff: PROC = {
FOR i: NAT ← 0, i + 1 WHILE i < p.size DO { -- Turn off Expects
saveddrives[i] ← p[i].d;
IF p[i].d = expect THEN p[i].d ← none;
};
ENDLOOP;
};
ExpectsOn: PROC = {
FOR i: NAT ← 0, i + 1 WHILE i < p.size DO-- Turn on Expects
p[i].d ← saveddrives[i];
ENDLOOP;
};
FOR i: NAT ← 0, i + 1 WHILE i < cycles DO-- Do clock cycles
ExpectsOff[];   -- checks off
IF extraEval THEN eval[];  -- Setup Values
extraEval ← FALSE;
SetP[p, clock, 0];   -- clock 0
eval[];    -- Setup Values
ExpectsOn[];   -- Turn on expects
SetP[p, clock,1];   -- clock 1
eval[];
SetP[p, clock, 0];   -- clock 0
eval[];    -- Setup Values
ENDLOOP;
};
RopeToLS: PUBLIC PROC [str: Rope.ROPE, ret: Ports.LevelSequence] = {
len: INT ← Rope.Length[str];
FOR i: INT IN [0..len) DO {
SELECT Rope.Fetch[str, i] FROM
'0, 'X => ret[i] ← L;
'1 => ret[i] ← H;
ENDCASE => ERROR;
}
ENDLOOP;
};
END.