NMosImpl.mesa
by Ch. Jacobi August 11, 1983 3:56 pm
last edited Christian Jacobi November 23, 1983 10:07 am
DIRECTORY
CD,
CDEvents,
CDOps,
CDPanel,
CDProperties,
CDSequencer,
CDTechnology,
CDViewer,
Commander USING [CommandProc, Register],
IO,
FS,
GraphicsColor,
NMos,
Rope,
SafeStorage,
TerminalIO,
TokenIO,
UserProfile,
ViewerOps;
NMosImpl: CEDAR PROGRAM
IMPORTS CD, CDEvents, CDOps, CDPanel, CDProperties, CDSequencer, CDTechnology, CDViewer, Commander, IO, FS, Rope, SafeStorage, TerminalIO, TokenIO, UserProfile, ViewerOps
EXPORTS NMos =
BEGIN
s1: CARDINAL = 1;
s2: CARDINAL = 16;
s3: CARDINAL = 16*16;
s4: CARDINAL = 16*16*16;
ss: CARDINAL = s1+s2+s3+s4;
sf: CARDINAL = s1+s3;
--4bit colors--
green: CARDINAL = 1;
blue: CARDINAL = 2;
red: CARDINAL = 4;
yellow: CARDINAL = 14;
cut: PUBLIC CD.Level;
pol: PUBLIC CD.Level;
dif: PUBLIC CD.Level;
met: PUBLIC CD.Level;
imp: PUBLIC CD.Level;
imp0: PUBLIC CD.Level;
impWeak: PUBLIC CD.Level;
ovg: PUBLIC CD.Level;
bur: PUBLIC CD.Level;
snerd: PUBLIC CD.Level;
nwel: PUBLIC CD.Level;
nwelCont: PUBLIC CD.Level;
NOcOL: PUBLIC CD.Level;
met2: PUBLIC CD.Level;
cut2: PUBLIC CD.Level;
zone: PUBLIC ZONE ← SafeStorage.GetSystemZone[];
RegisterObjectType: PUBLIC PROC [a: ATOM] RETURNS [REF CD.ObjectProcs] =
BEGIN
RETURN [ CD.RegisterObjectType[a, nmos] ];
END;
NewNWorld: Commander.CommandProc =
BEGIN
design: CD.Design ← CDOps.CreateDesign[nmos];
[] ← CDViewer.CreateViewer[design];
END;
nmos: PUBLIC CD.Technology;
CifName: PROC [lev: CD.Level, name: Rope.ROPE] =
BEGIN
CDProperties.PutPropOnLevel[onto: lev, prop: $CDxCIFName, val: name]
END;
Init4BitBricks: PROC [] =
BEGIN
CDTechnology.TeachColor[cut, 4, [7*ss, 11*ss, 7*ss, 11*ss]];
CDTechnology.TeachColor[dif, 4, CDTechnology.Brick4[green]];
CDTechnology.TeachColor[nwelCont, 4, [1*ss, 1*ss, 2*ss, 1*ss]];
CDTechnology.TeachColor[pol, 4, CDTechnology.Brick4[red]];
CDTechnology.TeachColor[met, 4, CDTechnology.Brick4[blue]];
CDTechnology.TeachColor[imp, 4, [14, 14, 0, 0]];
CDTechnology.TeachColor[imp0, 4, [14, 14, 0, 1]];
CDTechnology.TeachColor[impWeak, 4, [14, 14, 0, 2]];
CDTechnology.TeachColor[met2, 4, [2*(s1+s2+s3), 2*ss, 2*(s1+s2+s3)+15*s4, 2*ss]];
CDTechnology.TeachColor[nwel, 4, [8*s1, 0, 0, 0]];
CDTechnology.TeachColor[bur, 4, [11*ss, 11*ss, 11*ss, 11*ss]];
CDTechnology.TeachColor[ovg, 4, [8*ss, 8*ss, 8*ss, 8*ss]];
CDTechnology.TeachColor[snerd, 4, [12345, 7865, 543, 0]];
CDTechnology.TeachColor[cut2, 4, [3*ss, 14*ss, 3*ss, 14*ss]];
END;
tipTable: Rope.ROPENIL;
NoteProfileChange: UserProfile.ProfileChangedProc =
-- PROC [reason: ProfileChangeReason]
BEGIN
newTipTable: Rope.ROPE ← UserProfile.Token[
key: "Chipndale.NMos.TIPTable",
default: "ChipndaleNMos.TIP"
];
IF ~Rope.Equal[tipTable, newTipTable] THEN {
CDTechnology.SetTipTable[nmos, newTipTable];
tipTable ← newTipTable
}
END;
Init: PROC [] =
BEGIN
TerminalIO.WriteRope["nmos impl\n"];
nmos ← CD.RegisterTechnology[$nmos, "nmos"];
IF nmos=NIL THEN ERROR;
cut ← CD.NewLevel[nmos, $cut];
pol ← CD.NewLevel[nmos, $pol];
dif ← CD.NewLevel[nmos, $dif];
met ← CD.NewLevel[nmos, $met];
imp ← CD.NewLevel[nmos, $imp];
imp0 ← CD.NewLevel[nmos, $imp0];
impWeak ← CD.NewLevel[nmos, $impWeak];
ovg ← CD.NewLevel[nmos, $ovg];
bur ← CD.NewLevel[nmos, $bur];
snerd ← CD.NewLevel[nmos, $snerd];
nwel ← CD.NewLevel[nmos, $nwel];
nwelCont ← CD.NewLevel[nmos, $nwelCont];
NOcOL ← CD.NewLevel[nmos, $NOcOL];
met2 ← CD.NewLevel[nmos, $met2];
cut2 ← CD.NewLevel[nmos, $cut2];
UserProfile.CallWhenProfileChanges[NoteProfileChange];
CDTechnology.TeachColor[cut, 1, [7*ss, 11*ss, 7*ss, 11*ss]];
CDTechnology.TeachColor[cut, 8, [7*sf, 11*sf, 7*sf, 11*sf]];
CDTechnology.TeachColor[cut2, 1, [3*ss, 14*ss, 3*ss, 14*ss]];
CDTechnology.TeachColor[cut2, 8, [3*ss, 14*ss, 3*ss, 14*ss]];
CDTechnology.TeachColor[dif, 1, [4*ss, ss, 4*ss, ss]];
CDTechnology.TeachColor[dif, 8, [1*sf, 1*sf, 1*sf, 1*sf]];
CDTechnology.TeachColor[pol, 1, [8*ss, 4*ss, 2*ss, 1*ss]];
CDTechnology.TeachColor[pol, 8, [4*sf, 4*sf, 4*sf, 4*sf]];
CDTechnology.TeachColor[met, 1, [8*ss, 2*ss, 0, 0]];
CDTechnology.TeachColor[met, 8, [2*sf, 2*sf, 2*sf, 2*sf]];
CDTechnology.TeachColor[imp, 1, [2*ss, 0, 2*ss, 0]];
CDTechnology.TeachColor[imp, 8, [14, 14, 0, 0]];
CDTechnology.TeachColor[imp0, 1, [2*ss, 0, 2*ss, 1]];
CDTechnology.TeachColor[imp0, 8, [14, 14, 0, 1]];
CDTechnology.TeachColor[impWeak, 1, [2*ss, 0, 2*ss, 2]];
CDTechnology.TeachColor[impWeak, 8, [14, 14, 0, 2]];
CDTechnology.TeachColor[met2, 1, [8*ss, 8*ss, 2*ss, 2*ss]];
CDTechnology.TeachColor[met2, 8, [2*sf, 29*sf, 2*sf, 37*sf]];
CDTechnology.TeachColor[nwel, 1, [4*ss, 0, 0, 0]];
CDTechnology.TeachColor[nwel, 8, [8*s1, 0, 0, 0]];
CDTechnology.TeachColor[ovg, 1, [4*ss, 14*ss, 4*ss, 0*ss]];
CDTechnology.TeachColor[ovg, 8, [8*sf, 8*sf, 8*sf, 8*sf]];
CifName[cut, "$NC"];
CifName[dif, "$N"];
CifName[pol, "$NP"];
CifName[met, "$NM"];
CifName[imp, "$NI"];
CifName[imp0, "$ERROR"];
CifName[impWeak, "$ERROR"];
CifName[nwel, "$Y"];
CifName[ovg, "$NG"];
CifName[bur, "$NB"];
CifName[snerd, "$U"];
CifName[nwelCont, "$W"];
CifName[NOcOL, "$X"];
CifName[met2, "$NM2"];
CifName[cut2, "$NC2"];
CDPanel.DefineLevelEntry[nmos, dif, "dif", 0, 2*CD.lambda];
CDPanel.DefineLevelEntry[nmos, pol, "pol", 0, 2*CD.lambda];
CDPanel.DefineLevelEntry[nmos, met, "met", 0, 3*CD.lambda];
CDPanel.DefineLevelEntry[nmos, cut, "cut", 0, 0];
CDPanel.DefineLevelEntry[nmos, ovg, "ovg", 0, 0];
CDPanel.DefineLevelEntry[nmos, met2, "met2", 0, 3*CD.lambda];
CDPanel.DefineLevelEntry[nmos, cut2, "cut2", 0, 0];
CDPanel.DefineIntEntry[cdValueKey: $CDxSelectNewMode, tech: nmos,
text: "select new:", min: 0, max: 1, default: 1];
CDPanel.DefineNewLine[nmos];
CDPanel.DefineIntEntry[cdValueKey: $CDxStepValue, tech: nmos, text: "step moves size:", min: 1, default: 1];
CDPanel.DefineIntEntry[cdValueKey: $CDxStretchyMove, tech: nmos,
text: "stretchy:", min: 0, max: 1, default: 0];
CDPanel.DefineNewLine[nmos];
BEGIN
patNo: INT = UserProfile.Number[key: "Chipndale.NMos.ChipmonkColorPatternNum", default: 0];
IF patNo#0 THEN {ReadCMPatterns[]; SetChipmonkPatterns[patNo]}
END;
CDEvents.RegisterEventProc[$WriteTechnologyPrivate, WriteTechnologyKey, nmos];
CDEvents.RegisterEventProc[$ReadTechnologyPrivate, ReadTechnologyKey, nmos];
CDSequencer.ImplementCommand[$SetLayerDif, SetLevelDif, nmos];
CDSequencer.ImplementCommand[$SetLayerPol, SetLevelPol, nmos];
CDSequencer.ImplementCommand[$SetLayerMet, SetLevelMet, nmos];
CDSequencer.ImplementCommand[$SetLayerMet2, SetLevelMet2, nmos];
Commander.Register[
key: "CDNewNmos",
proc: NewNWorld,
doc: "Creates new nmos design"
];
Commander.Register[
key: "CDNMosPatterns",
proc: CMPatterns,
doc: "Read chipndale color patterns"
];
END;
SetLevelDif: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["diffusion for default\n"];
CDPanel.StoreDefaultLevel[comm.design, dif]
END;
SetLevelPol: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["poly for default\n"];
CDPanel.StoreDefaultLevel[comm.design, pol]
END;
SetLevelMet: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["metal for default\n"];
CDPanel.StoreDefaultLevel[comm.design, met]
END;
SetLevelMet2: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["metal-2 for default\n"];
CDPanel.StoreDefaultLevel[comm.design, met2]
END;
WriteTechnologyKey: CDEvents.EventProc =
BEGIN
TokenIO.WriteAtom[$Version];
TokenIO.WriteInt[0];
END;
ReadTechnologyKey: CDEvents.EventProc =
BEGIN
dont←TRUE;
IF TokenIO.ReadAtom[]=$Version THEN
IF TokenIO.ReadInt[]=0 THEN dont←FALSE;
IF dont THEN TerminalIO.WriteRope["NMos version miss-match\n"];
END;
--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
backgroundGray ← GetColorGray[background];
whiteGray ← GetColorGray[white];
level: TYPE = [0..15];
colPatNum: CARDINAL=8;
colPatRead: CARDINAL𡤀
colPatternTabs: ARRAY [0..colPatNum) OF ARRAY level OF CARDINAL;
colPatternBits: ARRAY [0..colPatNum) OF CARDINAL;
orLTab: ARRAY level OF CARDINAL ← [11B, 1, 4, 2, 76B, 8, 33B, 10, 9, 1, 10, 62B, 10, 8, 10, 10];
SetChipmonkPatterns: PROC [i: INT] =
BEGIN
fileLevel: ARRAY level OF CD.Level = [
cut, dif, pol, met,
imp, ovg, bur, snerd,
cut2, NOcOL, NOcOL, met2,
NOcOL, nwel, nwelCont, NOcOL];
IF i<0 THEN {
FOR j: NAT IN [0..colPatRead) DO
IF colPatternBits[j]=(-i) THEN {i←j; EXIT}
ENDLOOP
};
IF i>=2 AND i<colPatRead+2 THEN
FOR j: [0..15] IN [0..15] DO
IF fileLevel[j]=imp THEN {
CDTechnology.TeachColorCode[imp0, 4, colPatternTabs[i-2][j]];
CDTechnology.TeachColorCode[impWeak, 4, colPatternTabs[i-2][j]]
};
CDTechnology.TeachColorCode[fileLevel[j], 4, colPatternTabs[i-2][j]]
ENDLOOP
ELSE IF i=1 THEN
FOR j: [0..15] IN [0..15] DO
IF fileLevel[j]=imp THEN {
CDTechnology.TeachColorCode[imp0, 4, orLTab[j]];
CDTechnology.TeachColorCode[impWeak, 4, orLTab[j]]
};
CDTechnology.TeachColorCode[fileLevel[j], 4, orLTab[j]];
ENDLOOP
ELSE IF i=0 THEN Init4BitBricks[]
ELSE {TerminalIO.WriteRope["pattern not found\n"]; RETURN};
FOR l: CDViewer.ViewerList ← CDViewer.ViewersOf[nmos], l.rest WHILE l#NIL DO
IF l.first.column=color THEN ViewerOps.PaintViewer[l.first, client]
ENDLOOP;
END;
CMPatterns: Commander.CommandProc =
BEGIN
n: INT;
IF colPatRead=0 THEN ReadCMPatterns[];
TerminalIO.WriteRope["pattern no [0.."];
TerminalIO.WriteInt[colPatRead+1];
TerminalIO.WriteRope["] > "];
n ← TerminalIO.RequestInt["" ! TerminalIO.UserAbort => GOTO UserAbort];
SetChipmonkPatterns[n]
EXITS
UserAbort => {NULL};
END;
ReadCMPatterns: PROC[fileName: Rope.ROPENIL] =
BEGIN
binfile: IO.STREAM;
k, i, lv: CARDINAL;
GetByte: PROC [] RETURNS[c: [0..255]] = INLINE {
c ← LOOPHOLE[IO.GetChar[binfile], [0..255]];
};
Get2Bytes: PROC [] RETURNS [c: CARDINAL] = INLINE {
h: [0..255] = GetByte[];
c ← h*256+GetByte[];
};
IF fileName=NIL THEN
fileName ← UserProfile.Token[
key: "Chipndale.ChipmonkColorPatterns",
default: "default.CDColorPatterns"
];
binfile ← FS.StreamOpen[fileName ! FS.Error =>
IF error.group # bug THEN {
TerminalIO.WriteRope[fileName];
TerminalIO.WriteRope[" not opened: "];
TerminalIO.WriteRope[error.explanation];
TerminalIO.WriteLn[];
GOTO FileName
}];
k ← MIN[colPatNum, Get2Bytes[]];
colPatRead ← 0;
FOR i IN [0..k) DO
colPatternBits[i]←Get2Bytes[];
FOR lv IN level DO
colPatternTabs[i][lv]←Get2Bytes[];
ENDLOOP;
ENDLOOP;
colPatRead←k;
IO.Close[binfile];
EXITS
FileName => {NULL};
END;
--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Init[];
END.