The 6502 CPU Powered a Whole Generation!

The 8-Bit Guy
26 Mar 202425:16

Summary

TLDR本视频回顾了6502微处理器的历史和影响,这是20世纪80年代许多家用电脑和游戏机的核心。介绍了6502的基本功能、与其他芯片的通信方式以及它的一些变体,如6507、6502C和6510。还探讨了6502在现代的应用,包括在生命维持设备中的使用,以及与Bill Mensch的访谈,他是6502和816处理器的共同创造者。

Takeaways

  • 📺 6502微处理器是1980年代许多家用电脑、街机和游戏控制台的核心部件。
  • 🔍 6502处理器有多种变体,有些增加了额外功能,有些则为了更小或更便宜而移除了某些功能。
  • 🎮 6502处理器被广泛应用于许多经典游戏机,如Atari 2600、NES以及SNES。
  • 🚀 6502处理器甚至被用于一些非传统的设备,如玩具、心脏起搏器和卫星。
  • 💡 6502处理器的成功部分归因于其高性价比,与同期的Motorola 6800相比价格更低。
  • 🔧 6502处理器的设计允许它与其他芯片通过数据总线、读写线和片选信号线进行通信。
  • 🔩 6502处理器的8位数据总线可以传输8位数字,而其16位地址总线可以寻址高达64KB的内存。
  • 🏎️ 6502处理器在性能上与其他同期处理器相比具有竞争力,即使工作频率较低。
  • 🌐 6502处理器的变体在针脚排列和功能上有所不同,以适应不同的应用需求。
  • 📈 65c02是6502的一个变体,增加了新的指令集,提高了编程效率和执行速度。
  • 🛠️ 65c816是6502的重大升级版本,内部可以执行16位数学运算,并具有更大的地址总线。
  • 🗣️ 与Bill Mensch的对话揭示了6502处理器的现代应用,包括业余爱好者市场和生命维持设备。

Q & A

  • 6502微处理器是由哪家公司开发的?

    -6502微处理器是由MOS Technology公司开发的。

  • 6502微处理器在1980年代的哪些设备中被广泛使用?

    -6502微处理器在1980年代被广泛应用于家用电脑、街机游戏机、视频游戏控制台等设备中。例如Commodore PET、VIC-20、Apple II系列、Atari 400和800家用电脑、Oric Atmos、大部分Acorn电脑以及BBC微型电脑等。

  • 6502微处理器有哪些变种?

    -6502微处理器有多种变种,这些变种或者增加了一些额外的功能,或者在某些情况下为了使芯片更小或更便宜而移除了某些功能。这些变种包括用于Commodore 64和128、Plus/4、Apple III和IIgs、Atari的XL和XE系列家用电脑以及他们的磁盘驱动器中的变种。

  • 6502微处理器的8位数据总线是如何工作的?

    -6502微处理器的8位数据总线通过8个引脚与其它芯片进行通信,每个引脚可以表示1或0,以此来传输8位的数字。数据总线与读写线(read/write line)一起工作,通过读写线的状态来确定数据传输的方向是读取还是写入。

  • 什么是芯片选择(CS)线?

    -芯片选择(CS)线是CPU用来控制数据总线上的各个芯片何时可以进行通信的一条线。当这条线被激活时,意味着对应的芯片被允许在数据总线上进行通信。

  • 6502微处理器的地址总线是几位的?

    -6502微处理器的地址总线是16位的。这意味着它可以表示从0到65,535(或64KB)的地址范围,决定了计算机的最大内存容量。

  • 为什么内存模块在增加到下一个尺寸时总是翻倍?

    -内存模块在增加到下一个尺寸时总是翻倍,这与二进制寻址有关。因为每增加一个地址线,就相当于在二进制数中增加了一个位数,这将使得最大地址值乘以2。

  • 6502微处理器与Z80微处理器在性能上有何不同?

    -尽管Z80微处理器的时钟频率通常比6502高,但6502在每个时钟周期内可以完成更多的工作,因为它在时钟脉冲的上升沿和下降沿都进行操作。此外,6502在完成指令所需的时钟周期平均上比当时的其他CPU要少。

  • 6502微处理器在现代有哪些应用?

    -6502微处理器在现代仍有一些应用,包括作为复古计算和游戏设备的CPU,以及在一些生命维持设备中使用。此外,它还被用于一些玩具、游戏机和某些嵌入式系统中。

  • 65c816处理器与6502处理器的主要区别是什么?

    -65c816处理器是6502的16位升级版本,它在内部可以执行16位的数学运算,并且具有更大的地址总线,可以访问高达16MB的RAM。它在启动时以8位模式运行,与6502兼容,但在16位模式下可以利用更多的指令和更大的内存地址空间。

  • 为什么6502架构没有在16位时代之后继续广泛使用?

    -6502架构没有在16位时代之后继续广泛使用的原因包括市场转向MS-DOS兼容性更强的系统,以及技术发展到32位处理器的趋势。此外,ARM等更先进的处理器架构的出现也导致了6502架构的使用减少。

  • 如何将65c816处理器安装到原本使用6502的系统中?

    -将65c816处理器安装到原本使用6502的系统中通常需要一个适配板,因为65c816的引脚排列与6502略有不同。但是,一些系统如Commander X16默认支持65c816,可以直接安装并使用。

