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

module de_morgan_chips
(
    input  logic       a,
    input  logic       b,
    output logic       not_a_and_b,
    output logic       not_a_or_not_b,
    output logic       not_a_or_b,
    output logic       not_a_and_not_b
);

    // Connections between the chips that are not ports

    wire nb;
    wire na;
    wire a_or_b;
    wire a_and_b;

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

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

    // Outputs that go nowhere

    wire unused_u2_j;
    wire unused_u2_m;
    wire unused_u3_k;
    wire unused_u3_l;
    wire unused_u1_l;
    wire unused_u1_m;

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

    // U2: CD4071 quad 2-input OR, pin 1 in column 10

    cd4071 i_u2
    (
        .a ( gnd            ),  // Pin 1 <- GND, unused input
        .b ( gnd            ),  // Pin 2 <- GND, unused input
        .j ( unused_u2_j    ),  // Pin 3, unused output
        .k ( not_a_or_not_b ),  // Pin 4 -> ~A|~B
        .c ( nb             ),  // Pin 5 <- U3 pin 4 (H)
        .d ( na             ),  // Pin 6 <- U3 pin 2 (G)
        .e ( a              ),  // Pin 8 <- button A
        .f ( b              ),  // Pin 9 <- button B
        .l ( a_or_b         ),  // Pin 10 -> A|B
        .m ( unused_u2_m    ),  // Pin 11, unused output
        .g ( vdd            ),  // Pin 12 <- +5V, unused input
        .h ( vdd            )   // Pin 13 <- +5V, unused input
    );

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

    // U3: CD4069 hex inverter (six NOT gates), pin 1 in column 19

    cd4069 i_u3
    (
        .a ( a           ),  // Pin 1 <- button A
        .g ( na          ),  // Pin 2 -> ~A
        .b ( b           ),  // Pin 3 <- button B
        .h ( nb          ),  // Pin 4 -> ~B
        .c ( a_and_b     ),  // Pin 5 <- U1 pin 3 (J)
        .i ( not_a_and_b ),  // Pin 6 -> ~(A&B)
        .j ( not_a_or_b  ),  // Pin 8 -> ~(A|B)
        .d ( a_or_b      ),  // Pin 9 <- U2 pin 10 (L)
        .k ( unused_u3_k ),  // Pin 10, unused output
        .e ( vdd         ),  // Pin 11 <- +5V, unused input
        .l ( unused_u3_l ),  // Pin 12, unused output
        .f ( vdd         )   // Pin 13 <- +5V, unused input
    );

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

    // U1: CD4081 quad 2-input AND, pin 1 in column 27

    cd4081 i_u1
    (
        .a ( a               ),  // Pin 1 <- button A
        .b ( b               ),  // Pin 2 <- button B
        .j ( a_and_b         ),  // Pin 3 -> A&B
        .k ( not_a_and_not_b ),  // Pin 4 -> ~A&~B
        .c ( na              ),  // Pin 5 <- U3 pin 2 (G)
        .d ( nb              ),  // Pin 6 <- U3 pin 4 (H)
        .e ( vdd             ),  // Pin 8 <- +5V, unused input
        .f ( vdd             ),  // Pin 9 <- +5V, unused input
        .l ( unused_u1_l     ),  // Pin 10, unused output
        .m ( unused_u1_m     ),  // Pin 11, unused output
        .g ( vdd             ),  // Pin 12 <- +5V, unused input
        .h ( vdd             )   // Pin 13 <- +5V, unused input
    );

endmodule
