PDA

View Full Version : Reverse Engineering the MOS 6502 CPU



tomaitheous
10-30-2012, 01:35 PM
Great video: http://www.youtube.com/watch?v=fWqBmmPQP40

djcc
11-30-2012, 04:33 AM
I really enjoyed that video.

TmEE
11-30-2012, 05:19 AM
Naiss stuff !

I like Z80 more :P

Stef
11-30-2012, 05:21 AM
So do i :)

djcc
11-30-2012, 05:24 AM
But I hear the Z80 has cooties! Smelly cooties!

You wouldn't want a CPU with smelly cooties, do you?

TmEE
11-30-2012, 06:02 AM
*passes on some smelly cooties*

:P

djcc
11-30-2012, 09:53 AM
Of course I'm being silly. I don't really have anything against the Z80. I messed around with the 6502 last summer and it was quite fun. Didn't do anything meaningful with it but liked how I had to think about programming differently. My programming evolution went from Basic to Turbo Pascal to C/C++. Never any assembly. During my 6502 experiments I tried doing some NES programming but didn't get very far. During that phase I thought I'd check out Sega Master System programming, too. I had read somewhere that the Z80 was more difficult to use and that the SMS didn't have niceties like hardware sprite flipping. I was already struggling with the NES stuff so I figured I wouldn't give myself extra grief by trying out and even more challenging platform. That's about the sum of my exposure to the Z80 :)

Drakon
11-30-2012, 10:04 AM
I watched for less than a minute and then turned it off due to excessive nerdiness. I can take tech stuff in small amounts but this's too much for me. Maybe I just don't have the patience, but probably what did it is the lack of good looking ladies.

TmEE
12-01-2012, 02:01 PM
Of course I'm being silly. I don't really have anything against the Z80. I messed around with the 6502 last summer and it was quite fun. Didn't do anything meaningful with it but liked how I had to think about programming differently. My programming evolution went from Basic to Turbo Pascal to C/C++. Never any assembly. During my 6502 experiments I tried doing some NES programming but didn't get very far. During that phase I thought I'd check out Sega Master System programming, too. I had read somewhere that the Z80 was more difficult to use and that the SMS didn't have niceties like hardware sprite flipping. I was already struggling with the NES stuff so I figured I wouldn't give myself extra grief by trying out and even more challenging platform. That's about the sum of my exposure to the Z80 :)

SMS is pretty simple, like MD. There are no weird quirks to worry about. Everything is pretty simple, sometimes too simple (like no sprite flipping) and no way to do raster effects that involve vertical scroll change.

djcc
12-01-2012, 02:09 PM
I watched for less than a minute and then turned it off due to excessive nerdiness. I can take tech stuff in small amounts but this's too much for me. Maybe I just don't have the patience, but probably what did it is the lack of good looking ladies.

I require that all the technical videos I watch have tits in it. I mean, how else are they going to keep my attention?

I once did C# language "training". It was two days of watching a total of 16 hours of video. Tits would've helped a lot.

