Search in sources :

Example 61 with Program

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

the class Mos6502Test method testBRK.

@Test
public void testBRK() {
    Program program = new Program().with(BRK);
    memory.setBlock(0, program.getProgramAsByteArray());
    // New PC
    memory.setByteAt(0xFFFE, 0);
    memory.setByteAt(0xFFFF, 0);
    Registers registers = processor.getRegisters();
    // Sample register values
    registers.setRegister(Registers.Register.STATUS_FLAGS, 0b00000000);
    processor.step(1);
    assertEquals(0xFC, registers.getRegister(Registers.Register.STACK_POINTER_HI));
    // PC (on Stack)
    assertEquals(0x03, memory.getByte(0x1FE));
    assertEquals(0x00, memory.getByte(0x1FF));
    // Status (on stack) with B set
    assertEquals(Registers.Flag.BREAK.getPlaceValue(), memory.getByte(0x1FD));
    // PC is set to value of [FFFE:FFFF]
    assertEquals(memory.getByte(0xFFFE), registers.getRegister(Registers.Register.PROGRAM_COUNTER_HI));
    assertEquals(memory.getByte(0xFFFF), registers.getRegister(Registers.Register.PROGRAM_COUNTER_LOW));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 62 with Program

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

the class Mos6502Test method testROL.

@Test
public void testROL() {
    Program program = new Program().with(SEC, LDA_I, 0b00000001, ROL_A);
    memory.setBlock(0, program.getProgramAsByteArray());
    Registers registers = processor.getRegisters();
    processor.step(3);
    assertEquals(program.getLength(), registers.getPC());
    assertEquals(0b00000011, registers.getRegister(Registers.Register.ACCUMULATOR));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 63 with Program

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

the class Mos6502Test method testSBCWithCarry.

@Test
public void testSBCWithCarry() {
    Program program = new Program().with(CLC, LDA_I, 0xA, SBC_I, 0x5);
    memory.setBlock(0, program.getProgramAsByteArray());
    processor.step(3);
    Registers registers = processor.getRegisters();
    assertEquals(0x4, registers.getRegister(Registers.Register.ACCUMULATOR));
    assertEquals(program.getLength(), registers.getPC());
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 64 with Program

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

the class Mos6502Test method testJMP.

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

Example 65 with Program

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

the class Mos6502Test method testLoop.

@Test(timeout = 2000)
public void testLoop() {
    Program program = // Loop counter
    new Program().with(// Loop counter
    LDX_I, // Loop counter
    10, // Sum
    LDA_I, // Sum
    0, // LOOP: Clear cary before ADC
    CLC, // Add one
    ADC_I, // Add one
    1, // advance loop counter
    DEX, // is it the end of the loop?
    CPX_I, // is it the end of the loop?
    0, BNE, // If not, go again
    0b11110111);
    memory.setBlock(0, program.getProgramAsByteArray());
    Registers registers = processor.getRegisters();
    while (registers.getRegister(Registers.Register.PROGRAM_COUNTER_LOW) < program.getLength()) processor.step();
    assertEquals(10, registers.getRegister(Registers.Register.ACCUMULATOR));
    assertEquals(0, registers.getRegister(Registers.Register.X_INDEX));
}
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