Files
stack/chargen.sv
2026-03-07 23:45:11 -05:00

46 lines
1.2 KiB
Systemverilog

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 [10:0] i_row,
input [10:0] i_col,
input [15:0] i_ram_data,
output [12:0] o_ram_addr,
output o_r,
output o_g,
output o_b);
reg [7:0] fontrom [0:2047];
reg [7:0] glyph_line;
wire glyph_bit;
wire [7:0] char_attr;
wire [7:0] char_char;
assign o_ram_addr = i_row[10:3] * COLS + i_col[10:3];
assign glyph_bit = glyph_line[CHAR_WIDTH-1];
assign char_char = i_ram_data[7:0];
assign char_attr = i_ram_data[15:8];
assign o_r = glyph_bit?char_attr[0]:char_attr[3];
assign o_g = glyph_bit?char_attr[1]:char_attr[4];
assign o_b = glyph_bit?char_attr[2]:char_attr[5];
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 if (i_col[2:0] == 0) begin
glyph_line <= fontrom[{char_char, i_row[2:0]}];
end else begin
glyph_line <= glyph_line << 1;
end
end // always @ (posedge i_clk, posedge i_rst)
endmodule