// Exercise M6, chip-level version: the chips and wires of schematic 2 and
// of the breadboard.  Same ports as mux_8_aoi.sv.
//
// Generated by tools/bb_lib.py from the checked breadboard wire list;
// change the layout in tools/bb_m5678.py, not this file.  Synthesizable.

module mux_8_aoi_chips
(
    input  logic [7:0] d,
    input  logic [2:0] sel,
    output logic       mux_out
);

    // Connections between the chips that are not ports

    wire q0;
    wire j1;
    wire q2;
    wire q3;
    wire q1;
    wire q4;
    wire q7;
    wire q5;
    wire q6;
    wire j2;

    // The power rails of the breadboard, for tied-off inputs

    wire gnd = 1'b0;
    wire vdd = 1'b1;

    // Outputs that go nowhere

    wire unused_u1_q9;
    wire unused_u1_q8;
    wire unused_u4_g;
    wire unused_u4_i;
    wire unused_u4_j;
    wire unused_u4_k;
    wire unused_u4_l;

    //------------------------------------------------------------------------

    // U2: CD4086 expandable 4-wide 2-input AND-OR-INVERT gate, pin 1 in column 7

    cd4086 i_u2
    (
        .a       ( q0    ),  // Pin 1 <- U1 pin 3 (Q0)
        .b       ( d [0] ),  // Pin 2 <- D0 wire, at +5V on the breadboard
        .j       ( j1    ),  // Pin 3 -> J1
        .e       ( q2    ),  // Pin 5 <- U1 pin 2 (Q2)
        .f       ( d [2] ),  // Pin 6 <- D2 wire, at +5V on the breadboard
        .g       ( q3    ),  // Pin 8 <- U1 pin 15 (Q3)
        .h       ( d [3] ),  // Pin 9 <- D3 wire, at +5V on the breadboard
        .inhibit ( gnd   ),  // Pin 10 <- GND
        .enable  ( vdd   ),  // Pin 11 <- +5V
        .c       ( q1    ),  // Pin 12 <- U1 pin 14 (Q1)
        .d       ( d [1] )   // Pin 13 <- D1 wire, at GND on the breadboard
    );

    //------------------------------------------------------------------------

    // U1: CD4028 BCD-to-decimal decoder, pin 1 in column 15

    cd4028 i_u1
    (
        .q4 ( q4           ),  // Pin 1 -> Q4
        .q2 ( q2           ),  // Pin 2 -> Q2
        .q0 ( q0           ),  // Pin 3 -> Q0
        .q7 ( q7           ),  // Pin 4 -> Q7
        .q9 ( unused_u1_q9 ),  // Pin 5, unused output
        .q5 ( q5           ),  // Pin 6 -> Q5
        .q6 ( q6           ),  // Pin 7 -> Q6
        .q8 ( unused_u1_q8 ),  // Pin 9, unused output
        .a  ( sel [0]      ),  // Pin 10 <- button A
        .d  ( gnd          ),  // Pin 11 <- GND
        .c  ( sel [2]      ),  // Pin 12 <- button C
        .b  ( sel [1]      ),  // Pin 13 <- button B
        .q1 ( q1           ),  // Pin 14 -> Q1
        .q3 ( q3           )   // Pin 15 -> Q3
    );

    //------------------------------------------------------------------------

    // U3: CD4086 expandable 4-wide 2-input AND-OR-INVERT gate, pin 1 in column 26

    cd4086 i_u3
    (
        .a       ( q4    ),  // Pin 1 <- U1 pin 1 (Q4)
        .b       ( d [4] ),  // Pin 2 <- D4 wire, at GND on the breadboard
        .j       ( j2    ),  // Pin 3 -> J2
        .e       ( q6    ),  // Pin 5 <- U1 pin 7 (Q6)
        .f       ( d [6] ),  // Pin 6 <- D6 wire, at +5V on the breadboard
        .g       ( q7    ),  // Pin 8 <- U1 pin 4 (Q7)
        .h       ( d [7] ),  // Pin 9 <- D7 wire, at GND on the breadboard
        .inhibit ( gnd   ),  // Pin 10 <- GND
        .enable  ( j1    ),  // Pin 11 <- U2 pin 3 (J)
        .c       ( q5    ),  // Pin 12 <- U1 pin 6 (Q5)
        .d       ( d [5] )   // Pin 13 <- D5 wire, at GND on the breadboard
    );

    //------------------------------------------------------------------------

    // U4: CD4069 hex inverter (six NOT gates), pin 1 in column 34

    cd4069 i_u4
    (
        .a ( gnd         ),  // Pin 1 <- GND, unused input
        .g ( unused_u4_g ),  // Pin 2, unused output
        .b ( j2          ),  // Pin 3 <- U3 pin 3 (J)
        .h ( mux_out     ),  // Pin 4 -> OUT
        .c ( gnd         ),  // Pin 5 <- GND, unused input
        .i ( unused_u4_i ),  // Pin 6, unused output
        .j ( unused_u4_j ),  // Pin 8, unused output
        .d ( vdd         ),  // Pin 9 <- +5V, unused input
        .k ( unused_u4_k ),  // Pin 10, unused output
        .e ( vdd         ),  // Pin 11 <- +5V, unused input
        .l ( unused_u4_l ),  // Pin 12, unused output
        .f ( vdd         )   // Pin 13 <- +5V, unused input
    );

endmodule
