Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 5.37 KB | None | 0 0
  1. LIBRARY  ieee;
  2. USE ieee.std_logic_1164.all;
  3.  
  4.  
  5.  --TODO implement video on/off to this controller--
  6. entity GAME_VGA is
  7.     port(
  8.         in_clk_50 : in std_logic;      -- vga clock
  9.         in_clk_28: in std_logic;    -- clock to be divided to 1hz
  10.         out_xSync : out std_logic;  -- horizontal sync
  11.         out_ySync : out std_logic;  -- vertical sync
  12.         out_R :  out std_logic_vector(9 downto 0);
  13.         out_G :  out std_logic_vector(9 downto 0);
  14.         out_B :  out std_logic_vector(9 downto 0);
  15.         out_blank : out std_logic;
  16.         out_sync : out std_logic;
  17.         out_clk : out std_logic;
  18.         in_left: in std_logic;
  19.         in_right: in std_logic
  20.         );
  21.  
  22. end GAME_VGA;
  23.  
  24.     architecture DRAWING_LOGIC of GAME_VGA is
  25.         signal last_left_state: std_logic;
  26.         signal last_right_state: std_logic;
  27.         signal half_clock: std_logic;
  28.         signal one_hertz: std_logic;
  29.         signal flip: std_logic;
  30.         signal x: integer range 0 to 800 := 0;
  31.         signal y: integer range 0 to 525 := 0;
  32.         signal div: integer range 0 to 700000 := 0;
  33.         signal offset: integer range 0 to 400 := 0;
  34.         signal xSyncEnable: std_logic;
  35.         signal ySyncEnable: std_logic;
  36.  
  37.         -- horizontal - x
  38.         constant x_visibleArea : natural := 640; -- horizontal visible area
  39.         constant x_frontPorch : natural := 16;  -- horizontal front porch
  40.         constant x_syncPulse : natural := 96;  -- horizontal sync pulse
  41.         constant x_backPorch : natural := 48;  -- horizontal back porch
  42.         constant x_total : natural := 800;
  43.        
  44.         -- vertical - y
  45.         constant y_visibleArea : natural := 480; -- vertical visible area
  46.         constant y_frontPorch : natural := 10;  -- vertical front porch
  47.         constant y_syncPulse : natural := 2;   -- vertical sync pulse
  48.         constant y_backPorch : natural := 33;  -- vertical back porch
  49.         constant y_total : natural := 525;
  50.  
  51.         signal color: std_logic_vector(2 downto 0) := "000";
  52.  
  53.         begin
  54.             out_sync <= '0';
  55.             out_blank <= '1';
  56.             color <= "010";
  57.             out_xSync <= xSyncEnable;
  58.             out_ySync <= ySyncEnable;
  59.             out_clk <= half_clock;
  60.            
  61.         -- HALFING THE CLOCK --
  62.         clockScale: process(in_clk_50)
  63.         begin
  64.             if in_clk_50'event and in_clk_50 = '1' then
  65.                 half_clock <= not half_clock;
  66.             end if;
  67.         end process clockScale;
  68.        
  69.         -- ONE HERTZ CLOCK --
  70.         divCounter: process(in_clk_28)
  71.         begin
  72.             if in_clk_28'event and in_clk_28 = '1' then
  73.                 if div = 70000 then
  74.                     div <= 0;
  75.                     one_hertz <= not one_hertz;
  76.                 else
  77.                     div <= div + 1;
  78.                 end if;
  79.             end if;
  80.         end process divCounter;
  81.        
  82.        
  83.         -- SIGNAL TIMING --
  84.  
  85.         sig_timing: process(half_clock)
  86.         begin
  87.             if half_clock'event and half_clock = '1' then
  88.                 if x = x_total then
  89.                    
  90.                     x <= 0;
  91.                     y <= y + 1;
  92.                    
  93.                     if y = y_total then
  94.                         y <= 0;
  95.                     else
  96.                         y <= y + 1;
  97.                     end if;
  98.                 else
  99.                     x <= x + 1;
  100.                 end if;
  101.             end if;
  102.         end process sig_timing;
  103.  
  104.        
  105.         offset_maker: process(one_hertz)
  106.         begin
  107.             if rising_edge(one_hertz) then
  108.                 if in_left = '1' and last_left_state = '0' then
  109.                     offset <= offset + 1;
  110.                 elsif in_right = '1' and last_right_state = '1'  then
  111.                     offset <= offset - 1;
  112.                 end if;
  113.                 last_right_state <= in_right;
  114.                 last_left_state <= in_left;
  115.             end if;
  116.         end process offset_maker;
  117.        
  118.         vga_sync: process (half_clock)
  119.         begin
  120.        
  121.             if half_clock'event and half_clock = '1' then
  122.                 if x >= (x_visibleArea + x_frontPorch) and x < (x_visibleArea + x_frontPorch + x_syncPulse)  then --96 points
  123.                     xSyncEnable <= '0';
  124.                 else
  125.                     xSyncEnable <= '1';
  126.                 end if;
  127.                
  128.                 if y >= (y_visibleArea + y_frontPorch) and y < (y_visibleArea + y_frontPorch + y_syncPulse) then --2 points
  129.                     ySyncEnable <= '0';
  130.                 else
  131.                     ySyncEnable <= '1';
  132.                 end if;
  133.             end if;
  134.         end process vga_sync;
  135.  
  136. --      
  137. --        draw: process(half_clock)
  138. --            begin
  139. --                if half_clock'event and half_clock = '1' then
  140. --                        out_R(9) <= '0';
  141. --                        out_G(9) <= '0';
  142. --                        out_B(9) <= '0';
  143. --                  
  144. --                end if;
  145. --            end process draw;
  146.            
  147.         try_foreground: process(half_clock)
  148.             begin
  149.                 if half_clock'event and half_clock = '1' then
  150.                    
  151.                     if( x >=  (0 + offset) and x < (100 + offset) and y >= 200  and y < 300) and x < 640 and y < 480 then
  152.                         out_R(8) <= '1';
  153.                         out_G(8) <= '0';
  154.                         out_B(8) <= '1';
  155.                        
  156.                         out_R(6) <= '1';
  157.                         out_G(6) <= '0';
  158.                         out_B(6) <= '1';
  159.                     else
  160.                         out_R(8) <= '0';
  161.                         out_B(8) <= '0';
  162.                        
  163.                         out_R(6) <= '0';
  164.                         out_B(6) <= '0';
  165.                     end if;
  166.                 end if;
  167.             end process try_foreground;
  168.            
  169. end DRAWING_LOGIC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement