1 ----------------------------
2 ---- 6502 ALU implementation
3 ----------------------------
5 use ieee.std_logic_1164.all;
8 generic ( dsize : integer := 8
10 port ( alu_sel : in std_logic_vector (2 downto 0);
11 d_we_n : in std_logic;
12 d_oe_n : in std_logic;
13 ah_we_n : in std_logic;
14 ah_oe_n : in std_logic;
15 al_we_n : in std_logic;
16 al_oe_n : in std_logic;
17 acc_we_n : in std_logic;
18 acc_oe_n : in std_logic;
19 int_d_bus : inout std_logic_vector (dsize - 1 downto 0);
20 int_ah_bus : inout std_logic_vector (dsize - 1 downto 0);
21 int_al_bus : inout std_logic_vector (dsize - 1 downto 0);
22 acc : inout std_logic_vector (dsize - 1 downto 0);
23 carry : inout std_logic;
24 overflow : out std_logic
28 architecture rtl of alu is
29 signal d1 : std_logic_vector (dsize - 1 downto 0);
30 signal d2 : std_logic_vector (dsize - 1 downto 0);
31 signal d_out : std_logic_vector (dsize - 1 downto 0);
37 ----------------------------------------
38 ---- 6502 effective address calucurator
39 ----------------------------------------
41 use ieee.std_logic_1164.all;
42 use ieee.std_logic_unsigned.all;
44 entity effective_adder is
45 generic ( dsize : integer := 8
49 ah_oe_n : in std_logic;
50 al_oe_n : in std_logic;
51 base : in std_logic_vector (dsize - 1 downto 0);
52 index : in std_logic_vector (dsize - 1 downto 0);
53 ah_bus : out std_logic_vector (dsize - 1 downto 0);
54 al_bus : out std_logic_vector (dsize - 1 downto 0);
59 architecture rtl of effective_adder is
68 d : in std_logic_vector (dsize - 1 downto 0);
69 q : out std_logic_vector (dsize - 1 downto 0)
73 signal al_out : std_logic_vector (dsize - 1 downto 0);
74 signal ah_out : std_logic_vector (dsize - 1 downto 0);
75 signal old_al : std_logic_vector (dsize - 1 downto 0);
76 signal adc_work : std_logic_vector (dsize downto 0);
79 adc_work <= ('0' & base) + ('0' & index);
80 carry <= adc_work(dsize);
81 al_out <= adc_work(dsize - 1 downto 0);
83 al_buf : dff generic map (dsize)
84 port map (clk, '0', '0', al_out, old_al);
86 --both output means, page boundary crossed.
87 --output old effective addr low.
88 al_bus <= old_al when al_oe_n = '0' and ah_oe_n = '0' else
89 al_out when al_oe_n = '0' else
92 --ah output means, page boundary crossed.
93 ah_bus <= base + '1' when ah_oe_n = '0' else