nes-emu
Version:
A NES emulator
30 lines (28 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _constants = _interopRequireDefault(require("../../../constants"));
var _helpers = require("../../../helpers");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* An area of memory which defines a background. It's located at $2000 (VRAM).
* A background is made up of a grid of tiles, each tile being 8x8 pixels.
* A frame is 256x240 pixels or 32x30 tiles.
* Each byte represents a tile (they're indexes into the Pattern table).
*/
class NameTable {
constructor() {
_helpers.WithContext.apply(this);
}
/** Returns a tile index to the background Pattern table that contains (`x`, `y`). */
getTileIdOf(nameTableId, x, y) {
const startAddress = _constants.default.NAME_TABLES_START_ADDRESS + nameTableId * _constants.default.NAME_TABLE_SIZE;
const tileX = Math.floor(x / _constants.default.TILE_LENGTH);
const tileY = Math.floor(y / _constants.default.TILE_LENGTH);
const tileIndex = tileY * _constants.default.NAME_TABLE_TOTAL_TILES_X + tileX;
return this.context.ppu.memory.readAt(startAddress + tileIndex);
}
}
exports.default = NameTable;