-- ChipReticle.mesa

-- last modified by E. McCreight, November 22, 1982  1:40 PM
-- written by E. McCreight, March 18, 1982  5:29 PM

DIRECTORY
  ChipNetDefs,
  FeaturePST,
  LeftFeaturePQ,
  ppdefs,
  ReticleBandFormat,
  StreamDefs;

ChipReticle: DEFINITIONS =
  BEGIN OPEN ppdefs, ChipNetDefs;

  Masks: TYPE = ExtractLevel;

  ReticlePolarity: TYPE = {transparent, opaque};

  ReticleUnit: TYPE = ReticleBandFormat.LongCoord;
  siliconToReticleFactor: INTEGER = 10;
  reticleUnitsPerMicron: ReticleUnit = 2;
  coordsPerReticle: Coord = 1000/reticleUnitsPerMicron;
    -- a Coord is a nanometer

  ReticlePoint: TYPE = RECORD[x, y: ReticleUnit];

  ReticleRect: TYPE = RECORD [
    x1, x2, y1, y2: ReticleUnit
    ];

  RectsPerBlock: INTEGER = 100;
  CoordRectBlockPtr: TYPE = LONG POINTER TO
    CoordRectBlock ← NIL;
  CoordRectBlock: TYPE = ARRAY[0..RectsPerBlock) OF
    CoordRect;

  ReticleStatePtr: TYPE = LONG POINTER TO ReticleState ← NIL;
  ReticleState: TYPE = RECORD [
    mask: Masks,
    inReticleSet: BOOLEAN,
    slice: FeaturePST.FeaturePSTHandle ← NIL,
     -- the slice contains the active features under the scan
     -- line, independent of field polarity
    fieldPolarity: ReticlePolarity,
      -- in the active circuit area, the inactive area (no features)
      -- of this mask should be written in this polarity:
      -- transparent or opaque.
    fieldRect: CoordRect ← [0,0,0,0],
     -- if fieldPolarity is transparent, this is the rectangle that
     -- should be covered, except where there are active features.
    cover: FeaturePST.FeaturePSTHandle ← NIL,
     -- the cover is a set of non-overlapping semi-infinite
     -- (in .x2) set of rectangles that will be written transparent
     -- on the reticle.
    designAreaStarted, designAreaFinished: BOOLEAN ← FALSE,
    stretch: Coord ← 0,
    file: StreamDefs.DiskHandle ← NIL,
    block: CoordRectBlockPtr,
    lastRect: CoordRect ← [0,0,0,0],
    rectCount: LONG INTEGER ← 0
    ];

  makingReticles: BOOLEAN;

  ExtractReticles: PROCEDURE[univLp: listPtr];

  CoordBox: PROCEDURE[center, diameter: CoordPoint,
    offset: CoordPoint ← [0,0]] RETURNS[CoordRect];

  InitMaskStates: PROCEDURE[];

  maskStates: ARRAY Masks OF ReticleState;

  reticleName: PRIVATE STRING;

  herald: PRIVATE ReticleBandFormat.HeraldObject;

  reticleSize, reticleCenter: PRIVATE CoordPoint;
  reticleDesign, alignedDesign: PRIVATE CoordRect;

  NoteFeature, ForgetFeature:
    PRIVATE PROCEDURE[state: ReticleStatePtr,
      f: FeaturePtr];

  SetStretches: PRIVATE PROCEDURE[];

  CircumscribeAndBeyond: PRIVATE PROCEDURE[
    q: LeftFeaturePQ.LeftFeaturePQHandle,
    design: CoordRect];

  DrawFiducials: PRIVATE PROCEDURE[
    q: LeftFeaturePQ.LeftFeaturePQHandle];

  FinishMask: PRIVATE PROCEDURE[state: ReticleStatePtr,
    mask: Masks,
    showMasks: BOOLEAN, screenClip: CoordRect];

  WriteCoordRect: PRIVATE PROCEDURE[mask: Masks,
    r: CoordRect];

  NewReticleFeature: PRIVATE PROCEDURE[cover: CoordRect,
    mask: Masks, lq: LeftFeaturePQ.LeftFeaturePQHandle ← NIL]
    RETURNS[FeaturePtr];

  END. -- of ChipReticle