UNPKG

nes-emu

Version:

A NES emulator

46 lines (45 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getIndirectAddress = exports.default = void 0; var _helpers = require("../../helpers"); var _getValue = _interopRequireDefault(require("./_getValue")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * "Indirect" addressing mode. * * The parameter is an absolute memory address to look up another address. * The byte read from memory gives the least significant byte of the final * address, and the following byte gives the most significant byte. * * This addressing mode has a bug: * If `address` falls on a page boundary ($xxFF), it fetches the least significant byte from * $xxFF as expected, but takes the most significant byte from $xx00. */ var _default = exports.default = { id: "INDIRECT", parameterSize: 2, getAddress: (_ref, address) => { let { cpu } = _ref; const msb = _helpers.Byte.highPartOf(address); const lsb = _helpers.Byte.lowPartOf(address); const low = cpu.memory.readAt(address); const high = cpu.memory.readAt(lsb === 0xff ? _helpers.Byte.to16Bit(msb, 0x00) : address + 1); return _helpers.Byte.to16Bit(high, low); }, getValue: _getValue.default }; const getIndirectAddress = (_ref2, address) => { let { cpu } = _ref2; const start = _helpers.Byte.force8Bit(address); const end = _helpers.Byte.force8Bit(start + 1); const low = cpu.memory.readAt(start); const high = cpu.memory.readAt(end); return _helpers.Byte.to16Bit(high, low); }; exports.getIndirectAddress = getIndirectAddress;