nes-emu
Version:
A NES emulator
151 lines (150 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const instructions = () => [
/**
* Branch if Carry Clear
*
* If the C flag is clear, jumps to `address`.
*/
{
id: "BCC",
execute: B__("c", false)
},
/**
* Branch if Carry Set
*
* If the C flag is set, jumps to `address`.
*/
{
id: "BCS",
execute: B__("c", true)
},
/**
* Branch if Equal
*
* If the Z flag is set, jumps to `address`.
*/
{
id: "BEQ",
execute: B__("z", true)
},
/**
* Branch if Minus
*
* If the N flag is set, jumps to `address`.
*/
{
id: "BMI",
execute: B__("n", true)
},
/**
* Branch if Not Equal
*
* If the Z flag is clear, jumps to `address`.
*/
{
id: "BNE",
execute: B__("z", false)
},
/**
* Branch if Positive
*
* If the N flag is clear, jumps to `address`.
*/
{
id: "BPL",
execute: B__("n", false)
},
/**
* Branch if Overflow Clear
*
* If the V flag is clear, jumps to `address`.
*/
{
id: "BVC",
execute: B__("v", false)
},
/**
* Branch if Overflow Set
*
* If the V flag is set, jumps to `address`.
*/
{
id: "BVS",
execute: B__("v", true)
},
/**
* Jump
*
* Jumps to `address`.
*/
{
id: "JMP",
execute: (_ref, address) => {
let {
cpu
} = _ref;
cpu.pc.value = address;
}
},
/**
* Jump to Subroutine
*
* Pushes the current program counter (minus one) on to the stack and jumps to `address`.
*/
{
id: "JSR",
execute: (_ref2, address) => {
let {
cpu
} = _ref2;
cpu.stack.push2Bytes(cpu.pc.value - 1);
cpu.pc.value = address;
}
},
/**
* Return from Interrupt
*
* Pulls the flags from the stack followed by the program counter.
*/
{
id: "RTI",
execute: _ref3 => {
let {
cpu
} = _ref3;
cpu.flags.load(cpu.stack.pop());
cpu.pc.value = cpu.stack.pop2Bytes();
}
},
/**
* Return from Subroutine
*
* Pulls the program counter (plus one) from the stack.
*/
{
id: "RTS",
execute: _ref4 => {
let {
cpu
} = _ref4;
cpu.pc.value = cpu.stack.pop2Bytes() + 1;
}
}];
const B__ = (flag, value) => {
return (_ref5, address) => {
let {
cpu
} = _ref5;
if (cpu.flags[flag] === value) {
cpu.pc.value = address;
cpu.extraCycles++;
} else {
cpu.extraCycles = 0;
}
};
};
var _default = exports.default = instructions();