\newcommand{\AND}{\lstinline{And}}
\newcommand{\OR}{\lstinline{Or}}
\newcommand{\NOT}{\lstinline{Not}}

\newlength{\StrikeThruDistance}
\setlength{\StrikeThruDistance}{0.15cm}%

\tikzset{Busmark/.style={
    decoration={markings, mark=at position 0.5 with {
        \draw [thick,-]
            ++ (-\StrikeThruDistance,-\StrikeThruDistance)
            -- ( \StrikeThruDistance, \StrikeThruDistance)
            (-0.65\StrikeThruDistance, \StrikeThruDistance) node {\tiny{#1}};},
    },
    postaction={decorate},
}}

\tikzset{
  rf/.style={
    rectangle, draw,
    inner ysep=0pt, outer sep=1pt, inner xsep=1pt,
    node distance=2cm,
  }
}

\tikzset{
  registerfilecore/.pic={
    code={
      \begin{scope}[y=-1.0cm,shorten >=1pt,node distance=1cm,on grid,auto]
        \node [rf,minimum width=1.5cm,minimum height=3cm] (body) {};
        \draw (body.south west) coordinate (w)
          (body.north west) coordinate (x)
          (body.north east) coordinate(y)
          (body.south east) coordinate (z);
        \draw (body.north) coordinate (-we)
          (body.south) coordinate (-clk);
        \foreach \offset/\name in {0.2/D, 0.4/AD, 0.6/AQ0, 0.8/AQ1} {
          \draw ($(w) ! \offset ! (x)$) coordinate (-\name);
        }
        \foreach \offset/\name in {0.4/Q0, 0.6/Q1} {
          \draw ($(z) ! \offset ! (y)$) coordinate (-\name);
        };
      \end{scope}
    }
  }
}

\tikzset{
  registerfile/.pic={
    code={
      \begin{scope}[y=-1.0cm,shorten >=1pt,node distance=1cm,on grid,auto]
    \draw pic (rf) {registerfilecore};
    \draw[->, Busmark={32}] (rf-Q0) -- ++(0.0:0.5cm) node [right] {\texttt{$Q_0$}};
    \draw[<-, Busmark={2}] (rf-AQ0) -- ++(180.0:0.5cm) node [left] {\texttt{$A_{Q_0}$}};
    \draw[->, Busmark={32}] (rf-Q1) -- ++(0.0:0.5cm) node [right] {\texttt{$Q_1$}};
    \draw[<-, Busmark={2}] (rf-AQ1) -- ++(180.0:0.5cm) node [left] {\texttt{$A_{Q_1}$}};
    \draw[<-, Busmark={32}] (rf-D) -- ++(180.0:0.5cm) node [left] {\texttt{$D$}};
    \draw[<-, Busmark={2}] (rf-AD) -- ++(180.0:0.5cm) node [left] {\texttt{$A_D$}};
    \draw[<-] (rf-clk) -- ++(270.0:0.5cm) node [below] {\texttt{clk}};
    \draw[<-] (rf-we) -- ++(90.0:0.5cm) node [above] {\texttt{we}};
      \end{scope}
    }
  }
}

\tikzset{
  ramcore/.pic={
    code={
      \begin{scope}[y=-1.0cm,shorten >=1pt,node distance=1cm,on grid,auto]
        \node [rf,minimum width=1.5cm,minimum height=3cm] (body) {};
        \draw (body.south west) coordinate (w)
          (body.north west) coordinate (x)
          (body.north east) coordinate(y)
          (body.south east) coordinate (z);
        \draw (body.north) coordinate (-we)
          (body.south) coordinate (-clk);
        \foreach \offset/\name in {0.66/D, 0.33/A} {
          \draw ($(w) ! \offset ! (x)$) coordinate (-\name);
        }
        \foreach \offset/\name in {0.66/Q} {
          \draw ($(z) ! \offset ! (y)$) coordinate (-\name);
        };
      \end{scope}
    }
  }
}

\tikzset{
  ram8/.pic={
    code={
      \begin{scope}[y=-1.0cm,shorten >=1pt,node distance=1cm,on grid,auto]
    \draw pic (rcore) {ramcore};
    \draw[->, Busmark={8}] (rcore-Q) -- ++(0.0:0.5cm) node [right] {\texttt{Q}};
    \draw[<-, Busmark={?}] (rcore-A) -- ++(180.0:0.5cm) node [left] {\texttt{A}};
    \draw[<-, Busmark={8}] (rcore-D) -- ++(180.0:0.5cm) node [left] {\texttt{D}};
    \draw[<-] (rcore-clk) -- ++(270.0:0.5cm) node [below] {\texttt{clk}};
    \draw[<-] (rcore-we) -- ++(90.0:0.5cm) node [above] {\texttt{en}};
    \draw  node [rotate=90] {\texttt{RAM8}};
      \end{scope}
    }
  }
}

\tikzset{
  ram64/.pic={
    code={
      \begin{scope}[y=-1.0cm,shorten >=1pt,node distance=1cm,on grid,auto]
    \draw pic (rcore) {ramcore};
    \draw[->, Busmark={8}] (rcore-Q) -- ++(0.0:0.5cm) node [right] {\texttt{Q}};
    \draw[<-, Busmark={?}] (rcore-A) -- ++(180.0:0.5cm) node [left] {\texttt{A}};
    \draw[<-, Busmark={8}] (rcore-D) -- ++(180.0:0.5cm) node [left] {\texttt{D}};
    \draw[<-] (rcore-clk) -- ++(270.0:0.5cm) node [below] {\texttt{clk}};
    \draw[<-] (rcore-we) -- ++(90.0:0.5cm) node [above] {\texttt{en}};
    \draw  node [rotate=90] {\texttt{RAM64}};
      \end{scope}
    }
  }
}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "ram"
%%% End:
