|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Emulate a basic 6502 (MOS) chip. |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
var Memory = require('src/memory'); |
|
|
|
|
|
|
|
|
|
|
|
class MOS6502{ |
|
|
|
|
|
constructor(){ |
|
|
|
|
|
// Registers |
|
|
|
|
|
this.__PC = 0; // Program Counter (16 bit) |
|
|
|
|
|
this.__IRQ = 0; // IRQ interrupt address code (16 bit) |
|
|
|
|
|
this.__SR = 0; // Status Register (8 bit) |
|
|
|
|
|
this.__XR = 0; // X Register (8 bit) |
|
|
|
|
|
this.__YR = 0; // Y Register (8 bit) |
|
|
|
|
|
this.__AR = 0; // Accumulator Register (8 bit) |
|
|
|
|
|
|
|
|
|
|
|
// Variables to watch for Interrupts. |
|
|
|
|
|
this.__nmi = false; |
|
|
|
|
|
this.__irq = false; |
|
|
|
|
|
|
|
|
|
|
|
// Memory module or controller. |
|
|
|
|
|
this.__mem = null; // Must be explicitly attached. |
|
|
|
|
|
|
|
|
|
|
|
// Hold any created CLK instances. |
|
|
|
|
|
this.__clkfn = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
set NMI(n){ |
|
|
|
|
|
this.__nmi = (n === true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
set IRQ(q){ |
|
|
|
|
|
// TODO: Verify this. |
|
|
|
|
|
// TODO: Do not set if the interrupt flag is off. |
|
|
|
|
|
this.__irq = (q === true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CLK(){ |
|
|
|
|
|
if (this.__clkfn === null){ |
|
|
|
|
|
this.__clkfn = (function(){ |
|
|
|
|
|
// TODO: All the work!! |
|
|
|
|
|
}).bind(this); |
|
|
|
|
|
} |
|
|
|
|
|
return this.__clkfn; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Memory(mem){ |
|
|
|
|
|
if (!(mem instanceof Memory)) |
|
|
|
|
|
throw new ValueError("Expected Memory instance object."); |
|
|
|
|
|
this.__mem = mem; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = MOS6502; |