RegisterSimple:
PUBLIC
PROC [b:
NAT]
RETURNS [ct: CellType] = {
registerSimpleName: ROPE = "RegisterSimple";
fullName: ROPE = IO.PutFR["RegisterSimple b=%g", IO.int[b]];
ct ← CacheFetch[fullName];
IF ct#NIL THEN RETURN[ct];
IF b=0 THEN Error["Please specify size of register"];
ct ← SequenceCell[name: registerSimpleName, baseCell: Extract["reg1BSimple.sch"], count: b, sequencePorts: Wires["Input", "Output", "nOutput"]];
SimulateMacro[ct, RoseClass[registerSimpleName, RegSInit, RegSSimple, TRUE]];
Ports.InitPorts[ct, l, none, "CK"];
Ports.InitPorts[ct, ls, none, "Input"]; Ports.InitPorts[ct, ls, drive, "Output", "nOutput"];
CacheStore[fullName, ct];
};
RegSInit: Rosemary.InitProc = {
state: RegRef ← IF oldStateAny=NIL THEN NEW[RegRec] ELSE NARROW[oldStateAny];
b: NAT;
[state.ck, state.in, state.out, state.nOut] ← Ports.PortIndexes[cellType.public, "CK", "Input", "Output", "nOutput"];
b ← p[state.in].ls.size;
state.master ← NEW[Ports.LevelSequenceRec[b]];
state.slave ← NEW[Ports.LevelSequenceRec[b]];
Ports.SetLS[state.master, X];
Ports.SetLS[state.slave, X];
Ports.SetLS[p[state.out].ls, X];
Ports.SetLS[p[state.nOut].ls, X];
stateAny ← state;
};
RegSSimple: Rosemary.EvalProc = {
state: RegRef ← NARROW[stateAny];
IF ~clockEval
THEN
SELECT p[state.ck].l
FROM
L => Ports.CopyLS[from: p[state.in].ls, to: state.master]; -- load master bits
H => Ports.CopyLS[from: state.master, to: state.slave]; -- load slave bits
ENDCASE => {Ports.SetLS[state.master, X]; Ports.SetLS[state.slave, X]}; -- conservative
Ports.CopyLS[from: state.slave, to: p[state.out].ls];
Ports.NotLS[p[state.out].ls, p[state.nOut].ls];
};