display: farben ftw
[hwmod.git] / src / display.vhd
index 8b0a9cc1748b0e257f24cb6ef1b36141304a01e3..ccb8ba3befae217af250e649d361bf56cd03f6a3 100644 (file)
@@ -28,15 +28,17 @@ end entity display;
 
 architecture beh of display is
        type DISPLAY_STATE is (SIDLE, S_NEW_BS, S_BACK, S_BLANK, S_NEW_RESULT,
-               S_NEW_INPUT, S_COUNTUP, S_GETCH, S_CR1, S_NL1, S_PUTCH1, S_PUTCH2,
-               S_WAIT, S_NOP1);
+               S_ZEILEUP, S_NEW_INPUT, S_COUNTUP, S_GETCH, S_CR1, S_NL1, S_PUTCH1,
+               S_PUTCH2, S_WAIT, S_NOP1, S_READ_RESULT_0, S_READ_RESULT_1,
+               S_READ_RESULT_2, S_INIT, S_PS1_0, S_PS1_1, S_PS1_2, S_PS1_3, S_PS1_4,
+               S_PS1_5);
        signal state_int, state_next : DISPLAY_STATE;
        signal d_zeile_int, d_zeile_next : hzeile;
        signal d_spalte_int, d_spalte_next : hspalte;
        signal d_get_int, d_get_next : std_logic;
        signal command_int, command_next : std_logic_vector(7 downto 0);
        signal command_data_int, command_data_next : std_logic_vector(31 downto 0);
-       signal istate_next, istate_int : signed(2 downto 0);
+       signal istate_next, istate_int : signed(4 downto 0);
 begin
        d_zeile <= d_zeile_int;
        d_spalte <= d_spalte_int;
@@ -48,7 +50,7 @@ begin
        begin
                if sys_res_n = '0' then
                        -- internal
-                       state_int <= SIDLE;
+                       state_int <= S_INIT;
                        istate_int <= (others => '0');
                        -- out
                        d_zeile_int <= (others => '0');
@@ -77,8 +79,30 @@ begin
                istate_next <= istate_int;
 
                case state_int is
+                       when S_INIT =>
+                               state_next <= S_PS1_0;
+
+                       when S_PS1_0 =>
+                               istate_next <= b"01001";
+                               state_next <= S_WAIT;
+                       when S_PS1_1 =>
+                               istate_next <= b"01010";
+                               state_next <= S_WAIT;
+                       when S_PS1_2 =>
+                               istate_next <= b"01011";
+                               state_next <= S_WAIT;
+                       when S_PS1_3 =>
+                               istate_next <= b"01100";
+                               state_next <= S_WAIT;
+                       when S_PS1_4 =>
+                               istate_next <= b"01101";
+                               state_next <= S_WAIT;
+                       when S_PS1_5 =>
+                               istate_next <= b"00111";
+                               state_next <= S_WAIT;
+
                        when SIDLE =>
-                               istate_next <= b"111"; -- default: immer wieder ins SIDLE;
+                               istate_next <= b"00111"; -- default: immer wieder ins SIDLE;
                                if d_new_bs = '1' then
                                        state_next <= S_NEW_BS;
                                elsif d_new_eingabe = '1' then
@@ -89,7 +113,7 @@ begin
                                end if;
 
                        when S_NEW_RESULT =>
-                               state_next <= S_CR1;
+                               state_next <= S_ZEILEUP;
                        when S_NEW_INPUT =>
                                state_next <= S_COUNTUP;
 
@@ -99,25 +123,54 @@ begin
                                if free = '0' then
                                        state_next <= S_WAIT;
                                        case istate_int is
-                                               when b"111" => istate_next <= b"001"; -- => danach S_BLANK und wieder hierher
-                                               when others => istate_next <= b"111"; -- => danach SIDLE
+                                               when b"00111" => istate_next <= b"00001"; -- => danach S_BLANK und wieder hierher
+                                               when others => istate_next <= b"00111"; -- => danach SIDLE
                                        end case;
                                end if;
                        when S_BLANK =>
                                if free = '0' then
                                        state_next <= S_WAIT;
