OSDN Git Service

abs, x working.
[motonesfpga/motonesfpga.git] / simulation / cpu / alu.vhd
1 ----------------------------
2 ---- 6502 ALU implementation
3 ----------------------------
4 library ieee;
5 use ieee.std_logic_1164.all;
6
7 entity alu is 
8     generic (   dsize : integer := 8
9             );
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
25     );
26 end alu;
27
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);
32 begin
33
34 end rtl;
35
36
37 ----------------------------------------
38 ---- 6502 effective address calucurator
39 ----------------------------------------
40 library ieee;
41 use ieee.std_logic_1164.all;
42 use ieee.std_logic_unsigned.all;
43
44 entity effective_adder is 
45     generic (   dsize : integer := 8
46             );
47     port (  
48             clk         : in std_logic;
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);
55             carry           : out std_logic
56     );
57 end effective_adder;
58
59 architecture rtl of effective_adder is
60     component dff
61         generic (
62                 dsize : integer := 8
63                 );
64         port (  
65                 clk     : in std_logic;
66                 we_n    : in std_logic;
67                 oe_n    : in std_logic;
68                 d       : in std_logic_vector (dsize - 1 downto 0);
69                 q       : out std_logic_vector (dsize - 1 downto 0)
70             );
71     end component;
72
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);
77
78 begin
79     adc_work <= ('0' & base) + ('0' & index);
80     carry <= adc_work(dsize);
81     al_out <= adc_work(dsize - 1 downto 0);
82     ---always remory adl.
83     al_buf : dff generic map (dsize)
84         port map (clk, '0', '0', al_out, old_al);
85
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
90             (others => 'Z');
91
92     --ah output means, page boundary crossed.
93     ah_bus <= base + '1' when ah_oe_n = '0' else
94             (others => 'Z');
95
96 end rtl;
97