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

module two_bit_adder_chips
(
    input  logic       a1,
    input  logic       a0,
    input  logic       b1,
    input  logic       b0,
    output logic       s2,
    output logic       s1,
    output logic       s0
);

    // Connections between the chips that are not ports

    wire g1;
    wire t1;
    wire c0;
    wire p1;

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

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

    // Outputs that go nowhere

    wire unused_u3_k;
    wire unused_u3_l;
    wire unused_u3_m;
    wire unused_u2_m;
    wire unused_u1_k;

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

    // U3: CD4071 quad 2-input OR, pin 1 in column 9

    cd4071 i_u3
    (
        .a ( g1          ),  // Pin 1 <- U2 pin 4 (K)
        .b ( t1          ),  // Pin 2 <- U2 pin 10 (L)
        .j ( s2          ),  // Pin 3 -> S2
        .k ( unused_u3_k ),  // Pin 4, unused output
        .c ( vdd         ),  // Pin 5 <- +5V, unused input
        .d ( vdd         ),  // Pin 6 <- +5V, unused input
        .e ( gnd         ),  // Pin 8 <- GND, unused input
        .f ( gnd         ),  // Pin 9 <- GND, unused input
        .l ( unused_u3_l ),  // Pin 10, unused output
        .m ( unused_u3_m ),  // Pin 11, unused output
        .g ( gnd         ),  // Pin 12 <- GND, unused input
        .h ( gnd         )   // Pin 13 <- GND, unused input
    );

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

    // U2: CD4081 quad 2-input AND, pin 1 in column 19

    cd4081 i_u2
    (
        .a ( a0          ),  // Pin 1 <- button A0
        .b ( b0          ),  // Pin 2 <- button B0
        .j ( c0          ),  // Pin 3 -> C0
        .k ( g1          ),  // Pin 4 -> A1&B1
        .c ( a1          ),  // Pin 5 <- button A1
        .d ( b1          ),  // Pin 6 <- button B1
        .e ( c0          ),  // Pin 8 <- U2 pin 3 (J)
        .f ( p1          ),  // Pin 9 <- U1 pin 10 (L)
        .l ( t1          ),  // Pin 10 -> C0&(A1^B1)
        .m ( unused_u2_m ),  // Pin 11, unused output
        .g ( vdd         ),  // Pin 12 <- +5V, unused input
        .h ( vdd         )   // Pin 13 <- +5V, unused input
    );

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

    // U1: CD4070 quad 2-input XOR, pin 1 in column 28

    cd4070 i_u1
    (
        .a ( a0          ),  // Pin 1 <- button A0
        .b ( b0          ),  // Pin 2 <- button B0
        .j ( s0          ),  // Pin 3 -> S0
        .k ( unused_u1_k ),  // Pin 4, unused output
        .c ( gnd         ),  // Pin 5 <- GND, unused input
        .d ( gnd         ),  // Pin 6 <- GND, unused input
        .e ( a1          ),  // Pin 8 <- button A1
        .f ( b1          ),  // Pin 9 <- button B1
        .l ( p1          ),  // Pin 10 -> A1^B1
        .m ( s1          ),  // Pin 11 -> S1
        .g ( p1          ),  // Pin 12 <- U1 pin 10 (L)
        .h ( c0          )   // Pin 13 <- U2 pin 3 (J)
    );

endmodule
