\sectionright{\sffamily Combinatorial Logic}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{\sffamily Multiplexers and Demultiplexers}

    \subsubsection{\sffamily Description}
        Multiplexers and Demultiplexers are the primary steering elements for data paths. In \texttt{register-transfer-level}, these are not simple nodes but are generated via the \texttt{\textbackslash createMux} and \texttt{\textbackslash createDemux} commands. 
        
        These commands automatically calculate the vertical distribution of ports based on the number of labels provided. Multiplexers (yellow-tinted trapezoids) converge multiple inputs into one output, while Demultiplexers diverge a single input into multiple outputs. Both elements feature a dedicated selection (\texttt{sel}) anchor at the bottom.

    \subsubsection{\sffamily Attributes}
        The dimensions of the trapezoids can be adjusted using specific MUX/DEMUX sizing keys:

    \begin{center}
        \begin{tabular}{lp{8cm}}
        \toprule
            \textbf{Argument} & \textbf{Effect} \\
            \midrule
            \texttt{[\#1]} & Optional TikZ draw options for the projection lines (e.g., color, dash pattern). \\
            \texttt{\{\#2\}} & Name of the MUX/DEMUX. \\
            \texttt{\{\#3\}} & Optional Coordinates. \\
            \texttt{\{\#4\}} & List of input/output labels. \\
            \texttt{rtl\_mux\_width} & Sets the length of the input/output side (vertical span). \\
            \texttt{rtl\_mux\_height} & Sets the thickness of the component (horizontal span). \\
            \bottomrule
        \end{tabular}
    \end{center}

    \subsubsection{\sffamily Anchors}
        \begin{itemize}
            \item \textbf{MUX Inputs}: \texttt{\{name\}-in-1} to \texttt{\{name\}-in-n}.
            \item \textbf{DEMUX Outputs}: \texttt{\{name\}-out-1} to \texttt{\{name\}-out-n}.
            \item \textbf{Common}: \texttt{\{name\}-sel} (bottom), \texttt{\{name\}-out} (MUX) or \texttt{\{name\}-in} (DEMUX).
        \end{itemize}
        
    \subsubsection{\sffamily Listing}
        \begin{RTLexample}[4-to-1 Multiplexer]
            \begin{tikzpicture}[>=Stealth, thick, scale=0.8]

                \createMux[rtl_mux_width=3cm]{M1}(0,0){00, 01, 10, 11}
    
                \draw[<-, rtl_bus={}] (M1-sel) -- ++(0,-1.2) node[below] {sel};
                \draw[->] (M1-out) -- ++(0.8,0) node[right] {Y};
    
                \foreach \i/\lbl in {1/in\_1, 2/in\_2, 3/in\_3, 4/in\_4} {
                    \draw[<-] (M1-in-\i) -- ++(-0.8,0) node[left] {\lbl};
                }
            \end{tikzpicture}
        \end{RTLexample}

        \begin{RTLexample}[1-to-2 Demultiplexer]
            \begin{tikzpicture}[>=Stealth, thick, scale=0.8]

                \createDemux[rtl_mux_width=2cm]{D1}(0,0){A, B}
    
                \draw[<-] (D1-in) -- ++(-0.8,0) node[left] {X};
                \draw[<-, rtl_bus={}] (D1-sel) -- ++(0,-1.2) node[below] {sel};
    
                \foreach \i/\lbl in {1/out\_1, 2/out\_2} {
                    \draw[->] (D1-out-\i) -- ++(0.8,0) node[right] {\lbl};
                }
            \end{tikzpicture}
        \end{RTLexample}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{\sffamily Tri-State Buffer}

    \subsubsection{\sffamily Description}
        The \texttt{rtl\_tristate} element represents a controlled buffer used for bus arbitration. It features a triangular shape with an integrated \texttt{EN} (Enable) label at the top. This element is essential for modeling high-impedance states in shared signal lines.

    \subsubsection{\sffamily Anchors}
        \begin{itemize}
            \item \textbf{Specific Anchors}: Inherits \texttt{regular polygon} anchors. The \texttt{north} anchor is pre-configured for the Enable signal.
        \end{itemize}

    \subsubsection{\sffamily Listing}
\begin{RTLexample}[Tri-State Buffer]
\begin{tikzpicture}[>=Stealth, thick, scale=0.8]
    \node[rtl_tristate, rtl_size=2cm] (TS) at (0,0) {};
    
    \draw[<-] (TS.west) -- ++(-0.8,0) node[left] {In};
    \draw[->] (TS.east) -- ++(0.8,0) node[right] {Out};
    \draw[<-] (TS.north) -- ++(0,0.6) node[above] {EN};
\end{tikzpicture}
\end{RTLexample}
