Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move writing a character into a user-provided callback.

  • Loading branch information...
commit 387aa78d554345400dc13f42086eb8852758d46e 1 parent f0d7893
@nelhage authored
Showing with 11 additions and 2 deletions.
  1. +5 −1 CPU.js
  2. +6 −1 main.js
View
6 CPU.js
@@ -92,7 +92,8 @@ function callout(op) {
CPU.halt = true;
break;
case CALL_WRCHR:
- process.stdout.write(String.fromCharCode(CPU.regs[op.ra]));
+ if (CPU.config.write)
+ CPU.config.write(CPU.regs[op.ra]);
break;
}
} else {
@@ -161,6 +162,7 @@ var CPU = {
halt: false,
pending_interrupts: 0,
callback: null,
+ config: null,
clock: null,
decode: function(op) {
@@ -181,6 +183,7 @@ var CPU = {
CPU.halt = false;
CPU.pending_interrupts = 0;
CPU.callback = null;
+ CPU.config = {};
CPU.clock = null;
},
@@ -227,6 +230,7 @@ var CPU = {
} else {
cb = arguments[0];
}
+ CPU.config = options;
CPU.callback = cb;
if (options.timer) {
CPU.clock = setInterval(
View
7 main.js
@@ -33,6 +33,10 @@ function norm(x) {
return x >= 0 ? x : x + 0x100000000;
}
+function writeChar(ch) {
+ process.stdout.write(String.fromCharCode(ch));
+}
+
if (process.argv.length < 3){
console.log("Usage: " + process.argv[0] + " file.bin");
} else {
@@ -42,7 +46,8 @@ if (process.argv.length < 3){
if (e) throw e;
MMU.load(rom);
CPU.reset();
- CPU.run({timer: true},
+ CPU.run({timer: true,
+ write: writeChar},
function () {
console.log(sprintf.sprintf("[%08x] Done", norm(CPU.PC)));
for (var i = 0; i < 32; i++) {
Please sign in to comment.
Something went wrong with that request. Please try again.