Browse Source

Added pages property to memory. Bringing MMC more inline with IMem interface.

master
Bryan Miller 5 years ago
parent
commit
9d773f6894
3 changed files with 61 additions and 1 deletions
  1. +1
    -0
      src/memory/imem.js
  2. +4
    -0
      src/memory/memory.js
  3. +56
    -1
      src/memory/mmc.js

+ 1
- 0
src/memory/imem.js View File

class IMem{ class IMem{
constructor(){} constructor(){}


get pages(){return 0;}
get size(){return 0;} get size(){return 0;}
get writable(){return false;} get writable(){return false;}



+ 4
- 0
src/memory/memory.js View File

this.__rlisteners = new Listener(); this.__rlisteners = new Listener();
} }


get pages(){return this.__map.length / 256;}
get size(){return this.__map.length;} get size(){return this.__map.length;}


get address(){return this.__addr;} get address(){return this.__addr;}
this.__wlisteners = new Listener(); this.__wlisteners = new Listener();
} }


get pages(){return this.__map.length/256;}
get size(){return this.__map.length;} get size(){return this.__map.length;}
get writable(){return true;} get writable(){return true;}


this.__wlisteners = new Listener(); this.__wlisteners = new Listener();
} }


get pages(){return this.__size/256;}
get size(){return this.__size;} get size(){return this.__size;}
get registers(){return this.__map.length;}
get writable(){return true;} get writable(){return true;}


get address(){return this.__addr;} get address(){return this.__addr;}

+ 56
- 1
src/memory/mmc.js View File

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){

Loading…
Cancel
Save