Skip to content

Commit

Permalink
Updated to spec 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Bell committed Apr 27, 2012
1 parent 2f17fac commit 6e2d4b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
9 changes: 6 additions & 3 deletions lib/HMD2043.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

HMD2043.prototype.onInterrupt = function(callback) {
this.errored = false;
var call = true;

if(!this.busy) {
switch(this.cpu.mem.a) {
Expand Down Expand Up @@ -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:
Expand All @@ -151,7 +154,7 @@
};

if(!this.errored) this.error('NONE');
callback();
if(call) callback();
};

function accessDisk(read, callback) {
Expand Down
53 changes: 29 additions & 24 deletions lib/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -235,7 +235,6 @@ CPU.prototype = {
} else if(key === 'pop') {
key = this.get('sp');
this.set('sp', (key + 1) & this.maxValue);

}
value &= this.maxValue;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]();
Expand Down

0 comments on commit 6e2d4b0

Please sign in to comment.