-- ROMMakerDefs.mesa
-- a program to run within Chipmonk

-- last modified by E. McCreight, February 2, 1982  5:49 PM
-- written by E. McCreight, October 7, 1981  6:18 PM

DIRECTORY
  ppddefs,
  ppdefs;

RomMakerDefs: DEFINITIONS =
  BEGIN OPEN ppddefs, ppdefs;


  --    T y p e s

  Direction: TYPE = {
    vertical, horizontal, diagonal, up, down, left, right, upAndLeft, upAndRight,
    downAndLeft, downAndRight};

  topRight: Direction = upAndRight; -- synonyms
  topLeft: Direction = upAndLeft;
  bottomRight: Direction = downAndRight;
  bottomLeft: Direction = downAndLeft;

  ListPtr: TYPE = listPtr;
  Cell: TYPE = obPtr;
  DCell: TYPE = ARRAY BOOLEAN --data in cell-- OF Cell;
  DCellPr: TYPE = ARRAY BOOLEAN -- data in even cell -- OF DCell;

  NameGroup: TYPE = RECORD [
    x, y: Point ← [x: 1 -- coefficient --, y: 0 -- offset --],
    basicName: STRING ← NIL
    ];
  nilNameGroup: NameGroup = [];


--    V a r i a b l e s

  lpp: ListPtr; -- where new list elements are assembled

  uz: UNCOUNTED ZONE;

  dirFactor: ARRAY Direction OF Point;


--    P r o c e d u r e s

  FindCell: PROCEDURE [
    cellFamily: STRING, member: STRING, required: BOOLEAN ← FALSE,
    vCompat: Cell ← NIL, hCompat: Cell ← NIL] RETURNS [Cell];

  FindDCell: PROCEDURE [
    cellFamily, memberPrefix: STRING, required: BOOLEAN ← FALSE,
    vCompat: Cell ← NIL, hCompat: Cell ← NIL] RETURNS [d: DCell];

  FindDCellPr: PROCEDURE [
    cellFamily, memberPrefix: STRING, required: BOOLEAN ← FALSE,
    vCompat: Cell ← NIL, hCompat: Cell ← NIL] RETURNS [p: DCellPr];

  CheckPitchCompatability: PROCEDURE [
    c1, c2: Cell, dir: Direction, rep1: Point ← [1, 1], rep2: Point ← [1, 1]];


  Repeat: PROCEDURE[p: Point, cell: Cell, corner: Direction ← topLeft,
    dir: Direction ← horizontal, rep: locNum ← 1,
    midCell: Cell ← NIL, midGap: locNum ← 0,
    altCell: Cell ← NIL, altMod: INTEGER ← 0,
    name, midName: NameGroup ← nilNameGroup];


  RepeatArbitrary: PROCEDURE[p: Point, cp: PROCEDURE[i: INTEGER] RETURNS[Cell],
    corner: Direction ← topLeft, dir: Direction ← upAndLeft,
    rep: INTEGER ← 1, midCell: Cell ← NIL, midGap: locNum ← 0,
    name, midName: NameGroup ← nilNameGroup];


  MakeMidGrid: PROCEDURE[p: Point, cell: Cell, rep: Point,
    midVCell, midHCell, midVHCell: Cell ← NIL, midGap: Point ← [0,0]];


  PlaceCell: PROCEDURE[p: Point, cell: Cell, rep: Point ← [0,0], midCellSize: Point ← [0,0],
    midGap: Point ← [0,0], name: NameGroup ← nilNameGroup];


  DirSize: PROCEDURE[size: Point, dir: Direction ← diagonal] RETURNS[Point];


  CellSize: PROCEDURE[cell: Cell, dir: Direction ← diagonal] RETURNS[Point];


  Offset: PROCEDURE[p: Point ← [0, 0], cell: Cell, dir: Direction, rep: Point ← [0, 0],
    midCell: Cell ← NIL, midCellSize: Point ← [0,0],
    midGap: Point ← [0, 0], includeTerminalMid: BOOLEAN ← TRUE]
    RETURNS [Point];


  BlockSize: PROCEDURE [cell: Cell, rep: Point ← [1, 1],
    midCell: Cell ← NIL, midGap: Point ← [0, 0]]
    RETURNS [Point];


  MakeNewCell: PROCEDURE [name: STRING, lpp: ListPtr]
    RETURNS [cp: LONG POINTER TO cList];

  AddToMasterList: PROCEDURE[lpp: ListPtr];

  DrawCell: PROCEDURE [obp: Cell];

  BuildRom: PROCEDURE[];

  BuildDecoder: PROCEDURE[];

  END. -- of RomMakerDefs