Skip to content

Commit

Permalink
Code cleanup and attempt at optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarDevAchar authored Aug 27, 2024
1 parent 6af2fa5 commit 9270b6c
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 67 deletions.
2 changes: 0 additions & 2 deletions src/audio_engine.v
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,4 @@ module audio_engine(
.active(seq_active)
);

// TODO: Unused
// wire _unused = 0;
endmodule
2 changes: 0 additions & 2 deletions src/freq_synth.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ module freq_synth(

assign audio = audio_reg & active;

// TODO: Unused
// wire _unused = 0;
endmodule
10 changes: 5 additions & 5 deletions src/graphics_engine.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

module graphics_engine(
output wire [1:0] r, g, b,
input wire [9:0] x, y,
input wire [9:0] x,
input wire [8:0] y,
input wire frame_active, v_sync,
input wire clk, rst_n
input wire rst_n
);

wire [5:0] sine_off_y, sine_bg_off_y;
Expand All @@ -19,7 +20,7 @@ module graphics_engine(
if (~rst_n)
ctr <= 0;
else
ctr <= ctr + 1;
ctr <= ctr + 1'd1;
end

assign anim_x = x + ctr;
Expand Down Expand Up @@ -63,6 +64,5 @@ module graphics_engine(
)
) : 6'b00_00_00;

// TODO: Unused
// wire _unused = &{x[7:0], y[7:0], rst_n, v_sync};
wire _unused = &{sine_off_y[5], sine_bg_off_y[5], anim_x[9], anim_x[2:0], anim_2x[9:8], anim_2x[1:0]};
endmodule
14 changes: 7 additions & 7 deletions src/overlay_creator.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

module overlay_creator(
output wire overlay_active, text_active,
input wire [9:0] x, y
input wire [9:0] x,
input wire [8:0] y
);

//TODO: Double Layer optimization

wire [9:0] x_shadow, y_shadow;
wire [9:0] x_shadow;
wire [8:0] y_shadow;
wire shadow_active;

wire text_demosiine_main_active, text_demosiine_shadow_active;
wire text_tt08_main_active, text_tt08_shadow_active;
wire text_sda_main_active, text_sda_shadow_active;

assign x_shadow = x - 10'd4;
assign y_shadow = y - 10'd4;
assign y_shadow = y - 9'd4;

text_demosiine text_demosiine1 (
.overlay_active(text_demosiine_main_active),
Expand All @@ -29,12 +31,12 @@ module overlay_creator(

text_tt08 text_tt081 (
.overlay_active(text_tt08_main_active),
.x(x), .y(y)
.x(x[8:0]), .y(y)
);

text_tt08 text_tt082 (
.overlay_active(text_tt08_shadow_active),
.x(x_shadow), .y(y_shadow)
.x(x_shadow[8:0]), .y(y_shadow)
);

text_sda text_sda1 (
Expand All @@ -52,6 +54,4 @@ module overlay_creator(

assign overlay_active = text_active | shadow_active;

// TODO: Unused
// wire _unused = 0;
endmodule
4 changes: 1 addition & 3 deletions src/sine_layer.v
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,5 @@ module sine_layer (
default: sine_rgb = 6'b00_00_00;
endcase
end

// TODO: Unused
// wire _unused = &{qsine_flip_x[5:4]};

endmodule
24 changes: 12 additions & 12 deletions src/text_demosiine.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module text_demosiine(
output wire overlay_active,
input wire [9:0] x, y
input wire [9:0] x,
input wire [8:0] y
);

// TODO: Try array-based optimization
Expand All @@ -26,21 +27,20 @@ module text_demosiine(

always @(*) begin
case (demosiine_off_y)
6'd0: demosiine_active = demosiine_line0[demosiine_off_x];
6'd1: demosiine_active = demosiine_line1[demosiine_off_x];
6'd2: demosiine_active = demosiine_line2[demosiine_off_x];
6'd3: demosiine_active = demosiine_line3[demosiine_off_x];
6'd4: demosiine_active = demosiine_line4[demosiine_off_x];
6'd5: demosiine_active = demosiine_line5[demosiine_off_x];
6'd6: demosiine_active = demosiine_line6[demosiine_off_x];
6'd7: demosiine_active = demosiine_line7[demosiine_off_x];
6'd8: demosiine_active = demosiine_line8[demosiine_off_x];
6'd0: demosiine_active = demosiine_line0[demosiine_off_x[5:0]];
6'd1: demosiine_active = demosiine_line1[demosiine_off_x[5:0]];
6'd2: demosiine_active = demosiine_line2[demosiine_off_x[5:0]];
6'd3: demosiine_active = demosiine_line3[demosiine_off_x[5:0]];
6'd4: demosiine_active = demosiine_line4[demosiine_off_x[5:0]];
6'd5: demosiine_active = demosiine_line5[demosiine_off_x[5:0]];
6'd6: demosiine_active = demosiine_line6[demosiine_off_x[5:0]];
6'd7: demosiine_active = demosiine_line7[demosiine_off_x[5:0]];
6'd8: demosiine_active = demosiine_line8[demosiine_off_x[5:0]];
default: demosiine_active = 0;
endcase
end

assign overlay_active = (demosiine_off_x < 7'd47) & demosiine_active;

// TODO: Unused
// wire _unused = 0;
wire _unused = &{x[2:0], y[2:0]};
endmodule
26 changes: 13 additions & 13 deletions src/text_sda.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module text_sda(
output wire overlay_active,
input wire [9:0] x, y
input wire [9:0] x,
input wire [8:0] y
);

parameter [59:0] sda_line0 = 60'b000000000001000000100000000000110000000000000000001100011100;
Expand All @@ -26,22 +27,21 @@ module text_sda(

always @(*) begin
case (sda_off_y)
6'd0: sda_active = sda_line0[sda_off_x];
6'd1: sda_active = sda_line1[sda_off_x];
6'd2: sda_active = sda_line2[sda_off_x];
6'd3: sda_active = sda_line3[sda_off_x];
6'd4: sda_active = sda_line4[sda_off_x];
6'd5: sda_active = sda_line5[sda_off_x];
6'd6: sda_active = sda_line6[sda_off_x];
6'd7: sda_active = sda_line7[sda_off_x];
6'd8: sda_active = sda_line8[sda_off_x];
6'd9: sda_active = sda_line9[sda_off_x];
6'd0: sda_active = sda_line0[sda_off_x[5:0]];
6'd1: sda_active = sda_line1[sda_off_x[5:0]];
6'd2: sda_active = sda_line2[sda_off_x[5:0]];
6'd3: sda_active = sda_line3[sda_off_x[5:0]];
6'd4: sda_active = sda_line4[sda_off_x[5:0]];
6'd5: sda_active = sda_line5[sda_off_x[5:0]];
6'd6: sda_active = sda_line6[sda_off_x[5:0]];
6'd7: sda_active = sda_line7[sda_off_x[5:0]];
6'd8: sda_active = sda_line8[sda_off_x[5:0]];
6'd9: sda_active = sda_line9[sda_off_x[5:0]];
default: sda_active = 0;
endcase
end

assign overlay_active = (sda_off_x < 7'd61) & sda_active;

// TODO: Unused
// wire _unused = 0;
wire _unused = &{x[2:0], y[2:0]};
endmodule
29 changes: 14 additions & 15 deletions src/text_tt08.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module text_tt08(
output wire overlay_active,
input wire [9:0] x, y
input wire [8:0] x, y
);

parameter [21:0] tt08_line0 = 22'b0000000000000001111100;
Expand All @@ -15,31 +15,30 @@ module text_tt08(
parameter [21:0] tt08_line7 = 22'b0000000000000010100010;
parameter [21:0] tt08_line8 = 22'b0000000000000000111100;

wire [6:0] tt08_off_x;
wire [5:0] tt08_off_x;
wire [5:0] tt08_off_y;

reg tt08_active;

assign tt08_off_x = x[9:3] - 7'd30;
assign tt08_off_x = x[8:3] - 6'd30;
assign tt08_off_y = y[8:3] - 6'd25;

always @(*) begin
case (tt08_off_y)
6'd0: tt08_active = tt08_line0[tt08_off_x];
6'd1: tt08_active = tt08_line1[tt08_off_x];
6'd2: tt08_active = tt08_line2[tt08_off_x];
6'd3: tt08_active = tt08_line3[tt08_off_x];
6'd4: tt08_active = tt08_line4[tt08_off_x];
6'd5: tt08_active = tt08_line5[tt08_off_x];
6'd6: tt08_active = tt08_line6[tt08_off_x];
6'd7: tt08_active = tt08_line7[tt08_off_x];
6'd8: tt08_active = tt08_line8[tt08_off_x];
6'd0: tt08_active = tt08_line0[tt08_off_x[4:0]];
6'd1: tt08_active = tt08_line1[tt08_off_x[4:0]];
6'd2: tt08_active = tt08_line2[tt08_off_x[4:0]];
6'd3: tt08_active = tt08_line3[tt08_off_x[4:0]];
6'd4: tt08_active = tt08_line4[tt08_off_x[4:0]];
6'd5: tt08_active = tt08_line5[tt08_off_x[4:0]];
6'd6: tt08_active = tt08_line6[tt08_off_x[4:0]];
6'd7: tt08_active = tt08_line7[tt08_off_x[4:0]];
6'd8: tt08_active = tt08_line8[tt08_off_x[4:0]];
default: tt08_active = 0;
endcase
end

assign overlay_active = (tt08_off_x < 7'd23) & tt08_active;
assign overlay_active = (tt08_off_x < 6'd23) & tt08_active;

// TODO: Unused
// wire _unused = 0;
wire _unused = &{x[2:0], y[2:0]};
endmodule
8 changes: 3 additions & 5 deletions src/tt_um_demosiine_sda.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module tt_um_demosiine_sda (
input wire ena, // always 1 when the design is powered, so you can ignore it
input wire clk, // clock
input wire rst_n // reset_n - low to reset
);
);

wire [1:0] r, g, b;
wire audio;
Expand All @@ -32,7 +32,7 @@ module tt_um_demosiine_sda (

graphics_engine graphics_engine_1 (
.r(r), .g(g), .b(b),
.x(x), .y(y),
.x(x), .y(y[8:0]),
.frame_active(frame_active), .v_sync(v_sync),
.clk(clk), .rst_n(rst_n)
);
Expand All @@ -50,7 +50,5 @@ module tt_um_demosiine_sda (
assign uio_out = {audio, 7'd0};
assign uio_oe = 8'b1000_0000;

// TODO: Unused
// wire _unused = &{ena, ui_in, uio_in, x, y, frame_active};

wire _unused = &{ena, ui_in, uio_in, y[9]};
endmodule
7 changes: 4 additions & 3 deletions src/vga_controller.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ module vga_controller (
parameter H_SYNC_END = H_DISPLAY + H_BOTTOM + H_SYNC - 1;
parameter H_MAX = H_DISPLAY + H_TOP + H_BOTTOM + H_SYNC - 1;

wire h_limit = (x == W_MAX) || rst_n; // set when x is maximum
wire v_limit = (y == H_MAX) || rst_n; // set when y is maximum
wire h_limit = (x == W_MAX) || ~rst_n; // set when x is maximum
wire v_limit = (y == H_MAX) || ~rst_n; // set when y is maximum

// horizontal position counter
always @(posedge clk) begin
Expand All @@ -53,4 +53,5 @@ module vga_controller (

// frame_active is set when beam is in visible frame
assign frame_active = (x < W_DISPLAY) && (y < H_DISPLAY);
endmodule

endmodule

0 comments on commit 9270b6c

Please sign in to comment.