OSDN Git Service

adae47061f20455cf50d927e8ff57c0d5738dfce
[motonesfpga/motonesfpga.git] / de1_nes / ppu / ppu_registers.vhd
1 --------------------------------
2 ----------shift registers -----
3 --------------------------------
4 library ieee;
5 use ieee.std_logic_1164.all;
6
7 entity shift_register is 
8     generic (
9         dsize : integer := 8;
10         shift : integer := 1
11     );
12     port (  clk         : in std_logic;
13             rst_n       : in std_logic;
14             ce_n        : in std_logic;
15             we_n        : in std_logic;
16             d           : in std_logic_vector(dsize - 1 downto 0);
17             q           : out std_logic_vector(dsize - 1 downto 0)
18     );
19 end shift_register;
20
21 architecture rtl of shift_register is
22
23 component d_flip_flop
24     generic (
25             dsize : integer := 8
26             );
27     port (  
28             clk     : in std_logic;
29             res_n   : in std_logic;
30             set_n   : in std_logic;
31             we_n    : in std_logic;
32             d       : in std_logic_vector (dsize - 1 downto 0);
33             q       : out std_logic_vector (dsize - 1 downto 0)
34         );
35 end component;
36
37 signal dff_we_n : std_logic;
38 signal q_out : std_logic_vector(dsize - 1 downto 0);
39 signal df_in : std_logic_vector(dsize - 1 downto 0);
40
41 begin
42
43     q <= q_out;
44     dff_we_n <= ce_n and we_n;
45     dff_inst : d_flip_flop generic map (dsize)
46             port map (clk, rst_n, '1', dff_we_n, df_in, q_out);
47
48     clk_p : process (clk, we_n, ce_n, d) 
49     begin
50         if (we_n = '0') then
51             df_in <= d;
52         elsif (ce_n = '0') then
53             df_in (dsize - 1 downto dsize - shift) <= (others => '0');
54             df_in (dsize - shift - 1  downto 0) <= 
55                 q_out(dsize - 1 downto shift);
56         end if;
57     end process;
58
59 end rtl;
60
61 -------------------------------
62 -- LS373 transparent D-latch---
63 -------------------------------
64 library ieee;
65 use ieee.std_logic_1164.all;
66
67 entity ls373 is 
68     generic (
69         dsize : integer := 8
70     );
71     port (  c         : in std_logic;
72             oc_n      : in std_logic;
73             d         : in std_logic_vector(dsize - 1 downto 0);
74             q         : out std_logic_vector(dsize - 1 downto 0)
75     );
76 end ls373;
77
78 architecture rtl of ls373 is
79
80 component data_latch
81     generic (
82             dsize : integer := 8
83             );
84     port (  
85             clk     : in std_logic;
86             d       : in std_logic_vector (dsize - 1 downto 0);
87             q       : out std_logic_vector (dsize - 1 downto 0)
88         );
89 end component;
90
91 component tri_state_buffer
92     generic (
93             dsize : integer := 8
94             );
95     port (  
96             oe_n    : in std_logic;
97             d       : in std_logic_vector (dsize - 1 downto 0);
98             q       : out std_logic_vector (dsize - 1 downto 0)
99         );
100 end component;
101
102 signal q_out       : std_logic_vector (dsize - 1 downto 0);
103
104 begin
105     ls373_inst : data_latch generic map (dsize)
106             port map (c, d, q_out);
107     tsb_inst : tri_state_buffer generic map (dsize)
108             port map (oc_n, q_out, q);
109 end rtl;
110