Browse Source

Fixed a couple bugs. Removed mmSwitchRegister(). Added switchBank()

master
Bryan Miller 5 years ago
parent
commit
dda1c22cc6
1 changed files with 13 additions and 12 deletions
  1. +13
    -12
      src/memory/mmc.js

+ 13
- 12
src/memory/mmc.js View File

} }


addMemModule(mem){ addMemModule(mem){
if (!(mem instanceof Memory))
throw new ValueError("Only Memory instances can be added to MMC Banks.");
if (!(mem instanceof IMem))
throw new ValueError("Only IMem instances can be added to MMC Banks.");
if (this.__mem.length >= 4) if (this.__mem.length >= 4)
throw new RangeError("Bank handling maximum memory modules."); throw new RangeError("Bank handling maximum memory modules.");
if (this.__mem.length > 0 && mem.size !== this.__mem[0].size) if (this.__mem.length > 0 && mem.size !== this.__mem[0].size)
if (addroff < 0 || addroff === this.size){ if (addroff < 0 || addroff === this.size){
this.__switches.push(new Switch(mem)); this.__switches.push(new Switch(mem));
} else { } else {
offset = 0;
let offset = 0;
for (let s=0; s < this.__switches.length; s++){ for (let s=0; s < this.__switches.length; s++){
if (addroff === offset){ if (addroff === offset){
if (this.__switches[s].mem.size !== mem.size) if (this.__switches[s].mem.size !== mem.size)
} }
return this; return this;
} }
mmSwitchRegister(){
return (function(byte){
let mmcidx = (byte & 0xF0) >> 4;
if (mmcidx < this.__switches.length){
this.__switches[mmcidx].idx = (byte & 0x0F);
}
}).bind(this);
}

switchBank(bank){
// The variable <bank> contains two 4 bit offsets.
// The upper 4 bits is the bank switch offset.
// The lower 4 bits is the bank offset within the switch.
let mmcidx = (bank & 0xF0) >> 4;
if (mmcidx < this.__switches.length){
this.__switches[mmcidx].idx = (bank & 0x0F);
}
}
} }


module.exports = MMC; module.exports = MMC;

Loading…
Cancel
Save