Outlines

00:00

📺 6502微处理器的黄金时代

本段落介绍了6502微处理器的历史背景和广泛应用。6502微处理器在1980年代初期推动了家用电脑、街机游戏和视频游戏控制台的普及。MOS Technology公司生产的6502处理器因其高性能和低成本而成为了当时众多设备的心脏。从Commodore PET、VIC-20、Apple II到Atari 400和800等家用电脑,再到Asteroids、Centipede等街机游戏,6502微处理器几乎成为了那个时代的代表。此外,6502的变种也被广泛应用于Commodore 64、128、Plus/4、Apple III和IIgs等设备中。

05:04

🔍 6502微处理器的技术细节和工作原理

这一部分深入探讨了6502微处理器的技术细节和工作原理。通过解释数据总线、读写线和芯片选择(CS)线的作用,阐述了CPU如何与其他芯片进行通信。同时,介绍了6502的8位数据总线和16位地址总线,解释了为什么内存模块的容量总是按二的幂次增加。此外,还比较了6502与其他同期流行CPU(如Z80)的性能差异,并指出6502在每个时钟周期内能完成更多工作,因此在相同时钟频率下,6502的实际性能并不逊色于其他CPU。

10:07

🚀 6502微处理器的实际应用和性能对比

本段落讨论了6502微处理器及其变种在不同设备中的运行频率和性能表现。举例说明了Atari 2600、Apple III、BBC Micro、Commodore 128、Apple IIgs、Super Nintendo等设备的运行频率,并探讨了这些设备的性能。特别提到了Super Nintendo和Apple IIgs使用的是6502的16位版本65816。通过比较不同设备的性能,展示了6502处理器的强大能力和灵活性。

15:13

🤖 6502微处理器的数学运算和指令集

这一部分探讨了6502微处理器如何处理超出8位范围的数学运算,解释了通过指令和位操作来实现乘法和除法的方法。同时,讨论了6502没有专门的乘法和除法指令,但可以通过位移和查找表等技术来实现这些操作。此外,还提到了6502与Z80等其他处理器的数学性能对比,以及如何通过位操作和查找表来优化性能。

20:14

🌐 6502微处理器的变种和现代应用

本段落介绍了6502微处理器的不同变种,如6507、6502C(Sally芯片)、6510和65c02等,以及它们在不同设备中的应用。特别提到了65c02在Apple IIe、IIC、Laser 128和Atari Lynx等设备中的使用,以及它增加的新指令集。同时,讨论了65c816处理器的特点,包括它的16位内部数学运算能力和更大的地址总线。最后,通过与Bill Mensch的对话,揭示了6502微处理器在现代的持续应用,特别是在生命维持设备中的重要性,以及它为何没有在16位时代之后继续流行。

Mindmap

Keywords

💡6502微处理器

6502微处理器是MOS Technology公司在1975年推出的一款8位微处理器,它在20世纪80年代的家用电脑、游戏机和许多其他电子设备中得到了广泛应用。这款处理器因其高性能、低成本而广受欢迎,成为了一个时代的标志。

💡家用电脑

家用电脑是指在20世纪80年代初期,随着技术进步和成本降低,普通家庭能够负担得起的个人电脑。这些电脑通常具备基本的文本处理、编程和游戏功能,极大地推动了个人电脑的普及。

💡游戏机

游戏机是指专门用于玩游戏的电子设备,可以是家用游戏机、街机游戏机等。这些设备通常包含一个或多个微处理器,用于运行游戏程序,提供图形和声音输出。

💡数据总线

数据总线是计算机中用于传输数据的通道,它连接CPU和其他硬件设备,如内存、输入输出设备等。数据总线的宽度(比如8位、16位、32位)决定了处理器一次能够处理的数据量。

💡读/写线

读/写线是CPU用来控制数据流向的信号线。当这条线被激活时,它会指示数据是从CPU读取还是写入到其他设备。这是计算机内存管理中的一个重要概念。

💡芯片选择(CS)线

