UNPKG

nes-emu

Version:

A NES emulator

34 lines (33 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _helpers = require("../helpers"); var _lodash = _interopRequireDefault(require("lodash")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** A mixin for reading bytes in Little Endian. */ var _default = exports.default = { /** Applies the mixin. */ apply(obj) { _lodash.default.defaults(obj, _lodash.default.omit(this, "apply")); }, /** Reads `length` (1 or 2) bytes in LE from `address`. */ readBytesAt(address, length) { if (length === 0) return null; return length === 2 ? this.read2BytesAt(address) : this.readAt(address); }, /** Writes two bytes in LE to `address`. */ write2BytesAt(address, value) { const low = _helpers.Byte.lowPartOf(value); const high = _helpers.Byte.highPartOf(value); this.writeAt(address, low); this.writeAt(address + 1, high); }, /** Reads two bytes in LE from `address`. */ read2BytesAt(address) { const low = this.readAt(address); const high = this.readAt(address + 1); return _helpers.Byte.to16Bit(high, low); } };