1 |
4 |
Valerio63 |
library IEEE;
|
2 |
|
|
use IEEE.std_logic_1164.all; -- defines std_logic types
|
3 |
|
|
use IEEE.STD_LOGIC_unsigned.all;
|
4 |
|
|
use IEEE.STD_LOGIC_arith.all;
|
5 |
|
|
|
6 |
|
|
-- 16 bit memory pointer address register
|
7 |
|
|
entity mpr is
|
8 |
|
|
port( clk: in STD_LOGIC;
|
9 |
|
|
fwait: in STD_LOGIC;
|
10 |
|
|
c: in STD_LOGIC; -- carry input
|
11 |
|
|
fc: in STD_LOGIC_VECTOR(3 downto 0);
|
12 |
|
|
din_l: in STD_LOGIC_VECTOR(7 downto 0);
|
13 |
|
|
din_h: in STD_LOGIC_VECTOR(7 downto 0);
|
14 |
|
|
zp: in STD_LOGIC_VECTOR(7 downto 0);
|
15 |
|
|
v: in STD_LOGIC_VECTOR(2 downto 0);
|
16 |
|
|
dout: out STD_LOGIC_VECTOR(15 downto 0)
|
17 |
|
|
);
|
18 |
|
|
end mpr;
|
19 |
|
|
|
20 |
|
|
architecture rtl of mpr is
|
21 |
|
|
constant NOP_M: STD_LOGIC_VECTOR(3 downto 0) := "0000"; -- no operation
|
22 |
|
|
constant LSB_M: STD_LOGIC_VECTOR(3 downto 0) := "0001"; -- load lsb
|
23 |
|
|
constant MSB_M: STD_LOGIC_VECTOR(3 downto 0) := "0010"; -- load msb
|
24 |
|
|
constant INC_M: STD_LOGIC_VECTOR(3 downto 0) := "0011"; -- increment LSB
|
25 |
|
|
constant VEC_M: STD_LOGIC_VECTOR(3 downto 0) := "0100"; -- load vector
|
26 |
|
|
constant ZPL_M: STD_LOGIC_VECTOR(3 downto 0) := "0101"; -- load ZEROPAGE
|
27 |
|
|
constant ALL_M: STD_LOGIC_VECTOR(3 downto 0) := "0110"; -- load all 16 bit register
|
28 |
|
|
constant ICC_M: STD_LOGIC_VECTOR(3 downto 0) := "0111"; -- increment MSB with carry
|
29 |
|
|
constant INM_M: STD_LOGIC_VECTOR(3 downto 0) := "1000"; -- increment MSB/LSB
|
30 |
|
|
|
31 |
|
|
signal reg: STD_LOGIC_VECTOR(15 downto 0);
|
32 |
|
|
begin
|
33 |
|
|
process(clk)
|
34 |
|
|
begin
|
35 |
|
|
if (clk'event and clk = '1') then
|
36 |
|
|
if fwait = '1' then
|
37 |
|
|
reg <= reg;
|
38 |
|
|
else
|
39 |
|
|
case fc is
|
40 |
|
|
when LSB_M => reg(7 downto 0) <= din_l; reg(15 downto 8) <= reg(15 downto 8);
|
41 |
|
|
when MSB_M => reg(15 downto 8) <= din_h; reg(7 downto 0) <= reg(7 downto 0);
|
42 |
|
|
when ALL_M => reg(15 downto 8) <= din_h; reg(7 downto 0) <= din_l;
|
43 |
|
|
when INC_M => reg(7 downto 0) <= reg(7 downto 0) +1;
|
44 |
|
|
when VEC_M => reg(15 downto 3) <= "1111111111111"; reg(2 downto 0) <= v; -- 0xFFFX load vector
|
45 |
|
|
when ZPL_M => reg(15 downto 8) <= zp; reg(7 downto 0) <= din_l; -- 0xXXXX zeropage operation
|
46 |
|
|
when ICC_M => reg(15 downto 8) <= reg(15 downto 8) + c; -- increment MSB for indexed addressing mode
|
47 |
|
|
when INM_M => reg <= reg +1;
|
48 |
|
|
when others => reg <= reg;
|
49 |
|
|
end case;
|
50 |
|
|
end if;
|
51 |
|
|
end if;
|
52 |
|
|
end process;
|
53 |
|
|
dout <= reg;
|
54 |
|
|
end rtl;
|
55 |
|
|
|
56 |
|
|
|