芯片选择(Chip Select,简称CS)线是CPU用来激活特定硬件设备的信号线。当CS线被激活时,相应的硬件设备被允许在数据总线上进行通信。

💡地址总线

地址总线是计算机中用于指定内存地址的通道。它允许CPU访问内存中的数据或告诉其他设备数据应该发送到哪个内存地址。地址总线的宽度决定了计算机可以直接寻址的内存大小。

💡指令集

指令集是一组预定义的命令,CPU可以通过这些命令来执行各种操作。每个处理器都有其特定的指令集,这些指令集定义了处理器能够执行的操作类型。

💡变种处理器

变种处理器是指原始处理器的修改版,它们可能增加了一些新功能,或者为了使芯片更小、更便宜而移除了某些功能。尽管它们运行相同的机器代码,但可能在物理接口上有所不同,如引脚布局。

💡嵌入式系统

嵌入式系统是指嵌入到设备中的专用计算机系统,它通常是为了控制、监控或与外部设备进行通信而设计的。这些系统往往对成本、功耗和空间有严格的要求。

💡摩尔定律

摩尔定律是由英特尔联合创始人戈登·摩尔提出的观察,它预测集成电路上可容纳的晶体管数量大约每两年翻一番,这通常与计算能力的增长相对应。这一观察对半导体行业的发展有着重要影响。

Highlights

6502微处理器在1980年代推动了家用电脑、街机和游戏控制台的普及。

6502微处理器由MOS Technology公司开发,成为那个时代的标志。

6502微处理器的变体在不同的计算机和游戏控制台中广泛应用。

6502微处理器的8位数据总线和读写线是其与其他芯片通信的关键。

6502微处理器的地址总线为16位,能够寻址高达64KB的内存。

6502微处理器在性能上与其他同期CPU相比具有竞争力,即使工作频率较低。

6502微处理器能够在每个时钟周期的上升和下降阶段都进行工作,提高了效率。

6502微处理器缺乏乘法和除法指令,但可以通过位移和查找表等方法实现这些操作。

6502微处理器的变体,如65c02,增加了新的指令集以提高编程效率。

65c816微处理器是6502的16位升级版,内部可以执行16位数学运算。

65c816微处理器通过数据总线在不同模式下同时充当地址总线,扩展了寻址能力。

6502微处理器在现代仍有应用,如玩具、心脏起搏器和卫星中。

6502微处理器的创新设计使其在计算机历史上占有重要地位。

与Bill Mensch的访谈揭示了6502微处理器的创造者对其历史和未来的看法。

6502微处理器的低价位使其在个人电脑革命中发挥了重要作用。

6502微处理器的简单性和效率使其成为爱好者和工程师的首选。

Transcripts

00:11

I have made countless videos about old computers  from the 1980s, but in this episode we're going  

00:16

to have a look at the processor that powered  them all, or at least most of them. And then  

00:21

at the end of the video we're going to have  a quick chat with Bill Mensch, one of the  

00:24

original creators of the 6502 microprocessor The 1980s brought us affordable home computers  

00:30

for the first time ever, arcade  machines, and of course video game  

00:35

consoles. There was one microprocessor that  seemed to be ubiquitous. One processor that  

00:37

seemingly powered an entire generation. And  that processor was the 6502 by MOS Technology. 

00:44

I want to start with the standard 6502. There  were at least a dozen variants of it that were  

00:49

more or less compatible, but might not  be pin-compatible, and we'll come back  

00:53

to those later. So, let's start by having a look  at some of the computers that used the official,  

00:57

standard 6502. These would be the Commodore PET,  and the VIC-20 The original Apple II and II+. Also  

01:06

the Atari 400 and 800 home computers, the Oric  Atmos, most of the Acorn computers like the Atom  

01:12

and Electron series, and of course the BBC micro. There were also dozens of arcade machines that  

01:18

used the 6502, more than I want to cover here.  But if you've ever played Asteroids, Centipede,  

01:24

Missile Command, Tempest, crystal castles, or  ever really stepped into an arcade of any sort,  

01:31

you've probably played some  machines that ran on the 6502. 

01:35

All of these systems used a standard 6502  processor. And what I mean by that is,  

01:39

you can take the CPU out of say a VIC-20,  stick it in a very different kind of computer,  

01:44

such as an Apple II, and it will just work.  You can even pull the 6502 out of a Commdore  

01:49

disk drive and stick it in an Atari 400, and it  would work just fine. It's strange today to think  

01:55

of all of these different incompatible  computers running the same exact chip. 

02:01

However, the scope of the 6502 reaches  far beyond these. When you start looking  

02:05

at the variants, the list becomes huge. So, what is a variant exactly? Well, these  

