-- File CIFReticleControl.mesa
-- Written by Martin Newell, June 1981
-- Last updated: June 4, 1981 11:14 AM

DIRECTORY

CIFControlDefs: FROM "CIFControlDefs" USING [DrawCIF],
CIFDevicesDefs: FROM "CIFDevicesDefs" USING [DeviceDescriptor, DeviceDescriptorRecord,
RegisterDevice, MaxLENGTHLayerArray, GetCIFOutDevice],
CIFOutputDefs: FROM "CIFOutputDefs" USING [SetSorting],
CIFUtilitiesDefs: FROM "CIFUtilitiesDefs" USING [Rectangle,
SetClipRectangle, GetClipRectangle, DrawClipRectangle,
SetDisplayContext, GetDisplayContext],
Graphics: FROM "Graphics" USING [DisplayContext, NewContext, PushContext, PopContext, Scale, Translate],
IODefs: FROM "IODefs" USING [NUL, WriteString, WriteLine, WriteDecimal,
WriteChar],
JaMFnsDefs: FROM "JaMFnsDefs" USING [PopString],
PressDefs: FROM "PressDefs" USING[
InitPressFileDescriptor,
ClosePressFile, PressFileDescriptor, PutRectangle,
StartOutline, PutDrawTo, EndOutline],
Real: FROM "Real" USING [FixC, Fix],
StringDefs: FROM "StringDefs" USING[AppendString,
AppendDecimal, AppendChar],
SystemDefs: FROM "SystemDefs" USING [AllocateHeapNode, FreeHeapNode,
AllocateHeapString, FreeHeapString];

CIFReticleControl: PROGRAM
IMPORTS CIFControlDefs, CIFDevicesDefs, CIFOutputDefs, CIFUtilitiesDefs, Graphics, IODefs, JaMFnsDefs, PressDefs, Real, StringDefs, SystemDefs =

BEGIN OPEN CIFControlDefs, CIFDevicesDefs, CIFOutputDefs, CIFUtilitiesDefs, Graphics, IODefs, JaMFnsDefs, PressDefs, Real, StringDefs, SystemDefs;


-- Reticle procedures

ReticleDeviceRecord: DeviceDescriptorRecord ← [
next:NIL,
name:"reticle",
deviceSelect: ReticleSelect,
deviceDrawFrame: ReticleDrawFrame,
deviceSetScale: ReticleSetScale,
deviceSetClipRegion: ReticleSetClipRegion,
deviceOutput: ReticleOutput,
deviceLayer: ReticleLayer,
deviceLoadLayer: ReticleLoadLayer,
deviceRectangle: ReticleRectangle,
deviceStartPoly: ReticleStartPoly,
devicePolyVertex: ReticlePolyVertex,
deviceEndPoly: ReticleEndPoly,
deviceText: ReticleText
];

ReticleSelect: PROCEDURE RETURNS[BOOLEAN] =
BEGIN
ReticleSetClipRegion[GetClipRectangle[]];
RETURN[TRUE];
END;

ReticleDrawFrame: PROCEDURE =
BEGIN
r: Rectangle ← GetClipRectangle[];
DrawClipRectangle[];
END;

ReticleSetScale: PROCEDURE [factor: REAL] =
BEGIN
ReticleScale ← factor;
END;

ReticleSetClipRegion: PROCEDURE [rt: Rectangle] =
BEGIN
SetClipRectangle[rt];
END;

ReticleOutput: PROCEDURE =
--expects <filename> (STRING)
BEGIN
fileName: STRING ← [100];
saveContext: DisplayContext ← GetDisplayContext[];
r: Rectangle ← GetClipRectangle[]; --clipping region in CIF units
s: REAL ← ReticleScale/ReticleResolution;
PopString[fileName];
SetDisplayContext[reticleContext];
PushContext[reticleContext];
Translate[reticleContext, [ReticleCenter,ReticleCenter]]; --to center of Reticle region
Scale[reticleContext, [s,s]];
Translate[reticleContext, [-(r.llx+r.urx)/2,-(r.lly+r.ury)/2]]; --window center to origin
--
reticleClipRectangle ← MapRectangle[r,reticleContext,identityContext];
SetClipRectangle[r];
ReticleStart[fileName];
DrawCIF[Floor[r.llx],Floor[r.urx],Ceiling[r.lly],Ceiling[r.ury]];
ReticleEnd[];
PopContext[reticleContext];
SetDisplayContext[saveContext];
SetClipRectangle[r];
END;

ReticleStart: PROCEDURE[fileName: STRING] =
BEGIN
baseFileName.length ← 0;
AppendString[baseFileName,fileName];
PFD ← ALL[NIL];
FileName ← ALL[NIL];
SetSorting[none];
ReticleCurrentLayer ← 32000; --i.e. not set
END;

localName: STRING ← [50]; --in global frame since press shares it

ReticleEnd: PROCEDURE =
BEGIN
name12: STRING ← [12];
WriteLine["ReticleMaker output"];
FOR i:CARDINAL IN [0..MaxLENGTHLayerArray) DO
IF PFD[i]#NIL THEN
{
ClosePressFile[PFD[i]];
FreeHeapNode[PFD[i]];
FreeHeapString[FileName[i]];
WriteString["Layer "];
WriteDecimal[i];
IF LayerChar[i]#NUL THEN
{WriteString[" (N"];
WriteChar[LayerChar[i]];
WriteChar[’)];
};
WriteString[" on file "];
WriteString[baseFileName];
WriteChar[’-];
WriteDecimal[i];
WriteLine[".press."];
};
ENDLOOP;
END;

ReticleLayer: PROCEDURE [layer: CARDINAL] =
BEGIN
IF layer#ReticleCurrentLayer THEN
BEGIN
IF PFD[layer]=NIL THEN
{FileName[layer] ← AllocateHeapString[40];
AppendString[FileName[layer],baseFileName];
AppendChar[FileName[layer],’-];
AppendDecimal[FileName[layer],layer];
AppendString[FileName[layer],".press"];
PFD[layer] ← AllocateHeapNode[SIZE[PressFileDescriptor]];
InitPressFileDescriptor[PFD[layer],FileName[layer]];
};
ReticleCurrentLayer ← layer;
END;
END;

ReticleLoadLayer: PROCEDURE[layer:CARDINAL, v0,v1,v2,v3: CARDINAL] =
BEGIN
END;

ReticleText: PROCEDURE[text: STRING, x,y: REAL] =
BEGIN
END;


--Private procedures--

ReticleRectangle: PROCEDURE [r: Rectangle] =
BEGIN
left: CARDINAL ← FixC[r.llx];
bottom: CARDINAL ← FixC[r.lly];
right: CARDINAL ← FixC[r.urx];
top: CARDINAL ← FixC[r.ury];
PutRectangle[PFD[ReticleCurrentLayer],
left, bottom, right-left, top-bottom];
END;

ReticleStartPoly: PROCEDURE [x,y: REAL] =
BEGIN
StartOutline[PFD[ReticleCurrentLayer], FixC[x], FixC[y]];
END;

ReticlePolyVertex: PROCEDURE [x,y: REAL] =
BEGIN
PutDrawTo[PFD[ReticleCurrentLayer], FixC[x], FixC[y]];
END;

ReticleEndPoly: PROCEDURE =
BEGIN
EndOutline[PFD[ReticleCurrentLayer]];
END;


----
Ceiling: PROCEDURE[r: REAL] RETURNS[c: LONG INTEGER] = INLINE
BEGIN --"Truncate" r up to next integer
IF r>0 THEN
{b: LONG INTEGER ← Fix[r] + 1;
c ← Fix[r-b] + b;
}
ELSE c ← Fix[r];
END;

Floor: PROCEDURE[r: REAL] RETURNS[c: LONG INTEGER] = INLINE
BEGIN --"Truncate" r down to next integer
IF r<0 THEN
{b: LONG INTEGER ← -Fix[r] + 1;
c ← Fix[r+b] - b;
}
ELSE c ← Fix[r];
END;

--Reticle parameters
reticleContext: DisplayContext ← NewContext[GetCIFOutDevice[]];
baseFileName: STRING ← [100];

ReticleScale: REAL ← 1;
ReticleResolution: REAL = 50; --in units of 0.01 micron
ReticleCenter: REAL = 16000; --in reticlemaker units

ReticleCurrentLayer: CARDINAL;
PFD: ARRAY [0..MaxLENGTHLayerArray) OF POINTER TO PressFileDescriptor;
FileName: ARRAY [0..MaxLENGTHLayerArray) OF STRING; --used to hold onto filenames of press files since PressOut doesn’t copy
LayerChar: ARRAY [0..MaxLENGTHLayerArray) OF CHARACTER ← ALL[NUL];

--Set up CIF Layer names
LayerChar[0] ← ’I;
--implant
LayerChar[1] ← ’D;
--diffusion
LayerChar[2] ← ’P;
--poly
LayerChar[3] ← ’C;
--contact
LayerChar[4] ← ’M;
--metal
LayerChar[5] ← ’B;
--buried
LayerChar[6] ← ’G;
--glass

RegisterDevice[@ReticleDeviceRecord];

END.