-- Stack Virtual prom (revision I)
-- for RevB & up CP’s
-- last edited by R. Garner on April 25, 1980 4:31 PM
-- last edited by R. Garner on October 22, 1980 9:34 AM
--
RevGtoH: maxStackDepth changed from 8 to 14.
-- last edited by R. Garner on October 30, 1981 4:01 PM
--
RevHtoI: eliminated stack out of range trap.
-- File: StackVirtProm.mesa in [Iris]<Workstation>LH>CPPromsMesa-N.dm
--
and in [Iris]<Workstation>LH>CPProms-N.press
DIRECTORY
ImageDefs: FROM "ImageDefs"
USING [StopMesa],
PromBlowDefs: FROM "PromBlowDefs"
USING [WritePromData, WritePromList];

StackVirtProm: PROGRAM IMPORTS ImageDefs, PromBlowDefs =
BEGIN OPEN PromBlowDefs;

Size:
CARDINAL = 256;-- number of prom locations
addrWidth:
CARDINAL = 8;-- number of prom address bits
dataWidth:
CARDINAL = 4;-- number of prom output data bits

-- Note: a "n" at the end of a name indicates it is an active low signal, i.e. assigning
FALSE means that it represents a true state.

Addr: TYPE = MACHINE DEPENDENT RECORD -- Right-justified
[pad: [0..377B],
unused: BOOLEAN,
StackP: [0..15],
Push: BOOLEAN,
PopXn: BOOLEAN,
PopZn: BOOLEAN];

Output:
TYPE = MACHINE DEPENDENT RECORD -- Left-justified
[null1: BOOLEAN,
StackErr: BOOLEAN,
null2: BOOLEAN,
null3: BOOLEAN,
pad: [0..7777B]];

Prom:
ARRAY [0..Size] OF Output;
A: Addr;
Out: Output;
GenStackVirtProm: PROCEDURE =
BEGIN
i: CARDINAL;
Pop, StackOp, CheckSimUnderFlow, ChkUnderflow, ChkOverflow: BOOLEAN;
FOR i IN [0..Size) DO
A ← LOOPHOLE[i];
Out.StackErr ← FALSE;-- Initialize
Out.null1 ← Out.null2 ← Out.null3 ← TRUE;
Pop ← ~A.PopXn OR ~A.PopZn;
StackOp ← Pop OR A.Push;

--
StackErr
-- See the Dandelion Microcode Reference for description of stack pointer descriptions.

-- If a stack error occurs, one additional emulator click beyond the one which errored can execute before the emulator begins executing location 0 in c1. If the click in which the stack error occurs is suspended, no error results.

ChkUnderflow ← (Pop AND ~A.Push) OR ~A.PopXn;
ChkOverflow ← (A.Push AND A.PopXn);
CheckSimUnderFlow ← ~A.PopXn AND ~A.PopZn;

Out.StackErr ← (A.StackP=0 AND ChkUnderflow)
OR (A.StackP=1 AND CheckSimUnderFlow)
OR (A.StackP=15 AND ChkOverflow);

Prom[i] ← Out;
ENDLOOP;
END;

GenStackVirtProm[];
WritePromData["StackVirtProm-RevI", addrWidth, dataWidth, @Prom[0]];
WritePromList["StackVirtProm-RevI", addrWidth, dataWidth, @Prom[0]];
ImageDefs.StopMesa[]
END.