Line 70... |
Line 70... |
`include "t6507lp_package.v"
|
`include "t6507lp_package.v"
|
|
|
always @ (posedge clk or negedge reset_n)
|
always @ (posedge clk or negedge reset_n)
|
begin
|
begin
|
if (reset_n == 0) begin
|
if (reset_n == 0) begin
|
//$display("RESTART");
|
$display("RESTART");
|
alu_result <= 0;
|
alu_result <= 0;
|
alu_status[C] <= 0;
|
alu_status[C] <= 0;
|
alu_status[N] <= 0;
|
alu_status[N] <= 0;
|
alu_status[V] <= 0;
|
alu_status[V] <= 0;
|
|
alu_status[5] <= 1;
|
alu_status[Z] <= 1;
|
alu_status[Z] <= 1;
|
alu_status[I] <= 0;
|
alu_status[I] <= 0;
|
alu_status[B] <= 0;
|
alu_status[B] <= 0;
|
alu_status[D] <= 0;
|
alu_status[D] <= 0;
|
A <= 0;
|
A <= 0;
|
Line 86... |
Line 87... |
Y <= 0;
|
Y <= 0;
|
alu_x <= 0;
|
alu_x <= 0;
|
alu_y <= 0;
|
alu_y <= 0;
|
end
|
end
|
else if ( alu_enable == 1 ) begin
|
else if ( alu_enable == 1 ) begin
|
|
//$display("A = %h result = %h", A, result);
|
|
//$display("V = %b C = %b D = %b", STATUS[V], STATUS[C], STATUS[D]);
|
|
|
case (alu_opcode)
|
case (alu_opcode)
|
ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS, ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY,
|
ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS, ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY,
|
AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX, AND_IDY,
|
AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX, AND_IDY,
|
ASL_ACC, EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY, EOR_IDX,
|
ASL_ACC, EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY, EOR_IDX,
|
EOR_IDY, LSR_ACC, ORA_IMM, ORA_ZPG, ORA_ZPX, ORA_ABS, ORA_ABX, ORA_ABY,
|
EOR_IDY, LSR_ACC, ORA_IMM, ORA_ZPG, ORA_ZPX, ORA_ABS, ORA_ABX, ORA_ABY,
|
ORA_IDX, ORA_IDY, ROL_ACC, ROR_ACC, SBC_IMM, SBC_ZPG, SBC_ZPX, SBC_ABS,
|
ORA_IDX, ORA_IDY, ROL_ACC, ROR_ACC, SBC_IMM, SBC_ZPG, SBC_ZPX, SBC_ABS,
|
SBC_ABX, SBC_ABY, SBC_IDX, SBC_IDY, LDA_IMM, LDA_ZPG, LDA_ZPX, LDA_ABS,
|
SBC_ABX, SBC_ABY, SBC_IDX, SBC_IDY, LDA_IMM, LDA_ZPG, LDA_ZPX, LDA_ABS,
|
LDA_ABX, LDA_ABY, LDA_IDX, LDA_IDY, PLA_IMP, TXA_IMP, TYA_IMP :
|
LDA_ABX, LDA_ABY, LDA_IDX, LDA_IDY, PLA_IMP, TXA_IMP, TYA_IMP :
|
begin
|
begin
|
|
$display("A = %h result = %h", A, result);
|
|
//$display("V = %b C = %b D = %b", STATUS[V], STATUS[C], STATUS[D]);
|
A <= result;
|
A <= result;
|
alu_result <= result;
|
alu_result <= result;
|
alu_status <= STATUS;
|
alu_status <= STATUS;
|
end
|
end
|
LDX_IMM, LDX_ZPG, LDX_ZPY, LDX_ABS, LDX_ABY, TAX_IMP, TSX_IMP, INX_IMP, DEX_IMP :
|
LDX_IMM, LDX_ZPG, LDX_ZPY, LDX_ABS, LDX_ABY, TAX_IMP, TSX_IMP, INX_IMP, DEX_IMP :
|
Line 116... |
Line 122... |
begin
|
begin
|
Y <= result;
|
Y <= result;
|
alu_y <= result;
|
alu_y <= result;
|
alu_status <= STATUS;
|
alu_status <= STATUS;
|
end
|
end
|
LSR_ZPG, LSR_ZPX, LSR_ABS, LSR_ABX, ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX,
|
CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY,
|
ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX, CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS,
|
CPX_IMM, CPX_ZPG, CPX_ABS, CPY_IMM, CPY_ZPG, CPY_ABS, PHP_IMP :
|
CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY, CPX_IMM, CPX_ZPG, CPX_ABS, CPY_IMM,
|
|
CPY_ZPG, CPY_ABS, PHP_IMP :
|
|
begin
|
begin
|
alu_status <= STATUS;
|
alu_status <= STATUS;
|
end
|
end
|
SEC_IMP :
|
SEC_IMP :
|
begin
|
begin
|
Line 165... |
Line 169... |
begin
|
begin
|
alu_status[Z] <= STATUS[Z];
|
alu_status[Z] <= STATUS[Z];
|
alu_status[V] <= alu_a[6];
|
alu_status[V] <= alu_a[6];
|
alu_status[N] <= alu_a[7];
|
alu_status[N] <= alu_a[7];
|
end
|
end
|
INC_ZPG, INC_ZPX, INC_ABS, INC_ABX, DEC_ZPG, DEC_ZPX, DEC_ABS, DEC_ABX, ASL_ZPG, ASL_ZPX, ASL_ABS, ASL_ABX :
|
INC_ZPG, INC_ZPX, INC_ABS, INC_ABX, DEC_ZPG, DEC_ZPX, DEC_ABS, DEC_ABX,
|
|
ASL_ZPG, ASL_ZPX, ASL_ABS, ASL_ABX, LSR_ZPG, LSR_ZPX, LSR_ABS, LSR_ABX,
|
|
ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX, ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX :
|
begin
|
begin
|
alu_result <= result;
|
alu_result <= result;
|
alu_status <= STATUS;
|
alu_status <= STATUS;
|
end
|
end
|
default : begin
|
default : begin
|
Line 183... |
Line 189... |
bcd1 = A;
|
bcd1 = A;
|
bcd2 = alu_a;
|
bcd2 = alu_a;
|
result = alu_result;
|
result = alu_result;
|
STATUS[C] = alu_status[C];
|
STATUS[C] = alu_status[C];
|
STATUS[V] = alu_status[V];
|
STATUS[V] = alu_status[V];
|
STATUS[5] = 1;
|
|
STATUS[B] = alu_status[B];
|
STATUS[B] = alu_status[B];
|
STATUS[I] = alu_status[I];
|
STATUS[I] = alu_status[I];
|
STATUS[D] = alu_status[D];
|
STATUS[D] = alu_status[D];
|
|
|
case (alu_opcode)
|
case (alu_opcode)
|
Line 312... |
Line 317... |
end
|
end
|
if (bcd2[7:4] > 9) begin
|
if (bcd2[7:4] > 9) begin
|
bcd2 = bcd2[7:4] + 6; // A = A - 10 and A = A + 16
|
bcd2 = bcd2[7:4] + 6; // A = A - 10 and A = A + 16
|
end
|
end
|
end
|
end
|
|
$display("op1 = %h op2 = %h result = %h", bcd1, bcd2, result);
|
|
$display("V = %b C = %b D = %b", STATUS[V], STATUS[C], STATUS[D]);
|
{STATUS[C],result} = bcd1 + bcd2 + alu_status[C];
|
{STATUS[C],result} = bcd1 + bcd2 + alu_status[C];
|
if ((bcd1[7] == bcd2[7]) && (bcd1[7] != alu_result[7]))
|
if ((bcd1[7] == bcd2[7]) && (bcd1[7] != alu_result[7]))
|
STATUS[V] = 1;
|
STATUS[V] = 1;
|
else
|
else
|
STATUS[V] = 0;
|
STATUS[V] = 0;
|
Line 328... |
Line 334... |
if (result[7:4] > 9) begin
|
if (result[7:4] > 9) begin
|
result = result[7:4] + 6; // A = A - 10 and A = A + 16
|
result = result[7:4] + 6; // A = A - 10 and A = A + 16
|
STATUS[C] = 1;
|
STATUS[C] = 1;
|
end
|
end
|
end
|
end
|
|
$display("op1 = %h op2 = %h result = %h", bcd1, bcd2, result);
|
|
$display("V = %b C = %b D = %b", STATUS[V], STATUS[C], STATUS[D]);
|
end
|
end
|
|
|
// AND - Logical AND
|
// AND - Logical AND
|
AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX, AND_IDY : begin
|
AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX, AND_IDY : begin
|
result = A & alu_a;
|
result = A & alu_a;
|