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:
2018-04-25 23:50:09 +02:00
parent 2f858a6764
commit 1c22e73128
2 changed files with 107 additions and 39 deletions

View File

@ -35,50 +35,67 @@ architecture syn of terminal is
signal image_y: std_logic_vector(8 downto 0);
signal pixel_rgb: std_logic_vector(23 downto 0);
signal fb_write_enable: std_logic;
signal fb_write_address: std_logic_vector(12 downto 0);
signal fb_write_data: std_logic_vector(7 downto 0);
-- the cursor points to the position where the next char will be written
signal cursor_row: unsigned(5 downto 0);
signal cursor_col: unsigned(6 downto 0);
signal write_x: unsigned(6 downto 0);
signal write_y: unsigned(5 downto 0);
signal charbuf_we: std_logic;
signal charbuf_wa: std_logic_vector(12 downto 0);
signal charbuf_di: std_logic_vector(7 downto 0);
signal rowlen_we: std_logic;
signal rowlen_wa: std_logic_vector(5 downto 0);
signal rowlen_di: std_logic_vector(6 downto 0);
begin
fb_write_address <= std_logic_vector(write_x) & std_logic_vector(write_y);
-- writes the next character, advances the cursor and saves the length of
-- the current row before jumping to the next one
process(clk)
variable next_line: unsigned(5 downto 0);
begin
if rising_edge(clk) then
fb_write_enable <= '0';
fb_write_data <= write_data;
-- we write to the current cursor position and simply pass the data
-- through (but CR and LF are ignored, so charbuf_we is 0 by default)
charbuf_we <= '0';
charbuf_wa <= std_logic_vector(cursor_col) & std_logic_vector(cursor_row);
charbuf_di <= write_data;
-- we save the length of the current row before advancing to the
-- next row (the current row length is the cursor column when using
-- LF the go to the next line or one more when wrapping around)
rowlen_we <= '0';
rowlen_wa <= std_logic_vector(cursor_row);
rowlen_di <= std_logic_vector(cursor_col);
-- calculate next line
if write_y = 59 then
if cursor_row = 59 then
next_line := (others => '0');
else
next_line := write_y + 1;
next_line := cursor_row + 1;
end if;
if write_enable = '1' then
fb_write_enable <= '1';
if write_x = 79 then
write_x <= (others => '0');
write_y <= next_line;
else
write_x <= write_x + 1;
end if;
-- carriage return
if write_data = x"0d" then
fb_write_enable <= '0';
write_x <= (others => '0');
end if;
cursor_col <= (others => '0');
-- line feed (implicit CR)
if write_data = x"0a" then
fb_write_enable <= '0';
write_x <= (others => '0');
write_y <= next_line;
elsif write_data = x"0a" then
cursor_col <= (others => '0');
cursor_row <= next_line;
rowlen_we <= '1'; -- save row length
-- normal characters
else
charbuf_we <= '1'; -- write normal characters
if cursor_col = 79 then
cursor_col <= (others => '0');
cursor_row <= next_line;
rowlen_we <= '1'; -- save row length
rowlen_di <= "1010000"; -- 80 (cursor_col is only 79)
else
cursor_col <= cursor_col + 1;
end if;
end if;
end if;
end if;
@ -120,9 +137,14 @@ begin
x => image_x,
y => image_y,
rgb => pixel_rgb,
write_enable => fb_write_enable,
write_address => fb_write_address,
write_data => fb_write_data
cursor_row => cursor_row,
cursor_col => cursor_col,
charbuf_we => charbuf_we,
charbuf_wa => charbuf_wa,
charbuf_di => charbuf_di,
rowlen_we => rowlen_we,
rowlen_wa => rowlen_wa,
rowlen_di => rowlen_di
);
end syn;