1 -------------------------------------------------------------------------
\r
3 -- Filename: console_sm_beh.vhd
\r
6 -- Short Description:
\r
7 -- ==================
\r
8 -- Console mode finite state machine behavioral implementation
\r
10 -------------------------------------------------------------------------
\r
13 use ieee.std_logic_1164.all;
\r
14 use ieee.numeric_std.all;
\r
15 use work.textmode_vga_pkg.all;
\r
16 use work.textmode_vga_platform_dependent_pkg.all;
\r
18 architecture beh of console_sm is
\r
21 STATE_IDLE, STATE_ACK_UNKNOWN, STATE_WAIT_REQ_RELEASE, STATE_NEW_LINE_SIMPLE,
\r
22 STATE_NEW_LINE_SCROLL, STATE_CARRIAGE_RETURN, STATE_SET_CHAR,
\r
23 STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SIMPLE,
\r
24 STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SCROLL,
\r
25 STATE_SET_BACKGROUND, STATE_SCROLL_NEXT, STATE_SCROLL_TOP,
\r
26 STATE_SCROLL_CLEAR_LINE, STATE_SCROLL_CLEAR_LINE_LOOP,
\r
27 STATE_SCROLL_CLEAR_LINE_FINISH, STATE_SET_CURSOR_STATE,
\r
28 STATE_SET_CURSOR_COLOR, STATE_SET_CURSOR_COLUMN,
\r
29 STATE_SET_CURSOR_LINE, STATE_SET_CURSOR_STATE_OFF,
\r
30 STATE_SET_CURSOR_STATE_ON, STATE_SET_CURSOR_STATE_BLINK
\r
33 signal state, state_next : STATE_TYPE;
\r
34 signal line_int : integer range 0 to LINE_COUNT - 1;
\r
35 signal line_next : integer range 0 to LINE_COUNT;
\r
36 signal column_int : integer range 0 to COLUMN_COUNT - 1;
\r
37 signal column_save, column_save_next : integer range 0 to COLUMN_COUNT - 1;
\r
38 signal column_next : integer range 0 to COLUMN_COUNT;
\r
39 signal scroll_int : integer range 0 to LINE_COUNT - 1;
\r
40 signal scroll_next : integer range 0 to LINE_COUNT;
\r
41 signal ack_next : std_logic;
\r
42 signal background_color_int, background_color_next : std_logic_vector(RED_BITS + GREEN_BITS + BLUE_BITS - 1 downto 0);
\r
43 signal cursor_color_int, cursor_color_next : std_logic_vector(RED_BITS + GREEN_BITS + BLUE_BITS - 1 downto 0);
\r
44 signal cursor_state_int, cursor_state_next : CURSOR_STATE_TYPE;
\r
46 column_address <= std_logic_vector(to_unsigned(column_int, log2c(COLUMN_COUNT)));
\r
47 row_address <= std_logic_vector(to_unsigned(line_int, log2c(LINE_COUNT)));
\r
48 scroll_address <= std_logic_vector(to_unsigned(scroll_int, log2c(LINE_COUNT)));
\r
49 background_color <= background_color_int;
\r
50 cursor_color <= cursor_color_int;
\r
51 cursor_state <= cursor_state_int;
\r
53 process(state, line_int, column_int, scroll_int, command, command_data, command_req)
\r
55 state_next <= state;
\r
59 if command_req = '1' then
\r
60 if command = COMMAND_SET_CHAR then
\r
61 if command_data(CHAR_SIZE - 1 downto 0) = CHAR_NEW_LINE then
\r
62 if line_int < LINE_COUNT - 1 then
\r
63 state_next <= STATE_NEW_LINE_SIMPLE;
\r
65 state_next <= STATE_NEW_LINE_SCROLL;
\r
67 elsif command_data(CHAR_SIZE - 1 downto 0) = CHAR_CARRIAGE_RETURN then
\r
68 state_next <= STATE_CARRIAGE_RETURN;
\r
70 if column_int < COLUMN_COUNT - 1 then
\r
71 state_next <= STATE_SET_CHAR;
\r
73 if line_int < LINE_COUNT - 1 then
\r
74 state_next <= STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SIMPLE;
\r
76 state_next <= STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SCROLL;
\r
80 elsif command = COMMAND_SET_BACKGROUND then
\r
81 state_next <= STATE_SET_BACKGROUND;
\r
82 elsif command = COMMAND_SET_CURSOR_STATE then
\r
83 state_next <= STATE_SET_CURSOR_STATE;
\r
84 elsif command = COMMAND_SET_CURSOR_COLOR then
\r
85 state_next <= STATE_SET_CURSOR_COLOR;
\r
86 elsif command = COMMAND_SET_CURSOR_COLUMN then
\r
87 state_next <= STATE_SET_CURSOR_COLUMN;
\r
88 elsif command = COMMAND_SET_CURSOR_LINE then
\r
89 state_next <= STATE_SET_CURSOR_LINE;
\r
91 state_next <= STATE_ACK_UNKNOWN;
\r
94 when STATE_ACK_UNKNOWN =>
\r
95 state_next <= STATE_WAIT_REQ_RELEASE;
\r
96 when STATE_NEW_LINE_SIMPLE =>
\r
97 state_next <= STATE_WAIT_REQ_RELEASE;
\r
98 when STATE_NEW_LINE_SCROLL =>
\r
99 if scroll_int < LINE_COUNT - 1 then
\r
100 state_next <= STATE_SCROLL_NEXT;
\r
102 state_next <= STATE_SCROLL_TOP;
\r
104 when STATE_CARRIAGE_RETURN =>
\r
105 state_next <= STATE_WAIT_REQ_RELEASE;
\r
106 when STATE_SET_CHAR =>
\r
107 state_next <= STATE_WAIT_REQ_RELEASE;
\r
108 when STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SIMPLE =>
\r
109 state_next <= STATE_WAIT_REQ_RELEASE;
\r
110 when STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SCROLL =>
\r
111 if scroll_int < LINE_COUNT - 1 then
\r
112 state_next <= STATE_SCROLL_NEXT;
\r
114 state_next <= STATE_SCROLL_TOP;
\r
116 when STATE_SCROLL_NEXT =>
\r
117 state_next <= STATE_SCROLL_CLEAR_LINE;
\r
118 when STATE_SCROLL_TOP =>
\r
119 state_next <= STATE_SCROLL_CLEAR_LINE;
\r
120 when STATE_SCROLL_CLEAR_LINE =>
\r
121 state_next <= STATE_SCROLL_CLEAR_LINE_LOOP;
\r
122 when STATE_SCROLL_CLEAR_LINE_LOOP =>
\r
123 if column_int = COLUMN_COUNT - 2 then
\r
124 state_next <= STATE_SCROLL_CLEAR_LINE_FINISH;
\r
126 when STATE_SCROLL_CLEAR_LINE_FINISH =>
\r
127 state_next <= STATE_WAIT_REQ_RELEASE;
\r
128 when STATE_WAIT_REQ_RELEASE =>
\r
129 if command_req = '0' then
\r
130 state_next <= STATE_IDLE;
\r
132 when STATE_SET_BACKGROUND =>
\r
133 state_next <= STATE_WAIT_REQ_RELEASE;
\r
134 when STATE_SET_CURSOR_STATE =>
\r
135 if command_data(1 downto 0) = "00" then
\r
136 state_next <= STATE_SET_CURSOR_STATE_OFF;
\r
137 elsif command_data(1 downto 0) = "01" then
\r
138 state_next <= STATE_SET_CURSOR_STATE_ON;
\r
140 state_next <= STATE_SET_CURSOR_STATE_BLINK;
\r
142 when STATE_SET_CURSOR_STATE_OFF =>
\r
143 state_next <= STATE_WAIT_REQ_RELEASE;
\r
144 when STATE_SET_CURSOR_STATE_ON =>
\r
145 state_next <= STATE_WAIT_REQ_RELEASE;
\r
146 when STATE_SET_CURSOR_STATE_BLINK =>
\r
147 state_next <= STATE_WAIT_REQ_RELEASE;
\r
148 when STATE_SET_CURSOR_COLOR =>
\r
149 state_next <= STATE_WAIT_REQ_RELEASE;
\r
150 when STATE_SET_CURSOR_COLUMN =>
\r
151 state_next <= STATE_WAIT_REQ_RELEASE;
\r
152 when STATE_SET_CURSOR_LINE =>
\r
153 state_next <= STATE_WAIT_REQ_RELEASE;
\r
157 process(state, line_int, column_int, scroll_int, column_save, background_color_int, cursor_color_int, cursor_state_int, command_data)
\r
159 line_next <= line_int;
\r
160 column_next <= column_int;
\r
161 scroll_next <= scroll_int;
\r
162 column_save_next <= column_save;
\r
163 data <= std_logic_vector(to_unsigned(0, RED_BITS + GREEN_BITS + BLUE_BITS + CHAR_SIZE));
\r
166 background_color_next <= background_color_int;
\r
167 cursor_color_next <= cursor_color_int;
\r
168 cursor_state_next <= cursor_state_int;
\r
173 when STATE_ACK_UNKNOWN =>
\r
175 when STATE_NEW_LINE_SIMPLE =>
\r
176 line_next <= line_int + 1;
\r
178 when STATE_NEW_LINE_SCROLL =>
\r
180 when STATE_CARRIAGE_RETURN =>
\r
183 when STATE_SET_CHAR =>
\r
184 data <= command_data(CHAR_SIZE + 3 * COLOR_SIZE - 1 downto CHAR_SIZE + 3 * COLOR_SIZE - RED_BITS) &
\r
185 command_data(CHAR_SIZE + 2 * COLOR_SIZE - 1 downto CHAR_SIZE + 2 * COLOR_SIZE - GREEN_BITS) &
\r
186 command_data(CHAR_SIZE + COLOR_SIZE - 1 downto CHAR_SIZE + COLOR_SIZE - BLUE_BITS) &
\r
187 command_data(CHAR_SIZE - 1 downto 0);
\r
189 column_next <= column_int + 1;
\r
191 when STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SIMPLE =>
\r
192 data <= command_data(CHAR_SIZE + 3 * COLOR_SIZE - 1 downto CHAR_SIZE + 3 * COLOR_SIZE - RED_BITS) &
\r
193 command_data(CHAR_SIZE + 2 * COLOR_SIZE - 1 downto CHAR_SIZE + 2 * COLOR_SIZE - GREEN_BITS) &
\r
194 command_data(CHAR_SIZE + COLOR_SIZE - 1 downto CHAR_SIZE + COLOR_SIZE - BLUE_BITS) &
\r
195 command_data(CHAR_SIZE - 1 downto 0);
\r
197 line_next <= line_int + 1;
\r
200 when STATE_SET_CHAR_NEW_LINE_AND_CARRIAGE_RETURN_SCROLL =>
\r
201 data <= command_data(CHAR_SIZE + 3 * COLOR_SIZE - 1 downto CHAR_SIZE + 3 * COLOR_SIZE - RED_BITS) &
\r
202 command_data(CHAR_SIZE + 2 * COLOR_SIZE - 1 downto CHAR_SIZE + 2 * COLOR_SIZE - GREEN_BITS) &
\r
203 command_data(CHAR_SIZE + COLOR_SIZE - 1 downto CHAR_SIZE + COLOR_SIZE - BLUE_BITS) &
\r
204 command_data(CHAR_SIZE - 1 downto 0);
\r
207 when STATE_SCROLL_NEXT =>
\r
208 scroll_next <= scroll_int + 1;
\r
209 when STATE_SCROLL_TOP =>
\r
211 when STATE_SCROLL_CLEAR_LINE =>
\r
212 column_save_next <= column_int;
\r
214 when STATE_SCROLL_CLEAR_LINE_LOOP =>
\r
215 data <= COLOR_BLACK(3 * COLOR_SIZE - 1 downto 3 * COLOR_SIZE - RED_BITS) &
\r
216 COLOR_BLACK(2 * COLOR_SIZE - 1 downto 2 * COLOR_SIZE - GREEN_BITS) &
\r
217 COLOR_BLACK(COLOR_SIZE - 1 downto COLOR_SIZE - BLUE_BITS) &
\r
220 column_next <= column_int + 1;
\r
221 when STATE_SCROLL_CLEAR_LINE_FINISH =>
\r
222 data <= COLOR_BLACK(3 * COLOR_SIZE - 1 downto 3 * COLOR_SIZE - RED_BITS) &
\r
223 COLOR_BLACK(2 * COLOR_SIZE - 1 downto 2 * COLOR_SIZE - GREEN_BITS) &
\r
224 COLOR_BLACK(COLOR_SIZE - 1 downto COLOR_SIZE - BLUE_BITS) &
\r
227 column_next <= column_save;
\r
229 when STATE_WAIT_REQ_RELEASE =>
\r
231 when STATE_SET_BACKGROUND =>
\r
232 background_color_next <=
\r
233 command_data(3 * COLOR_SIZE - 1 downto 3 * COLOR_SIZE - RED_BITS) &
\r
234 command_data(2 * COLOR_SIZE - 1 downto 2 * COLOR_SIZE - GREEN_BITS) &
\r
235 command_data(COLOR_SIZE - 1 downto COLOR_SIZE - BLUE_BITS);
\r
237 when STATE_SET_CURSOR_STATE =>
\r
239 when STATE_SET_CURSOR_STATE_OFF =>
\r
240 cursor_state_next <= CURSOR_OFF;
\r
242 when STATE_SET_CURSOR_STATE_ON =>
\r
243 cursor_state_next <= CURSOR_ON;
\r
245 when STATE_SET_CURSOR_STATE_BLINK =>
\r
246 cursor_state_next <= CURSOR_BLINK;
\r
248 when STATE_SET_CURSOR_COLOR =>
\r
249 cursor_color_next <=
\r
250 command_data(3 * COLOR_SIZE - 1 downto 3 * COLOR_SIZE - RED_BITS) &
\r
251 command_data(2 * COLOR_SIZE - 1 downto 2 * COLOR_SIZE - GREEN_BITS) &
\r
252 command_data(COLOR_SIZE - 1 downto COLOR_SIZE - BLUE_BITS);
\r
254 when STATE_SET_CURSOR_COLUMN =>
\r
255 column_next <= to_integer(unsigned(command_data(log2c(COLUMN_COUNT) - 1 downto 0)));
\r
257 when STATE_SET_CURSOR_LINE =>
\r
258 line_next <= to_integer(unsigned(command_data(log2c(LINE_COUNT) - 1 downto 0)));
\r
263 process(vga_clk, vga_res_n)
\r
265 if vga_res_n = '0' then
\r
266 state <= STATE_IDLE;
\r
272 background_color_int <= COLOR_BLACK(3 * COLOR_SIZE - 1 downto 3 * COLOR_SIZE - RED_BITS) &
\r
273 COLOR_BLACK(2 * COLOR_SIZE - 1 downto 2 * COLOR_SIZE - GREEN_BITS) &
\r
274 COLOR_BLACK(COLOR_SIZE - 1 downto COLOR_SIZE - BLUE_BITS);
\r
275 cursor_color_int <= COLOR_WHITE(3 * COLOR_SIZE - 1 downto 3 * COLOR_SIZE - RED_BITS) &
\r
276 COLOR_WHITE(2 * COLOR_SIZE - 1 downto 2 * COLOR_SIZE - GREEN_BITS) &
\r
277 COLOR_WHITE(COLOR_SIZE - 1 downto COLOR_SIZE - BLUE_BITS);
\r
278 cursor_state_int <= CURSOR_BLINK;
\r
279 elsif rising_edge(vga_clk) then
\r
280 state <= state_next;
\r
281 line_int <= line_next;
\r
282 column_int <= column_next;
\r
283 scroll_int <= scroll_next;
\r
284 column_save <= column_save_next;
\r
286 background_color_int <= background_color_next;
\r
287 cursor_color_int <= cursor_color_next;
\r
288 cursor_state_int <= cursor_state_next;
\r
291 end architecture beh;
\r