Line 56... |
Line 56... |
output reg [7:0] alu_result;
|
output reg [7:0] alu_result;
|
output reg [7:0] alu_status;
|
output reg [7:0] alu_status;
|
output reg [7:0] alu_x;
|
output reg [7:0] alu_x;
|
output reg [7:0] alu_y;
|
output reg [7:0] alu_y;
|
|
|
//reg [7:0] A;
|
reg [7:0] A;
|
//reg [7:0] X;
|
//reg [7:0] X;
|
//reg [7:0] Y;
|
//reg [7:0] Y;
|
|
|
reg [7:0] STATUS;
|
reg [7:0] STATUS;
|
reg [7:0] result;
|
reg [7:0] result;
|
Line 86... |
Line 86... |
alu_status[5] <= 1;
|
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;
|
//X <= 0;
|
//X <= 0;
|
//Y <= 0;
|
//Y <= 0;
|
alu_x <= 0;
|
alu_x <= 0;
|
alu_y <= 0;
|
alu_y <= 0;
|
end
|
end
|
Line 102... |
Line 102... |
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
|
//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 :
|
begin
|
begin
|
Line 205... |
Line 205... |
end
|
end
|
|
|
always @ (*) begin
|
always @ (*) begin
|
if (alu_enable == 1) begin
|
if (alu_enable == 1) begin
|
//op1 = A;
|
//op1 = A;
|
op1 = alu_result;
|
op1 = A;
|
op2 = alu_a;
|
op2 = alu_a;
|
result = alu_result;
|
result = alu_result;
|
STATUS[N] = alu_status[N];
|
STATUS[N] = alu_status[N];
|
STATUS[C] = alu_status[C];
|
STATUS[C] = alu_status[C];
|
STATUS[V] = alu_status[V];
|
STATUS[V] = alu_status[V];
|
Line 228... |
Line 228... |
|
|
case (alu_opcode)
|
case (alu_opcode)
|
// BIT - Bit Test
|
// BIT - Bit Test
|
BIT_ZPG, BIT_ABS: begin
|
BIT_ZPG, BIT_ABS: begin
|
//result = A & alu_a;
|
//result = A & alu_a;
|
result = alu_result & alu_a;
|
result = A & alu_a;
|
end
|
end
|
|
|
// BRK - Force Interrupt
|
// BRK - Force Interrupt
|
//BRK_IMP: begin
|
//BRK_IMP: begin
|
// STATUS[B] = 1'b1;
|
// STATUS[B] = 1'b1;
|
Line 277... |
Line 277... |
// PHA - Push A
|
// PHA - Push A
|
// TAX - Transfer Accumulator to X
|
// TAX - Transfer Accumulator to X
|
// TAY - Transfer Accumulator to Y
|
// TAY - Transfer Accumulator to Y
|
TAX_IMP, TAY_IMP, PHA_IMP, STA_ZPG, STA_ZPX, STA_ABS, STA_ABX, STA_ABY, STA_IDX, STA_IDY : begin
|
TAX_IMP, TAY_IMP, PHA_IMP, STA_ZPG, STA_ZPX, STA_ABS, STA_ABX, STA_ABY, STA_IDX, STA_IDY : begin
|
//result = A;
|
//result = A;
|
result = alu_result;
|
result = A;
|
end
|
end
|
|
|
// STX - Store X Register
|
// STX - Store X Register
|
// TXA - Transfer X to Accumulator
|
// TXA - Transfer X to Accumulator
|
// TXS - Transfer X to Stack pointer
|
// TXS - Transfer X to Stack pointer
|
Line 392... |
Line 392... |
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;
|
result = alu_result & alu_a;
|
result = A & alu_a;
|
end
|
end
|
|
|
// CMP - Compare
|
// CMP - Compare
|
CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY : begin
|
CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY : begin
|
//result = A - alu_a;
|
//result = A - alu_a;
|
result = alu_result - alu_a;
|
result = A - alu_a;
|
//STATUS[C] = (A >= alu_a) ? 1 : 0;
|
//STATUS[C] = (A >= alu_a) ? 1 : 0;
|
STATUS[C] = (alu_result >= alu_a) ? 1 : 0;
|
STATUS[C] = (A >= alu_a) ? 1 : 0;
|
end
|
end
|
|
|
// EOR - Exclusive OR
|
// EOR - Exclusive OR
|
EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY, EOR_IDX, EOR_IDY : begin
|
EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY, EOR_IDX, EOR_IDY : begin
|
result = alu_result ^ alu_a;
|
result = A ^ alu_a;
|
//result = A ^ alu_a;
|
//result = A ^ alu_a;
|
//$display("op1 ^ op2 = result");
|
//$display("op1 ^ op2 = result");
|
//$display("%d ^ %d = %d", op1, op2, result);
|
//$display("%d ^ %d = %d", op1, op2, result);
|
end
|
end
|
|
|
Line 425... |
Line 425... |
end
|
end
|
|
|
// ORA - Logical OR
|
// ORA - Logical OR
|
ORA_IMM, ORA_ZPG, ORA_ZPX, ORA_ABS, ORA_ABX, ORA_ABY, ORA_IDX, ORA_IDY : begin
|
ORA_IMM, ORA_ZPG, ORA_ZPX, ORA_ABS, ORA_ABX, ORA_ABY, ORA_IDX, ORA_IDY : begin
|
//result = A | alu_a;
|
//result = A | alu_a;
|
result = alu_result | alu_a;
|
result = A | alu_a;
|
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
|
op2 = ~op2;
|
|
if (alu_status[D] == 1) begin
|
if (alu_status[D] == 1) begin
|
//AL = A[3:0] + alu_a[3:0] + alu_status[C];
|
/* //AL = A[3:0] + alu_a[3:0] + alu_status[C];
|
AL = op1[3:0] + op2[3:0] + alu_status[C];
|
AL = op1[3:0] + op2[3:0] + alu_status[C];
|
//AH = A[7:4] + alu_a[7:4];
|
//AH = A[7:4] + alu_a[7:4];
|
AH = op1[7:4] + op2[7:4];
|
AH = op1[7:4] + op2[7:4];
|
if (AL > 9) begin
|
if (AL > 9) begin
|
bcdh = AH + (AL / 10);
|
bcdh = AH + (AL / 10);
|
bcdl = AL % 10;
|
bcdl = AL % 10;
|
end
|
end
|
else begin
|
else begin
|
bcdh = AH;
|
bcdh = AH;
|
bcdl = AL;
|
bcdl = AL;
|
end
|
end
|
if (bcdh > 9) begin
|
if (bcdh > 9) begin
|
STATUS[C] = 1;
|
STATUS[C] = 1;
|
bcdh2 = bcdh % 10;
|
bcdh2 = bcdh % 10;
|
end
|
end
|
else begin
|
else begin
|
STATUS[C] = 0;
|
STATUS[C] = 0;
|
bcdh2 = bcdh;
|
bcdh2 = bcdh;
|
|
end
|
|
result = {bcdh2[3:0],bcdl[3:0]};*/
|
|
//C := P_In(Flag_C) or not Op(0);
|
|
AL = {op1[3:0],alu_status[C]} - {op2[3:0],1'b1};
|
|
AH = {op1[7:4],1'b0} - {op2[7:4],AL[5]};
|
|
|
|
if (AL[5] == 1) begin
|
|
bcdl[5:1] = AL[5:1] - 6;
|
|
end
|
|
AH = {op1[7:4],1'b0} - {op2[7:4],bcdl[6]};
|
|
if (AH[5] == 1) begin
|
|
bcdh[5:1] = AH[5:1] - 6;
|
end
|
end
|
result = {bcdh2[3:0],bcdl[3:0]};
|
result = {bcdh[4:1],bcdl[4:1]};
|
|
STATUS[C] = ~result[7];
|
end
|
end
|
else begin
|
else begin
|
|
op2 = ~op2;
|
//$display("MODO NORMAL");
|
//$display("MODO NORMAL");
|
result = op1 + op2 + alu_status[C];
|
result = op1 + op2 + alu_status[C];
|
STATUS[C] = ~result[7];
|
STATUS[C] = ~result[7];
|
end
|
end
|
/* if (alu_status[D] == 1) begin
|
/* if (alu_status[D] == 1) begin
|
Line 490... |
Line 503... |
|
|
// ASL - Arithmetic Shift Left
|
// ASL - Arithmetic Shift Left
|
ASL_ACC : begin
|
ASL_ACC : begin
|
//{STATUS[C],result} = A << 1;
|
//{STATUS[C],result} = A << 1;
|
//{STATUS[C],result} = {A,1'b0};
|
//{STATUS[C],result} = {A,1'b0};
|
{STATUS[C],result} = {alu_result,1'b0};
|
{STATUS[C],result} = {A,1'b0};
|
end
|
end
|
ASL_ZPG, ASL_ZPX, ASL_ABS, ASL_ABX : begin
|
ASL_ZPG, ASL_ZPX, ASL_ABS, ASL_ABX : begin
|
//{STATUS[C],result} = alu_a << 1;
|
//{STATUS[C],result} = alu_a << 1;
|
{STATUS[C],result} = {alu_a,1'b0};
|
{STATUS[C],result} = {alu_a,1'b0};
|
end
|
end
|
|
|
// LSR - Logical Shift Right
|
// LSR - Logical Shift Right
|
LSR_ACC: begin
|
LSR_ACC: begin
|
//{result, STATUS[C]} = A >> 1;
|
//{result, STATUS[C]} = A >> 1;
|
//{result,STATUS[C]} = {1'b0,A};
|
//{result,STATUS[C]} = {1'b0,A};
|
{result,STATUS[C]} = {1'b0,alu_result};
|
{result,STATUS[C]} = {1'b0,A};
|
end
|
end
|
LSR_ZPG, LSR_ZPX, LSR_ABS, LSR_ABX : begin
|
LSR_ZPG, LSR_ZPX, LSR_ABS, LSR_ABX : begin
|
//{result, STATUS[C]} = alu_a >> 1;
|
//{result, STATUS[C]} = alu_a >> 1;
|
{result,STATUS[C]} = {1'b0,alu_a};
|
{result,STATUS[C]} = {1'b0,alu_a};
|
end
|
end
|
|
|
// ROL - Rotate Left
|
// ROL - Rotate Left
|
ROL_ACC : begin
|
ROL_ACC : begin
|
//{STATUS[C],result} = {A,alu_status[C]};
|
//{STATUS[C],result} = {A,alu_status[C]};
|
{STATUS[C],result} = {alu_result,alu_status[C]};
|
{STATUS[C],result} = {A,alu_status[C]};
|
end
|
end
|
ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX : begin
|
ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX : begin
|
{STATUS[C],result} = {alu_a,alu_status[C]};
|
{STATUS[C],result} = {alu_a,alu_status[C]};
|
end
|
end
|
|
|
// ROR - Rotate Right
|
// ROR - Rotate Right
|
ROR_ACC : begin
|
ROR_ACC : begin
|
//{result,STATUS[C]} = {alu_status[C],A};
|
//{result,STATUS[C]} = {alu_status[C],A};
|
{result,STATUS[C]} = {alu_status[C],alu_result};
|
{result,STATUS[C]} = {alu_status[C],A};
|
end
|
end
|
ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX : begin
|
ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX : begin
|
{result, STATUS[C]} = {alu_status[C], alu_a};
|
{result, STATUS[C]} = {alu_status[C], alu_a};
|
end
|
end
|
|
|