Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

49 lines
1.2KB

  1. var Memory = require('chip/memory');
  2. class Bank{
  3. constructor(mem){
  4. this.__mem = [mem];
  5. this.__idx = 0;
  6. }
  7. get mem(){return this.__mem[this.__idx];}
  8. get idx(){return this.__idx;}
  9. set idx(i){
  10. if (i >= 0 && i < this.__mem.length)
  11. this.__idx = i;
  12. }
  13. addMemModule(mem){
  14. if (!(mem instanceof Memory))
  15. throw new ValueError("Only Memory instances can be added to MMC Banks.");
  16. if (this.__mem.length >= 4)
  17. throw new RangeError("Bank handling maximum memory modules.");
  18. if (this.__mem.length > 0 && mem.size !== this.__mem[0].size)
  19. throw new RangeError("Memory module does not match size of already connected memory modules on this bank.");
  20. this.__mem.push(mem);
  21. }
  22. }
  23. class MMC{
  24. constructor(){
  25. this.__banks = [];
  26. }
  27. get size(){
  28. return this.__banks.reduce((acc, b)=>{
  29. acc += b.mem.size;
  30. }, 0);
  31. }
  32. get banks(){return this.__banks.length;}
  33. // TODO: Add a get/set for the memory address. This should handle banking and memory address offsets.
  34. // TODO: Add a get/set for memory data at the current address.
  35. // TODO: Add method for adding memory modules}
  36. // TODO: Add a connection between a memory address and the triggering of bank switching.
  37. }
  38. module.exports = MMC;