/* ---------------------------------------------------------------
   This example shows you that you can define your component
   with a ***groups of signals***

   MyMux( sd,  control-signals,  input-signals,  output-signal)
   --------------------------------------------------------------- */

#include "Sim.h"


/* --------------------------------------------------------------------
   Mux macro with separate control and input signals as input
   -------------------------------------------------------------------- */
void MyMux ( const SD &sd, const Signal &c, const Signal &in, const Signal &out)
//                         ^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^
//                         Separate control and input signals
{
   Module( sd, (c, in), out);    // Start a new coordinate system.
//             ^^^^^^^^
//             Need to make 1 single input signal vector !!!

   Signal not_c0, not_c1, out_0, out_1, out_2, out_3;

   Not ( SD(sd,"ab"), c[0], not_c0 );
   Not ( SD(sd,"bb"), c[1], not_c1 );

   And ( SD(sd,"ac"), (in[0], not_c1, not_c0), out_0 );
   And ( SD(sd,"bc"), (in[1], not_c1, c[0]),   out_1 );
   And ( SD(sd,"cc"), (in[2], c[1],   not_c0), out_2 );
   And ( SD(sd,"dc"), (in[3], c[1],   c[0]),   out_3 );


   Or  ( SD(sd,"cd"), (out_0, out_1, out_2, out_3), out[0] );
}


/* -----
   Set up circuit that uses "MyMux"
   ----- */
void simnet()
{
   Signal in0, in1, in2, in3, co0, co1, out;

   /* The input bits to the mux */
   Switch ( "da", in0, '0', Zero );
   Switch ( "ca", in1, '1', Zero );
   Switch ( "ba", in2, '2', Zero );
   Switch ( "aa", in3, '3', Zero );
   
   /* The control bits of the mux */
   Switch ( "fa", co1, '4', Zero );
   Switch ( "ga", co0, '5', Zero );
   
   /* =======================================================
      You need to pass the control signals and input signals
      as different parameters
      ======================================================= */
   MyMux ( "ab-dd", (co1, co0), (in3, in2, in1, in0), out );
//                   ^^^^^^^^    ^^^^^^^^^^^^^^^^^^^
//                      Pass 2 GROUPS of signals
   
   Probe ( "ce", out );
}



