/*
 * Exercise B3d on Tiny Tapeout: the 8-input gates, with the DIP switches as
 * inputs and the 7-segment display of the demo board as lamps.
 *
 * Add gates_8_input.sv to source_files in info.yaml next to project.v.
 * Rename the module to tt_um_<your GitHub name>_<project name> and use the
 * same name as top_module in info.yaml.
 */

`default_nettype none

module tt_um_example (
    input  wire [7:0] ui_in,    // DIP switches, INPUT Pmod, RP2350 GPIO17-24
    output wire [7:0] uo_out,   // 7-segment display, OUTPUT Pmod, RP2350 GPIO33-40
    input  wire [7:0] uio_in,   // BIDIR Pmod, RP2350 GPIO25-32
    output wire [7:0] uio_out,  //   (same pins)
    output wire [7:0] uio_oe,   //   1 = your design drives the pin
    input  wire       ena,      // set by the on-chip project mux, not a board pin
    input  wire       clk,      // RP2350 GPIO16
    input  wire       rst_n     // RP2350 GPIO14
);

    // Switch 0 is a, switch 1 is b, switch 2 is c, switch 3 is d
    // Inputs E-H of each chip are fixed as on the breadboard: 1 for the 4068,
    // 0 for the 4078.

    wire y_and;
    wire y_nand;
    wire y_or;
    wire y_nor;

    gates_8_input i_gates_8_input (
        .a        ( ui_in [0] ),
        .b        ( ui_in [1] ),
        .c        ( ui_in [2] ),
        .d        ( ui_in [3] ),
        .rest_and ( 4'b1111   ),
        .rest_or  ( 4'b0000   ),
        .y_and    ( y_and     ),
        .y_nand   ( y_nand    ),
        .y_or     ( y_or      ),
        .y_nor    ( y_nor     )
    );

    // 7-segment display: uo_out [0] is segment a, ..., uo_out [6] is g,
    // uo_out [7] is the dot.  Each output lights one segment:
    // a (top) y_and, b (top right) y_nand, c (bottom right) y_or, d (bottom)
    // y_nor.

    assign uo_out  = { 4'b0, y_nor, y_or, y_nand, y_and };

    assign uio_out = 8'b0;
    assign uio_oe  = 8'b0;

    // The circuit needs no clock or reset.
    // List all unused inputs to prevent warnings

    wire _unused = & { ena, clk, rst_n, ui_in [7:4], uio_in, 1'b0 };

endmodule
