Search in sources :

Example 56 with Program

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

the class Mos6502Test method testCLC.

@Test
public void testCLC() {
    Program program = new Program().with(SEC, CLC);
    memory.setBlock(0, program.getProgramAsByteArray());
    Registers registers = processor.getRegisters();
    processor.step();
    assert (processor.getRegisters().getFlag(Registers.Flag.CARRY));
    processor.step();
    assertEquals(program.getLength(), registers.getPC());
    assertEquals(false, registers.getFlag(Registers.Flag.CARRY));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 57 with Program

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

the class Mos6502Test method testBPL.

@Test
public void testBPL() {
    Program program = new Program().with(LDA_I, 0b00000001, BPL, 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(0b00000001, 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 58 with Program

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

the class Mos6502Test method testLDX.

@Test
public void testLDX() {
    Program program = new Program().with(LDX_I, 0xAA);
    memory.setBlock(0, program.getProgramAsByteArray());
    processor.step();
    Registers registers = processor.getRegisters();
    assertEquals(0xAA, registers.getRegister(Registers.Register.X_INDEX));
    assertEquals(0x0, 0);
    assertEquals(program.getLength(), registers.getPC());
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 59 with Program

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

the class Mos6502Test method testMultiplicationLoop.

@Test
public void testMultiplicationLoop() {
    int data_offset = 0x32;
    int MPD = data_offset + 0x10;
    int MPR = data_offset + 0x11;
    int TMP = data_offset + 0x20;
    int RESAD_0 = data_offset + 0x30;
    int RESAD_1 = data_offset + 0x31;
    int valMPD = 7;
    int valMPR = 4;
    Program program = new Program().with(LDA_I, valMPD, STA_Z, MPD, LDA_I, valMPR, STA_Z, MPR, // <---- start
    LDA_I, // <---- start
    0, // Clear
    STA_Z, // Clear
    TMP, // ...
    STA_Z, // ...
    RESAD_0, // ...
    STA_Z, // ...
    RESAD_1, // X counts each bit
    LDX_I, // X counts each bit
    8, // :MULT(18) LSR(MPR)
    LSR_Z, // :MULT(18) LSR(MPR)
    MPR, // Test carry and jump (forward 13) to NOADD
    BCC, // Test carry and jump (forward 13) to NOADD
    13, // RESAD -> A
    LDA_Z, // RESAD -> A
    RESAD_0, // Prepare to add
    CLC, // +MPD
    ADC_Z, // +MPD
    MPD, // Save result
    STA_Z, // Save result
    RESAD_0, // RESAD+1 -> A
    LDA_Z, // RESAD+1 -> A
    RESAD_1, // +TMP
    ADC_Z, // +TMP
    TMP, // RESAD+1 <- A
    STA_Z, // RESAD+1 <- A
    RESAD_1, // :NOADD(35) ASL(MPD)
    ASL_Z, // :NOADD(35) ASL(MPD)
    MPD, // Save bit from MPD
    ROL_Z, // Save bit from MPD
    TMP, // --X
    DEX, // Test equal and jump (back 24) to MULT
    BNE, // Test equal and jump (back 24) to MULT
    0b11100111);
    memory.setBlock(0, program.getProgramAsByteArray());
    Registers registers = processor.getRegisters();
    processor.step(27);
    assertEquals(0x1C, memory.getByte(RESAD_0));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Test(org.junit.Test)

Example 60 with Program

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

the class Mos6502Test method testDEX.

@Test
public void testDEX() {
    Program program = new Program().with(LDX_I, 0x01, DEX);
    memory.setBlock(0, program.getProgramAsByteArray());
    Registers registers = processor.getRegisters();
    processor.step();
    assert (processor.getRegisters().getRegister(Registers.Register.X_INDEX) == 1);
    processor.step();
    assertEquals(program.getLength(), registers.getPC());
    assertEquals(0, processor.getRegisters().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