Lately I am writing (or trying) an emulator for the 6502 NES CPU.
I am learning many many things, some of them really surprise me and I was wondering what's the explanation for those, in particular, two things came to my mind
- The existence of bugs, in particular the 6502 seems to have a bug in the indirect addressing mode, at least for the first processors (it affects the one used in the NES)
- Unofficial operation codes: Again, really surprising that there are codes not official yet usable, some of them seem to be totally useless (like DOP and TOP which are variations of NOP), and some of them seem to be composition of other operation codes (such SAX or DCP).
The question is, how is it possible that when manufacturing millions of those CPUs, they ended up with bugs (such the indirect addressing mode) and also, why on earth would you as a manufacturer include unofficial operation codes that may be removed in following revisions? Does this happen also with newer CPUs?
1: Sometimes there are bugs even in popular and supposedly well tested processors, like for example the Pentium FDIV bug. Any system that is complex enough to be really useful, has bugs.
2: The existence of undocumented operation codes was mainly to simplify the logic in the operation code identifying process.
If we look for example at the
LDY
,LDA
,LDX
andLAX
operations (zero page addressing mode), the values for the operation codes are:If you look at the lower two bits, you see that they were used to specify the target of the operation.
00
means theY
register,01
means theA
register,10
means theX
register, and as11
has both bits set the data ends up both in theA
andX
register.