3f40bd31517b95e07e6d6b6a142cd6ff14e8da10
[ScratchNES.git] / src / CPU / branch-maker.js
1 /**
2 * branch-maker.js
3 * look at the name
4 * it makes branches :P
5 */
6
7 var fs = require("fs");
8
9 // flag: [clear, set]
10
11 var branches = {
12 "C": ["BCC", "BCS"],
13 "Z": ["BNE", "BEQ"],
14 "V": ["BVC", "BVS"],
15 "N": ["BPL", "BMI"]
16 };
17
18 function emit(name, flag, value) {
19 var emission = [];
20
21 // header
22 emission.push("BRANCH");
23 emission.push("mapper read PC+1");
24
25 // emission
26 var flagNum = value ? "flag" + flag
27 : "(1 - flag" + flag + ")";
28
29 emission.push(
30 "change PC by " +
31 flagNum +
32 " * (M + 256 * (<M < 128> - 1))"
33 );
34
35 console.log(emission.join("\n"));
36 }
37
38 for(var flag in branches) {
39 emit(branches[flag][0], flag, false);
40 emit(branches[flag][1], flag, true);
41 }
This page took 0.10346 seconds and 3 git commands to generate.