-- wiresDefs2.mesa

WiresDefs:DEFINITIONS=BEGIN

OnI:TYPE=PROCEDURE[i:INTEGER];
CR:CHARACTER=’
;
-- Stuff for Graphics

Hop:TYPE=INTEGER;
Circuit:TYPE=INTEGER;
GridXY:TYPE=INTEGER;
Dir:TYPE={h,v,none};
Direction:TYPE={h,v};
Loc:TYPE=[0..128);
Slot: TYPE={chanA,gate,chanB,none};
Contact:TYPE=Slot[chanA..chanB];
OrientState:TYPE={none,unkn,gHorr,aLeft,cLeft,gVert,aDown,cDown};
RedOrient:TYPE={none,ul,lr,both};
Color:TYPE={none,r,g,b};
Way:TYPE={l,r,u,d,none};
Twist:TYPE={none,n,b,f,s,a};

topCircuit:Circuit=1000;
nullCircuit:Circuit=topCircuit;
nullTransistor:Transistor=[nullCircuit,nullCircuit,nullCircuit];
--nilOrientation:OrientData=
-- [state:unkn,red:none,num:0,leftSeg:NIL,rightSeg:NIL,
-- upSeg:NIL,downSeg:NIL];
terminalHop:Hop=10000;
nilOrient:Orient=[NIL,0];

Where: TYPE=RECORD[h,l:BOOLEAN,x,y:[0..128)];
-- h => horizontal, l => level=blue
Node: TYPE=RECORD[s:SegPtr,hop:Hop,
back:NodePtr,normal,movingLD,l:BOOLEAN,contact: Slot];
Follow: TYPE=RECORD[s:SegPtr];
Location: TYPE=RECORD[contact:Contact,i,j:Loc];
Coords: TYPE=RECORD[d:Dir,x,y:Loc];
Transistor:TYPE=RECORD[a,b,c:Circuit];
Wire: TYPE=RECORD[a,b:Location,c:Color,l,circuit:INTEGER];
Orient: TYPE=RECORD[seg:SegPtr,num:[0..16)];
OrientData:TYPE=RECORD[state: OrientState,pullup,pullupToC: BOOLEAN,
num: INTEGER,leftSeg,rightSeg,upSeg,downSeg:Seg];
Seg: TYPE=RECORD[c:Color,circuit:INTEGER,stick:StkPtr,xy:Where,
nc,bc,ac,dummy:BOOLEAN,w:Way,next,back,first,second,across:SegPtr];
-- dummy => not really part of a wire
-- nc,bc,ac => connected to next,back,across (levels) resp.
-- way is defined only for dummies
Stk: TYPE=RECORD[c:Color, circuit: INTEGER,
dir:Direction,major,minor1,minor2:INTEGER];

WirePtr: TYPE=POINTER TO Wire;
OrientPtr:TYPE=POINTER TO Orient;
OrientDataPtr:TYPE=POINTER TO OrientData;
NodePtr: TYPE=POINTER TO Node;
FollowPtr:TYPE=POINTER TO Follow;
SegPtr: TYPE=POINTER TO Seg;
StkPtr: TYPE=POINTER TO Stk;


--CIRCUITS
EnumerateWires:PROCEDURE[call:PROCEDURE[WirePtr]];
MakeWireList:PROCEDURE[BOOLEAN];
PrintWireList:PROCEDURE;
ChangeWireScale:PROCEDURE;
WireLength: PROCEDURE[i,j: Location] RETURNS[INTEGER];
--CONTROL
AllocateStuffForCreate:PROCEDURE[PROCEDURE];
--GRID
EnumerateGrid:PROCEDURE[call:PROCEDURE[i,j:INTEGER]];
EnumerateGridPlusOne:PROCEDURE[call:PROCEDURE[i,j:INTEGER]];
EnumerateGridPlusTwo:PROCEDURE[call:PROCEDURE[i,j:INTEGER]];
ClearGrid:PROCEDURE[i,j:INTEGER];
EnumerateSide:PROCEDURE[call:PROCEDURE[INTEGER]];
EnumerateSidePlusOne:PROCEDURE[call:PROCEDURE[INTEGER]];
EnumerateSidePlusTwo:PROCEDURE[call:PROCEDURE[INTEGER]];
--INPUT STUFF
GetInput:PROCEDURE[BOOLEAN];
--PRINTING
PrintG:PROCEDURE;
--GRAPHICS
PutBox:PROCEDURE[color:Color,x,y,m,n:CARDINAL];
--
Graphics Display Procedures
DoOutputs: PROCEDURE[name:STRING,limitX,limitY:INTEGER];
-- Segs
InitSegs:PROCEDURE;
--EnumerateSegs:PROCEDURE[start:SegPtr,call:PROCEDURE[SegPtr]];
--FindXYFromSeg:PROCEDURE[s:SegPtr] RETURNS[x,y:INTEGER,w:Way];
ShowSeg:PROCEDURE[s:SegPtr] RETURNS[INTEGER];
PrintSegs:PROCEDURE;
SetPullup:PROCEDURE[Location];
PrintOneSeg:PROCEDURE[s:SegPtr];
--ClearOrientation:PROCEDURE[i,j:INTEGER];
SetSeg:PROCEDURE[from:NodePtr,col:Color, circuit: INTEGER,old: SegPtr,
tieN,tieB:BOOLEAN] RETURNS[SegPtr];
--AddToSeg:PROCEDURE RETURNS[ret:SegPtr];
SetInitialSegment:PROCEDURE[l:Location,n:NodePtr,circuit: INTEGER]
RETURNS[BOOLEAN,BOOLEAN];
SetFinalSegment:PROCEDURE[l:Location,s:SegPtr,n:NodePtr,circuit: INTEGER];
--Stks
TurnToStks:PROCEDURE[print:BOOLEAN] RETURNS[limitX,limitY: INTEGER];
PrintStks:PROCEDURE;
--orient
--NextOrient:PROCEDURE[Orient,Location] RETURNS[Orient];
EnumerateOrient:PUBLIC PROCEDURE[Location,PROCEDURE[SegPtr, Contact]
RETURNS[BOOLEAN]] RETURNS[BOOLEAN];
PrintOrientations: PROCEDURE[i,j:INTEGER];
--Control
AllocateStuffForSeg:PROCEDURE;

debugPrint:BOOLEAN;
side:Loc;
maxSide:Loc=10;
gridType:TYPE=ARRAY [0..maxSide) OF ARRAY[0..maxSide) OF Transistor;
grid:POINTER TO gridType;
END..