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

@@ -16,8 +16,8 @@ class Switch{
}

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)
throw new RangeError("Bank handling maximum memory modules.");
if (this.__mem.length > 0 && mem.size !== this.__mem[0].size)
@@ -131,7 +131,7 @@ class MMC extends IMem{
if (addroff < 0 || addroff === this.size){
this.__switches.push(new Switch(mem));
} else {
offset = 0;
let offset = 0;
for (let s=0; s < this.__switches.length; s++){
if (addroff === offset){
if (this.__switches[s].mem.size !== mem.size)
@@ -148,15 +148,16 @@ class MMC extends IMem{
}
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;

Loading…
Cancel
Save