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 |
|
|
-- 8 bit processor status register P
|
7 |
|
|
-- NV1BDIZC
|
8 |
|
|
-- 76543210
|
9 |
|
|
-- ||||||||
|
10 |
|
|
-- ||||||||--- C = carry/borrow flag
|
11 |
|
|
-- |||||||---- Z = zero flag
|
12 |
|
|
-- ||||||----- I = interrupt mask
|
13 |
|
|
-- |||||------ D = decimal/binary alu mode
|
14 |
|
|
-- ||||------- B = break opcode flag
|
15 |
|
|
-- |||-------- 1 = always "1'
|
16 |
|
|
-- ||--------- V = overflow flag
|
17 |
|
|
-- |---------- N = negative flag
|
18 |
|
|
entity pr is
|
19 |
|
|
port( clk: in STD_LOGIC; -- clock
|
20 |
|
|
clr: in STD_LOGIC; -- clear
|
21 |
|
|
fwait: in STD_LOGIC;
|
22 |
|
|
n: in STD_LOGIC; -- N input
|
23 |
|
|
v: in STD_LOGIC; -- V input
|
24 |
|
|
z: in STD_LOGIC; -- Z input
|
25 |
|
|
c: in STD_LOGIC; -- C input
|
26 |
|
|
b: in STD_LOGIC; -- B input
|
27 |
|
|
sv: in STD_LOGIC; -- set overflow (by external pin SO)
|
28 |
|
|
acr_in: in STD_LOGIC; -- auxiliary carry in
|
29 |
|
|
fc: in STD_LOGIC_VECTOR(3 downto 0); -- function code
|
30 |
|
|
din: in STD_LOGIC_VECTOR(7 downto 0); -- input
|
31 |
|
|
dout: out STD_LOGIC_VECTOR(7 downto 0); -- output
|
32 |
|
|
acr_out: out STD_LOGIC -- auxiliary carry out
|
33 |
|
|
);
|
34 |
|
|
end pr;
|
35 |
|
|
|
36 |
|
|
architecture rtl of pr is
|
37 |
|
|
constant NOP_P: STD_LOGIC_VECTOR(3 downto 0) := "0000"; -- PR no operation
|
38 |
|
|
constant PLD_P: STD_LOGIC_VECTOR(3 downto 0) := "0001"; -- PR load
|
39 |
|
|
constant FLD_P: STD_LOGIC_VECTOR(3 downto 0) := "0010"; -- NVZC load
|
40 |
|
|
constant SEC_P: STD_LOGIC_VECTOR(3 downto 0) := "0011"; -- 1 => C
|
41 |
|
|
constant CLC_P: STD_LOGIC_VECTOR(3 downto 0) := "0100"; -- 0 => C
|
42 |
|
|
constant SEI_P: STD_LOGIC_VECTOR(3 downto 0) := "0101"; -- 1 => I
|
43 |
|
|
constant CLI_P: STD_LOGIC_VECTOR(3 downto 0) := "0110"; -- 0 => I
|
44 |
|
|
constant SED_P: STD_LOGIC_VECTOR(3 downto 0) := "0111"; -- 1 => D
|
45 |
|
|
constant CLD_P: STD_LOGIC_VECTOR(3 downto 0) := "1000"; -- 0 => D
|
46 |
|
|
constant CLV_P: STD_LOGIC_VECTOR(3 downto 0) := "1010"; -- 0 => V
|
47 |
|
|
constant AUC_P: STD_LOGIC_VECTOR(3 downto 0) := "1011"; -- auc => ACR
|
48 |
|
|
constant HAC_P: STD_LOGIC_VECTOR(3 downto 0) := "1100"; -- hold ACR
|
49 |
|
|
constant SID_P: STD_LOGIC_VECTOR(3 downto 0) := "1101"; -- 1 => I/D
|
50 |
|
|
constant LDZ_P: STD_LOGIC_VECTOR(3 downto 0) := "1110"; -- Z load
|
51 |
|
|
|
52 |
|
|
signal reg: STD_LOGIC_VECTOR(7 downto 0);
|
53 |
|
|
signal acr: STD_LOGIC; -- carry/borrow used for effectve address calculation
|
54 |
|
|
signal i_so: STD_LOGIC;
|
55 |
|
|
|
56 |
|
|
begin
|
57 |
|
|
i_so <= reg(6) when sv = '1' else '1'; -- logic for external pin SO
|
58 |
|
|
process(clk)
|
59 |
|
|
begin
|
60 |
|
|
if (clk'event and clk = '1') then
|
61 |
|
|
if fwait = '1' then
|
62 |
|
|
reg <= reg;
|
63 |
|
|
else
|
64 |
|
|
if clr = '1' then
|
65 |
|
|
reg <= "00100100";
|
66 |
|
|
acr <= '0';
|
67 |
|
|
else
|
68 |
|
|
case fc is
|
69 |
|
|
when PLD_P => reg(7 downto 6) <= din(7 downto 6); -- load NV1BDIZC
|
70 |
|
|
reg(5) <= '1';
|
71 |
|
|
reg(4 downto 0) <= din(4 downto 0);
|
72 |
|
|
acr <= '0';
|
73 |
|
|
when FLD_P => reg <= n & v & '1' & reg(4 downto 2) & z & c; -- load NVZC
|
74 |
|
|
acr <= '0';
|
75 |
|
|
when SEC_P => reg <= reg or "00000001"; -- 1 => C
|
76 |
|
|
acr <= acr;
|
77 |
|
|
when CLC_P => reg <= reg and "11111110"; -- 0 => C
|
78 |
|
|
acr <= acr;
|
79 |
|
|
when CLI_P => reg <= reg and "11111011"; -- 0 => I
|
80 |
|
|
acr <= acr;
|
81 |
|
|
when SED_P => reg <= reg or "00001000"; -- 1 => D
|
82 |
|
|
acr <= acr;
|
83 |
|
|
when CLD_P => reg <= reg and "11110111"; -- 0 => D
|
84 |
|
|
acr <= acr;
|
85 |
|
|
when LDZ_P => reg(1) <= z; -- z => Z
|
86 |
|
|
reg(7 downto 2) <= reg(7 downto 2);
|
87 |
|
|
reg(0) <= reg(0);
|
88 |
|
|
when SEI_P => reg(7 downto 5) <= reg(7 downto 5);
|
89 |
|
|
reg(4) <= reg(4);
|
90 |
|
|
reg(3) <= reg(3);
|
91 |
|
|
reg(2) <= '1'; -- 1 => I
|
92 |
|
|
reg(1 downto 0) <= reg(1 downto 0);
|
93 |
|
|
acr <= acr;
|
94 |
|
|
when SID_P => reg(7 downto 5) <= reg(7 downto 5); -- set I and clear D decimal flag (used by interrupt sequence)
|
95 |
|
|
reg(4) <= b; -- 1 => B (if BRK)
|
96 |
|
|
reg(3) <= '0'; -- 0 -> D
|
97 |
|
|
reg(2) <= '1'; -- 1 => I
|
98 |
|
|
reg(1 downto 0) <= reg(1 downto 0);
|
99 |
|
|
acr <= acr;
|
100 |
|
|
when CLV_P => reg <= reg and "10111111"; -- 0 => V
|
101 |
|
|
acr <= acr;
|
102 |
|
|
when AUC_P => acr <= acr_in; -- store auxiliary carry (ACR)
|
103 |
|
|
reg <= reg;
|
104 |
|
|
when HAC_P => acr <= acr; -- holds auxiliary carry (ACR)
|
105 |
|
|
reg <= reg;
|
106 |
|
|
when others => reg(7) <= reg(7);
|
107 |
|
|
reg(6) <= i_so; -- set overflow by pin SO
|
108 |
|
|
reg(5 downto 0) <= reg(5 downto 0);
|
109 |
|
|
acr <= '0';
|
110 |
|
|
end case;
|
111 |
|
|
end if;
|
112 |
|
|
end if;
|
113 |
|
|
end if;
|
114 |
|
|
end process;
|
115 |
|
|
dout <= reg;
|
116 |
|
|
acr_out <= acr;
|
117 |
|
|
end rtl;
|
118 |
|
|
|
119 |
|
|
|