Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1.  
  2. library IEEE;
  3. use IEEE.STD_LOGIC_1164.ALL;
  4. use IEEE.STD_LOGIC_ARITH.ALL;
  5. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  6. use IEEE.NUMERIC_STD.ALL;
  7.  
  8.  
  9. entity VGA is
  10. Port (
  11. clk : in STD_LOGIC;
  12. hsync_out : out STD_LOGIC;
  13. vsync_out : out STD_LOGIC;
  14. red_out : out STD_LOGIC;
  15. green_out : out STD_LOGIC;
  16. blue_out : out STD_LOGIC;
  17. );
  18. end VGA;
  19.  
  20. architecture Behavioral of Pong is
  21.  
  22. signal halfClock : STD_LOGIC;
  23. signal horizontalPosition : integer range 0 to 800 := 0;
  24. signal verticalPosition : integer range 0 to 640 := 0;
  25. signal hsyncEnable : STD_LOGIC;
  26. signal vsyncEnable : STD_LOGIC;
  27.  
  28.  
  29. signal color : STD_LOGIC_VECTOR (2 downto 0) := "000";
  30.  
  31. begin
  32. -- Half the clock
  33. clockScaler : process(clk)
  34. begin
  35. if clk'event and clk = '1' then
  36. halfClock <= not halfClock;
  37. end if;
  38. end process clockScaler;
  39.  
  40. signalTiming : process(halfClock)
  41. begin
  42. if halfClock'event and halfClock = '1' then
  43. if horizontalPosition = 640 then
  44. horizontalPosition <= 0;
  45. verticalPosition <= verticalPosition + 1;
  46.  
  47. if verticalPosition = 480 then
  48. verticalPosition <= 0;
  49. else
  50. verticalPosition <= verticalPosition + 1;
  51. end if;
  52. else
  53. horizontalPosition <= horizontalPosition + 1;
  54. end if;
  55. end if;
  56. end process signalTiming;
  57.  
  58. vgaSync : process(halfClock, horizontalPosition, verticalPosition)
  59. begin
  60. if halfClock'event and halfClock = '1' then
  61. if horizontalPosition > 0 and horizontalPosition < 640 then
  62. hsyncEnable <= '0';
  63. else
  64. hsyncEnable <= '1';
  65. end if;
  66.  
  67. if verticalPosition > 0 and verticalPosition < 480 then
  68. vsyncEnable <= '0';
  69. else
  70. vsyncEnable <= '1';
  71. end if;
  72. end if;
  73. end process vgaSync;
  74.  
  75. -- VGA Controller
  76. draw : process(halfClock)
  77. begin
  78. if halfClock'event and halfClock = '1' then
  79. hsync_out <= hsyncEnable;
  80. vsync_out <= vsyncEnable;
  81.  
  82. if hsyncEnable = '0' then
  83. red_out <= 0;
  84. green_out <= 0;
  85. blue_out <= 1;
  86. else
  87. red_out <= '0';
  88. green_out <= '0';
  89. blue_out <= '0';
  90. end if;
  91. end if;
  92. end process draw;
  93.  
  94. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement