Fix #17: Correct disassembly

This commit is contained in:
Seth Morabito committed 2025-03-15 15:46:50 -07:00
1 parent 963526621d
commit 2284535b7f
3 files changed
+84 -1

No files matched your search

+4
View File
@@ -1925,6 +1925,7 @@ public class Cpu implements InstructionTable {
break; break;
case AIX: case AIX:
sb.append(" ($").append(Utils.wordToHex(Utils.address(args[0], args[1]))).append(",X)"); sb.append(" ($").append(Utils.wordToHex(Utils.address(args[0], args[1]))).append(",X)");
break;
case ABX: case ABX:
sb.append(" $").append(Utils.wordToHex(Utils.address(args[0], args[1]))).append(",X"); sb.append(" $").append(Utils.wordToHex(Utils.address(args[0], args[1]))).append(",X");
break; break;
@@ -1937,6 +1938,9 @@ public class Cpu implements InstructionTable {
case IND: case IND:
sb.append(" ($").append(Utils.wordToHex(Utils.address(args[0], args[1]))).append(")"); sb.append(" ($").append(Utils.wordToHex(Utils.address(args[0], args[1]))).append(")");
break; break;
case ZPI:
sb.append(" ($").append(Utils.byteToHex(args[0])).append(")");
break;
case XIN: case XIN:
sb.append(" ($").append(Utils.byteToHex(args[0])).append(",X)"); sb.append(" ($").append(Utils.byteToHex(args[0])).append(",X)");
break; break;
@@ -62,11 +62,13 @@ public interface InstructionTable {
return "Accumulator"; return "Accumulator";
} }
}, },
AIX { AIX {
public String toString() { public String toString() {
return "Absolute, X-Indexed Indirect"; return "Absolute, X-Indexed Indirect";
} }
}, },
ABS { ABS {
public String toString() { public String toString() {
return "Absolute"; return "Absolute";
@@ -162,7 +164,10 @@ public interface InstructionTable {
/** /**
* Instruction opcode names. This lists all opcodes for * Instruction opcode names. This lists all opcodes for
* NMOS 6502, CMOS 65C02, and CMOS 65C816 * NMOS 6502, CMOS 65C02, and CMOS 65C816.
* <p>
* TODO (2025-03-14): This table is clearly wrong for 65C816.
* TODO (2025-03-14): Rockwell/WDC 65C02 names conflict with 65C816 names.
*/ */
String[] opcodeNames = { String[] opcodeNames = {
"BRK", "ORA", "NOP", "NOP", "TSB", "ORA", "ASL", "RMB0", // 0x00-0x07 "BRK", "ORA", "NOP", "NOP", "TSB", "ORA", "ASL", "RMB0", // 0x00-0x07
@@ -670,4 +670,78 @@ public class CpuTest extends TestCase {
cpu.step(); cpu.step();
assertEquals(0x3E, cpu.getAccumulator()); assertEquals(0x3E, cpu.getAccumulator());
} }
// Have tests:
// ACC, AIX, ABS, ABX, ABY, IMP, IMM, IND, XIN, INY,
// REL, ZPG, ZPI
// Need to test:
// ZPR, ZPX, ZPY, NUL
// Question: Should 'NUL' even exist? Isn't it just 'IMP'?
public void testDisassembleOpHandlesAccumulatorCorrectly() {
var dis = Cpu.disassembleOp(0x2a, new int[]{});
assertEquals("ROL", dis);
}
public void testDisassembleOpHandlesAbsoluteXIndexedIndirectCorrectly() {
var dis = Cpu.disassembleOp(0x7c, new int[]{0x00, 0x1a});
assertEquals("JMP ($1A00,X)", dis);
}
public void testDisassembleOpHandlesAbsoluteCorrectly() {
var dis = Cpu.disassembleOp(0x0d, new int[]{0x10, 0x0c});
assertEquals("ORA $0C10", dis);
}
public void testDisassembleOpHandlesAbsoluteXIndexedCorrectly() {
var dis = Cpu.disassembleOp(0x1d, new int[]{0x00, 0x1c});
assertEquals("ORA $1C00,X", dis);
}
public void testDisassembleOpHandlesAbsoluteYIndexedCorrectly() {
var dis = Cpu.disassembleOp(0x19, new int[]{0x00, 0x1c});
assertEquals("ORA $1C00,Y", dis);
}
public void testDisassembleOpHandlesImpliedCorrectly() {
var dis = Cpu.disassembleOp(0x00, new int[]{});
assertEquals("BRK", dis);
}
public void testDisassembleOpHandlesIndirectCorrectly() {
var dis = Cpu.disassembleOp(0x6c, new int[]{0x00, 0x1c});
assertEquals("JMP ($1C00)", dis);
}
public void testDisassembleOpHandlesImmediateCorrectly() {
var dis = Cpu.disassembleOp(0xA9, new int[]{0xff});
assertEquals("LDA #$FF", dis);
}
public void testDisassembleOpHandlesXIndexedIndirectCorrectly() {
var dis = Cpu.disassembleOp(0x01, new int[]{0x10});
assertEquals("ORA ($10,X)", dis);
}
public void testDisassembleOpHandlesIndirectYIndexedCorrectly() {
var dis = Cpu.disassembleOp(0x11, new int[]{0x10});
assertEquals("ORA ($10),Y", dis);
}
public void testDisassembleOpHandlesRelativeCorrectly() {
var dis = Cpu.disassembleOp(0x10, new int[]{0xff});
assertEquals("BPL $FF", dis);
}
public void testDisassembleOpHandlesZeroPageCorrectly() {
var dis = Cpu.disassembleOp(0x24, new int[]{0x10});
assertEquals("BIT $10", dis);
}
public void testDisassembleOpHandlesZeroPageIndirectCorrectly() throws Exception {
var dis = Cpu.disassembleOp(0xB2, new int[]{0x1a});
assertEquals("LDA ($1A)", dis);
}
} }