Build lookup tables
authorAlyssa Rosenzweig <alyssa@backtick.town>
Thu, 23 Jun 2016 21:45:48 +0000 (14:45 -0700)
committerAlyssa Rosenzweig <alyssa@backtick.town>
Thu, 23 Jun 2016 21:45:48 +0000 (14:45 -0700)
src/CPU/Makefile
src/CPU/build-lookups.js [new file with mode: 0644]

index a378384..9cc700c 100644 (file)
@@ -4,6 +4,9 @@ bin/reference.txt: build-reference.sh
 bin/table.json: bin/reference.txt parse-reference.js
        node parse-reference.js bin/reference.txt
 
+bin/EOR.txt:
+       node build-lookups.js
+
 instructions/BCC:
        node branch-maker.js
 
diff --git a/src/CPU/build-lookups.js b/src/CPU/build-lookups.js
new file mode 100644 (file)
index 0000000..6e97e8a
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * build-lookups.js
+ * builds lookup tables for bitwise operations
+ */
+
+var fs = require("fs");
+
+emit("EOR", function(a,b){return a^b});
+emit("ORA", function(a,b){return a|b});
+emit("AND", function(a,b){return a&b});
+
+function emit(name, func) {
+    var emission = [];
+
+    for(var i = 0; i < 256; ++i) {
+        var a = (i & 0xF0) >> 4;
+        var b = (i & 0x0F) >> 0;
+        emission.push(func(a,b));
+    }
+
+    fs.writeFileSync("bin/" + name + ".txt", emission.join("\n"));
+}
This page took 0.0237 seconds and 4 git commands to generate.