OSDN Git Service

latch clean up
[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     port (\r
69             dbg_vl_we_n     : out std_logic;\r
70 \r
71             clk         : in std_logic;\r
72             rst_n       : in std_logic;\r
73             ale         : in std_logic;\r
74             vram_a      : in std_logic_vector (13 downto 8);\r
75             vram_ad     : in std_logic_vector (7 downto 0);\r
76             v_addr      : out std_logic_vector (13 downto 0)\r
77             );
78 end ls373;
79
80 architecture rtl of ls373 is
81
82 component d_flip_flop\r
83     generic (\r
84             dsize : integer := 8\r
85             );\r
86     port (  clk     : in std_logic;\r
87             res_n   : in std_logic;\r
88             set_n   : in std_logic;\r
89             we_n    : in std_logic;\r
90             d       : in std_logic_vector (dsize - 1 downto 0);\r
91             q       : out std_logic_vector (dsize - 1 downto 0)\r
92         );\r
93 end component;\r
94
95 signal d_in     : std_logic_vector(13 downto 0);\r
96 signal we_n     : std_logic;\r
97
98 begin\r
99     dbg_vl_we_n <= we_n;\r
100 \r
101     d_in <= vram_a & vram_ad;\r
102     we_n <= '0' when ale = '1' else\r
103             '1';
104     out_reg_inst : d_flip_flop generic map (14)\r
105             port map (clk, rst_n, '1', we_n, d_in, v_addr);\r
106 end rtl;
107