display: arbeitet endlich wie gewuenscht
[hwmod.git] / src / display.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use work.gen_pkg.all;
5 use work.textmode_vga_component_pkg.all;
6 use work.textmode_vga_pkg.all;
7 use work.textmode_vga_platform_dependent_pkg.all;
8
9 entity display is
10         port (
11                 sys_clk : in std_logic;
12                 sys_res_n : in std_logic;
13                 -- History
14                 d_new_eingabe : in std_logic;
15                 d_new_result : in std_logic;
16                 d_zeile : out hzeile;
17                 d_spalte : out hspalte;
18                 d_get : out std_logic;
19                 d_done : in std_logic;
20                 d_char : in hbyte;
21                 -- VGA
22                 command : out std_logic_vector(7 downto 0);
23                 command_data : out std_logic_vector(31 downto 0);
24                 free : in std_logic
25         );
26 end entity display;
27
28 architecture beh of display is
29         type DISPLAY_STATE is (S_INIT, SIDLE, S_NEW_RESULT, S_NEW_INPUT, S_COUNTUP, S_GETCH,
30         S_CR1, S_NL1, S_PUTCH1, S_PUTCH2, S_WAIT, S_NOP1);
31         signal state_int, state_next : DISPLAY_STATE;
32         signal d_zeile_int, d_zeile_next : hzeile;
33         signal d_spalte_int, d_spalte_next : hspalte;
34         signal d_get_int, d_get_next : std_logic;
35         signal command_int, command_next : std_logic_vector(7 downto 0);
36         signal command_data_int, command_data_next : std_logic_vector(31 downto 0);
37         signal istate_next, istate_int : signed(2 downto 0);
38 begin
39         d_zeile <= d_zeile_int;
40         d_spalte <= d_spalte_int;
41         d_get <= d_get_int;
42         command <= command_int;
43         command_data <= command_data_int;
44
45         process(sys_clk, sys_res_n)
46         begin
47                 if sys_res_n = '0' then
48                         -- internal
49                         state_int <= S_INIT;
50                         istate_int <= (others => '0');
51                         -- out
52                         d_zeile_int <= (others => '0');
53                         d_spalte_int <= (others => '0');
54                         d_get_int <= '0';
55                         command_int <= COMMAND_NOP;
56                         command_data_int <= (others => '0');
57                 elsif rising_edge(sys_clk) then
58                         -- internal
59                         state_int <= state_next;
60                         istate_int <= istate_next;
61                         -- out
62                         d_zeile_int <= d_zeile_next;
63                         d_spalte_int <= d_spalte_next;
64                         d_get_int <= d_get_next;
65                         command_int <= command_next;
66                         command_data_int <= command_data_next;
67                 end if;
68         end process;
69
70         -- next state
71         process(state_int, d_new_result, d_new_eingabe, d_done, free, d_spalte_int,
72                 d_char, istate_int)
73         begin
74                 state_next <= state_int;
75                 istate_next <= istate_int;
76
77                 case state_int is
78                         when S_INIT =>
79                                 state_next <= SIDLE;
80                         when SIDLE =>
81                                 if d_new_eingabe = '1' then
82                                         state_next <= S_NEW_INPUT;
83                                 end if;
84                                 if d_new_result = '1' then
85                                         state_next <= S_NEW_RESULT;
86                                 end if;
87                         when S_NEW_RESULT =>
88                                 state_next <= S_CR1;
89                         when S_NEW_INPUT =>
90                                 state_next <= S_COUNTUP;
91                         when S_CR1 =>
92                                 if free = '0' then
93                                         state_next <= S_WAIT;
94                                         istate_next <= b"000"; -- => danach S_NL1
95                                 end if;
96                         when S_NL1 =>
97                                 if free = '0' then
98                                         state_next <= S_WAIT;
99                                         istate_next <= b"111";
100                                 end if;
101                         when S_COUNTUP =>
102                                 state_next <= S_GETCH;
103                         when S_GETCH =>
104                                 if free = '1' and d_done = '1' and d_new_result = '0' and d_new_eingabe = '0' then
105                                         state_next <= S_PUTCH1;
106                                 end if;
107                         when S_PUTCH1 =>
108                                 state_next <= S_PUTCH2;
109                         when S_PUTCH2 =>
110                                 if free = '0' or (free = '1' and d_char = x"00") then
111                                         state_next <= S_WAIT;
112                                         istate_next <= b"111";
113                                 end if;
114                         when S_WAIT =>
115                                 if free = '1' and d_done = '0' then
116                                         state_next <= S_NOP1;
117                                 end if;
118                         when S_NOP1 =>
119                                 if free = '1' then
120                                         case istate_int is
121                                                 when b"000" => state_next <= S_NL1;
122                                                 when others => state_next <= SIDLE;
123                                         end case;
124                                 end if;
125                 end case;
126         end process;
127
128         -- out
129         process(state_int, d_zeile_int, d_spalte_int, d_get_int, command_int,
130                 command_data_int, d_char)
131         begin
132                 d_zeile_next <= d_zeile_int;
133                 d_spalte_next <= d_spalte_int;
134                 d_get_next <= '0';
135                 command_next <= command_int;
136                 command_data_next <= command_data_int;
137
138                 case state_int is
139                         when S_INIT =>
140                                 d_spalte_next <= (others => '0');
141                                 d_zeile_next <= (others => '0');
142                         when SIDLE =>
143                                 null;
144                         when S_NEW_INPUT =>
145                                 null;
146                         when S_NEW_RESULT =>
147                                 d_spalte_next <= (others => '0');
148                                 case d_zeile_int is
149                                         when "11111" => d_zeile_next <= "00000";
150                                         when others => d_zeile_next <= std_logic_vector(unsigned(d_zeile_int) + 1);
151                                 end case;
152                         when S_CR1 =>
153                                 command_next <= COMMAND_SET_CHAR;
154                                 command_data_next <= x"ffffff" & x"0d"; -- carrige return
155                         when S_NL1 =>
156                                 command_next <= COMMAND_SET_CHAR;
157                                 command_data_next <= x"ffffff" & x"0a"; -- newline
158                         when S_COUNTUP =>
159                                 d_get_next <= '1';
160                                 d_spalte_next <= std_logic_vector(unsigned(d_spalte_int) + 1);
161                         when S_GETCH =>
162                                 d_get_next <= '1';
163                         when S_PUTCH1 =>
164                                 if d_char /= x"00" then
165                                         command_next <= COMMAND_SET_CHAR;
166                                         command_data_next <= x"ffffff" & std_logic_vector(d_char);
167                                 end if;
168                         when S_PUTCH2 => null;
169                         when S_WAIT | S_NOP1 =>
170                                 command_next <= COMMAND_NOP;
171                                 command_data_next <= x"00000000";
172                 end case;
173         end process;
174 end architecture beh;