-
Notifications
You must be signed in to change notification settings - Fork 3
/
vio0800.vhd
375 lines (331 loc) · 9.48 KB
/
vio0800.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 11:37:53 05/19/2019
-- Design Name:
-- Module Name: sio0800 - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
use work.tms0800_package.all;
entity vio0800 is
Port ( reset : in STD_LOGIC;
clk : in STD_LOGIC;
char : in STD_LOGIC_VECTOR (7 downto 0);
char_sent : out STD_LOGIC;
busy_in: in STD_LOGIC;
busy_out: out STD_LOGIC;
we : out STD_LOGIC;
din: in STD_LOGIC_VECTOR(7 downto 0);
dout: out STD_LOGIC_VECTOR(7 downto 0);
x: out STD_LOGIC_VECTOR(7 downto 0);
y: out STD_LOGIC_VECTOR(7 downto 0));
end vio0800;
architecture Behavioral of vio0800 is
constant bst_none: std_logic_vector(1 downto 0) := "00";
constant bst_read: std_logic_vector(1 downto 0) := "10";
constant bst_write: std_logic_vector(1 downto 0) := "11";
---- internal registers
signal row, col: std_logic_vector(7 downto 0);
signal busstate: std_logic_vector(1 downto 0);
--signal u_pc, u_ra, u_next: std_logic_vector(7 downto 0);
--
---- conditions
--signal u_condition: std_logic;
--signal row0, row49: std_logic;
--signal col0, col79: std_logic;
--signal char0, charcontrol, charcr, charlf, charcls, charhome: std_logic;
--
type state is (st_reset, --0
st_readytostart, --1
st_memread0, --2
st_memread1, --2
st_memwrite0, --3
st_memwrite1, --3
st_print, --4
st_print_incx, --5
st_print_incy, --6
st_next_row, --7
st_next_col, --8
st_cr,
st_lf,--9
st_done, --A
st_donehold --B
);
signal state_current, state_next, state_return: state;
begin
-- direct output signals
busy_out <= busstate(1);
we <= busstate(0);
x <= col;
y <= row when (busstate(0) = '0') else std_logic_vector(unsigned(row) + 1); -- always read from the row below
-- FSM --
drive: process(reset, clk, state_next)
begin
if (reset = '1') then
state_current <= st_reset;
else
if (rising_edge(clk)) then
state_current <= state_next;
end if;
end if;
end process;
execute: process(clk, state_current)
begin
if (rising_edge(clk)) then
case state_current is
when st_reset =>
busstate <= bst_none;
char_sent <= '1';
when st_readytostart =>
busstate <= bst_none;
char_sent <= '1';
when st_print =>
busstate <= bst_none;
char_sent <= '0'; -- indicates wait for the client
dout <= char; -- will write char to memory
when st_next_row =>
busstate <= bst_none;
char_sent <= '0'; -- indicates wait for the client
row <= std_logic_vector(unsigned(row) + 1);
when st_next_col =>
busstate <= bst_none;
char_sent <= '0'; -- indicates wait for the client
col <= std_logic_vector(unsigned(col) + 1);
row <= X"00";
when st_cr =>
busstate <= bst_none;
char_sent <= '0'; -- indicates wait for the client
row <= X"00";
when st_lf =>
busstate <= bst_none;
char_sent <= '0'; -- indicates wait for the client
col <= std_logic_vector(unsigned(col) + 1);
when st_memread0 =>
busstate <= bst_read;
char_sent <= '0'; -- indicates wait for the client
when st_memread1 =>
busstate <= bst_read;
char_sent <= '0'; -- indicates wait for the client
dout <= din;
when st_memwrite0 =>
busstate <= bst_write;
char_sent <= '0'; -- indicates wait for the client
dout <= din;
when st_memwrite1 =>
busstate <= bst_write;
char_sent <= '0'; -- indicates wait for the client
when others =>
busstate <= bst_none;
char_sent <= '1'; -- client can continue
end case;
end if;
end process;
sequence: process(state_current, char, row, col)
begin
case state_current is
when st_reset =>
state_next <= st_readytostart;
when st_readytostart =>
if (char(7 downto 5) = "000") then
case char is
when char_NULL =>
state_next <= st_print;
when char_CLEAR =>
state_next <= st_print; -- TODO: implement clear screen
when char_HOME =>
state_next <= st_print; -- TODO: implement home
when char_CR =>
state_next <= st_cr;
when char_LF =>
state_next <= st_lf;
when others =>
state_next <= st_print;
end case;
else
state_next <= st_print;
end if;
when st_print =>
if (busy_in = '1') then
state_next <= st_print; -- hold in loop until bus clears
else
state_next <= st_memwrite0;
end if;
when st_next_row =>
if (unsigned(row) >= 79) then
state_next <= st_print_incy;
else
state_next <= st_done;
end if;
when st_next_col =>
if (unsigned(col) >= 50) then
state_next <= st_reset; -- TODO!!
else
state_next <= st_done;
end if;
when st_cr =>
state_next <= st_done;
when st_lf =>
if (unsigned(col) >= 50) then
state_next <= st_reset; -- TODO!!
else
state_next <= st_done;
end if;
when st_memread0 =>
state_next <= st_memread1;
when st_memread1 =>
state_next <= st_done; -- TODO
when st_memwrite0 =>
state_next <= st_memwrite1;
when st_memwrite1 =>
state_next <= st_done; -- TODO?
when st_done =>
state_next <= st_donehold;
when st_donehold =>
if (char = char_NULL) then
state_next <= st_readytostart;
else
state_next <= st_donehold;
end if;
when others =>
state_next <= st_done;
end case;
end process;
--
--u_instruction <= u_code(to_integer(unsigned(u_pc(5 downto 0))));
--
---- various conditions
--row0 <= '1' when (unsigned(row) = 0) else '0';
--row49 <= '1' when (unsigned(row) = 49) else '0';
--col0 <= '1' when (unsigned(col) = 0) else '0';
--col79 <= '1' when (unsigned(col) = 79) else '0';
--char0 <= '1' when (char = char_NULL) else '0';
--charcontrol <= '1' when (char(7 downto 5) = "000") else '0';
--charcr <= '1' when (char = char_CR) else '0';
--charlf <= '1' when (char = char_LF) else '0';
--charcls <= '1' when (char = char_CLEAR) else '0';
--charhome <= '1' when (char = char_HOME) else '0';
--
---- select condition code
--with u_if select
-- u_condition <= '1' when cond_true, -- 0
-- char0 when cond_char0,
-- charcontrol when cond_charcontrol,
-- busy_in when cond_busyin,
-- row0 when cond_row0,
-- row49 when cond_row49,
-- col0 when cond_col0,
-- col79 when cond_col79,
-- charcr when cond_charcr,
-- charlf when cond_charlf,
-- charhome when cond_charhome,
-- charcls when cond_charcls,
-- '0' when cond_12, -- not used
-- '0' when cond_13, -- not used
-- '0' when cond_14, -- not used
-- '0' when cond_false; -- 15
--
---- select then or else part
--u_next <= u_then when (u_condition = '1') else u_else;
--
---- update microcode program counter
--update_upc: process(clk, reset, u_next)
--begin
-- if (reset = '1') then
-- -- start execution at location 0
-- u_pc <= X"00";
-- u_ra <= X"00";
-- else
-- if (rising_edge(clk)) then
-- case u_next is
-- -- if condition(0) = '1' then X"00000" (default) will cause simple u_pc advance
-- when upc_next =>
-- u_pc <= std_logic_vector(unsigned(u_pc) + 1);
-- -- used to repeat same microinstruction until condition turns true
-- when upc_repeat =>
-- u_pc <= u_pc;
-- -- not used
-- --when upc_fork =>
-- -- u_pc <= '1' & instruction;
-- -- return from "1 level subroutine"
-- when upc_return =>
-- u_pc <= u_ra;
-- -- any other value is a jump to that microinstruction location, save return address for "1 level stack"
-- when others =>
-- u_pc <= u_next;
-- u_ra <= std_logic_vector(unsigned(u_pc) + 1);
-- end case;
-- end if;
-- end if;
--end process;
--
---- update dout
--update_dout: process(clk)
--begin
-- if (rising_edge(clk)) then
-- case u_dout is
-- when dout_constant =>
-- dout <= u_constant;
-- when dout_din =>
-- dout <= din;
-- when dout_char =>
-- dout <= char;
-- when others =>
-- null;
-- end case;
-- end if;
--end process;
--
---- update row
--update_row: process(clk)
--begin
-- if (rising_edge(clk)) then
-- case u_row is
-- when row_constant =>
-- row <= u_constant;
-- when row_inc =>
-- row <= std_logic_vector(unsigned(row) + 1);
-- when row_dec =>
-- row <= std_logic_vector(unsigned(row) + 1);
-- when others =>
-- null;
-- end case;
-- end if;
--end process;
--
---- update row
--update_col: process(clk)
--begin
-- if (rising_edge(clk)) then
-- case u_row is
-- when row_constant =>
-- col <= u_constant;
-- when row_inc =>
-- col <= std_logic_vector(unsigned(col) + 1);
-- when row_dec =>
-- col <= std_logic_vector(unsigned(col) + 1);
-- when others =>
-- null;
-- end case;
-- end if;
--end process;
end Behavioral;