/* ---------------------------------------------------------------
   This example shows you that you can define your component
   with "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,"1b"), c[0], not_c0 );
   Not ( SD(sd,"2b"), c[1], not_c1 );

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


   Or  ( SD(sd,"3d"), (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 ( "4a", in0, '0', Zero );
   Switch ( "3a", in1, '1', Zero );
   Switch ( "2a", in2, '2', Zero );
   Switch ( "1a", in3, '3', Zero );
   
   /* The control bits of the mux */
   Switch ( "6a", co1, '4', Zero );
   Switch ( "7a", co0, '5', Zero );
   
   /* =======================================================
      You need to pass the control signals and input signals
      as different parameters
      ======================================================= */
   MyMux ( "1b-4d", (co1, co0), (in3, in2, in1, in0), out );
//                   ^^^         ^^^
//                   Pass in the control and input signals separately
   
   Probe ( "3e", out );
}



