! ILAP counter 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.               #}
{#                                                                       #}
{#########################################################################}

%external %routine COUNTER %alias "ILAP_COUNTER" (%string(31) name,
   %integer size, %integer %name suby, loady, vddy, phi2y, phi1y, gndy,
   %integer %array %name ins,
   %integer %array %name outs,
   %integer %array %name outsb)

   %integer i, j, COSX, CESX   { Size of Counter, and size of cells }
   %integer offset

   %if SYMBOL EXISTS("Counter ncell")#TRUE %start
       %include "countc.ted"  { ted cell }
       %include "count.ted"

       SYMBOL ("Counter ncell")   {no refresh of T}
          layer (blue)
          width (4)
          wirex (24,53,6)
       END SYMBOL  {counter}
       
       SYMBOL ("Counter refcell")   { refresh of T}
         layer (blue)
         width (4)
         wirey (30,32,21)
       END SYMBOL  {counter}
       
       SYMBOL ("Counter pair")      { Pair of cells with refresh & no-refresh }
          draw ("Counter cell", 0, 0)
          draw ("Counter ncell", 0, 0)
          draw ("Counter cell", SX("Counter cell"), 0)
          draw ("Counter refcell", SX("Counter cell"), 0)
       END SYMBOL
   %finish
   
   SYMBOL (name)
      cesx = SX ("Counter Pair")
      draw ("Counter control", 0, 0)
      offset = SX ("Counter control")
      cosx = offset
      %for i = 1,1,size//2 %cycle
          draw ("Counter pair", cosx, 0)
          cosx = cosx + cesx
      %repeat
      %if rem (size,2) = 1 %start
          draw ("Counter cell", cosx, 0)
          draw ("Counter ncell", cosx, 0)
      %finish

      ! Dimensions
      vddy=33
      suby=20
      loady=27
      gndy=64
      phi2y=72
      phi1y=85

      cosx = SX("Counter cell")

      %for i=1,1,size %cycle
        j=i-1
        ins(i)=j*cosx+offset+5
        outs(i)=j*cosx+offset+34
        outsb(i)=j*cosx+offset+53
      %repeat

   END SYMBOL
%end

%end %of %file
