1

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

  1. 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)
  2. 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?

Juan Antonio Gomez Moriano
  • 13,103
  • 10
  • 47
  • 65
  • 1
    This question appears to be off-topic because it is about hardware and not programming as defined in the [help] guidelines. – Ken White Dec 07 '14 at 21:39
  • Every processor has bugs. But yes, 6502 was a particularly nasty bag of them. Fixing masks is very expensive so it is always a trade-off to document or fix the bug. And 6502 was special, it was *very* cheap. – Hans Passant Dec 07 '14 at 22:50
  • @KenWhite I have been checking the guidelines and you might be right... any suggestion on where should I ask this? – Juan Antonio Gomez Moriano Dec 07 '14 at 22:53
  • MOved the question to super user where it belongs. – Juan Antonio Gomez Moriano Dec 07 '14 at 23:39
  • Also possibly of relevance: in those days, the CPU was drawn out by hand on a huge table and then photographically reduced. That's quite a lot of manual work. There would be some mistakes. A larger scale example is the C64 disk drive port. A connection was omitted on the final board that could be worked around in software but made the thing significantly shower than designed. Basically every other micro's drive was a lot faster. – Tommy Dec 08 '14 at 22:17
  • 1
    Of possible relevance: http://www.llx.com/~nparker/a2/opcodes.html – Ivan X Dec 21 '14 at 00:51

1 Answers1

4

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 and LAX operations (zero page addressing mode), the values for the operation codes are:

operation  hex  binary
-----------------------------
LDY        A4   10100100
LDA        A5   10100101
LDX        A6   10100110
LAX        A7   10100111

If you look at the lower two bits, you see that they were used to specify the target of the operation. 00 means the Y register, 01 means the A register, 10 means the X register, and as 11 has both bits set the data ends up both in the A and X register.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • @Eight-BitGuru: Both of those are just opinions of yours, not facts. Could you back up your opinions with some kind of explanation why you think so? – Guffa Dec 07 '14 at 23:16
  • @Guffa see the comments to the question for why the question is off topic. I think the reason they feel it doesn't seem to answer the question is because it doesn't answer *why* bugs exist. – AdamMc331 Dec 08 '14 at 00:35
  • The second isn't really an opinion. Old CPUs used hard-wired operation decoding. It's cheaper not to add extra logic that makes sure the operation is within the documentation. Those are objective facts. The appearance of undocumented instructions is then a corollary. – Tommy Dec 08 '14 at 22:13
  • @Tommy: Sorry for the confusion. The comment referered to another comment that was removed, not the answer. – Guffa Dec 08 '14 at 22:22
  • @Guffa ... the cause of confusion appears more likely to be: I can't read @ comments. How dare you accuse yourself of relying on unevidenced opinions?!? – Tommy Dec 09 '14 at 01:50