AxromMapper.java

1
package com.rox.cartridge;
2
3
import java.util.LinkedHashMap;
4
import java.util.Map;
5
6
import static com.rox.ByteUtil.BYTE_MASK;
7
8
/**
9
 * iNES mapper 7 (AxROM - Rare's boards, e.g. Battletoads). One register, written anywhere in
10
 * {@code $8000-$FFFF} (nesdev, https://www.nesdev.org/wiki/AxROM):
11
 * <pre>
12
 * 7  bit  0
13
 * ---- ----
14
 * xxxM xPPP
15
 *    |  |||
16
 *    |  +++- Select 32 KB PRG ROM bank for CPU $8000-$FFFF
17
 *    +------ Select 1 KB VRAM page for all 4 nametables
18
 * </pre>
19
 * M = 0 is the lower page, M = 1 the upper. 8KB of CHR-RAM, unbanked; no PRG-RAM, so
20
 * {@code $6000-$7FFF} reads 0 and ignores writes.
21
 *
22
 * Bus conflicts aren't modeled - nesdev: "Submapper 0: Bus conflict behavior undefined, but emulators
23
 * shouldn't emulate bus conflicts". Bank 0 is mapped at power on; nesdev gives no initial state, and
24
 * Rare's games don't rely on one.
25
 */
26
public final class AxromMapper implements Mapper {
27
    private static final int PRG_ROM_START_ADDRESS = 0x8000;
28
    private static final int PRG_BANK_SIZE = 0x8000;
29
    private static final int PRG_BANK_MASK = 0x07;
30
    private static final int NAMETABLE_PAGE_BIT = 0x10;
31
    private static final int CHR_SIZE = 0x2000;
32
    private static final int[] NO_PRG_RAM = new int[0];
33
34
    private final byte[] prgRom;
35
    private final int prgBankCount;
36
    private final ChrMemory chr;
37
38
    /** last value written to $8000-$FFFF: PRG bank (bits 0-2), nametable page (bit 4) */
39
    private int bankSelect;
40
41
    public AxromMapper(final INesRom rom){
42
        this.prgRom = rom.prgRom();
43 3 1. <init> : Replaced integer modulus with multiplication → KILLED
2. <init> : negated conditional → KILLED
3. <init> : negated conditional → KILLED
        if (prgRom.length == 0 || prgRom.length % PRG_BANK_SIZE != 0){
44
            throw new IllegalArgumentException("AxROM expects PRG-ROM in whole 32KB banks, got " + prgRom.length + " bytes");
45
        }
46 1 1. <init> : Replaced integer division with multiplication → KILLED
        this.prgBankCount = prgRom.length / PRG_BANK_SIZE;
47
        this.chr = ChrMemory.of(rom, CHR_SIZE);
48
    }
49
50
    /** Contract: only ever called with {@code address} in {@code $6000-$FFFF} (see {@link Mapper}'s class doc). */
51
    @Override
52
    public int read(final int address){
53 2 1. read : changed conditional boundary → KILLED
2. read : negated conditional → KILLED
        if (address < PRG_ROM_START_ADDRESS){
54
            return 0;
55
        }
56 5 1. read : Replaced bitwise AND with OR → KILLED
2. read : replaced int return with 0 for com/rox/cartridge/AxromMapper::read → KILLED
3. read : Replaced integer subtraction with addition → KILLED
4. read : Replaced integer multiplication with division → KILLED
5. read : Replaced integer addition with subtraction → KILLED
        return prgRom[prgBank() * PRG_BANK_SIZE + (address - PRG_ROM_START_ADDRESS)] & BYTE_MASK;
57
    }
58
59
    /** Contract: only ever called with {@code address} in {@code $6000-$FFFF} (see {@link Mapper}'s class doc). */
60
    @Override
61
    public void write(final int address, final int value){
62 2 1. write : changed conditional boundary → KILLED
2. write : negated conditional → KILLED
        if (address >= PRG_ROM_START_ADDRESS){
63 1 1. write : Replaced bitwise AND with OR → KILLED
            bankSelect = value & BYTE_MASK;
64
        }
65
    }
66
67
    /** Wraps a bank number past the ROM's end, as the board's unconnected address lines do. */
68
    private int prgBank(){
69 3 1. prgBank : replaced int return with 0 for com/rox/cartridge/AxromMapper::prgBank → KILLED
2. prgBank : Replaced bitwise AND with OR → KILLED
3. prgBank : Replaced integer modulus with multiplication → KILLED
        return (bankSelect & PRG_BANK_MASK) % prgBankCount;
70
    }
71
72
    @Override
73
    public int readChr(final int address){
74 2 1. readChr : Replaced bitwise AND with OR → KILLED
2. readChr : replaced int return with 0 for com/rox/cartridge/AxromMapper::readChr → KILLED
        return chr.read(address & (CHR_SIZE - 1));
75
    }
76
77
    /** No-op on CHR-ROM boards - real hardware has nowhere to write CHR-ROM writes to. */
78
    @Override
79
    public void writeChr(final int address, final int value){
80 2 1. writeChr : removed call to com/rox/cartridge/ChrMemory::write → KILLED
2. writeChr : Replaced bitwise AND with OR → KILLED
        chr.write(address & (CHR_SIZE - 1), value);
81
    }
82
83
    @Override
84
    public Mirroring nametableMirroring(){
85 3 1. nametableMirroring : replaced return value with null for com/rox/cartridge/AxromMapper::nametableMirroring → KILLED
2. nametableMirroring : negated conditional → KILLED
3. nametableMirroring : Replaced bitwise AND with OR → KILLED
        return (bankSelect & NAMETABLE_PAGE_BIT) == 0 ? Mirroring.SINGLE_SCREEN_LOWER : Mirroring.SINGLE_SCREEN_UPPER;
86
    }
87
88
    /** None - AxROM boards have no PRG-RAM. */
89
    @Override
90
    public int[] prgRam(){
91 1 1. prgRam : replaced return value with null for com/rox/cartridge/AxromMapper::prgRam → KILLED
        return NO_PRG_RAM.clone();
92
    }
93
94
    @Override
95
    public void restorePrgRam(final int[] prgRam){
96 1 1. restorePrgRam : removed call to com/rox/cartridge/SnapshotArrays::requireSameSize → KILLED
        SnapshotArrays.requireSameSize(prgRam, null, "PRG-RAM");
97
    }
98
99
    @Override
100
    public Map<String, String> debugState(){
101
        final Map<String, String> state = new LinkedHashMap<>();
102
        state.put("Bank select", String.format("$%02X", bankSelect));
103
        state.put("PRG bank", String.valueOf(prgBank()));
104 1 1. debugState : replaced return value with Collections.emptyMap for com/rox/cartridge/AxromMapper::debugState → KILLED
        return state;
105
    }
106
107
    @Override
108
    public MapperSnapshot snapshot(){
109 1 1. snapshot : replaced return value with null for com/rox/cartridge/AxromMapper::snapshot → KILLED
        return new AxromMapperSnapshot(NO_PRG_RAM.clone(), chr.snapshot(), bankSelect);
110
    }
111
112
    @Override
113
    public void checkRestorable(final MapperSnapshot snapshot){
114
        final AxromMapperSnapshot axrom = SnapshotArrays.expect(snapshot, AxromMapperSnapshot.class);
115 1 1. checkRestorable : removed call to com/rox/cartridge/SnapshotArrays::requireSameSize → KILLED
        SnapshotArrays.requireSameSize(axrom.prgRam(), null, "PRG-RAM");
116 1 1. checkRestorable : removed call to com/rox/cartridge/ChrMemory::checkRestorable → KILLED
        chr.checkRestorable(axrom.chrRam());
117
    }
118
119
    @Override
120
    public void restore(final MapperSnapshot snapshot){
121 1 1. restore : removed call to com/rox/cartridge/AxromMapper::checkRestorable → KILLED
        checkRestorable(snapshot);
122
        final AxromMapperSnapshot axrom = (AxromMapperSnapshot) snapshot;
123 1 1. restore : removed call to com/rox/cartridge/ChrMemory::restore → KILLED
        chr.restore(axrom.chrRam());
124
        bankSelect = axrom.bankSelect();
125
    }
126
}

Mutations

