| 1 | package com.rox; | |
| 2 | ||
| 3 | import com.rox.cpu.mos6502.MOS6502Snapshot; | |
| 4 | import com.rox.cpu.mos6502.assembler.DisassembledInstruction; | |
| 5 | import com.rox.cpu.mos6502.assembler.Disassembler; | |
| 6 | import com.rox.debug.cpu.CpuDebugSource; | |
| 7 | import com.rox.debug.cpu.InstructionTrace; | |
| 8 | import com.rox.debug.cpu.TracedInstruction; | |
| 9 | ||
| 10 | import java.util.List; | |
| 11 | import java.util.Optional; | |
| 12 | import java.util.function.IntUnaryOperator; | |
| 13 | ||
| 14 | /** {@link CpuDebugSource} over a live {@link NES}, reading memory through {@link DebugCapture}'s side-effect-free peek. */ | |
| 15 | final class NesCpuDebugSource implements CpuDebugSource { | |
| 16 | private final NES nes; | |
| 17 | private final NesMemoryDebugSource memory; | |
| 18 | ||
| 19 | NesCpuDebugSource(final NES nes){ | |
| 20 | this.nes = nes; | |
| 21 | this.memory = new NesMemoryDebugSource(nes); | |
| 22 | } | |
| 23 | ||
| 24 | @Override | |
| 25 | public MOS6502Snapshot state(){ | |
| 26 |
1
1. state : replaced return value with null for com/rox/NesCpuDebugSource::state → KILLED |
return nes.cpu().liveState(); |
| 27 | } | |
| 28 | ||
| 29 | /** | |
| 30 | * Starts at the current instruction - the trace's newest entry, not the raw PC: read live, the CPU is | |
| 31 | * usually part-way through an instruction, with the PC already pointing into its operand bytes | |
| 32 | * (e.g. at the {@code $5B} of {@code JMP $E45B}), which would disassemble as nonsense. | |
| 33 | */ | |
| 34 | @Override | |
| 35 | public List<DisassembledInstruction> upcomingInstructions(final int count){ | |
| 36 | final int[] trace = nes.instructionTrace().recent(); | |
| 37 |
3
1. upcomingInstructions : changed conditional boundary → KILLED 2. upcomingInstructions : negated conditional → KILLED 3. upcomingInstructions : Replaced integer subtraction with addition → KILLED |
final int current = trace.length > 0 ? trace[trace.length - 1] : nes.cpu().programCounter(); |
| 38 |
1
1. upcomingInstructions : replaced return value with Collections.emptyList for com/rox/NesCpuDebugSource::upcomingInstructions → KILLED |
return Disassembler.disassembleForward(peek(), current, count); |
| 39 | } | |
| 40 | ||
| 41 | /** Decoded from the bytes recorded as each instruction ran, not today's memory - see {@link InstructionTrace}. */ | |
| 42 | @Override | |
| 43 | public List<TracedInstruction> recentInstructions(){ | |
| 44 | final List<TracedInstruction> history = nes.instructionTrace().history(); | |
| 45 | //the newest entry is the current instruction (about to start, or part-way through) - not history yet | |
| 46 |
3
1. recentInstructions : Replaced integer subtraction with addition → KILLED 2. recentInstructions : replaced return value with Collections.emptyList for com/rox/NesCpuDebugSource::recentInstructions → KILLED 3. recentInstructions : negated conditional → KILLED |
return history.isEmpty() ? history : history.subList(0, history.size() - 1); |
| 47 | } | |
| 48 | ||
| 49 | @Override | |
| 50 | public Optional<MOS6502Snapshot> currentInstructionState(){ | |
| 51 | final List<TracedInstruction> history = nes.instructionTrace().history(); | |
| 52 |
3
1. currentInstructionState : negated conditional → KILLED 2. currentInstructionState : Replaced integer subtraction with addition → KILLED 3. currentInstructionState : replaced return value with Optional.empty for com/rox/NesCpuDebugSource::currentInstructionState → KILLED |
return history.isEmpty() ? Optional.empty() : Optional.of(history.get(history.size() - 1).before()); |
| 53 | } | |
| 54 | ||
| 55 | @Override | |
| 56 | public long instructionCount(){ | |
| 57 |
1
1. instructionCount : replaced long return with 0 for com/rox/NesCpuDebugSource::instructionCount → KILLED |
return nes.instructionTrace().recorded(); |
| 58 | } | |
| 59 | ||
| 60 | @Override | |
| 61 | public double measuredHz(){ | |
| 62 |
1
1. measuredHz : replaced double return with 0.0d for com/rox/NesCpuDebugSource::measuredHz → KILLED |
return nes.tickRateMonitor().measuredHz(); |
| 63 | } | |
| 64 | ||
| 65 | @Override | |
| 66 | public long intendedHz(){ | |
| 67 |
1
1. intendedHz : replaced long return with 0 for com/rox/NesCpuDebugSource::intendedHz → KILLED |
return NES.intendedCpuHz(); |
| 68 | } | |
| 69 | ||
| 70 | @Override | |
| 71 | public boolean pause(){ | |
| 72 |
2
1. pause : replaced boolean return with true for com/rox/NesCpuDebugSource::pause → KILLED 2. pause : replaced boolean return with false for com/rox/NesCpuDebugSource::pause → KILLED |
return nes.pause(); |
| 73 | } | |
| 74 | ||
| 75 | @Override | |
| 76 | public void resume(){ | |
| 77 |
1
1. resume : removed call to com/rox/NES::resume → KILLED |
nes.resume(); |
| 78 | } | |
| 79 | ||
| 80 | @Override | |
| 81 | public boolean isPaused(){ | |
| 82 |
2
1. isPaused : replaced boolean return with true for com/rox/NesCpuDebugSource::isPaused → KILLED 2. isPaused : replaced boolean return with false for com/rox/NesCpuDebugSource::isPaused → KILLED |
return nes.isPaused(); |
| 83 | } | |
| 84 | ||
| 85 | @Override | |
| 86 | public void stepInstruction(){ | |
| 87 |
1
1. stepInstruction : removed call to com/rox/NES::stepInstruction → KILLED |
nes.stepInstruction(); |
| 88 | } | |
| 89 | ||
| 90 | @Override | |
| 91 | public void stepCycles(final int cycles){ | |
| 92 |
1
1. stepCycles : removed call to com/rox/NES::stepCycles → KILLED |
nes.stepCycles(cycles); |
| 93 | } | |
| 94 | ||
| 95 | @Override | |
| 96 | public void stepFrame(){ | |
| 97 |
1
1. stepFrame : removed call to com/rox/NES::stepFrame → KILLED |
nes.stepFrame(); |
| 98 | } | |
| 99 | ||
| 100 | private IntUnaryOperator peek(){ | |
| 101 |
1
1. peek : replaced return value with null for com/rox/NesCpuDebugSource::peek → KILLED |
return memory.peek(); |
| 102 | } | |
| 103 | } | |
Mutations | ||
| 26 |
1.1 |
|
| 37 |
1.1 2.2 3.3 |
|
| 38 |
1.1 |
|
| 46 |
1.1 2.2 3.3 |
|
| 52 |
1.1 2.2 3.3 |
|
| 57 |
1.1 |
|
| 62 |
1.1 |
|
| 67 |
1.1 |
|
| 72 |
1.1 2.2 |
|
| 77 |
1.1 |
|
| 82 |
1.1 2.2 |
|
| 87 |
1.1 |
|
| 92 |
1.1 |
|
| 97 |
1.1 |
|
| 101 |
1.1 |