-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlotter.vhd
194 lines (183 loc) · 5.92 KB
/
Plotter.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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- 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;
entity Plotter is
Port ( clk :in STD_LOGIC;
reset: in STD_LOGIC;
Y : in STD_LOGIC_VECTOR (9 downto 0); --coordenada y proveniente del vga
X : in STD_LOGIC_VECTOR (9 downto 0); --coordenada x proceniente del vga
objeto : in STD_LOGIC_VECTOR (3 downto 0); -- tipo de objeto a representar
yxt : out STD_LOGIC_VECTOR (7 downto 0); --coordenada yx que va al tablero
RGB : out STD_LOGIC_VECTOR (7 downto 0)); --color a representar
end Plotter;
architecture Behavioral of Plotter is
COMPONENT BR1
PORT (
clka : IN STD_LOGIC;
addra : IN STD_LOGIC_VECTOR(10 DOWNTO 0);
douta : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END COMPONENT;
COMPONENT BR2
PORT (
clka : IN STD_LOGIC;
addra : IN STD_LOGIC_VECTOR(10 DOWNTO 0);
douta : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END COMPONENT;
COMPONENT BR3
PORT (
clka : IN STD_LOGIC;
addra : IN STD_LOGIC_VECTOR(9 DOWNTO 0);
douta : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END COMPONENT;
signal yt, xt:unsigned (3 downto 0); --seales de y x para el tablero
signal yr, xr:unsigned (4 downto 0); --seales de y x para las imagenes
signal addraBR1, addraBR2: std_logic_vector(10 downto 0); --direcciones de lectura a las memorias
signal addraBR3: std_logic_vector(9 downto 0); --direcciones de lectura a la memoria del pez
signal doutaBR1, doutaBR2, doutaBR3: std_logic_vector(7 downto 0); --info dentro de memorias
begin
RomBR1:BR1
Port Map(clka=>clk,addra=>addraBR1,douta=>doutaBR1);
RomBR2:BR2
Port Map(clka=>clk,addra=>addraBR2,douta=>doutaBR2);
RomBR3:BR3
Port Map(clka=>clk,addra=>addraBR3,douta=>doutaBR3);
yxt(7 downto 4)<=std_logic_vector(yt); --asignacin de las coordenadas
yxt(3 downto 0)<=std_logic_vector(xt); --yx que iran al tablero
xt<= unsigned(X(8 downto 5))-2; --coordenadas yt y xt sern los bits
yt<= unsigned(Y(8 downto 5)); --que dividen el tablero en grupos de 32 bits
xr<= unsigned(X(4 downto 0)); --coordenadas yr y xr sern los bits
yr<= unsigned(Y(4 downto 0)); --que cuentan de 32 en 32
comb: process(objeto,yr,xr,Y,X,doutaBR1,doutaBR2,doutaBR3)
begin
if(unsigned(X)<63 or unsigned(X)>575)then
RGB<="00101011";
addraBR2<=(others=>'0');
addraBR1<=(others=>'0');
addraBR3<=(others=>'0');
else
case objeto is
when "0000" => --vacio (tablero libre)
addraBR1<=(others=>'0');
addraBR2<=(others=>'0');
addraBR3<=(others=>'0');
RGB<="11111010";
when "0100"=> --cabeza arriba
addraBR1(10)<='1';
addraBR1(9 downto 5)<=std_logic_vector(yr);
addraBR1(4 downto 0)<=std_logic_vector(xr);
addraBR2<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR1 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR1;
end if;
when "0101"=> --cabeza derecha (inversin)
addraBR1(10)<='0';
addraBR1(9 downto 5)<=std_logic_vector(yr);
addraBR1(4 downto 0)<=std_logic_vector(31-xr); --le restamos 31 a la coordenada x para invertir la matriz
addraBR2<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR1 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR1;
end if;
when "0110"=> --cabeza izquierda
addraBR1(10)<='0';
addraBR1(9 downto 5)<=std_logic_vector(yr);
addraBR1(4 downto 0)<=std_logic_vector(xr);
addraBR2<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR1 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR1;
end if;
when "0111"=> --cabeza abajo (inversion)
addraBR1(10)<='1';
addraBR1(9 downto 5)<=std_logic_vector(31-yr);
addraBR1(4 downto 0)<=std_logic_vector(xr);
addraBR2<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR1 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR1;
end if;
when "0011" => --pescado
addraBR3(9 downto 5)<=std_logic_vector(yr);
addraBR3(4 downto 0)<=std_logic_vector(xr);
addraBR2<=(others=>'0');
addraBR1<=(others=>'0');
if (doutaBR3 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR3;
end if;
when "1000" => --gato arriba
addraBR2(10)<='1';
addraBR2(9 downto 5)<=std_logic_vector(yr);
addraBR2(4 downto 0)<=std_logic_vector(xr);
addraBR1<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR2 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR2;
end if;
when "1001"=> --gato derecha (inversin)
addraBR2(10)<='0';
addraBR2(9 downto 5)<=std_logic_vector(yr);
addraBR2(4 downto 0)<=std_logic_vector(31-xr); --le restamos 31 a la coordenada x para invertir la matriz
addraBR1<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR2 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR2;
end if;
when "1010"=> --gato izquierda
addraBR2(10)<='0';
addraBR2(9 downto 5)<=std_logic_vector(yr);
addraBR2(4 downto 0)<=std_logic_vector(xr);
addraBR1<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR2 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR2;
end if;
when "1011"=> --gato abajo (inversion)
addraBR2(10)<='1';
addraBR2(9 downto 5)<=std_logic_vector(31-yr);
addraBR2(4 downto 0)<=std_logic_vector(xr);
addraBR1<=(others=>'0');
addraBR3<=(others=>'0');
if (doutaBR2 = "11111111") then
RGB<="11111010";
else
RGB<=doutaBR2;
end if;
when "1111"=> --muro
addraBR2<=(others=>'0');
addraBR1<=(others=>'0');
addraBR3<=(others=>'0');
RGB<="00011011";
when others =>
addraBR2<=(others=>'0');
addraBR1<=(others=>'0');
addraBR3<=(others=>'0');
RGB<="00011100";--"00011100" es para detectar errores
end case;
end if;
end process;
end Behavioral;