-- Interactive Audio Manipulation Processor -- -- file: joystick.vhd -- status: simulated; works in hardware, but sometimes cursor "teleports" -- -- author: Stephen Tang -- -- Uses input from the joystick to update the cursor position library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library work; use work.Constants_Pkg.all; entity joystick is port ( clock : in std_logic; -- should be the VGA h-sync signal up, down, left, right, fire: in std_logic; -- pins TBD X: buffer std_logic_vector(DISPLAY_X-1 downto 0); Y: buffer std_logic_vector(DISPLAY_Y-1 downto 0) ); end joystick; architecture driver of joystick is constant JOYCOUNT_WIDTH: positive := 6; constant REPEAT_TIME: std_logic_vector(JOYCOUNT_WIDTH-1 downto 0) := "101001"; -- 41 ticks -- this constant was set to "11" (4-1 ticks) -- when testing in MAX+plus II simulator signal CountTicks: std_logic_vector(JOYCOUNT_WIDTH-1 downto 0); begin UpdatePosition: process (clock) begin if rising_edge(clock) then if CountTicks /= REPEAT_TIME then CountTicks <= CountTicks + 1; else -- restart the counter CountTicks <= (others => '0'); if (left = '0') and (X /= MIN_X_COORD) then X <= X - 1; elsif (right = '0') and (X /= MAX_X_COORD) then X <= X + 1; end if; if (up = '0') and (Y /= MIN_Y_COORD) then Y <= Y - 1; elsif (down = '0') and (Y /= MAX_Y_COORD) then Y <= Y + 1; end if; end if; end if; end process; end;