Implement scrolling for the terminal
The line where the cursor located is always displayed at the bottom and old content scrolls up until disappearing eventually at the top of the screen. This is implemented using a ring buffer of all rows, where old chars are only overwritten when writing new ones. To avoid displaying stale data at the end of rows, we save the length of every row and hide chars that were not overwritten (yet).
This commit is contained in:
@ -18,9 +18,16 @@ entity framebuffer is
|
||||
|
||||
rgb: out std_logic_vector(23 downto 0);
|
||||
|
||||
write_enable: std_logic;
|
||||
write_address: std_logic_vector(12 downto 0);
|
||||
write_data: std_logic_vector(7 downto 0)
|
||||
cursor_row: in unsigned(5 downto 0);
|
||||
cursor_col: in unsigned(6 downto 0);
|
||||
|
||||
-- write access to the character and row length rams
|
||||
charbuf_we: in std_logic;
|
||||
charbuf_wa: in std_logic_vector(12 downto 0);
|
||||
charbuf_di: in std_logic_vector(7 downto 0);
|
||||
rowlen_we: in std_logic;
|
||||
rowlen_wa: in std_logic_vector(5 downto 0);
|
||||
rowlen_di: in std_logic_vector(6 downto 0)
|
||||
);
|
||||
end framebuffer;
|
||||
|
||||
@ -45,10 +52,18 @@ architecture logic of framebuffer is
|
||||
|
||||
constant font: rom_type := read_font("font.hex");
|
||||
|
||||
signal row: unsigned(5 downto 0);
|
||||
signal col: unsigned(6 downto 0);
|
||||
|
||||
signal eff_row_wide: unsigned(6 downto 0);
|
||||
signal eff_row: unsigned(5 downto 0);
|
||||
|
||||
signal read_address: std_logic_vector(12 downto 0);
|
||||
signal current_char: std_logic_vector(7 downto 0);
|
||||
signal current_row_length: std_logic_vector(6 downto 0);
|
||||
|
||||
signal current_glyph: std_logic_vector(63 downto 0);
|
||||
signal current_glyph_valid: boolean;
|
||||
|
||||
-- delay by 2 cycles to match the delay of x/y -> rgb
|
||||
constant glyph_pos_length: integer := 2;
|
||||
@ -56,7 +71,16 @@ architecture logic of framebuffer is
|
||||
signal glyph_pos: glyph_pos_type;
|
||||
begin
|
||||
|
||||
read_address <= x(9 downto 3) & y(8 downto 3);
|
||||
row <= unsigned(y(8 downto 3));
|
||||
col <= unsigned(x(9 downto 3));
|
||||
|
||||
-- calculate effective row with respect to the cursor; this keeps the
|
||||
-- cursor always at the bottom of the screen and old contents scoll up
|
||||
eff_row_wide <= resize(cursor_row, 7) + row + 1;
|
||||
eff_row <= resize(eff_row_wide, 6) when eff_row_wide < "0111100" else -- 60
|
||||
resize(eff_row_wide - "0111100", 6); -- 60
|
||||
|
||||
read_address <= std_logic_vector(col) & std_logic_vector(eff_row);
|
||||
|
||||
terminal_buffer: entity work.ram_2port generic map (
|
||||
WIDTH_BITS => 8,
|
||||
@ -65,11 +89,32 @@ begin
|
||||
clk => clk,
|
||||
ra => read_address,
|
||||
do => current_char,
|
||||
we => write_enable,
|
||||
wa => write_address,
|
||||
di => write_data
|
||||
we => charbuf_we,
|
||||
wa => charbuf_wa,
|
||||
di => charbuf_di
|
||||
);
|
||||
|
||||
-- store the length of every row so that we don't have to overwrite
|
||||
-- existing rows when wrapping around and can simply disable display
|
||||
-- of non-overwritten characters
|
||||
row_lengths: entity work.ram_2port generic map (
|
||||
WIDTH_BITS => 7,
|
||||
DEPTH_BITS => 6
|
||||
) port map (
|
||||
clk => clk,
|
||||
ra => std_logic_vector(eff_row),
|
||||
do => current_row_length,
|
||||
we => rowlen_we,
|
||||
wa => rowlen_wa,
|
||||
di => rowlen_di
|
||||
);
|
||||
|
||||
-- as the row length is only saved after switching to the next row, we use
|
||||
-- the current cursor col position in the case of the current row, which
|
||||
-- is always at the bottom, so it is always row 59
|
||||
current_glyph_valid <= col < cursor_col when row = "111011" else -- 59
|
||||
col < unsigned(current_row_length);
|
||||
|
||||
process(clk)
|
||||
variable current_glyph_pos: integer range 0 to 127;
|
||||
begin
|
||||
@ -95,8 +140,9 @@ begin
|
||||
end process delay_glyph_pos;
|
||||
|
||||
-- actually currently BRG
|
||||
rgb <=
|
||||
"111111111111111111111111" when current_glyph(glyph_pos(1)) = '1' else
|
||||
"000000000000000000000000";
|
||||
with current_glyph(glyph_pos(1)) = '1' and current_glyph_valid
|
||||
select rgb <=
|
||||
"111111111111111111111111" when true,
|
||||
"000000000000000000000000" when false;
|
||||
|
||||
end logic;
|
||||
|
Reference in New Issue
Block a user