UNPKG

flashmagic.js

Version:
62 lines (61 loc) 2.21 kB
"use strict"; var Symbol = require('es6-symbol'); var Utilities = require('./Utilities'); var _addressSym = Symbol(); var _sectorSym = Symbol(); var ROMAddress = (function () { function ROMAddress(addr, sect) { addr = ~~addr; sect = ~~sect; if (addr & 3) { throw new RangeError("ROM address 0x" + addr.toString(16) + " must be aligned"); } if (addr < ROMAddress.BASE || addr >= ROMAddress.BASE + ROMAddress.SIZE) { throw new RangeError("ROM address 0x" + addr.toString(16) + " out of range"); } if (sect < 0 || sect > Utilities.MAX_SECTOR) { throw new RangeError("ROM sector " + sect + " out of range"); } if (Utilities.addressToSector(addr) !== sect) { throw new RangeError("ROM address 0x" + addr.toString(16) + " / sector " + sect + " mismatch"); } this[_addressSym] = addr; this[_sectorSym] = sect; } Object.defineProperty(ROMAddress, "BASE", { get: function () { return 0; }, enumerable: true, configurable: true }); Object.defineProperty(ROMAddress, "SIZE", { get: function () { return Utilities.MAX_ROM_ADDRESS + 1; }, enumerable: true, configurable: true }); Object.defineProperty(ROMAddress.prototype, "address", { get: function () { return this[_addressSym]; }, enumerable: true, configurable: true }); Object.defineProperty(ROMAddress.prototype, "sector", { get: function () { return this[_sectorSym]; }, enumerable: true, configurable: true }); ROMAddress.prototype.increment = function (diff) { return ROMAddress.fromAddress(this[_addressSym] + diff); }; ROMAddress.prototype.valueOf = function () { return this.address; }; ROMAddress.fromAddress = function (addr) { var sect = Utilities.addressToSector(addr); return new ROMAddress(addr, sect); }; ROMAddress.fromSector = function (sect) { var addr = Utilities.sectorToAddress(sect); return new ROMAddress(addr, sect); }; return ROMAddress; }()); exports.ROMAddress = ROMAddress;