(*******************************************************************)
(** Release history:                                              **)
(**    17th January 1985   version 1.0.0 First port to new world  **)
(*******************************************************************)
IMPLEMENTATION MODULE Defaults;
(*
    Title    :  Technology & Display Defaults
    LastEdit :  Thu Jan 10 17:01:56 1985
    Authors  :  GT & LDS
    Acorn Computers VLSI Design Aids Group
*)

IMPORT Strings;
IMPORT Dict;
IMPORT GenDict;
(*IMPORT LLDefaults;*)
FROM Strings IMPORT String;
FROM Dict IMPORT DICT, NewDict, KeyAttr, KeyMatchOptions;
FROM SYSTEM IMPORT WORD;
FROM Streams IMPORT Stream;
VAR
     Values: DICT;
      Names: DICT;
     Layers: DICT;
    MinDict: DICT;
   techDict: DICT;
(*------------------------------------------------------------------------*)
PROCEDURE ReadTechnology(stream :Stream);
BEGIN
  GenDict.ReadDict(stream, Contents); Update()
END ReadTechnology;
(*------------------------------------------------------------------------*)
  PROCEDURE Value(Var :ARRAY OF CHAR) :INTEGER;
  VAR Result :INTEGER;
    Name   :String;
  BEGIN
    Name := Strings.CopyCS(Var);
    IF Dict.Found (Values, Name, Result) THEN END;
    Strings.Dispose(Name);
    RETURN (Result)
  END Value;
  (*---------------------------------------------------------------------*)
  PROCEDURE GetLayNames(VAR ThisLayer :ARRAY OF CHAR; No :WORD;
    VAR LastLayerUsed :WORD) :BOOLEAN;
                        (*-----------------------------------------------*)
                        (*  Parameters are: ThisLayer - Clean string     *)
                        (*                        returned from Dict     *)
                        (*                  No - 'Layer' entered as an   *)
                        (*                        integer, so ORD/VAL    *)
                        (*                        apply.                 *)
                        (*                  Last... Cumulative value     *)
                        (*                        passed by type forcing *)
                        (*                        of 'Layer' to WORD, so *)
                        (*                        inverse cast applies.  *)
                        (*-----------------------------------------------*)
  BEGIN
    IF VAL(CARDINAL,INTEGER(No)) > CARDINAL(LastLayerUsed) THEN
      (* Assumes Layer numbers are contiguous & complete *)
      LastLayerUsed := WORD(VAL(CARDINAL,INTEGER(No)));
(*    LLDefaults.NoOfLayers := INTEGER(No) + 1;*)
    END;
    LayerName [CARDINAL(No)] := Strings.CopyCS(ThisLayer);
(*  Strings.CopyCC(ThisLayer,LLDefaults.LayerName[INTEGER(No)]);*)
    RETURN (FALSE)
  END GetLayNames;
  (*---------------------------------------------------------------------*)
  PROCEDURE GetMinima(VAR ThisLayer :ARRAY OF CHAR; Value :WORD;
    VAR Parm      :WORD) :BOOLEAN;
  VAR NameSTR :String;  layer : CARDINAL;
  BEGIN
    NameSTR := Strings.CopyCS(ThisLayer);
    layer := LayerID(NameSTR);
    MinWidth [layer] := INTEGER(Value);
(*  LLDefaults.MinWidth[ORD(layer)] := INTEGER(Value);*)
    Strings.Dispose(NameSTR);
    RETURN (FALSE)
  END GetMinima;
  (*----------------------------------------------------------------------*)
PROCEDURE Update();
VAR EachLayer    :CARDINAL;
  DefaultWidth :INTEGER;
  EarlyStop    :BOOLEAN;
  DummyWORD    :WORD;
  MinWidthSTR  :String;
BEGIN
  MinWidthSTR := Strings.CopyCS("minwidth");
  LastUsedLayer := 0;
  Lambda := Value("lambda");
  Micron := Value("micron");
  IF Dict.Found (Values, MinWidthSTR, DefaultWidth) THEN
  ELSE DefaultWidth := 0 END;
  EarlyStop := Dict.ForAllIn(Layers,GetLayNames,LastUsedLayer);
  FOR EachLayer := 0 TO LastUsedLayer DO
    MinWidth [EachLayer] := DefaultWidth
  END (* for *);
  EarlyStop := Dict.ForAllIn(MinDict,GetMinima,DummyWORD);
  Strings.Dispose(MinWidthSTR);
END Update;
(*------------------------------------------------------------------------*)
PROCEDURE Dictionary(DictName : ARRAY OF CHAR) : DICT;
VAR Result  :DICT;
  DictSTR :String;
BEGIN
  DictSTR := Strings.CopyCS(DictName);
  IF Dict.Found(techDict,DictSTR,Result) THEN END;
  Strings.Dispose(DictSTR);
  RETURN Result;
END Dictionary;
(*------------------------------------------------------------------------*)
PROCEDURE LayerID (Name :String) : CARDINAL;
VAR Result  :CARDINAL;
BEGIN
  IF Dict.Found(Layers, Name, Result) THEN END;
  RETURN Result;
END LayerID;

PROCEDURE Layer(Name: ARRAY OF CHAR): CARDINAL;
VAR name: String;
  Result  :CARDINAL;
