display: ergebnis mit '> ' prefix
[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_new_bs : in std_logic;
17                 d_zeile : out hzeile;
18                 d_spalte : out hspalte;
19                 d_get : out std_logic;
20                 d_done : in std_logic;
21                 d_char : in hbyte;
22                 -- VGA
23                 command : out std_logic_vector(7 downto 0);
24                 command_data : out std_logic_vector(31 downto 0);
25                 free : in std_logic
26         );
27 end entity display;
28
29 architecture beh of display is
30         type DISPLAY_STATE is (SIDLE, S_NEW_BS, S_BACK, S_BLANK, S_NEW_RESULT,
31                 S_ZEILEUP, S_NEW_INPUT, S_COUNTUP, S_GETCH, S_CR1, S_NL1, S_PUTCH1,
32                 S_PUTCH2, S_WAIT, S_NOP1, S_READ_RESULT_0, S_READ_RESULT_1,
33                 S_READ_RESULT_2, S_INIT, S_PS1_0, S_PS1_1, S_PS1_2, S_PS1_3, S_PS1_4,
34                 S_PS1_5);
35         signal state_int, state_next : DISPLAY_STATE;
36         signal d_zeile_int, d_zeile_next : hzeile;
37         signal d_spalte_int, d_spalte_next : hspalte;
38         signal d_get_int, d_get_next : std_logic;
39         signal command_int, command_next : std_logic_vector(7 downto 0);
40         signal command_data_int, command_data_next : std_logic_vector(31 downto 0);
41         signal istate_next, istate_int : signed(4 downto 0);
42 begin
43         d_zeile <= d_zeile_int;
44         d_spalte <= d_spalte_int;
45         d_get <= d_get_int;
46         command <= command_int;
47         command_data <= command_data_int;
48
49         process(sys_clk, sys_res_n)
50         begin
51                 if sys_res_n = '0' then
52                         -- internal
53                         state_int <= S_INIT;
54                         istate_int <= (others => '0');
55                         -- out
56                         d_zeile_int <= (others => '0');
57                         d_spalte_int <= (others => '0');
58                         d_get_int <= '0';
59                         command_int <= COMMAND_NOP;
60                         command_data_int <= (others => '0');
61                 elsif rising_edge(sys_clk) then
62                         -- internal
63                         state_int <= state_next;
64                         istate_int <= istate_next;
65                         -- out
66                         d_zeile_int <= d_zeile_next;
67                         d_spalte_int <= d_spalte_next;
68                         d_get_int <= d_get_next;
69                         command_int <= command_next;
70                         command_data_int <= command_data_next;
71                 end if;
72         end process;
73
74         -- next state
75         process(state_int, d_new_result, d_new_eingabe, d_new_bs, d_done, free,
76                 d_spalte_int, d_char, istate_int)
77         begin
78                 state_next <= state_int;
79                 istate_next <= istate_int;
80
81                 case state_int is
82                         when S_INIT =>
83                                 state_next <= S_PS1_0;
84
85                         when S_PS1_0 =>
86                                 istate_next <= b"01001";
87                                 state_next <= S_WAIT;
88                         when S_PS1_1 =>
89                                 istate_next <= b"01010";
90                                 state_next <= S_WAIT;
91                         when S_PS1_2 =>
92                                 istate_next <= b"01011";
93                                 state_next <= S_WAIT;
94                         when S_PS1_3 =>
95                                 istate_next <= b"01100";
96                                 state_next <= S_WAIT;
97                         when S_PS1_4 =>
98                                 istate_next <= b"01101";
99                                 state_next <= S_WAIT;
100                         when S_PS1_5 =>
101                                 istate_next <= b"00111";
102                                 state_next <= S_WAIT;
103
104                         when SIDLE =>
105                                 istate_next <= b"00111"; -- default: immer wieder ins SIDLE;
106                                 if d_new_bs = '1' then
107                                         state_next <= S_NEW_BS;
108                                 elsif d_new_eingabe = '1' then
109                                         state_next <= S_NEW_INPUT;
110                                 end if;
111                                 if d_new_result = '1' then
112                                         state_next <= S_NEW_RESULT;
113                                 end if;
114
115                         when S_NEW_RESULT =>
116                                 state_next <= S_ZEILEUP;
117                         when S_NEW_INPUT =>
118                                 state_next <= S_COUNTUP;
119
120                         when S_NEW_BS =>
121                                 state_next <= S_BACK;
122                         when S_BACK =>
123                                 if free = '0' then
124                                         state_next <= S_WAIT;
125                                         case istate_int is
126                                                 when b"00111" => istate_next <= b"00001"; -- => danach S_BLANK und wieder hierher
127                                                 when others => istate_next <= b"00111"; -- => danach SIDLE
128                                         end case;
129                                 end if;
130                         when S_BLANK =>
131                                 if free = '0' then
132                                         state_next <= S_WAIT;
133                                         istate_next <= b"00010"; -- => danach S_BACK
134                                 end if;
135
136                         when S_ZEILEUP =>
137                                 case istate_int is
138                                         when b"00011" =>
139                                                 state_next <= S_WAIT;
140                                                 istate_next <= b"01000"; -- => danach S_PS1
141                                         when others => state_next <= S_CR1;
142                                 end case;
143
144                         when S_CR1 =>
145                                 if free = '0' then
146                                         state_next <= S_WAIT;
147                                         case istate_int is
148                                                 when b"00110" => istate_next <= b"00101"; -- => danach S_NL1, S_ZEILEUP, S_PS1, SIDLE
149                                                 when others => istate_next <= b"00000"; -- => danach S_NL1 und S_COUNTUP
150                                         end case;
151                                 end if;
152                         when S_NL1 =>
153                                 if free = '0' then
154                                         state_next <= S_WAIT;
155                                         case istate_int is
156                                                 when b"00101" => istate_next <= b"00011"; -- => danach S_ZEILEUP, PS1
157                                                 when others => istate_next <= b"10000"; -- => danach S_READ_RESULT_0
158                                         end case;
159                                 end if;
160
161                         when S_READ_RESULT_0 =>
162                                 istate_next <= b"10001";
163                                 state_next <= S_WAIT;
164                         when S_READ_RESULT_1 =>
165                                 istate_next <= b"10010";
166                                 state_next <= S_WAIT;
167                         when S_READ_RESULT_2 =>
168                                 if unsigned(d_spalte_int) /= 70 then
169                                         state_next <= S_COUNTUP;
170                                         istate_next <= b"10010"; -- => wieder nach S_READ_RESULT_2
171                                 else
172                                         state_next <= S_WAIT;
173                                         istate_next <= b"00110"; -- => danach S_CR1 und d_spalte_next clearen und d_zeile_next inkrementieren
174                                 end if;
175
176                         when S_COUNTUP =>
177                                 state_next <= S_GETCH;
178                         when S_GETCH =>
179                                 if free = '1' and d_done = '1' and d_new_result = '0' and d_new_eingabe = '0' then
180                                         state_next <= S_PUTCH1;
181                                 end if;
182                         when S_PUTCH1 =>
183                                 state_next <= S_PUTCH2;
184                         when S_PUTCH2 =>
185                                 if free = '0' or (free = '1' and d_char = x"00") then
186                                         state_next <= S_WAIT;
187                                 end if;
188                         when S_WAIT =>
189                                 if free = '1' and d_done = '0' then
190                                         state_next <= S_NOP1;
191                                 end if;
192                         when S_NOP1 =>
193                                 if free = '1' then
194                                         case istate_int is
195                                                 when b"00000" => state_next <= S_NL1;
196                                                 when b"00001" => state_next <= S_BLANK;
197                                                 when b"00010" => state_next <= S_BACK;
198                                                 when b"00011" => state_next <= S_ZEILEUP;
199                                                 when b"00110" => state_next <= S_CR1;
200                                                 when b"00101" => state_next <= S_NL1;
201
202                                                 when b"10000" => state_next <= S_READ_RESULT_0;
203                                                 when b"10001" => state_next <= S_READ_RESULT_1;
204                                                 when b"10010" => state_next <= S_READ_RESULT_2;
205
206                                                 when b"01000" => state_next <= S_PS1_0;
207                                                 when b"01001" => state_next <= S_PS1_1;
208                                                 when b"01010" => state_next <= S_PS1_2;
209                                                 when b"01011" => state_next <= S_PS1_3;
210                                                 when b"01100" => state_next <= S_PS1_4;
211                                                 when b"01101" => state_next <= S_PS1_5;
212                                                 when others => state_next <= SIDLE;
213                                         end case;
214                                 end if;
215                 end case;
216         end process;
217
218         -- out
219         process(state_int, d_zeile_int, d_spalte_int, d_get_int, command_int,
220                 command_data_int, d_char)
221         begin
222                 d_zeile_next <= d_zeile_int;
223                 d_spalte_next <= d_spalte_int;
224                 d_get_next <= '0';
225                 command_next <= command_int;
226                 command_data_next <= command_data_int;
227
228                 case state_int is
229                         when S_INIT => null;
230
231                         -- TODO: coole farben
232                         when S_PS1_0 =>
233                                 command_next <= COMMAND_SET_CHAR;
234                                 command_data_next <= x"ffffff" & x"28"; -- '('
235                         when S_PS1_1 =>
236                                 command_next <= COMMAND_SET_CHAR;
237                                 -- d_zeile/2, zehnerstelle
238                                 command_data_next <= x"ffffff" & x"78"; -- 'x'
239                         when S_PS1_2 =>
240                                 command_next <= COMMAND_SET_CHAR;
241                                 -- d_zeile/2, einerstelle
242                                 command_data_next <= x"ffffff" & x"79"; -- 'y'
243                         when S_PS1_3 =>
244                                 command_next <= COMMAND_SET_CHAR;
245                                 command_data_next <= x"ffffff" & x"29"; -- ')'
246                         when S_PS1_4 =>
247                                 command_next <= COMMAND_SET_CHAR;
248                                 command_data_next <= x"ffffff" & x"24"; -- '$'
249                         when S_PS1_5 =>
250                                 command_next <= COMMAND_SET_CHAR;
251                                 command_data_next <= x"ffffff" & x"20"; -- ' '
252
253                         when SIDLE => null;
254                         when S_NEW_RESULT => null;
255                         when S_NEW_INPUT => null;
256
257                         when S_NEW_BS =>
258                                 -- underflow check schon im history modul
259                                 d_spalte_next <= std_logic_vector(unsigned(d_spalte_int) - 1);
260                         when S_BACK =>
261                                 -- einen schritt zurueck, +6 wegen $PS1
262                                 command_next <= COMMAND_SET_CURSOR_COLUMN;
263                                 command_data_next <= x"ffffff" & '0' & std_logic_vector(unsigned(d_spalte_int) + 6);
264                         when S_BLANK =>
265                                 command_next <= COMMAND_SET_CHAR;
266                                 command_data_next <= x"ffffff" & x"20"; -- white space
267
268                         when S_ZEILEUP =>
269                                 d_spalte_next <= (others => '0');
270                                 case d_zeile_int is
271                                         -- 49 * 2 + 1
272                                         when "1100010" => d_zeile_next <= (others => '0');
273                                         when others => d_zeile_next <= std_logic_vector(unsigned(d_zeile_int) + 1);
274                                 end case;
275
276                         when S_CR1 =>
277                                 command_next <= COMMAND_SET_CHAR;
278                                 command_data_next <= x"ffffff" & x"0d"; -- carrige return
279                         when S_NL1 =>
280                                 command_next <= COMMAND_SET_CHAR;
281                                 command_data_next <= x"ffffff" & x"0a"; -- newline
282
283                         -- TODO: coole farben
284                         when S_READ_RESULT_0 =>
285                                 command_next <= COMMAND_SET_CHAR;
286                                 command_data_next <= x"ffffff" & x"3e"; -- '>'
287                         when S_READ_RESULT_1 =>
288                                 command_next <= COMMAND_SET_CHAR;
289                                 command_data_next <= x"ffffff" & x"20"; -- ' '
290                         when S_READ_RESULT_2 => null;
291
292                         when S_COUNTUP =>
293                                 d_get_next <= '1';
294                                 d_spalte_next <= std_logic_vector(unsigned(d_spalte_int) + 1);
295                         when S_GETCH =>
296                                 d_get_next <= '1';
297                         when S_PUTCH1 =>
298                                 if d_char /= x"00" then
299                                         command_next <= COMMAND_SET_CHAR;
300                                         command_data_next <= x"ffffff" & std_logic_vector(d_char);
301                                 end if;
302                         when S_PUTCH2 => null;
303                         when S_WAIT | S_NOP1 =>
304                                 command_next <= COMMAND_NOP;
305                                 command_data_next <= x"00000000";
306                 end case;
307         end process;
308 end architecture beh;