mirror of
https://github.com/sethm/symon.git
synced 2024-06-03 07:29:30 +00:00
4cca0b4663
First pass at adding CMOS 65C02 support for the following instructions and addressing modes: * ORA (ZP Indirect) * AND (ZP Indirect) * EOR (ZP Indirect) * ADC (ZP Indirect) * STA (ZP Indirect) * LDA (ZP Indirect) * CMP (ZP Indirect) * SBC (ZP Indirect)
111 lines
3.3 KiB
Java
111 lines
3.3 KiB
Java
package com.loomcom.symon;
|
|
|
|
import com.loomcom.symon.devices.Memory;
|
|
import com.loomcom.symon.exceptions.MemoryAccessException;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
public class CpuIndirectModeTest {
|
|
|
|
protected Cpu cpu;
|
|
protected Bus bus;
|
|
protected Memory mem;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
this.cpu = new Cpu();
|
|
this.bus = new Bus(0x0000, 0xffff);
|
|
this.mem = new Memory(0x0000, 0xffff);
|
|
bus.addCpu(cpu);
|
|
bus.addDevice(mem);
|
|
|
|
// Load the reset vector.
|
|
bus.write(0xfffc, Bus.DEFAULT_LOAD_ADDRESS & 0x00ff);
|
|
bus.write(0xfffd, (Bus.DEFAULT_LOAD_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 */
|
|
|
|
@Test
|
|
public void test_JMP_notOnPageBoundary() throws MemoryAccessException {
|
|
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());
|
|
}
|
|
|
|
@Test
|
|
public void test_JMP_with_ROR_Bug() throws MemoryAccessException {
|
|
cpu.setBehavior(Cpu.CpuBehavior.NMOS_WITH_ROR_BUG);
|
|
bus.write(0x3400, 0x22);
|
|
bus.write(0x34ff, 0x00);
|
|
bus.write(0x3500, 0x54);
|
|
bus.loadProgram(0x6c, 0xff, 0x34);
|
|
cpu.step();
|
|
assertEquals(0x2200, cpu.getProgramCounter());
|
|
// No change to status flags.
|
|
assertEquals(0x20, cpu.getProcessorStatus());
|
|
}
|
|
|
|
@Test
|
|
public void test_JMP_withIndirectBug() throws MemoryAccessException {
|
|
cpu.setBehavior(Cpu.CpuBehavior.NMOS_6502);
|
|
bus.write(0x3400, 0x22);
|
|
bus.write(0x34ff, 0x00);
|
|
bus.write(0x3500, 0x54);
|
|
bus.loadProgram(0x6c, 0xff, 0x34);
|
|
cpu.step();
|
|
assertEquals(0x2200, cpu.getProgramCounter());
|
|
// No change to status flags.
|
|
assertEquals(0x20, cpu.getProcessorStatus());
|
|
}
|
|
|
|
@Test
|
|
public void test_JMP_withOutIndirectBug() throws MemoryAccessException {
|
|
cpu.setBehavior(Cpu.CpuBehavior.CMOS_6502);
|
|
bus.write(0x3400, 0x22);
|
|
bus.write(0x34ff, 0x00);
|
|
bus.write(0x3500, 0x54);
|
|
bus.loadProgram(0x6c, 0xff, 0x34);
|
|
cpu.step();
|
|
assertEquals(0x5400, cpu.getProgramCounter());
|
|
// No change to status flags.
|
|
assertEquals(0x20, cpu.getProcessorStatus());
|
|
}
|
|
|
|
@Test
|
|
public void test_JMP_cmos() throws MemoryAccessException {
|
|
cpu.setBehavior(Cpu.CpuBehavior.CMOS_6502);
|
|
bus.write(0x3400, 0x22);
|
|
bus.write(0x34ff, 0x00);
|
|
bus.write(0x3500, 0x54);
|
|
bus.loadProgram(0x6c, 0xff, 0x34);
|
|
cpu.step();
|
|
assertEquals(0x5400, cpu.getProgramCounter());
|
|
// No change to status flags.
|
|
assertEquals(0x20, cpu.getProcessorStatus());
|
|
}
|
|
|
|
} |