OSDN Git Service

8112b09ef57525d90b1577424c6795c53bb93120
[motonesfpga/motonesfpga.git] / tools / qt_proj_test5 / vga.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.all;
4
5 entity dummy_ppu is 
6     port (  ppu_clk     : in std_logic;
7             rst_n       : in std_logic;
8             pos_x       : buffer std_logic_vector (8 downto 0);
9             pos_y       : buffer std_logic_vector (8 downto 0);
10             nes_r       : buffer std_logic_vector (3 downto 0);
11             nes_g       : buffer std_logic_vector (3 downto 0);
12             nes_b       : buffer std_logic_vector (3 downto 0)
13     );
14 end dummy_ppu;
15
16
17 architecture rtl of dummy_ppu is
18
19 component counter_register
20     generic (
21         dsize       : integer := 8;
22         inc         : integer := 1
23     );
24     port (  clk         : in std_logic;
25             rst_n       : in std_logic;
26             ce_n        : in std_logic;
27             we_n        : in std_logic;
28             d           : in std_logic_vector(dsize - 1 downto 0);
29             q           : out std_logic_vector(dsize - 1 downto 0)
30     );
31 end component;
32
33 signal x_res_n, y_res_n, y_en_n : std_logic;
34 signal cnt_clk : std_logic;
35 signal frame_en_n : std_logic;
36
37
38 signal frame_cnt : std_logic_vector(7 downto 0);
39
40 begin
41
42     cnt_clk <= not ppu_clk;
43     x_inst : counter_register generic map (9, 1)
44             port map (cnt_clk , x_res_n, '0', '1', (others => '0'), pos_x);
45     y_inst : counter_register generic map (9, 1)
46             port map (cnt_clk , y_res_n, y_en_n, '1', (others => '0'), pos_y);
47
48     frame_cnt_inst : counter_register generic map (8, 1)
49             port map (cnt_clk , rst_n, frame_en_n, '1', (others => '0'), frame_cnt);
50
51     
52     p_write : process (rst_n, ppu_clk)
53     begin
54         if (rst_n = '0') then
55             x_res_n <= '0';
56             y_res_n <= '0';
57             frame_en_n <= '1';
58             nes_r <= (others => '0');
59             nes_g <= (others => '0');
60             nes_b <= (others => '0');
61         elsif (rising_edge(ppu_clk)) then
62             --xmax = 340
63             if (pos_x = "101010100") then
64                 x_res_n <= '0';
65                 y_en_n <= '0';
66                 --ymax=261
67                 if (pos_y = "100000101") then
68                     y_res_n <= '0';
69                     frame_en_n <= '0';
70                     nes_r <= nes_r + '1';
71                     nes_g <= nes_g + '1';
72                     nes_b <= nes_b + '1';
73                 else
74                     frame_en_n <= '1';
75                     y_res_n <= '1';
76                 end if;
77             else
78                 frame_en_n <= '1';
79                 x_res_n <= '1';
80                 y_en_n <= '1';
81                 y_res_n <= '1';
82             end if;
83         end if;
84     end process;
85 end rtl;
86
87
88
89 library ieee;
90 use ieee.std_logic_1164.all;
91 use ieee.std_logic_unsigned.conv_integer;
92 use ieee.std_logic_arith.conv_std_logic_vector;
93 use work.motonesfpga_common.all;
94
95 entity vga_ctl is 
96     port (  ppu_clk     : in std_logic;
97             vga_clk     : in std_logic;
98             rst_n       : in std_logic;
99             pos_x       : in std_logic_vector (8 downto 0);
100             pos_y       : in std_logic_vector (8 downto 0);
101             nes_r       : in std_logic_vector (3 downto 0);
102             nes_g       : in std_logic_vector (3 downto 0);
103             nes_b       : in std_logic_vector (3 downto 0);
104             h_sync_n    : out std_logic;
105             v_sync_n    : out std_logic;
106             r           : out std_logic_vector(3 downto 0);
107             g           : out std_logic_vector(3 downto 0);
108             b           : out std_logic_vector(3 downto 0)
109     );
110 end vga_ctl;
111
112 architecture rtl of vga_ctl is
113
114 component counter_register
115     generic (
116         dsize       : integer := 8;
117         inc         : integer := 1
118     );
119     port (  clk         : in std_logic;
120             rst_n       : in std_logic;
121             ce_n        : in std_logic;
122             we_n        : in std_logic;
123             d           : in std_logic_vector(dsize - 1 downto 0);
124             q           : out std_logic_vector(dsize - 1 downto 0)
125     );
126 end component;
127
128 constant VGA_W    : integer := 640;
129 constant VGA_H    : integer := 480;
130 constant VGA_W_MAX    : integer := 800;
131 constant VGA_H_MAX    : integer := 525;
132 constant H_SP    : integer := 95;
133 constant H_BP    : integer := 48;
134 constant H_FP    : integer := 15;
135
136 constant V_SP    : integer := 2;
137 constant V_BP    : integer := 33;
138 constant V_FP    : integer := 10;
139
140 signal vga_x       :  std_logic_vector (9 downto 0);
141 signal vga_y       :  std_logic_vector (9 downto 0);
142 signal x_res_n, y_res_n, y_en_n : std_logic;
143 signal cnt_clk : std_logic;
144
145 begin
146
147     cnt_clk <= not vga_clk;
148     x_inst : counter_register generic map (10, 1)
149             port map (cnt_clk , x_res_n, '0', '1', (others => '0'), vga_x);
150     y_inst : counter_register generic map (10, 1)
151             port map (cnt_clk , y_res_n, y_en_n, '1', (others => '0'), vga_y);
152     
153     p_vga : process (rst_n, vga_clk)
154     begin
155         if (rst_n = '0') then
156             h_sync_n <= '0';
157             v_sync_n <= '0';
158             x_res_n <= '0';
159             y_res_n <= '0';
160             r<=(others => '0');
161             g<=(others => '0');
162             b<=(others => '0');
163         elsif (rising_edge(vga_clk)) then
164             --xmax = 799
165             if (vga_x = "1100011111") then
166                 x_res_n <= '0';
167                 y_en_n <= '0';
168                 --ymax=524
169                 if (vga_y = "1000001100") then
170                     y_res_n <= '0';
171                 else
172                     y_res_n <= '1';
173                 end if;
174             else
175                 x_res_n <= '1';
176                 y_en_n <= '1';
177                 y_res_n <= '1';
178             end if;
179             
180             --sync signal assert.
181             if (vga_x >= conv_std_logic_vector((VGA_W + H_FP) , 10) and 
182                 vga_x < conv_std_logic_vector((VGA_W + H_FP + H_SP) , 10)) then
183                 h_sync_n <= '0';
184             else
185                 h_sync_n <= '1';
186             end if;
187
188             if (vga_y >= conv_std_logic_vector((VGA_H + V_FP) , 10) and 
189                 vga_y < conv_std_logic_vector((VGA_H + V_FP + V_SP) , 10)) then
190                 v_sync_n <= '0';
191             else
192                 v_sync_n <= '1';
193             end if;
194
195
196             if (vga_y <=conv_std_logic_vector((VGA_H) , 10)) then
197                 if (vga_x < conv_std_logic_vector((VGA_W) , 10)) then
198 --                    r<=nes_r;
199 --                    g<=nes_g;
200 --                    b<=nes_b;
201                     r<=(others => '1');
202                     g<=(others => '1');
203                     b<=(others => '1');
204                 else
205                     r<=(others => '0');
206                     g<=(others => '0');
207                     b<=(others => '0');
208                 end if;
209             else
210                 r<=(others => '0');
211                 g<=(others => '0');
212                 b<=(others => '0');
213             end if;
214         end if;
215     end process;
216
217
218
219 --
220 --constant VGA_W    : integer := 256;
221 --constant VGA_H    : integer := 240;
222 --constant VGA_W_MAX    : integer := 341;
223 --constant VGA_H_MAX    : integer := 262;
224 --
225 --constant H_SP    : integer := (95 / 2);
226 --constant H_FP    : integer := (15 / 2);
227 --
228 --constant V_SP    : integer := (2 / 2);
229 --constant V_FP    : integer := (10 / 2);
230 --
231 --begin
232 --
233 --    p_vga : process (rst_n, vga_clk)
234 --    begin
235 --        if (rst_n = '0') then
236 --            h_sync_n <= '0';
237 --            v_sync_n <= '0';
238 --            r<=(others => '0');
239 --            g<=(others => '0');
240 --            b<=(others => '0');
241 --        elsif (rising_edge(vga_clk)) then
242 --            
243 --            --sync signal assert.
244 --            if (pos_x >= conv_std_logic_vector(VGA_W + H_FP , 9) and 
245 --                pos_x < conv_std_logic_vector(VGA_W + H_FP + H_SP, 9)) then
246 --                h_sync_n <= '0';
247 --            else
248 --                h_sync_n <= '1';
249 --            end if;
250 --
251 --            if (pos_y >= conv_std_logic_vector(VGA_H + V_FP, 9) and 
252 --                pos_y < conv_std_logic_vector(VGA_H + V_FP + V_SP, 9)) then
253 --                v_sync_n <= '0';
254 --            else
255 --                v_sync_n <= '1';
256 --            end if;
257 --
258 --            if (pos_y <=conv_std_logic_vector(VGA_H, 9)) then
259 --                if (pos_x < conv_std_logic_vector(VGA_W, 9)) then
260 --                    r<=(others => '1');
261 --                    g<=(others => '1');
262 --                    b<=(others => '1');
263 --                else
264 --                    r<=(others => '0');
265 --                    g<=(others => '0');
266 --                    b<=(others => '0');
267 --                end if;
268 --            else
269 --                r<=(others => '0');
270 --                g<=(others => '0');
271 --                b<=(others => '0');
272 --            end if;
273 --        end if;
274 --    end process;
275 end rtl;
276
277
278