class Memory{ constructor(size, ro){ this.__ro = (ro === true); this.__map = null; this.__addr = 0; if (size > 0){ this.__map = new Uint8Array(size); } } get size(){return (this.__map) ? this.__map.length : 0;} get address(){return this.__addr;} set address(a){ if (this.__map) this.__addr = Math.min(this.__map.length, Math.max(0, a)); } get byte(){return (this.__map) ? this.__map[this.__addr] : -1;} set byte(b){ if (!this.__ro && this.__map) this.__map[this.__addr] = b; } sysStore(address, data){ if (this.__map){ let dc = data; if (address < 0 || address >= this.__map.length) throw new RangeError("Memory address out of range."); if (this.__map.length - address < dc.length) dc = dc.slice(0, this.__map.length - address); this.__map.set(address, dc); return dc.length; } } } module.exports = Memory;