Line 20... |
Line 20... |
//
|
//
|
// ============================================================================
|
// ============================================================================
|
//
|
//
|
BYTE_IFETCH:
|
BYTE_IFETCH:
|
begin
|
begin
|
vect <= `BYTE_IRQ_VECT;
|
ic_whence <= BYTE_IFETCH;
|
|
vect <= m816 ? `BRK_VECT_816 : `BYTE_IRQ_VECT;
|
vect[31:16] <= abs8[31:16];
|
vect[31:16] <= abs8[31:16];
|
suppress_pcinc <= 4'hF; // default: no suppression of increment
|
suppress_pcinc <= 4'hF; // default: no suppression of increment
|
opc <= pc;
|
opc <= pc;
|
hwi <= `FALSE;
|
hwi <= `FALSE;
|
isBusErr <= `FALSE;
|
isBusErr <= `FALSE;
|
pg2 <= `FALSE;
|
pg2 <= `FALSE;
|
store_what <= `STW_DEF;
|
isIY <= `FALSE;
|
|
isIY24 <= `FALSE;
|
|
store_what <= m16 ? `STW_DEF70 : `STW_DEF;
|
if (nmi_edge & gie) begin
|
if (nmi_edge & gie) begin
|
ir[7:0] <= `BRK;
|
ir[7:0] <= `BRK;
|
nmi_edge <= 1'b0;
|
nmi_edge <= 1'b0;
|
wai <= 1'b0;
|
wai <= 1'b0;
|
hwi <= `TRUE;
|
hwi <= `TRUE;
|
if (nmoi) begin
|
if (nmoi) begin
|
vect <= `NMI_VECT;
|
vect <= `NMI_VECT;
|
next_state(DECODE);
|
next_state(DECODE);
|
end
|
end
|
else begin
|
else begin
|
vect <= `BYTE_NMI_VECT;
|
vect <= m816 ? `NMI_VECT_816 : `BYTE_NMI_VECT;
|
vect[31:16] <= abs8[31:16];
|
vect[31:16] <= abs8[31:16];
|
next_state(BYTE_DECODE);
|
next_state(BYTE_DECODE);
|
end
|
end
|
end
|
end
|
else if (irq_i & gie) begin
|
else if (irq_i & gie) begin
|
Line 52... |
Line 55... |
if (bhit) begin
|
if (bhit) begin
|
ir <= ibuf;
|
ir <= ibuf;
|
next_state(BYTE_DECODE);
|
next_state(BYTE_DECODE);
|
end
|
end
|
else
|
else
|
state <= LOAD_IBUF1;
|
next_state(LOAD_IBUF1);
|
end
|
end
|
else begin
|
else begin
|
if (ihit) begin
|
if (ihit) begin
|
ir <= insn;
|
ir <= insn;
|
next_state(BYTE_DECODE);
|
next_state(BYTE_DECODE);
|
end
|
end
|
else
|
else
|
state <= ICACHE1;
|
next_state(ICACHE1);
|
end
|
end
|
end
|
end
|
else begin
|
else begin
|
ir[7:0] <= `BRK;
|
ir[7:0] <= `BRK;
|
|
if (m816)
|
|
vect <= `IRQ_VECT_816;
|
hwi <= `TRUE;
|
hwi <= `TRUE;
|
if (nmoi) begin
|
if (nmoi) begin
|
vect <= {vbr[31:9],irq_vect,2'b00};
|
vect <= {vbr[31:9],irq_vect,2'b00};
|
next_state(DECODE);
|
next_state(DECODE);
|
end
|
end
|
Line 82... |
Line 87... |
if (bhit) begin
|
if (bhit) begin
|
ir <= ibuf;
|
ir <= ibuf;
|
next_state(BYTE_DECODE);
|
next_state(BYTE_DECODE);
|
end
|
end
|
else
|
else
|
state <= LOAD_IBUF1;
|
next_state(LOAD_IBUF1);
|
end
|
end
|
else begin
|
else begin
|
if (ihit) begin
|
if (ihit) begin
|
ir <= insn;
|
ir <= insn;
|
next_state(BYTE_DECODE);
|
next_state(BYTE_DECODE);
|
end
|
end
|
else
|
else
|
state <= ICACHE1;
|
next_state(ICACHE1);
|
end
|
end
|
end
|
end
|
`ifdef DEBUG
|
`ifdef DEBUG
|
if (hist_capture) begin
|
if (hist_capture) begin
|
history_buf[history_ndx] <= pc;
|
history_buf[history_ndx] <= pc;
|
history_ndx <= history_ndx+7'd1;
|
history_ndx <= history_ndx+7'd1;
|
end
|
end
|
`endif
|
`endif
|
case(ir[7:0])
|
case(ir[7:0])
|
`TAY,`TXY,`DEY,`INY: begin y[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
// Note the break flag is not affected by SEP/REP
|
`TAX,`TYX,`TSX,`DEX,`INX: begin x[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
// Setting the index registers to eight bit zeros out the upper part of the register.
|
`TSA,`TYA,`TXA,`INA,`DEA: begin acc[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
`SEP:
|
`TAS,`TXS: begin sp <= res8[7:0]; end
|
begin
|
|
cf <= cf | ir[8];
|
|
zf <= zf | ir[9];
|
|
im <= im | ir[10];
|
|
df <= df | ir[11];
|
|
if (m816) begin
|
|
x_bit <= x_bit | ir[12];
|
|
m_bit <= m_bit | ir[13];
|
|
//if (ir[13]) acc[31:8] <= 24'd0;
|
|
if (ir[12]) begin
|
|
x[31:8] <= 24'd0;
|
|
y[31:8] <= 24'd0;
|
|
end
|
|
end
|
|
vf <= vf | ir[14];
|
|
nf <= nf | ir[15];
|
|
end
|
|
`REP:
|
|
begin
|
|
cf <= cf & ~ir[8];
|
|
zf <= zf & ~ir[9];
|
|
im <= im & ~ir[10];
|
|
df <= df & ~ir[11];
|
|
if (m816) begin
|
|
x_bit <= x_bit & ~ir[12];
|
|
m_bit <= m_bit & ~ir[13];
|
|
end
|
|
vf <= vf & ~ir[14];
|
|
nf <= nf & ~ir[15];
|
|
end
|
|
`XBA:
|
|
begin
|
|
acc[15:0] <= res16[15:0];
|
|
nf <= resn8;
|
|
zf <= resz8;
|
|
end
|
|
`TAY,`TXY,`DEY,`INY: if (xb16) begin y[15:0] <= res16[15:0]; nf <= resn16; zf <= resz16; end else begin y[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
|
`TAX,`TYX,`TSX,`DEX,`INX: if (xb16) begin x[15:0] <= res16[15:0]; nf <= resn16; zf <= resz16; end else begin x[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
|
`TSA,`TYA,`TXA,`INA,`DEA: if (m16) begin acc[15:0] <= res16[15:0]; nf <= resn16; zf <= resz16; end else begin acc[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
|
`TAS,`TXS: begin if (m816) sp <= res16[15:0]; else sp <= {8'h01,res8[7:0]}; end
|
|
`TCD: begin dpr <= res16[15:0]; end
|
|
`TDC: begin acc[15:0] <= res16[15:0]; nf <= resn16; zf <= resz16; end
|
`ADC_IMM:
|
`ADC_IMM:
|
begin
|
begin
|
acc[7:0] <= df ? bcaio : res8[7:0];
|
if (m16) begin
|
cf <= df ? bcaico : resc8;
|
acc[15:0] <= df ? bcaio : res16[15:0];
|
|
cf <= df ? bcaico : resc16;
|
|
// vf <= resv8;
|
|
vf <= (res16[15] ^ b16[15]) & (1'b1 ^ acc[15] ^ b16[15]);
|
|
nf <= df ? bcaio[15] : resn16;
|
|
zf <= df ? bcaio==16'h0000 : resz16;
|
|
end
|
|
else begin
|
|
acc[7:0] <= df ? bcaio[7:0] : res8[7:0];
|
|
cf <= df ? bcaico8 : resc8;
|
// vf <= resv8;
|
// vf <= resv8;
|
vf <= (res8[7] ^ b8[7]) & (1'b1 ^ acc[7] ^ b8[7]);
|
vf <= (res8[7] ^ b8[7]) & (1'b1 ^ acc[7] ^ b8[7]);
|
nf <= df ? bcaio[7] : resn8;
|
nf <= df ? bcaio[7] : resn8;
|
zf <= df ? bcaio==8'h00 : resz8;
|
zf <= df ? bcaio[7:0]==8'h00 : resz8;
|
end
|
end
|
`ADC_ZP,`ADC_ZPX,`ADC_IX,`ADC_IY,`ADC_ABS,`ADC_ABSX,`ADC_ABSY,`ADC_I:
|
end
|
|
`ADC_ZP,`ADC_ZPX,`ADC_IX,`ADC_IY,`ADC_IYL,`ADC_ABS,`ADC_ABSX,`ADC_ABSY,`ADC_I,`ADC_IL,`ADC_AL,`ADC_ALX,`ADC_DSP,`ADC_DSPIY:
|
begin
|
begin
|
acc[7:0] <= df ? bcao : res8[7:0];
|
if (m16) begin
|
cf <= df ? bcaco : resc8;
|
acc[15:0] <= df ? bcao : res16[15:0];
|
|
cf <= df ? bcaco : resc16;
|
|
vf <= (res16[15] ^ b16[15]) & (1'b1 ^ acc[15] ^ b16[15]);
|
|
nf <= df ? bcao[15] : resn16;
|
|
zf <= df ? bcao==16'h0000 : resz16;
|
|
end
|
|
else begin
|
|
acc[7:0] <= df ? bcao[7:0] : res8[7:0];
|
|
cf <= df ? bcaco8 : resc8;
|
vf <= (res8[7] ^ b8[7]) & (1'b1 ^ acc[7] ^ b8[7]);
|
vf <= (res8[7] ^ b8[7]) & (1'b1 ^ acc[7] ^ b8[7]);
|
nf <= df ? bcao[7] : resn8;
|
nf <= df ? bcao[7] : resn8;
|
zf <= df ? bcao==8'h00 : resz8;
|
zf <= df ? bcao[7:0]==8'h00 : resz8;
|
|
end
|
end
|
end
|
`SBC_IMM:
|
`SBC_IMM:
|
begin
|
begin
|
acc[7:0] <= df ? bcsio : res8[7:0];
|
if (m16) begin
|
cf <= ~(df ? bcsico : resc8);
|
acc[15:0] <= df ? bcsio : res16[15:0];
|
|
cf <= ~(df ? bcsico : resc16);
|
|
vf <= (1'b1 ^ res16[15] ^ b16[15]) & (acc[15] ^ b16[15]);
|
|
nf <= df ? bcsio[15] : resn16;
|
|
zf <= df ? bcsio==16'h0000 : resz16;
|
|
end
|
|
else begin
|
|
acc[7:0] <= df ? bcsio[7:0] : res8[7:0];
|
|
cf <= ~(df ? bcsico8 : resc8);
|
vf <= (1'b1 ^ res8[7] ^ b8[7]) & (acc[7] ^ b8[7]);
|
vf <= (1'b1 ^ res8[7] ^ b8[7]) & (acc[7] ^ b8[7]);
|
nf <= df ? bcsio[7] : resn8;
|
nf <= df ? bcsio[7] : resn8;
|
zf <= df ? bcsio==8'h00 : resz8;
|
zf <= df ? bcsio[7:0]==8'h00 : resz8;
|
|
end
|
end
|
end
|
`SBC_ZP,`SBC_ZPX,`SBC_IX,`SBC_IY,`SBC_ABS,`SBC_ABSX,`SBC_ABSY,`SBC_I:
|
`SBC_ZP,`SBC_ZPX,`SBC_IX,`SBC_IY,`SBC_IYL,`SBC_ABS,`SBC_ABSX,`SBC_ABSY,`SBC_I,`SBC_IL,`SBC_AL,`SBC_ALX,`SBC_DSP,`SBC_DSPIY:
|
begin
|
begin
|
acc[7:0] <= df ? bcso : res8[7:0];
|
if (m16) begin
|
|
acc[15:0] <= df ? bcso : res16[15:0];
|
|
vf <= (1'b1 ^ res16[15] ^ b16[15]) & (acc[15] ^ b16[15]);
|
|
cf <= ~(df ? bcsco : resc16);
|
|
nf <= df ? bcso[15] : resn16;
|
|
zf <= df ? bcso==16'h0000 : resz16;
|
|
end
|
|
else begin
|
|
acc[7:0] <= df ? bcso[7:0] : res8[7:0];
|
vf <= (1'b1 ^ res8[7] ^ b8[7]) & (acc[7] ^ b8[7]);
|
vf <= (1'b1 ^ res8[7] ^ b8[7]) & (acc[7] ^ b8[7]);
|
cf <= ~(df ? bcsco : resc8);
|
cf <= ~(df ? bcsco8 : resc8);
|
nf <= df ? bcso[7] : resn8;
|
nf <= df ? bcso[7] : resn8;
|
zf <= df ? bcso==8'h00 : resz8;
|
zf <= df ? bcso[7:0]==8'h00 : resz8;
|
|
end
|
end
|
end
|
`CMP_IMM,`CMP_ZP,`CMP_ZPX,`CMP_IX,`CMP_IY,`CMP_ABS,`CMP_ABSX,`CMP_ABSY,`CMP_I,
|
`CMP_IMM,`CMP_ZP,`CMP_ZPX,`CMP_IX,`CMP_IY,`CMP_IYL,`CMP_ABS,`CMP_ABSX,`CMP_ABSY,`CMP_I,`CMP_IL,`CMP_AL,`CMP_ALX,`CMP_DSP,`CMP_DSPIY:
|
|
if (m16) begin cf <= ~resc16; nf <= resn16; zf <= resz16; end else begin cf <= ~resc8; nf <= resn8; zf <= resz8; end
|
`CPX_IMM,`CPX_ZP,`CPX_ABS,
|
`CPX_IMM,`CPX_ZP,`CPX_ABS,
|
`CPY_IMM,`CPY_ZP,`CPY_ABS:
|
`CPY_IMM,`CPY_ZP,`CPY_ABS:
|
begin cf <= ~resc8; nf <= resn8; zf <= resz8; end
|
if (xb16) begin cf <= ~resc16; nf <= resn16; zf <= resz16; end else begin cf <= ~resc8; nf <= resn8; zf <= resz8; end
|
`BIT_IMM,`BIT_ZP,`BIT_ZPX,`BIT_ABS,`BIT_ABSX:
|
`BIT_IMM,`BIT_ZP,`BIT_ZPX,`BIT_ABS,`BIT_ABSX:
|
begin nf <= b8[7]; vf <= b8[6]; zf <= resz8; end
|
if (m16) begin nf <= b16[15]; vf <= b16[14]; zf <= resz16; end else begin nf <= b8[7]; vf <= b8[6]; zf <= resz8; end
|
`TRB_ZP,`TRB_ABS,`TSB_ZP,`TSB_ABS:
|
`TRB_ZP,`TRB_ABS,`TSB_ZP,`TSB_ABS:
|
begin zf <= resz8; end
|
if (m16) begin zf <= resz16; end else begin zf <= resz8; end
|
`LDA_IMM,`LDA_ZP,`LDA_ZPX,`LDA_IX,`LDA_IY,`LDA_ABS,`LDA_ABSX,`LDA_ABSY,`LDA_I,
|
`LDA_IMM,`LDA_ZP,`LDA_ZPX,`LDA_IX,`LDA_IY,`LDA_IYL,`LDA_ABS,`LDA_ABSX,`LDA_ABSY,`LDA_I,`LDA_IL,`LDA_AL,`LDA_ALX,`LDA_DSP,`LDA_DSPIY,
|
`AND_IMM,`AND_ZP,`AND_ZPX,`AND_IX,`AND_IY,`AND_ABS,`AND_ABSX,`AND_ABSY,`AND_I,
|
`AND_IMM,`AND_ZP,`AND_ZPX,`AND_IX,`AND_IY,`AND_IYL,`AND_ABS,`AND_ABSX,`AND_ABSY,`AND_I,`AND_IL,`AND_AL,`AND_ALX,`AND_DSP,`AND_DSPIY,
|
`ORA_IMM,`ORA_ZP,`ORA_ZPX,`ORA_IX,`ORA_IY,`ORA_ABS,`ORA_ABSX,`ORA_ABSY,`ORA_I,
|
`ORA_IMM,`ORA_ZP,`ORA_ZPX,`ORA_IX,`ORA_IY,`ORA_IYL,`ORA_ABS,`ORA_ABSX,`ORA_ABSY,`ORA_I,`ORA_IL,`ORA_AL,`ORA_ALX,`ORA_DSP,`ORA_DSPIY,
|
`EOR_IMM,`EOR_ZP,`EOR_ZPX,`EOR_IX,`EOR_IY,`EOR_ABS,`EOR_ABSX,`EOR_ABSY,`EOR_I:
|
`EOR_IMM,`EOR_ZP,`EOR_ZPX,`EOR_IX,`EOR_IY,`EOR_IYL,`EOR_ABS,`EOR_ABSX,`EOR_ABSY,`EOR_I,`EOR_IL,`EOR_AL,`EOR_ALX,`EOR_DSP,`EOR_DSPIY:
|
begin acc[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
if (m16) begin acc[15:0] <= res16[15:0]; nf <= resn16; zf <= resz16; end
|
`ASL_ACC: begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
else begin acc[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
`ROL_ACC: begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ASL_ACC: if (m16) begin acc[15:0] <= res16[15:0]; cf <= resc16; nf <= resn16; zf <= resz16; end else begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
`LSR_ACC: begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ROL_ACC: if (m16) begin acc[15:0] <= res16[15:0]; cf <= resc16; nf <= resn16; zf <= resz16; end else begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ROR_ACC: begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
`LSR_ACC: if (m16) begin acc[15:0] <= res16[15:0]; cf <= resc16; nf <= resn16; zf <= resz16; end else begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ASL_ZP,`ASL_ZPX,`ASL_ABS,`ASL_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ROR_ACC: if (m16) begin acc[15:0] <= res16[15:0]; cf <= resc16; nf <= resn16; zf <= resz16; end else begin acc[7:0] <= res8[7:0]; cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ROL_ZP,`ROL_ZPX,`ROL_ABS,`ROL_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ASL_ZP,`ASL_ZPX,`ASL_ABS,`ASL_ABSX: if (m16) begin cf <= resc16; nf <= resn16; zf <= resz16; end else begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`LSR_ZP,`LSR_ZPX,`LSR_ABS,`LSR_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ROL_ZP,`ROL_ZPX,`ROL_ABS,`ROL_ABSX: if (m16) begin cf <= resc16; nf <= resn16; zf <= resz16; end else begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`ROR_ZP,`ROR_ZPX,`ROR_ABS,`ROR_ABSX: begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`LSR_ZP,`LSR_ZPX,`LSR_ABS,`LSR_ABSX: if (m16) begin cf <= resc16; nf <= resn16; zf <= resz16; end else begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`INC_ZP,`INC_ZPX,`INC_ABS,`INC_ABSX: begin nf <= resn8; zf <= resz8; end
|
`ROR_ZP,`ROR_ZPX,`ROR_ABS,`ROR_ABSX: if (m16) begin cf <= resc16; nf <= resn16; zf <= resz16; end else begin cf <= resc8; nf <= resn8; zf <= resz8; end
|
`DEC_ZP,`DEC_ZPX,`DEC_ABS,`DEC_ABSX: begin nf <= resn8; zf <= resz8; end
|
`INC_ZP,`INC_ZPX,`INC_ABS,`INC_ABSX: if (m16) begin nf <= resn16; zf <= resz16; end else begin nf <= resn8; zf <= resz8; end
|
`PLA: begin acc[7:0] <= res8[7:0]; zf <= resz8; nf <= resn8; end
|
`DEC_ZP,`DEC_ZPX,`DEC_ABS,`DEC_ABSX: if (m16) begin nf <= resn16; zf <= resz16; end else begin nf <= resn8; zf <= resz8; end
|
`PLX: begin x[7:0] <= res8[7:0]; zf <= resz8; nf <= resn8; end
|
`PLA: if (m16) begin acc[15:0] <= res16[15:0]; zf <= resz16; nf <= resn16; end else begin acc[7:0] <= res8[7:0]; zf <= resz8; nf <= resn8; end
|
`PLY: begin y[7:0] <= res8[7:0]; zf <= resz8; nf <= resn8; end
|
`PLX: if (xb16) begin x[15:0] <= res16[15:0]; zf <= resz16; nf <= resn16; end else begin x[7:0] <= res8[7:0]; zf <= resz8; nf <= resn8; end
|
`LDX_IMM,`LDX_ZP,`LDX_ZPY,`LDX_ABS,`LDX_ABSY: begin x[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
`PLY: if (xb16) begin y[15:0] <= res16[15:0]; zf <= resz16; nf <= resn16; end else begin y[7:0] <= res8[7:0]; zf <= resz8; nf <= resn8; end
|
`LDY_IMM,`LDY_ZP,`LDY_ZPX,`LDY_ABS,`LDY_ABSX: begin y[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
`PLB: begin dbr <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
|
`PLD: begin dpr <= res16[15:0]; nf <= resn16; zf <= resz16; end
|
|
`LDX_IMM,`LDX_ZP,`LDX_ZPY,`LDX_ABS,`LDX_ABSY: if (xb16) begin x[15:0] <= res16[15:0]; nf <= resn16; zf <= resz16; end else begin x[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
|
`LDY_IMM,`LDY_ZP,`LDY_ZPX,`LDY_ABS,`LDY_ABSX: if (xb16) begin y[15:0] <= res16[15:0]; nf <= resn16; zf <= resz16; end else begin y[7:0] <= res8[7:0]; nf <= resn8; zf <= resz8; end
|
endcase
|
endcase
|
end
|
end
|
|
|
No newline at end of file
|
No newline at end of file
|