CMosImpl.mesa
by Ch. Jacobi August 11, 1983 3:56 pm
last edited Christian Jacobi February 16, 1984 2:38 pm
DIRECTORY
CD,
CDEvents,
CDExtras,
CDOps,
CDPanel,
CDProperties,
CDSequencer,
CDTechnology,
CDViewer,
CMos,
Commander USING [CommandProc, Register],
Convert,
FS,
GraphicsColor,
IO,
Rope,
TerminalIO,
TokenIO,
UserProfile,
ViewerOps;
CMosImpl: CEDAR PROGRAM
IMPORTS CD, CDEvents, CDExtras, CDOps, CDPanel, CDProperties, CDSequencer, CDTechnology, CDViewer, Commander, Convert, IO, FS, Rope, TerminalIO, TokenIO, UserProfile, ViewerOps
EXPORTS CMos =
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;
ndif: PUBLIC CD.Level;
met: PUBLIC CD.Level;
imp: PUBLIC CD.Level;
ovg: PUBLIC CD.Level;
bur: PUBLIC CD.Level;
snerd: PUBLIC CD.Level;
pdif: PUBLIC CD.Level;
pwelCont: PUBLIC CD.Level;
met2: PUBLIC CD.Level;
pwel: PUBLIC CD.Level;
nwel: PUBLIC CD.Level;
nwelCont: PUBLIC CD.Level;
NOcOL: PUBLIC CD.Level;
cut2: PUBLIC CD.Level;
CurrentDiffusion: PUBLIC PROC [design: CD.Design] RETURNS [CD.Level] =
BEGIN
lev: CD.Level ← CDPanel.FetchDefaultLevel[design];
IF lev=ndif OR lev=pdif OR lev=pwelCont OR lev=nwelCont THEN RETURN [lev] ELSE RETURN [CD.combined]
END;
CifName: PROC [lev: CD.Level, name: Rope.ROPE] =
BEGIN
CDProperties.PutPropOnLevel[onto: lev, prop: $CDxCIFName, val: name]
END;
SetLevelDif: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["diffusion for default\n"];
CDPanel.StoreDefaultLevel[comm.design, ndif]
END;
SetLevelPol: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["poly for default\n"];
CDPanel.StoreDefaultLevel[comm.design, pol]
END;
SetLevelMet2: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["metal-2 for default\n"];
CDPanel.StoreDefaultLevel[comm.design, met2]
END;
SetLevelMet: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["metal for default\n"];
CDPanel.StoreDefaultLevel[comm.design, met]
END;
SetLevelPDif: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["p-diff for default\n"];
CDPanel.StoreDefaultLevel[comm.design, pdif]
END;
SetLevelNWCnt: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["N-Well Cnt for default\n"];
CDPanel.StoreDefaultLevel[comm.design, nwelCont]
END;
SetLevelPWCnt: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["P-Well Cnt for default\n"];
CDPanel.StoreDefaultLevel[comm.design, pwelCont]
END;
RegisterObjectType: PUBLIC PROC [a: ATOM] RETURNS [REF CD.ObjectProcs] =
BEGIN
RETURN [ CD.RegisterObjectType[a, cmos] ];
END;
NewCWorld: Commander.CommandProc =
BEGIN
design: CD.Design ← CDOps.CreateDesign[cmos];
[] ← CDViewer.CreateViewer[design];
END;
WriteTechnologyKey: CDEvents.EventProc =
BEGIN
TokenIO.WriteAtom[$CMos];
TokenIO.WriteInt[0];
END;
ReadTechnologyKey: CDEvents.EventProc =
BEGIN
dont←TRUE;
IF TokenIO.ReadAtom[]=$CMos THEN
IF TokenIO.ReadInt[]=0 THEN dont←FALSE;
IF dont THEN TerminalIO.WriteRope["CMos version miss-match\n"];
END;
cmos: PUBLIC CD.Technology;
Init4BitBricks: PROC [] =
BEGIN
CDTechnology.TeachColor[cut, 4, [7*ss, 11*ss, 7*ss, 11*ss]];
CDTechnology.TeachColor[ndif, 4, CDTechnology.Brick4[green]];
CDTechnology.TeachColor[pdif, 4, [1*ss, 3*ss, 1*ss, 1*ss]];
CDTechnology.TeachColor[pwelCont, 4, [1*ss, 1*ss, 0*ss, 1*ss]];
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, CDTechnology.Brick4[yellow, 8800H]];
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[snerd, 4, [12345, 7865, 543, 0]];
CDTechnology.TeachColor[cut2, 4, [3*ss, 14*ss, 3*ss, 14*ss]];
CDTechnology.TeachColor[pwel, 4, [4*s1, 0, 0, 0]];
END;
tipTable: Rope.ROPENIL;
NoteProfileChange: UserProfile.ProfileChangedProc =
-- PROC [reason: ProfileChangeReason]
BEGIN
newTipTable: Rope.ROPE ← UserProfile.Token[
key: "Chipndale.CMos.TIPTable",
default: "ChipndaleCMos.TIP"
];
IF ~Rope.Equal[tipTable, newTipTable] THEN {
CDTechnology.SetTipTable[cmos, newTipTable];
tipTable ← newTipTable
}
END;
Init: PROC [] =
BEGIN
TerminalIO.WriteRope["cmos impl\n"];
cmos ← CD.RegisterTechnology[$cmos, "cmos"];
IF cmos=NIL THEN ERROR;
cut ← CD.NewLevel[cmos, $cut];
pol ← CD.NewLevel[cmos, $pol];
ndif ← CD.NewLevel[cmos, $ndif];
met ← CD.NewLevel[cmos, $met];
imp ← CD.NewLevel[cmos, $imp];
ovg ← CD.NewLevel[cmos, $ovg];
bur ← CD.NewLevel[cmos, $bur];
snerd ← CD.NewLevel[cmos, $snerd];
pdif ← CD.NewLevel[cmos, $pdif];
pwelCont ← CD.NewLevel[cmos, $pwelCont];
met2 ← CD.NewLevel[cmos, $met2];
pwel ← CD.NewLevel[cmos, $pwel];
nwel ← CD.NewLevel[cmos, $nwel];
nwelCont ← CD.NewLevel[cmos, $nwelCont];
NOcOL ← CD.NewLevel[cmos, $NOcOL];
cut2 ← CD.NewLevel[cmos, $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[ndif, 1, [4*ss, ss, 4*ss, ss]];
CDTechnology.TeachColor[ndif, 8, CDTechnology.Brick8[green]];
CDTechnology.TeachColor[pdif, 1, [5*ss, ss, 4*ss, ss]];
CDTechnology.TeachColor[pdif, 8, [1*sf, 3*sf, 1*sf, 1*sf]];
CDTechnology.TeachColor[pwelCont, 1, [0*ss, ss, 4*ss, ss]];
CDTechnology.TeachColor[pwelCont, 8, [1*sf, 1*sf, 0*sf, 1*sf]];
CDTechnology.TeachColor[nwelCont, 1, [2*ss, ss, 4*ss, ss]];
CDTechnology.TeachColor[nwelCont, 8, [1*sf, 1*sf, 2*sf, 1*sf]];
CDTechnology.TeachColor[pol, 1, [8*ss, 4*ss, 2*ss, 1*ss]];
CDTechnology.TeachColor[pol, 8, CDTechnology.Brick8[red]];
CDTechnology.TeachColor[met, 1, [8*ss, 2*ss, 0, 0]];
CDTechnology.TeachColor[met, 8, CDTechnology.Brick8[blue]];
CDTechnology.TeachColor[imp, 1, [2*ss, 0, 2*ss, 0]];
CDTechnology.TeachColor[imp, 8, [14, 14, 0, 0]];
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[bur, 1, [4*ss, 14*ss, 4*ss, 0*ss]];
CDTechnology.TeachColor[bur, 8, [11*sf, 11*sf, 11*sf, 11*sf]];
CDTechnology.TeachColor[ovg, 1, [4*ss, 14*ss, 4*ss, 0*ss]];
CDTechnology.TeachColor[ovg, 8, [8*sf, 8*sf, 8*sf, 8*sf]];
CDTechnology.TeachColor[snerd, 1, [12345, 7865, 543, 0]];
CDTechnology.TeachColor[snerd, 8, [12345, 7865, 543, 0]];
CDTechnology.TeachColor[snerd, 1, [12345, 7865, 543, 0]];
CDTechnology.TeachColor[snerd, 8, [12345, 7865, 543, 0]];
CDTechnology.TeachColor[cut2, 1, [3*ss, 14*ss, 3*ss, 14*ss]];
CDTechnology.TeachColor[cut2, 8, [2*ss, 10*ss, 4*ss, 5*ss]];
CDTechnology.TeachColor[pwel, 1, [2*ss, 0, 0, 0]];
CDTechnology.TeachColor[pwel, 8, [4*s1, 0, 0, 0]];
Init4BitBricks[];
CifName[cut, "$NC"];
CifName[ndif, "$N"];
CifName[pol, "$NP"];
CifName[met, "$NM"];
CifName[imp, "$NI"];
CifName[nwel, "$Y"];
CifName[ovg, "$NG"];
CifName[bur, "$NB"];
CifName[snerd, "$U"];
CifName[nwelCont, "$W"];
CifName[NOcOL, "$X"];
CifName[met2, "$NM2"];
CifName[cut2, "$NC2"];
CifName[pdif, "$Q"];
CifName[pwelCont, "$$V"];
CifName[pwel, "$NX"];
CDPanel.DefineLevelEntry[cmos, ndif, "ndif", 0, 2*CD.lambda];
CDPanel.DefineLevelEntry[cmos, pdif, "pdif", 0, 2*CD.lambda];
CDPanel.DefineLevelEntry[cmos, pwelCont, "p-wCnt", 0, 0];
CDPanel.DefineLevelEntry[cmos, nwelCont, "n-wCnt", 0, 0];
CDPanel.DefineLevelEntry[cmos, pol, "pol", 0, 2*CD.lambda];
CDPanel.DefineLevelEntry[cmos, met, "met", 0, 3*CD.lambda];
CDPanel.DefineLevelEntry[cmos, cut, "cut", 0, 0];
CDPanel.DefineLevelEntry[cmos, met2, "met2", 0, 3*CD.lambda];
CDPanel.DefineLevelEntry[cmos, cut2, "cut2", 0, 0];
CDPanel.DefineLevelEntry[cmos, ovg, "ovg", 0, 0];
CDPanel.DefineLevelEntry[cmos, nwel, "nwel", 0, 0];
CDPanel.DefineLevelEntry[cmos, bur, "bur", 0, 0];
CDPanel.DefineIntEntry[cdValueKey: $CDxSelectNewMode, tech: cmos,
text: "select new:", min: 0, max: 1, default: 1];
CDPanel.DefineNewLine[cmos];
CDPanel.DefineIntEntry[cdValueKey: $CDxStepValue, tech: cmos, text: "step moves size:", min: 1, default: 1];
CDPanel.DefineIntEntry[cdValueKey: $CDxStretchyMove, tech: cmos,
text: " stretchy:", min: 0, max: 1, default: 0];
CDPanel.DefineNewLine[cmos];
CDSequencer.ImplementCommand[$SetLayerNDif, SetLevelDif, cmos];
CDSequencer.ImplementCommand[$SetLayerPol, SetLevelPol, cmos];
CDSequencer.ImplementCommand[$SetLayerMet, SetLevelMet, cmos];
CDSequencer.ImplementCommand[$SetLayerMet2, SetLevelMet2, cmos];
CDSequencer.ImplementCommand[$SetLayerPDif, SetLevelPDif, cmos];
CDSequencer.ImplementCommand[$SetLayerNWCnt, SetLevelNWCnt, cmos];
CDSequencer.ImplementCommand[$SetLayerPWCnt, SetLevelPWCnt, cmos];
CDEvents.RegisterEventProc[$WriteTechnologyPrivate, WriteTechnologyKey, cmos];
CDEvents.RegisterEventProc[$ReadTechnologyPrivate, ReadTechnologyKey, cmos];
BEGIN
patNo: INT ← UserProfile.Number[key: "Chipndale.ChipmonkColorPatternNum", default: 0];
IF patNo=0 THEN patNo ← UserProfile.Number[key: "Chipndale.CMos.ChipmonkColorPatternNum", default: 0];
IF patNo#0 THEN {ReadCMPatterns[]; SetChipmonkPatterns[patNo]}
END;
Commander.Register[
key: "CDNewCmos",
proc: NewCWorld,
doc: "Creates new cmos design"
];
Commander.Register[
key: "CDCMosPatterns",
proc: CMPatterns,
doc: "Read chipndale color patterns"
];
Commander.Register[
key: "CDPatterns",
proc: CMPatterns,
doc: "Read chipndale color patterns"
];
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, ndif, pol, met,
imp, ovg, bur, snerd,
cut2, pdif, pwelCont, met2,
pwel, 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
CDTechnology.TeachColorCode[fileLevel[j], 4, colPatternTabs[i-2][j]]
ENDLOOP
ELSE IF i=1 THEN
FOR j: [0..15] IN [0..15] DO
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[cmos], l.rest WHILE l#NIL DO
IF l.first.column=color THEN ViewerOps.PaintViewer[l.first, client]
ENDLOOP;
END;
CMPatterns: Commander.CommandProc =
BEGIN
patNum: INT ← -1;
patFile: Rope.ROPENIL;
s: IO.STREAM ~ IO.RIS[cmd.commandLine];
DO
token: Rope.ROPEIO.GetTokenRope[s ! IO.EndOfStream => EXIT].token;
IF Rope.IsEmpty[token] THEN EXIT;
IF Rope.Fetch[token, 0] IN ['0..'9] THEN {
patNum ← Convert.IntFromRope[token ! Convert.Error => EXIT];
}
ELSE patFile ← CDExtras.AppendExt[token, "CDColorPatterns"];
ENDLOOP;
IF colPatRead=0 OR NOT Rope.IsEmpty[patFile] THEN ReadCMPatterns[patFile];
IF patNum<0 THEN {
TerminalIO.WriteRope["pattern no [0.."];
TerminalIO.WriteInt[colPatRead+1];
TerminalIO.WriteRope["] > "];
patNum ← TerminalIO.RequestInt["" ! TerminalIO.UserAbort => GOTO UserAbort];
};
SetChipmonkPatterns[patNum]
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 Rope.IsEmpty[fileName] THEN
fileName ← UserProfile.Token[
key: "Chipndale.ChipmonkColorPatterns",
default: "default.CDColorPatterns"
];
fileName ← CDExtras.AppendExt[fileName, "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.