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

Subversion Repositories gamepads

[/] [gamepads/] [trunk/] [snespad/] [rtl/] [vhdl/] [snespad_pack-p.vhd] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 arniml
-------------------------------------------------------------------------------
2
--
3
-- SNESpad controller core
4
--
5
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
6
--
7
-- $Id: snespad_pack-p.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
8
--
9
-------------------------------------------------------------------------------
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
 
14
package snespad_pack is
15
 
16
  constant num_buttons_c : natural := 12;
17
  subtype  buttons_t is std_logic_vector(num_buttons_c-1 downto 0);
18
  subtype  num_buttons_read_t is natural range 0 to num_buttons_c-1;
19
 
20
  function button_active_f(state : in std_logic; ref : in natural) return std_logic;
21
  function button_reset_f(ref : in natural) return std_logic;
22
  function "=" (a : std_logic; b : integer) return boolean;
23
 
24
  -----------------------------------------------------------------------------
25
  -- The button positions inside the SNES packet
26
  -----------------------------------------------------------------------------
27
  constant but_pos_b_c     : natural := 11;
28
  constant but_pos_y_c     : natural := 10;
29
  constant but_pos_sel_c   : natural := 9;
30
  constant but_pos_start_c : natural := 8;
31
  constant but_pos_up_c    : natural := 7;
32
  constant but_pos_down_c  : natural := 6;
33
  constant but_pos_left_c  : natural := 5;
34
  constant but_pos_right_c : natural := 4;
35
  constant but_pos_a_c     : natural := 3;
36
  constant but_pos_x_c     : natural := 2;
37
  constant but_pos_tl_c    : natural := 1;
38
  constant but_pos_tr_c    : natural := 0;
39
 
40
end snespad_pack;
41
 
42
 
43
package body snespad_pack is
44
 
45
  function button_active_f(state : in std_logic; ref : in natural) return std_logic is
46
    variable result_v : std_logic;
47
  begin
48
    if ref = 0 then
49
      result_v := state;
50
    else
51
      result_v := not state;
52
    end if;
53
 
54
    return result_v;
55
  end button_active_f;
56
 
57
  function button_reset_f(ref : in natural) return std_logic is
58
    variable result_v : std_logic;
59
  begin
60
    if ref = 0 then
61
      result_v := '1';
62
    else
63
      result_v := '0';
64
    end if;
65
 
66
    return result_v;
67
  end button_reset_f;
68
 
69
  function "=" (a : std_logic; b : integer) return boolean is
70
    variable result_v : boolean;
71
  begin
72
    result_v := false;
73
 
74
    case a is
75
      when '0' =>
76
        if b = 0 then
77
          result_v := true;
78
        end if;
79
 
80
      when '1' =>
81
        if b = 1 then
82
          result_v := true;
83
        end if;
84
 
85
      when others =>
86
        null;
87
 
88
    end case;
89
 
90
    return result_v;
91
  end;
92
 
93
 
94
end snespad_pack;

powered by: WebSVN 2.1.0

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