Back to the subject, it's amazing that they didn't (or couldn't?) use computers to help in the design of the chip. They had to draw everything by hand. And it's sad that they lost all that original work. It's good that there exists the Visual 6502 and related projects.

Drakon
12-01-2012, 02:30 PM
Haha damn straight I want more titties otherwise I'd rather just read it on a post somewhere.

Also if you can hand draw the 6502 schematic I wonder how big a hand built version would be.


I require that all the technical videos I watch have tits in it. I mean, how else are they going to keep my attention?

I once did C# language "training". It was two days of watching a total of 16 hours of video. Tits would've helped a lot.

Back to the subject, it's amazing that they didn't (or couldn't?) use computers to help in the design of the chip. They had to draw everything by hand. And it's sad that they lost all that original work. It's good that there exists the Visual 6502 and related projects.

Joe Redifer
12-01-2012, 08:02 PM
SMS is pretty simple, like MD. There are no weird quirks to worry about. Everything is pretty simple, sometimes too simple (like no sprite flipping) and no way to do raster effects that involve vertical scroll change.

What if an SMS cart had a cheater chip inside it like most NES games do?

TmEE
12-01-2012, 08:25 PM
I am working on that, and it will give 80% more animation capacity (the CPU can only reach 20% of VDP potential !) and I have some extra sound coming too (PSG is used as a DAC to play the new sound channels as there is no audio line on SMS cartslot). It will only work on real US/EU SMS1 or SMS2, and on Japanese SMS if you use exp slot adaptor. It won't work on MD or GG as they don't have full funtionality on the cartslot.
http://www.tmeeco.eu/BitShit/SMSDMA.png

Joe Redifer
12-01-2012, 08:59 PM
That's awesome. The kickass logos are especially impressive. Is this just a hardware goal right now or is there software being written for it? What's the plans for all of this or should we wait for an announcement? That's too bad about no audio line on the cart slot. There is one on the expansion slot, right?

TmEE
12-01-2012, 09:17 PM
Expansion slot has no audio line either, it is same as cartslot but with reversed gender.
The HW goes in hand with a run 'n' gun type game I am making. SMS has half the VRAM bandwidth of MD, being able to use all of it will mean animation that puts NES to shame.
I am not making any fuzz about it until I got something that works, so far it is all on paper but I am getting the PCBs on Monday, but some of the key parts are not around for at least a week more.
Great things will come none the less (at least one haha).

djcc
12-01-2012, 11:47 PM
I am working on that, and it will give 80% more animation capacity (the CPU can only reach 20% of VDP potential !) and I have some extra sound coming too (PSG is used as a DAC to play the new sound channels as there is no audio line on SMS cartslot). It will only work on real US/EU SMS1 or SMS2, and on Japanese SMS if you use exp slot adaptor. It won't work on MD or GG as they don't have full funtionality on the cartslot.
http://www.tmeeco.eu/BitShit/SMSDMA.png


It's a device that goes into the SMS card slot? Interesting!

TmEE
12-02-2012, 12:02 AM
It is a "flashcart" that plugs into the cartridge slot not card slot.
The card slot is worthless :P

Joe Redifer
12-02-2012, 12:35 AM
Is the card slot slower than the cart slot? Is it less capable?

TmEE
12-02-2012, 12:38 AM
Card slot has no bus control signals. GG, JP SMS cartslot and MD in SMS mode have none of these signals present so the cart cannot work on them. There is a small MCU on the cart that can move data faster to VDP than Z80 can and that is where the missing 80% comes. The MCU has a sound engine in it too that does 8x square wave channels with 0.4% duty cycle adjustment (think NES on some serious steroids) + 2x 4bit logarithmic PCM channels for drums (sound quality is close to TG16)

Drakon
12-02-2012, 08:27 AM
God I just want a flashcart that uses fpga to make sms fm. Is that too much to ask?!@?$?!@%

Chilly Willy
12-02-2012, 12:38 PM
God I just want a flashcart that uses fpga to make sms fm. Is that too much to ask?!@?$?!@%

Yes, it is. :D

Anywho, that's one of the better things about the Z80 - being able to take over the bus. With most other 8 bit CPUs, you need a bunch of extra chips to isolate the CPU from the buses when it's halted. That's what the ANTIC does in the Atari 8-bit computers - it isolates the 6502 and serves as the source for the DMA.

TVC 15
12-02-2012, 07:42 PM
Card slot has no bus control signals. GG, JP SMS cartslot and MD in SMS mode have none of these signals present so the cart cannot work on them. There is a small MCU on the cart that can move data faster to VDP than Z80 can and that is where the missing 80% comes. The MCU has a sound engine in it too that does 8x square wave channels with 0.4% duty cycle adjustment (think NES on some serious steroids) + 2x 4bit logarithmic PCM channels for drums (sound quality is close to TG16)

Thats truly awesome TmEE. I've read elsewhere, I think on sprites mind, you considered making a console of your own, sort of around PS1/Saturn performance. Has any more research gone into that?

You could stick a super fast arm co-processor in a cart for a lot of these older consoles, or build a fast modern RISC console for cheap. But I'd really love to see a homemade console, with strict limitations, with slower and exotic hardware, much like when everybody was rushing in the 90's to strike gold with the limited 3D technology we used to have. The best art always comes from strict limitation.

TmEE
12-02-2012, 08:01 PM
Those super fast ARM CPUs explode with 5V and they need too much extra stuff to be useful... like 6502, you cannot just kick most of them off the bus :lol:

As for my own stuff...
http://www.tmeeco.eu/BitShit/MelodieIsBigHaha.png ... :opa:

evildragon
12-02-2012, 09:30 PM
Well, the voltage issue is easily fixed.

TmEE
12-02-2012, 09:58 PM
It is still fair bit of addititonal headache and cost

kool kitty89
01-21-2013, 08:27 PM
I am working on that, and it will give 80% more animation capacity (the CPU can only reach 20% of VDP potential !) and I have some extra sound coming too (PSG is used as a DAC to play the new sound channels as there is no audio line on SMS cartslot). It will only work on real US/EU SMS1 or SMS2, and on Japanese SMS if you use exp slot adaptor. It won't work on MD or GG as they don't have full funtionality on the cartslot.
http://www.tmeeco.eu/BitShit/SMSDMA.png
Wait, you say 80% more capacity, but then you say the CPU can only handle 20% of the total bandwidth. If that DMA engine can max out the VRAM bandwidth (ie 100%), then that should be 5 times the animation capacity of the CPU alone, or 500% (much more substantial) . . . and 80% more than the base CPU performance (1.8x20%) would only be 36% of the VRAM bandwidth. (using CPU performance as the base 100% metric)

Going by percentages gets stupidly confusing (ugh, statistics), as it depends where you set the base for 100% to actually calculate that (and if you don't use the same base for 2 compared percentages, it makes no sense).
I tend to prefer strict ratios rather than percentages for any sort of comparison like this.


Oh, and awesome work in any case. :D

TmEE
01-23-2013, 10:27 AM
* 342 pixels per line
* 313 lines in PAL
* 262 lines in NTSC

* 1 slot every 4 pixels
* 1 slot every 2 on MD, with refresh cycles every 64 pixels
* 85 slots per passive line
* 10 slots per active line

* 228 CPU cycles per line

* 53693175 / 5 / 262 / 342 / 2 = 59.92Hz
* 53203424 / 5 / 313 / 342 / 2 = 49.70Hz

* Tile is 32 bytes


Number of bytes that can be transferred using Z80 (OUTI):
+------+--------+---------+-------+
| Mode | Active | Passive | Total |
+------+--------+---------+-------+
| PAL | 1920 | 1724 | 3644 |
| NTSC | 1920 | 997 | 2917 |
+------+--------+---------+-------+
Number of tiles that can be transferred using Z80 (OUTI):
+------+--------+---------+-------+
| Mode | Active | Passive | Total |
+------+--------+---------+-------+
| PAL | 60 | 53 | 113 |
| NTSC | 60 | 31 | 91 |
+------+--------+---------+-------+

Number of bytes that can be transferred using DMA:
+------+--------+---------+-------+
| Mode | Active | Passive | Total |
+------+--------+---------+-------+
| PAL | 1920 | 10285 | 12205 |
| NTSC | 1920 | 5950 | 7870 |
+------+--------+---------+-------+
Number of tiles that can be transferred using DMA:
+------+--------+---------+-------+
| Mode | Active | Passive | Total |
+------+--------+---------+-------+
| PAL | 60 | 321 | 381 |
| NTSC | 60 | 185 | 245 |
+------+--------+---------+-------+

SMS has basically half the VRAM capacity of MD.

kool kitty89
01-23-2013, 10:52 PM
Looking at that, DMA gives roughly a 6 fold increase in data transfer capacity in passive display time compared to Z80 (total passive+active improvement is about 1/2 that though, since active transfer was already maxed by Z80 it looks like . . . NTSC around 2.6 times more and PAL about 3.3x, given the much larger passive time allotted to PAL)

It's also probably there and I missed it, but are both of those using 224 active lines, or the more typical 192? (especially for NTSC)

Unless I'm reading those wrong, that's per-frame bandwidth, right? (so, per second, NTSC would be somewhat closer to PAL . . . albeit since games run at 60 Hz, some updates need to be more frequent to stay at full speed)

TmEE
01-24-2013, 12:47 AM
All per frame, all 192 lines. 224 and 240 work on too little hardware so I cannot use them really.

Drakon
01-24-2013, 09:04 AM
*head explodes from the power of tiido*

kool kitty89
01-24-2013, 06:35 PM
*head explodes from the power of tiido*
http://i661.photobucket.com/albums/uu339/Breener96/Random%20crap/YOUR_HEAD_A_SPLODE.png

sega16
01-29-2013, 08:27 PM
Those super fast ARM CPUs explode with 5V and they need too much extra stuff to be useful... like 6502, you cannot just kick most of them off the bus :lol:

As for my own stuff...
http://www.tmeeco.eu/BitShit/MelodieIsBigHaha.png ... :opa:
What about all those 5v tolerant arm processors on the market? You would still need a 3.3v regulator but I have noticed that ICs that do not accept a 5v power supply are cheaper sometimes.

TmEE
01-29-2013, 09:54 PM
These are CPUs not MCUs, you need extra stuff to make them useful. You also won't have good software support (at least not unless you pay $$$)

sega16
01-29-2013, 10:36 PM
These are CPUs not MCUs, you need extra stuff to make them useful. You also won't have good software support (at least not unless you pay $$$)
Here is a random arm micro-controller series that has 5v tolerances
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/DM00037051.pdf

TmEE
01-29-2013, 10:51 PM
Too many bells and whistles for what I need things for and cost is 5x higher too...
Ton of spread out docs from where it is exceedingly hard to find data from (like Texas Instruments stuff), device programmers and debuggers cost arm and leg too...

sega16
01-30-2013, 02:50 PM
Too many bells and whistles for what I need things for and cost is 5x higher too...
Ton of spread out docs from where it is exceedingly hard to find data from (like Texas Instruments stuff), device programmers and debuggers cost arm and leg too...
Yes I know arm documentation is very confusing. Although you can get a full arm development board which includes a debugger for $15 USD http://www.st.com/internet/evalboard/product/252419.jsp it will take alot of time to get everything working and it is much harder to program for. I guess arm is more for very high volume stuff where huge increase of time used is worth it.
Also I am not trying to make you change your design by using an arm instead of an avr. What you have works there is no reason to change.

TmEE
01-30-2013, 03:32 PM
They could be useful for something else, but that remains to be seen where. I also lean towards AVR32 instead of ARM. Got to be different :P