1 |
32 |
robfinch |
// ============================================================================
|
2 |
|
|
// __
|
3 |
|
|
// \\__/ o\ (C) 2013 Robert Finch, Stratford
|
4 |
|
|
// \ __ / All rights reserved.
|
5 |
|
|
// \/_// robfinch<remove>@opencores.org
|
6 |
|
|
// ||
|
7 |
|
|
//
|
8 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
9 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
10 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
// (at your option) any later version.
|
12 |
|
|
//
|
13 |
|
|
// This source file is distributed in the hope that it will be useful,
|
14 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
// GNU General Public License for more details.
|
17 |
|
|
//
|
18 |
|
|
// You should have received a copy of the GNU General Public License
|
19 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
|
|
//
|
21 |
|
|
// ============================================================================
|
22 |
|
|
//
|
23 |
|
|
BYTE_IFETCH:
|
24 |
|
|
begin
|
25 |
|
|
vect <= `BYTE_IRQ_VECT;
|
26 |
|
|
suppress_pcinc <= 4'hF; // default: no suppression of increment
|
27 |
|
|
opc <= pc;
|
28 |
|
|
hwi <= `FALSE;
|
29 |
|
|
isBusErr <= `FALSE;
|
30 |
|
|
pg2 <= `FALSE;
|
31 |
|
|
store_what <= `STW_DEF;
|
32 |
|
|
if (nmi_edge & gie) begin // imiss indicates cache controller is active and this state is in a waiting loop
|
33 |
|
|
ir[7:0] <= `BRK;
|
34 |
|
|
nmi_edge <= 1'b0;
|
35 |
|
|
wai <= 1'b0;
|
36 |
|
|
hwi <= `TRUE;
|
37 |
|
|
if (nmoi) begin
|
38 |
|
|
vect <= `NMI_VECT;
|
39 |
|
|
state <= DECODE;
|
40 |
|
|
end
|
41 |
|
|
else begin
|
42 |
|
|
vect <= `BYTE_NMI_VECT;
|
43 |
|
|
state <= BYTE_DECODE;
|
44 |
|
|
end
|
45 |
|
|
end
|
46 |
|
|
else if (irq_i & gie) begin
|
47 |
|
|
wai <= 1'b0;
|
48 |
|
|
if (im) begin
|
49 |
|
|
if (unCachedInsn) begin
|
50 |
|
|
if (bhit) begin
|
51 |
|
|
ir <= ibuf;
|
52 |
|
|
state <= BYTE_DECODE;
|
53 |
|
|
end
|
54 |
|
|
else
|
55 |
|
|
state <= LOAD_IBUF1;
|
56 |
|
|
end
|
57 |
|
|
else begin
|
58 |
|
|
if (ihit) begin
|
59 |
|
|
ir <= insn;
|
60 |
|
|
state <= BYTE_DECODE;
|
61 |
|
|
end
|
62 |
|
|
else
|
63 |
|
|
state <= ICACHE1;
|
64 |
|
|
end
|
65 |
|
|
end
|
66 |
|
|
else begin
|
67 |
|
|
ir[7:0] <= `BRK;
|
68 |
|
|
hwi <= `TRUE;
|
69 |
|
|
if (nmoi) begin
|
70 |
|
|
vect <= {vbr[31:9],irq_vect,2'b00};
|
71 |
|
|
state <= DECODE;
|
72 |
|
|
end
|
73 |
|
|
else begin
|
74 |
|
|
state <= BYTE_DECODE;
|
75 |
|
|
end
|
76 |
|
|
end
|
77 |
|
|
end
|
78 |
|
|
else if (!wai) begin
|
79 |
|
|
if (unCachedInsn) begin
|
80 |
|
|
if (bhit) begin
|
81 |
|
|
ir <= ibuf;
|
82 |
|
|
state <= BYTE_DECODE;
|
83 |
|
|
end
|
84 |
|
|
else
|
85 |
|
|
state <= LOAD_IBUF1;
|
86 |
|
|
end
|
87 |
|
|
else begin
|
88 |
|
|
if (ihit) begin
|
89 |
|
|
ir <= insn;
|
90 |
|
|
state <= BYTE_DECODE;
|
91 |
|
|
end
|
92 |
|
|
else
|
93 |
|
|
state <= ICACHE1;
|
94 |
|
|
end
|
95 |
|
|
end
|
96 |
|
|
if (hist_capture) begin
|
97 |
|
|
history_buf[history_ndx] <= pc;
|
98 |
|
|
history_ndx <= history_ndx+7'd1;
|
99 |
|
|
end
|
100 |
|
|
case(ir[7:0])
|
101 |
|
|
`TAY,`TXY,`DEY,`INY: begin y[7:0] <= res8; nf <= resn8; zf <= resz8; end
|
102 |
|
|
`TAX,`TYX,`TSX,`DEX,`INX: begin x[7:0] <= res8; nf <= resn8; zf <= resz8; end
|
103 |
|
|
`TSA,`TYA,`TXA,`INA,`DEA: begin acc[7:0] <= res8; nf <= resn8; zf <= resz8; end
|
104 |
|
|
`TAS,`TXS: begin sp <= res8[7:0]; end
|
105 |
|
|
`ADC_IMM:
|
106 |
|
|
begin
|
107 |
|
|
acc[7:0] <= df ? bcaio : res8;
|
108 |
|
|
cf <= df ? bcaico : resc8;
|
109 |
|
|
// vf <= resv8;
|
110 |
|
|
vf <= (res8[7] ^ b8[7]) & (1'b1 ^ acc[7] ^ b8[7]);
|
111 |
|
|
nf <= df ? bcaio[7] : resn8;
|
112 |
|
|
zf <= df ? bcaio==8'h00 : resz8;
|
113 |
|
|
end
|
114 |
|
|
`ADC_ZP,`ADC_ZPX,`ADC_IX,`ADC_IY,`ADC_ABS,`ADC_ABSX,`ADC_ABSY,`ADC_I:
|
115 |
|
|
begin
|
116 |
|
|
acc[7:0] <= df ? bcao : res8;
|
117 |
|
|
cf <= df ? bcaco : resc8;
|
118 |
|
|
vf <= (res8[7] ^ b8[7]) & (1'b1 ^ acc[7] ^ b8[7]);
|
119 |
|
|
nf <= df ? bcao[7] : resn8;
|
120 |
|
|
zf <= df ? bcao==8'h00 : resz8;
|
121 |
|
|
end
|
122 |
|
|
`SBC_IMM:
|
123 |
|
|
begin
|
124 |
|
|
acc[7:0] <= df ? bcsio : res8;
|
125 |
|
|
cf <= ~(df ? bcsico : resc8);
|
126 |
|
|
vf <= (1'b1 ^ res8[7] ^ b8[7]) & (acc[7] ^ b8[7]);
|
127 |
|
|
nf <= df ? bcsio[7] : resn8;
|
128 |
|
|
zf <= df ? bcsio==8'h00 : resz8;
|
129 |
|
|
end
|
130 |
|
|
`SBC_ZP,`SBC_ZPX,`SBC_IX,`SBC_IY,`SBC_ABS,`SBC_ABSX,`SBC_ABSY,`SBC_I:
|
131 |
|
|
begin
|
132 |
|
|
acc[7:0] <= df ? bcso : res8;
|
133 |
|
|
vf <= (1'b1 ^ res8[7] ^ b8[7]) & (acc[7] ^ b8[7]);
|
134 |
|
|
cf <= ~(df ? bcsco : resc8);
|
135 |
|
|
nf <= df ? bcso[7] : resn8;
|
136 |
|
|
zf <= df ? bcso==8'h00 : resz8;
|
137 |
|
|
end
|
138 |
|
|
`CMP_IMM,`CMP_ZP,`CMP_ZPX,`CMP_IX,`CMP_IY,`CMP_ABS,`CMP_ABSX,`CMP_ABSY,`CMP_I,
|
139 |
|
|
`CPX_IMM,`CPX_ZP,`CPX_ABS,
|
140 |
|
|
`CPY_IMM,`CPY_ZP,`CPY_ABS:
|
141 |
|
|
begin cf <= ~resc8; nf <= resn8; zf <= resz8; end
|
142 |
|
|
`BIT_IMM,`BIT_ZP,`BIT_ZPX,`BIT_ABS,`BIT_ABSX:
|
143 |
|
|
begin nf <= b8[7]; vf <= b8[6]; zf <= resz8; end
|
144 |
|
|
`TRB_ZP,`TRB_ABS,`TSB_ZP,`TSB_ABS:
|
145 |
|
|
begin zf <= resz8; end
|
146 |
|
|
`LDA_IMM,`LDA_ZP,`LDA_ZPX,`LDA_IX,`LDA_IY,`LDA_ABS,`LDA_ABSX,`LDA_ABSY,`LDA_I,
|
147 |
|
|
`AND_IMM,`AND_ZP,`AND_ZPX,`AND_IX,`AND_IY,`AND_ABS,`AND_ABSX,`AND_ABSY,`AND_I,
|
148 |
|
|
`ORA_IMM,`ORA_ZP,`ORA_ZPX,`ORA_IX,`ORA_IY,`ORA_ABS,`ORA_ABSX,`ORA_ABSY,`ORA_I,
|
149 |
|
|
`EOR_IMM,`EOR_ZP,`EOR_ZPX,`EOR_IX,`EOR_IY,`EOR_ABS,`EOR_ABSX,`EOR_ABSY,`EOR_I:
|
150 |
|
|
begin acc[7:0] <= res8; nf <= resn8; zf <= resz8; end
|
151 |
|
|
`ASL_ACC: begin acc[7:0] <= res8; cf <= resc8; nf <= resn8; zf <= resz8; end
|
152 |
|
|
`ROL_ACC: begin acc[7:0] <= res8; cf <= resc8; nf <= resn8; zf <= resz8; end
|
153 |
|
|
`LSR_ACC: begin acc[7:0] <= res8; cf <= resc8; nf <= resn8; zf <= resz8; end
|
154 |
|
|
`ROR_ACC: begin acc[7:0] <= res8; cf <= resc8; nf <= resn8; zf <= resz8; end
|
155 |
|
|
`ASL_ZP,`ASL_ZPX,`ASL_ABS,`ASL_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
156 |
|
|
`ROL_ZP,`ROL_ZPX,`ROL_ABS,`ROL_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
157 |
|
|
`LSR_ZP,`LSR_ZPX,`LSR_ABS,`LSR_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
158 |
|
|
`ROR_ZP,`ROR_ZPX,`ROR_ABS,`ROR_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
159 |
|
|
`INC_ZP,`INC_ZPX,`INC_ABS,`INC_ABSX: begin nf <= resn8; zf <= resz8; end
|
160 |
|
|
`DEC_ZP,`DEC_ZPX,`DEC_ABS,`DEC_ABSX: begin nf <= resn8; zf <= resz8; end
|
161 |
|
|
`PLA: begin acc[7:0] <= res8; zf <= resz8; nf <= resn8; end
|
162 |
|
|
`PLX: begin x[7:0] <= res8; zf <= resz8; nf <= resn8; end
|
163 |
|
|
`PLY: begin y[7:0] <= res8; zf <= resz8; nf <= resn8; end
|
164 |
|
|
`LDX_IMM,`LDX_ZP,`LDX_ZPY,`LDX_ABS,`LDX_ABSY: begin x[7:0] <= res8; nf <= resn8; zf <= resz8; end
|
165 |
|
|
`LDY_IMM,`LDY_ZP,`LDY_ZPX,`LDY_ABS,`LDY_ABSX: begin y[7:0] <= res8; nf <= resn8; zf <= resz8; end
|
166 |
|
|
endcase
|
167 |
|
|
end
|