Fixed some sloppy coding (my bad)
This commit is contained in:
parent
9d045008a3
commit
b5a7525ad2
5 changed files with 449 additions and 329 deletions
|
|
@ -34,9 +34,7 @@
|
|||
"use strict";
|
||||
|
||||
if (NODE) {
|
||||
var str = require("../../shared/lib/strlib");
|
||||
var PDP11 = require("./defines");
|
||||
var MessagesPDP11 = require("./messages");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,6 +67,21 @@ PDP11.fnBIC = function(src, dst)
|
|||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* fnBICB(dst, src)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} src
|
||||
* @param {number} dst
|
||||
* @return {number} (~src & dst)
|
||||
*/
|
||||
PDP11.fnBICB = function(src, dst)
|
||||
{
|
||||
var result = ~src & dst;
|
||||
this.updateNZFlags(result << 8);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* fnBIS(dst, src)
|
||||
*
|
||||
|
|
@ -84,6 +97,21 @@ PDP11.fnBIS = function(src, dst)
|
|||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* fnBISB(dst, src)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} src
|
||||
* @param {number} dst
|
||||
* @return {number} (src | dst)
|
||||
*/
|
||||
PDP11.fnBISB = function(src, dst)
|
||||
{
|
||||
var result = src | dst;
|
||||
this.updateNZFlags(result << 8);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* fnSUB(dst, src)
|
||||
*
|
||||
|
|
@ -99,28 +127,6 @@ PDP11.fnSUB = function(src, dst)
|
|||
return result & 0xffff;
|
||||
};
|
||||
|
||||
/**
|
||||
* op1170(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.op1170 = function(opCode)
|
||||
{
|
||||
PDP11.aOpsF000_1170[opCode >> 12].call(this, opCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* op0XXX_1170(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.op0XXX_1170 = function(opCode)
|
||||
{
|
||||
// PDP11.aOpsF000_1170[opCode >> 12].call(this, opCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* opADD(opCode)
|
||||
*
|
||||
|
|
@ -145,6 +151,18 @@ PDP11.opBIC = function(opCode)
|
|||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opBICB(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.opBICB = function(opCode)
|
||||
{
|
||||
this.updateByteByMode(opCode, this.readByteByMode(opCode >> PDP11.SRCMODE.SHIFT), PDP11.fnBICB);
|
||||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opBIS(opCode)
|
||||
*
|
||||
|
|
@ -157,6 +175,18 @@ PDP11.opBIS = function(opCode)
|
|||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opBISB(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.opBISB = function(opCode)
|
||||
{
|
||||
this.updateByteByMode(opCode, this.readByteByMode(opCode >> PDP11.SRCMODE.SHIFT), PDP11.fnBISB);
|
||||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opBIT(opCode)
|
||||
*
|
||||
|
|
@ -169,6 +199,18 @@ PDP11.opBIT = function(opCode)
|
|||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opBITB(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.opBITB = function(opCode)
|
||||
{
|
||||
this.updateNZFlags((this.readByteByMode(opCode >> PDP11.SRCMODE.SHIFT) & this.readByteByMode(opCode)) << 8);
|
||||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opCMP(opCode)
|
||||
*
|
||||
|
|
@ -188,6 +230,25 @@ PDP11.opCMP = function(opCode)
|
|||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opCMPB(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.opCMPB = function(opCode)
|
||||
{
|
||||
var src = this.readByteByMode(opCode >> PDP11.SRCMODE.SHIFT) << 8;
|
||||
var dst = this.readByteByMode(opCode) << 8;
|
||||
var result = src - dst;
|
||||
/*
|
||||
* NOTE: CMP calculates (src - dst) rather than (dst - src), so when we call updateSubFlags(),
|
||||
* we must reverse the order of the src and dst parameters.
|
||||
*/
|
||||
this.updateSubFlags(result, dst, src);
|
||||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* opMOV(opCode)
|
||||
*
|
||||
|
|
@ -212,7 +273,7 @@ PDP11.opMOVB = function(opCode)
|
|||
/*
|
||||
* When dst is a register, data must be sign-extended; otherwise, sign-extension is unnecessary (but harmless).
|
||||
*/
|
||||
this.updateNZFlags(this.writeByteByMode(opCode, (data & 0x80)? data | 0xff00 : data));
|
||||
this.updateNZFlags(this.writeByteByMode(opCode, (data & 0x80)? data | 0xff00 : data) << 8);
|
||||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
|
|
@ -239,6 +300,28 @@ PDP11.opSUB = function(opCode)
|
|||
this.nStepCycles -= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* op1170(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.op1170 = function(opCode)
|
||||
{
|
||||
PDP11.aOpsF000_1170[opCode >> 12].call(this, opCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* op0XXX_1170(opCode)
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} opCode
|
||||
*/
|
||||
PDP11.op0XXX_1170 = function(opCode)
|
||||
{
|
||||
// PDP11.aOpsF000_1170[opCode >> 12].call(this, opCode);
|
||||
};
|
||||
|
||||
PDP11.aOpsF000_1170 = [
|
||||
PDP11.op0XXX_1170,
|
||||
PDP11.opMOV, // MOV 01SSDD
|
||||
|
|
@ -250,10 +333,10 @@ PDP11.aOpsF000_1170 = [
|
|||
PDP11.opNOP, // 0x7XXX
|
||||
PDP11.opNOP, // 0x8XXX
|
||||
PDP11.opMOVB, // MOVB 11SSDD
|
||||
PDP11.opNOP, // 0xAXXX
|
||||
PDP11.opNOP, // 0xBXXX
|
||||
PDP11.opNOP, // 0xCXXX
|
||||
PDP11.opNOP, // 0xDXXX
|
||||
PDP11.opCMPB, // CMPB 12SSDD
|
||||
PDP11.opBITB, // BITB 13SSDD
|
||||
PDP11.opBICB, // BICB 14SSDD
|
||||
PDP11.opBISB, // BISB 15SSDD
|
||||
PDP11.opSUB, // SUB 16SSDD
|
||||
PDP11.opNOP // 0xFXXX
|
||||
];
|
||||
|
|
|
|||
|
|
@ -639,7 +639,7 @@ CPUStatePDP11.prototype.setPSW = function(newPSW)
|
|||
*/
|
||||
CPUStatePDP11.prototype.updateNZFlags = function(result)
|
||||
{
|
||||
if (!this.opFlags & PDP11.OPFLAG.SKIP_FLAGS) {
|
||||
if (!(this.opFlags & PDP11.OPFLAG.SKIP_FLAGS)) {
|
||||
this.flagN = this.flagZ = result;
|
||||
this.flagV = 0;
|
||||
}
|
||||
|
|
@ -655,7 +655,7 @@ CPUStatePDP11.prototype.updateNZFlags = function(result)
|
|||
*/
|
||||
CPUStatePDP11.prototype.updateAddFlags = function(result, src, dst)
|
||||
{
|
||||
if (!this.opFlags & PDP11.OPFLAG.SKIP_FLAGS) {
|
||||
if (!(this.opFlags & PDP11.OPFLAG.SKIP_FLAGS)) {
|
||||
this.flagN = this.flagZ = this.flagC = result;
|
||||
this.flagV = (src ^ result) & (dst ^ result);
|
||||
}
|
||||
|
|
@ -674,7 +674,7 @@ CPUStatePDP11.prototype.updateAddFlags = function(result, src, dst)
|
|||
*/
|
||||
CPUStatePDP11.prototype.updateSubFlags = function(result, src, dst)
|
||||
{
|
||||
if (!this.opFlags & PDP11.OPFLAG.SKIP_FLAGS) {
|
||||
if (!(this.opFlags & PDP11.OPFLAG.SKIP_FLAGS)) {
|
||||
this.flagN = this.flagZ = this.flagC = result;
|
||||
this.flagV = (src ^ dst) & (dst ^ result);
|
||||
}
|
||||
|
|
@ -1292,6 +1292,33 @@ CPUStatePDP11.prototype.updateWordByMode = function(addressMode, src, fnOp)
|
|||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
* updateByteByMode(addressMode, src, fnOp)
|
||||
*
|
||||
* Used whenever the dst operand (as described by addressMode) DOES need to be read before writing.
|
||||
*
|
||||
* TODO: writeByteByAddr() currently plays it safe and always masks the incoming data. Let's see if we can
|
||||
* change that to an assert(), and make sure we never give writeByteByAddr() unmasked data.
|
||||
*
|
||||
* @this {CPUStatePDP11}
|
||||
* @param {number} addressMode
|
||||
* @param {number} src
|
||||
* @param {function(number,number)} fnOp
|
||||
* @return {number}
|
||||
*/
|
||||
CPUStatePDP11.prototype.updateByteByMode = function(addressMode, src, fnOp)
|
||||
{
|
||||
var data;
|
||||
if (!(addressMode & PDP11.OPMODE.MASK)) {
|
||||
var reg = addressMode & PDP11.OPREG.MASK;
|
||||
this.regsGen[reg] = (data = fnOp.call(this, src, this.regsGen[reg]));
|
||||
} else {
|
||||
var addr = this.getAddrByMode(addressMode, PDP11.ACCESS.UPDATE_BYTE);
|
||||
this.writeByteByAddr(addr, (data = fnOp.call(this, src, this.readByteByAddr(addr))));
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
* writeWordByMode(addressMode, data)
|
||||
*
|
||||
|
|
@ -1622,49 +1649,49 @@ CPUStatePDP11.prototype.stepCPU = function(nMinCycles)
|
|||
// }
|
||||
// }
|
||||
// break;
|
||||
case 0xA000: /*0120000*/ // CMPB 12SSDD
|
||||
//LOG_INSTRUCTION(instruction, 2, "CMPB");
|
||||
if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
if ((dst = this.readByteByMode(instruction)) >= 0) {
|
||||
result = src - dst;
|
||||
this.flagN = this.flagZ = this.flagC = result << 8;
|
||||
this.flagV = ((src ^ dst) & (src ^ result)) << 8;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xB000: /*0130000*/ // BITB 13SSDD
|
||||
//LOG_INSTRUCTION(instruction, 2, "BITB");
|
||||
if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
if ((dst = this.readByteByMode(instruction)) >= 0) {
|
||||
this.flagN = this.flagZ = (src & dst) << 8;
|
||||
this.flagV = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xC000: /*0140000*/ // BICB 14SSDD
|
||||
//LOG_INSTRUCTION(instruction, 2, "BICB");
|
||||
if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
if ((dst = this.readByteByAddr(dstAddr = this.getAddrByMode(instruction, PDP11.ACCESS.UPDATE_BYTE))) >= 0) {
|
||||
result = dst & ~src;
|
||||
if (this.writeByteByAddr(dstAddr, result) >= 0) {
|
||||
this.flagN = this.flagZ = result << 8;
|
||||
this.flagV = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xD000: /*0150000*/ // BISB 15SSDD
|
||||
//LOG_INSTRUCTION(instruction, 2, "BISB");
|
||||
if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
if ((dst = this.readByteByAddr(dstAddr = this.getAddrByMode(instruction, PDP11.ACCESS.UPDATE_BYTE))) >= 0) {
|
||||
result = dst | src;
|
||||
if (this.writeByteByAddr(dstAddr, result) >= 0) {
|
||||
this.flagN = this.flagZ = result << 8;
|
||||
this.flagV = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case 0xA000: /*0120000*/ // CMPB 12SSDD
|
||||
// //LOG_INSTRUCTION(instruction, 2, "CMPB");
|
||||
// if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
// if ((dst = this.readByteByMode(instruction)) >= 0) {
|
||||
// result = src - dst;
|
||||
// this.flagN = this.flagZ = this.flagC = result << 8;
|
||||
// this.flagV = ((src ^ dst) & (src ^ result)) << 8;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case 0xB000: /*0130000*/ // BITB 13SSDD
|
||||
// //LOG_INSTRUCTION(instruction, 2, "BITB");
|
||||
// if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
// if ((dst = this.readByteByMode(instruction)) >= 0) {
|
||||
// this.flagN = this.flagZ = (src & dst) << 8;
|
||||
// this.flagV = 0;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case 0xC000: /*0140000*/ // BICB 14SSDD
|
||||
// //LOG_INSTRUCTION(instruction, 2, "BICB");
|
||||
// if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
// if ((dst = this.readByteByAddr(dstAddr = this.getAddrByMode(instruction, PDP11.ACCESS.UPDATE_BYTE))) >= 0) {
|
||||
// result = dst & ~src;
|
||||
// if (this.writeByteByAddr(dstAddr, result) >= 0) {
|
||||
// this.flagN = this.flagZ = result << 8;
|
||||
// this.flagV = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case 0xD000: /*0150000*/ // BISB 15SSDD
|
||||
// //LOG_INSTRUCTION(instruction, 2, "BISB");
|
||||
// if ((src = this.readByteByMode(instruction >> 6)) >= 0) {
|
||||
// if ((dst = this.readByteByAddr(dstAddr = this.getAddrByMode(instruction, PDP11.ACCESS.UPDATE_BYTE))) >= 0) {
|
||||
// result = dst | src;
|
||||
// if (this.writeByteByAddr(dstAddr, result) >= 0) {
|
||||
// this.flagN = this.flagZ = result << 8;
|
||||
// this.flagV = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case 0xE000: /*0160000*/ // SUB 16SSDD
|
||||
// //LOG_INSTRUCTION(instruction, 2, "SUB");
|
||||
// if ((src = this.readWordByMode(instruction >> 6)) >= 0) {
|
||||
|
|
|
|||
|
|
@ -163,12 +163,15 @@ var PDP11 = {
|
|||
INTR: 0x00ff, // mask for 8 bits, representing interrupt levels 0-7
|
||||
HALT: 0x0100 // halt requested; see opHLT()
|
||||
},
|
||||
/*
|
||||
* Internal operation state flags
|
||||
*/
|
||||
OPFLAG: {
|
||||
TRAP_TF: 0x10, // aka PDP11.PSW.TF
|
||||
TRAP_MMU: 0x20,
|
||||
TRAP_SP: 0x40,
|
||||
TRAP_MASK: 0x70,
|
||||
SKIP_FLAGS: 0x80
|
||||
SKIP_FLAGS: 0x80 // when set, all updateXXXFlags() functions must leave flags unchanged
|
||||
},
|
||||
/*
|
||||
* Opcode reg (opcode bits 2-0)
|
||||
|
|
@ -198,6 +201,9 @@ var PDP11 = {
|
|||
MASK: 0x0FC0,
|
||||
SHIFT: 6
|
||||
},
|
||||
/*
|
||||
* PDP-11 trap vectors
|
||||
*/
|
||||
TRAP: {
|
||||
UNDEFINED: 0x00, // 000 (reserved)
|
||||
BUS_ERROR: 0x04, // 004 illegal instructions, bus errors, stack limit, illegal internal address, microbreak
|
||||
|
|
@ -210,6 +216,9 @@ var PDP11 = {
|
|||
PIRQ: 0xA0, // 240 PIRQ, program interrupt request
|
||||
MMU_FAULT: 0xA8 // 250 MMU aborts and traps
|
||||
},
|
||||
/*
|
||||
* Internal memory access flags
|
||||
*/
|
||||
ACCESS: {
|
||||
WORD: 0x0,
|
||||
BYTE: 0x1,
|
||||
|
|
|
|||
Loading…
Reference in a new issue