{ PLA chip generator, with the PLA described as equations, Tables or Roms}
{                                                                        }
{ Current version restricted to all inputs at bottom, all outputs at top }

Program Pla_Chip_Generator (input,output);

Const
   %Include 'ilap:nmos.consts'
   max_port = 100;

Type
   %Include 'ilap:nmos.types'

Var
   Mode,rest:char;
   datafile, outfile :string[255];

%Include 'ilap:nmos.specs'

Procedure Pla_Chip (mode:char; datafile, outfile:string);

   Var
      p1,p2 : integer;
      outs,ins,i : integer;
      null             : array [1..1] of integer;
      ia,oa            : array [1..Max_Port] of Integer;
      ports            : array [1..Max_Port] of Connf;
      
   Begin      
      initialise (outfile);

      If mode = 'e' then
         sepla ('pla', datafile, topoutputs, null,null, p1,p2,ia,oa)
      else If mode = 't' then
         stpla ('Pla', datafile, topoutputs, null, null, p1, p2, ia, oa)
      else
         srom ('Pla',datafile,topoutputs, null, null, p1,p2, ia, oa);

      pladatasize (ins, outs);
      
      fillport (ports[1], vddpad, left, 0, 8, metal);
      fillport (ports[2], inpad,  left, p1, 2, poly);
      fillport (ports[3], inpad,  right, p2, 2, poly);
      fillport (ports[4], gndpad, right, 0, 8, metal);
      for i := 1 to ins do begin
         fillport (ports[i+4], inpad, bottom, ia[i], 2, diffusion);
      end;
      ins := ins + 4;
      for i := 1 to outs do begin
         fillport (ports[i+ins], outpad, top, oa[i], 2, diffusion);
      end;
      i := outs+ins;
      placepads ('Pla chip', 'Pla', ports, outs+ins);
      finish;
   End;

Begin
   prompt ('PLA from Equations, Truth Tables or Rom data (E, T, or R)? ');
   repeat
      read (mode);
   until (mode='e') or (mode='t') or (mode='r');
   readln;
   prompt ('File name containing PLA data: ');
   readln (datafile);
   prompt ('File name for the chip: ');
   readln (outfile);
   pla_chip (mode, datafile, outfile);
end.
