What exactly happens if you do an RTS without doing a JSR or something similar first? Does the stack pointer wrap to 0x00?
The reason I ask is because I'm currently making a 6502 emulator, and my testsuite is based on actual 6502 assembly code. It works by first assembling, then executing, and finally perform asserts on the mpu's state.
At this moment (with tests for every opcode except the ones that manipulates the stack) I do this by stepping as many times as there's lines in the assembly file.
Pseudocode:
Code:
int lines = assembly.num_newlines();
while (lines--)
mpu.step();
This works great for the tests I have right now, but it won't work for more complex assembly (using labels and JSR/RTS, etc). What I find most logical is having a rule that an RTS while stack poiner is at 0xFF stops the loop; but of course, that won't work if people rely on some other behaviour (I can't seem to google an answer on this one).
Another idea I've had is having a 'test mode' state in the MPU, where it treats an arbitrary and unused opcode as 'the end of test'.
Other suggestions are welcome.