BEGIN
  name := Strings.CopyCS(Name);
  IF Dict.Found(Layers, name, Result) THEN END;
  Strings.Dispose(name);
  RETURN Result;
END Layer;

BEGIN
(*------------------------------------------------------------------------*)
  Contents    := NewDict("Contents");
  techDict    := NewDict("technology");
  Dict.Enter(Contents, "technology", KeyAttr{}, techDict);
  Values      := NewDict("Value");
  Dict.Enter(techDict, "Value",       KeyAttr{},  Values);
  Names       := NewDict("Text");
  Dict.Enter(techDict, "Text",        KeyAttr{},  Names);
  Layers      := NewDict("Layer");
  Dict.Enter(techDict, "Layer",       KeyAttr{},  Layers);
  MinDict     := NewDict("MinWidth");
  Dict.Enter(techDict, "MinWidth",    KeyAttr{},  MinDict);
(*------------------------------------------------------------------------*)  
  Dict.Enter(Values, "lambda", KeyAttr{}, 50);
  Dict.Enter(Values, "micron", KeyAttr{}, 100);
  Dict.Enter(Values, "minwidth", KeyAttr{ExactLength}, 0);
(*------------------------------------------------------------------------*)
  Dict.Enter(Layers, "bbox",       KeyAttr{ExactLength}, 1);
  Dict.Enter(Layers, "contact",    KeyAttr{ExactLength}, 2);
  Dict.Enter(Layers, "drcerror",   KeyAttr{ExactLength}, 3);
  Dict.Enter(Layers, "glass",      KeyAttr{ExactLength}, 4);
  Dict.Enter(Layers, "metal",      KeyAttr{ExactLength}, 5);
  Dict.Enter(Layers, "metaltwo",   KeyAttr{ExactLength}, 6);
  Dict.Enter(Layers, "ndiff",      KeyAttr{ExactLength}, 7);
  Dict.Enter(Layers, "nimpcd",     KeyAttr{ExactLength}, 8);  (* cd *)
  Dict.Enter(Layers, "nwell",      KeyAttr{ExactLength}, 9);
  Dict.Enter(Layers, "pdiff",     KeyAttr{ExactLength}, 10);
  Dict.Enter(Layers, "pimpcd",    KeyAttr{ExactLength}, 11);  (* cd *)
  Dict.Enter(Layers, "poly",      KeyAttr{ExactLength}, 12);
  Dict.Enter(Layers, "polytwo",   KeyAttr{ExactLength}, 13);
  Dict.Enter(Layers, "pwell",     KeyAttr{ExactLength}, 14);
  Dict.Enter(Layers, "via",       KeyAttr{ExactLength}, 15);
  Dict.Enter(Layers, "contaccd",  KeyAttr{ExactLength}, 16);
  Dict.Enter(Layers, "fieldcd",   KeyAttr{ExactLength}, 17);
  Dict.Enter(Layers, "glasscd",   KeyAttr{ExactLength}, 18);
  Dict.Enter(Layers, "metalcd",   KeyAttr{ExactLength}, 19);
  Dict.Enter(Layers, "npluscd",   KeyAttr{ExactLength}, 20);
  Dict.Enter(Layers, "nwellcd",   KeyAttr{ExactLength}, 21);
  Dict.Enter(Layers, "ppluscd",   KeyAttr{ExactLength}, 22);
  Dict.Enter(Layers, "polycd",    KeyAttr{ExactLength}, 23);
  Dict.Enter(Layers, "pwellcd",   KeyAttr{ExactLength}, 24);
(*------------------------------------------------------------------------*)
  Dict.Enter(MinDict, "bbox",       KeyAttr{ExactLength}, 0);
  Dict.Enter(MinDict, "contact",    KeyAttr{ExactLength}, 6);
  Dict.Enter(MinDict, "drcerror",   KeyAttr{ExactLength}, 0);
  Dict.Enter(MinDict, "glass",    KeyAttr{ExactLength}, 220);
  Dict.Enter(MinDict, "metal",      KeyAttr{ExactLength}, 8);
  Dict.Enter(MinDict, "metaltwo",   KeyAttr{ExactLength}, 8); (* Error *)
  Dict.Enter(MinDict, "ndiff",      KeyAttr{ExactLength}, 7);
  Dict.Enter(MinDict, "nimpcd",     KeyAttr{ExactLength}, 7);    (* cd *)
  Dict.Enter(MinDict, "nwell",      KeyAttr{ExactLength}, 5);
  Dict.Enter(MinDict, "pdiff",      KeyAttr{ExactLength}, 7);
  Dict.Enter(MinDict, "pimpcd",     KeyAttr{ExactLength}, 7);    (* cd *)
  Dict.Enter(MinDict, "poly",       KeyAttr{ExactLength}, 6);
  Dict.Enter(MinDict, "polytwo",    KeyAttr{ExactLength}, 6);
  Dict.Enter(MinDict, "pwell",     KeyAttr{ExactLength}, 20);
  Dict.Enter(MinDict, "via",        KeyAttr{ExactLength}, 7);
  (****************************************************)
  (* remainder of cd layers to 0                      *)
  (****************************************************)
  Update ()
END Defaults.
