// Exercise B7: a BCD-to-7-segment decoder for a common-cathode display.
//
// Generic version that matches schematic 1: a decoder written as a table,
// not tied to any chip.  It draws the digits like the 4511: 6 without the
// top segment, 9 without the bottom one, and codes 10-15 blank the display.
// Synthesizable.

module seven_segment
(
    input  logic [3:0] bcd,      // The code: bcd [3] is D (weight 8), bcd [0] is A (weight 1)
    output logic [6:0] abcdefg   // 1 = segment lit: abcdefg [6] is a, abcdefg [0] is g
);

    //   --a--
    //  |     |
    //  f     b
    //  |     |
    //   --g--
    //  |     |
    //  e     c
    //  |     |
    //   --d--

    always_comb
        case (bcd)
        4'd0:    abcdefg = 7'b111_1110;
        4'd1:    abcdefg = 7'b011_0000;
        4'd2:    abcdefg = 7'b110_1101;
        4'd3:    abcdefg = 7'b111_1001;
        4'd4:    abcdefg = 7'b011_0011;
        4'd5:    abcdefg = 7'b101_1011;
        4'd6:    abcdefg = 7'b001_1111;
        4'd7:    abcdefg = 7'b111_0000;
        4'd8:    abcdefg = 7'b111_1111;
        4'd9:    abcdefg = 7'b111_0011;
        default: abcdefg = 7'b000_0000;
        endcase

endmodule