43

1.1
Location : <init>
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:restoringPrgRamAcceptsOnlyNone()]
Replaced integer modulus with multiplication → KILLED

2.2
Location : <init>
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[test-template:rejectsPrgRomThatIsntWhole32KbBanks(int)]/[test-template-invocation:#3]
negated conditional → KILLED

3.3
Location : <init>
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[test-template:rejectsPrgRomThatIsntWhole32KbBanks(int)]/[test-template-invocation:#1]
negated conditional → KILLED

46

1.1
Location : <init>
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
Replaced integer division with multiplication → KILLED

53

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

2.2
Location : read
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
negated conditional → KILLED

56

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

2.2
Location : read
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
replaced int return with 0 for com/rox/cartridge/AxromMapper::read → KILLED

3.3
Location : read
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
Replaced integer subtraction with addition → KILLED

4.4
Location : read
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
Replaced integer multiplication with division → KILLED

5.5
Location : read
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[test-template:bitsZeroToTwoSelectThe32KbBank(int, java.lang.String)]/[test-template-invocation:#4]
Replaced integer addition with subtraction → KILLED

62

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

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

63

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

69

1.1
Location : prgBank
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
replaced int return with 0 for com/rox/cartridge/AxromMapper::prgBank → KILLED

2.2
Location : prgBank
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
Replaced bitwise AND with OR → KILLED

3.3
Location : prgBank
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:aBankPastTheEndOfASmallerRomWraps()]
Replaced integer modulus with multiplication → KILLED

74

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

2.2
Location : readChr
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:chrRamReadsBackWhatWasWrittenAcross8Kb()]
replaced int return with 0 for com/rox/cartridge/AxromMapper::readChr → KILLED

80

1.1
Location : writeChr
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:chrRamReadsBackWhatWasWrittenAcross8Kb()]
removed call to com/rox/cartridge/ChrMemory::write → KILLED

2.2
Location : writeChr
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:chrRamReadsBackWhatWasWrittenAcross8Kb()]
Replaced bitwise AND with OR → KILLED

85

1.1
Location : nametableMirroring
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:bit4PicksWhichNametablePageAllFourUse()]
replaced return value with null for com/rox/cartridge/AxromMapper::nametableMirroring → KILLED

2.2
Location : nametableMirroring
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:bit4PicksWhichNametablePageAllFourUse()]
negated conditional → KILLED

3.3
Location : nametableMirroring
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:bit4PicksWhichNametablePageAllFourUse()]
Replaced bitwise AND with OR → KILLED

91

1.1
Location : prgRam
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:thereIsNoPrgRam()]
replaced return value with null for com/rox/cartridge/AxromMapper::prgRam → KILLED

96

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

104

1.1
Location : debugState
Killed by : com.rox.cartridge.AxromMapperTest.[engine:junit-jupiter]/[class:com.rox.cartridge.AxromMapperTest]/[method:debugStateShowsTheRegisterAndTheBankItSelects()]
replaced return value with Collections.emptyMap for com/rox/cartridge/AxromMapper::debugState → KILLED

109

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

115

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

116

1.1
Location : checkRestorable
Killed by : com.rox.cartridge.MapperSnapshotTest.[engine:junit-jupiter]/[class:com.rox.cartridge.MapperSnapshotTest]/[test-template:checkRestorableRejectsWhicheverArrayIsWrong(java.lang.String, java.lang.String)]/[test-template-invocation:#8]
removed call to com/rox/cartridge/ChrMemory::checkRestorable → KILLED

121

1.1
Location : restore
Killed by : com.rox.cartridge.MapperSnapshotTest.[engine:junit-jupiter]/[class:com.rox.cartridge.MapperSnapshotTest]/[method:axromRejectsASnapshotClaimingPrgRam()]
removed call to com/rox/cartridge/AxromMapper::checkRestorable → KILLED

123

1.1
Location : restore
Killed by : com.rox.cartridge.MapperSnapshotTest.[engine:junit-jupiter]/[class:com.rox.cartridge.MapperSnapshotTest]/[method:axromRoundTripsItsRegisterAndChrRam()]
removed call to com/rox/cartridge/ChrMemory::restore → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1