6502 Unsupported Opcodes
The 6502 is famous for doing interesting and sometimes useful things when the program includes invalid (or unspecified) opcodes.
The visual6502 simulator can help when investigating what these opcodes do, and why - see below!
- LAX will load both A and X - notice signals SBX and SBAC which control the writes to X and to A.
- KIL will put the T-state counter into an unrecoverable state
- XAA #$5A (also known as ANE) with A=FF
- and with A=00 shows A is OR with 00 before AND with X and the immediate value
Beware: different revisions of 6502 and versions from different manufacturers may have different behaviours.
For some of these opcodes, the chip does something logically predictable and our model has the same behaviour. But there may be opcodes which are not logically predictable, because they cause marginal voltages on the chip as different drivers fight one another, or a node which is undriven is sampled at a later time. In those cases, our visual6502 simulator, which is just a switch-level simulator with a couple of coarse heuristics for modelling contention and charge storage, won't do the same as a chip.
In fact, as some opcodes produce results which vary from one chip to another, no deterministic simulator could be 'accurate'. (A simulator could let you know that something is amiss)
But note that the underlying circuit data which we now have includes transistor strengths and an approximation of capacitative load: it could easily be extended for resistance and more accurate capacitance. So a more refined (lower level) simulation might shed more light on these undocumented opcodes. In fact, the FPGA model works differently - it moves charge from one node to another - and it might be more accurate for the difficult cases.
- Michael Steil's presentation at 27C3 youtube link direct to section on illegal opcodes
- How MOS 6502 Illegal Opcodes really work on Michael Steil's blog
- 64doc.txt by VICE team
- Extra Instructions Of The 65XX Series CPU by Adam Vardy
- 6502 Undocumented Opcodes by Freddy Offenga
- 6502/6510/8500/8502 Opcode matrix by "Graham"
- Full 6502 Opcode List Including Undocumented Opcodes by J.G.Harston
- Michael Steil's presentation at 27C3 (pagetable.com links to 6 sections on youtube)