Implemented Zero Page,X, Zero Page,Y, and Indirect addressing mode instructions, along with unit tests.

This commit is contained in:
Seth Morabito committed 2008-12-29 20:46:48 -08:00
1 parent 66fc63a36e
commit 107aca7777
6 files changed
+1406 -22

No files matched your search

@@ -0,0 +1,53 @@
package com.loomcom.symon;
import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException;
import junit.framework.TestCase;
public class CpuIndirectModeTest extends TestCase {
protected Cpu cpu;
protected Bus bus;
protected Memory mem;
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
bus.addCpu(cpu);
bus.addDevice(mem);
// Load the reset vector.
bus.write(0xfffc, Cpu.DEFAULT_BASE_ADDRESS & 0x00ff);
bus.write(0xfffd, (Cpu.DEFAULT_BASE_ADDRESS & 0xff00)>>>8);
cpu.reset();
// Assert initial state
assertEquals(0, cpu.getAccumulator());
assertEquals(0, cpu.getXRegister());
assertEquals(0, cpu.getYRegister());
assertEquals(0x200, cpu.getProgramCounter());
assertEquals(0xff, cpu.getStackPointer());
assertEquals(0x20, cpu.getProcessorStatus());
}
/*
* The following opcodes are tested for correctness in this file:
*
* JMP - $6c
*
*/
/* JMP - Jump - $6c */
public void test_JMP() {
bus.write(0x3400, 0x00);
bus.write(0x3401, 0x54);
bus.loadProgram(0x6c, 0x00, 0x34);
cpu.step();
assertEquals(0x5400, cpu.getProgramCounter());
// No change to status flags.
assertEquals(0x20, cpu.getProcessorStatus());
}
}
@@ -355,4 +355,44 @@ public class CpuTest extends TestCase {
assertEquals(0xffff, cpu.address(0xff, 0xff));
}
public void testZpxAddress() {
cpu.setXRegister(0x00);
assertEquals(0x10, cpu.zpxAddress(0x10));
cpu.setXRegister(0x10);
assertEquals(0x20, cpu.zpxAddress(0x10));
cpu.setXRegister(0x25);
assertEquals(0x35, cpu.zpxAddress(0x10));
cpu.setXRegister(0xf5);
assertEquals(0x05, cpu.zpxAddress(0x10));
cpu.setXRegister(0x00);
assertEquals(0x80, cpu.zpxAddress(0x80));
cpu.setXRegister(0x10);
assertEquals(0x90, cpu.zpxAddress(0x80));
cpu.setXRegister(0x25);
assertEquals(0xa5, cpu.zpxAddress(0x80));
cpu.setXRegister(0x95);
assertEquals(0x15, cpu.zpxAddress(0x80));
}
public void testZpyAddress() {
cpu.setYRegister(0x00);
assertEquals(0x10, cpu.zpyAddress(0x10));
cpu.setYRegister(0x10);
assertEquals(0x20, cpu.zpyAddress(0x10));
cpu.setYRegister(0x25);
assertEquals(0x35, cpu.zpyAddress(0x10));
cpu.setYRegister(0xf5);
assertEquals(0x05, cpu.zpyAddress(0x10));
cpu.setYRegister(0x00);
assertEquals(0x80, cpu.zpyAddress(0x80));
cpu.setYRegister(0x10);
assertEquals(0x90, cpu.zpyAddress(0x80));
cpu.setYRegister(0x25);
assertEquals(0xa5, cpu.zpyAddress(0x80));
cpu.setYRegister(0x95);
assertEquals(0x15, cpu.zpyAddress(0x80));
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,101 @@
package com.loomcom.symon;
import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException;
import junit.framework.TestCase;
public class CpuZeroPageYModeTest extends TestCase {
protected Cpu cpu;
protected Bus bus;
protected Memory mem;
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
bus.addCpu(cpu);
bus.addDevice(mem);
// Load the reset vector.
bus.write(0xfffc, Cpu.DEFAULT_BASE_ADDRESS & 0x00ff);
bus.write(0xfffd, (Cpu.DEFAULT_BASE_ADDRESS & 0xff00)>>>8);
cpu.reset();
// Assert initial state
assertEquals(0, cpu.getAccumulator());
assertEquals(0, cpu.getXRegister());
assertEquals(0, cpu.getYRegister());
assertEquals(0x200, cpu.getProgramCounter());
assertEquals(0xff, cpu.getStackPointer());
assertEquals(0x20, cpu.getProcessorStatus());
}
/*
* The following opcodes are tested for correctness in this file:
*
* STX - $96
* LDX - $b6
*
*/
/* STX - Store X Register - $96 */
public void test_STX() {
cpu.setYRegister(0x30);
cpu.setXRegister(0x00);
bus.loadProgram(0x96, 0x10); // STX $10,Y
cpu.step();
assertEquals(0x00, bus.read(0x40));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.reset();
cpu.setYRegister(0x30);
cpu.setXRegister(0x0f);
bus.loadProgram(0x96, 0x10); // STX $10,Y
cpu.step();
assertEquals(0x0f, bus.read(0x40));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.reset();
cpu.setYRegister(0x30);
cpu.setXRegister(0x80);
bus.loadProgram(0x96, 0x10); // STX $10,Y
cpu.step();
assertEquals(0x80, bus.read(0x40));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
}
/* LDX - Load X Register - $b6 */
public void test_LDX() {
bus.write(0x40, 0x00);
bus.write(0x41, 0x0f);
bus.write(0x42, 0x80);
bus.loadProgram(0xb6, 0x10,
0xb6, 0x11,
0xb6, 0x12);
cpu.setYRegister(0x30);
cpu.step();
assertEquals(0x00, cpu.getXRegister());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
assertEquals(0x0f, cpu.getXRegister());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
assertEquals(0x80, cpu.getXRegister());
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
}
}