Line 64... |
Line 64... |
|
|
reg [7:0] STATUS;
|
reg [7:0] STATUS;
|
reg [7:0] result;
|
reg [7:0] result;
|
reg [7:0] op1;
|
reg [7:0] op1;
|
reg [7:0] op2;
|
reg [7:0] op2;
|
|
reg [7:0] bcdl;
|
|
reg [7:0] bcdh;
|
|
|
|
|
`include "t6507lp_package.v"
|
`include "t6507lp_package.v"
|
|
|
always @ (posedge clk or negedge reset_n)
|
always @ (posedge clk or negedge reset_n)
|
begin
|
begin
|
Line 315... |
Line 318... |
end
|
end
|
|
|
// ADC - Add with carry
|
// ADC - Add with carry
|
ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS, ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY : begin
|
ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS, ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY : begin
|
if (alu_status[D] == 1) begin
|
if (alu_status[D] == 1) begin
|
if (A[3:0] > 9) begin
|
bcdl = A[3:0] + alu_a[3:0] + alu_status[C];
|
op1 = A + 6; // A = A - 10 and A = A + 16
|
bcdh = A[7:4] + alu_a[7:4];
|
end
|
if (bcdl > 9) begin
|
if (op1[7:4] > 9) begin
|
bcdl = bcdl - 10; // A = A - 10 and A = A + 16
|
op1 = op1[7:4] + 6; // A = A - 10 and A = A + 16
|
bcdh = bcdh + 1; // A = A - 10 and A = A + 16
|
end
|
|
if (alu_a[3:0] > 9) begin
|
|
op2 = alu_a + 6;
|
|
end
|
end
|
if (op2[7:4] > 9) begin
|
if (bcdh > 9) begin
|
op2 = op2[7:4] + 6; // A = A - 10 and A = A + 16
|
STATUS[C] = 1;
|
|
bcdh = bcdh - 10;
|
end
|
end
|
|
/*if (op1[7:4] > 9) begin
|
|
op1 = op1[7:4] + 6; // A = A - 10 and A = A + 16
|
|
end
|
|
if (alu_a[3:0] > 9) begin
|
|
op2 = alu_a + 6;
|
|
end
|
|
if (op2[7:4] > 9) begin
|
|
op2 = op2[7:4] + 6; // A = A - 10 and A = A + 16
|
|
end
|
|
*/
|
|
result = {bcdh[3:0],bcdl[3:0]};
|
end
|
end
|
|
else begin
|
{STATUS[C],result} = op1 + op2 + alu_status[C];
|
{STATUS[C],result} = op1 + op2 + alu_status[C];
|
|
end
|
if ((op1[7] == op2[7]) && (op1[7] != result[7]))
|
if ((op1[7] == op2[7]) && (op1[7] != result[7]))
|
STATUS[V] = 1;
|
STATUS[V] = 1;
|
else
|
else
|
STATUS[V] = 0;
|
STATUS[V] = 0;
|
//$display("op1 + op2 + C = result + C (V)");
|
//$display("op1 + op2 + C = result + C (V)");
|
//$display("%d + %d + %b = %d + %b (%b)", op1, op2, alu_status[C],result,STATUS[C],STATUS[V]);
|
//$display("%d + %d + %b = %d + %b (%b)", op1, op2, alu_status[C],result,STATUS[C],STATUS[V]);
|
|
/*
|
if (alu_status[D] == 1) begin
|
if (alu_status[D] == 1) begin
|
if (result[3:0] > 9) begin
|
if (result[3:0] > 9) begin
|
result = result[3:0] + 6; // A = A - 10 and A = A + 16
|
result = result[3:0] + 6; // A = A - 10 and A = A + 16
|
end
|
end
|
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
|
|
*/
|
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;
|
Line 384... |
Line 399... |
end
|
end
|
|
|
// SBC - Subtract with Carry
|
// SBC - Subtract with Carry
|
SBC_IMM, SBC_ZPG, SBC_ZPX, SBC_ABS, SBC_ABX, SBC_ABY, SBC_IDX, SBC_IDY : begin
|
SBC_IMM, SBC_ZPG, SBC_ZPX, SBC_ABS, SBC_ABX, SBC_ABY, SBC_IDX, SBC_IDY : begin
|
if (alu_status[D] == 1) begin
|
if (alu_status[D] == 1) begin
|
if (A[3:0] > 9) begin
|
bcdl = A[3:0] + alu_a[3:0] + alu_status[C];
|
op1 = A + 6; // A = A - 10 and A = A + 16
|
bcdh = A[7:4] + alu_a[7:4];
|
end
|
if (bcdl > 9) begin
|
if (op1[7:4] > 9) begin
|
bcdl = bcdl - 10; // A = A - 10 and A = A + 16
|
op1 = op1[7:4] + 6; // A = A - 10 and A = A + 16
|
bcdh = bcdh + 1; // A = A - 10 and A = A + 16
|
end
|
|
if (alu_a[3:0] > 9) begin
|
|
op2 = alu_a + 6;
|
|
end
|
end
|
if (op2[7:4] > 9) begin
|
if (bcdh > 9) begin
|
op2 = op2[7:4] + 6; // A = A - 10 and A = A + 16
|
STATUS[C] = 1;
|
|
bcdh = bcdh - 10;
|
end
|
end
|
|
result = {bcdh[3:0],bcdl[3:0]};
|
end
|
end
|
|
else begin
|
{STATUS[C],result} = op1 - op2 - ~alu_status[C];
|
{STATUS[C],result} = op1 - op2 - ~alu_status[C];
|
|
end
|
if ((op1[7] == op2[7]) && (op1[7] != result[7]))
|
if ((op1[7] == op2[7]) && (op1[7] != result[7]))
|
STATUS[V] = 1;
|
STATUS[V] = 1;
|
else
|
else
|
STATUS[V] = 0;
|
STATUS[V] = 0;
|
end
|
end
|