Line 19... |
Line 19... |
-- GNU General Public License for more details.
|
-- GNU General Public License for more details.
|
|
|
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
-- along with JART (Just Another Ray Tracer). If not, see <http://www.gnu.org/licenses/>.library ieee;
|
-- along with JART (Just Another Ray Tracer). If not, see <http://www.gnu.org/licenses/>.library ieee;
|
|
|
-- Unitary ray vector Y component integrator. In a memory block of 1x16384 bits, it is stored the FY' that represents the first derivate of FY, this function is the Y function along any horizontal line in the image.
|
-- Ray Generator.....
|
-- The derivative is stored in this way: logic 0 means a 0 pendant and logic 1 means a -1 pendant. So a counter with enable / disable control it is everything we need, and of course a load input to represent the initial value added to the integral.
|
-- The entity synthesizes 4 simmetrical rays each clock. The ena signal enables/disables the ray production.
|
|
-- The Ray Generator starts by generating after the first clock's rising edge with the ena signal set.
|
|
-- The first four rays generated are the Rays passing through the center of the screen, in the 320x200 screen these rays are : (159,99)(160,99)(159,100)(160,100), after those rays the next four rays are (158,99)(161,99)(158,100)(161,100).
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_signed.all;
|
use ieee.std_logic_signed.all;
|
use work.powerGrid.all;
|
use work.powerGrid.all;
|
|
|
|
|
entity yu is
|
entity yu is
|
generic (
|
generic (
|
|
VALSTARTX : integer := 34;
|
|
VALSTARTY : integer := 1023;
|
|
VALSTARTZ : integer := 9;
|
TOP : integer := 1024; -- Define the max counting number.. the number must be expressed as 2 power, cause the range of counting is going to be defined as TOP-1 downto TOP/2.
|
TOP : integer := 1024; -- Define the max counting number.. the number must be expressed as 2 power, cause the range of counting is going to be defined as TOP-1 downto TOP/2.
|
-- However this is going to be by now, cause in the future the ray generation will GO on for higher resolution images , and perhaps it would be required a more extended range for the yu component.
|
-- However this is going to be by now, cause in the future the ray generation will GO on for higher resolution images , and perhaps it would be required a more extended range for the yu component.
|
SCREENW : integer := 320 -- resolution width is 320
|
SCREENW : integer := 320 -- resolution width is 320
|
);
|
);
|
port (
|
port (
|
clk,rst,ena : in std_logic;
|
clk,rst,ena : in std_logic;
|
lineDone : out std_logic; -- Finished image row. once a hundred and sixty times....
|
lineDone : out std_logic; -- Finished image row. once a hundred and sixty times....
|
ypos : out integer range TOP/2 to TOP-1
|
ocntr : out integer range 0 to SCREENW/2;
|
-- ocntr : out integer range 0 to SCREENW/2
|
ypos : out integer range TOP/2 to TOP-1;
|
|
zpos : out integer range -TOP to TOP-1;
|
|
zneg : out integer range -TOP to TOP-1;
|
|
xpos : out integer range -TOP to TOP-1;
|
|
xneg : out integer range -TOP to TOP-1
|
|
|
);
|
);
|
end entity;
|
end entity;
|
|
|
architecture rtl of yu is
|
architecture rtl of yu is
|
|
|
-- 1x16384 bits, true dual port, ROM Memory declaration.
|
-- 1x16384 bits, true dual port, ROM Memory declaration.
|
-- This memory uses 2 cycles.. a memory fetch cycle and a data to q memory cycle.
|
-- This memory uses 2 cycles.. a memory fetch cycle and a data to q memory cycle.
|
component yurom
|
component yurom
|
port
|
port
|
(
|
(
|
Line 59... |
Line 68... |
);
|
);
|
|
|
end component;
|
end component;
|
|
|
|
|
constant linefeed : integer range 0 to (SCREENW/2) := (SCREENW/2)-2;
|
constant linefeed : integer range 0 to (SCREENW/2) := (SCREENW/2)-4;
|
|
|
|
|
-- Support signals.
|
-- Support signals.
|
signal s1addf0 : std_logic_vector (13 downto 0); -- The function 0 is the function of the y component derivative.
|
signal s1addf0 : std_logic_vector (13 downto 0); -- The function 0 is the function of the y component derivative.
|
signal s1addf1 : std_logic_vector (13 downto 0); -- The function 1 is the function of the y component integration curve initial constant.
|
signal s1addf1 : std_logic_vector (13 downto 0); -- The function 1 is the function of the y component integration curve initial constant.
|
signal sf0 : std_logic_vector (0 downto 0); -- Derivative function
|
signal sf0 : std_logic_vector (0 downto 0); -- Derivative function
|
signal sf1 : std_logic_vector (0 downto 0); -- Derivative curve, initial constant derivative function.
|
signal sf1 : std_logic_vector (0 downto 0); -- Derivative curve, initial constant derivative function.
|
signal cc : integer range 0 to SCREENW/2;
|
signal cc : integer range 0 to SCREENW/2;
|
signal f0 : integer range TOP/2 to TOP-1;
|
signal fy : integer range TOP/2 to TOP-1;
|
|
signal pivotCol,pivotRow : std_logic;
|
|
signal fz : integer range -TOP to TOP-1;
|
|
signal fx : integer range -TOP to TOP-1;
|
begin
|
begin
|
|
|
-- Connect f0, to the output.
|
-- Connect fy, to the output.
|
ypos <= f0;
|
ypos <= fy;
|
|
xpos <= fx;
|
|
xneg <= -fx;
|
|
zpos <= fz;
|
|
zneg <= -fz;
|
|
ocntr<= cc;
|
|
|
derivate : yurom
|
derivate : yurom
|
port map (
|
port map (
|
address_a => s1addf0,
|
address_a => s1addf0,
|
address_b => s1addf1,
|
address_b => s1addf1,
|
Line 87... |
Line 103... |
);
|
);
|
|
|
|
|
integrationControl : process (clk,rst,ena)
|
integrationControl : process (clk,rst,ena)
|
variable f1 : integer range TOP/2 to TOP-1;
|
variable f1 : integer range TOP/2 to TOP-1;
|
|
|
begin
|
begin
|
|
|
if rst='0' then
|
if rst='0' then
|
|
|
f0<=TOP-1;
|
fy<=TOP/2;
|
f1:=TOP-1;
|
f1:=VALSTARTY;
|
lineDone<='0';
|
fz<=VALSTARTZ-2;
|
|
fx<=0;
|
|
pivotCol <= '0';
|
|
pivotRow <= '0';
|
|
|
|
|
elsif rising_edge(clk) and ena='1' then
|
elsif rising_edge(clk) and ena='1' then
|
|
|
if cc=0 then
|
if cc=(SCREENW/2)-1 then
|
lineDone<='1';
|
|
if sf1(0) ='1' then
|
-- Y component
|
f1 := f1 - 1;
|
f1 := f1 - CONV_INTEGER('0'&sf1(0));
|
end if;
|
fy <= f1;
|
f0 <= f1;
|
|
|
-- X component
|
|
fx <= VALSTARTX;
|
|
|
|
-- Z component
|
|
fz <= fz+2+CONV_INTEGER('0'&pivotRow); -- Beware of the sign!
|
|
pivotRow <= not (pivotRow);
|
|
|
else
|
else
|
lineDone<='0';
|
|
if sf0(0) = '1' then
|
|
f0 <= f0-1;
|
|
end if;
|
|
|
|
end if;
|
-- Y Component
|
|
fy <= fy-CONV_INTEGER('0'&sf0(0));
|
|
|
|
-- X component
|
|
fx <= fx+2+CONV_INTEGER('0'&pivotCol); -- Beware of the sign!
|
|
pivotCol <= not(pivotCol);
|
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
end if;
|
|
|
|
|
Line 124... |
Line 154... |
counterControl : process (clk,rst,ena)
|
counterControl : process (clk,rst,ena)
|
begin
|
begin
|
|
|
if rst='0' then
|
if rst='0' then
|
|
|
cc<=0;
|
cc<=SCREENW/2-1;
|
|
lineDone<='0';
|
|
|
elsif rising_edge(clk) and ena='1' then
|
elsif rising_edge(clk) and ena='1' then
|
if cc=(SCREENW/2)-1 then
|
if cc=(SCREENW/2)-1 then
|
|
lineDone<='1';
|
cc<=0;
|
cc<=0;
|
else
|
else
|
|
lineDone<='0';
|
cc<=cc+1;
|
cc<=cc+1;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
end process;
|
end process;
|