浏览代码

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

master
Bryan Miller 5 年前
父节点
当前提交
dda1c22cc6
共有 1 个文件被更改,包括 13 次插入12 次删除
  1. +13
    -12
      src/memory/mmc.js

+ 13
- 12
src/memory/mmc.js 查看文件

@@ -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;

正在加载...
取消
保存