-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_drawer.vhdl
206 lines (166 loc) · 5.57 KB
/
line_drawer.vhdl
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library UNISIM;
use UNISIM.VComponents.ALL;
entity line_drawer is
port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
t_ready : in STD_LOGIC;
t_stop : in STD_LOGIC;
t_pull : out STD_LOGIC;
t_xl : in STD_LOGIC_VECTOR ( 9 downto 0);
t_xr : in STD_LOGIC_VECTOR ( 9 downto 0);
t_zl : in STD_LOGIC_VECTOR (17 downto 0);
t_dz : in STD_LOGIC_VECTOR (17 downto 0);
t_color : in STD_LOGIC_VECTOR ( 8 downto 0);
zbuffer_x_i : out STD_LOGIC_VECTOR ( 9 downto 0);
zbuffer_d_i : in STD_LOGIC_VECTOR (17 downto 0);
buffer_we : out STD_LOGIC;
buffer_x_o : out STD_LOGIC_VECTOR ( 9 downto 0);
cbuffer_d_o : out STD_LOGIC_VECTOR ( 8 downto 0);
zbuffer_d_o : out STD_LOGIC_VECTOR (17 downto 0);
stop : out STD_LOGIC);
end line_drawer;
architecture Behavioral of line_drawer is
constant STATE_WAITING : integer := 0;
constant STATE_STOP : integer := 1;
constant STATE_DRAWING : integer := 2;
constant STATE_FINISH : integer := 3;
signal state : integer;
signal x1 : signed( 9 downto 0);
signal x : signed( 9 downto 0);
signal xr : signed( 9 downto 0);
signal z : signed(17 downto 0);
signal dz : signed(17 downto 0);
signal color : STD_LOGIC_VECTOR (8 downto 0);
signal a : std_logic_vector(17 downto 0) := (others=>'0');
signal b : std_logic_vector(17 downto 0) := (others=>'0');
signal c : std_logic_vector(17 downto 0) := (others=>'0');
signal d : std_logic_vector(17 downto 0) := (others=>'0');
signal p : std_logic_vector(17 downto 0) := (others=>'0');
signal c48 : std_logic_vector(47 downto 0);
signal p48 : std_logic_vector(47 downto 0);
signal queue : std_logic;
begin
process (clk)
variable tmpx : signed(9 downto 0);
begin
if rising_edge(clk) then
if reset='1' then
state <= STATE_WAITING;
else
case state is
when STATE_WAITING =>
if t_stop='1' then
state <= STATE_STOP;
elsif t_ready='1' then
state <= STATE_DRAWING;
queue <= '0';
tmpx := signed(t_xl);
if tmpx>=-128 then x <= tmpx(9 downto 0); else x <= "1110000000"; end if;
tmpx := signed(t_xr);
if tmpx<+128 then xr <= tmpx(9 downto 0); else xr <= "0001111111"; end if;
a <= t_dz;
c <= t_zl;
b(17 downto 9) <= (others=>t_xl(9));
b( 9 downto 0) <= std_logic_vector(t_xl);
color <= t_color;
end if;
when STATE_DRAWING =>
if x>=xr then
if queue='0' then
state <= STATE_FINISH;
end if;
queue <= '0';
else
x <= x+1;
queue <= '1';
end if;
when STATE_FINISH =>
state <= STATE_WAITING;
when others =>
end case;
case state is
when STATE_DRAWING | STATE_FINISH =>
-- prepare mult and fetch previous z
d(17 downto 10) <= (others=>x(9));
d( 9 downto 0) <= std_logic_vector(x);
zbuffer_x_i <= std_logic_vector(x+128);
-- for next cycle...
x1 <= x;
-- ...compare z, and write if closer
if queue='1' and signed(zbuffer_d_i)<signed(p) then
buffer_we <= '1';
else
buffer_we <= '0';
end if;
buffer_x_o <= std_logic_vector(x1+128);
cbuffer_d_o <= color;
zbuffer_d_o <= p;
when others =>
buffer_we <= '0';
end case;
end if;
end if;
end process;
t_pull <= t_ready when state=STATE_WAITING else '0';
stop <= '1' when state=STATE_STOP else '0';
c48(47 downto 18) <= (others=>c(17));
c48(17 downto 0) <= c;
p <= p48(17 downto 0);
DSP48A1_inst : DSP48A1
generic map (
A0REG => 0, -- First stage A input pipeline register (0/1)
A1REG => 0, -- Second stage A input pipeline register (0/1)
B0REG => 0, -- First stage B input pipeline register (0/1)
B1REG => 0, -- Second stage B input pipeline register (0/1)
CARRYINREG => 1, -- CARRYIN input pipeline register (0/1)
CARRYINSEL => "OPMODE5", -- Specify carry-in source, "CARRYIN" or "OPMODE5"
CARRYOUTREG => 1, -- CARRYOUT output pipeline register (0/1)
CREG => 0, -- C input pipeline register (0/1)
DREG => 0, -- D pre-adder input pipeline register (0/1)
MREG => 0, -- M pipeline register (0/1)
OPMODEREG => 0, -- Enable=1/disable=0 OPMODE input pipeline registers
PREG => 1, -- P output pipeline register (0/1)
RSTTYPE => "SYNC" -- Specify reset type, "SYNC" or "ASYNC"
)
port map (
-- Control Input Ports: 1-bit (each) input: Clocking and operation mode
CLK => clk,
OPMODE => "01011101", -- P = C + A*(D-B)
-- Cascade Ports: 18-bit (each) output: Ports to cascade from one DSP48 to another
BCOUT => open,
PCOUT => open,
CARRYOUT => open,
CARRYOUTF => open,
M => open,
P => p48,
-- Cascade Ports: 48-bit (each) input: Ports to cascade from one DSP48 to another
PCIN => (others=>'0'),
-- Data Ports: 18-bit (each) input: Data input and output ports
A => a,
B => b,
C => c48,
D => d,
CARRYIN => '0',
-- Reset/Clock Enable Input Ports: 1-bit (each) input: Reset and enable input ports
CEA => '1',
CEB => '1',
CEC => '1',
CECARRYIN => '1',
CED => '1',
CEM => '1',
CEOPMODE => '1',
CEP => '1',
RSTA => '0',
RSTB => '0',
RSTC => '0',
RSTCARRYIN => '0',
RSTD => '0',
RSTM => '0',
RSTOPMODE => '0',
RSTP => '0'
);
end Behavioral;