From 6e2d4b07fdc11b99b13374946b5cca7814782b51 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Fri, 27 Apr 2012 15:24:15 -0700 Subject: [PATCH] Updated to spec 1.7 --- lib/HMD2043.js | 9 ++++++--- lib/cpu.js | 53 +++++++++++++++++++++++++++----------------------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/lib/HMD2043.js b/lib/HMD2043.js index b8ef651..40b1d38 100644 --- a/lib/HMD2043.js +++ b/lib/HMD2043.js @@ -69,6 +69,7 @@ HMD2043.prototype.onInterrupt = function(callback) { this.errored = false; + var call = true; if(!this.busy) { switch(this.cpu.mem.a) { @@ -133,12 +134,14 @@ // READ_SECTORS case 0x10: accessDisk.call(this, true, callback); - return; + call = false; + break; // WRITE_SECTORS case 0x11: accessDisk.call(this, false, callback); - return; + call = false; + break; // QUERY_MEDIA_QUALITY case 0xffff: @@ -151,7 +154,7 @@ }; if(!this.errored) this.error('NONE'); - callback(); + if(call) callback(); }; function accessDisk(read, callback) { diff --git a/lib/cpu.js b/lib/cpu.js index 95c6729..0f00bfb 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -43,9 +43,9 @@ var opcodes = [ {id: 'AND', code: 0x0a, cost: 1, args: 2}, {id: 'BOR', code: 0x0b, cost: 1, args: 2}, {id: 'XOR', code: 0x0c, cost: 1, args: 2}, - {id: 'SHR', code: 0x0d, cost: 2, args: 2}, - {id: 'ASR', code: 0x0e, cost: 2, args: 2}, - {id: 'SHL', code: 0x0f, cost: 2, args: 2}, + {id: 'SHR', code: 0x0d, cost: 1, args: 2}, + {id: 'ASR', code: 0x0e, cost: 1, args: 2}, + {id: 'SHL', code: 0x0f, cost: 1, args: 2}, {id: 'IFB', code: 0x10, cost: 2, args: 2}, {id: 'IFC', code: 0x11, cost: 2, args: 2}, {id: 'IFE', code: 0x12, cost: 2, args: 2}, @@ -65,11 +65,11 @@ var opcodes = [ {id: 'JSR', code: 0x20, cost: 3, args: 1}, {id: 'BRK', code: 0x40, cost: 0, args: 0}, - {id: 'HCF', code: 0xe0, cost: 9, args: 1}, + {id: 'HCF', code: 0xe0, cost: 9, args: 0}, {id: 'INT', code: 0x100, cost: 4, args: 1}, {id: 'IAG', code: 0x120, cost: 1, args: 1}, {id: 'IAS', code: 0x140, cost: 1, args: 1}, - {id: 'IAP', code: 0x160, cost: 3, args: 1}, + {id: 'RFI', code: 0x160, cost: 3, args: 0}, {id: 'IAQ', code: 0x180, cost: 2, args: 1}, {id: 'HWN', code: 0x200, cost: 2, args: 1}, @@ -235,7 +235,6 @@ CPU.prototype = { } else if(key === 'pop') { key = this.get('sp'); this.set('sp', (key + 1) & this.maxValue); - } value &= this.maxValue; @@ -266,10 +265,7 @@ CPU.prototype = { step: function() { if(!this.paused) { if(this._triggerInterrupts && this._interruptQueue.length > 0) { - this.set('push', this.mem.pc); - this.set('push', this.mem.a); - this.set('pc', this.mem.ia); - this.set('a', this._interruptQueue.shift()); + this.trigger(this._interruptQueue.shift()); } var insn, aVal, bVal, result; @@ -518,13 +514,11 @@ CPU.prototype = { this.set('ia', aVal); break; - // IAP + // RFI case 0x160: - var ia = this.get('ia'); - if(ia) { - this.set('push', ia); - this.set('ia', aVal); - } + this._triggerInterrupts = true; + this.set('a', this.get('pop')); + this.set('pc', this.get('pop')); break; // IAQ @@ -645,17 +639,28 @@ CPU.prototype = { this._devices.push(device); }, interrupt: function(message) { - this.cycle += 2; + this.cycle += 4; - if(this.mem.ia !== 0) { - this._interruptQueue.push(message); - } - - if(this._interruptQueue.length > 256) { - this.stop(); - this.end(); + if(!this.triggerInterrupts) { + this._interruptQueue.push(message); + + if(this._interruptQueue.length > 256) { + this.stop(); + this.end(); + } + } else { + if(this.mem.ia !== 0) { + this.trigger(message); + } } }, + trigger: function(message) { + this._triggerInterrupts = false; + this.set('push', this.mem.pc); + this.set('push', this.mem.a); + this.set('pc', this.mem.ia); + this.set('a', message); + }, end: function() { for(var i = 0; i < this._endListeners.length; i++) { this._endListeners[i]();