02:10

are other versions of the 6502 that have either  added some extra features, or in some cases even  

02:16

removed features in order to make the chip either  smaller or cheaper. They all run the same machine  

02:22

code as the original, but they aren't necessarily  pin compatible, meaning you can't pull one out  

02:27

of one type of machine and then stick it in a  different kind of machine and expect it to work. 

02:31

Computers that used variants would be the  Commodore 64 and 128, and the Plus/4. Also  

02:38

Apple used variants in the Apple III and IIgs.  Atari used them in the XL and XE series of home  

02:44

computers, and even inside their disk drives. Another popular use of the 6502 was of course,  

02:49

in game consoles. This would include the Atari  2600, 5200, 7800, and the Lynx handheld. More  

02:56

importantly Nintendo used a variant in the NES, as  well as the Super Nintendo, and the TurboGrafx 16. 

03:04

But what might surprise you would be some of  the not so obvious places you can find 6502  

03:09

processors. Ever played with a Furby, yeah, those  run on a 6502. How about a Tamagotchi, surprise,  

03:15

those run on a 6502. In fact, there are countless  toys that have a 6502 core, but they are really  

03:22

hard to catalog for you because they are usually  embedded into an epoxy blob these days, making it  

03:26

really hard to tell just by opening up a toy. Here's one that may surprise you. If you have  

03:32

a pacemaker or any sort of implanted technology  in your body, it is very likely running a 6502  

03:37

inside. There are even 6502 processors  orbiting the planet inside satellites,  

03:42

and I believe they were used in few minor  systems on the space shuttle and international  

03:46

space station, although I don't know if  there are still any in use there today. 

03:50

And apparently the terminators of the future  also run on 6502 as the computer code seen on  

03:56

screen is 6502 assembly instructions,  and if Futurama is to be believed,  

04:00

then a thousand years from now, robots like  Bender will be operating on 6502 processors. 

04:06

The point is, unless you have been living under  a rock your whole life, everyone on the planet  

04:10

has at some point interacted with this processor. But, let's go back in time to the beginning. Back  

04:15

to 1975. Many notable things were happening.  Gerald Ford was President of the USA. Disco  

04:21

music was at its peak. The Rubiks cube went  on sale. The movie Jaws just came out. And,  

04:27

the Vietnam war was coming to an end. Oh,  and The 8-Bit Guy was born, that's me. 

04:33

But in the world of technolgy, there were  also many exciting things happening that  

04:37

year. Video Cassette Recorders for home users  entered the market. The Altrair home computer  

04:42

kit was introduced. A little software company  called Microsoft was started. And of course,  

04:47

more importantly for the purposes of this  video, the 6502 Microprocessor went on sale. 

04:53

For the first year, it was being sold for $25  a unit, which was crazy cheap compared to its  

04:57

nearest competitor, the Motorola 6800, which  sold for $175 a unit. At this time it was mostly  

05:04

being used in hobby and enginering projects  like the KIM-1 computer, and later in Steve  

05:09

Wozniak's little computer, the Apple 1. But, let's skip forward to 1977, a year  

05:15

mostly remembered for the debut of the Star Wars  franchise, was also the year the 6502 really took  

05:21

off. Computers like the Apple II and Commodore  PET entered the market. Two of the big-3 home  

05:26

computers of that year used the 6502. But the  real volume would come, not from a home computer,  

05:32

but from the Atari 2600 video game console.  Atari would sell nearly 400,000 units of the  

05:38

2600 in 1977 alone, and eventually over 30  million of them over the life of the product. 

05:45

Needless to say, this was just the tip of the  iceberg. but now let's have a look at some of the  

05:50

features of this chip, and see how it worked. I want to start by talking about how the CPU  

05:54

communicates with other chips. 8 of the pins on  the CPU represent the data bus. Each of these  

06:00

can be either on or off, which represent a 1 or  zero. Hence, this is an an 8-bit data bus. So,  

06:06

for illustration we'll connect this to the  data bus of a RAM chip. This way the CPU and  

06:10

the RAM chip can send and receive 8-bit numbers. But there's another important line that the CPU  

06:15

controls. This is the read/write line. If  the line is on, its means to read and thus  

06:20

the data is expected to travel this direction.  If the line is off, then it means write, and  

06:25

the data will travel in this direction instead. And so this line also has to connect to the RAM  

06:30

chip so both the CPU and the RAM chip understand  the direction data is flowing at any given time.  

06:36

OK, hopefully all of this makes sense so far. Of  course, most any motherboard is going to be far  

06:41

more complicated than this, because there will  be a lot more chips like I/O chips, video chips,  

06:45

etc. And they all connect to the same data bus. So the question is, how do they all talk over  

06:50

the same data bus at the same time without  signals colliding with each other? Well,  

06:54

they don't. They are all allowed to listen  to the bus, but only allowed to talk on the  

06:58

bus when the CPU wants to talk to them. So how  does that work? Well, each chip on the bus has  

07:04

a CS line. It stands for Chip Select. Sometimes  it may be called an Enable line. Either way,  

07:09

it does the same thing. When this line is  activated, that means the chip is allowed  

07:13

to talk on the bus. That chip could be a RAM  chip, ROM chip, I/O chip, video chip, whatever. 

07:18

So the next question is, what determines when  that chip is activated? OK, we have the data bus,  

07:23

and the read/write line. But we also  have something called the address bus,  

07:27

which on the 6502 is 16 bits. So, while the data  bus can communicate in numbers between 0 and 255,  

07:33

the address bus can represent numbers between 0  and 65,535, or another way of saying that is 64  

07:39

Kilobytes. The size of the address bus determins  the maximum memory of the computer, not counting  

07:44

banking schemes, which we can get into later. Have you ever wondered why memory modules,  

07:48

when they increase to the next size, are always  double the previous size? They increase in powers  

07:53

of two. Well, the reason for that has to do with  binary addressing. So, imagine you have a RAM chip  

07:58

that is 16 megabytes in size. It would need 24  address lines to be able to access all of that  

08:03

RAM. And that means a minimum address of zero, or  a maximum address of, well, a bunch of ones. So,  

08:09

if you wanted to make the chip bigger, there's  no way to really add fractional amounts of RAM.  

08:14

You would have to add an additional address  line. In doing so, you've also added another  

08:18

number to your binary number, which will always  result in multiplying the max value by two. 

08:23

So, back to our CPU address bus. The way this  works is it goes into a bunch of decoding logic,  

08:28

which I'm not going to get into here,  but that logic will take the address and  

08:31

determine which of the chips will be selected,  whether it is RAM, ROM, or a video chip, etc. 

08:37

Now, much of what I've shown here could be applied  to most any CPU. But now I want to tell you a few  

08:42

things that sets the 6502 apart. So, let's compare  with the Z80 , another popular CPU of the era. It  

08:48

was quite common for 6502 systems to run at  1 Mhz, and Z80 systems to run at 4 mhz. Now,  

08:55

you might be tempted to think the Z80 would  be 4 times faster. But it's not. Why is that? 

09:01

Well, for one thing let's look at the clock pulse.  Imagine this is your 1 mhz clock pulse. Most CPUs  

09:07

would only be doing work at the top of the clock  pulse like this. However, the 6502 also does work  

09:13

on the bottom of the clock pulse like this,  essentially doing twice as much work per clock  

09:17

cycle than a typical CPU. But that isn't the only  thing that makes a difference. Most instructions  

09:23

require more than one clock pulse to complete and  the 6502 requires fewer cycles on average than  

09:28

other CPUs of the era to complete an instruction. The Z80 was especially inefficient because,  

09:34

despite being an 8-bit CPU, it's ALU, or  "Arithmetic Logic Unit" is only 4 bit,  

09:40

and thus most calculations require extra  clock cyclces to complete any 8-bit math. 

09:45

So, let's compare 4 common CPUs from the 1980s  at their most common clock frequencies. If you  

09:50

look at raw performance, the 6502 actually  competes well against the other CPUs even  

09:55

at its much lower clock speed of 1 Mhz.  The moment you double it to even 2 Mhz,  

10:00

it suddenly outperforms just about everything  except the 68000. Most systems ran at 1 Mhz,  

10:06

but there were some that ran just a bit faster. Atari 2600 ran at 1.19 Mhz 

10:13

Basically all subsequent Atari computers  and game consoles ran at 1.79 Mhz. 

10:19

interestingly enough, the original  Nintendo also ran at 1.79 Mhz 

10:24

Apple III ran even faster at 1.8 Mhz The BBC Micro ran at 2.0 Mhz 

10:30

as did the Commodore 128,  but only in 80 columns mode. 

10:35

The Apple IIgs ran at 2.8 Mhz The Super Nintendo 3.58 Mhz 

10:41

And the fastest machines from the time period  that I know of are the Apple IIc Plus and some  

10:46

clones like Laser 128 ex2, which ran at 4  Mhz. I know 4 Mhz doesn't sound like a lot,  

10:53

but that was some serious speed. unfortunaetly,  there was little to no software that really took  

10:57

advantage of that. So the best examples we  really have of what could be done at the  

11:01

time would be to look at the Super Nintendo. The problem is, it's hard to say exactly what  

11:06

aspects of these games you can really credit  the CPU, versus some of the advanced graphics  

11:11

co-processors that were also in the system. In  fact, some of these games, like starfox, even used  

11:16

a 3D coprocessor located in the cartridge itself. The Apple IIgs might be a better system to look  

11:22

at since it had much less in terms of graphics  acceleration, thus relying primarily on the CPU  

11:28

for most of the work. of course, another  problem is the Super Nintendo and Apple  

11:33

IIgs are technically running 65816 CPUs,  which is the 16-bit version of the 6502,  

11:39

which we're going to come back to here in a little  bit. That being said, one interesting comparison  

11:44

is Wolfenstein 3D. This is the SNES version.  And while there is some amount of graphics  

11:50

acceleration on the SNES, the CPU is really  doing the heavy lifting of rendering this game. 

11:55

Now let's look at the Apple IIgs version. It uses  the exact same processor, but lacks most of the  

12:00

accelerated graphics features. That's why the  game is scaled down to the center of the screen,  

12:05

even though technically the level of detail  is exactly the same as the SNES version. And  

12:10

you may notice it runs a little slower, which  makes sense because the CPU in the Apple IIgs  

12:15

is slower. But now check this out. This is the  same version but here the Apple IIgs has an 8 Mhz  

12:21

accellerator in it. So, same type of processor,  just running almost 3 times faster. In fact,  

12:26

with this CPU you can expand the rest of the  screen out and it still plays relatively decently. 

12:33

Modern versions of the 6502, made by  WDC are actually rated to run at 14 Mhz,  

12:39

and I've heard of people overclocking them to run  even faster. The commander X16 runs at 8 Mhz, and  

12:45

thus might be a good example of what can be done. Planet X16, which is a real-time-strategy game I  

12:50

wrote for the Commander X16, is a somewhat  interesting example. Believe it or not,  

12:54

it runs just about perfectly, even if I jumper the  computer down to 4 Mhz. And that's why we're also  

13:00

working on a port for the Super Nintendo which  is close enough to that speed. I hope to show  

13:04

you more of this in a later episode, but I think  it will be a very interesting game for the SNES. 

13:10

A better example might be the KG3D demo on  the Commander X16, running a bog standard  

13:15

8-bit 6502 at 8 mhz. As you can see, this 3D  environment runs very smoothly at 8 Mhz. Now,  

13:23

for those that grew up with IBM PCs, imagine  trying to run something like this on a turbo-XT  

13:28

at 8 mhz. It's just not going to happen. And  so, I hope this better illustrates that CPU  

13:34

megahertz isn't a good method for comparing  speed between different types of CPUs. 

13:39

Let's switch gears for a moment and talk about  some technical details, specifically math. So,  

13:45

a lot of people might ask the question, "if the  processor can only deal with 8 bit numbers as in  

13:49

numbers from 0 to 255 how can it possibly do  math operations on numbers larger than that?" 

13:55

Imagine you have two 16-bit numbers you need to  add together. Well, it can't do it all at once.  

14:00

So, as a programmer you'll need to add the least  significant bytes together and get the result. But  

14:05

adding these two values exceeds 255, so that will  set the carry bit. So the next addition you do,  

14:10

over here will take that into account and  there you go, you'll get your 16 bit result. 

14:16

So really, the only downside to working with  larger numbers on the 8bit CPU is that it  

14:20

does require more instructions, which makes  the code longer and more cycle counts than  

14:25

performing the same operation on, say a 16bit  CPU. Well, one thing you may find particularly  

14:30

interesting is the 6502 actually has no  instructions for multiply or divide. But,  

14:36

I'm sure you've guessed, there is a way to  accomplish that. Actually, more than one way. 

14:40

The easiest way to multiply is with bit shifting.  There is an instruction to shift all of the  

14:44

bits to the left or right. So, take this binary  number, which is equal to 26 in decimal. If you  

14:49

shift everything to the left by one bit, then you  essentially multiplied the number by two. You can  

14:54

do it again, and now you've multiplied by 4, and  again and now you've multiplied by 8. Likewise,  

14:59

you can shift a number to the right, and you can  divide by 2, divide by 4, divide by 8, or here  

15:05

even divide by 16. So, multiplying or dividing  by powers of 2 is very easy to do, and very fast. 

15:12

But let's take the original number and let's say  you need to multiply it by a number that is not a  

15:16

power of 2, such as the number 6. Well, you can  accomplish that by shifting twice to the left,  

15:21

that gets you multiply by 4. Then you take  the original number and shift it just once  

15:26

to the left, that multiplies by 2, and then  you can add those together, and you have  

15:30

your result. This method is also fairly fast. And of course, the last method is by simply  

