diff --git a/src/main/kotlin/razorvine/c64emu/c64Main.kt b/src/main/kotlin/razorvine/c64emu/c64Main.kt index b312dcd..224bc7e 100644 --- a/src/main/kotlin/razorvine/c64emu/c64Main.kt +++ b/src/main/kotlin/razorvine/c64emu/c64Main.kt @@ -245,6 +245,10 @@ class C64Machine(title: String) : IVirtualMachine { // this should result in ~1 Mhz cpu speed val timer = java.util.Timer("cpu-cycle", true) timer.scheduleAtFixedRate(0, 1000L/VicII.framerate) { +// if(cpu.isLooping) { +// // cpu is jump looping, could do some sleeping here perhaps +// // but should still consider irqs occurring in the meantime... +// } if (!paused) { try { while (vic.vsync) step() diff --git a/src/main/kotlin/razorvine/ksim65/Cpu6502.kt b/src/main/kotlin/razorvine/ksim65/Cpu6502.kt index 29d20f1..4521ad8 100644 --- a/src/main/kotlin/razorvine/ksim65/Cpu6502.kt +++ b/src/main/kotlin/razorvine/ksim65/Cpu6502.kt @@ -98,6 +98,11 @@ open class Cpu6502 : BusComponent() { protected set var instrCycles: Int = 0 protected set + val isLooping: Boolean get() { + // jump loop detection + return (previousOpcodeAddress == currentOpcodeAddress) && !(pendingNMI || pendingIRQ) + } + private var previousOpcodeAddress: Address = 0xffff lateinit var currentInstruction: Instruction @@ -263,6 +268,7 @@ open class Cpu6502 : BusComponent() { } // no interrupt, fetch next instruction from memory + previousOpcodeAddress = currentOpcodeAddress currentOpcodeAddress = regPC currentOpcode = read(regPC) currentInstruction = instructions[currentOpcode]