|
|
|
|
|
|
|
|
this.__sidx = 0; |
|
|
this.__sidx = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get pages(){ |
|
|
|
|
|
return this.__switches.reduce((acc, s)=>{ |
|
|
|
|
|
return acc + s.mem.pages; |
|
|
|
|
|
}, 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
get size(){ |
|
|
get size(){ |
|
|
return this.__switches.reduce((acc, s)=>{ |
|
|
return this.__switches.reduce((acc, s)=>{ |
|
|
acc += s.mem.size; |
|
|
|
|
|
|
|
|
return acc + s.mem.size; |
|
|
}, 0); |
|
|
}, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get writable(){ |
|
|
|
|
|
let iw = false; |
|
|
|
|
|
for (let i=0; i < this.__switches.length; i++){ |
|
|
|
|
|
if (this.__switches[i].mem.writable){ |
|
|
|
|
|
iw = true; break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return iw; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
get switches(){return this.__switches.length;} |
|
|
get switches(){return this.__switches.length;} |
|
|
|
|
|
|
|
|
get address(){return this.__addr;} |
|
|
get address(){return this.__addr;} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
load(addr, data){ |
|
|
|
|
|
if (addr < 0 || addr > this.size) |
|
|
|
|
|
throw new RangeError("Memory address out of range."); |
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
data = data.slice(mem.size); |
|
|
|
|
|
offset += mem.size; |
|
|
|
|
|
if (d.length > 0) |
|
|
|
|
|
addr = offset; |
|
|
|
|
|
} |
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clearPage(paddr){ |
|
|
|
|
|
for (let i=0; i < this.__switches.length; i++){ |
|
|
|
|
|
let pgs = this.__switches[i].mem.pages; |
|
|
|
|
|
if (paddr < pgs){ |
|
|
|
|
|
this.__switches[i].mem.clearPage(addr); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
paddr -= pgs; |
|
|
|
|
|
} |
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clear(){ |
|
|
|
|
|
this.__switches.forEach((s)=>{ |
|
|
|
|
|
s.clear(); |
|
|
|
|
|
}); |
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
connectMemory(mem, addroff){ |
|
|
connectMemory(mem, addroff){ |
|
|
addroff = (typeof(addroff) === 'number' && addroff >= 0) ? addroff : -1; |
|
|
addroff = (typeof(addroff) === 'number' && addroff >= 0) ? addroff : -1; |
|
|
if (addroff < 0 || addroff === this.size){ |
|
|
if (addroff < 0 || addroff === this.size){ |