broken-neees
Version:
A really broken NEEES emulator that introduces glitches and random bugs on purpose!
33 lines (32 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _byte = _interopRequireDefault(require("../lib/byte"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const PATTERN_TABLE_SIZE = 0x1000;
const TILE_SIZE_PIXELS = 8;
const TILE_TOTAL_BYTES = 16;
class Tile {
constructor(ppu, patternTableId, tileId, y) {
const startAddress = patternTableId * PATTERN_TABLE_SIZE;
let firstPlane;
if (ppu.cpu.unbroken) {
firstPlane = tileId * TILE_TOTAL_BYTES;
} else {
// [!!!]
firstPlane = (tileId + (Math.random() < 0.01 ? 1 : 0)) * TILE_TOTAL_BYTES;
}
const secondPlane = firstPlane + TILE_TOTAL_BYTES / 2;
this._lowRow = ppu.memory.read(startAddress + firstPlane + y);
this._highRow = ppu.memory.read(startAddress + secondPlane + y);
}
getColorIndex(x) {
const bitNumber = TILE_SIZE_PIXELS - 1 - x;
const lowBit = _byte.default.getBit(this._lowRow, bitNumber);
const highBit = _byte.default.getBit(this._highRow, bitNumber);
return _byte.default.buildU2(highBit, lowBit);
}
}
exports.default = Tile;