ChrMemory.java

1
package com.rox.cartridge;
2
3
import com.rox.ByteUtil;
4
5
import static com.rox.ByteUtil.BYTE_MASK;
6
7
/**
8
 * A board's CHR memory, by offset:
9
 * <ul>
10
 * <li>CHR-ROM if the ROM file has any - read-only, writes are dropped as on real hardware</li>
11
 * <li>otherwise CHR-RAM, which games fill with their own tiles</li>
12
 * </ul>
13
 * Mapping a PPU address to an offset (banking) is left to each mapper.
14
 */
15
final class ChrMemory {
16
    private static final String WHAT = "CHR-RAM";
17
18
    private final int[] bytes;
19
    private final boolean ram;
20
21
    private ChrMemory(final int[] bytes, final boolean ram){
22
        this.bytes = bytes;
23
        this.ram = ram;
24
    }
25
26
    /** @param ramSize how much CHR-RAM a board gets when the ROM file has no CHR-ROM */
27
    static ChrMemory of(final INesRom rom, final int ramSize){
28
        final byte[] romChr = rom.chrRom();
29 3 1. of : changed conditional boundary → KILLED
2. of : replaced return value with null for com/rox/cartridge/ChrMemory::of → KILLED
3. of : negated conditional → KILLED
        return romChr.length > 0
30
                ? new ChrMemory(ByteUtil.toUnsigned(romChr), false)
31
                : new ChrMemory(new int[ramSize], true);
32
    }
33
34
    int read(final int offset){
35 1 1. read : replaced int return with 0 for com/rox/cartridge/ChrMemory::read → KILLED
        return bytes[offset];
36
    }
37
38
    /** A no-op on CHR-ROM. */
39
    void write(final int offset, final int value){
40 1 1. write : negated conditional → KILLED
        if (ram){
41 1 1. write : Replaced bitwise AND with OR → KILLED
            bytes[offset] = value & BYTE_MASK;
42
        }
43
    }
44
45
    boolean isRam(){
46 2 1. isRam : replaced boolean return with false for com/rox/cartridge/ChrMemory::isRam → KILLED
2. isRam : replaced boolean return with true for com/rox/cartridge/ChrMemory::isRam → KILLED
        return ram;
47
    }
48
49
    int size(){
50 1 1. size : replaced int return with 0 for com/rox/cartridge/ChrMemory::size → KILLED
        return bytes.length;
51
    }
52
53
    /** The CHR-RAM, or empty for CHR-ROM - it comes back from the ROM file, so there's nothing to save. */
54
    int[] snapshot(){
55 1 1. snapshot : replaced return value with null for com/rox/cartridge/ChrMemory::snapshot → KILLED
        return SnapshotArrays.copyOf(ramOrNull());
56
    }
57
58
    /** @throws IllegalArgumentException if {@code saved} doesn't fit, i.e. it's from a different board */
59
    void checkRestorable(final int[] saved){
60 1 1. checkRestorable : removed call to com/rox/cartridge/SnapshotArrays::requireSameSize → KILLED
        SnapshotArrays.requireSameSize(saved, ramOrNull(), WHAT);
61
    }
62
63
    void restore(final int[] saved){
64 1 1. restore : removed call to com/rox/cartridge/SnapshotArrays::copy → KILLED
        SnapshotArrays.copy(saved, ramOrNull());
65
    }
66
67
    /** {@link SnapshotArrays}' "this board has none". */
68
    private int[] ramOrNull(){
69 1 1. ramOrNull : negated conditional → KILLED
        return ram ? bytes : null;
70
    }
71
}

Mutations

29

1.1
Location : of
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
changed conditional boundary → KILLED

2.2
Location : of
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
replaced return value with null for com/rox/cartridge/ChrMemory::of → KILLED

3.3
Location : of
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
negated conditional → KILLED

35

1.1
Location : read
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
replaced int return with 0 for com/rox/cartridge/ChrMemory::read → KILLED

40

1.1
Location : write
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
negated conditional → KILLED

41

1.1
Location : write
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
Replaced bitwise AND with OR → KILLED

46

1.1
Location : isRam
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
replaced boolean return with false for com/rox/cartridge/ChrMemory::isRam → KILLED

2.2
Location : isRam
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRomIsReadUnsignedAndIgnoresWrites()]
replaced boolean return with true for com/rox/cartridge/ChrMemory::isRam → KILLED

50

1.1
Location : size
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:withoutChrRomItsRamOfTheGivenSize()]
replaced int return with 0 for com/rox/cartridge/ChrMemory::size → KILLED

55

1.1
Location : snapshot
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
replaced return value with null for com/rox/cartridge/ChrMemory::snapshot → KILLED

60

1.1
Location : checkRestorable
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
removed call to com/rox/cartridge/SnapshotArrays::requireSameSize → KILLED

64

1.1
Location : restore
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
removed call to com/rox/cartridge/SnapshotArrays::copy → KILLED

69

1.1
Location : ramOrNull
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1