nes-emu
Version:
A NES emulator
43 lines (40 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _registers = require("../../registers");
var _constants = _interopRequireDefault(require("../../constants"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* PPU Scrolling Position Register (>> write twice, first X then Y)
*
* Changes the scroll position. Used to tell the PPU which pixel of the Name table
* (selected through `PPUCtrl`) should be at the top left corner of the rendered screen.
* Connected to `LoopyRegister`.
*/
class PPUScroll extends _registers.WriteOnlyInMemoryRegister {
/**
* Returns the scrolled X in Name table coordinates ([0..262]).
* If this value overflows (> 255), switch the horizontal Name table.
*/
scrolledX(x) {
const {
vAddress,
fineX
} = this.context.ppu.loopy;
return vAddress.coarseX * _constants.default.TILE_LENGTH + fineX + x % _constants.default.TILE_LENGTH;
}
/** Returns the scrolled X in Name table coordinates ([0..255]). */
scrolledY() {
const {
vAddress
} = this.context.ppu.loopy;
return vAddress.coarseY * _constants.default.TILE_LENGTH + vAddress.fineY;
}
/** Alternately writes the X and the Y coordinates of the scroll. */
writeAt(__, byte) {
this.context.ppu.loopy.onPPUScrollWrite(byte);
}
}
exports.default = PPUScroll;