-                                       istate_next <= b"010"; -- => danach S_BACK
+                                       istate_next <= b"00010"; -- => danach S_BACK
                                end if;
 
+                       when S_ZEILEUP =>
+                               case istate_int is
+                                       when b"00011" =>
+                                               state_next <= S_WAIT;
+                                               istate_next <= b"01000"; -- => danach S_PS1
+                                       when others => state_next <= S_CR1;
+                               end case;
+
                        when S_CR1 =>
                                if free = '0' then
                                        state_next <= S_WAIT;
-                                       istate_next <= b"000"; -- => danach S_NL1
+                                       case istate_int is
+                                               when b"00110" => istate_next <= b"00101"; -- => danach S_NL1, S_ZEILEUP, S_PS1, SIDLE
+                                               when others => istate_next <= b"00000"; -- => danach S_NL1 und S_COUNTUP
+                                       end case;
                                end if;
                        when S_NL1 =>
                                if free = '0' then
                                        state_next <= S_WAIT;
-                                       istate_next <= b"111"; -- => wieder nach SIDLE
+                                       case istate_int is
+                                               when b"00101" => istate_next <= b"00011"; -- => danach S_ZEILEUP, PS1
+                                               when others => istate_next <= b"10000"; -- => danach S_READ_RESULT_0
+                                       end case;
+                               end if;
+
+                       when S_READ_RESULT_0 =>
+                               istate_next <= b"10001";
+                               state_next <= S_WAIT;
+                       when S_READ_RESULT_1 =>
+                               istate_next <= b"10010";
+                               state_next <= S_WAIT;
+                       when S_READ_RESULT_2 =>
+                               if unsigned(d_spalte_int) /= 70 then
+                                       state_next <= S_COUNTUP;
+                                       istate_next <= b"10010"; -- => wieder nach S_READ_RESULT_2
+                               else
+                                       state_next <= S_WAIT;
+                                       istate_next <= b"00110"; -- => danach S_CR1 und d_spalte_next clearen und d_zeile_next inkrementieren
                                end if;
 
                        when S_COUNTUP =>
@@ -139,9 +192,23 @@ begin
                        when S_NOP1 =>
                                if free = '1' then
                                        case istate_int is
-                                               when b"000" => state_next <= S_NL1;
-                                               when b"001" => state_next <= S_BLANK;
-                                               when b"010" => state_next <= S_BACK;
+                                               when b"00000" => state_next <= S_NL1;
+                                               when b"00001" => state_next <= S_BLANK;
+                                               when b"00010" => state_next <= S_BACK;
+                                               when b"00011" => state_next <= S_ZEILEUP;
+                                               when b"00110" => state_next <= S_CR1;
+                                               when b"00101" => state_next <= S_NL1;
+
+                                               when b"10000" => state_next <= S_READ_RESULT_0;
+                                               when b"10001" => state_next <= S_READ_RESULT_1;
+                                               when b"10010" => state_next <= S_READ_RESULT_2;
+
+                                               when b"01000" => state_next <= S_PS1_0;
+                                               when b"01001" => state_next <= S_PS1_1;
+                                               when b"01010" => state_next <= S_PS1_2;
+                                               when b"01011" => state_next <= S_PS1_3;
+                                               when b"01100" => state_next <= S_PS1_4;
+                                               when b"01101" => state_next <= S_PS1_5;
                                                when others => state_next <= SIDLE;
                                        end case;
                                end if;
@@ -151,6 +218,27 @@ begin
        -- out
        process(state_int, d_zeile_int, d_spalte_int, d_get_int, command_int,
                command_data_int, d_char)
