Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- use IEEE.NUMERIC_STD.ALL;
- entity VGA is
- Port (
- clk : in STD_LOGIC;
- hsync_out : out STD_LOGIC;
- vsync_out : out STD_LOGIC;
- red_out : out STD_LOGIC;
- green_out : out STD_LOGIC;
- blue_out : out STD_LOGIC;
- );
- end VGA;
- architecture Behavioral of Pong is
- signal halfClock : STD_LOGIC;
- signal horizontalPosition : integer range 0 to 800 := 0;
- signal verticalPosition : integer range 0 to 640 := 0;
- signal hsyncEnable : STD_LOGIC;
- signal vsyncEnable : STD_LOGIC;
- signal color : STD_LOGIC_VECTOR (2 downto 0) := "000";
- begin
- -- Half the clock
- clockScaler : process(clk)
- begin
- if clk'event and clk = '1' then
- halfClock <= not halfClock;
- end if;
- end process clockScaler;
- signalTiming : process(halfClock)
- begin
- if halfClock'event and halfClock = '1' then
- if horizontalPosition = 640 then
- horizontalPosition <= 0;
- verticalPosition <= verticalPosition + 1;
- if verticalPosition = 480 then
- verticalPosition <= 0;
- else
- verticalPosition <= verticalPosition + 1;
- end if;
- else
- horizontalPosition <= horizontalPosition + 1;
- end if;
- end if;
- end process signalTiming;
- vgaSync : process(halfClock, horizontalPosition, verticalPosition)
- begin
- if halfClock'event and halfClock = '1' then
- if horizontalPosition > 0 and horizontalPosition < 640 then
- hsyncEnable <= '0';
- else
- hsyncEnable <= '1';
- end if;
- if verticalPosition > 0 and verticalPosition < 480 then
- vsyncEnable <= '0';
- else
- vsyncEnable <= '1';
- end if;
- end if;
- end process vgaSync;
- -- VGA Controller
- draw : process(halfClock)
- begin
- if halfClock'event and halfClock = '1' then
- hsync_out <= hsyncEnable;
- vsync_out <= vsyncEnable;
- if hsyncEnable = '0' then
- red_out <= 0;
- green_out <= 0;
- blue_out <= 1;
- else
- red_out <= '0';
- green_out <= '0';
- blue_out <= '0';
- end if;
- end if;
- end process draw;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement