From 9e49f5e332d202c33394551833c3faed9ab647b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemens=20Sch=C3=B6lhorn?= Date: Mon, 4 Jun 2018 23:03:53 +0200 Subject: [PATCH] Correctly handle CR followed by LF This would previously result in an empty line, because the CR resets the current column to zero. Now we remember the last written char and column so that we can restore the column before finishing the line. --- terminal.vhd | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/terminal.vhd b/terminal.vhd index 854ad20..2ee85e4 100644 --- a/terminal.vhd +++ b/terminal.vhd @@ -46,6 +46,9 @@ architecture syn of terminal is signal rowlen_we: std_logic; signal rowlen_wa: std_logic_vector(5 downto 0); signal rowlen_di: std_logic_vector(6 downto 0); + + signal last_written_char: std_logic_vector(7 downto 0); + signal last_cursor_col: unsigned(6 downto 0); begin -- writes the next character, advances the cursor and saves the length of @@ -83,6 +86,10 @@ begin end if; if write_enable = '1' then + -- save last written char and column for correct CR, LF handling + last_written_char <= write_data; + last_cursor_col <= cursor_col; + -- backspace if write_data = x"08" then cursor_col <= previous_col; @@ -97,6 +104,12 @@ begin cursor_row <= next_line; rowlen_we <= '1'; -- save row length + -- write the row length with was valid before CR reset the + -- cursor (for consecutive CR, LF) + if last_written_char = x"0d" then + rowlen_di <= std_logic_vector(last_cursor_col); + end if; + -- normal characters else charbuf_we <= '1'; -- write normal characters