| 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 2.2 3.3 |
|
| 35 |
1.1 |
|
| 40 |
1.1 |
|
| 41 |
1.1 |
|
| 46 |
1.1 2.2 |
|
| 50 |
1.1 |
|
| 55 |
1.1 |
|
| 60 |
1.1 |
|
| 64 |
1.1 |
|
| 69 |
1.1 |