TileDecoder.java

1
package com.rox.ppu.debug;
2
3
import com.rox.cartridge.Cartridge;
4
5
/**
6
 * Decodes a raw 16-byte NES CHR tile into an 8x8 grid of 2-bit pixel values (0-3): bytes 0-7 are
7
 * bit-plane 0 (one byte per row), bytes 8-15 are bit-plane 1 - column 0 is each row byte's MSB, not
8
 * its LSB. Pure decode logic only, no colour - callers (e.g. the debug viewer) decide how a 0-3 value
9
 * maps to a displayed shade/colour.
10
 */
11
public final class TileDecoder {
12
    public static final int TILE_BYTES = 16;
13
    private static final int TILE_SIZE = 8;
14
    private static final int BITPLANE_SIZE = 8;
15
16
    private TileDecoder(){
17
    }
18
19
    /**
20
     * @param tileBytes the tile's raw 16 CHR bytes
21
     * @return an 8x8 grid, {@code pixels[row][col]}, each value 0-3
22
     */
23
    public static int[][] decode(final int[] tileBytes){
24
        final int[][] pixels = new int[TILE_SIZE][TILE_SIZE];
25 2 1. decode : negated conditional → KILLED
2. decode : changed conditional boundary → KILLED
        for (int row = 0; row < TILE_SIZE; row++){
26
            final int lowPlaneByte = tileBytes[row];
27 1 1. decode : Replaced integer addition with subtraction → KILLED
            final int highPlaneByte = tileBytes[BITPLANE_SIZE + row];
28 2 1. decode : changed conditional boundary → KILLED
2. decode : negated conditional → KILLED
            for (int col = 0; col < TILE_SIZE; col++){
29 1 1. decode : Replaced integer subtraction with addition → KILLED
                final int bitShift = TILE_SIZE - 1 - col;
30 2 1. decode : Replaced bitwise AND with OR → KILLED
2. decode : Replaced Shift Right with Shift Left → KILLED
                final int lowBit = (lowPlaneByte >> bitShift) & 1;
31 2 1. decode : Replaced bitwise AND with OR → KILLED
2. decode : Replaced Shift Right with Shift Left → KILLED
                final int highBit = (highPlaneByte >> bitShift) & 1;
32 2 1. decode : Replaced bitwise OR with AND → KILLED
2. decode : Replaced Shift Left with Shift Right → KILLED
                pixels[row][col] = lowBit | (highBit << 1);
33
            }
34
        }
35 1 1. decode : replaced return value with null for com/rox/ppu/debug/TileDecoder::decode → KILLED
        return pixels;
36
    }
37
38
    /**
39
     * @param cartridge from which to extract the tile
40
     * @param tileBase from which to extract the tile
41
     * @return the 2D array of pixels for this tile
42
     */
43
    static int[][] decode(final Cartridge cartridge,
44
                          final int tileBase){
45
        final int[] tileBytes = new int[TILE_BYTES];
46 2 1. decode : changed conditional boundary → KILLED
2. decode : negated conditional → KILLED
        for (int i = 0; i < TILE_BYTES; i++){
47 1 1. decode : Replaced integer addition with subtraction → KILLED
            tileBytes[i] = cartridge.readChr(tileBase + i);
48
        }
49 1 1. decode : replaced return value with null for com/rox/ppu/debug/TileDecoder::decode → KILLED
        return decode(tileBytes);
50
    }
51
52
    /**
53
     * @param cartridge from which to extract the tile
54
     * @param patternTableBase from which to extract the tile
55
     * @param tileIndex to extract
56
     * @return the 2D array of pixels for this tile
57
     */
58
    public static int[][] decode(final Cartridge cartridge,
59
                                 final int patternTableBase,
60
                                 final int tileIndex){
61 2 1. decode : Replaced integer multiplication with division → KILLED
2. decode : Replaced integer addition with subtraction → KILLED
        final int tileBase = patternTableBase + tileIndex * TILE_BYTES;
62 1 1. decode : replaced return value with null for com/rox/ppu/debug/TileDecoder::decode → KILLED
        return decode(cartridge, tileBase);
63
    }
64
}

Mutations

25

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
negated conditional → KILLED

2.2
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
changed conditional boundary → KILLED

27

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:eachRowIsDecodedIndependentlyFromItsOwnBytesNotTransposed()]
Replaced integer addition with subtraction → KILLED

28

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
changed conditional boundary → KILLED

2.2
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
negated conditional → KILLED

29

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
Replaced integer subtraction with addition → KILLED

30

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
Replaced bitwise AND with OR → KILLED

2.2
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
Replaced Shift Right with Shift Left → KILLED

31

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
Replaced bitwise AND with OR → KILLED

2.2
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:eachRowIsDecodedIndependentlyFromItsOwnBytesNotTransposed()]
Replaced Shift Right with Shift Left → KILLED

32

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
Replaced bitwise OR with AND → KILLED

2.2
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:eachRowIsDecodedIndependentlyFromItsOwnBytesNotTransposed()]
Replaced Shift Left with Shift Right → KILLED

35

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:onlyLowPlaneSetDecodesToAllOnes()]
replaced return value with null for com/rox/ppu/debug/TileDecoder::decode → KILLED

46

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:decodeFromCartridgeReadsExactlySixteenConsecutiveAddressesStartingAtTileBase()]
changed conditional boundary → KILLED

2.2
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:decodeFromCartridgeReadsExactlySixteenConsecutiveAddressesStartingAtTileBase()]
negated conditional → KILLED

47

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:decodeFromCartridgeReadsExactlySixteenConsecutiveAddressesStartingAtTileBase()]
Replaced integer addition with subtraction → KILLED

49

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:decodeFromCartridgeReadsBytesStartingAtTileBase()]
replaced return value with null for com/rox/ppu/debug/TileDecoder::decode → KILLED

61

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:decodeFromPatternTableAndIndexComputesTileBaseAsPatternTablePlusIndexTimesTileBytes()]
Replaced integer multiplication with division → KILLED

2.2
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:decodeFromPatternTableAndIndexComputesTileBaseAsPatternTablePlusIndexTimesTileBytes()]
Replaced integer addition with subtraction → KILLED

62

1.1
Location : decode
Killed by : com.rox.ppu.debug.TileDecoderTest.[engine:junit-jupiter]/[class:com.rox.ppu.debug.TileDecoderTest]/[method:decodeFromPatternTableAndIndexComputesTileBaseAsPatternTablePlusIndexTimesTileBytes()]
replaced return value with null for com/rox/ppu/debug/TileDecoder::decode → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1