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

module register_file_chips
(
    input  logic       clk,
    input  logic       we,
    input  logic [1:0] waddr,
    input  logic [3:0] wdata,
    input  logic [1:0] raddr_a,
    input  logic [1:0] raddr_b,
    output logic [3:0] rdata_a,
    output logic [3:0] rdata_b
);

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

    wire vdd = 1'b1;

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

    // U1: CD40108 4 × 4 multiport register: four 4-bit words, one write port, two read ports, pin 1 in column 15

    cd40108 i_u1
    (
        .q3b          ( rdata_b [3] ),  // Pin 1 -> Q3B
        .q2b          ( rdata_b [2] ),  // Pin 2 -> Q2B
        .enable_a     ( vdd         ),  // Pin 3 <- +5V
        .q0a          ( rdata_a [0] ),  // Pin 4 -> Q0A
        .q1a          ( rdata_a [1] ),  // Pin 5 -> Q1A
        .q2a          ( rdata_a [2] ),  // Pin 6 -> Q2A
        .q3a          ( rdata_a [3] ),  // Pin 7 -> Q3A
        .write0       ( waddr [0]   ),  // Pin 8 <- button W0
        .write1       ( waddr [1]   ),  // Pin 9 <- button W1
        .read1b       ( raddr_b [1] ),  // Pin 10 <- R1B wire, at GND on the breadboard
        .read0b       ( raddr_b [0] ),  // Pin 11 <- R0B wire, at +5V on the breadboard
        .read0a       ( raddr_a [0] ),  // Pin 13 <- R0A wire, at GND on the breadboard
        .read1a       ( raddr_a [1] ),  // Pin 14 <- R1A wire, at GND on the breadboard
        .write_enable ( we          ),  // Pin 15 <- button WRITE
        .clock        ( clk         ),  // Pin 16 <- 555 clock module
        .d3           ( wdata [3]   ),  // Pin 17 <- button D3
        .d2           ( wdata [2]   ),  // Pin 18 <- button D2
        .d1           ( wdata [1]   ),  // Pin 19 <- button D1
        .d0           ( wdata [0]   ),  // Pin 20 <- button D0
        .enable_b     ( vdd         ),  // Pin 21 <- +5V
        .q0b          ( rdata_b [0] ),  // Pin 22 -> Q0B
        .q1b          ( rdata_b [1] )   // Pin 23 -> Q1B
    );

endmodule
