Strip leading zeros from selected debugger constants (typically immediate values)
This commit is contained in:
parent
15fe831fc7
commit
eb5aaa5d66
10 changed files with 348 additions and 335 deletions
|
|
@ -879,7 +879,7 @@ CPUStatePDP11.prototype.trap = function(vector, reason)
|
|||
this.opFlags &= ~PDP11.OPFLAG.TRAP_MASK; // lose interest in traps after an abort
|
||||
this.trapPSW = -1; // reset flag that we have a trap within a trap
|
||||
|
||||
if (DEBUG && this.dbg) this.dbg.println("trap to vector " + this.dbg.toStrBase(vector) + (reason? " (reason " + reason + ")" : ""));
|
||||
if (DEBUG && this.dbg) this.dbg.println("trap to vector " + this.dbg.toBase(vector) + (reason? " (reason " + reason + ")" : ""));
|
||||
|
||||
throw vector;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -215,6 +215,8 @@ if (DEBUGGER) {
|
|||
|
||||
/*
|
||||
* CPU opcode IDs
|
||||
*
|
||||
* Not listed: BLO (same as BCS) and BHIS (same as BCC).
|
||||
*/
|
||||
DebuggerPDP11.OPS = {
|
||||
NONE: 0, ADC: 1, ADCB: 2, ADD: 3, ASL: 4, ASLB: 5, ASR: 6, ASRB: 7,
|
||||
|
|
@ -256,8 +258,6 @@ if (DEBUGGER) {
|
|||
/*
|
||||
* Register numbers 0-7 are reserved for cpu.regsGen, 8-15 are reserved for cpu.regsAlt, and 16-19 for cpu.regsStack.
|
||||
*/
|
||||
DebuggerPDP11.REG_SP = 6; // aka R6
|
||||
DebuggerPDP11.REG_PC = 7; // aka R7
|
||||
DebuggerPDP11.REG_PSW = 20;
|
||||
|
||||
/*
|
||||
|
|
@ -777,7 +777,7 @@ if (DEBUGGER) {
|
|||
*/
|
||||
DebuggerPDP11.prototype.toStrOffset = function(off)
|
||||
{
|
||||
return this.toStrBase(off);
|
||||
return this.toBase(off);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1929,7 +1929,7 @@ if (DEBUGGER) {
|
|||
var sLine = this.toStrAddr(dbgAddrOp) + ":";
|
||||
if (dbgAddrOp.addr !== PDP11.ADDR_INVALID && dbgAddr.addr !== PDP11.ADDR_INVALID) {
|
||||
do {
|
||||
sOpcodes += ' ' + this.toStrBase(this.getWord(dbgAddrOp, 2));
|
||||
sOpcodes += ' ' + this.toBase(this.getWord(dbgAddrOp, 2));
|
||||
if (dbgAddrOp.addr == null) break;
|
||||
} while (dbgAddrOp.addr != dbgAddr.addr);
|
||||
}
|
||||
|
|
@ -1973,20 +1973,20 @@ if (DEBUGGER) {
|
|||
if (opTypeOther == DebuggerPDP11.OP_BRANCH) {
|
||||
disp = ((opCode & 0xff) << 24) >> 23;
|
||||
addr = (dbgAddr.addr + disp) & 0xffff;
|
||||
sOperand = this.toStrBase(addr);
|
||||
sOperand = this.toBase(addr);
|
||||
}
|
||||
else if (opTypeOther == DebuggerPDP11.OP_DSTOFF) {
|
||||
disp = (opCode & 0x3f) << 1;
|
||||
addr = (dbgAddr.addr - disp) & 0xffff;
|
||||
sOperand = this.toStrBase(addr);
|
||||
sOperand = this.toBase(addr);
|
||||
}
|
||||
else if (opTypeOther == DebuggerPDP11.OP_DSTNUM3) {
|
||||
disp = (opCode & 0x7);
|
||||
sOperand = this.toStrBase(disp, 1);
|
||||
sOperand = this.toBase(disp, 1);
|
||||
}
|
||||
else if (opTypeOther == DebuggerPDP11.OP_DSTNUM6) {
|
||||
disp = (opCode & 0x3f);
|
||||
sOperand = this.toStrBase(disp, 1);
|
||||
sOperand = this.toBase(disp, 1);
|
||||
}
|
||||
else {
|
||||
/*
|
||||
|
|
@ -2022,7 +2022,7 @@ if (DEBUGGER) {
|
|||
* When using R7 (aka PC), POST-INCREMENT is known as IMMEDIATE
|
||||
*/
|
||||
wIndex = this.getWord(dbgAddr, 2);
|
||||
sOperand = "#" + this.toStrBase(wIndex);
|
||||
sOperand = '#' + this.toBase(wIndex, 0, true);
|
||||
}
|
||||
break;
|
||||
case PDP11.OPMODE.POSTINCD: // 0x3: POST-INCREMENT DEFERRED
|
||||
|
|
@ -2033,7 +2033,7 @@ if (DEBUGGER) {
|
|||
* When using R7 (aka PC), POST-INCREMENT DEFERRED is known as ABSOLUTE
|
||||
*/
|
||||
wIndex = this.getWord(dbgAddr, 2);
|
||||
sOperand = "@#" + this.toStrBase(wIndex);
|
||||
sOperand = "@#" + this.toBase(wIndex, 0, true);
|
||||
}
|
||||
break;
|
||||
case PDP11.OPMODE.PREDEC: // 0x4: PRE-DECREMENT
|
||||
|
|
@ -2044,22 +2044,22 @@ if (DEBUGGER) {
|
|||
break;
|
||||
case PDP11.OPMODE.INDEX: // 0x6: INDEX
|
||||
wIndex = this.getWord(dbgAddr, 2);
|
||||
sOperand = this.toStrBase(wIndex) + '(' + this.getRegName(reg) + ')';
|
||||
sOperand = this.toBase(wIndex, 0, true) + '(' + this.getRegName(reg) + ')';
|
||||
if (reg == 7) {
|
||||
/*
|
||||
* When using R7 (aka PC), INDEX is known as RELATIVE
|
||||
*/
|
||||
sOperand = [sOperand, this.toStrBase((wIndex + dbgAddr.addr) & 0xffff)];
|
||||
sOperand = [sOperand, this.toBase((wIndex + dbgAddr.addr) & 0xffff)];
|
||||
}
|
||||
break;
|
||||
case PDP11.OPMODE.INDEXD: // 0x7: INDEX DEFERRED
|
||||
wIndex = this.getWord(dbgAddr, 2);
|
||||
sOperand = '@' + this.toStrBase(wIndex) + '(' + this.getRegName(reg) + ')';
|
||||
sOperand = '@' + this.toBase(wIndex) + '(' + this.getRegName(reg) + ')';
|
||||
if (reg == 7) {
|
||||
/*
|
||||
* When using R7 (aka PC), INDEX DEFERRED is known as RELATIVE DEFERRED
|
||||
*/
|
||||
sOperand = [sOperand, this.toStrBase((wIndex + dbgAddr.addr) & 0xffff)];
|
||||
sOperand = [sOperand, this.toBase((wIndex + dbgAddr.addr) & 0xffff)];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
@ -2148,16 +2148,16 @@ if (DEBUGGER) {
|
|||
|
||||
if (iReg < 8) {
|
||||
sReg = this.getRegName(iReg);
|
||||
sReg += '=' + this.toStrBase(cpu.regsGen[iReg]);
|
||||
sReg += '=' + this.toBase(cpu.regsGen[iReg]);
|
||||
}
|
||||
else if (iReg < 13) {
|
||||
sReg = "A" + (iReg - 8) + '=' + this.toStrBase(cpu.regsAlt[iReg - 8]);
|
||||
sReg = "A" + (iReg - 8) + '=' + this.toBase(cpu.regsAlt[iReg - 8]);
|
||||
}
|
||||
else if (iReg >= 16 && iReg < 20) {
|
||||
sReg = "S" + (iReg - 16) + '=' + this.toStrBase(cpu.regsAltStack[iReg - 16]);
|
||||
sReg = "S" + (iReg - 16) + '=' + this.toBase(cpu.regsAltStack[iReg - 16]);
|
||||
}
|
||||
else if (iReg == DebuggerPDP11.REG_PSW) {
|
||||
sReg = "PS=" + this.toStrBase(cpu.getPSW());
|
||||
sReg = "PS=" + this.toBase(cpu.getPSW());
|
||||
}
|
||||
if (sReg) sReg += ' ';
|
||||
return sReg;
|
||||
|
|
@ -2178,11 +2178,11 @@ if (DEBUGGER) {
|
|||
{
|
||||
var i;
|
||||
var sDump = "";
|
||||
for (i = 0; i < DebuggerPDP11.REG_SP; i++) {
|
||||
for (i = 0; i < PDP11.REG.SP; i++) {
|
||||
sDump += this.getRegOutput(i);
|
||||
}
|
||||
sDump += '\n';
|
||||
sDump += this.getRegOutput(DebuggerPDP11.REG_SP) + this.getRegOutput(DebuggerPDP11.REG_PC) + this.getRegOutput(DebuggerPDP11.REG_PSW);
|
||||
sDump += this.getRegOutput(PDP11.REG.SP) + this.getRegOutput(PDP11.REG.PC) + this.getRegOutput(DebuggerPDP11.REG_PSW);
|
||||
sDump += this.getFlagOutput('T') + this.getFlagOutput('N') + this.getFlagOutput('Z') + this.getFlagOutput('V') + this.getFlagOutput('C');
|
||||
return sDump;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -179,10 +179,10 @@ var PDP11 = {
|
|||
OPMODE: {
|
||||
REG: 0x00, // REGISTER (register is operand)
|
||||
REGD: 0x08, // REGISTER DEFERRED (register is address of operand)
|
||||
POSTINC: 0x10, // POST-INCREMENT (register is address of operand, register incremented)
|
||||
POSTINCD: 0x18, // POST-INCREMENT DEFERRED (register is address of address of operand, register incremented)
|
||||
PREDEC: 0x20, // PRE-DECREMENT (register decremented, register is address of operand)
|
||||
PREDECD: 0x28, // PRE-DECREMENT DEFERRED (register decremented, register is address of address of operand)
|
||||
POSTINC: 0x10, // AUTO-INCREMENT (register is address of operand, register incremented)
|
||||
POSTINCD: 0x18, // AUTO-INCREMENT DEFERRED (register is address of address of operand, register incremented)
|
||||
PREDEC: 0x20, // AUTO-DECREMENT (register decremented, register is address of operand)
|
||||
PREDECD: 0x28, // AUTO-DECREMENT DEFERRED (register decremented, register is address of address of operand)
|
||||
INDEX: 0x30, // INDEX (register + next word is address of operand)
|
||||
INDEXD: 0x38, // INDEX DEFERRED (register + next word is address of address of operand)
|
||||
MASK: 0x38
|
||||
|
|
|
|||
|
|
@ -659,26 +659,35 @@ if (DEBUGGER) {
|
|||
};
|
||||
|
||||
/**
|
||||
* toStrBase(n, nBytes)
|
||||
* toBase(n, nBytes, fStripLeadingZeros)
|
||||
*
|
||||
* Use this instead of str.toHex() or str.toOct() to convert bytes/words to the Debugger's default base.
|
||||
*
|
||||
* @this {Debugger}
|
||||
* @param {number|null|undefined} n
|
||||
* @param {number} [nBytes] is the number of bytes to display, which we translate into a number of characters
|
||||
* @param {boolean} [fStripLeadingZeros]
|
||||
* @return {string}
|
||||
*/
|
||||
Debugger.prototype.toStrBase = function(n, nBytes)
|
||||
Debugger.prototype.toBase = function(n, nBytes, fStripLeadingZeros)
|
||||
{
|
||||
var s;
|
||||
switch(this.nBase) {
|
||||
case 8:
|
||||
return str.toOct(n, nBytes * 3);
|
||||
s = str.toOct(n, nBytes * 3);
|
||||
break;
|
||||
case 10:
|
||||
return n.toString();
|
||||
s = n.toString();
|
||||
break;
|
||||
case 16:
|
||||
default:
|
||||
return str.toHex(n, nBytes * 2);
|
||||
s = str.toHex(n, nBytes * 2);
|
||||
break;
|
||||
}
|
||||
if (fStripLeadingZeros && s.charAt(0) == '0') {
|
||||
s = s.replace(/^0+([0-9A-F]+)$/i, "$1");
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
||||
} // endif DEBUGGER
|
||||
|
|
|
|||
Loading…
Reference in a new issue