15:35

using a chart. You just store all of the results  in RAM as part of your code. And then let's say  

15:40

you need to multiply 5 times 9, you can just look  up the answer in the table, and there you have it. 

15:45

So, you might think these methods are overly  complicated or slow. But, here's a little  

15:49

interesting anecdote for you. When I started  coding Planet X3 on the 8088 microprocessor, at  

15:55

first I was really excited that I finally had use  of built-in commands for multiply and divide. But,  

16:01

one of the things I realized once I started trying  to optimize the game for speed is that using bit  

16:06

shifts or lookup tables was actually significantly  faster than using the built-in multiply and divide  

16:11

commands. So, I ended up actually stripping  out all of those multiply and divide commands  

16:15

and replacing them with the same techniques  I had been using all along on the 6502. So,  

16:20

it turns out um those multiply and divide  commands really aren't all that useful after all. 

16:25

Let's take a look at how the regular 6502 compares  to some of the variants. The Atari 2600 used a  

16:31

processor known as the 6507, which as you can  see is a smaller package having fewer pins. I'd  

16:37

like to draw your attention to the address bus.  As you can see there are only zero through 12,  

16:41

instead of 0 through 15. That reduces the  addressable memory down to 8 kilobytes  

16:47

instead of the usual 64. That is also why Atari  2600 cartridges are typically limited to 8 KB,  

16:53

unless clever banking schemes are used. Now let's look at the 6502C, otherwise  

16:58

called the Sally chip. This chip was used in  Later Atari computers like the XL and XE series,  

17:04

and game consoles like the 7800. It's basically  the same as a regular 6502. These 4 pins over  

17:10

here are re-arranged. The main reason for this  is that they wanted to add the HALT signal so  

17:15

that the CPU could temporarily be halted  so that the video circuits could use DMA. 

17:21

Now let's look at the 6510, which was used in the  Commodore 64. As you can see, basically every pin  

17:27

is in a different place. But the main difference  is these P0 through P5. These are essentially  

17:32

general purpose IO pins. In the Commodore 64 they  are used for memory banking. This was essentially  

17:38

a cost saving measure to add this into the CPU  as it eliminated extra circuits on the board. 

17:44

OK, so I'm not going to cover every variant  as that would take forever. You can see here  

17:48

on Wikipedia a list of all of the variations  of the CPU. But I just wanted to give you an  

17:53

idea of the ways in which most of them differ. But, I do want to take a look at the Western  

17:58

Design Center 65c02. This launched in 1983 and  it's the only variant to my knowledge that is  

18:04

still in production today. This CPU was used in  the Apple IIe, and IIc, Laser 128, and the Atari  

18:11

Lynx, among others. One of the big differences  is the instruction set. This is the standard 6502  

18:17

instruction set. There are some undocumented  opcodes, but we won't get into that. The  

18:21

65c02 added these new opcodes. Most of these are  designed to make life easier on the programmer,  

18:27

as well as make execution a little faster. Older  code will still run on this CPU, it just won't be  

18:33

making use of any of these new instructions. In fact, I want to show you something a lot  

18:37

of people don't know about. This is an ordinary  Commodore VIC-20, and I'm going to remove it's  

18:42

CPU. It's just a standard 6502, which is to be  expected. And here we have a brand new 65c02  

18:49

from Western Design Center. And what I'm going  to do is insert this into the VIC-20, and power  

18:54

it on. And well, if you thought it was going  to work, then I guess you'll be disappointed. 

19:00

The reason it doesn't work has nothing to do with  the new opcodes, but rather the pin arrangement.  

19:04

If you compare the two processors, you'll see they  are almost identical pin arrangements. In fact,  

19:08

only these 3 pins are different. I'm not going  to go into great detail on what these do. But,  

19:14

let's see if we can make this work  in the VIC-20. I'll start by bending  

19:17

up two of those pins that were different.  I'm just going to leave one disconnected,  

19:20

and the other I'm going to use a resistor  and tie it to 5V, pulling it high. I know,  

19:26

it doesn't look terribly elegant. But let's stick  it back into the VIC-20 now and see what happens. 

19:31

Check it out, it works. At this point the VIC-20  now has additional instructions available to it if  

19:37

you wanted to write code to support it. And even  though this CPU can run at 14 mhz, it is obviously  

19:43

only going to run at the clock speed the VIC-20  gives it, which is still 1 mhz. So there isn't a  

19:48

huge advantage to using this. I run a number of  games and didn't have any compatibility issues,  

19:55

although I'm sure there's probably at least one  or two out there that were using some undocumented  

19:58

opcodes that might fail with this CPU inside. OK, now let's take a look at the 65c816. This  

