library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.numeric_std.all; use std.textio.all; use ieee.std_logic_textio.all; entity font_rom is generic ( input_clk: integer ); port ( clk: in std_logic; x, y: in std_logic_vector(9 downto 0); rgb: out std_logic_vector(23 downto 0) ); end font_rom; architecture logic of font_rom is type rom_type is array(0 to 127) of std_logic_vector(63 downto 0); type framebuffer_type is array(0 to 59, 0 to 79) of std_logic_vector(7 downto 0); impure function read_font(filename: in string) return rom_type is file rom_file: text is in filename; variable rom_line: line; variable rom: rom_type; begin -- skip comment in first line readline(rom_file, rom_line); for i in rom_type'range loop readline(rom_file, rom_line); hread(rom_line, rom(i)); end loop; return rom; end function; constant font: rom_type := read_font("font.hex"); constant framebuffer: framebuffer_type := ( 0 => (x"48", x"61", x"6C", x"6c", x"6f", others => x"00"), 1 to 59 => (others => x"00") ); signal char_x: integer range 0 to 79; signal char_y: integer range 0 to 59; signal current_char: std_logic_vector(7 downto 0); signal current_glyph: std_logic_vector(63 downto 0); signal current_glyph_pos: integer range 0 to 127; signal glyph_pos_raw: std_logic_vector(5 downto 0); signal glyph_pos: integer range 0 to 63; begin char_x <= to_integer(unsigned(x(9 downto 3))); char_y <= to_integer(unsigned(y(9 downto 3))); process(clk) is begin if rising_edge(clk) then current_char <= framebuffer(char_y, char_x); end if; end process; current_glyph_pos <= to_integer(unsigned(current_char)); process(clk) is begin if rising_edge(clk) then current_glyph <= font(current_glyph_pos); end if; end process; glyph_pos_raw <= y(2 downto 0) & x(2 downto 0); glyph_pos <= to_integer(unsigned(glyph_pos_raw)); -- actually currently BRG rgb <= "111111111111111111111111" when current_glyph(glyph_pos) = '1' else "000000000000000000000000"; end logic;