break;
case AM_IND_AUTOINC:
if (register == 0) {
// Can this be PC and be incremented only one byte?
int tmp = memory[pc] + (memory[pc + 1] << 8);
MapEntry me;
if (map != null && (me = map.getEntry(tmp)) != null) {
adr = me.getName(); // + " = $" + Utils.hex16(tmp);
} else {
adr = "#$" + Utils.hex16(tmp);
}
size += 2;
} else {
adr = "@(R" + register + "+)";
dstAddress = reg[register];
}
break;
}
switch(instruction & 0xff80) {
case RRC:
opstr = "RRC" + (word ? ".W" : ".B");
break;
case SWPB:
opstr = "SWPB" + (word ? ".W" : ".B");
break;
case RRA:
opstr = "RRA" + (word ? ".W" : ".B");
break;
case SXT:
opstr = "RRA" + (word ? ".W" : ".B");
break;
case PUSH:
opstr = "PUSH" + (word ? ".W" : ".B");
break;
case CALL:
opstr = "CALL";
break;
case RETI:
opstr = "RETI";
break;
default:
if ((instruction & 0xf800) == 0x1800) {
int zc = (instruction & EXTWORD_ZC) > 0 ? 1 : 0;
int al = (instruction & EXTWORD_AL) > 0 ? 1 : 0;
int rp = (instruction & EXTWORD_REPEAT) > 0 ? 1 : 0;
int shi = (instruction & EXTWORD_SRC) >> 7;
int dhi = (instruction & EXTWORD_DST);
opstr = "ExtWord " + Utils.hex16(instruction) + ":ZC:" + zc + " #:" + rp +
" A/L:" + al + " src:" + shi + " dst:" + dhi;
dbg.setExtWord(true);
} else {
System.out.println("Not implemented instruction: $" + Utils.hex16(instruction) +
" at " + Utils.hex16(startPC));
opstr = "<Unkown>";
}
}
output += dumpMem(startPC, size, memory);
output += opstr + " " + adr;
regs = "R" + register + "=" + Utils.hex16(reg[register]);
regs += " SP=" + Utils.hex16(reg[SP]);
}
}
break;
// Jump instructions
case 2:
case 3:
// 10 bits for address for these => 0x00fc => remove 2 bits
int jmpOffset = instruction & 0x3ff;
jmpOffset = (jmpOffset & 0x200) == 0 ?
2 * jmpOffset : -(2 * (0x200 - (jmpOffset & 0x1ff)));
boolean jump = false;
String opstr = "";
switch(instruction & 0xfc00) {
case JNE:
opstr = "JNE";
break;
case JEQ:
opstr = "JEQ";
break;
case JNC:
opstr = "JNC";
break;
case JC:
opstr = "JC";
break;
case JN:
opstr = "JN";
break;
case JGE:
opstr = "JGE";
break;
case JL:
opstr = "JL";
break;
case JMP:
opstr = "JMP";
break;
default:
System.out.println("Not implemented instruction: " +
Utils.binary16(instruction));
}
output += dumpMem(startPC, size, memory);
output += opstr + " $" + Utils.hex16(jmpOffset);
regs = "\tSR=" + dumpSR(reg[SR]);
break;
default:
// ---------------------------------------------------------------
// Double operand instructions!
// ---------------------------------------------------------------
int dstRegister = (instruction & 0xf);
int srcRegister = (instruction >> 8) & 0xf;
int as = (instruction >> 4) & 3;
// AD: 0 => register direct, 1 => register index, e.g. X(Rn)
boolean dstRegMode = ((instruction >> 7) & 1) == 0;
int dstAddress = 0;
int srcAddress = 0;
int src = 0;
int dst = 0;
boolean write = false;
boolean updateStatus = true;
String srcadr = "";
String dstadr = "";
switch(as) {
// Operand in register!
case AM_REG:
if (srcRegister == CG2) {
srcadr = "#0";
} else if (srcRegister == CG1) {
srcadr = "#0";
} else {
srcadr = getRegName(srcRegister);
}
break;
case AM_INDEX:
// Indexed if reg != PC & CG1/CG2 - will PC be incremented?
if (srcRegister == CG1) {
srcAddress = memory[pc] + (memory[pc + 1] << 8);
MapEntry me;
if (map != null && (me = map.getEntry(srcAddress)) != null) {
srcadr = "&" + me.getName(); // + " = $" + Utils.hex16(srcAddress);
} else {
srcadr = "&$" + Utils.hex16(srcAddress);
}
size += 2;
} else if (srcRegister == CG2) {
srcadr = "#1";
} else {
srcAddress = reg[srcRegister] + memory[pc] + (memory[pc + 1] << 8);
srcadr = "$" + Utils.hex16(memory[pc] + (memory[pc + 1] << 8)) + "(R" + srcRegister + ")";
size += 2;
}
pc += 2;
break;
// Indirect register
case AM_IND_REG:
if (srcRegister == CG2) {
srcadr = "#2";
} else if (srcRegister == CG1) {
srcadr = "#4";
} else {
srcadr = "@" + getRegName(srcRegister);
}
break;
case AM_IND_AUTOINC:
if (srcRegister == CG2) {
srcadr = "#$ffff";
} else if (srcRegister == CG1) {
srcadr = "#8";
} else if (srcRegister == PC) {
srcadr = "#$" + Utils.hex16(memory[pc] + (memory[pc + 1] << 8));
pc += 2;
size += 2;
} else if (srcRegister == CG2) {
srcadr = "#$ffff";
} else {
srcadr = "@" + getRegName(srcRegister) + "+";
srcAddress = reg[srcRegister];
}
break;
}
if (dstRegMode) {
dstadr = getRegName(dstRegister);
} else {
dstAddress = memory[pc] + (memory[pc + 1] << 8);
MapEntry me = map != null ? map.getEntry(dstAddress) : null;
if (dstRegister == 2) {
if (me != null) {
dstadr = "&" + me.getName(); // + " = $" + Utils.hex16(srcAddress);
} else {
dstadr = "&$" + Utils.hex16(dstAddress);
}
} else {
if (me != null) {
dstadr = me.getName() + "(R" + dstRegister + ")";
} else {
dstadr = "$" + Utils.hex16(dstAddress) + "(R" + dstRegister + ")";
}
}
pc += 2;