92 lines
2.1 KiB
Plaintext
92 lines
2.1 KiB
Plaintext
module chargen
|
|
#(
|
|
parameter CHAR_WIDTH=8,
|
|
parameter CHAR_HEIGHT=8,
|
|
parameter COLS=80,
|
|
parameter ROWS=60)
|
|
(input i_clk,
|
|
input i_rst,
|
|
input i_de,
|
|
input i_hsync,
|
|
input i_vsync,
|
|
output o_r,
|
|
output o_g,
|
|
output o_b);
|
|
|
|
reg [7:0] fontrom [0:2047];
|
|
reg [19:0] pos;
|
|
reg [2:0] font_row_offset;
|
|
reg font_row_offset_lock;
|
|
reg [7:0] glyph_line;
|
|
reg [11:0] cram_addr;
|
|
reg [11:0] cram_addr_sol;
|
|
reg [6:0] line_counter;
|
|
|
|
wire [7:0] glyph_line_wire;
|
|
wire glyph_bit;
|
|
wire [11:0] font_index;
|
|
|
|
assign font_index = {cram_addr[7:0], font_row_offset};
|
|
assign glyph_bit = glyph_line[7];
|
|
assign o_r = glyph_bit;
|
|
assign o_g = glyph_bit;
|
|
assign o_b = cram_addr[0];
|
|
|
|
initial begin
|
|
$readmemh("/Users/car/Projects/hope/font.hex", fontrom);
|
|
end
|
|
|
|
always @(posedge i_clk, posedge i_rst) begin
|
|
if (i_rst) begin
|
|
glyph_line <= 0;
|
|
end else begin
|
|
if (pos[2:0] == 7) begin
|
|
glyph_line <= fontrom[font_index];
|
|
end else if (i_de) begin
|
|
glyph_line <= (glyph_line << 1);
|
|
end
|
|
end
|
|
end // always @ (posedge i_clk, posedge i_rst)
|
|
|
|
always @(posedge i_clk, posedge i_rst) begin
|
|
if (i_rst) begin
|
|
cram_addr <= 0;
|
|
cram_addr_sol <= 0;
|
|
line_counter <= 0;
|
|
end else if (i_hsync) begin
|
|
if (line_counter == 0) begin
|
|
cram_addr_sol <= cram_addr;
|
|
line_counter <= 0;
|
|
end else begin
|
|
cram_addr <= cram_addr_sol;
|
|
line_counter <= line_counter + 1;
|
|
end
|
|
end else if (pos[2:0] == 7)
|
|
cram_addr <= cram_addr + 1;
|
|
end
|
|
|
|
always @(posedge i_clk, posedge i_rst) begin
|
|
if (i_rst) begin
|
|
pos <= 0;
|
|
font_row_offset <= 0;
|
|
font_row_offset_lock <= 0;
|
|
end else begin
|
|
if (i_vsync) begin
|
|
pos <= 0;
|
|
font_row_offset <= 0;
|
|
end else if (i_de) begin
|
|
pos <= pos + 1;
|
|
end else begin
|
|
pos <= pos;
|
|
|
|
if (~font_row_offset_lock & i_hsync) begin
|
|
font_row_offset_lock <= 1;
|
|
font_row_offset <= font_row_offset + 1;
|
|
end else if (~i_hsync) begin
|
|
font_row_offset_lock <= 0;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
endmodule
|