Implemented Relative mode (branch) instructions and unit tests. Fixed

a bug in the instruction size table.
This commit is contained in:
Seth Morabito committed 2009-01-07 18:26:11 -08:00
1 parent f21a0d76e9
commit ed943687bf
3 files changed
+321 -9

No files matched your search

+40 -8
View File
@@ -188,7 +188,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(k);
break;
case 0x10: // TODO: implement
case 0x10: // BPL - Branch if Positive - Relative
if (!getNegativeFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0x11: // TODO: implement
break;
@@ -277,7 +280,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(k);
break;
case 0x30: // TODO: implement
case 0x30: // BMI - Branch if Minus - Relative
if (getNegativeFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0x31: // TODO: implement
break;
@@ -356,7 +362,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(k);
break;
case 0x50: // TODO: implement
case 0x50: // BVC - Branch if Overflow Clear - Relative
if (!getOverflowFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0x51: // TODO: implement
break;
@@ -459,7 +468,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(k);
break;
case 0x70: // TODO: implement
case 0x70: // BVS - Branch if Overflow Set - Relative
if (getOverflowFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0x71: // TODO: implement
break;
@@ -538,7 +550,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(x);
break;
case 0x90: // TODO: implement
case 0x90: // BCC - Branch if Carry Clear - Relative
if (!getCarryFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0x91: // TODO: implement
break;
@@ -617,7 +632,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(x);
break;
case 0xb0: // TODO: implement
case 0xb0: // BCS - Branch if Carry Set - Relative
if (getCarryFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0xb1: // TODO: implement
break;
@@ -698,7 +716,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(k);
break;
case 0xd0: // TODO: implement
case 0xd0: // BNE - Branch if Not Equal to Zero - Relative
if (!getZeroFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0xd1: // TODO: implement
break;
@@ -781,7 +802,10 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(k);
break;
case 0xf0: // TODO: implement
case 0xf0: // BEQ - Branch if Equal to Zero - Relative
if (getZeroFlag()) {
pc = relAddress(operands[0]);
}
break;
case 0xf1: // TODO: implement
break;
@@ -1562,6 +1586,14 @@ public class Cpu implements InstructionTable {
return (zp+getXRegister())&0xff;
}
/**
* Given a single byte, compute the offset address.
*/
int relAddress(int offset) {
// Cast the offset to a signed byte to handle negative offsets
return (pc + (byte)offset) & 0xffff;
}
/**
* Given a single byte, compute the Zero Page,Y offset address.
*/
@@ -217,7 +217,7 @@ public interface InstructionTable {
2, 2, 0, 0, 2, 2, 2, 0, 1, 0, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 0, 3, 0, 0,
2, 2, 2, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
0, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,