! ILAP stack generator

%include "nmos.inc"

{#########################################################################}
{#                                                                       #}
{#      This program is part of the ILAP library, and was written in     #}
{#   The Department of Computer Science at the University of Edinburgh   #}
{#       (James Clerk Maxwell Building, Kings Buildings, Edinburgh)      #}
{#                                                                       #}
{#   This software is available free to other educational establisments  #}
{#   but the University of Edinburgh, retains all commercial rights.     #}
{#   It is a condition of having this software is that the sources are   #}
{#   not passed on to any other site, and that Edinburgh University is   #}
{#   given credit in any re-implementations of any of the algorithms     #}
{#   used, or articles published which refer to the software.            #}
{#                                                                       #}
{#   There is no formal support for this software, but any bugs should   #}
{#   be reported to Gordon Hughes or David Rees at the above address,    #}
{#   and these are likely to be fixed in a future release.               #}
{#                                                                       #}
{#########################################################################}

%externalroutine stack %alias "ILAP_STACK" (%string(31) name,%integer bits,words,
   %integer %name controlx, controly, pushcony, popcony,
   phi1x, phi2x, phi3x, phi4x,
   %integer %array %name pushy,
   %integer %array %name popy)
%routinespec stackcellcon(%integer offset)
%routinespec controlcon
%routinespec positioncell(%string(13) cell,ground,
                          %integer cellypitch,cellxpitch,gndypitch,
                          %integer %name xcur,ycur)
%integer stackcellxpitch,stackcellypitch,conypitch,stackcellgndypitch
%integer i,j,curx,cury,stackcellpushy,stackcellpopy,controlypitch
%integer stackcellaxpitch, stackx, stacky
  %if symbol exists("stackcell")=true %then ->gen
%include "stack.ted"     {defines "Stack cell" }
%include "stackc.ted"    {defined "Stack Control Half" }
  symbol("Stack cell null")
    layer(metal)
      box(0,0,4,28) ; box(27,0,31,28) ; box(54,0,58,28)
    layer(diffusion)
      box(0,2,58,4) ; box(0,25,58,27)
  endsymbol
  symbol("Stack cell vdd")
    layer(metal)
      box(0,0,58,4) ; box(27,4,31,8)
  endsymbol
  symbol("Stack control top")
    layer(poly)
      box(9,0,11,6) ; box(24,0,26,6) ; box(42,0,44,12)
      box(68,0,70,12) ; box(86,0,88,6)
    layer(metal)
      pm(10,8) ; box(8,10,12,24)
      pm(25,8) ; box(27,6,85,9) ; pm(87,8) ; box(85,10,89,24)
      pm(42,14) ; box(44,12,68,15) ; pm(70,14) ; box(68,16,72,24)
      pm(102,2) ; box(16,0,100,3) ; box(16,3,20,24)
    layer(diffusion)
      box(45,0,47,19) ; box(0,17,45,19)
      box(65,0,67,24) ; box(0,22,65,24)
  endsymbol
  symbol("Stack control")
    draw("Stack controlhalf",0,0)
    drawmx("Stack controlhalf",112,0)
    draw("Stack controltop",0,48)
  endsymbol
  symbol("Stack control con1")
    controlcon
    stackcellcon(0)
    layer(diffusion)
      box(11,3,41,5) ; box(17,9,20,12)
      box(38,15,88,17) ; dm(90,16) ; box(51,21,73,23)
  endsymbol
  symbol("Stack control con2")
    controlcon
    stackcellcon(0)
    stackcellcon(54)
    layer(diffusion)
      box(11,3,61,5) ; box(17,9,20,12) ; box(24,9,74,11)
      box(38,15,88,17) ; box(51,21,101,23)
  endsymbol
  symbol("Stack control conn")
    controlcon
    stackcellcon(0)
    stackcellcon(54)
    layer(diffusion)
      box(11,3,112,5) ; box(17,9,20,12) ; box(24,9,112,11)
      box(38,15,112,17) ; box(51,21,112,23)
  endsymbol
  symbol("Stack cell con")
    stackcellcon(0)
    layer(diffusion)
      box(0,3,58,5) ; box(0,9,58,11)
      box(0,15,58,17) ; box(0,21,58,23)
    layer(metal)
      box(4,30,54,34) ; box(54,0,58,34)
  endsymbol
  symbol("Stack cell con last")
    stackcellcon(0)
    layer(diffusion)
      box(0,3,7,5) ; box(0,9,20,11)
      box(0,15,34,17) ; box(0,21,47,23)
    layer(metal)
      box(4,30,54,34) ; box(54,0,58,34)
  endsymbol
gen:! all symbols defined
  stackcellpushy=25
  stackcellpopy=2
  stackcellxpitch=54
  stackcellaxpitch=48
  stackcellypitch=28
  stackcellgndypitch=8
  conypitch=26
  controlypitch=72
  symbol(name)
    curx=0
      %for i = 1,1,words %cycle
        positioncell("Stack cell","Stack cellvdd",stackcellypitch,
                     stackcellxpitch,stackcellgndypitch,curx,cury)
      %repeat
    %if words=1 %then %start
      draw("Stack cellvdd",curx,0)
      cury=stackcellgndypitch
      %for j=1,1,bits %cycle
        draw("Stack cellnull",curx,cury)
        cury=cury+stackcellypitch
      %repeat
      curx=curx+stackcellxpitch
      draw("Stack controlcon1",0,cury)
    %finish %else %c
    %if words=2 %then draw("Stack controlcon2",0,cury) %else %start
      draw("Stack controlconn",0,cury)
      curx=2*stackcellxpitch
      %for i=3,1,words-1 %cycle
          draw("Stack cellcon",curx,cury)
          curx=curx+stackcellxpitch
      %repeat
        draw("Stack cellconlast",curx,cury)
        curx=curx+stackcellxpitch
    %finish
    cury=cury+conypitch
    draw("Stack control",0,cury)
  endsymbol
  stackx=curx+4
  stacky=cury+controlypitch
  controlx=2*stackcellxpitch+4
  controly=controlypitch-8
  pushcony=stacky-7
  popcony=stacky-2
  phi1x=8
  phi2x=16
  phi3x=68
  phi4x=85
  cury=stackcellgndypitch
  %for i=1,1,bits %cycle
    pushy(i)=cury+stackcellpushy
    popy(i)=cury+stackcellpopy
    cury=cury+stackcellypitch
  %repeat
  %return
!-------------------------------------------------------------------------------
%routine stackcellcon(%integer offset)
  layer(metal)
    box(offset+7,0,offset+10,2) ; dm(offset+9,4)
    box(offset+21,0,offset+24,8) ; dm(offset+22,10)
    box(offset+34,0,offset+37,14) ; dm(offset+36,16)
    box(offset+48,0,offset+51,20) ; dm(offset+49,22)
%end
!-------------------------------------------------------------------------------
%routine controlcon
  layer(metal)
    box(0,0,4,30)
    box(27,0,31,28) ; box(54,0,58,30)
    box(81,0,85,28) ; box(108,0,112,30)
    dm(43,4) ; box(41,6,44,25); dm (42, 27)
    box(92,15,95,18) ; box(95,15,98,25); dm (96, 27)
  layer(diffusion)
    box(17,11,19,29) ; box(71,23,73,29)
%end
!-------------------------------------------------------------------------------
%routine positioncell(%string(13) cell,ground,
                      %integer cellypitch,cellxpitch,gndypitch,
                      %integer %name xcur,ycur)
%integer j
  draw(ground,xcur,0)
  ycur = gndypitch
  %for j = 1,1,bits %cycle
    draw(cell,xcur,ycur)
    ycur = ycur + cellypitch
  %repeat
  xcur = xcur + cellxpitch
%end
%end
%endoffile
