| set address(a){ | set address(a){ | ||||
| if (a >= 0 && a < this.size){ | if (a >= 0 && a < this.size){ | ||||
| this.__addr = a; | this.__addr = a; | ||||
| offset = 0; | |||||
| let offset = 0; | |||||
| for (let s=0; s < this.__switches.length; s++){ | for (let s=0; s < this.__switches.length; s++){ | ||||
| if (a >= offset && a < offset + this.__switches[s].mem.size){ | if (a >= offset && a < offset + this.__switches[s].mem.size){ | ||||
| this.__sidx = b; | |||||
| this.__sidx = s; | |||||
| this.__switches[s].mem.address = a - offset; | this.__switches[s].mem.address = a - offset; | ||||
| break; | break; | ||||
| } else { | } else { | ||||
| } | } | ||||
| } | } | ||||
| get byte(){return (this.__switches.length > 0) ? this.__switches[this.__sidx].mem.byte : -1;} | |||||
| get byte(){ | |||||
| return (this.__switches.length > 0) ? this.__switches[this.__sidx].mem.byte : -1; | |||||
| } | |||||
| set byte(b){ | set byte(b){ | ||||
| if (this.__switches.length > 0){ | if (this.__switches.length > 0){ | ||||
| this.__switches[this.__sidx].mem.byte = b; | this.__switches[this.__sidx].mem.byte = b; | ||||
| if (addr < 0 || addr > this.size) | if (addr < 0 || addr > this.size) | ||||
| throw new RangeError("Memory address out of range."); | throw new RangeError("Memory address out of range."); | ||||
| let offset = 0; | let offset = 0; | ||||
| for (let i = 0; i < this.__switches.length; i++){ | |||||
| let mem = this.__switches[i].mem; | |||||
| let od = data; | |||||
| if (addr >= offset && addr < offset + mem.size){ | |||||
| if ((addr - offset) + d.length >= mem.size) | |||||
| od = data.slice(0, mem.size); | |||||
| mem.load(addr - offset, od); | |||||
| let doff = 0; | |||||
| let addre = addr + data.length; | |||||
| for (let s = 0; s < this.__switches.length; s++){ | |||||
| let mem = this.__switches[s].mem; | |||||
| if (addr < offset + mem.size && addre >= offset){ | |||||
| let a = (addr > offset) ? addr - offset : 0; | |||||
| let dlen = (mem.size - a < data.length - doff) ? | |||||
| mem.size - a : data.length - doff; | |||||
| mem.load(a, data.slice(doff, doff + dlen)); | |||||
| doff += dlen; | |||||
| } | } | ||||
| data = data.slice(mem.size); | |||||
| offset += mem.size; | offset += mem.size; | ||||
| if (d.length > 0) | |||||
| addr = offset; | |||||
| } | } | ||||
| return this; | return this; | ||||
| } | } |