| 1 | package com.rox; | |
| 2 | ||
| 3 | import com.rox.cpu.mos6502.MOS6502Snapshot; | |
| 4 | import com.rox.debug.labels.MemoryLabel; | |
| 5 | import com.rox.roundabout.debugger.DebugTarget; | |
| 6 | import com.rox.roundabout.memory.AddressFormat; | |
| 7 | import com.rox.roundabout.memory.MemoryRegion; | |
| 8 | import com.rox.roundabout.memory.MemorySource; | |
| 9 | import com.rox.roundabout.memory.NamedAddress; | |
| 10 | import com.rox.roundabout.timing.FrameTimes; | |
| 11 | ||
| 12 | import java.util.List; | |
| 13 | import java.util.Locale; | |
| 14 | import java.util.function.IntUnaryOperator; | |
| 15 | ||
| 16 | import static org.lwjgl.glfw.GLFW.GLFW_KEY_F; | |
| 17 | import static org.lwjgl.glfw.GLFW.GLFW_KEY_I; | |
| 18 | ||
| 19 | /** | |
| 20 | * Roundabout's {@link DebugTarget} over a live {@link NES} - reads through {@link NesMemoryDebugSource} (one RAM copy | |
| 21 | * per pass), run control and registers through {@link NesCpuDebugSource}, and any frame-timing streams given. | |
| 22 | */ | |
| 23 | final class NesRoundaboutTarget implements DebugTarget, MemorySource { | |
| 24 | private static final int ADDRESS_SPACE = 0x10000; | |
| 25 | private static final int UNUSED_FLAG = 0x20; | |
| 26 | ||
| 27 | private final NesMemoryDebugSource memory; | |
| 28 | private final NesCpuDebugSource cpu; | |
| 29 | private final List<NamedAddress> labels; | |
| 30 | private final List<FrameTimes> frameTimings; | |
| 31 | private final List<Step> steps; | |
| 32 | ||
| 33 | NesRoundaboutTarget(final NES nes, final List<MemoryLabel> labels){ | |
| 34 | this(nes, labels, List.of()); | |
| 35 | } | |
| 36 | ||
| 37 | NesRoundaboutTarget(final NES nes, final List<MemoryLabel> labels, final List<FrameTimes> frameTimings){ | |
| 38 | this.memory = new NesMemoryDebugSource(nes); | |
| 39 | this.cpu = new NesCpuDebugSource(nes); | |
| 40 |
1
1. lambda$new$0 : replaced return value with null for com/rox/NesRoundaboutTarget::lambda$new$0 → KILLED |
this.labels = labels.stream().map(l -> new NamedAddress(l.name(), l.start())).toList(); |
| 41 | this.frameTimings = List.copyOf(frameTimings); | |
| 42 | this.steps = List.of(new Step("Step frame", GLFW_KEY_F, cpu::stepFrame), | |
| 43 | new Step("Step instr", GLFW_KEY_I, cpu::stepInstruction)); | |
| 44 | } | |
| 45 | ||
| 46 | @Override | |
| 47 | public MemorySource memory(){ | |
| 48 |
1
1. memory : replaced return value with null for com/rox/NesRoundaboutTarget::memory → KILLED |
return this; |
| 49 | } | |
| 50 | ||
| 51 | @Override | |
| 52 | public List<MemoryRegion> regions(){ | |
| 53 |
1
1. regions : replaced return value with Collections.emptyList for com/rox/NesRoundaboutTarget::regions → KILLED |
return NesMemoryMap.REGIONS; |
| 54 | } | |
| 55 | ||
| 56 | /** {@code $}/{@code %} prefixes, as 6502 assemblers write them. */ | |
| 57 | @Override | |
| 58 | public AddressFormat.Style numberStyle(){ | |
| 59 |
1
1. numberStyle : replaced return value with null for com/rox/NesRoundaboutTarget::numberStyle → KILLED |
return AddressFormat.Style.MOTOROLA; |
| 60 | } | |
| 61 | ||
| 62 | @Override | |
| 63 | public List<NamedAddress> labels(){ | |
| 64 |
1
1. labels : replaced return value with Collections.emptyList for com/rox/NesRoundaboutTarget::labels → KILLED |
return labels; |
| 65 | } | |
| 66 | ||
| 67 | @Override | |
| 68 | public List<FrameTimes> frameTimings(){ | |
| 69 |
1
1. frameTimings : replaced return value with Collections.emptyList for com/rox/NesRoundaboutTarget::frameTimings → KILLED |
return frameTimings; |
| 70 | } | |
| 71 | ||
| 72 | @Override | |
| 73 | public CpuState cpu(){ | |
| 74 | final MOS6502Snapshot s = cpu.state(); | |
| 75 | final int p = status(s); | |
| 76 |
1
1. cpu : replaced return value with null for com/rox/NesRoundaboutTarget::cpu → KILLED |
return new CpuState(List.of(new Register("PC", s.pc(), 16), new Register("A", s.a(), 8), |
| 77 | new Register("X", s.x(), 8), new Register("Y", s.y(), 8), new Register("SP", s.stackPointer(), 8), | |
| 78 | new Register("P", p, 8)), Flag.fromBits("NV-BDIZC", p)); | |
| 79 | } | |
| 80 | ||
| 81 | /** The NV-BDIZC byte; bit 5 has no flag behind it and reads as 1, as {@code PHP} would push it. */ | |
| 82 | static int status(final MOS6502Snapshot s){ | |
| 83 |
5
1. status : negated conditional → KILLED 2. status : replaced int return with 0 for com/rox/NesRoundaboutTarget::status → KILLED 3. status : Replaced bitwise OR with AND → KILLED 4. status : Replaced bitwise OR with AND → KILLED 5. status : negated conditional → KILLED |
return (s.negative() ? 0x80 : 0) | (s.signedOverflow() ? 0x40 : 0) | UNUSED_FLAG |
| 84 |
6
1. status : negated conditional → KILLED 2. status : Replaced bitwise OR with AND → KILLED 3. status : Replaced bitwise OR with AND → KILLED 4. status : Replaced bitwise OR with AND → KILLED 5. status : negated conditional → KILLED 6. status : negated conditional → KILLED |
| (s.breakFlag() ? 0x10 : 0) | (s.decimal() ? 0x08 : 0) | (s.interruptDisable() ? 0x04 : 0) |
| 85 |
4
1. status : Replaced bitwise OR with AND → KILLED 2. status : Replaced bitwise OR with AND → KILLED 3. status : negated conditional → KILLED 4. status : negated conditional → KILLED |
| (s.zero() ? 0x02 : 0) | (s.carry() ? 0x01 : 0); |
| 86 | } | |
| 87 | ||
| 88 | @Override | |
| 89 | public boolean isPaused(){ | |
| 90 |
2
1. isPaused : replaced boolean return with false for com/rox/NesRoundaboutTarget::isPaused → KILLED 2. isPaused : replaced boolean return with true for com/rox/NesRoundaboutTarget::isPaused → KILLED |
return cpu.isPaused(); |
| 91 | } | |
| 92 | ||
| 93 | @Override | |
| 94 | public void pause(){ | |
| 95 | cpu.pause(); | |
| 96 | } | |
| 97 | ||
| 98 | @Override | |
| 99 | public void resume(){ | |
| 100 |
1
1. resume : removed call to com/rox/NesCpuDebugSource::resume → KILLED |
cpu.resume(); |
| 101 | } | |
| 102 | ||
| 103 | @Override | |
| 104 | public List<Step> steps(){ | |
| 105 |
1
1. steps : replaced return value with Collections.emptyList for com/rox/NesRoundaboutTarget::steps → KILLED |
return steps; |
| 106 | } | |
| 107 | ||
| 108 | @Override | |
| 109 | public String status(){ | |
| 110 | final double hz = cpu.measuredHz(); | |
| 111 |
3
1. status : Replaced double multiplication with division → KILLED 2. status : Replaced double division with multiplication → KILLED 3. status : replaced return value with "" for com/rox/NesRoundaboutTarget::status → KILLED |
return String.format(Locale.ROOT, "%,d instructions · %.3f MHz (%d%%)", cpu.instructionCount(), hz / 1e6, |
| 112 |
1
1. status : Replaced double division with multiplication → KILLED |
Math.round(100 * hz / cpu.intendedHz())); |
| 113 | } | |
| 114 | ||
| 115 | // ---- MemorySource --------------------------------------------------------------------------- | |
| 116 | ||
| 117 | @Override | |
| 118 | public int size(){ | |
| 119 |
1
1. size : replaced int return with 0 for com/rox/NesRoundaboutTarget::size → KILLED |
return ADDRESS_SPACE; |
| 120 | } | |
| 121 | ||
| 122 | /** One RAM copy per call - use {@link #reader()} for more than the odd byte. */ | |
| 123 | @Override | |
| 124 | public int peek(final int address){ | |
| 125 |
1
1. peek : replaced int return with 0 for com/rox/NesRoundaboutTarget::peek → KILLED |
return memory.peek().applyAsInt(address); |
| 126 | } | |
| 127 | ||
| 128 | @Override | |
| 129 | public IntUnaryOperator reader(){ | |
| 130 |
1
1. reader : replaced return value with null for com/rox/NesRoundaboutTarget::reader → KILLED |
return memory.peek(); |
| 131 | } | |
| 132 | ||
| 133 | @Override | |
| 134 | public boolean isEditable(final int address){ | |
| 135 |
2
1. isEditable : replaced boolean return with false for com/rox/NesRoundaboutTarget::isEditable → KILLED 2. isEditable : replaced boolean return with true for com/rox/NesRoundaboutTarget::isEditable → KILLED |
return memory.isEditable(address); |
| 136 | } | |
| 137 | ||
| 138 | @Override | |
| 139 | public void poke(final int address, final int value){ | |
| 140 |
1
1. poke : removed call to com/rox/NesMemoryDebugSource::poke → KILLED |
memory.poke(address, value); |
| 141 | } | |
| 142 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 48 |
1.1 |
|
| 53 |
1.1 |
|
| 59 |
1.1 |
|
| 64 |
1.1 |
|
| 69 |
1.1 |
|
| 76 |
1.1 |
|
| 83 |
1.1 2.2 3.3 4.4 5.5 |
|
| 84 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 85 |
1.1 2.2 3.3 4.4 |
|
| 90 |
1.1 2.2 |
|
| 100 |
1.1 |
|
| 105 |
1.1 |
|
| 111 |
1.1 2.2 3.3 |
|
| 112 |
1.1 |
|
| 119 |
1.1 |
|
| 125 |
1.1 |
|
| 130 |
1.1 |
|
| 135 |
1.1 2.2 |
|
| 140 |
1.1 |