Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 8.81 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3.  
  4. -- Uncomment the following library declaration if using
  5. -- arithmetic functions with Signed or Unsigned values
  6. use IEEE.NUMERIC_STD.ALL;
  7.  
  8. -- Uncomment the following library declaration if instantiating
  9. -- any Xilinx primitives in this code.
  10. --library UNISIM;
  11. --use UNISIM.VComponents.all;
  12.  
  13. entity image1 is
  14.     port
  15.     (
  16.         clk : in std_logic;
  17.         x : in std_logic_vector(10 downto 0);
  18.         y : in std_logic_vector(9 downto 0);
  19.         datardy : in std_logic;
  20.         b1_stat : in std_logic_vector(7 downto 0);
  21.         b_x : in std_logic_vector(7 downto 0);
  22.         b_y : in std_logic_vector(7 downto 0);
  23.         rgb : out std_logic_vector(2 downto 0)
  24.     );
  25. end image1;
  26.  
  27. architecture image1_arch of image1 is
  28.  
  29.     signal x_position : std_logic_vector (29 downto 0) := "000110010001001011000111110100";
  30.     signal y_position : std_logic_vector (29 downto 0) := "000110010000011001000001100100";
  31.     signal colors : std_logic_vector(5 downto 0);
  32.    
  33.     signal counter: integer range 0 to 2 := 0;
  34.    
  35.     signal xint : integer range 0 to 800;
  36.     signal yint : integer range 0 to 600;
  37.    
  38.     signal ofset_x : integer range -127 to 127;
  39.     signal ofset_y : integer range -127 to 127;
  40.    
  41.     signal rgb_mysz : std_logic_vector(2 downto 0) := "000";
  42.    
  43.     signal prawy : std_logic;
  44.     signal lewy : std_logic;
  45.     signal srodek : std_logic;
  46.    
  47.     signal x_tmp : integer range 0 to 800 := 0;
  48.     signal y_tmp : integer range 0 to 600 := 0;
  49.     signal c_tmp : std_logic_vector(2 downto 0) := "000";
  50.     signal mouse_x_tmp : std_logic_vector(9 downto 0);
  51.     signal mouse_y_tmp : std_logic_vector(9 downto 0);
  52.    
  53.     signal kx : integer range 0 to 800 := 395;
  54.     signal ky : integer range 0 to 600 := 295;
  55.    
  56.     type rom_type is array (0 to 15)
  57.         of std_logic_vector(0 to 15);
  58.    -- ROM definition
  59.    constant MOUSE_ROM: rom_type :=
  60.    (
  61.         "1000000000000000",
  62.         "1100000000000000",
  63.         "1110000000000000",
  64.         "1111000000000000",
  65.         "1111100000000000",
  66.         "1111110000000000",
  67.         "1111111000000000",
  68.         "1111111100000000",
  69.         "1111100000000000",
  70.         "1101100000000000",
  71.         "1000110000000000",
  72.         "0000110000000000",
  73.         "0000011000000000",
  74.         "0000011000000000",
  75.         "0000000000000000",
  76.         "0000000000000000");
  77.    signal rom_addr, rom_col: unsigned(3 downto 0);
  78.    signal rom_data: std_logic_vector(15 downto 0);
  79.    signal rom_bit: std_logic;
  80.    
  81. begin
  82.  
  83.     process (x, y)
  84.     begin
  85.          if xint > kx and xint < kx+10 and yint > ky and yint < ky+10 then
  86.             rgb(2) <= rgb_mysz(2);
  87.             rgb(1) <= rgb_mysz(1);
  88.             rgb(0) <= rgb_mysz(0);
  89.          else
  90.          
  91.             rgb(2) <= '1';
  92.             rgb(1) <= '1';
  93.             rgb(0) <= '1';
  94.          
  95.          --generowanie ksztaltu
  96.          
  97.          --for I in 0 to 2 loop
  98.             --if x_position(9+(I*10) downto 0+(I*10)) /= "0000000000" then
  99.                --x_tmp <= to_integer(unsigned(x_position(9+(I*10) downto 0+(I*10))));
  100.                --y_tmp <= to_integer(unsigned(y_position(9+(I*10) downto 0+(I*10))));
  101.                
  102.                x_tmp <= to_integer(unsigned(x_position(19 downto 10)));
  103.                y_tmp <= to_integer(unsigned(y_position(19 downto 10)));
  104.                if xint >= x_tmp and xint < x_tmp+50 and yint >=y_tmp and yint < y_tmp+50 then
  105.                   rgb(2) <= rgb_mysz(2);
  106.                   rgb(1) <= rgb_mysz(1);
  107.                   rgb(0) <= rgb_mysz(0);
  108.                end if;
  109.             --end if;
  110.             --if xint >= 100+(I*100) and xint < 150+(I*100) and yint >=50 and yint < 100 then
  111.             --   rgb(2) <= rgb_mysz(2);
  112.             --   rgb(1) <= rgb_mysz(1);
  113.             --   rgb(0) <= rgb_mysz(0);
  114.             --end if;
  115.          --end loop;
  116.          
  117.          --if x_tmp /= 0 and y_tmp /= 0 then
  118.                --when counter = 0
  119.                  -- if xint >= 0 and xint < 100 and yint >=60 and yint < 80 then
  120.                  --    rgb(2) <= '0';
  121.                  --    rgb(1) <= '1';
  122.                  --    rgb(0) <= '0';
  123.                  -- end if;
  124.             --if xint >= x_tmp and xint < x_tmp+50 and yint >=y_tmp and yint < y_tmp+50 then
  125.             --   rgb(2) <= c_tmp(2);
  126.             --   rgb(1) <= c_tmp(1);
  127.              --  rgb(0) <= c_tmp(0);
  128.             --end if;
  129.          --end if;
  130.          
  131.          
  132.          --generowanie palety
  133.          if xint >= 0 and xint < 100 and yint >=0 and yint < 20 then
  134.             rgb(2) <= '0';
  135.             rgb(1) <= '0';
  136.             rgb(0) <= '0';
  137.          end if;
  138.           if xint >= 100 and xint < 200 and yint >=0 and yint < 20 then
  139.             rgb(2) <= '0';
  140.             rgb(1) <= '0';
  141.             rgb(0) <= '1';
  142.          end if;
  143.           if xint >= 200 and xint < 300 and yint >=0 and yint < 20 then
  144.             rgb(2) <= '0';
  145.             rgb(1) <= '1';
  146.             rgb(0) <= '0';
  147.          end if;
  148.           if xint >= 300 and xint < 400 and yint >=0 and yint < 20 then
  149.             rgb(2) <= '0';
  150.             rgb(1) <= '1';
  151.             rgb(0) <= '1';
  152.          end if;
  153.           if xint >= 400 and xint < 500 and yint >=0 and yint < 20 then
  154.             rgb(2) <= '1';
  155.             rgb(1) <= '0';
  156.             rgb(0) <= '0';
  157.          end if;
  158.          if xint >= 500 and xint < 600 and yint >=0 and yint < 20 then
  159.             rgb(2) <= '1';
  160.             rgb(1) <= '0';
  161.             rgb(0) <= '1';
  162.          end if;
  163.          if xint >= 600 and xint < 700 and yint >=0 and yint < 20 then
  164.             rgb(2) <= '1';
  165.             rgb(1) <= '1';
  166.             rgb(0) <= '0';  
  167.          end if;
  168.          if xint >= 700 and xint <= 800 and yint >=0 and yint < 20 then  
  169.             rgb(2) <= '1';
  170.             rgb(1) <= '1';
  171.             rgb(0) <= '1';
  172.          end if;
  173.       end if;
  174.     end process;
  175.    
  176.     --rysuj : process (kx,ky)
  177.     --begin
  178.     --  if kx >= 0  and kx <= 800 and ky >= 20 and ky <= 600 and b1_stat(0) = '1' then
  179.     --     x_tmp <= kx;
  180.     --     y_tmp <= ky;
  181.     --     c_tmp(2) <= rgb_mysz(2);
  182.     --     c_tmp(1) <= rgb_mysz(1);
  183.     --     c_tmp(0) <= rgb_mysz(0);
  184.     --  end if;
  185.     --end process;
  186.    
  187.     pickcolor : process (kx,ky)
  188.     begin
  189.       if kx >= 0 and b1_stat(0) = '1' and kx < 100 and ky >=0 and ky < 10 then
  190.             rgb_mysz(2) <= '0';
  191.             rgb_mysz(1) <= '0';
  192.             rgb_mysz(0) <= '0';
  193.          end if;
  194.           if kx >= 100 and b1_stat(0) = '1' and kx < 200 and ky >=0 and ky < 10 then
  195.             rgb_mysz(2) <= '0';
  196.             rgb_mysz(1) <= '0';
  197.             rgb_mysz(0) <= '1';
  198.          end if;
  199.           if kx >= 200 and b1_stat(0) = '1' and kx < 300 and ky >=0 and ky < 10 then
  200.             rgb_mysz(2) <= '0';
  201.             rgb_mysz(1) <= '1';
  202.             rgb_mysz(0) <= '0';
  203.          end if;
  204.           if kx >= 300 and b1_stat(0) = '1' and kx < 400 and ky >=0 and ky < 10 then
  205.             rgb_mysz(2) <= '0';
  206.             rgb_mysz(1) <= '1';
  207.             rgb_mysz(0) <= '1';
  208.          end if;
  209.           if kx >= 400 and b1_stat(0) = '1' and kx < 500 and ky >=0 and ky < 10 then
  210.             rgb_mysz(2) <= '1';
  211.             rgb_mysz(1) <= '0';
  212.             rgb_mysz(0) <= '0';
  213.          end if;
  214.          if kx >= 500 and b1_stat(0) = '1' and kx < 600 and ky >=0 and ky < 10 then
  215.             rgb_mysz(2) <= '1';
  216.             rgb_mysz(1) <= '0';
  217.             rgb_mysz(0) <= '1';
  218.          end if;
  219.          if kx >= 600 and b1_stat(0) = '1' and kx < 700 and ky >=0 and ky < 10 then
  220.             rgb_mysz(2) <= '1';
  221.             rgb_mysz(1) <= '1';
  222.             rgb_mysz(0) <= '0';  
  223.          end if;
  224.          if kx >= 700 and b1_stat(0) = '1' and kx <= 800 and ky >=0 and ky < 10 then  
  225.             rgb_mysz(2) <= '1';
  226.             rgb_mysz(1) <= '1';
  227.             rgb_mysz(0) <= '1';
  228.          end if;
  229.     end process;
  230.    
  231.     mysz : process (datardy)
  232.     begin
  233.       if b1_stat(0) = '1' and rising_edge(clk) and datardy='1' then --lewy
  234.          mouse_x_tmp <= std_logic_vector(to_unsigned(kx, mouse_x_tmp'length));
  235.          mouse_y_tmp <= std_logic_vector(to_unsigned(ky, mouse_y_tmp'length));
  236.          
  237.          x_position(19 downto 10) <= mouse_x_tmp;
  238.          y_position(19 downto 10) <= mouse_y_tmp;
  239.          
  240.          --x_position(9+(counter*10) downto 0+(counter*10)) <= mouse_x_tmp;
  241.          --y_position(9+(counter*10) downto 0+(counter*10)) <= mouse_y_tmp;
  242.          
  243.          --counter <= counter + 1;
  244.       end if;
  245.       if b1_stat(2) = '1' then --srodek
  246.        --TODO
  247.       end if;
  248.       if b1_stat(1) = '1' then --prawy
  249.        --TODO
  250.       end if;
  251.       if rising_edge(clk) and datardy='1' then
  252.          kx <= kx + ofset_x;
  253.          ky <= ky - ofset_y;
  254.       end if;
  255.     end process;
  256.    
  257.     xint <= to_integer(unsigned(x));
  258.     yint <= to_integer(unsigned(y));
  259.     ofset_x <= to_integer(signed(b_x));
  260.     ofset_y <= to_integer(signed(b_y));
  261.    
  262. end image1_arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement