OpenCores
URL https://opencores.org/ocsvn/gamepads/gamepads/trunk

Subversion Repositories gamepads

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 2 to Rev 3
    Reverse comparison

Rev 2 → Rev 3

/trunk/snespad/bench/vhdl/tb-c.vhd
0,0 → 1,20
-------------------------------------------------------------------------------
--
-- Testbench for the
-- SNESpad controller core
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- $Id: tb-c.vhd,v 1.1 2004-10-05 17:05:31 arniml Exp $
--
-------------------------------------------------------------------------------
 
configuration tb_behav_c0 of tb is
 
for behav
for dut : snespad
use configuration work.snespad_struct_c0;
end for;
end for;
 
end tb_behav_c0;
/trunk/snespad/bench/vhdl/tb.vhd
0,0 → 1,249
-------------------------------------------------------------------------------
--
-- Testbench for the
-- SNESpad controller core
--
-- $Id: tb.vhd,v 1.1 2004-10-05 17:05:31 arniml Exp $
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- All rights reserved
--
-- Redistribution and use in source and synthezised forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- Redistributions in synthesized form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- Neither the name of the author nor the names of other contributors may
-- be used to endorse or promote products derived from this software without
-- specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--
-- Please report bugs to the author, but before you do so, please
-- make sure that this is not a derivative work and that
-- you have the latest version of this file.
--
-- The latest version of this file can be found at:
-- http://www.opencores.org/cvsweb.shtml/gamepads/
--
-- The project homepage is located at:
-- http://www.opencores.org/projects.cgi/web/gamepads/overview
--
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
 
entity tb is
 
end tb;
 
 
use work.snespad_pack.all;
 
architecture behav of tb is
 
constant period_c : time := 100 ns;
constant num_pads_c : natural := 2;
constant reset_level_c : natural := 0;
constant button_level_c : natural := 0;
 
component snespad
generic (
num_pads_g : natural := 1;
reset_level_g : natural := 0;
button_level_g : natural := 0;
clocks_per_6us_g : natural := 6
);
port (
clk_i : in std_logic;
reset_i : in std_logic;
pad_clk_o : out std_logic;
pad_latch_o : out std_logic;
pad_data_i : in std_logic_vector(num_pads_g-1 downto 0);
but_a_o : out std_logic_vector(num_pads_g-1 downto 0);
but_b_o : out std_logic_vector(num_pads_g-1 downto 0);
but_x_o : out std_logic_vector(num_pads_g-1 downto 0);
but_y_o : out std_logic_vector(num_pads_g-1 downto 0);
but_start_o : out std_logic_vector(num_pads_g-1 downto 0);
but_sel_o : out std_logic_vector(num_pads_g-1 downto 0);
but_tl_o : out std_logic_vector(num_pads_g-1 downto 0);
but_tr_o : out std_logic_vector(num_pads_g-1 downto 0);
but_up_o : out std_logic_vector(num_pads_g-1 downto 0);
but_down_o : out std_logic_vector(num_pads_g-1 downto 0);
but_left_o : out std_logic_vector(num_pads_g-1 downto 0);
but_right_o : out std_logic_vector(num_pads_g-1 downto 0)
);
end component snespad;
 
 
signal clk_s : std_logic;
signal reset_s : std_logic;
 
signal pad_clk_s : std_logic;
signal pad_latch_s : std_logic;
signal pad_data_s : std_logic_vector(num_pads_c-1 downto 0);
 
type buttons_t is array (11 downto 0) of std_logic_vector(num_pads_c-1 downto 0);
signal buttons_s : buttons_t;
 
signal buttons0_s,
buttons1_s : std_logic_vector(11 downto 0);
 
begin
 
dut : snespad
generic map (
num_pads_g => 2,
reset_level_g => reset_level_c,
button_level_g => button_level_c,
clocks_per_6us_g => 60
)
port map (
clk_i => clk_s,
reset_i => reset_s,
pad_clk_o => pad_clk_s,
pad_latch_o => pad_latch_s,
pad_data_i => pad_data_s,
but_a_o => buttons_s(but_pos_a_c),
but_b_o => buttons_s(but_pos_b_c),
but_x_o => buttons_s(but_pos_x_c),
but_y_o => buttons_s(but_pos_y_c),
but_start_o => buttons_s(but_pos_start_c),
but_sel_o => buttons_s(but_pos_sel_c),
but_tl_o => buttons_s(but_pos_tl_c),
but_tr_o => buttons_s(but_pos_tr_c),
but_up_o => buttons_s(but_pos_up_c),
but_down_o => buttons_s(but_pos_down_c),
but_left_o => buttons_s(but_pos_left_c),
but_right_o => buttons_s(but_pos_right_c)
);
 
buttons: process (buttons_s)
begin
for i in 0 to 11 loop
buttons0_s(i) <= buttons_s(i)(0);
buttons1_s(i) <= buttons_s(i)(1);
end loop;
end process buttons;
 
-----------------------------------------------------------------------------
-- DUT Stimuli
-----------------------------------------------------------------------------
stimuli: process
 
procedure dispatch(pad : in natural;
packet : in std_logic_vector(11 downto 0)) is
begin
 
wait until pad_latch_s = '0';
for i in 11 downto 0 loop
wait until pad_clk_s = '0';
pad_data_s(pad) <= packet(i);
wait until pad_clk_s = '1';
end loop;
 
wait for period_c;
 
assert pad_latch_s = '1'
report "Latch not deasserted!"
severity error;
 
wait for period_c;
for i in 11 downto 0 loop
assert button_active_f(buttons_s(i)(pad), button_level_c) = packet(i)
report "Mismatch for received vs. sent buttons!"
severity error;
end loop;
 
end dispatch;
 
begin
pad_data_s <= (others => '1');
 
wait until reset_s = '1';
wait for period_c * 4;
 
for pad in 0 to 1 loop
dispatch(pad, packet => "000000000000");
dispatch(pad, packet => "111111111111");
dispatch(pad, packet => "010101010101");
dispatch(pad, packet => "101010101010");
dispatch(pad, packet => "100000000000");
dispatch(pad, packet => "010000000000");
dispatch(pad, packet => "001000000000");
dispatch(pad, packet => "000100000000");
dispatch(pad, packet => "000010000000");
dispatch(pad, packet => "000001000000");
dispatch(pad, packet => "000000100000");
dispatch(pad, packet => "000000010000");
dispatch(pad, packet => "000000001000");
dispatch(pad, packet => "000000000100");
dispatch(pad, packet => "000000000010");
dispatch(pad, packet => "000000000001");
end loop;
 
 
wait for period_c * 4;
assert false
report "End of simulation reached."
severity failure;
 
end process stimuli;
 
 
-----------------------------------------------------------------------------
-- Clock Generator
-----------------------------------------------------------------------------
clk: process
begin
clk_s <= '0';
wait for period_c / 2;
clk_s <= '1';
wait for period_c / 2;
end process clk;
 
 
-----------------------------------------------------------------------------
-- Reset Generator
-----------------------------------------------------------------------------
reset: process
begin
if reset_level_c = 0 then
reset_s <= '0';
else
reset_s <= '1';
end if;
 
wait for period_c * 4 + 10 ns;
 
reset_s <= not reset_s;
 
wait;
end process reset;
 
end behav;
 
 
-------------------------------------------------------------------------------
-- File History:
--
-- $Log: not supported by cvs2svn $
-------------------------------------------------------------------------------
/trunk/snespad/rtl/vhdl/snespad_ctrl-c.vhd
0,0 → 1,16
-------------------------------------------------------------------------------
--
-- SNESpad controller core
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- $Id: snespad_ctrl-c.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
--
-------------------------------------------------------------------------------
 
configuration snespad_ctrl_rtl_c0 of snespad_ctrl is
 
for rtl
end for;
 
end snespad_ctrl_rtl_c0;
/trunk/snespad/rtl/vhdl/snespad_ctrl.vhd
0,0 → 1,219
-------------------------------------------------------------------------------
--
-- SNESpad controller core
--
-- $Id: snespad_ctrl.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- All rights reserved
--
-- Redistribution and use in source and synthezised forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- Redistributions in synthesized form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- Neither the name of the author nor the names of other contributors may
-- be used to endorse or promote products derived from this software without
-- specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--
-- Please report bugs to the author, but before you do so, please
-- make sure that this is not a derivative work and that
-- you have the latest version of this file.
--
-- The latest version of this file can be found at:
-- http://www.opencores.org/cvsweb.shtml/gamepads/
--
-- The project homepage is located at:
-- http://www.opencores.org/projects.cgi/web/gamepads/overview
--
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
 
entity snespad_ctrl is
 
generic (
reset_level_g : natural := 0;
clocks_per_6us_g : natural := 6
);
port (
-- System Interface -------------------------------------------------------
clk_i : in std_logic;
reset_i : in std_logic;
clk_en_o : out boolean;
-- Control Interface ------------------------------------------------------
shift_buttons_o : out boolean;
save_buttons_o : out boolean;
-- Pad Interface ----------------------------------------------------------
pad_clk_o : out std_logic;
pad_latch_o : out std_logic
);
 
end snespad_ctrl;
 
 
use work.snespad_pack.all;
 
architecture rtl of snespad_ctrl is
 
subtype clocks_per_6us_t is natural range 0 to clocks_per_6us_g;
 
type state_t is (IDLE,
IDLE2,
LATCH,
CLOCK,
READ_PAD);
 
signal pad_latch_q,
pad_latch_s : std_logic;
 
signal pad_clk_q,
pad_clk_s : std_logic;
 
signal num_buttons_read_q : num_buttons_read_t;
signal clocks_per_6us_q : clocks_per_6us_t;
 
signal state_q,
state_s : state_t;
 
signal clk_en_s : boolean;
signal shift_buttons_s : boolean;
 
begin
 
-- pragma translate_off
-----------------------------------------------------------------------------
-- Check generics
-----------------------------------------------------------------------------
assert (reset_level_g = 0) or (reset_level_g = 1)
report "reset_level_g must be either 0 or 1!"
severity failure;
 
assert clocks_per_6us_g > 1
report "clocks_per_6us_g must be at least 2!"
severity failure;
-- pragma translate_on
 
 
seq: process (reset_i, clk_i)
variable clocks_per_6us_overflow_v : boolean;
begin
if reset_i = reset_level_g then
pad_latch_q <= '1';
pad_clk_q <= '1';
 
num_buttons_read_q <= num_buttons_c-1;
 
clocks_per_6us_q <= 0;
 
state_q <= IDLE;
 
elsif clk_i'event and clk_i = '1' then
if clk_en_s then
clocks_per_6us_q <= 0;
else
clocks_per_6us_q <= clocks_per_6us_q + 1;
end if;
 
if clk_en_s and shift_buttons_s then
if num_buttons_read_q = 0 then
num_buttons_read_q <= num_buttons_c-1;
else
num_buttons_read_q <= num_buttons_read_q - 1;
end if;
end if;
 
if clk_en_s then
state_q <= state_s;
end if;
 
pad_clk_q <= pad_clk_s;
 
pad_latch_q <= pad_latch_s;
 
end if;
end process;
 
clk_en_s <= clocks_per_6us_q = clocks_per_6us_g-1;
 
 
fsm: process (state_q,
num_buttons_read_q)
begin
-- default assignments
pad_clk_s <= '1';
pad_latch_s <= '1';
shift_buttons_s <= false;
save_buttons_o <= false;
state_s <= IDLE;
 
case state_q is
when IDLE =>
save_buttons_o <= true;
state_s <= IDLE2;
 
when IDLE2 =>
state_s <= LATCH;
 
when LATCH =>
pad_latch_s <= '0';
state_s <= READ_PAD;
 
when READ_PAD =>
pad_latch_s <= '0';
-- set clock low
-- pad data will be read at end of 6us cycle
pad_clk_s <= '0';
 
shift_buttons_s <= true;
 
if num_buttons_read_q = 0 then
-- return to IDLE after last button bit has been read
state_s <= IDLE;
else
state_s <= LATCH;
end if;
 
when others =>
null;
 
end case;
 
end process fsm;
 
 
-----------------------------------------------------------------------------
-- Output Mapping
-----------------------------------------------------------------------------
clk_en_o <= clk_en_s;
shift_buttons_o <= shift_buttons_s;
pad_clk_o <= pad_clk_q;
pad_latch_o <= pad_latch_q;
 
end rtl;
 
 
-------------------------------------------------------------------------------
-- File History:
--
-- $Log: not supported by cvs2svn $
-------------------------------------------------------------------------------
/trunk/snespad/rtl/vhdl/snespad_pad-c.vhd
0,0 → 1,16
-------------------------------------------------------------------------------
--
-- SNESpad controller core
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- $Id: snespad_pad-c.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
--
-------------------------------------------------------------------------------
 
configuration snespad_pad_rtl_c0 of snespad_pad is
 
for rtl
end for;
 
end snespad_pad_rtl_c0;
/trunk/snespad/rtl/vhdl/snespad_pad.vhd
0,0 → 1,154
-------------------------------------------------------------------------------
--
-- SNESpad controller core
--
-- $Id: snespad_pad.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- All rights reserved
--
-- Redistribution and use in source and synthezised forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- Redistributions in synthesized form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- Neither the name of the author nor the names of other contributors may
-- be used to endorse or promote products derived from this software without
-- specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--
-- Please report bugs to the author, but before you do so, please
-- make sure that this is not a derivative work and that
-- you have the latest version of this file.
--
-- The latest version of this file can be found at:
-- http://www.opencores.org/cvsweb.shtml/gamepads/
--
-- The project homepage is located at:
-- http://www.opencores.org/projects.cgi/web/gamepads/overview
--
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
 
entity snespad_pad is
 
generic (
reset_level_g : natural := 0;
button_level_g : natural := 0
);
port (
-- System Interface -------------------------------------------------------
clk_i : in std_logic;
reset_i : in std_logic;
clk_en_i : in boolean;
-- Control Interface ------------------------------------------------------
shift_buttons_i : in boolean;
save_buttons_i : in boolean;
-- Pad Interface ----------------------------------------------------------
pad_data_i : in std_logic;
-- Buttons Interface ------------------------------------------------------
but_a_o : out std_logic;
but_b_o : out std_logic;
but_x_o : out std_logic;
but_y_o : out std_logic;
but_start_o : out std_logic;
but_sel_o : out std_logic;
but_tl_o : out std_logic;
but_tr_o : out std_logic;
but_up_o : out std_logic;
but_down_o : out std_logic;
but_left_o : out std_logic;
but_right_o : out std_logic
);
 
end snespad_pad;
 
 
use work.snespad_pack.all;
 
architecture rtl of snespad_pad is
 
signal buttons_q,
shift_buttons_q : buttons_t;
 
begin
 
-- pragma translate_off
-----------------------------------------------------------------------------
-- Check generics
-----------------------------------------------------------------------------
assert (reset_level_g = 0) or (reset_level_g = 1)
report "reset_level_g must be either 0 or 1!"
severity failure;
 
assert (button_level_g = 0) or (button_level_g = 1)
report "button_level_g must be either 0 or 1!"
severity failure;
-- pragma translate_on
 
seq: process (reset_i, clk_i)
variable mult_6us_overflow_v : boolean;
begin
if reset_i = reset_level_g then
for i in buttons_t'range loop
buttons_q(i) <= button_reset_f(button_level_g);
shift_buttons_q(i) <= button_reset_f(button_level_g);
end loop;
 
elsif clk_i'event and clk_i = '1' then
if save_buttons_i then
buttons_q <= shift_buttons_q;
end if;
 
if clk_en_i and shift_buttons_i then
shift_buttons_q(buttons_t'high downto 1) <= shift_buttons_q(buttons_t'high-1 downto 0);
shift_buttons_q(0) <= button_active_f(pad_data_i, button_level_g);
end if;
 
end if;
end process;
 
 
-----------------------------------------------------------------------------
-- Output Mapping
-----------------------------------------------------------------------------
but_a_o <= buttons_q(but_pos_a_c);
but_b_o <= buttons_q(but_pos_b_c);
but_x_o <= buttons_q(but_pos_x_c);
but_y_o <= buttons_q(but_pos_y_c);
but_start_o <= buttons_q(but_pos_start_c);
but_sel_o <= buttons_q(but_pos_sel_c);
but_tl_o <= buttons_q(but_pos_tl_c);
but_tr_o <= buttons_q(but_pos_tr_c);
but_up_o <= buttons_q(but_pos_up_c);
but_down_o <= buttons_q(but_pos_down_c);
but_left_o <= buttons_q(but_pos_left_c);
but_right_o <= buttons_q(but_pos_right_c);
 
end rtl;
 
 
-------------------------------------------------------------------------------
-- File History:
--
-- $Log: not supported by cvs2svn $
-------------------------------------------------------------------------------
/trunk/snespad/rtl/vhdl/snespad_pack-p.vhd
0,0 → 1,94
-------------------------------------------------------------------------------
--
-- SNESpad controller core
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- $Id: snespad_pack-p.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
--
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
 
package snespad_pack is
 
constant num_buttons_c : natural := 12;
subtype buttons_t is std_logic_vector(num_buttons_c-1 downto 0);
subtype num_buttons_read_t is natural range 0 to num_buttons_c-1;
 
function button_active_f(state : in std_logic; ref : in natural) return std_logic;
function button_reset_f(ref : in natural) return std_logic;
function "=" (a : std_logic; b : integer) return boolean;
 
-----------------------------------------------------------------------------
-- The button positions inside the SNES packet
-----------------------------------------------------------------------------
constant but_pos_b_c : natural := 11;
constant but_pos_y_c : natural := 10;
constant but_pos_sel_c : natural := 9;
constant but_pos_start_c : natural := 8;
constant but_pos_up_c : natural := 7;
constant but_pos_down_c : natural := 6;
constant but_pos_left_c : natural := 5;
constant but_pos_right_c : natural := 4;
constant but_pos_a_c : natural := 3;
constant but_pos_x_c : natural := 2;
constant but_pos_tl_c : natural := 1;
constant but_pos_tr_c : natural := 0;
 
end snespad_pack;
 
 
package body snespad_pack is
 
function button_active_f(state : in std_logic; ref : in natural) return std_logic is
variable result_v : std_logic;
begin
if ref = 0 then
result_v := state;
else
result_v := not state;
end if;
 
return result_v;
end button_active_f;
 
function button_reset_f(ref : in natural) return std_logic is
variable result_v : std_logic;
begin
if ref = 0 then
result_v := '1';
else
result_v := '0';
end if;
 
return result_v;
end button_reset_f;
 
function "=" (a : std_logic; b : integer) return boolean is
variable result_v : boolean;
begin
result_v := false;
 
case a is
when '0' =>
if b = 0 then
result_v := true;
end if;
 
when '1' =>
if b = 1 then
result_v := true;
end if;
 
when others =>
null;
 
end case;
 
return result_v;
end;
 
 
end snespad_pack;
/trunk/snespad/rtl/vhdl/snespad-c.vhd
0,0 → 1,25
-------------------------------------------------------------------------------
--
-- SNESpad controller core
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- $Id: snespad-c.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
--
-------------------------------------------------------------------------------
 
configuration snespad_struct_c0 of snespad is
 
for struct
for ctrl_b : snespad_ctrl
use configuration work.snespad_ctrl_rtl_c0;
end for;
 
for pads
for pad_b : snespad_pad
use configuration work.snespad_pad_rtl_c0;
end for;
end for;
end for;
 
end snespad_struct_c0;
/trunk/snespad/rtl/vhdl/snespad.vhd
0,0 → 1,189
-------------------------------------------------------------------------------
--
-- SNESpad controller core
--
-- $Id: snespad.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
--
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
--
-- All rights reserved
--
-- Redistribution and use in source and synthezised forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- Redistributions in synthesized form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- Neither the name of the author nor the names of other contributors may
-- be used to endorse or promote products derived from this software without
-- specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--
-- Please report bugs to the author, but before you do so, please
-- make sure that this is not a derivative work and that
-- you have the latest version of this file.
--
-- The latest version of this file can be found at:
-- http://www.opencores.org/cvsweb.shtml/gamepads/
--
-- The project homepage is located at:
-- http://www.opencores.org/projects.cgi/web/gamepads/overview
--
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
 
entity snespad is
 
generic (
num_pads_g : natural := 1;
reset_level_g : natural := 0;
button_level_g : natural := 0;
clocks_per_6us_g : natural := 6
);
port (
-- System Interface -------------------------------------------------------
clk_i : in std_logic;
reset_i : in std_logic;
-- Gamepad Interface ------------------------------------------------------
pad_clk_o : out std_logic;
pad_latch_o : out std_logic;
pad_data_i : in std_logic_vector(num_pads_g-1 downto 0);
-- Buttons Interface ------------------------------------------------------
but_a_o : out std_logic_vector(num_pads_g-1 downto 0);
but_b_o : out std_logic_vector(num_pads_g-1 downto 0);
but_x_o : out std_logic_vector(num_pads_g-1 downto 0);
but_y_o : out std_logic_vector(num_pads_g-1 downto 0);
but_start_o : out std_logic_vector(num_pads_g-1 downto 0);
but_sel_o : out std_logic_vector(num_pads_g-1 downto 0);
but_tl_o : out std_logic_vector(num_pads_g-1 downto 0);
but_tr_o : out std_logic_vector(num_pads_g-1 downto 0);
but_up_o : out std_logic_vector(num_pads_g-1 downto 0);
but_down_o : out std_logic_vector(num_pads_g-1 downto 0);
but_left_o : out std_logic_vector(num_pads_g-1 downto 0);
but_right_o : out std_logic_vector(num_pads_g-1 downto 0)
);
 
end snespad;
 
 
architecture struct of snespad is
 
component snespad_ctrl
generic (
reset_level_g : natural := 0;
clocks_per_6us_g : natural := 6
);
port (
clk_i : in std_logic;
reset_i : in std_logic;
clk_en_o : out boolean;
shift_buttons_o : out boolean;
save_buttons_o : out boolean;
pad_clk_o : out std_logic;
pad_latch_o : out std_logic
);
end component snespad_ctrl;
 
component snespad_pad
generic (
reset_level_g : natural := 0;
button_level_g : natural := 0
);
port (
clk_i : in std_logic;
reset_i : in std_logic;
clk_en_i : in boolean;
shift_buttons_i : in boolean;
save_buttons_i : in boolean;
pad_data_i : in std_logic;
but_a_o : out std_logic;
but_b_o : out std_logic;
but_x_o : out std_logic;
but_y_o : out std_logic;
but_start_o : out std_logic;
but_sel_o : out std_logic;
but_tl_o : out std_logic;
but_tr_o : out std_logic;
but_up_o : out std_logic;
but_down_o : out std_logic;
but_left_o : out std_logic;
but_right_o : out std_logic
);
end component snespad_pad;
 
 
signal clk_en_s : boolean;
signal shift_buttons_s : boolean;
signal save_buttons_s : boolean;
 
begin
 
ctrl_b : snespad_ctrl
generic map (
reset_level_g => reset_level_g,
clocks_per_6us_g => clocks_per_6us_g
)
port map (
clk_i => clk_i,
reset_i => reset_i,
clk_en_o => clk_en_s,
shift_buttons_o => shift_buttons_s,
save_buttons_o => save_buttons_s,
pad_clk_o => pad_clk_o,
pad_latch_o => pad_latch_o
);
 
 
pads: for i in 0 to num_pads_g-1 generate
pad_b : snespad_pad
generic map (
reset_level_g => reset_level_g,
button_level_g => button_level_g
)
port map (
clk_i => clk_i,
reset_i => reset_i,
clk_en_i => clk_en_s,
shift_buttons_i => shift_buttons_s,
save_buttons_i => save_buttons_s,
pad_data_i => pad_data_i(i),
but_a_o => but_a_o(i),
but_b_o => but_b_o(i),
but_x_o => but_x_o(i),
but_y_o => but_y_o(i),
but_start_o => but_start_o(i),
but_sel_o => but_sel_o(i),
but_tl_o => but_tl_o(i),
but_tr_o => but_tr_o(i),
but_up_o => but_up_o(i),
but_down_o => but_down_o(i),
but_left_o => but_left_o(i),
but_right_o => but_right_o(i)
);
end generate;
 
end struct;
 
 
-------------------------------------------------------------------------------
-- File History:
--
-- $Log: not supported by cvs2svn $
-------------------------------------------------------------------------------
/trunk/snespad/sim/rtl_sim/Makefile
0,0 → 1,67
 
 
PROJECT_DIR = ../..
RTL_DIR = $(PROJECT_DIR)/rtl/vhdl
BENCH_DIR = $(PROJECT_DIR)/bench/vhdl
 
 
 
ANALYZE=ghdl -a --std=87 --workdir=work
ELABORATE=ghdl -e --std=87 --workdir=work
 
.PHONY: all
all: work elaborate
 
work:
mkdir work
 
work/snespad_pack-p.o: $(RTL_DIR)/snespad_pack-p.vhd
$(ANALYZE) $(RTL_DIR)/snespad_pack-p.vhd
 
work/snespad_ctrl.o: $(RTL_DIR)/snespad_ctrl.vhd \
work/snespad_pack-p.o
$(ANALYZE) $(RTL_DIR)/snespad_ctrl.vhd
work/snespad_ctrl-c.o: $(RTL_DIR)/snespad_ctrl-c.vhd \
work/snespad_ctrl.o
$(ANALYZE) $(RTL_DIR)/snespad_ctrl-c.vhd
 
work/snespad_pad.o: $(RTL_DIR)/snespad_pad.vhd \
work/snespad_pack-p.o
$(ANALYZE) $(RTL_DIR)/snespad_pad.vhd
work/snespad_pad-c.o: $(RTL_DIR)/snespad_pad-c.vhd \
work/snespad_pad.o
$(ANALYZE) $(RTL_DIR)/snespad_pad-c.vhd
 
work/snespad.o: $(RTL_DIR)/snespad.vhd \
work/snespad_pack-p.o \
work/snespad_ctrl.o \
work/snespad_pad.o
$(ANALYZE) $(RTL_DIR)/snespad.vhd
work/snespad-c.o: $(RTL_DIR)/snespad-c.vhd \
work/snespad.o \
work/snespad_ctrl-c.o \
work/snespad_pad-c.o
$(ANALYZE) $(RTL_DIR)/snespad-c.vhd
 
work/tb.o: $(BENCH_DIR)/tb.vhd \
work/snespad.o
$(ANALYZE) $(BENCH_DIR)/tb.vhd
work/tb-c.o: $(BENCH_DIR)/tb-c.vhd \
work/tb.o \
work/snespad-c.o
$(ANALYZE) $(BENCH_DIR)/tb-c.vhd
 
 
.PHONY: elaborate
elaborate: tb_behav_c0
 
tb_behav_c0: analyze
$(ELABORATE) tb_behav_c0; \
strip tb_behav_c0
 
.PHONY: analyze
analyze: work/tb-c.o
 
.PHONY: clean
clean:
rm -rf work tb_behav_c0 *~

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.