YTread Logo
YTread Logo

The 6502 CPU Powered a Whole Generation!

Apr 01, 2024
a turbo-XT   at 8 mhz. It's just not going to happen. So I hope this better illustrates that CPU megahertz is not a good method of comparing speed between different types of CPUs. Let's switch gears for a moment and talk about some technical details, specifically mathematical ones. So, many people might ask: "if the processor can only handle 8-bit numbers, such as numbers 0 to 255, how can it possibly perform mathematical operations on numbers larger than that?" Imagine you have two 16-bit numbers that you need to add. Well, you can't do it all at once. Therefore, as a programmer you will need to add the least significant bytes and get the result.
the 6502 cpu powered a whole generation
But the sum of these two values ​​exceeds 255, so the carry bit will be set. So the next addition you do, here it will take that into account and voila, you'll get the 16-bit result. So really, the only downside to working with larger numbers on an 8-bit CPU is that it requires more instructions, making the code longer and more cycles than performing the same operation on, say, a CPU. 16 bit. Well, one thing you may find particularly interesting is that the

6502

doesn't actually have instructions for multiplying or dividing. But, I'm sure you've guessed, there is a way to achieve this.
the 6502 cpu powered a whole generation

More Interesting Facts About,

the 6502 cpu powered a whole generation...

Actually, more than one way. The simplest way to multiply is by bit shifting. There is an instruction to shift all bits left or right. So, take this binary number, which is equal to 26 in decimal. If you shift the entire bit to the left, you will basically multiply the number by two. You can do it again and now you have multiplied by 4, and again and now you have multiplied by 8. Similarly, you can shift a number to the right and you can divide by 2, divide by 4, divide by 8, or here even divide by 16. So multiplying or dividing by powers of 2 is very easy to do and very fast.
the 6502 cpu powered a whole generation
But let's take the original number and say you need to multiply it by a number that is not a power of 2, like the number 6. Well, you can achieve this by moving left twice, that allows you to multiply by 4. Then you take the original number and You move it just once to the left, that is multiplied by 2, and then you can add them together and you have the result. This method is also quite fast. And of course, the last method is to simply use a graph. Simply store all results in RAM as part of your code. And then let's say you need to multiply 5 by 9, you can just look up the answer in the table and there you have it.
the 6502 cpu powered a whole generation
Therefore, you might think that these methods are too complicated or time-consuming. But here's an interesting little anecdote. When I started coding Planet But one of the things I realized once I started trying to optimize game speed is that using bit shifts or lookup tables was significantly faster than using the built-in multiply and divide commands. So, I ended up removing all those multiply and divide commands and replacing them with the same techniques I had been using all along on the

6502

