var Memory = require('chip/memory'); class Bank{ constructor(mem){ this.__mem = [mem]; this.__idx = 0; } get mem(){return this.__mem[this.__idx];} get idx(){return this.__idx;} set idx(i){ if (i >= 0 && i < this.__mem.length) this.__idx = i; } addMemModule(mem){ if (!(mem instanceof Memory)) throw new ValueError("Only Memory 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) throw new RangeError("Memory module does not match size of already connected memory modules on this bank."); this.__mem.push(mem); } } class MMC{ constructor(){ this.__banks = []; } get size(){ return this.__banks.reduce((acc, b)=>{ acc += b.mem.size; }, 0); } get banks(){return this.__banks.length;} // TODO: Add a get/set for the memory address. This should handle banking and memory address offsets. // TODO: Add a get/set for memory data at the current address. // TODO: Add method for adding memory modules} // TODO: Add a connection between a memory address and the triggering of bank switching. } module.exports = MMC;