OpenCores
URL https://opencores.org/ocsvn/v65c816/v65c816/trunk

Subversion Repositories v65c816

[/] [v65c816/] [trunk/] [pr.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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/E = carry/borrow flag (emulation bit: 1 = emulation mode, 0 = native mode)
11
-- |||||||---- Z = zero flag
12
-- ||||||----- I = interrupt mask
13
-- |||||------ D = decimal/binary alu mode
14
-- ||||------- B/X = index reg. select (1 = 8 bit, 0 = 16 bit) (B Break: 0 on stack after interrupt if E emulation mode = 1)
15
-- |||-------- M = memory/acc. select (1 = 8 bit, 0 = 16 bit) (always 1 if E = 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
                     mpy_z:  in STD_LOGIC;                        -- Z input from multiplier                    
27
                     mpy_n:  in STD_LOGIC;                        -- N input from multiplier                    
28
             swi:  in STD_LOGIC;                        -- software interrupt (BRK/COP opcode flag)
29
          acr_in:  in STD_LOGIC;                        -- auxiliary carry in   
30
              fc:  in STD_LOGIC_VECTOR(4 downto 0);     -- function code 
31
             din:  in STD_LOGIC_VECTOR(7 downto 0);     -- input
32
            dout: out STD_LOGIC_VECTOR(7 downto 0);     -- output
33
         acr_out: out STD_LOGIC;                        -- auxiliary carry out   
34
                             em: out STD_LOGIC;                        -- emulation (1)/native mode (0)
35
                         two_op: out STD_LOGIC                         -- two byte instruction    
36
      );
37
end pr;
38
 
39
architecture rtl of pr is
40
constant NOP_P: STD_LOGIC_VECTOR(4 downto 0) := "00000"; -- PR no operation
41
constant PLD_P: STD_LOGIC_VECTOR(4 downto 0) := "00001"; -- PR load
42
constant FLD_P: STD_LOGIC_VECTOR(4 downto 0) := "00010"; -- NZ load
43
constant FLC_P: STD_LOGIC_VECTOR(4 downto 0) := "00011"; -- NZC load
44
constant FLV_P: STD_LOGIC_VECTOR(4 downto 0) := "00100"; -- NVZC load
45
constant SEC_P: STD_LOGIC_VECTOR(4 downto 0) := "00101"; -- 1 => C 
46
constant CLC_P: STD_LOGIC_VECTOR(4 downto 0) := "00110"; -- 0 => C 
47
constant SEI_P: STD_LOGIC_VECTOR(4 downto 0) := "00111"; -- 1 => I 
48
constant CLI_P: STD_LOGIC_VECTOR(4 downto 0) := "01000"; -- 0 => I 
49
constant SED_P: STD_LOGIC_VECTOR(4 downto 0) := "01001"; -- 1 => D 
50
constant CLD_P: STD_LOGIC_VECTOR(4 downto 0) := "01010"; -- 0 => D 
51
constant CLV_P: STD_LOGIC_VECTOR(4 downto 0) := "01011"; -- 0 => V 
52
constant AUC_P: STD_LOGIC_VECTOR(4 downto 0) := "01100"; -- auc => ACR 
53
constant HAC_P: STD_LOGIC_VECTOR(4 downto 0) := "01101"; -- hold ACR 
54
constant SID_P: STD_LOGIC_VECTOR(4 downto 0) := "01110"; -- 1 => I/D 
55
constant LDZ_P: STD_LOGIC_VECTOR(4 downto 0) := "01111"; -- Z load
56
constant XCE_P: STD_LOGIC_VECTOR(4 downto 0) := "10000"; -- E => C; C => E
57
constant SEP_P: STD_LOGIC_VECTOR(4 downto 0) := "10001"; -- P = P OR din
58
constant REP_P: STD_LOGIC_VECTOR(4 downto 0) := "10010"; -- P = P AND not din
59
constant WDM_P: STD_LOGIC_VECTOR(4 downto 0) := "10011"; -- 1 => op_exp;
60
constant WDC_P: STD_LOGIC_VECTOR(4 downto 0) := "10100"; -- 0 => op_exp;
61
constant FLW_P: STD_LOGIC_VECTOR(4 downto 0) := "10101"; -- NZ load, 0 -> op_exp
62
constant MUF_P: STD_LOGIC_VECTOR(4 downto 0) := "10110"; -- Z load from unsigned multplier
63
constant MSF_P: STD_LOGIC_VECTOR(4 downto 0) := "10111"; -- NZ load from unsigned multplier
64
 
65
signal    reg: STD_LOGIC_VECTOR(7 downto 0);
66
signal    acr: STD_LOGIC;                                                      -- carry/borrow used for effective address calculation 
67
signal     eb: STD_LOGIC;                                                      -- emulation/native bit
68
signal op_exp: STD_LOGIC;                                                      -- two opcode bit
69
signal  swint: STD_LOGIC;                                                      -- bit 4 saved on stack when BRK/COP
70
 
71
begin
72
  process(clk)
73
    begin
74
      if (clk'event and clk = '1') then
75
        if fwait = '1' then
76
          reg <= reg;
77
        else
78
          if clr = '1' then
79
            reg <= "00110100";                                                 -- on reset M,X,I = '1'
80
            acr <= '0';
81
                                eb <= '1';                                                         -- on reset set emulation mode
82
                                op_exp <= '0';
83
          else
84
            case fc is
85
              when PLD_P  => reg    <= din;                                    -- load NVMXDIZC 
86
                             acr    <= '0';
87
                                                                          eb     <= eb;
88
                                                                          op_exp <= op_exp;
89
              when FLD_P  => reg    <= n & reg(6 downto 2) & z & reg(0);       -- load NZ
90
                             acr    <= '0';
91
                                                                          eb     <= eb;
92
                                                                          op_exp <= op_exp;
93
              when FLC_P  => reg    <= n & reg(6 downto 2) & z & c;            -- load NZC
94
                             acr    <= '0';
95
                                                                          eb     <= eb;
96
                                                                          op_exp <= op_exp;
97
              when FLV_P  => reg <= n & v & reg(5 downto 2) & z & c;           -- load NVZC
98
                             acr <= '0';
99
              when SEC_P  => reg    <= reg or  "00000001";                     -- 1 => C
100
                             acr    <= acr;
101
                                                                          eb     <= eb;
102
                                                                          op_exp <= op_exp;
103
              when CLC_P  => reg    <= reg and "11111110";                     -- 0 => C
104
                             acr    <= acr;
105
                                                                          eb     <= eb;
106
                                                                          op_exp <= op_exp;
107
              when CLI_P  => reg    <= reg and "11111011";                     -- 0 => I
108
                             acr    <= acr;
109
                                                                          eb     <= eb;
110
                                                                          op_exp <= op_exp;
111
              when SED_P  => reg    <= reg or  "00001000";                     -- 1 => D
112
                             acr    <= acr;
113
                                                                          eb     <= eb;
114
                                                                          op_exp <= op_exp;
115
              when CLD_P  => reg    <= reg and "11110111";                     -- 0 => D
116
                             acr    <= acr;
117
                                                                          eb     <= eb;
118
                                                                          op_exp <= op_exp;
119
                                  when LDZ_P  => reg(1) <= z;                                      -- z => Z
120
                             reg(7 downto 2) <= reg(7 downto 2);
121
                                            reg(0) <= reg(0);
122
                                                                          eb     <= eb;
123
                                                                          op_exp <= op_exp;
124
              when SEI_P  => reg(7 downto 3) <= reg(7 downto 3);
125
                             reg(2) <= '1';                                    -- 1 => I
126
                             reg(1 downto 0) <= reg(1 downto 0);
127
                             acr    <= acr;
128
                                                                          eb     <= eb;
129
                                                                          op_exp <= op_exp;
130
              when SID_P  => reg(7 downto 4) <= reg(7 downto 4);               -- set I and clear D decimal flag (used by interrupt sequence)
131
                             reg(3) <= '0';                                    -- 0 -> D                                 
132
                             reg(2) <= '1';                                    -- 1 => I
133
                             reg(1 downto 0) <= reg(1 downto 0);
134
                             acr    <= acr;
135
                                                                          eb     <= eb;
136
                                                                          op_exp <= op_exp;
137
              when CLV_P  => reg    <= reg and "10111111";                     -- 0 => V
138
                             acr    <= acr;
139
                                                                          eb     <= eb;
140
                                                                          op_exp <= op_exp;
141
              when AUC_P  => acr    <= acr_in;                                 -- store auxiliary carry (ACR)
142
                             reg    <= reg;
143
                                                                          eb     <= eb;
144
                                                                          op_exp <= op_exp;
145
              when HAC_P  => acr    <= acr;                                    -- holds auxiliary carry (ACR)
146
                             reg    <= reg;
147
                                                                          eb     <= eb;
148
                                                                          op_exp <= op_exp;
149
              when XCE_P  => eb     <= reg(0);                                 -- exchange C <=> E (switch emulation/native mode)
150
                             reg(0) <= eb;
151
                             reg(7 downto 1) <= reg(7 downto 1);
152
                             acr    <= '0';
153
                                                                          op_exp <= op_exp;
154
                                  when SEP_P  => reg    <= reg or din;                             -- SEP
155
                             acr    <= '0';
156
                                                                          eb     <= eb;
157
                                                                          op_exp <= op_exp;
158
                                  when REP_P  => reg    <= reg and (not din);                      -- REP
159
                             acr    <= '0';
160
                                                                          eb     <= eb;
161
                                                                          op_exp <= op_exp;
162
                                  when WDM_P  => op_exp <= '1';                                    -- set two byte opcode
163
                             reg    <= reg;
164
                             acr    <= '0';
165
                                                                          eb     <= eb;
166
                                  when WDC_P  => op_exp <= '0';                                    -- clear two byte opcode
167
                             reg    <= reg;
168
                             acr    <= '0';
169
                                                                          eb     <= eb;
170
              when FLW_P  => reg    <= n & reg(6 downto 2) & z & reg(0);       -- load NZ, 0 => op_exp
171
                             acr    <= '0';
172
                                                                          eb     <= eb;
173
                                                                          op_exp <= '0';
174
              when MUF_P  => reg    <= "00" & reg(5 downto 2) & mpy_z & '0';    -- load Z from multiplier, C/VN=0
175
                             acr    <= '0';
176
                                                                          eb     <= eb;
177
                                                                          op_exp <= op_exp;
178
              when MSF_P  => reg    <= mpy_n & '0' & reg(5 downto 2) & mpy_z & '0';  -- load NZ from multiplier, CV=0
179
                             acr    <= '0';
180
                                                                          eb     <= eb;
181
                                                                          op_exp <= op_exp;
182
              when others => reg    <= reg;
183
                             acr    <= '0';
184
                                                                          eb     <= eb;
185
                                                                          op_exp <= op_exp;
186
            end case;
187
                                if eb = '1' then                                                   -- in emulation mode M/X are always set to '1'
188
                                   reg(5 downto 4) <= "11";
189
                                end if;
190
          end if;
191
        end if;
192
      end if;
193
  end process;
194
 
195
  process(fc,reg(4),eb,swi)
196
  begin
197
    if fc = SID_P then
198
            if eb = '0' then
199
                    swint <= reg(4);
200
                 else
201
               swint <= swi;                                                        -- when emulation mode is set the bit 4 reflects BRK opcode (pushed on stack)
202
            end if;
203
         else
204
       swint <= reg(4);
205
    end if;
206
  end process;
207
 
208
  dout(7 downto 5) <= reg(7 downto 5);
209
  dout(4) <= swint;                                                            -- save BRK/COP B="1" on stack if emulation mode
210
  dout(3 downto 0) <= reg(3 downto 0);
211
  acr_out <= acr;
212
  em <= eb;
213
  two_op <= op_exp;
214
end rtl;
215
 
216
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.