6502 and 65816
This is a processor with a very dramatic fate, no other processor can compare with it. Its appearance and introduction were accompanied by very large events in scope and consequences. I will list some of them:
- the weakening of the giant Motorola company, which for some time exceeded the capabilities of Intel;
- the destruction of the independent company MOS Technology;
- the cessation of the 6502 development and its stagnant production with little or no modernization.
It all started with the fact that Motorola for unknown reasons refused to support the initiative of young engineers, who offered to improve the overall rather mediocre processor 6800. They had to leave Motorola and continue their work in a small but promising MOS Technology company, where they soon prepared two processors, the 6501 and 6502, both of them (like almost all processors of that time) were fabricated using NMOS technology. The first one was pin-compatible with the 6800, but in other details they were identical. The 6501/6502 team was able to successfully introduce a new chip production technology, which radically reduced the cost of new processors. In 1975, MOS Technology could offer the 6502 for $25, while the starting price for the Intel 8080 and Motorola 6800 was $360 in 1974. In 1975, Motorola and Intel lowered prices, but they were still close to $100. MOS Technology specialists claimed that their processor was up to 4 times faster than the 6800. I find this questionable: the 6502 can work much faster with memory, but the 6800's second accumulator greatly accelerated many calculations. I can assume on estimation that the 6502 was on average no more than 2 times faster. As follows from some publications as far back as 1975, MOS Technology had plans to expand the 6502 to the 16-bit level...
|MOS 6501 tears up competitors apart: Intel and Motorola are already crossed out!|
But Motorola launched a lawsuit against its former employees – they allegedly used some of the company's technological secrets. During the trial it was possible to establish that one of the engineers who had left Motorola took some confidential documents on the 6800, acting contrary to the attitudes of his colleagues. Whether it was his own act or there were still some guiding forces behind him is still unknown. Eventually, Motorola indirectly won the case and MOS Technology whose financial capabilities were limited, was forced to pay a substantial amount of $200,000 and to abandon production of the 6501. Intel in a similar situation with Zilog acted quite differently. Although it must be admitted that MOS Technology was sometimes too risky when trying to use the big money that Motorola spent on promoting the 6800 for its own purposes. The irony of the situation is that as the leader of the 6502 development team noted, since the 6501 they just wanted to do "a shot across the bow" and observe what happened, there was no goal to suggest using the 6501 instead of the 6800. It should be also pointed out the 6501 was still not completely compatible with the equipment for the 6800: the 6501 and 6502 in particular, did not support working with three output states and therefore could not be used directly, for example with hardware with direct memory access.
We still don't know exactly why Motorola won the lawsuit against MOS Technologies. Perhaps MOS Technologies just ran out of money, they spent up to $800,000 on the lawsuit, and money then was several times more significant than now. Although there were other factors: like the mentioned removal of Motorola's documents and it is also known that, for example the 6520 parallel interface chip manufactured by MOS Technology was an exact copy of the Motorola 6820. Everyone who left Motorola had to sign their consent to the decision of the lawsuit, since before the start of the process they had signed a paper with the fact that they would acknowledge any result.
Further, the legendary Commodore company and its no less legendary founder Jack Tramiel appeared in the 6502 story, in the shadows of whom was the figure of the chief financier of the company determining its policy – a man named Irving Gould. Jack got a loan from Irving and with this money, using a few to put it mildly unscrupulous tactics, forced MOS Technology to become a part of Commodore. After that and possibly against the wishes of Tramiel, who was forced to give in to Gould, the development of the 6502 almost stopped, despite the fact that even in 1976 it was possible to produce prototypes of the 6502 with operating frequencies up to 10 MHz. Although the message about this appeared only many years later from a man named Bill Mensch, who was with the team that left Motorola and sometimes made loud but by and large empty statements and played a rather ambiguous role in the fate of the 6502. The main developer of the 6502 Chuck Peddle was forever removed from the development of processors. Work with the 6502 continued not only at Commodore but also at Western Design Center (WDC) which was created by Bill Mensch. It is fascinating that none of the former 6502 team worked with him in the future. By the way, it was Bill Mensch who developed the aforementioned 6820, which became the 6520.
The continuing drama around the 6502 was not over. In 1980, a short anonymous article appeared in Rockwell's AIM65 Interactive magazine stating that all 6502's carry a dangerous bug called the JMP (xxFF). The tone of the article suggests something completely out of the ordinary. Subsequently this attitude moved to Apple regarding the issue and became a kind of mainstream. Although a "bug" strictly speaking it was not. Of course for a specialist accustomed to the comfortable processors of large systems of those years one of the features that is quite relevant and even useful among microprocessors, could seem something annoying, a bug. But in fact this behavior of hurting someone's feelings was described in the official documentation from 1976, and in the textbooks on programming published before the appearance of the mentioned article. The "bug" was eliminated by Bill Mensch, who made the 65С02 (CMOS 6502) in collaboration with Apple supposedly by 1983. The author of this material himself has encountered several times the problem of the aforementioned “bug”, although knowing nothing about it, he was writing programs for the Commodores. There was an incompatibility, he had to change the codes, to do a conditional assembly. The code for the 65C02 turned out to be more cumbersome and slower. Then I raised this question on the forum 6502.org, where some participants had familiarity with the Apple ][ computers. I asked if anyone could give an example when the "bug" crashed the program. I received only emotional and general comments, a specific example was never offered. Ironically, in the official WDC documentation, the "bug" is not directly called a bug, but rather a quirk.
While Intel, Motorola and others had already made 16-bit processors of new generations, the 6502 was only microscopically improved and made artificially partially incompatible with itself. Even if you compare the improvements made in the Motorola 6801 over the 6800 or the Intel 8085 over the 8080, they are gigantic compared to those made in the 65C02, and Intel and Motorola made them much earlier. A number of tiny changes were made in the 65C02, which in particular led to a change in the course of executing several instructions. These instructions became slower in a cycle, but at the same time they became more correct in some far-fetched academic sense. We are talking about the mentioned "bug" and instructions for decimal arithmetic. The latter were "adjusted" so that the oVerflow, Negative, and Zero flags started working "correctly". However, when working with decimal numbers on the 6502 (and other microprocessors), the sign is not supported and, accordingly the N and V flags do not make any sense. Only the correction of the Z flag makes some sense, but it is extremely insignificant. Dozens of new instructions were also added, the absolute majority of which only occupied the code space, adding almost nothing to the capabilities of the 6502, which left fewer opcodes for possible further upgrades. But it must be admitted that several new instructions turned out to be expected and useful, for instance new addressing modes for BIT or instruction JMP (ABS,X). Although again, we must admit that the new instructions allow you to get slightly faster and more compact codes. Besides this, four relatively rare instructions became sometimes a clock cycle faster on the 65C02. Additionally, the 65C02 became to reset the decimal mode flag on interrupt, which sometimes allows an interrupt handler to be 2 cycles faster and 1 byte shorter – this tiny improvement illustrates the overall amount of improvements made in the 65C02.
The 65C02 was licensed to many companies, in particular NCR, GTE, Rockwell, Synertek, and Sanyo. It was used in the Apple II starting with model IIe, although many IIe used NMOS 6502. The 6512 was a 65C02 variant which was used in later BBC Micro models. Atari used the NMOS 6502. Synertek and Rockwell companies in addition to the production of the CMOS 6502, also continued to produce the NMOS 6502. By the way the NMOS 6502 has its own set of undocumented instructions, the nature of which is completely different from the secret commands of the 8085. In the 6502 these instructions appeared as a side effect, so most of them are rather useless. But several instructions for example, loading or unloading two registers with one command at once, and some others can make the code faster and more compact.
Interestingly, the NMOS 6502 compatible with the 65C02 was never made. Although in the early 80's CMOS technology had no obvious advantages (except for reduced power consumption) over NMOS/HMOS and was noticeably more expensive. It is worth noting of course that WDC was able to create a CMOS processor only a few years after Intel, and Motorola made CMOS versions of their 8085 and 680x processors. In this, it was significantly ahead of Zilog, where the CMOS version of the Z80 was created only by 1987. However, if the CMOS 8085 and Z80 immediately found the wide use in mobile computers, the low power consumption 65C02 found its application in computers relatively late. I can only name the Atari Lynx game console, produced since 1989. It is also worth noting that the introduction of CMOS technology itself is quite a routine process, through which other processors (the x86, 68k, ...) passed almost unnoticed.
There were other attempts to modernize the 6502. In 1979, an article appeared that for the Atari computers, the 6509 processor was being prepared for production (not to be confused with the later Commodore's processor with the same name), in which command execution acceleration by 25% and many new instructions were expected. For unknown reasons the production of this processor never took place. Commodore conducted only tiny upgrades. From the point of view of programming, the most interesting was the processor 6509 which, albeit in a very primitive form, with the help of only two instructions specially allocated for this purpose and two bytes of the page zero allows addressing up to 1 MB of memory. In the super-popular Commodore 64 and 128, there were the 6510/8510 processors, and in the less successful 264 series – the 7501/8501. These processors had 6 and 7 embedded I/O bit-ports respectively, while the 7501/8501 did not support non-masked interrupts. In addition, these processors implemented support of tri-state logic which was necessary for the working of video controllers in the C64 and C264. Rockwell produced a version of the 65C02 extended by their own 32 operations for one-bit values (similar to the z80's bit instructions). However, as far as I know such processors were not used in computers, and these bit instructions themselves were more likely to be used only in embedded systems. This extension was also made by Bill Mensch. It has turned out that Bill worked on the 6502, with only specifications received, and he never tried to improve this processor himself.
The last scene of the drama with the participation of the 6502 was featured in the prevention of computers based on the 6502 with a frequency of 2 MHz on the US market in the first half of the 80's. This affected the English BBC Micro, their manufacturing company Acorn made a large batch of computers for the United States, but as it turned out, in vain. Some kind of lock was triggered and the computers had to be urgently redone to European standards. Almost American, but formally Canadian computers Commodore CBM II (1982), despite some problems (in particular, compliance with the standards for electrical equipment), were nevertheless admitted. Perhaps it was due to a fact that they did not have graphic modes and even color text which made them little threat to American market mainstreams and even the stylish Porsche design could not compensate for this. The latest in the list of losers was the 100% American Apple III (1980) – it is known that Steve Jobs like Apple's management in general did a lot to prevent this computer from being successful. Steve demanded obviously impracticable specifications and the management asked for unrealistic deadlines. Will we ever know their motives? It became possible to eliminate the flaws of the Apple III in the Apple III Plus (1983), but the Apple’s management quietly closed the project in 1984 because of their reluctance to have a competition with the Macintosh computer. Only in 1985, when the era of 8-bit technology began to go away, did the Commodore 128 appear which could use in one of its modes the 6502 at 2 MHz clock. But even here it turned out to be more of a joke since this mode was practically not supported and there are practically no programs for it. Only in the second half of the 80's in the United States there began production of accelerators for the Apple II and since 1988 the Apple IIc+ model with a 4 MHz processor. Why did it happen that way? Perhaps because the 6502 at 2 or 3 MHz (and these were already produced at the very beginning of the 80's) could successfully compete with systems based on the Intel 8088 or Motorola 68000 in a number of tasks and especially games. In 1991, the willful decision of Commodore closed an interesting albeit belated project, the C65 based on the 4510 processor with a frequency of 3.54 MHz. The 4510 chip was based on the 65CE02 processor, which in turn is based on the WDC 65C02. The 65CE02 is the fastest 6502, made only in 1988, it finally carried out the previously mentioned optimization of cycles which gave a 25% increase in speed. Thus, the processor in the C65 is close in speed to the 6502 systems at 4.5 MHz. Surprisingly, this fastest 6502 with an extended set of instructions (in some detail this extension turned out to be more convenient than in the 65816) has never been used anywhere else.
The Commodore C128 and Apple III Plus had a MMU that allowed them to use several stacks and zero pages, to address more than 64 KB of memory, etc. The C128's MMU was artificially trimmed to work with only 128KB of memory. For the BBC Micro computers the second processor boards were produced with the 6502 at 3 MHz (1984) and 4 MHz (1986).
|Anti-advertising – multiple Porsche PETs in the apartment of the villain of The Jewel of the Nile – The Apple only era in Hollywood had not yet come|
Now a few words about the instruction system of the 6502. The main feature of this processor is that it was made almost as fast as possible, with almost no extra clock cycles which are especially numerous in the 8080/8085/z80/8088/68000 processors. In fact, it was the main concept of the ARM architecture for processors that appeared later under the direct influence of the 6502. The same concept dominates among Intel processors starting with the 80486. In addition, the 6502 responded very quickly to interrupts, which made it very useful in some embedded systems. The 6502 has one accumulator and two index registers, in addition, the first 256 bytes of memory can be used in dedicated commands either as faster memory or as a set of 16-bit registers (which are almost identical in their functionality to the BC and DE registers in the 8080/z80) for pretty powerful ways to address memory locations. Some arithmetic commands (shifts, rotation, increment, and decrement) can be used with memory directly, without using registers. There are no 16-bit instructions – this is a 100% 8-bit processor. It supports all the basic flags but the parity flag which is typical only for the Intel's architecture. There is one more special flag of the low-useful decimal mode which has replaced the half-carry flag used by most other processors. Intel, Zilog and Motorola processors use special corrective instructions for working with decimal numbers, but the 6502 can switch to decimal mode which makes its speed advantage with decimal numbers even more significant than with binary ones. Very impressive for the 6502 is the presence of a table multiplication of 8-bit operands with a 16-bit result in less than 30 cycles, with an auxiliary table size of 2048 bytes. The 6502 uses a simple instruction pipeline that speeds up the execution time of many instructions by 1 clock cycle. One of the slowest 6502's operations is a block memory copy, it can take more than 14 cycles per byte. The instruction system 6502 in some particular ways is unusually asymmetric, for example, there is an instruction to load register Y,
LDY addr,X, but there is no pairwise unload to it. There is an instruction to reset the overflow flag, but there is no paired instruction to set it. The 6502 allows the overflow flag to be set via a hardware signal instead of this instruction. This way of working with the overflow flag allows you to use a very fast input port, but for programming arithmetic both setting this flag and clearing it are useless. Therefore, in the 6510 or 7501/8501, they abandoned the special method of setting the overflow flag, but the now completely useless instruction for resetting it remains!
The main drawback of the 6502 is the small stack size, only 256 bytes. However, for a system with a memory capacity of 64 KB, this, as practice has shown, is usually quite enough. The 6502 has few registers and therefore the pressure on its stack is less than for example, the 8080, 6809 or Z80. Besides that the 6502 architecture naturally assumes the organization of an additional stack on the zero page – such a stack is especially good when working with pointers, since the addressing (zp,X) is ideal for such cases. Of course, the size of such an additional stack is very limited and on many systems can not be more than a few dozen bytes.
Support for hardware interrupts in the 6502 is implemented plainly and efficiently. For masked and non-masked interrupts, two fixed addresses are allocated in memory, where the addresses of the corresponding handlers are written. Similarly, but even simpler, the most popular interrupt mode 1 on the Z80 was later realized. But software interrupts in the 6502 are implemented quite primitively: they use the address for masked interrupts, which requires a cumbersome additional software check to distinguish them. This is why there is a unique software interrupt flag among the 6502 flags. In addition, the software interrupt instruction has no argument, although such an argument can be added at the cost of complicating the handler procedure. Due to the fact that the ability to handle software interrupts significantly slows down the processing of hardware interrupts, support for software interrupts is often simply not implemented.
The 6502 can work in parallel with another device, for example another 6502. Such dual-processor systems were extremely rare. As an example of such systems, I know of only a few very rare models of Commodore drives. Instead of the second processor a video controller was usually used, which shared memory with the 6502.
The 65816 was released by WDC in 1983. This was the first time that a 16-bit processor compatible with its 8-bit predecessor was made – for the Z80, similar developments (the Z800, Z180, Z380, eZ80, ...) began to appear only from 1985. In addition, it was one of the first 16-bit processors manufactured using CMOS technology! Interesting is the fact that some specifications of the new processor Bill Mensch received from Apple. Of course, this was a big step forward, but clearly belated and with large architectural flaws. The 65816 was not considered by anyone as a competitor for the main processors of Intel or Motorola – it was already a minor outsider, which was already somehow programmed to be set to further lose its positions. The 65816 had two important advantages – it was relatively cheap and almost compatible with the still very popular 6502. In subsequent years, Bill Mensch didn’t even try to somehow improve his brainchild, do cycle optimization, replace the zero page addressing by extended one using the Z register (this was done in the 65CE02), add at least multiplication, etc. WDC only increased the limiting clock speeds, reaching 14 MHz by the mid-90's (this processor was used in the popular accelerator for the C64, the SuperCPU at a frequency of 20 MHz). However, even now (2020!) WDC for some reason, offers the 65816 only at the same 14 MHz. The 65816 can use up to 16 MB of memory, but the addressing methods used for this look far from optimal. For example: index registers can be only 8 or 16 bit, the stack can be placed only in the first 64 KB of memory, only there you can use the convenient short addressing of the direct page (the generalization of zero page addressing), working with memory above 64 KB is comparatively awkward, etc. The 65816 has a 16-bit ALU but an 8-bit data bus, so it is only about 50% faster than the 6502 with arithmetic operations. Nevertheless, the 65816, according to Bill Mensch, was released as an amount of more than a billion. Indeed, some instructions of the 65816 clearly fill the gaps in the 6502 architecture, for example, the commands for block copying of memory in 7 clock cycles per byte and addressing modes for working with the stack. I can also add that the 65816 uses almost all instruction codes, 255 out of 256. The last unused code is for future long instructions that have not yet appeared.
The Apple IIx in the development of which Steve Wozniak was actively involved had to use the 65816. However, it was possible to start mass production of this processor only in 1984 and the first batches of it were defective, which caused excessive delays and eventually the closure of the entire project.
The 65802 is another version of the 65816, which uses a 16-bit address bus and a pin layout compatible with the 6502. An upgrade for the Apple II based on this processor was offered, but acceleration with such an upgrade can only be obtained with specially written programs.
The 6502 was used in a large number of computer systems, the most popular of which were the 8-bit Commodore, Atari, Apple, Acorn, and NES. The Commodore PET in the development of which Chuck Peddle was actively involved appeared on sale half a year earlier than the Apple ][, although its mass production started only half a year later than the Apple ][. It and its variants were the first computers widely used in schools in the United States and Canada – one can only wonder why Commodore so easily lost its position to Apple in this business. It is also surprising that Commodore easily gave up its good position in the text editing business, where later Amstrad achieved impressive success. Earlier, Commodore, for still unclear reasons, left the calculator market. Also, for unclear reasons, the production of the very promising Commodore LCD laptop computer was abandoned. Nevertheless, the Commodore VIC-20 was the first home computer to sell more than a million units. The Commodore 64 became the most popular PC in history, with up to 17 million units sold. Atari game consoles produced from 1977 to 1996 were sold in the amount of approximately 35 million! But this is not a record, NES game consoles were sold about 62 million between 1983 and 2003. By the way, the NES used Ricoh's 6502 version without decimal mode support perhaps because of its almost complete uselessness or maybe simply because of the reluctance to get involved with MOS Technology patent for this mode. We can probably say that for most users until the end of the 80's, the door to the world of digital technology was precisely based on the 6502. The 6502 was also used in the keyboard controller of the Commodore Amiga, and two 6502's at 10 MHz were used in the high-performance Apple Macintosh IIfx. The 6502-based processor is used in the famous Tomagotchi digital pet: probably released in more than a hundred million copies. The 65816 was used in the rather popular Apple IIgs computer, and also in the rare Acorn Communicator computer. The Super NES game consoles based on the 65816 were produced from 1990 to 2003, approx. 50 million were sold. The 65816 was also used in some early e-book models.
Interestingly, of the three mass PCs that appeared in 1977, "the holy trinity", two were based on the 6502 and only one on the Z80. Unfortunately, the most important American computer manufacturers (Apple, Tandy RadioShack, IBM), from the 80's did not publish information about the number of PCs they produced.
In 1984, an article in Byte magazine about a bad copy of the Apple ][ computer, the Agat, made in the USSR appeared in the background of pictures with red banners, Lenin and marching soldiers. This article cited a curious price for this computer of $17,000 (it was an absurd amount, the real price was about 4000 rubles) and ironically indicated that Soviet manufacturers would have to dramatically lower the price if they wanted to sell their product in the West. The Agat was used mainly in school education. The older Agat models were almost 100% compatible with the Apple ][ and had some pretty useful extensions.
One can only try to fantasize about what would have happened if the 6502 had developed at the same pace as its competitors. It seems to me that the gradual moving of zero-page memory to registers, the improvement of instruction pipelining, and the gradual expansion of the command system with simultaneous optimization of cycles would allow The Terminator 6502 to remain in the lead in terms of performance until the early 90's. Introducing 16-bit mode and then 32-bit, would allow more memory and faster commands to be used. Would its competitors have been able to oppose this?
Bill Mensch was able to provide some support for the development of 6502. However, the capabilities of one person to support the competitiveness of a processor is clearly not enough. Bill, as an excellent electronics engineer was able to provide support for the execution of orders for the 6502 upgrade, but ensuring the independent development of a successful processor required a team. Someone had to develop an upgrade of the instruction system, someone had to develop new marketing strategies, etc. In addition, at least the years 1976-78 were lost for development, and one person was no longer able to catch up. In a sense, WDC created an illusion of well-being around the 6502 development situation, and this had a rather negative effect on the real development.
Although Chuck Peddle himself saw the future of the 6502 more as a cheap controller and competitor not for the Z80, but rather for microcontrollers like the Intel 8048 and processors like the 6800 which were usually used only as controllers. In 2014, he was working on a solid-state drive that used 10 pieces of the 6502-based controllers. In the early 80's, he and his partner created a company where he developed the Victor 9000 computer in 1981. The 8088 was used as a processor in this system – Chuck didn't think the 6502 would be the best choice for his personal computer.
Interestingly, Chuck himself, as well as some other key IT figures in the USA of the 1970s and 1980s, went to work using high technologies with the idea of preventing the backlog from the USSR in the development of IT, this idea was very popular after the launch of Sputnik. In this connection, we can also mention a key figure for Intel Bill Davidow whom Chuck greatly respected and kept in touch with.
Chuck passed away at the end of 2019. He studied under Claude Shannon and was the first to suggest using group encoding when working with disks. Although he failed to patent it, he developed disk drives in the late 70s and early 80s that allowed up to twice as much space as typical drives. This, in particular was used in some of the best Commodore disk drives and in the Victor computer. Then he made the first portable hard drive. That drive didn't break if it fell on the floor! Subsequently he worked with the production of low-cost RAM, after that, he developed the ultra-fast solid-state drive that has already been mentioned.
I would like to finish with some general philosophical arguments. Why the 6502 was slowed down in its development and deprived of a much brighter future? Maybe due to the fact that this development really could very much press large firms and create a completely new reality. Was the 6502 team set up for this? In my humble opinion, rather no, they just wanted to make a better processor. Perhaps they themselves did not understand how good their processor was and that speed is the main feature of any processor.
Already much later, at the beginning of the 21st century, with the help of lawsuits imposed from far-fetched reasons, the Lexra company, which produced various innovative processors for 5 years, was crushed. This sad story is somewhat reminiscent of what happened to MOS Technology.
Edited by Richard BN and Dr Jefyll