UNPKG

broken-neees

Version:

A really broken NEEES emulator that introduces glitches and random bugs on purpose!

48 lines (45 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _Mapper = _interopRequireDefault(require("../lib/Mapper")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * The simplest mapper (also called "Mapper 0"). * It can have either one or two PRG ROM of 16KB, which are mapped * at ranges $8000-$BFFF and $C000-$FFFF of the CPU memory. * It also has CHR ROM which contains the tile and sprite data. * This CHR ROM is mapped to the PPU memory at addresses $0000-$1FFF. */ class NROM extends _Mapper.default { cpuRead(address) { if (address >= 0x4020 && address <= 0x7fff) { // Unused return 0; } else if (address >= 0x8000 && address <= 0xbfff) { // CPU $8000-$BFFF: First 16 KB of PRG-ROM return this.$getPrgPage(0)[address - 0x8000]; } else if (address >= 0xc000 && address <= 0xffff) { // CPU $C000-$FFFF: Last 16 KB of PRG-ROM (or mirror of $8000-$BFFF) return this.$getPrgPage(1)[address - 0xc000]; } } cpuWrite() { // Unused } ppuRead(address) { // PPU $0000-$1FFF: 8 KB of CHR-ROM (or CHR-RAM) return this.$getChrPage(0)[address]; } ppuWrite(address, value) { if (!this.cartridge.header.usesChrRam) { return; // (only CHR-RAM is writable) } // [!!!] if (this.cartridge.isBroken) address += 3; // PPU $0000-$1FFF: 8 KB of CHR-RAM this.$getChrPage(0)[address] = value; } } exports.default = NROM;