From 77b0a73ac35aa34ec2a36b7f1523a35e2cd586cb Mon Sep 17 00:00:00 2001 From: astoria-d Date: Sun, 1 Sep 2013 10:45:07 +0900 Subject: [PATCH] - DE1 board initial commit - vga and cpu/ppu clock unified. vga = ppu x 2 multipled. clock driver updted. --- de1_nes/.gitignore | 6 + de1_nes/clock/clock_divider.vhd | 71 +++++ de1_nes/cpu/cpu_registers.vhd | 492 +++++++++++++++++++++++++++++++++++ de1_nes/de1_nes.dpf | 12 + de1_nes/de1_nes.pin | 559 ++++++++++++++++++++++++++++++++++++++++ de1_nes/de1_nes.qpf | 23 ++ de1_nes/de1_nes.qsf | 48 ++++ de1_nes/de1_nes.qws | 22 ++ de1_nes/de1_nes.vhd | 154 +++++++++++ de1_nes/de1_nes.vwf | 186 +++++++++++++ de1_nes/ppu/ppu_registers.vhd | 170 ++++++++++++ 11 files changed, 1743 insertions(+) create mode 100644 de1_nes/.gitignore create mode 100644 de1_nes/clock/clock_divider.vhd create mode 100644 de1_nes/cpu/cpu_registers.vhd create mode 100644 de1_nes/de1_nes.dpf create mode 100644 de1_nes/de1_nes.pin create mode 100644 de1_nes/de1_nes.qpf create mode 100644 de1_nes/de1_nes.qsf create mode 100644 de1_nes/de1_nes.qws create mode 100644 de1_nes/de1_nes.vhd create mode 100644 de1_nes/de1_nes.vwf create mode 100644 de1_nes/ppu/ppu_registers.vhd diff --git a/de1_nes/.gitignore b/de1_nes/.gitignore new file mode 100644 index 0000000..1055d93 --- /dev/null +++ b/de1_nes/.gitignore @@ -0,0 +1,6 @@ +*.done +*.summary +*.rpt +*.pof +*.sof +db/* \ No newline at end of file diff --git a/de1_nes/clock/clock_divider.vhd b/de1_nes/clock/clock_divider.vhd new file mode 100644 index 0000000..83d8562 --- /dev/null +++ b/de1_nes/clock/clock_divider.vhd @@ -0,0 +1,71 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.std_logic_unsigned.all; + +entity clock_divider is + port ( base_clk : in std_logic; + reset_n : in std_logic; + cpu_clk : out std_logic; + ppu_clk : out std_logic; + vga_clk : out std_logic + ); +end clock_divider; + +architecture rtl of clock_divider is + +signal loop2 : std_logic_vector (0 downto 0); +signal loop6 : std_logic_vector (2 downto 0); +signal cpu_cnt_rst_n : std_logic; +signal cpu_clk_new : std_logic; +signal cpu_clk_old : std_logic; +signal cpu_we_n : std_logic; + +component counter_register + generic ( + dsize : integer := 8; + inc : integer := 1 + ); + port ( clk : in std_logic; + rst_n : in std_logic; + ce_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector(dsize - 1 downto 0); + q : out std_logic_vector(dsize - 1 downto 0) + ); +end component; + +component d_flip_flop_bit + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + we_n : in std_logic; + d : in std_logic; + q : out std_logic + ); +end component; + +begin + ---base clock 25 MHz = VGA clock. + cpu_clk_old <= not cpu_clk_new; + cpu_clk <= cpu_clk_new; + ppu_clk <= not loop2(0); + vga_clk <= base_clk; + + cpu_cnt_rst_n <= '0' when reset_n = '0' else + '0' when loop6 = "110" else + '1'; + cpu_we_n <= '0' when loop6 = "101" else + '1'; + + ppu_clk_cnt : counter_register generic map (1) port map + (base_clk, reset_n, '0', '1', (others=>'0'), loop2); + + cpu_clk_cnt : counter_register generic map (3) port map + (base_clk, cpu_cnt_rst_n, '0', '1', (others=>'0'), loop6); + + cpu_clk_cnt2 : d_flip_flop_bit port map + (base_clk, reset_n, '1', cpu_we_n, cpu_clk_old, cpu_clk_new); + +end rtl; + diff --git a/de1_nes/cpu/cpu_registers.vhd b/de1_nes/cpu/cpu_registers.vhd new file mode 100644 index 0000000..7021c0a --- /dev/null +++ b/de1_nes/cpu/cpu_registers.vhd @@ -0,0 +1,492 @@ + +---------------------------------------- +--- d-flipflop with set/reset +---------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; + +entity d_flip_flop is + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end d_flip_flop; + +architecture rtl of d_flip_flop is +begin + + process (clk, res_n, set_n, d) + begin + if (res_n = '0') then + q <= (others => '0'); + elsif (set_n = '0') then + q <= d; + elsif (clk'event and clk = '1') then + if (we_n = '0') then + q <= d; + end if; + end if; + end process; +end rtl; + + +--------- 1 bit d-flipflop. +library ieee; +use ieee.std_logic_1164.all; + +entity d_flip_flop_bit is + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + we_n : in std_logic; + d : in std_logic; + q : out std_logic + ); +end d_flip_flop_bit; + +architecture rtl of d_flip_flop_bit is +begin + + process (clk, res_n, set_n, d) + begin + if (res_n = '0') then + q <= '0'; + elsif (set_n = '0') then + q <= d; + elsif (clk'event and clk = '1') then + if (we_n = '0') then + q <= d; + end if; + end if; + end process; +end rtl; + +---------------------------------------- +--- data latch declaration +---------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; + +entity latch is + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end latch; + +architecture rtl of latch is +begin + + process (clk, d) + begin + if ( clk = '1') then + --latch only when clock is high + q <= d; + end if; + end process; +end rtl; + +---------------------------------------- +--- tri-state buffer +---------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; + +entity tri_state_buffer is + generic ( + dsize : integer := 8 + ); + port ( + oe_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end tri_state_buffer; + +architecture rtl of tri_state_buffer is +begin + q <= d when oe_n = '0' else + (others => 'Z'); +end rtl; + + +---------------------------------------- +--- dual port d flip flop w/ tri-state buffer +---------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; + +entity dual_dff is + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + gate_cmd : in std_logic_vector (3 downto 0); + front_port : inout std_logic_vector (dsize - 1 downto 0); + back_in_port : in std_logic_vector (dsize - 1 downto 0); + back_out_port : out std_logic_vector (dsize - 1 downto 0) + ); +end dual_dff; + +architecture rtl of dual_dff is + +component d_flip_flop + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +component tri_state_buffer + generic ( + dsize : integer := 8 + ); + port ( + oe_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +signal we_n : std_logic; +signal q : std_logic_vector (dsize - 1 downto 0); +signal d : std_logic_vector (dsize - 1 downto 0); + +begin + ----------gate_cmd format + ------3 : front port oe_n + ------2 : front port we_n + ------1 : back port oe_n + ------0 : back port we_n + we_n <= (gate_cmd(2) and gate_cmd(0)); + + d <= front_port when gate_cmd(2) = '0' else + back_in_port when gate_cmd(0) = '0' else + (others => 'Z'); + + dff_inst : d_flip_flop generic map (dsize) + port map(clk, res_n, set_n, we_n, d, q); + + front_tsb : tri_state_buffer generic map (dsize) + port map(gate_cmd(3), q, front_port); + + back_tsb : tri_state_buffer generic map (dsize) + port map(gate_cmd(1), q, back_out_port); +end rtl; + + +---------------------------------------- +--- data bus buffer +---------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; + +entity data_bus_buffer is + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + r_nw : in std_logic; + int_oe_n : in std_logic; + int_dbus : inout std_logic_vector (dsize - 1 downto 0); + ext_dbus : inout std_logic_vector (dsize - 1 downto 0) + ); +end data_bus_buffer; + +architecture rtl of data_bus_buffer is +component latch + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +component tri_state_buffer + generic ( + dsize : integer := 8 + ); + port ( + oe_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +signal rd_clk : std_logic; +signal wr_clk : std_logic; +signal read_buf : std_logic_vector (dsize - 1 downto 0); +signal write_buf : std_logic_vector (dsize - 1 downto 0); +begin + rd_clk <= r_nw and clk; + wr_clk <= (not r_nw) and clk; + + --read from i/o to cpu + latch_r : latch generic map (dsize) + port map(rd_clk, ext_dbus, read_buf); + read_tsb : tri_state_buffer generic map (dsize) + port map(int_oe_n, read_buf, int_dbus); + --write from cpu to io + latch_w : latch generic map (dsize) + port map(wr_clk, int_dbus, write_buf); + write_tsb : tri_state_buffer generic map (dsize) + port map(r_nw, write_buf, ext_dbus); +end rtl; + +------------------------------------------ +----- input data latch register +------------------------------------------ + +library ieee; +use ieee.std_logic_1164.all; + +entity input_data_latch is + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + oe_n : in std_logic; + we_n : in std_logic; + int_dbus : in std_logic_vector (dsize - 1 downto 0); + alu_bus : out std_logic_vector (dsize - 1 downto 0) + ); +end input_data_latch; + +architecture rtl of input_data_latch is + +component latch + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +component tri_state_buffer + generic ( + dsize : integer := 8 + ); + port ( + oe_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +signal latch_clk : std_logic; +signal latch_buf : std_logic_vector (dsize - 1 downto 0); + +begin + latch_clk <= (not we_n) and clk; + latch_inst : latch generic map (dsize) + port map(latch_clk, int_dbus, latch_buf); + iput_data_tsb : tri_state_buffer generic map (dsize) + port map(oe_n, latch_buf, alu_bus); + +end rtl; + +---------------------------------------- +--- status register component +---------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; + +entity processor_status is + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + res_n : in std_logic; + dec_oe_n : in std_logic; + bus_oe_n : in std_logic; + set_flg_n : in std_logic; + flg_val : in std_logic; + load_bus_all_n : in std_logic; + load_bus_nz_n : in std_logic; + set_from_alu_n : in std_logic; + alu_n : in std_logic; + alu_v : in std_logic; + alu_z : in std_logic; + alu_c : in std_logic; + stat_c : out std_logic; + dec_val : inout std_logic_vector (dsize - 1 downto 0); + int_dbus : inout std_logic_vector (dsize - 1 downto 0) + ); +end processor_status; + +architecture rtl of processor_status is + +component d_flip_flop + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +component tri_state_buffer + generic ( + dsize : integer := 8 + ); + port ( + oe_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +signal we_n : std_logic; +signal d : std_logic_vector (dsize - 1 downto 0); +signal status_val : std_logic_vector (dsize - 1 downto 0); + +begin + dec_tsb : tri_state_buffer generic map (dsize) + port map(dec_oe_n, status_val, dec_val); + dbus_tsb : tri_state_buffer generic map (dsize) + port map(bus_oe_n, status_val, int_dbus); + + we_n <= set_flg_n and load_bus_all_n and + load_bus_nz_n and set_from_alu_n; + + dff_inst : d_flip_flop generic map (dsize) + port map(clk, '1', res_n, we_n, d, status_val); + + --carry status for adc/sbc. + stat_c <= status_val(0); + + main_p : process (clk, res_n, we_n, dec_val, int_dbus, + alu_n, alu_v, alu_z, alu_c) + variable tmp : std_logic_vector (dsize - 1 downto 0); + begin +-- SR Flags (bit 7 to bit 0): +-- +-- N .... Negative +-- V .... Overflow +-- - .... ignored +-- B .... Break +-- D .... Decimal (use BCD for arithmetics) +-- I .... Interrupt (IRQ disable) +-- Z .... Zero +-- C .... Carry + + ---only interrupt flag is set on reset. + if (res_n = '0') then + d <= "00000100"; + else + d <= (others => 'Z'); + end if; + + ---from flag set/clear instructions + if (set_flg_n = '0') then + if flg_val = '1' then + tmp := (dec_val and "11111111"); + else + tmp := "00000000"; + end if; + d <= tmp or (status_val and not dec_val); + + ---status flag set from the data on the internal data bus. + ---interpret the input data by the dec_val input. + ---load/pop/rti/t[asxy] + elsif (load_bus_all_n = '0') then + ---set the data bus data as they are. + d <= int_dbus; + elsif (load_bus_nz_n = '0') then + tmp := status_val; + d (6 downto 2) <= tmp (6 downto 2); + d (0) <= tmp (0); + + ---other case: n/z data must be interpreted. + --n bit. + if int_dbus(7) = '1' then + d (7) <= '1'; + else + d (7) <= '0'; + end if; + --z bit. + ---nor outputs 1 when all inputs are 0. + if (int_dbus(7) or int_dbus(6) or + int_dbus(5) or int_dbus(4) or int_dbus(3) or + int_dbus(2) or int_dbus(1) or int_dbus(0)) = '0' then + d (1) <= '1'; + else + d (1) <= '0'; + end if; + + ---status set from alu + elsif (set_from_alu_n = '0') then + tmp := status_val; + d (5 downto 2) <= tmp (5 downto 2); + + --n bit. + if (dec_val(7) = '1') then + d (7) <= alu_n; + else + d (7) <= tmp (7); + end if; + --v bit. + if (dec_val(6) = '1') then + d (6) <= alu_v; + else + d (6) <= tmp (6); + end if; + --z bit. + if (dec_val(1) = '1') then + d (1) <= alu_z; + else + d (1) <= tmp (1); + end if; + --c bit. + if (dec_val(0) = '1') then + d (0) <= alu_c; + else + d (0) <= tmp (0); + end if; + end if; --if (set_flg_n = '0') then + end process; +end rtl; + + diff --git a/de1_nes/de1_nes.dpf b/de1_nes/de1_nes.dpf new file mode 100644 index 0000000..f0b3ecc --- /dev/null +++ b/de1_nes/de1_nes.dpf @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/de1_nes/de1_nes.pin b/de1_nes/de1_nes.pin new file mode 100644 index 0000000..bb13649 --- /dev/null +++ b/de1_nes/de1_nes.pin @@ -0,0 +1,559 @@ + -- Copyright (C) 1991-2007 Altera Corporation + -- Your use of Altera Corporation's design tools, logic functions + -- and other software and tools, and its AMPP partner logic + -- functions, and any output files from any of the foregoing + -- (including device programming or simulation files), and any + -- associated documentation or information are expressly subject + -- to the terms and conditions of the Altera Program License + -- Subscription Agreement, Altera MegaCore Function License + -- Agreement, or other applicable license agreement, including, + -- without limitation, that your use is for the sole purpose of + -- programming logic devices manufactured by Altera and sold by + -- Altera or its authorized distributors. Please refer to the + -- applicable agreement for further details. + -- + -- This is a Quartus II output file. It is for reporting purposes only, and is + -- not intended for use as a Quartus II input file. This file cannot be used + -- to make Quartus II pin assignments - for instructions on how to make pin + -- assignments, please see Quartus II help. + --------------------------------------------------------------------------------- + + + + --------------------------------------------------------------------------------- + -- NC : No Connect. This pin has no internal connection to the device. + -- DNU : Do Not Use. This pin MUST NOT be connected. + -- VCCPGM : Dedicated power pin for configuration, which MUST be connected to 1.8V, 2.5V or 3.0V depending on the needs of the configuration device. + -- VCCINT : Dedicated power pin, which MUST be connected to VCC (1.2V). + -- VCCIO : Dedicated power pin, which MUST be connected to VCC + -- of its bank. + -- Bank 1: 3.3V + -- Bank 2: 3.3V + -- Bank 3: 3.3V + -- Bank 4: 3.3V + -- Bank 5: 3.3V + -- Bank 6: 3.3V + -- Bank 7: 3.3V + -- Bank 8: 3.3V + -- GND : Dedicated ground pin. Dedicated GND pins MUST be connected to GND. + -- It can also be used to report unused dedicated pins. The connection + -- on the board for unused dedicated pins depends on whether this will + -- be used in a future design. One example is device migration. When + -- using device migration, refer to the device pin-tables. If it is a + -- GND pin in the pin table or if it will not be used in a future design + -- for another purpose the it MUST be connected to GND. If it is an unused + -- dedicated pin, then it can be connected to a valid signal on the board + -- (low, high, or toggling) if that signal is required for a different + -- revision of the design. + -- GND+ : Unused input pin. It can also be used to report unused dual-purpose pins. + -- This pin should be connected to GND. It may also be connected to a + -- valid signal on the board (low, high, or toggling) if that signal + -- is required for a different revision of the design. + -- GND* : Unused I/O pin. For transceiver I/O banks (Bank 13, 14, 15, 16 and 17), + -- connect each pin marked GND* either individually through a 10 kohm resistor + -- to GND or tie all pins together and connect through a single 10 kohm resistor + -- to GND. + -- For non-transceiver I/O banks, connect each pin marked GND* directly to GND + -- or leave it unconnected. + -- RESERVED : Unused I/O pin, which MUST be left unconnected. + -- RESERVED_INPUT : Pin is tri-stated and should be connected to the board. + -- RESERVED_INPUT_WITH_WEAK_PULLUP : Pin is tri-stated with internal weak pull-up resistor. + -- RESERVED_INPUT_WITH_BUS_HOLD : Pin is tri-stated with bus-hold circuitry. + -- RESERVED_OUTPUT_DRIVEN_HIGH : Pin is output driven high. + --------------------------------------------------------------------------------- + + + + --------------------------------------------------------------------------------- + -- Pin directions (input, output or bidir) are based on device operating in user mode. + --------------------------------------------------------------------------------- + +Quartus II Version 7.2 Build 151 09/26/2007 SJ Web Edition +CHIP "de1_nes" ASSIGNED TO AN: EP2C20F484C7 + +Pin Name/Usage : Location : Dir. : I/O Standard : Voltage : I/O Bank : User Assignment +------------------------------------------------------------------------------------------------------------- +GND : A1 : gnd : : : : +VCCIO3 : A2 : power : : 3.3V : 3 : +GND* : A3 : : : : 3 : +GND* : A4 : : : : 3 : +GND* : A5 : : : : 3 : +GND* : A6 : : : : 3 : +GND* : A7 : : : : 3 : +GND* : A8 : : : : 3 : +GND* : A9 : : : : 3 : +GND* : A10 : : : : 3 : +GND* : A11 : : : : 3 : +GND+ : A12 : : : : 4 : +GND* : A13 : : : : 4 : +GND* : A14 : : : : 4 : +GND* : A15 : : : : 4 : +GND* : A16 : : : : 4 : +GND* : A17 : : : : 4 : +GND* : A18 : : : : 4 : +GND* : A19 : : : : 4 : +GND* : A20 : : : : 4 : +VCCIO4 : A21 : power : : 3.3V : 4 : +GND : A22 : gnd : : : : +VCCIO1 : AA1 : power : : 3.3V : 1 : +GND : AA2 : gnd : : : : +GND* : AA3 : : : : 8 : +GND* : AA4 : : : : 8 : +GND* : AA5 : : : : 8 : +GND* : AA6 : : : : 8 : +GND* : AA7 : : : : 8 : +GND* : AA8 : : : : 8 : +dbg_pin0 : AA9 : output : 3.3-V LVTTL : : 8 : N +GND* : AA10 : : : : 8 : +GND* : AA11 : : : : 8 : +GND* : AA12 : : : : 7 : +GND* : AA13 : : : : 7 : +GND* : AA14 : : : : 7 : +GND* : AA15 : : : : 7 : +GND* : AA16 : : : : 7 : +GND* : AA17 : : : : 7 : +GND* : AA18 : : : : 7 : +GND* : AA19 : : : : 7 : +GND* : AA20 : : : : 7 : +GND : AA21 : gnd : : : : +VCCIO6 : AA22 : power : : 3.3V : 6 : +GND : AB1 : gnd : : : : +VCCIO8 : AB2 : power : : 3.3V : 8 : +GND* : AB3 : : : : 8 : +GND* : AB4 : : : : 8 : +GND* : AB5 : : : : 8 : +GND* : AB6 : : : : 8 : +GND* : AB7 : : : : 8 : +GND* : AB8 : : : : 8 : +GND* : AB9 : : : : 8 : +GND* : AB10 : : : : 8 : +GND* : AB11 : : : : 8 : +GND* : AB12 : : : : 7 : +GND* : AB13 : : : : 7 : +GND* : AB14 : : : : 7 : +GND* : AB15 : : : : 7 : +GND* : AB16 : : : : 7 : +GND* : AB17 : : : : 7 : +GND* : AB18 : : : : 7 : +GND* : AB19 : : : : 7 : +GND* : AB20 : : : : 7 : +VCCIO7 : AB21 : power : : 3.3V : 7 : +GND : AB22 : gnd : : : : +VCCIO2 : B1 : power : : 3.3V : 2 : +GND : B2 : gnd : : : : +GND* : B3 : : : : 3 : +GND* : B4 : : : : 3 : +GND* : B5 : : : : 3 : +GND* : B6 : : : : 3 : +GND* : B7 : : : : 3 : +GND* : B8 : : : : 3 : +GND* : B9 : : : : 3 : +GND* : B10 : : : : 3 : +dbg_pin2 : B11 : output : 3.3-V LVTTL : : 3 : N +GND+ : B12 : : : : 4 : +GND* : B13 : : : : 4 : +GND* : B14 : : : : 4 : +GND* : B15 : : : : 4 : +dbg_pin4 : B16 : output : 3.3-V LVTTL : : 4 : N +GND* : B17 : : : : 4 : +GND* : B18 : : : : 4 : +GND* : B19 : : : : 4 : +GND* : B20 : : : : 4 : +GND : B21 : gnd : : : : +VCCIO5 : B22 : power : : 3.3V : 5 : +GND* : C1 : : : : 2 : +GND* : C2 : : : : 2 : +~nCSO~ / RESERVED_INPUT_WITH_WEAK_PULLUP : C3 : input : 3.3-V LVTTL : : 2 : N +~ASDO~ / RESERVED_INPUT_WITH_WEAK_PULLUP : C4 : input : 3.3-V LVTTL : : 2 : N +GND : C5 : gnd : : : : +VCCIO3 : C6 : power : : 3.3V : 3 : +GND* : C7 : : : : 3 : +GND : C8 : gnd : : : : +GND* : C9 : : : : 3 : +GND* : C10 : : : : 3 : +VCCIO3 : C11 : power : : 3.3V : 3 : +VCCIO4 : C12 : power : : 3.3V : 4 : +GND* : C13 : : : : 4 : +GND* : C14 : : : : 4 : +GND : C15 : gnd : : : : +GND* : C16 : : : : 4 : +GND* : C17 : : : : 4 : +GND* : C18 : : : : 4 : +GND* : C19 : : : : 5 : +GND* : C20 : : : : 5 : +GND* : C21 : : : : 5 : +GND* : C22 : : : : 5 : +GND* : D1 : : : : 2 : +GND* : D2 : : : : 2 : +GND* : D3 : : : : 2 : +GND* : D4 : : : : 2 : +GND* : D5 : : : : 2 : +GND* : D6 : : : : 2 : +GND* : D7 : : : : 3 : +GND* : D8 : : : : 3 : +GND* : D9 : : : : 3 : +GND : D10 : gnd : : : : +GND* : D11 : : : : 3 : +base_clk : D12 : input : 3.3-V LVTTL : : 3 : Y +GND : D13 : gnd : : : : +GND* : D14 : : : : 4 : +GND* : D15 : : : : 4 : +GND* : D16 : : : : 4 : +VCCIO4 : D17 : power : : 3.3V : 4 : +GND : D18 : gnd : : : : +GND* : D19 : : : : 5 : +GND* : D20 : : : : 5 : +GND* : D21 : : : : 5 : +GND* : D22 : : : : 5 : +GND* : E1 : : : : 2 : +GND* : E2 : : : : 2 : +GND* : E3 : : : : 2 : +GND* : E4 : : : : 2 : +VCCD_PLL3 : E5 : power : : 1.2V : : +VCCA_PLL3 : E6 : power : : 1.2V : : +GND* : E7 : : : : 3 : +GND* : E8 : : : : 3 : +GND* : E9 : : : : 3 : +VCCIO3 : E10 : power : : 3.3V : 3 : +GND* : E11 : : : : 3 : +GND+ : E12 : : : : 3 : +VCCIO4 : E13 : power : : 3.3V : 4 : +GND* : E14 : : : : 4 : +GND* : E15 : : : : 4 : +GNDA_PLL2 : E16 : gnd : : : : +GND_PLL2 : E17 : gnd : : : : +dbg_pin3 : E18 : output : 3.3-V LVTTL : : 5 : N +GND* : E19 : : : : 5 : +GND* : E20 : : : : 5 : +GND* : E21 : : : : 5 : +GND* : E22 : : : : 5 : +GND* : F1 : : : : 2 : +GND* : F2 : : : : 2 : +GND* : F3 : : : : 2 : +GND* : F4 : : : : 2 : +GND_PLL3 : F5 : gnd : : : : +GND_PLL3 : F6 : gnd : : : : +GNDA_PLL3 : F7 : gnd : : : : +GND* : F8 : : : : 3 : +dbg_pin7 : F9 : output : 3.3-V LVTTL : : 3 : N +dbg_pin1 : F10 : output : 3.3-V LVTTL : : 3 : N +GND* : F11 : : : : 3 : +dbg_pin6 : F12 : output : 3.3-V LVTTL : : 4 : N +GND* : F13 : : : : 4 : +GND* : F14 : : : : 4 : +GND* : F15 : : : : 4 : +VCCA_PLL2 : F16 : power : : 1.2V : : +VCCD_PLL2 : F17 : power : : 1.2V : : +GND_PLL2 : F18 : gnd : : : : +GND : F19 : gnd : : : : +GND* : F20 : : : : 5 : +GND* : F21 : : : : 5 : +GND* : F22 : : : : 5 : +NC : G1 : : : : : +NC : G2 : : : : : +GND* : G3 : : : : 2 : +GND : G4 : gnd : : : : +GND* : G5 : : : : 2 : +GND* : G6 : : : : 2 : +GND* : G7 : : : : 3 : +GND* : G8 : : : : 3 : +VCCIO3 : G9 : power : : 3.3V : 3 : +GND : G10 : gnd : : : : +GND* : G11 : : : : 3 : +GND* : G12 : : : : 4 : +GND : G13 : gnd : : : : +VCCIO4 : G14 : power : : 3.3V : 4 : +GND* : G15 : : : : 4 : +dbg_pin5 : G16 : output : 3.3-V LVTTL : : 4 : N +GND* : G17 : : : : 5 : +GND* : G18 : : : : 5 : +VCCIO5 : G19 : power : : 3.3V : 5 : +GND* : G20 : : : : 5 : +GND* : G21 : : : : 5 : +GND* : G22 : : : : 5 : +GND* : H1 : : : : 2 : +GND* : H2 : : : : 2 : +GND* : H3 : : : : 2 : +GND* : H4 : : : : 2 : +GND* : H5 : : : : 2 : +GND* : H6 : : : : 2 : +GND* : H7 : : : : 3 : +GND* : H8 : : : : 3 : +GND* : H9 : : : : 3 : +GND* : H10 : : : : 3 : +GND* : H11 : : : : 3 : +GND* : H12 : : : : 4 : +GND* : H13 : : : : 4 : +GND* : H14 : : : : 4 : +GND* : H15 : : : : 4 : +GND* : H16 : : : : 5 : +GND* : H17 : : : : 5 : +GND* : H18 : : : : 5 : +GND* : H19 : : : : 5 : +GND : H20 : gnd : : : : +NC : H21 : : : : : +NC : H22 : : : : : +GND* : J1 : : : : 2 : +GND* : J2 : : : : 2 : +NC : J3 : : : : : +GND* : J4 : : : : 2 : +NC : J5 : : : : : +NC : J6 : : : : : +VCCIO2 : J7 : power : : 3.3V : 2 : +NC : J8 : : : : : +NC : J9 : : : : : +VCCINT : J10 : power : : 1.2V : : +VCCINT : J11 : power : : 1.2V : : +VCCINT : J12 : power : : 1.2V : : +VCCINT : J13 : power : : 1.2V : : +GND* : J14 : : : : 4 : +GND* : J15 : : : : 5 : +VCCIO5 : J16 : power : : 3.3V : 5 : +GND* : J17 : : : : 5 : +GND* : J18 : : : : 5 : +GND* : J19 : : : : 5 : +GND* : J20 : : : : 5 : +GND* : J21 : : : : 5 : +GND* : J22 : : : : 5 : +nCE : K1 : : : : 2 : +TCK : K2 : input : : : 2 : +GND : K3 : gnd : : : : +DATA0 : K4 : input : : : 2 : +TDI : K5 : input : : : 2 : +TMS : K6 : input : : : 2 : +GND : K7 : gnd : : : : +NC : K8 : : : : : +VCCINT : K9 : power : : 1.2V : : +GND : K10 : gnd : : : : +GND : K11 : gnd : : : : +GND : K12 : gnd : : : : +GND : K13 : gnd : : : : +VCCINT : K14 : power : : 1.2V : : +NC : K15 : : : : : +GND : K16 : gnd : : : : +NC : K17 : : : : : +NC : K18 : : : : : +GND : K19 : gnd : : : : +GND* : K20 : : : : 5 : +GND* : K21 : : : : 5 : +GND* : K22 : : : : 5 : +GND+ : L1 : : : : 2 : +GND+ : L2 : : : : 2 : +VCCIO2 : L3 : power : : 3.3V : 2 : +nCONFIG : L4 : : : : 2 : +TDO : L5 : output : : : 2 : +DCLK : L6 : : : : 2 : +NC : L7 : : : : : +GND* : L8 : : : : 2 : +VCCINT : L9 : power : : 1.2V : : +GND : L10 : gnd : : : : +GND : L11 : gnd : : : : +GND : L12 : gnd : : : : +GND : L13 : gnd : : : : +VCCINT : L14 : power : : 1.2V : : +NC : L15 : : : : : +NC : L16 : : : : : +NC : L17 : : : : : +GND* : L18 : : : : 5 : +GND* : L19 : : : : 5 : +VCCIO5 : L20 : power : : 3.3V : 5 : +GND+ : L21 : : : : 5 : +GND+ : L22 : : : : 5 : +GND+ : M1 : : : : 1 : +GND+ : M2 : : : : 1 : +VCCIO1 : M3 : power : : 3.3V : 1 : +GND : M4 : gnd : : : : +GND* : M5 : : : : 1 : +GND* : M6 : : : : 1 : +NC : M7 : : : : : +NC : M8 : : : : : +VCCINT : M9 : power : : 1.2V : : +GND : M10 : gnd : : : : +GND : M11 : gnd : : : : +GND : M12 : gnd : : : : +GND : M13 : gnd : : : : +VCCINT : M14 : power : : 1.2V : : +NC : M15 : : : : : +NC : M16 : : : : : +MSEL0 : M17 : : : : 6 : +GND* : M18 : : : : 6 : +GND* : M19 : : : : 6 : +VCCIO6 : M20 : power : : 3.3V : 6 : +GND+ : M21 : : : : 6 : +GND+ : M22 : : : : 6 : +GND* : N1 : : : : 1 : +GND* : N2 : : : : 1 : +GND* : N3 : : : : 1 : +GND* : N4 : : : : 1 : +NC : N5 : : : : : +GND* : N6 : : : : 1 : +GND : N7 : gnd : : : : +NC : N8 : : : : : +VCCINT : N9 : power : : 1.2V : : +GND : N10 : gnd : : : : +GND : N11 : gnd : : : : +GND : N12 : gnd : : : : +GND : N13 : gnd : : : : +VCCINT : N14 : power : : 1.2V : : +GND* : N15 : : : : 6 : +GND : N16 : gnd : : : : +MSEL1 : N17 : : : : 6 : +CONF_DONE : N18 : : : : 6 : +GND : N19 : gnd : : : : +nSTATUS : N20 : : : : 6 : +GND* : N21 : : : : 6 : +GND* : N22 : : : : 6 : +GND* : P1 : : : : 1 : +GND* : P2 : : : : 1 : +GND* : P3 : : : : 1 : +NC : P4 : : : : : +GND* : P5 : : : : 1 : +GND* : P6 : : : : 1 : +VCCIO1 : P7 : power : : 3.3V : 1 : +GND* : P8 : : : : 8 : +GND* : P9 : : : : 8 : +VCCINT : P10 : power : : 1.2V : : +VCCINT : P11 : power : : 1.2V : : +VCCINT : P12 : power : : 1.2V : : +VCCINT : P13 : power : : 1.2V : : +NC : P14 : : : : : +GND* : P15 : : : : 6 : +VCCIO6 : P16 : power : : 3.3V : 6 : +GND* : P17 : : : : 6 : +GND* : P18 : : : : 6 : +NC : P19 : : : : : +NC : P20 : : : : : +NC : P21 : : : : : +NC : P22 : : : : : +GND* : R1 : : : : 1 : +GND* : R2 : : : : 1 : +GND : R3 : gnd : : : : +NC : R4 : : : : : +GND* : R5 : : : : 1 : +GND* : R6 : : : : 1 : +GND* : R7 : : : : 1 : +GND* : R8 : : : : 1 : +GND* : R9 : : : : 8 : +GND* : R10 : : : : 8 : +GND* : R11 : : : : 8 : +GND* : R12 : : : : 7 : +GND* : R13 : : : : 7 : +GND* : R14 : : : : 7 : +GND* : R15 : : : : 7 : +GND* : R16 : : : : 7 : +GND* : R17 : : : : 6 : +GND* : R18 : : : : 6 : +GND* : R19 : : : : 6 : +GND* : R20 : : : : 6 : +GND* : R21 : : : : 6 : +rst_n : R22 : input : 3.3-V LVTTL : : 6 : Y +GND* : T1 : : : : 1 : +GND* : T2 : : : : 1 : +GND* : T3 : : : : 1 : +VCCIO1 : T4 : power : : 3.3V : 1 : +GND* : T5 : : : : 1 : +GND* : T6 : : : : 1 : +GND* : T7 : : : : 8 : +GND* : T8 : : : : 8 : +VCCIO8 : T9 : power : : 3.3V : 8 : +GND : T10 : gnd : : : : +GND* : T11 : : : : 8 : +GND* : T12 : : : : 7 : +GND : T13 : gnd : : : : +VCCIO7 : T14 : power : : 3.3V : 7 : +GND* : T15 : : : : 7 : +GND* : T16 : : : : 7 : +GND_PLL4 : T17 : gnd : : : : +GND* : T18 : : : : 6 : +VCCIO6 : T19 : power : : 3.3V : 6 : +GND : T20 : gnd : : : : +GND* : T21 : : : : 6 : +GND* : T22 : : : : 6 : +GND* : U1 : : : : 1 : +GND* : U2 : : : : 1 : +GND* : U3 : : : : 1 : +GND* : U4 : : : : 1 : +GND_PLL1 : U5 : gnd : : : : +VCCD_PLL1 : U6 : power : : 1.2V : : +VCCA_PLL1 : U7 : power : : 1.2V : : +GND* : U8 : : : : 8 : +GND* : U9 : : : : 8 : +GND* : U10 : : : : 8 : +GND+ : U11 : : : : 8 : +GND+ : U12 : : : : 8 : +GND* : U13 : : : : 7 : +GND* : U14 : : : : 7 : +GND* : U15 : : : : 7 : +VCCA_PLL4 : U16 : power : : 1.2V : : +VCCD_PLL4 : U17 : power : : 1.2V : : +GND* : U18 : : : : 6 : +GND* : U19 : : : : 6 : +GND* : U20 : : : : 6 : +GND* : U21 : : : : 6 : +GND* : U22 : : : : 6 : +GND* : V1 : : : : 1 : +GND* : V2 : : : : 1 : +GND : V3 : gnd : : : : +GND* : V4 : : : : 1 : +GND_PLL1 : V5 : gnd : : : : +GND : V6 : gnd : : : : +GNDA_PLL1 : V7 : gnd : : : : +GND* : V8 : : : : 8 : +GND* : V9 : : : : 8 : +VCCIO8 : V10 : power : : 3.3V : 8 : +GND* : V11 : : : : 8 : +GND+ : V12 : : : : 7 : +VCCIO7 : V13 : power : : 3.3V : 7 : +GND* : V14 : : : : 7 : +GND* : V15 : : : : 7 : +GNDA_PLL4 : V16 : gnd : : : : +GND : V17 : gnd : : : : +GND_PLL4 : V18 : gnd : : : : +GND* : V19 : : : : 6 : +GND* : V20 : : : : 6 : +GND* : V21 : : : : 6 : +GND* : V22 : : : : 6 : +GND* : W1 : : : : 1 : +GND* : W2 : : : : 1 : +GND* : W3 : : : : 1 : +GND* : W4 : : : : 1 : +GND* : W5 : : : : 1 : +VCCIO8 : W6 : power : : 3.3V : 8 : +GND* : W7 : : : : 8 : +GND* : W8 : : : : 8 : +GND* : W9 : : : : 8 : +GND : W10 : gnd : : : : +GND* : W11 : : : : 8 : +GND+ : W12 : : : : 7 : +GND : W13 : gnd : : : : +GND* : W14 : : : : 7 : +GND* : W15 : : : : 7 : +GND* : W16 : : : : 7 : +VCCIO7 : W17 : power : : 3.3V : 7 : +NC : W18 : : : : : +GND : W19 : gnd : : : : +~LVDS91p/nCEO~ : W20 : output : 3.3-V LVTTL : : 6 : N +GND* : W21 : : : : 6 : +GND* : W22 : : : : 6 : +GND* : Y1 : : : : 1 : +GND* : Y2 : : : : 1 : +GND* : Y3 : : : : 1 : +GND* : Y4 : : : : 1 : +GND* : Y5 : : : : 8 : +GND* : Y6 : : : : 8 : +GND* : Y7 : : : : 8 : +GND : Y8 : gnd : : : : +GND* : Y9 : : : : 8 : +GND* : Y10 : : : : 8 : +VCCIO8 : Y11 : power : : 3.3V : 8 : +VCCIO7 : Y12 : power : : 3.3V : 7 : +GND* : Y13 : : : : 7 : +GND* : Y14 : : : : 7 : +GND : Y15 : gnd : : : : +GND* : Y16 : : : : 7 : +GND* : Y17 : : : : 7 : +GND* : Y18 : : : : 6 : +GND* : Y19 : : : : 6 : +GND* : Y20 : : : : 6 : +GND* : Y21 : : : : 6 : +GND* : Y22 : : : : 6 : diff --git a/de1_nes/de1_nes.qpf b/de1_nes/de1_nes.qpf new file mode 100644 index 0000000..99408ce --- /dev/null +++ b/de1_nes/de1_nes.qpf @@ -0,0 +1,23 @@ +# Copyright (C) 1991-2007 Altera Corporation +# Your use of Altera Corporation's design tools, logic functions +# and other software and tools, and its AMPP partner logic +# functions, and any output files from any of the foregoing +# (including device programming or simulation files), and any +# associated documentation or information are expressly subject +# to the terms and conditions of the Altera Program License +# Subscription Agreement, Altera MegaCore Function License +# Agreement, or other applicable license agreement, including, +# without limitation, that your use is for the sole purpose of +# programming logic devices manufactured by Altera and sold by +# Altera or its authorized distributors. Please refer to the +# applicable agreement for further details. + + + +QUARTUS_VERSION = "7.2" +DATE = "10:06:40 September 01, 2013" + + +# Revisions + +PROJECT_REVISION = "de1_nes" diff --git a/de1_nes/de1_nes.qsf b/de1_nes/de1_nes.qsf new file mode 100644 index 0000000..0908aff --- /dev/null +++ b/de1_nes/de1_nes.qsf @@ -0,0 +1,48 @@ +# Copyright (C) 1991-2007 Altera Corporation +# Your use of Altera Corporation's design tools, logic functions +# and other software and tools, and its AMPP partner logic +# functions, and any output files from any of the foregoing +# (including device programming or simulation files), and any +# associated documentation or information are expressly subject +# to the terms and conditions of the Altera Program License +# Subscription Agreement, Altera MegaCore Function License +# Agreement, or other applicable license agreement, including, +# without limitation, that your use is for the sole purpose of +# programming logic devices manufactured by Altera and sold by +# Altera or its authorized distributors. Please refer to the +# applicable agreement for further details. + + +# The default values for assignments are stored in the file +# de1_nes_assignment_defaults.qdf +# If this file doesn't exist, and for assignments not listed, see file +# assignment_defaults.qdf + +# Altera recommends that you do not modify this file. This +# file is updated automatically by the Quartus II software +# and any changes you make may be lost or overwritten. + + +set_global_assignment -name FAMILY "Cyclone II" +set_global_assignment -name DEVICE EP2C20F484C7 +set_global_assignment -name TOP_LEVEL_ENTITY de1_nes +set_global_assignment -name ORIGINAL_QUARTUS_VERSION 7.2 +set_global_assignment -name PROJECT_CREATION_TIME_DATE "10:06:40 SEPTEMBER 01, 2013" +set_global_assignment -name LAST_QUARTUS_VERSION 7.2 +set_global_assignment -name USE_GENERATED_PHYSICAL_CONSTRAINTS OFF -section_id eda_palace +set_global_assignment -name DEVICE_FILTER_PACKAGE FBGA +set_global_assignment -name DEVICE_FILTER_PIN_COUNT 484 +set_global_assignment -name DEVICE_FILTER_SPEED_GRADE 7 +set_instance_assignment -name PARTITION_HIERARCHY no_file_for_top_partition -to | -section_id Top +set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top +set_global_assignment -name PARTITION_COLOR 2147039 -section_id Top +set_global_assignment -name LL_ROOT_REGION ON -section_id "Root Region" +set_global_assignment -name LL_MEMBER_STATE LOCKED -section_id "Root Region" +set_location_assignment PIN_D12 -to base_clk +set_location_assignment PIN_R22 -to rst_n +set_global_assignment -name VHDL_FILE ppu/ppu_registers.vhd +set_global_assignment -name VHDL_FILE cpu/cpu_registers.vhd +set_global_assignment -name VHDL_FILE clock/clock_divider.vhd +set_global_assignment -name VHDL_FILE de1_nes.vhd +set_global_assignment -name VECTOR_WAVEFORM_FILE de1_nes.vwf +set_global_assignment -name INCREMENTAL_VECTOR_INPUT_SOURCE de1_nes.vwf \ No newline at end of file diff --git a/de1_nes/de1_nes.qws b/de1_nes/de1_nes.qws new file mode 100644 index 0000000..ea3644e --- /dev/null +++ b/de1_nes/de1_nes.qws @@ -0,0 +1,22 @@ +[ProjectWorkspace] +ptn_Child1=Frames +[ProjectWorkspace.Frames] +ptn_Child1=ChildFrames +[ProjectWorkspace.Frames.ChildFrames] +ptn_Child1=Document-0 +ptn_Child2=Document-1 +ptn_Child3=Document-2 +ptn_Child4=Document-3 +ptn_Child5=Document-4 +[ProjectWorkspace.Frames.ChildFrames.Document-0] +ptn_Child1=ViewFrame-0 +[ProjectWorkspace.Frames.ChildFrames.Document-0.ViewFrame-0] +DocPathName=de1_nes.vwf +DocumentCLSID={4a9ed22a-e60b-11d1-a0bd-0020affa43f2} +IsChildFrameDetached=False +IsActiveChildFrame=False +ptn_Child1=StateMap +[ProjectWorkspace.Frames.ChildFrames.Document-0.ViewFrame-0.StateMap] +AFC_SIM_AP_NAME=de1_nes +AFC_PROJ_DB_PATH=D:/daisuke/nes/repo/motonesfpga/de1_nes/db/de1_nes.quartus_db +AFC_IN_REPORT=False diff --git a/de1_nes/de1_nes.vhd b/de1_nes/de1_nes.vhd new file mode 100644 index 0000000..f8fd347 --- /dev/null +++ b/de1_nes/de1_nes.vhd @@ -0,0 +1,154 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.std_logic_unsigned.conv_integer; + +-- +-- MOTO NES FPGA On GHDL Simulation Environment Virtual Cuicuit Board +-- All of the components are assembled and instanciated on this board. +-- + +entity de1_nes is + port ( + base_clk : in std_logic; + rst_n : in std_logic; + dbg_pin0 : out std_logic; + dbg_pin1 : out std_logic; + dbg_pin2 : out std_logic; + dbg_pin3 : out std_logic; + dbg_pin4 : out std_logic; + dbg_pin5 : out std_logic; + dbg_pin6 : out std_logic; + dbg_pin7 : out std_logic + ); +end de1_nes; + +architecture rtl of de1_nes is + component mos6502 + generic ( dsize : integer := 8; + asize : integer :=16 + ); + port ( input_clk : in std_logic; --phi0 input pin. + rdy : in std_logic; + rst_n : in std_logic; + irq_n : in std_logic; + nmi_n : in std_logic; + dbe : in std_logic; + r_nw : out std_logic; + phi1 : out std_logic; + phi2 : out std_logic; + addr : out std_logic_vector ( asize - 1 downto 0); + d_io : inout std_logic_vector ( dsize - 1 downto 0) + ); + end component; + + component clock_divider + port ( base_clk : in std_logic; + reset_n : in std_logic; + cpu_clk : out std_logic; + ppu_clk : out std_logic; + vga_clk : out std_logic + ); + end component; + + component address_decoder + generic (abus_size : integer := 16; dbus_size : integer := 8); + port ( phi2 : in std_logic; + R_nW : in std_logic; + addr : in std_logic_vector (abus_size - 1 downto 0); + d_io : inout std_logic_vector (dbus_size - 1 downto 0); + ppu_ce_n : out std_logic + ); + end component; + + component ppu + port ( clk : in std_logic; + ce_n : in std_logic; + rst_n : in std_logic; + r_nw : in std_logic; + cpu_addr : in std_logic_vector (2 downto 0); + cpu_d : inout std_logic_vector (7 downto 0); + vblank_n : out std_logic; + rd_n : out std_logic; + wr_n : out std_logic; + ale : out std_logic; + vram_ad : inout std_logic_vector (7 downto 0); + vram_a : out std_logic_vector (13 downto 8); + vga_clk : in std_logic; + h_sync_n : out std_logic; + v_sync_n : out std_logic; + r : out std_logic_vector(3 downto 0); + g : out std_logic_vector(3 downto 0); + b : out std_logic_vector(3 downto 0) + ); + end component; + + component v_address_decoder + generic (abus_size : integer := 14; dbus_size : integer := 8); + port ( clk : in std_logic; + rd_n : in std_logic; + wr_n : in std_logic; + ale : in std_logic; + vram_ad : inout std_logic_vector (7 downto 0); + vram_a : in std_logic_vector (13 downto 8) + ); + end component; + + constant data_size : integer := 8; + constant addr_size : integer := 16; + constant size14 : integer := 14; + + signal cpu_clk : std_logic; + signal ppu_clk : std_logic; + + signal rdy, irq_n, nmi_n, dbe, r_nw : std_logic; + signal phi1, phi2 : std_logic; + signal addr : std_logic_vector( addr_size - 1 downto 0); + signal d_io : std_logic_vector( data_size - 1 downto 0); + + signal ppu_ce_n : std_logic; + signal rd_n : std_logic; + signal wr_n : std_logic; + signal ale : std_logic; + signal vram_ad : std_logic_vector (7 downto 0); + signal vram_a : std_logic_vector (13 downto 8); + + signal vga_clk : std_logic; + signal h_sync_n : std_logic; + signal v_sync_n : std_logic; + signal r : std_logic_vector(3 downto 0); + signal g : std_logic_vector(3 downto 0); + signal b : std_logic_vector(3 downto 0); + +begin + + irq_n <= '0'; + rdy <= '1'; + + --ppu/cpu clock generator + clock_inst : clock_divider port map + (base_clk, rst_n, cpu_clk, ppu_clk, vga_clk); + +-- --mos 6502 cpu instance +-- cpu_inst : mos6502 generic map (data_size, addr_size) +-- port map (cpu_clk, rdy, rst_n, irq_n, nmi_n, dbe, r_nw, +-- phi1, phi2, addr, d_io); + +-- addr_dec_inst : address_decoder generic map (addr_size, data_size) +-- port map (phi2, r_nw, addr, d_io, ppu_ce_n); + + --nes ppu instance +-- ppu_inst : ppu +-- port map (ppu_clk, ppu_ce_n, rst_n, r_nw, addr(2 downto 0), d_io, +-- nmi_n, rd_n, wr_n, ale, vram_ad, vram_a, +-- vga_clk, h_sync_n, v_sync_n, r, g, b); + +-- ppu_addr_decoder : v_address_decoder generic map (size14, data_size) +-- port map (ppu_clk, rd_n, wr_n, ale, vram_ad, vram_a); + +-----debug----- + dbg_pin0 <= cpu_clk; + dbg_pin1 <= ppu_clk; + dbg_pin2 <= vga_clk; + +end rtl; + diff --git a/de1_nes/de1_nes.vwf b/de1_nes/de1_nes.vwf new file mode 100644 index 0000000..469bc77 --- /dev/null +++ b/de1_nes/de1_nes.vwf @@ -0,0 +1,186 @@ +/* +WARNING: Do NOT edit the input and output ports in this file in a text +editor if you plan to continue editing the block that represents it in +the Block Editor! File corruption is VERY likely to occur. +*/ + +/* +Copyright (C) 1991-2007 Altera Corporation +Your use of Altera Corporation's design tools, logic functions +and other software and tools, and its AMPP partner logic +functions, and any output files from any of the foregoing +(including device programming or simulation files), and any +associated documentation or information are expressly subject +to the terms and conditions of the Altera Program License +Subscription Agreement, Altera MegaCore Function License +Agreement, or other applicable license agreement, including, +without limitation, that your use is for the sole purpose of +programming logic devices manufactured by Altera and sold by +Altera or its authorized distributors. Please refer to the +applicable agreement for further details. +*/ + +HEADER +{ + VERSION = 1; + TIME_UNIT = ns; + DATA_OFFSET = 0.0; + DATA_DURATION = 10000000.0; + SIMULATION_TIME = 0.0; + GRID_PHASE = 0.0; + GRID_PERIOD = 10.0; + GRID_DUTY_CYCLE = 50; +} + +SIGNAL("base_clk") +{ + VALUE_TYPE = NINE_LEVEL_BIT; + SIGNAL_TYPE = SINGLE_BIT; + WIDTH = 1; + LSB_INDEX = -1; + DIRECTION = INPUT; + PARENT = ""; +} + +SIGNAL("rst_n") +{ + VALUE_TYPE = NINE_LEVEL_BIT; + SIGNAL_TYPE = SINGLE_BIT; + WIDTH = 1; + LSB_INDEX = -1; + DIRECTION = INPUT; + PARENT = ""; +} + +SIGNAL("dbg_pin0") +{ + VALUE_TYPE = NINE_LEVEL_BIT; + SIGNAL_TYPE = SINGLE_BIT; + WIDTH = 1; + LSB_INDEX = -1; + DIRECTION = OUTPUT; + PARENT = ""; +} + +SIGNAL("dbg_pin1") +{ + VALUE_TYPE = NINE_LEVEL_BIT; + SIGNAL_TYPE = SINGLE_BIT; + WIDTH = 1; + LSB_INDEX = -1; + DIRECTION = OUTPUT; + PARENT = ""; +} + +SIGNAL("dbg_pin2") +{ + VALUE_TYPE = NINE_LEVEL_BIT; + SIGNAL_TYPE = SINGLE_BIT; + WIDTH = 1; + LSB_INDEX = -1; + DIRECTION = OUTPUT; + PARENT = ""; +} + +TRANSITION_LIST("base_clk") +{ + NODE + { + REPEAT = 1; + NODE + { + REPEAT = 125000; + LEVEL 0 FOR 40.0; + LEVEL 1 FOR 40.0; + } + } +} + +TRANSITION_LIST("rst_n") +{ + NODE + { + REPEAT = 1; + LEVEL 0 FOR 400.0; + LEVEL 1 FOR 9999600.0; + } +} + +TRANSITION_LIST("dbg_pin0") +{ + NODE + { + REPEAT = 1; + LEVEL X FOR 10000000.0; + } +} + +TRANSITION_LIST("dbg_pin1") +{ + NODE + { + REPEAT = 1; + LEVEL X FOR 10000000.0; + } +} + +TRANSITION_LIST("dbg_pin2") +{ + NODE + { + REPEAT = 1; + LEVEL X FOR 10000000.0; + } +} + +DISPLAY_LINE +{ + CHANNEL = "base_clk"; + EXPAND_STATUS = COLLAPSED; + RADIX = ASCII; + TREE_INDEX = 0; + TREE_LEVEL = 0; +} + +DISPLAY_LINE +{ + CHANNEL = "rst_n"; + EXPAND_STATUS = COLLAPSED; + RADIX = ASCII; + TREE_INDEX = 1; + TREE_LEVEL = 0; +} + +DISPLAY_LINE +{ + CHANNEL = "dbg_pin0"; + EXPAND_STATUS = COLLAPSED; + RADIX = ASCII; + TREE_INDEX = 2; + TREE_LEVEL = 0; +} + +DISPLAY_LINE +{ + CHANNEL = "dbg_pin1"; + EXPAND_STATUS = COLLAPSED; + RADIX = ASCII; + TREE_INDEX = 3; + TREE_LEVEL = 0; +} + +DISPLAY_LINE +{ + CHANNEL = "dbg_pin2"; + EXPAND_STATUS = COLLAPSED; + RADIX = ASCII; + TREE_INDEX = 4; + TREE_LEVEL = 0; +} + +TIME_BAR +{ + TIME = 29850; + MASTER = TRUE; +} +; diff --git a/de1_nes/ppu/ppu_registers.vhd b/de1_nes/ppu/ppu_registers.vhd new file mode 100644 index 0000000..bca7ea2 --- /dev/null +++ b/de1_nes/ppu/ppu_registers.vhd @@ -0,0 +1,170 @@ +-------------------------------- +----------shift registers ----- +-------------------------------- +library ieee; +use ieee.std_logic_1164.all; + +entity shift_register is + generic ( + dsize : integer := 8; + shift : integer := 1 + ); + port ( clk : in std_logic; + rst_n : in std_logic; + ce_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector(dsize - 1 downto 0); + q : out std_logic_vector(dsize - 1 downto 0) + ); +end shift_register; + +architecture rtl of shift_register is + +component d_flip_flop + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +signal dff_we_n : std_logic; +signal q_out : std_logic_vector(dsize - 1 downto 0); +signal df_in : std_logic_vector(dsize - 1 downto 0); + +begin + + q <= q_out; + dff_we_n <= ce_n and we_n; + dff_inst : d_flip_flop generic map (dsize) + port map (clk, rst_n, '1', dff_we_n, df_in, q_out); + + clk_p : process (clk, we_n, ce_n, d) + begin + if (we_n = '0') then + df_in <= d; + elsif (ce_n = '0') then + df_in (dsize - 1 downto dsize - shift) <= (others => '0'); + df_in (dsize - shift - 1 downto 0) <= + q_out(dsize - 1 downto shift); + end if; + end process; + +end rtl; + +------------------------------- +------ count up registers ----- +------------------------------- +library ieee; +use ieee.std_logic_1164.all; + +entity counter_register is + + generic ( + dsize : integer := 8; + inc : integer := 1 + ); + port ( clk : in std_logic; + rst_n : in std_logic; + ce_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector(dsize - 1 downto 0); + q : out std_logic_vector(dsize - 1 downto 0) + ); +end counter_register; + +architecture rtl of counter_register is + +component d_flip_flop + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + res_n : in std_logic; + set_n : in std_logic; + we_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +use ieee.std_logic_unsigned.all; + +signal dff_we_n : std_logic; +signal d_in : std_logic_vector(dsize - 1 downto 0); +signal q_out : std_logic_vector(dsize - 1 downto 0); + +begin + q <= q_out; + dff_we_n <= ce_n and we_n; + counter_reg_inst : d_flip_flop generic map (dsize) + port map (clk, rst_n, '1', dff_we_n, d_in, q_out); + + clk_p : process (clk, we_n, ce_n, d) + begin + if (we_n = '0') then + d_in <= d; + elsif (ce_n = '0') then + d_in <= q_out + inc; + end if; + end process; + +end rtl; + +------------------------------- +-- LS373 transparent D-latch--- +------------------------------- +library ieee; +use ieee.std_logic_1164.all; + +entity ls373 is + generic ( + dsize : integer := 8 + ); + port ( c : in std_logic; + oc_n : in std_logic; + d : in std_logic_vector(dsize - 1 downto 0); + q : out std_logic_vector(dsize - 1 downto 0) + ); +end ls373; + +architecture rtl of ls373 is + +component latch + generic ( + dsize : integer := 8 + ); + port ( + clk : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +component tri_state_buffer + generic ( + dsize : integer := 8 + ); + port ( + oe_n : in std_logic; + d : in std_logic_vector (dsize - 1 downto 0); + q : out std_logic_vector (dsize - 1 downto 0) + ); +end component; + +signal q_out : std_logic_vector (dsize - 1 downto 0); + +begin + ls373_inst : latch generic map (dsize) + port map (c, d, q_out); + tsb_inst : tri_state_buffer generic map (dsize) + port map (oc_n, q_out, q); +end rtl; + -- 2.11.0