1 |
10 |
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 |
20 |
robfinch |
//
|
21 |
|
|
// Datapath calculations for 32 bit mode.
|
22 |
10 |
robfinch |
// ============================================================================
|
23 |
|
|
//
|
24 |
5 |
robfinch |
CALC:
|
25 |
|
|
begin
|
26 |
|
|
state <= IFETCH;
|
27 |
20 |
robfinch |
case(ir[7:0])
|
28 |
|
|
//The following handled in the DECODE stage which reduces the CPI at a cost of clock frequency.
|
29 |
|
|
`RR:
|
30 |
|
|
case(ir[23:20])
|
31 |
19 |
robfinch |
// `ADD_RR: res <= a + b;
|
32 |
|
|
// `SUB_RR: res <= a - b; // Also CMP
|
33 |
|
|
// `AND_RR: res <= a & b; // Also BIT
|
34 |
|
|
// `OR_RR: res <= a | b;
|
35 |
|
|
// `EOR_RR: res <= a ^ b;
|
36 |
|
|
// `MUL_RR: prod <= a * b; // slows the whole core down
|
37 |
20 |
robfinch |
`ASL_RRR: res <= shlo;
|
38 |
|
|
`LSR_RRR: res <= shro;
|
39 |
|
|
endcase
|
40 |
21 |
robfinch |
`ADD_ZPX,`ADD_IX,`ADD_IY,`ADD_ABS,`ADD_ABSX,`ADD_RIND: begin res <= a + b + {31'b0,df&cf}; end
|
41 |
|
|
`SUB_ZPX,`SUB_IX,`SUB_IY,`SUB_ABS,`SUB_ABSX,`SUB_RIND: begin res <= a - b - {31'b0,df&~cf&|Rt}; end // Also CMP
|
42 |
20 |
robfinch |
`AND_ZPX,`AND_IX,`AND_IY,`AND_ABS,`AND_ABSX,`AND_RIND: begin res <= a & b; end // Also BIT
|
43 |
|
|
`OR_ZPX,`OR_IX,`OR_IY,`OR_ABS,`OR_ABSX,`OR_RIND: begin res <= a | b; end // Also LD
|
44 |
|
|
`EOR_ZPX,`EOR_IX,`EOR_IY,`EOR_ABS,`EOR_ABSX,`EOR_RIND: begin res <= a ^ b; end
|
45 |
|
|
`LDX_ZPY,`LDX_ABS,`LDX_ABSY: begin res <= b; end
|
46 |
|
|
`LDY_ZPX,`LDY_ABS,`LDY_ABSX: begin res <= b; end
|
47 |
|
|
`CPX_ZPX,`CPX_ABS: begin res <= x - b; end
|
48 |
|
|
`CPY_ZPX,`CPY_ABS: begin res <= y - b; end
|
49 |
|
|
`ASL_IMM8: res <= shlo;
|
50 |
|
|
`LSR_IMM8: res <= shro;
|
51 |
|
|
//The following handled in the DECODE stage which reduces the CPI at a cost of clock frequency.
|
52 |
19 |
robfinch |
// `ASL_RR: begin res <= {a,1'b0}; end
|
53 |
|
|
// `ROL_RR: begin res <= {a,cf}; end
|
54 |
|
|
// `LSR_RR: begin res <= {a[0],1'b0,a[31:1]}; end
|
55 |
|
|
// `ROR_RR: begin res <= {a[0],cf,a[31:1]}; end
|
56 |
20 |
robfinch |
`ASL_ZPX,`ASL_ABS,`ASL_ABSX: begin res <= {b,1'b0}; wdat <= {b,1'b0}; wadr <= radr; wadr2LSB <= radr2LSB; state <= STORE1; end
|
57 |
|
|
`ROL_ZPX,`ROL_ABS,`ROL_ABSX: begin res <= {b,cf}; wdat <= {b,cf}; wadr <= radr; wadr2LSB <= radr2LSB; state <= STORE1; end
|
58 |
|
|
`LSR_ZPX,`LSR_ABS,`LSR_ABSX: begin res <= {b[0],1'b0,b[31:1]}; wdat <= {b[0],1'b0,b[31:1]}; wadr <= radr; wadr2LSB <= radr2LSB; state <= STORE1; end
|
59 |
|
|
`ROR_ZPX,`ROR_ABS,`ROR_ABSX: begin res <= {b[0],cf,b[31:1]}; wdat <= {b[0],cf,b[31:1]}; wadr <= radr; wadr2LSB <= radr2LSB; state <= STORE1; end
|
60 |
|
|
`INC_ZPX,`INC_ABS,`INC_ABSX: begin res <= b + 1; wdat <= b + 1; wadr <= radr; wadr2LSB <= radr2LSB; state <= STORE1; end
|
61 |
|
|
`DEC_ZPX,`DEC_ABS,`DEC_ABSX: begin res <= b - 1; wdat <= b - 1; wadr <= radr; wadr2LSB <= radr2LSB; state <= STORE1; end
|
62 |
|
|
`ORB_ZPX,`ORB_ABS,`ORB_ABSX: begin res <= a | {24'h0,b8}; end
|
63 |
|
|
endcase
|
64 |
5 |
robfinch |
end
|