I finally got to the point where my 6502 emulator passed all of the tests in AllSuiteA.asm, but my emulator is failing to emulate Enhanced Basic, which I have loaded at $C000. What happens is PC slowly climbs up to $C03E, and then JSRs to $C892. After that it steadily rises until $C908, where it JSRs again to $E0ED, and then JMPs indirectly to $0.
Why is Enhanced Basic infinitely looping, despite AllSuiteA saying my emulator was fine?
Here are the relevant functions:
Opcodes:
JSR:
case "JSR":
var t = pc + 1;
memory[0x0100 + sp] = (t & 0xFF00) >> 8;
sp--;
memory[0x0100 + sp] = t & 0x00FF;
sp--;
pc = address - opcode[2];
break;
JMP:
case "JMP":
pc = address - opcode[2];
break;
Addressing Modes:
IND:
case "IND":
var b1 = memory[pc + 1];
var b2 = memory[pc + 2];
var mem = (b2 << 8) | b1;
var bb1 = memory[mem];
var bb2 = memory[mem + 1];
address = (bb2 << 8) | bb1;
break;
ABS:
case "ABS":
var b1 = memory[pc + 1];
var b2 = memory[pc + 2];
address = (b2 << 8) | b1;
break;
Note: opcode[2] is the number of bytes of the opcode being executed
And here is a JSFiddle of the running program. Included in this fiddle is a hexadecimal representation of ehbasic.bin.