/* -------------------------------------------------
   Mux:

     input:    n controls   (c1, c0)
               2^n data:    (d3, d2, d1, d0)

     output:   Z
   ------------------------------------------------- */

#include "Sim.h"

void simnet()
{
   Sig(i0, 1);
   Sig(i1, 1);
   Sig(i2, 1);
   Sig(i3, 1);

   Sig(c0, 1);
   Sig(c1, 1);

   Sig(out, 1);   

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

   Switch ( "aa", i3, '3', Zero );  // Data
   Switch ( "ba", i2, '2', Zero );  // 
   Switch ( "ca", i1, '1', Zero );  // 
   Switch ( "da", i0, '0', Zero );  // 

   Switch ( "ga", c1, '7', Zero );  // 
   Switch ( "ha", c0, '8', Zero );  // Controls

   Not ( "db",   c0, not_c0 );
   Not ( "db",   c1, not_c1 );

   And ( "ac", (i0, not_c1, not_c0), out_0 );
   And ( "ac", (i1, not_c1,     c0), out_1 );
   And ( "bc", (i2,     c1, not_c0), out_2 );
   And ( "bc", (i3,     c1,     c0), out_3 );

   Or  ( "ad", (out_0, out_1, out_2, out_3), out );

   Probe( "af", out );        // Probe out
}



