Program: 3214
Project: 3214
Buggy source:
/** 
 * Loads and outputs the current pixel and increments x to move to the next pixel in the scanline.
 */
public void loadPixel(){
  int index=0;
  int pixelX=x % tileWidth;
  if ((tile & 0x4000) != 0) {
    pixelX=tileWidth - pixelX - 1;
  }
  int xMask=0x80 >> (pixelX % 8);
switch (colorMode) {
case Color4:
    index|=((PPU.vram[characterAddr] & xMask) != 0) ? 0x1 : 0;
  index|=((PPU.vram[characterAddr + 1] & xMask) != 0) ? 0x2 : 0;
break;
case Color16:
index|=((PPU.vram[characterAddr] & xMask) != 0) ? 0x1 : 0;
index|=((PPU.vram[characterAddr + 1] & xMask) != 0) ? 0x2 : 0;
index|=((PPU.vram[characterAddr + 16] & xMask) != 0) ? 0x4 : 0;
index|=((PPU.vram[characterAddr + 17] & xMask) != 0) ? 0x8 : 0;
break;
case Color256:
index|=((PPU.vram[characterAddr] & xMask) != 0) ? 0x1 : 0;
index|=((PPU.vram[characterAddr + 1] & xMask) != 0) ? 0x2 : 0;
index|=((PPU.vram[characterAddr + 16] & xMask) != 0) ? 0x4 : 0;
index|=((PPU.vram[characterAddr + 17] & xMask) != 0) ? 0x8 : 0;
index|=((PPU.vram[characterAddr + 32] & xMask) != 0) ? 0x10 : 0;
index|=((PPU.vram[characterAddr + 33] & xMask) != 0) ? 0x20 : 0;
index|=((PPU.vram[characterAddr + 48] & xMask) != 0) ? 0x40 : 0;
index|=((PPU.vram[characterAddr + 49] & xMask) != 0) ? 0x80 : 0;
break;
}
if (mainScreen) {
if (index == 0) {
outMainPriority=0;
}
 else {
outMainPriority=curPriority;
outMainPixel=index + tilePaletteOffset;
}
}
if (subScreen) {
if (index == 0) {
outSubPriority=0;
}
 else {
outSubPriority=curPriority;
outSubPixel=index + tilePaletteOffset;
}
}
x=(x + 1) % (size.width * tileWidth);
if (((x % 8) == 0 && !tile16px) || (x % 16) == 0) {
loadTile();
}
 else if ((x % 16) == 8 && tile16px) {
characterAddr+=8 * colorMode.bitDepth;
}
}

Fixed version (ground truth):
/** 
 * Loads and outputs the current pixel and increments x to move to the next pixel in the scanline.
 */
public int loadPixel(){
  int index=0;
  int pixelX=x % tileWidth;
  if ((tile & 0x4000) != 0) {
    pixelX=tileWidth - pixelX - 1;
  }
  int xMask=0x80 >> (pixelX % 8);
switch (colorMode) {
case Color4:
    index|=((PPU.vram[characterAddr] & xMask) != 0) ? 0x1 : 0;
  index|=((PPU.vram[characterAddr + 1] & xMask) != 0) ? 0x2 : 0;
break;
case Color16:
index|=((PPU.vram[characterAddr] & xMask) != 0) ? 0x1 : 0;
index|=((PPU.vram[characterAddr + 1] & xMask) != 0) ? 0x2 : 0;
index|=((PPU.vram[characterAddr + 16] & xMask) != 0) ? 0x4 : 0;
index|=((PPU.vram[characterAddr + 17] & xMask) != 0) ? 0x8 : 0;
break;
case Color256:
index|=((PPU.vram[characterAddr] & xMask) != 0) ? 0x1 : 0;
index|=((PPU.vram[characterAddr + 1] & xMask) != 0) ? 0x2 : 0;
index|=((PPU.vram[characterAddr + 16] & xMask) != 0) ? 0x4 : 0;
index|=((PPU.vram[characterAddr + 17] & xMask) != 0) ? 0x8 : 0;
index|=((PPU.vram[characterAddr + 32] & xMask) != 0) ? 0x10 : 0;
index|=((PPU.vram[characterAddr + 33] & xMask) != 0) ? 0x20 : 0;
index|=((PPU.vram[characterAddr + 48] & xMask) != 0) ? 0x40 : 0;
index|=((PPU.vram[characterAddr + 49] & xMask) != 0) ? 0x80 : 0;
break;
}
if (mainScreen) {
if (index == 0) {
outMainPriority=0;
}
 else {
outMainPriority=curPriority;
outMainPixel=index + tilePaletteOffset;
}
}
if (subScreen) {
if (index == 0) {
outSubPriority=0;
}
 else {
outSubPriority=curPriority;
outSubPixel=index + tilePaletteOffset;
}
}
x=(x + 1) % (size.width * tileWidth);
if (((x % 8) == 0 && !tile16px) || (x % 16) == 0) {
loadTile();
}
 else if ((x % 16) == 8 && tile16px) {
characterAddr+=8 * colorMode.bitDepth;
}
return (index == 0 ? 0 : index + tilePaletteOffset);
}