// Exercise B9, chip-level version: the chips and wires of schematic 2 and
// of the breadboards.  Same ports as adder_display.sv.  The displays and
// their resistors are not in the design: its outputs are the outputs of
// the 4511s and of the 4008.
//
// Generated by tools/bb_lib.py from the checked breadboard wire list;
// change the layout in tools/bb_b9.py, not this file.  Synthesizable.

module adder_display_chips
(
    input  logic [3:0] a,
    input  logic [3:0] b,
    output logic [3:0] sum,
    output logic       carry,
    output logic [6:0] abcdefg_a,
    output logic [6:0] abcdefg_b,
    output logic [6:0] abcdefg_sum
);

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

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

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

    // UA: CD4511 BCD-to-7-segment latch, decoder and driver, pin 1 in column 18 of board 1

    cd4511 i_ua
    (
        .bcd_b        ( a [1]         ),  // Pin 1 <- button A2
        .bcd_c        ( a [2]         ),  // Pin 2 <- button A3
        .lamp_test_n  ( vdd           ),  // Pin 3 <- +5V
        .blank_n      ( vdd           ),  // Pin 4 <- +5V
        .latch_enable ( gnd           ),  // Pin 5 <- GND
        .bcd_d        ( a [3]         ),  // Pin 6 <- button A4
        .bcd_a        ( a [0]         ),  // Pin 7 <- button A1
        .seg_e        ( abcdefg_a [2] ),  // Pin 9 -> A.e
        .seg_d        ( abcdefg_a [3] ),  // Pin 10 -> A.d
        .seg_c        ( abcdefg_a [4] ),  // Pin 11 -> A.c
        .seg_b        ( abcdefg_a [5] ),  // Pin 12 -> A.b
        .seg_a        ( abcdefg_a [6] ),  // Pin 13 -> A.a
        .seg_g        ( abcdefg_a [0] ),  // Pin 14 -> A.g
        .seg_f        ( abcdefg_a [1] )   // Pin 15 -> A.f
    );

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

    // U4008: CD4008 4-bit full adder, pin 1 in column 28 of board 1

    cd4008 i_u4008
    (
        .a4        ( a [3]   ),  // Pin 1 <- button A4
        .b3        ( b [2]   ),  // Pin 2 <- button B3
        .a3        ( a [2]   ),  // Pin 3 <- button A3
        .b2        ( b [1]   ),  // Pin 4 <- button B2
        .a2        ( a [1]   ),  // Pin 5 <- button A2
        .b1        ( b [0]   ),  // Pin 6 <- button B1
        .a1        ( a [0]   ),  // Pin 7 <- button A1
        .carry_in  ( gnd     ),  // Pin 9 <- GND
        .s1        ( sum [0] ),  // Pin 10 -> S1
        .s2        ( sum [1] ),  // Pin 11 -> S2
        .s3        ( sum [2] ),  // Pin 12 -> S3
        .s4        ( sum [3] ),  // Pin 13 -> S4
        .carry_out ( carry   ),  // Pin 14 -> CO
        .b4        ( b [3]   )   // Pin 15 <- button B4
    );

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

    // UB: CD4511 BCD-to-7-segment latch, decoder and driver, pin 1 in column 38 of board 1

    cd4511 i_ub
    (
        .bcd_b        ( b [1]         ),  // Pin 1 <- button B2
        .bcd_c        ( b [2]         ),  // Pin 2 <- button B3
        .lamp_test_n  ( vdd           ),  // Pin 3 <- +5V
        .blank_n      ( vdd           ),  // Pin 4 <- +5V
        .latch_enable ( gnd           ),  // Pin 5 <- GND
        .bcd_d        ( b [3]         ),  // Pin 6 <- button B4
        .bcd_a        ( b [0]         ),  // Pin 7 <- button B1
        .seg_e        ( abcdefg_b [2] ),  // Pin 9 -> B.e
        .seg_d        ( abcdefg_b [3] ),  // Pin 10 -> B.d
        .seg_c        ( abcdefg_b [4] ),  // Pin 11 -> B.c
        .seg_b        ( abcdefg_b [5] ),  // Pin 12 -> B.b
        .seg_a        ( abcdefg_b [6] ),  // Pin 13 -> B.a
        .seg_g        ( abcdefg_b [0] ),  // Pin 14 -> B.g
        .seg_f        ( abcdefg_b [1] )   // Pin 15 -> B.f
    );

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

    // US: CD4511 BCD-to-7-segment latch, decoder and driver, pin 1 in column 28 of board 2

    cd4511 i_us
    (
        .bcd_b        ( sum [1]         ),  // Pin 1 <- U4008 pin 11 (S2)
        .bcd_c        ( sum [2]         ),  // Pin 2 <- U4008 pin 12 (S3)
        .lamp_test_n  ( vdd             ),  // Pin 3 <- +5V
        .blank_n      ( vdd             ),  // Pin 4 <- +5V
        .latch_enable ( gnd             ),  // Pin 5 <- GND
        .bcd_d        ( sum [3]         ),  // Pin 6 <- U4008 pin 13 (S4)
        .bcd_a        ( sum [0]         ),  // Pin 7 <- U4008 pin 10 (S1)
        .seg_e        ( abcdefg_sum [2] ),  // Pin 9 -> S.e
        .seg_d        ( abcdefg_sum [3] ),  // Pin 10 -> S.d
        .seg_c        ( abcdefg_sum [4] ),  // Pin 11 -> S.c
        .seg_b        ( abcdefg_sum [5] ),  // Pin 12 -> S.b
        .seg_a        ( abcdefg_sum [6] ),  // Pin 13 -> S.a
        .seg_g        ( abcdefg_sum [0] ),  // Pin 14 -> S.g
        .seg_f        ( abcdefg_sum [1] )   // Pin 15 -> S.f
    );

endmodule
