// Exercise B3d on an FPGA board with the Basics-Graphics-Music (BGM) labs:
// https://github.com/yuri-panchul/basics-graphics-music
//
// Copy labs/1_basics/1_01_and_or_not_xor_de_morgan to a new directory,
// replace its lab_top.sv with this file and add gates_8_input.sv. For the
// chip-level design add gates_8_input_chips.sv and cd4068.sv, cd4078.sv
// instead, and change the module name below.
//
// Keys: key [0] a, key [1] b, key [2] c, key [3] d. The LEDs: led [0] y_and,
// led [1] y_nand, led [2] y_or, led [3] y_nor. A board with fewer LEDs shows
// the first ones.
//
// Inputs E-H of each chip are fixed as on the breadboard: 1 for the 4068, 0
// for the 4078.

`include "config.svh"

module lab_top
# (
    parameter  clk_mhz       = 50,
               w_key         = 4,
               w_sw          = 8,
               w_led         = 8,
               w_digit       = 8,
               w_gpio        = 100,

               screen_width  = 640,
               screen_height = 480,

               w_red         = 4,
               w_green       = 4,
               w_blue        = 4,

               w_x           = $clog2 ( screen_width  ),
               w_y           = $clog2 ( screen_height )
)
(
    input                        clk,
    input                        slow_clk,
    input                        rst,

    // Keys, switches, LEDs

    input        [w_key   - 1:0] key,
    input        [w_sw    - 1:0] sw,
    output logic [w_led   - 1:0] led,

    // A dynamic seven-segment display

    output logic [          7:0] abcdefgh,
    output logic [w_digit - 1:0] digit,

    // Graphics

    input        [w_x     - 1:0] x,
    input        [w_y     - 1:0] y,

    output logic [w_red   - 1:0] red,
    output logic [w_green - 1:0] green,
    output logic [w_blue  - 1:0] blue,

    // Microphone, sound output and UART

    input        [         23:0] mic,
    output       [         15:0] sound,

    input                        uart_rx,
    output                       uart_tx,

    // General-purpose Input/Output

    inout        [w_gpio  - 1:0] gpio
);

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

       assign abcdefgh   = '0;
       assign digit      = '0;
       assign red        = '0;
       assign green      = '0;
       assign blue       = '0;
       assign sound      = '0;
       assign uart_tx    = '1;

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

    logic y_and;
    logic y_nand;
    logic y_or;
    logic y_nor;

    gates_8_input i_gates_8_input
    (
        .a        ( key [0] ),
        .b        ( key [1] ),
        .c        ( key [2] ),
        .d        ( key [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   )
    );

    assign led = w_led' ({ y_nor, y_or, y_nand, y_and });

endmodule