. So, it turns out that those multiply and divide commands really aren't that useful. after all. Let's take a look at how the regular 6502 compares to some of the variants.
The Atari 2600 used a processor known as the 6507, which as you can see is a smaller package with fewer pins. I would like to draw your attention to the address bus. As you can see, there are only zero to 12, instead of 0 to 15. That reduces the addressable memory to 8 kilobytes instead of the usual 64. That's also why Atari 2600 cartridges are typically limited to 8KB, unless clever banking schemes are used. They are used. Now let's look at the 6502C, also called the Sally chip. This chip was used in later Atari computers, such as the XL and XE series, and in game consoles such as the 7800.
It is basically the same as a regular 6502. These 4 pins here are rearranged. The main reason for this is that they wanted to add the HALT signal so that the CPU could be temporarily stopped and the video circuits could use DMA. Now let's look at the 6510, which was used in the Commodore 64. As you can see, basically each pin is in a different place. But the main difference is these P0 to P5. These are essentially general purpose IO pins. On the Commodore 64 they are used for memory storage. This was essentially a cost saving measure to add this to the CPU as it eliminated extra circuitry on the board.
Well, I'm not going to cover all the variants, as that would take forever. You can see here on Wikipedia for a list of all CPU variations. But I just wanted to give you an idea of ​​the ways most of them differ. But I do want to take a look at the Western   Design Center 65c02. It was released in 1983 and, as far as I know, is the only variant still in production today. This CPU was used in the Apple IIe and IIc, Laser 128, and Atari Lynx, among others. One of the big differences is the instruction set. This is the standard 6502 instruction set.
There are some undocumented opcodes, but we won't go into that. 65c02 added these new opcodes. Most of them are designed to make life easier for the programmer, as well as to make execution a little faster. The old code will still run on this CPU, but it will not use any of these new instructions. In fact, I want to show you something that many people don't know. This is a regular Commodore VIC-20 and I'm going to remove the CPU. It's just a standard 6502, which is to be expected. And here we have a new 65c02 from Western Design Center.
And what I'm going to do is insert this into the VIC-20 and turn it on. And well, if you thought it was going to work, I guess you'll be disappointed. The reason it doesn't work has nothing to do with the new opcodes, but rather the pin layout. If you compare the two processors, you will see that they have almost identical pin layouts. In fact,   only these 3 pins are different. I'm not going to go into too much detail about what they do. But let's see if we can get this to work on the VIC-20. I'll start by bending two of those pins that were different.
I'll just leave one unplugged and the other I'll use a resistor and connect it to 5V, turning it up. I know, it doesn't look very elegant. But let's put it back into the VIC-20 now and see what happens. Check it, it works. At this point, the VIC-20 now has additional instructions available if you want to write code to support it. And although this CPU can run at 14mhz, it will obviously only run at the clock speed given to it by the VIC-20, which is still 1mhz. Therefore, there is no big advantage in using this. I ran several games and didn't have any compatibility issues, although I'm sure there were probably at least one or two that were using some undocumented opcodes that could fail with this internal CPU.
Okay, now let's take a look at 65c816. This chip debuted in 1985 and is a significant upgrade from the 6502. This chip is 16-bit, more or less. You see, there is no standard way to define how many bits a CPU has. Some people judge it based on the width of the data bus. In this case, the data bus is still 8-bit, like the 6502. But internally, it can perform 16-bit math. It also has many other new features. In fact, here are the opcodes we saw earlier for the 65c02. Well, the 816 supports all of these opcodes. In fact, when it boots up, it does so in 8-bit mode, so it basically works exactly like the 65c02.
There are some small differences, I'm sure some of you keyboard warriors will want to point them out. For example, some 65C02s made by Rockwell and WDC had these additional instructions here. I didn't show them before because not all variants support them and they are not used very often. But the 816 definitely doesn't support them and instead adds them all when operating in 16-bit mode. When doing 16-bit math, that means that instead of requiring 6 or 7 instructions to solve problems like this half at a time, you can do it all in a single instruction. These kinds of things can really speed up the execution of certain types of software.
But perhaps a more important aspect of the chip is the larger address bus. Let me show you how it works. The pin layout of the 816 is very similar to the 6502, but it is a little more complicated to get started on an older computer because, as you can see, there are now 9 pins that are different from the original. but you might be counting the address lines and see that there are still only 0 to 15. So how can you access more than 64 KB, you might ask? Well, when you put the chip in the right mode, the data bus pins will do double duty.
So when the clock cycle is high, it's data lines as usual. but when the clock is low, they become address lines 16 through 23, giving you a 24-bit address, capable of addressing up to 16 MB of RAM, a huge amount more than a typical 8-bit computer. So can you install one of these on something like a VIC-20? Kind of. You're going to need a title adapter board like this one, which is very hard to find right now. But in theory, you can install this on your VIC-20 or other 8-bit system and instantly have a 16-bit capable computer, except you won't have access to the extra RAM.
Perhaps a better example, something I can actually show off, is the Commander X16. By default it comes with a 65c02, but it is actually compatible with the 816. I have one available to test and I have a large label so I don't confuse it with my other CPUs. But yes, the I think the 816 was a really fantastic processor, but it only saw widespread use in Apple IIgs and Super Nintendo. So the last thing I have for you is that I finally got to sit down and have a conversation with Bill Mensch, one of the original creators of the 6502 and 816 processor, and I had a few questions for him.
So, Bill, tell me who the current, modern customers of the 6502 are. Well, we have a lot of interest in your world, that is, the hobby world. And so we sell boards for that. and we sell chips   for that. And as you and Ben Eater know, Ben Eater has been especially active in that world. And then we have some others, Stefany, I think you know. But in any case. I find it hard to believe that the retro market alone keeps the entire 6502 business alive. There must be more modern customers. And the other thing we still get royalties for is life support.
Thus, we keep millions of people alive one heartbeat at a time, with 65c02. Actually? Why do you think the 6502 architecture didn't last long beyond the 16-bit era, like the Apple IIgs and Super Nintendo? Is it just because everyone opted for MS-DOS compatibility or was there some other reason? Well, I was specifically recommending ARM. OK. So when my licensees asked me what I was doing in 32-bit, I said, "Well, I have some specs for 32-bit. I'm happy to share them with you, but I don't think that's what you want." "Well, if you've made it this far, you've probably learned more about the 6502 than you probably ever wanted to know.
But I hope you at least have a little understanding of the important role the CPU has played over the last 40 years and also why It's my favorite CPU. But that's all I have for now, so as always, thanks for watching!

If you have any copyright issue, please Contact