20:06

chip debuted in 1985, and it is a significant  upgrade to the 6502. This chip is 16-bit,  

20:13

sort of. You see, there's no standard way to  define how many bits a CPU is. Some people  

20:18

judge it based on how wide the data-bus is. In  this case, the data-bus is still 8-bit, just like  

20:24

the 6502. But internally, it can do 16-bit math. It also has a ton of other new features. In fact,  

20:31

here are those opcodes we looked  at earlier for the 65c02. Well,  

20:35

the 816 supports all of these opcodes. In fact,  when it boots up, it starts in 8-bit mode,  

20:41

thus essentially operating exactly like the 65c02.  There are a few small differencees, I'm sure some  

20:47

of the keyboard warriors will want to point out.  For example, Some 65C02s made by rockwell and WDC,  

20:53

had these extra instructions here. I didn't show  them earlier because not all varients supported  

20:58

these, and they aren't used very often. But the  816 definitely doesn't support these and instead  

21:03

adds all of these when operating in 16-bit mode. When performing 16-bit math, that means instead  

21:10

of requing 6 or 7 instructions to handle  problems like this one half at a time,  

21:14

it can do the whole thing in a single  instruction. This sort of thing can really  

21:18

speed up execution for certain types of software. But, perhaps a more important aspect of the chip  

21:23

is the larger address bus, let me show you how  that works. The pin arrangement on the 816 is very  

21:29

similar to the 6502, but it's a little bit more  complicated to get to work in an older computer  

21:34

because as you can see there are now 9 pins that  are different from the original. but you may be  

21:39

counting up the address lines and seeing that  there are still only 0 through 15. So how can  

21:44

it access more than 64K, you might ask? Well,  when you put the chip into the correct mode,  

21:48

the data-bus pins will pull double  duty. So when the clock cycle is high,  

21:52

they are data lines like usual. but when the  clock is low, they are become address lines 16  

21:57

through 23. Thus giving it a 24-bit address,  capable of addressing up to 16 MB of RAM, a  

22:04

massive amount more than a typical 8-bit computer. So, can you install one of these into something  

22:09

like a VIC-20? Well, sort of. You're going  to need a ltitle adapter board like this one,  

22:14

which are remarkably hard to find at the moment.  But in theory you can pop this into your VIC-20  

22:18

or other 8-bit system and instantly have  a 16-bit capable computer, except that  

22:23

you won't have access to the extra RAM. Perhaps a better example, something I can  

22:28

actually show, is the Commander X16. By default  it comes with a 65c02, but it actually supports  

22:34

the 816. I keep one around for testing and  I have a big label on it so I don't get it  

22:37

confused with my other CPUs. But yeah, the  X16 runs just fine with the 816 installed,  

22:42

and in theory if people wanted to write code that  made use of the 16-bit aspect of it, they could. 

22:48

I think the 816 was a really great processor,  but it only ever saw widespread use in  

22:53

the Apple IIgs and the Super Nintendo. So, the last thing I have for you guys is,  

22:57

I finally man managed to sit down and  have a conversation with Bill Mensch,  

23:01

one of the original creators of the 6502 and the  816 processor, and I had a few questions for him. 

23:07

So, Bill, tell me who are the current, modern-day  customers of the 6502. OK, so we have a lot of  

23:15

interest in your world, meaning the hobby world.  And so we sell boards into that. and we sell chips  

23:23

into that. And as you know, you and Ben Eater,  Ben Eater has been especially active in that  

23:34

world. And then we have some others, Stefany I  think you know. But in any event. I find it hard  

23:39

to believe that just the retro market keeps the  whole 6502 business alive. There's got to be more  

23:45

other modern customers. And the other thing that  we still get royalties off of is life-support. so,  

23:53

we keep millions of people alive one  heartbeat at a time, with the 65c02. Really? 

24:02

Why do you feel like the 6502 architecture didn't  last much beyond the 16-bit era with like the  

24:11

Apple IIgs and Super Nintendo? Is it just because  everyone was going to MS-DOS compatibility,  

24:17

or was there some other reason? Well, I  specifically was recommending ARM. OK. So when  

24:26

my licensees asked what I was doing at 32-bit,  I said, "Well, I have some specifications for  

24:37

32 bit. I'm happy to share them with you.  But, I don't think that's what you want." 

24:42

Well, if you've made it this far then you've  probably learned more about the 6502 than you  

24:46

probably ever wanted to know. But, hopefully at  least you have a little bit of understanding of  

24:50

the significant role that the CPU has played  over the last 40 years and also why it is my  

24:55

favorite CPU. But, that's all I have for  now, so as always thanks for watching!