Search in sources :

Example 16 with Program

use of com.rox.emu.processor.mos6502.util.Program in project emuRox by rossdrew.

the class Mos6502CompilerTest method testIntegration.

@Test
public void testIntegration() {
    final Mos6502Compiler compiler = new Mos6502Compiler("LDA #$14 ADC #$5 STA $20");
    Program program = compiler.compileProgram();
    final int[] programByte = program.getProgramAsByteArray();
    Memory memory = new SimpleMemory();
    Mos6502 processor = new Mos6502(memory);
    processor.reset();
    memory.setBlock(0, programByte);
    processor.step(3);
    Registers registers = processor.getRegisters();
    assertEquals(0x19, registers.getRegister(Registers.Register.ACCUMULATOR));
    assertEquals(0x19, memory.getByte(0x20));
    assertEquals(programByte.length, registers.getPC());
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) SimpleMemory(com.rox.emu.mem.SimpleMemory) Memory(com.rox.emu.mem.Memory) SimpleMemory(com.rox.emu.mem.SimpleMemory) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 17 with Program

use of com.rox.emu.processor.mos6502.util.Program in project emuRox by rossdrew.

the class Mos6502Properties method testInvalidImmediateADC.

@Property(trials = 100)
public void testInvalidImmediateADC(@When(satisfies = "#_ < 0 || #_ > 255") int value) {
    Program program = new Program().with(LDA_I, value);
    memory.setBlock(0, program.getProgramAsByteArray());
    processor.step();
    Registers registers = processor.getRegisters();
    assertNotEquals(value, registers.getRegister(Registers.Register.ACCUMULATOR));
    assertEquals(program.getLength(), registers.getPC());
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Property(com.pholser.junit.quickcheck.Property)

Example 18 with Program

use of com.rox.emu.processor.mos6502.util.Program in project emuRox by rossdrew.

the class Mos6502Test method testADC.

@Test
public void testADC() {
    Program program = new Program().with(CLC, LDA_I, 0x1, ADC_I, 0x1);
    memory.setBlock(0, program.getProgramAsByteArray());
    processor.step(3);
    Registers registers = processor.getRegisters();
    // Accumulator is 0x2 == (0x1 + 0x1) == (mem[0x1] + mem[0x3])
    assertEquals(0x2, registers.getRegister(Registers.Register.ACCUMULATOR));
    assertEquals(program.getLength(), registers.getPC());
    assertEquals(0x0, 0);
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 19 with Program

use of com.rox.emu.processor.mos6502.util.Program in project emuRox by rossdrew.

the class Mos6502Test method testBEQ.

@Test
public void testBEQ() {
    Program program = new Program().with(LDA_I, 0x0, BEQ, 0x4, LDA_I, 0x99, LDX_I, 0x98, LDY_I, 0x97);
    memory.setBlock(0, program.getProgramAsByteArray());
    Registers registers = processor.getRegisters();
    processor.step(3);
    assertEquals(program.getLength(), registers.getPC());
    assertEquals(0x0, registers.getRegister(Registers.Register.ACCUMULATOR));
    assertEquals(0x0, registers.getRegister(Registers.Register.X_INDEX));
    assertEquals(0x97, registers.getRegister(Registers.Register.Y_INDEX));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 20 with Program

use of com.rox.emu.processor.mos6502.util.Program in project emuRox by rossdrew.

the class Mos6502Test method testCPX.

@Test
public void testCPX() {
    Program program = new Program().with(LDX_I, 0x10, CPX_I, 0x10);
    memory.setBlock(0, program.getProgramAsByteArray());
    Registers registers = processor.getRegisters();
    processor.step(2);
    assertEquals(program.getLength(), registers.getPC());
    assertEquals(0x10, registers.getRegister(Registers.Register.X_INDEX));
    assertEquals(true, registers.getFlag(Registers.Flag.ZERO));
    assertEquals(false, registers.getFlag(Registers.Flag.NEGATIVE));
    assertEquals(true, registers.getFlag(Registers.Flag.CARRY));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Aggregations

Program (com.rox.emu.processor.mos6502.util.Program)100 Test (org.junit.Test)86 Mos6502Compiler (com.rox.emu.processor.mos6502.util.Mos6502Compiler)32 Property (com.pholser.junit.quickcheck.Property)12 UnknownOpCodeException (com.rox.emu.UnknownOpCodeException)6 Memory (com.rox.emu.mem.Memory)2 SimpleMemory (com.rox.emu.mem.SimpleMemory)2 UnknownTokenException (com.rox.emu.UnknownTokenException)1 RoxWord (com.rox.emu.env.RoxWord)1 AddressingMode (com.rox.emu.processor.mos6502.op.AddressingMode)1 OpCode (com.rox.emu.processor.mos6502.op.OpCode)1 StringTokenizer (java.util.StringTokenizer)1