OSDN Git Service

vga rendering start.
[motonesfpga/motonesfpga.git] / de0_cv_nes / ppu / render.vhd
1 -------------------------------------------------------------\r
2 -------------------------------------------------------------\r
3 ------------------- PPU VGA Output Control ------------------\r
4 -------------------------------------------------------------\r
5 -------------------------------------------------------------\r
6 library ieee;\r
7 use ieee.std_logic_1164.all;\r
8 use ieee.std_logic_unsigned.conv_integer;\r
9 use ieee.std_logic_arith.conv_std_logic_vector;\r
10 use ieee.std_logic_unsigned.all;\r
11 \r
12 entity render is \r
13     port (\r
14         pi_rst_n       : in std_logic;\r
15         pi_base_clk    : in std_logic;\r
16 \r
17         --ppu i/f\r
18         pi_ppu_ctrl        : in std_logic_vector (7 downto 0);\r
19         pi_ppu_mask        : in std_logic_vector (7 downto 0);\r
20         po_ppu_status      : out std_logic_vector (7 downto 0);\r
21         pi_ppu_scroll_x    : in std_logic_vector (7 downto 0);\r
22         pi_ppu_scroll_y    : in std_logic_vector (7 downto 0);\r
23 \r
24         --vram i/f\r
25         po_rd_n         : out std_logic;\r
26         po_wr_n         : out std_logic;\r
27         po_v_addr       : out std_logic_vector (13 downto 0);\r
28         io_v_data       : in std_logic_vector (7 downto 0);\r
29 \r
30         --sprite i/f\r
31         po_spr_ce_n     : out std_logic;\r
32         po_spr_rd_n     : out std_logic;\r
33         po_spr_wr_n     : out std_logic;\r
34         po_spr_addr     : out std_logic_vector (7 downto 0);\r
35         pi_spr_data     : in std_logic_vector (7 downto 0);\r
36 \r
37         --vga output\r
38         po_h_sync_n    : out std_logic;\r
39         po_v_sync_n    : out std_logic;\r
40         po_r           : out std_logic_vector(3 downto 0);\r
41         po_g           : out std_logic_vector(3 downto 0);\r
42         po_b           : out std_logic_vector(3 downto 0)\r
43         );\r
44 end render;\r
45 \r
46 architecture rtl of render is\r
47 \r
48 \r
49 --------- VGA screen constant -----------\r
50 constant VGA_W          : integer := 640;\r
51 constant VGA_H          : integer := 480;\r
52 constant VGA_W_MAX      : integer := 800;\r
53 constant VGA_H_MAX      : integer := 525;\r
54 constant H_SP           : integer := 95;\r
55 constant H_BP           : integer := 48;\r
56 constant H_FP           : integer := 15;\r
57 constant V_SP           : integer := 2;\r
58 constant V_BP           : integer := 33;\r
59 constant V_FP           : integer := 10;\r
60 \r
61 --nes screen size is emulated to align with the vga timing...\r
62 constant HSCAN                  : integer := 256;\r
63 constant VSCAN                  : integer := 240;\r
64 constant HSCAN_NEXT_START       : integer := 382;\r
65 constant VSCAN_NEXT_START       : integer := 262;\r
66 constant HSCAN_SPR_MAX          : integer := 321;\r
67 constant HSCAN_OAM_EVA_START    : integer := 64;\r
68 \r
69 constant PPUBNA    : integer := 1;  --base name address\r
70 constant PPUVAI    : integer := 2;  --vram address increment\r
71 constant PPUSPA    : integer := 3;  --sprite pattern table address\r
72 constant PPUBPA    : integer := 4;  --background pattern table address\r
73 constant PPUSPS    : integer := 5;  --sprite size\r
74 constant PPUMS     : integer := 6;  --ppu master/slave\r
75 constant PPUNEN    : integer := 7;  --nmi enable\r
76 \r
77 constant PPUGS     : integer := 0;  --grayscale\r
78 constant PPUSBL    : integer := 1;  --show 8 left most bg pixel\r
79 constant PPUSSL    : integer := 2;  --show 8 left most sprite pixel\r
80 constant PPUSBG    : integer := 3;  --show bg\r
81 constant PPUSSP    : integer := 4;  --show sprie\r
82 constant PPUIR     : integer := 5;  --intensify red\r
83 constant PPUIG     : integer := 6;  --intensify green\r
84 constant PPUIB     : integer := 7;  --intensify blue\r
85 \r
86 constant SPRHFL     : integer := 6;  --flip sprigte horizontally\r
87 constant SPRVFL     : integer := 7;  --flip sprigte vertically\r
88 \r
89 constant ST_BSY     : integer := 4;  --vram busy\r
90 constant ST_SOF     : integer := 5;  --sprite overflow\r
91 constant ST_SP0     : integer := 6;  --sprite 0 hits\r
92 constant ST_VBL     : integer := 7;  --vblank\r
93 \r
94 \r
95 subtype nes_color_data  is std_logic_vector (11 downto 0);\r
96 type nes_color_array    is array (0 to 63) of nes_color_data;\r
97 --ref: http://hlc6502.web.fc2.com/NesPal2.htm\r
98 constant nes_color_palette : nes_color_array := (\r
99         conv_std_logic_vector(16#777#, 12), \r
100         conv_std_logic_vector(16#20b#, 12), \r
101         conv_std_logic_vector(16#20b#, 12), \r
102         conv_std_logic_vector(16#61a#, 12), \r
103         conv_std_logic_vector(16#927#, 12), \r
104         conv_std_logic_vector(16#b13#, 12), \r
105         conv_std_logic_vector(16#a30#, 12), \r
106         conv_std_logic_vector(16#740#, 12), \r
107         conv_std_logic_vector(16#450#, 12), \r
108         conv_std_logic_vector(16#360#, 12), \r
109         conv_std_logic_vector(16#360#, 12), \r
110         conv_std_logic_vector(16#364#, 12), \r
111         conv_std_logic_vector(16#358#, 12), \r
112         conv_std_logic_vector(16#000#, 12), \r
113         conv_std_logic_vector(16#000#, 12), \r
114         conv_std_logic_vector(16#000#, 12),\r
115         conv_std_logic_vector(16#bbb#, 12), \r
116         conv_std_logic_vector(16#46f#, 12), \r
117         conv_std_logic_vector(16#44f#, 12), \r
118         conv_std_logic_vector(16#94f#, 12), \r
119         conv_std_logic_vector(16#d4c#, 12), \r
120         conv_std_logic_vector(16#d46#, 12), \r
121         conv_std_logic_vector(16#e50#, 12), \r
122         conv_std_logic_vector(16#c70#, 12), \r
123         conv_std_logic_vector(16#880#, 12), \r
124         conv_std_logic_vector(16#5a0#, 12), \r
125         conv_std_logic_vector(16#4a1#, 12), \r
126         conv_std_logic_vector(16#4a6#, 12), \r
127         conv_std_logic_vector(16#49c#, 12), \r
128         conv_std_logic_vector(16#000#, 12), \r
129         conv_std_logic_vector(16#000#, 12), \r
130         conv_std_logic_vector(16#000#, 12),\r
131         conv_std_logic_vector(16#fff#, 12), \r
132         conv_std_logic_vector(16#6af#, 12), \r
133         conv_std_logic_vector(16#58f#, 12), \r
134         conv_std_logic_vector(16#a7f#, 12), \r
135         conv_std_logic_vector(16#f6f#, 12), \r
136         conv_std_logic_vector(16#f6b#, 12), \r
137         conv_std_logic_vector(16#f73#, 12), \r
138         conv_std_logic_vector(16#fa0#, 12), \r
139         conv_std_logic_vector(16#ed2#, 12), \r
140         conv_std_logic_vector(16#9e0#, 12), \r
141         conv_std_logic_vector(16#7f4#, 12), \r
142         conv_std_logic_vector(16#7e9#, 12), \r
143         conv_std_logic_vector(16#6de#, 12), \r
144         conv_std_logic_vector(16#777#, 12), \r
145         conv_std_logic_vector(16#000#, 12), \r
146         conv_std_logic_vector(16#000#, 12),\r
147         conv_std_logic_vector(16#fff#, 12), \r
148         conv_std_logic_vector(16#9df#, 12), \r
149         conv_std_logic_vector(16#abf#, 12), \r
150         conv_std_logic_vector(16#cbf#, 12), \r
151         conv_std_logic_vector(16#ebf#, 12), \r
152         conv_std_logic_vector(16#fbe#, 12), \r
153         conv_std_logic_vector(16#fcb#, 12), \r
154         conv_std_logic_vector(16#fda#, 12), \r
155         conv_std_logic_vector(16#ff9#, 12), \r
156         conv_std_logic_vector(16#cf8#, 12), \r
157         conv_std_logic_vector(16#afa#, 12), \r
158         conv_std_logic_vector(16#afc#, 12), \r
159         conv_std_logic_vector(16#aff#, 12), \r
160         conv_std_logic_vector(16#aaa#, 12), \r
161         conv_std_logic_vector(16#000#, 12), \r
162         conv_std_logic_vector(16#000#, 12)\r
163         );\r
164 \r
165 signal reg_vga_x        : std_logic_vector (9 downto 0);\r
166 signal reg_vga_y        : std_logic_vector (9 downto 0);\r
167 \r
168 signal reg_nes_x        : std_logic_vector (8 downto 0);\r
169 signal reg_nes_y        : std_logic_vector (8 downto 0);\r
170 \r
171 begin\r
172     \r
173 end rtl;\r
174 \r