include "7seg_driver";

subdesign LED_7seg_driver (
    D[0..7][0..3], clk : input;
    dig[0..7], seg[6..0] : output;
)

variable
    in_buf[7..0][3..0] : DFF;
    decoder_out[7..0][7..0] : NODE;
	 switcher[3..0] : DFF;

begin

DEFAULTS
	switcher[].d = 0;
END DEFAULTS;

	in_buf[][].clk = clk;
   in_buf[7..0][3..0].d = D[7..0][3..0];
	
	switcher[].clk = clk;
	if switcher[].q == 7 
	THEN
		switcher[].d = 0;
	ELSE
		switcher[].d = switcher[].q + 1;
	END IF;
	 
	CASE  switcher[].q IS
	WHEN 0 => dig[] = 0; seg[] = 7seg_driver(in_buf[0][].q);
	WHEN 1 => dig[] = 1; seg[] = 7seg_driver(in_buf[1][].q);
	WHEN 2 => dig[] = 2; seg[] = 7seg_driver(in_buf[2][].q);
	WHEN 3 => dig[] = 3; seg[] = 7seg_driver(in_buf[3][].q);
	WHEN 4 => dig[] = 4; seg[] = 7seg_driver(in_buf[4][].q);
	WHEN 5 => dig[] = 5; seg[] = 7seg_driver(in_buf[5][].q);
	WHEN 6 => dig[] = 6; seg[] = 7seg_driver(in_buf[6][].q);
	WHEN 7 => dig[] = 7; seg[] = 7seg_driver(in_buf[7][].q);
   END CASE;
end;