NesCpuDebugSource.java

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

Mutations

29

1.1
Location : state
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:stepInstructionStepsTheNes()]
replaced return value with null for com/rox/NesCpuDebugSource::state → KILLED

34

1.1
Location : beam
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:beamIsWhereThePpuIsDrawing()]
replaced return value with null for com/rox/NesCpuDebugSource::beam → KILLED

45

1.1
Location : upcomingInstructions
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:upcomingInstructionsStartAtThePc()]
Replaced integer subtraction with addition → KILLED

2.2
Location : upcomingInstructions
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:beforeAnythingRunsUpcomingInstructionsStartAtThePc()]
changed conditional boundary → KILLED

3.3
Location : upcomingInstructions
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:beforeAnythingRunsUpcomingInstructionsStartAtThePc()]
negated conditional → KILLED

46

1.1
Location : upcomingInstructions
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:beforeAnythingRunsUpcomingInstructionsStartAtThePc()]
replaced return value with Collections.emptyList for com/rox/NesCpuDebugSource::upcomingInstructions → KILLED

54

1.1
Location : recentInstructions
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:recentInstructionsAreHistoryOldestFirstWithoutTheOneAtThePc()]
replaced return value with Collections.emptyList for com/rox/NesCpuDebugSource::recentInstructions → KILLED

2.2
Location : recentInstructions
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:recentInstructionsIsEmptyBeforeAnythingRuns()]
negated conditional → KILLED

3.3
Location : recentInstructions
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:recentInstructionsAreHistoryOldestFirstWithoutTheOneAtThePc()]
Replaced integer subtraction with addition → KILLED

60

1.1
Location : currentInstructionState
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:beforeAnythingRunsThereIsNoCurrentInstructionState()]
negated conditional → KILLED

2.2
Location : currentInstructionState
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:historyCarriesEachInstructionsStartingStateAndTheCurrentOnesToo()]
Replaced integer subtraction with addition → KILLED

3.3
Location : currentInstructionState
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:historyCarriesEachInstructionsStartingStateAndTheCurrentOnesToo()]
replaced return value with Optional.empty for com/rox/NesCpuDebugSource::currentInstructionState → KILLED

65

1.1
Location : instructionCount
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:instructionCountGoesUpByOnePerInstructionStep()]
replaced long return with 0 for com/rox/NesCpuDebugSource::instructionCount → KILLED

70

1.1
Location : measuredHz
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:measuredHzIsTheNessTickRateMonitors()]
replaced double return with 0.0d for com/rox/NesCpuDebugSource::measuredHz → KILLED

75

1.1
Location : intendedHz
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:ratesComeFromTheNes()]
replaced long return with 0 for com/rox/NesCpuDebugSource::intendedHz → KILLED

80

1.1
Location : speed
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:speedPassesThroughToTheNes()]
replaced double return with 0.0d for com/rox/NesCpuDebugSource::speed → KILLED

85

1.1
Location : setSpeed
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:speedPassesThroughToTheNes()]
removed call to com/rox/NES::setSpeed → KILLED

90

1.1
Location : pause
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:pauseReportsWhenThereWasNothingRunningToPause()]
replaced boolean return with true for com/rox/NesCpuDebugSource::pause → KILLED

2.2
Location : pause
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:pauseAndResumeDriveTheNes()]
replaced boolean return with false for com/rox/NesCpuDebugSource::pause → KILLED

95

1.1
Location : resume
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:pauseAndResumeDriveTheNes()]
removed call to com/rox/NES::resume → KILLED

100

1.1
Location : isPaused
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:pauseAndResumeDriveTheNes()]
replaced boolean return with true for com/rox/NesCpuDebugSource::isPaused → KILLED

2.2
Location : isPaused
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:pauseAndResumeDriveTheNes()]
replaced boolean return with false for com/rox/NesCpuDebugSource::isPaused → KILLED

105

1.1
Location : stepInstruction
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:stepInstructionStepsTheNes()]
removed call to com/rox/NES::stepInstruction → KILLED

110

1.1
Location : stepCycles
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:stepCyclesStepsTheNes()]
removed call to com/rox/NES::stepCycles → KILLED

115

1.1
Location : stepFrame
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:breakpointsAndTheLastHitPassThroughToTheNes()]
removed call to com/rox/NES::stepFrame → KILLED

120

1.1
Location : breakpoints
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:breakpointsAndTheLastHitPassThroughToTheNes()]
replaced return value with null for com/rox/NesCpuDebugSource::breakpoints → KILLED

125

1.1
Location : lastHit
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:breakpointsAndTheLastHitPassThroughToTheNes()]
replaced return value with Optional.empty for com/rox/NesCpuDebugSource::lastHit → KILLED

129

1.1
Location : peek
Killed by : com.rox.NesCpuDebugSourceTest.[engine:junit-jupiter]/[class:com.rox.NesCpuDebugSourceTest]/[method:beforeAnythingRunsUpcomingInstructionsStartAtThePc()]
replaced return value with null for com/rox/NesCpuDebugSource::peek → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1