aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-09-03 17:36:48 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-09-03 17:36:48 +0200
commitd39bdc0782ce5dcfc422ddb613f6af1953f664c0 (patch)
tree0b2d148b70772ca73b2967ea93a1a34f9f2a62c1
parentfe733d971b4eeef8f5decfb762de01e57f977734 (diff)
downloadAGH-engineering-thesis-d39bdc0782ce5dcfc422ddb613f6af1953f664c0.tar.gz
AGH-engineering-thesis-d39bdc0782ce5dcfc422ddb613f6af1953f664c0.zip
register values immediately after reading the from embedded ram (this is required for memories to get inferred)
-rw-r--r--design/vga.v130
1 files changed, 91 insertions, 39 deletions
diff --git a/design/vga.v b/design/vga.v
index e652ea6..b46dcbd 100644
--- a/design/vga.v
+++ b/design/vga.v
@@ -17,11 +17,11 @@
/* Non-wishbone */
input wire clock_25mhz,
- output reg h_sync,
- output reg v_sync,
- output reg [2:0] red,
- output reg [2:0] green,
- output reg [2:0] blue
+ output wire h_sync,
+ output wire v_sync,
+ output wire [2:0] red,
+ output wire [2:0] green,
+ output wire [2:0] blue
);
reg powered_on;
@@ -156,18 +156,10 @@
$readmemb(FONT_FILE, font, 0, 128 * 16 - 1);
end
- wire [6:0] char_x;
- wire [4:0] char_y;
- wire [12:0] char_flat_idx;
- wire [15:0] text_memory_field;
- wire [7:0] char;
- assign char_x = h_counter / 8;
- assign char_y = v_counter / 16;
- assign char_flat_idx = char_x + char_y * LINE_LENGTH;
- assign text_memory_field = text_memory[char_flat_idx[12:1]];
- assign char = char_flat_idx[0] ?
- text_memory_field[15:8] : text_memory_field[7:0];
+ parameter FG_COLOR = {3'b010, 3'b111, 3'b101};
+ parameter BG_COLOR = {3'b000, 3'b000, 3'b111};
+ /* display this for non-ascii characters */
wire [0:7] replacement_char [0:16];
assign replacement_char[0] = 8'b00000000;
assign replacement_char[1] = 8'b00011000;
@@ -186,38 +178,90 @@
assign replacement_char[14] = 8'b00011000;
assign replacement_char[15] = 8'b00000000;
- wire [2:0] char_pixel_x;
- wire [3:0] char_pixel_y;
+ wire [6:0] char_x;
+ wire [4:0] char_y;
+ wire [12:0] char_flat_idx;
+ assign char_x = h_counter / 8;
+ assign char_y = v_counter / 16;
+ assign char_flat_idx = char_x + char_y * LINE_LENGTH;
+
+ /*
+ * hs[0], vs[0], fetched_memory_field, is_high_byte, char, char_pixel_x[0],
+ * char_pixel_y and display_on[0] get loaded first, then, one tick later,
+ * hs[1], vs[1], char_pixel_x[1], display_on[1], char_pixel_row,
+ * replacement_pixel_row and is_ascii_char get loaded and finally, another
+ * tick later, color gets loaded
+ */
+ reg [2:0] hs;
+ reg [2:0] vs;
+ reg [15:0] fetched_memory_field;
+ reg is_high_byte;
+ reg [2:0] char_pixel_x [1:0];
+ reg [3:0] char_pixel_y;
+ reg [1:0] display_on;
+ reg [0:7] char_pixel_row;
+ reg [0:7] replacement_pixel_row;
+ reg is_ascii_char;
+ reg [8:0] color;
+
+ wire [7:0] char;
+ wire [0:7] pixel_row_to_use;
wire pixel_on;
- wire display_on;
- assign char_pixel_x = h_counter % 8;
- assign char_pixel_y = v_counter % 16;
- /* Replace non-ASCII characters (i.e. chars with values above 127) */
- assign pixel_on = char[7] ? replacement_char[char_pixel_y][char_pixel_x] :
- font[char[6:0] * 16 + char_pixel_y][char_pixel_x];
- assign display_on = h_stage == H_STAGE_ACTIVE_VIDEO &&
- v_stage == V_STAGE_ACTIVE_VIDEO;
+ assign char = is_high_byte ? fetched_memory_field[15:8] :
+ fetched_memory_field[7:0];
+ assign pixel_row_to_use = is_ascii_char ? char_pixel_row :
+ replacement_pixel_row;
+ assign pixel_on = pixel_row_to_use[char_pixel_x[1]];
- parameter FG_COLOR = {3'b010, 3'b111, 3'b101};
- parameter BG_COLOR = {3'b000, 3'b000, 3'b111};
+ /* Assign module's outputs */
+ assign h_sync = hs[2];
+ assign v_sync = vs[2];
+ assign {red, green, blue} = color;
always @ (posedge clock_25mhz) begin
+ /* Stuff, that gets loaded first */
if (h_stage == H_STAGE_SYNC)
- h_sync <= H_POLARITY;
+ hs[0] <= H_POLARITY;
else
- h_sync <= ~H_POLARITY;
+ hs[0] <= ~H_POLARITY;
if (v_stage == V_STAGE_SYNC)
- v_sync <= V_POLARITY;
+ vs[0] <= V_POLARITY;
else
- v_sync <= ~V_POLARITY;
+ vs[0] <= ~V_POLARITY;
+
+ fetched_memory_field <= text_memory[char_flat_idx[12:1]];
+ is_high_byte <= char_flat_idx[0];
+
+ char_pixel_x[0] <= h_counter % 8;
+ char_pixel_y <= v_counter % 16;
+
+ display_on[0] <= h_stage == H_STAGE_ACTIVE_VIDEO &&
+ v_stage == V_STAGE_ACTIVE_VIDEO;
+
+ /* Stuff, that gets loaded one tick later */
+ hs[1] <= hs[0];
+ vs[1] <= vs[0];
+
+ char_pixel_x[1] <= char_pixel_x[0];
+
+ display_on[1] <= display_on[0];
+
+ char_pixel_row <= font[char[6:0] * 16 + char_pixel_y];
+ replacement_pixel_row <= replacement_char[char_pixel_y];
+
+ is_ascii_char <= ~char[7];
+
+ /* Stuff, that gets loaded another tick later */
+ hs[2] <= hs[1];
+ vs[2] <= vs[1];
if (!display_on)
- {red, green, blue} <= 9'b0;
+ color <= 9'b0;
else if (pixel_on)
- {red, green, blue} <= FG_COLOR;
+ color <= FG_COLOR;
else
- {red, green, blue} <= BG_COLOR;
+ color <= BG_COLOR;
end // always @ (posedge clock_25mhz)
`ifdef SIMULATION
@@ -227,9 +271,18 @@
powered_on_latched <= 0;
ack <= 0;
- h_sync <= ~H_POLARITY;
- v_sync <= ~V_POLARITY;
- {red, green, blue} <= 9'b0;
+ hs <= {3{~H_POLARITY}};
+ vs <= {3{~V_POLARITY}};
+ fetched_memory_field <= 16'b0;
+ is_high_byte <= 0;
+ char_pixel_x[0] <= 0;
+ char_pixel_x[1] <= 0;
+ char_pixel_y <= 0;
+ display_on <= 2'b0;
+ char_pixel_row <= 8'b0;
+ replacement_pixel_row <= 8'b0;
+ is_ascii_char <= 0;
+ color <= 9'b0;
h_counter <= 0;
h_stage <= H_STAGE_RB_OR_FP;
@@ -239,4 +292,3 @@
end
`endif
endmodule // vga
-