add cpuFetchStage instance
[rv32.git] / vga_font_generator.v
1 /*
2 * Copyright 2018 Jacob Lifshay
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 */
23 `timescale 1ns / 100ps
24
25 module vga_font_generator(
26 input pixel_clock,
27 input [15:0] screen_x,
28 input [15:0] screen_y,
29 input screen_valid,
30 input [7:0] screen_char,
31 output [7:0] vga_r,
32 output [7:0] vga_g,
33 output [7:0] vga_b
34 );
35
36 parameter font_x_size = 8;
37 parameter font_y_size = 8;
38
39 // ram_style = "block"
40 reg [font_x_size - 1 : 0] font8x8[0 : 256 * font_y_size - 1];
41
42 initial $readmemh("font8x8.hex", font8x8);
43
44 wire [2:0] sub_char_x = screen_x[2:0];
45 wire [2:0] sub_char_y = screen_y[2:0];
46 wire [15:0] font_address = {screen_char, sub_char_y};
47 reg [7:0] font_line;
48 reg [2:0] output_sub_char_x;
49
50 initial font_line = 0;
51 initial output_sub_char_x = 0;
52
53 always @(posedge pixel_clock) begin
54 font_line <= font8x8[font_address];
55 output_sub_char_x <= sub_char_x;
56 end
57
58 wire pixel_active = ((font_line >> output_sub_char_x) & 1) == 1;
59 assign vga_r = pixel_active ? 255 : 0;
60 assign vga_g = pixel_active ? 255 : 0;
61 assign vga_b = pixel_active ? 255 : 0;
62
63 endmodule