+               function zeile2char(i : std_logic_vector; stelle : natural) return hbyte is
+                       subtype zeilnum is string(1 to 2);
+                       type zeilnum_arr is array (natural range 0 to 49) of zeilnum;
+                       constant zn : zeilnum_arr := (
+                               0 => "00", 1 => "01", 2 => "02", 3 => "03", 4 => "04",
+                               5 => "05", 6 => "06", 7 => "07", 8 => "08", 9 => "09",
+                               10 => "10", 11 => "11", 12 => "12", 13 => "13", 14 => "14",
+                               15 => "15", 16 => "16", 17 => "17", 18 => "18", 19 => "19",
+                               20 => "20", 21 => "21", 22 => "22", 23 => "23", 24 => "24",
+                               25 => "25", 26 => "26", 27 => "27", 28 => "28", 29 => "29",
+                               30 => "30", 31 => "31", 32 => "32", 33 => "33", 34 => "34",
+                               35 => "35", 36 => "36", 37 => "37", 38 => "38", 39 => "39",
+                               40 => "40", 41 => "41", 42 => "42", 43 => "43", 44 => "44",
+                               45 => "45", 46 => "46", 47 => "47", 48 => "48", 49 => "49",
+                               others => "xy");
+                       variable t : signed(hzeile'length downto 0);
+               begin
+                       t := signed('0' & i);
+                       t := t / 2;
+                       return hbyte(to_unsigned(character'pos(zn(to_integer(t))(stelle)),8));
+               end;
        begin
                d_zeile_next <= d_zeile_int;
                d_spalte_next <= d_spalte_int;
@@ -159,28 +247,50 @@ begin
                command_data_next <= command_data_int;
 
                case state_int is
-                       when SIDLE =>
-                               null;
-                       when S_NEW_RESULT =>
-                               d_spalte_next <= (others => '0');
-                               case d_zeile_int is
-                                       when "11111" => d_zeile_next <= "00000";
-                                       when others => d_zeile_next <= std_logic_vector(unsigned(d_zeile_int) + 1);
-                               end case;
-                       when S_NEW_INPUT =>
-                               null;
+                       when S_INIT => null;
+
+                       when S_PS1_0 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"0000ff" & x"28"; -- '('
+                       when S_PS1_1 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"00ff00" & zeile2char(d_zeile_int,1); -- 'x'
+                       when S_PS1_2 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"00ff00" & zeile2char(d_zeile_int,2); -- 'y'
+                       when S_PS1_3 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"0000ff" & x"29"; -- ')'
+                       when S_PS1_4 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"00ffff" & x"24"; -- '$'
+                       when S_PS1_5 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"ffffff" & x"20"; -- ' '
+
+                       when SIDLE => null;
+                       when S_NEW_RESULT => null;
+                       when S_NEW_INPUT => null;
 
                        when S_NEW_BS =>
                                -- underflow check schon im history modul
                                d_spalte_next <= std_logic_vector(unsigned(d_spalte_int) - 1);
                        when S_BACK =>
-                               -- einen schritt zurueck
+                               -- einen schritt zurueck, +6 wegen $PS1
                                command_next <= COMMAND_SET_CURSOR_COLUMN;
-                               command_data_next <= x"ffffff" & '0' & std_logic_vector(unsigned(d_spalte_int));
+                               command_data_next <= x"ffffff" & '0' & std_logic_vector(unsigned(d_spalte_int) + 6);
                        when S_BLANK =>
                                command_next <= COMMAND_SET_CHAR;
                                command_data_next <= x"ffffff" & x"20"; -- white space
 
+                       when S_ZEILEUP =>
+                               d_spalte_next <= (others => '0');
+                               case d_zeile_int is
+                                       -- 49 * 2 + 1
+                                       when "1100010" => d_zeile_next <= (others => '0');
+                                       when others => d_zeile_next <= std_logic_vector(unsigned(d_zeile_int) + 1);
+                               end case;
+
                        when S_CR1 =>
                                command_next <= COMMAND_SET_CHAR;
                                command_data_next <= x"ffffff" & x"0d"; -- carrige return
@@ -188,6 +298,14 @@ begin
                                command_next <= COMMAND_SET_CHAR;
                                command_data_next <= x"ffffff" & x"0a"; -- newline
 
+                       when S_READ_RESULT_0 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"ff0000" & x"3e"; -- '>'
+                       when S_READ_RESULT_1 =>
+                               command_next <= COMMAND_SET_CHAR;
+                               command_data_next <= x"ffffff" & x"20"; -- ' '
+                       when S_READ_RESULT_2 => null;
+
                        when S_COUNTUP =>
                                d_get_next <= '1';
                                d_spalte_next <= std_logic_vector(unsigned(d_spalte_int) + 1);