DerpymanMT wrote:
Hi again, I was looking online for documentation of anyone connecting the Arduino UNO to the 6502. And I couldn’t...
If you were to look in my previous posts, I am planning on using it as a video output device. And since I’m using the library TVout, the pins 9 and 7 are going to filled. Could I use the Digital pins as input for the Arduino? And how should I go about this give me a general idea and I can most likely figure out the rest!
-EAS
So... There isn't really any documentation mostly because there is no "one way" to do it. Everyone does it their own way. Ask 12 engineers, get a bakers dozen answers ...
Here is my way...
I have interfaced an Arduino (actually an ATmega) to a 65C02 and 65128. It's part of my Ruby 6502 (and Ruby816) systems and roughly documented in an overview sort of way over at:
https://projects.drogon.net/6502-ruby/In essence:
There is no ROM on the 6502. The ATmega (it's a 1284p, so lots of IO pins), uses 8 pins for the data bus, another 8 for the lower 8 address lines and can control the 6502 reset, BE and Rdy signals. It also has /Rd and /Wr outputs to go into the SRAM. The top 8 address lines are pulled high via 10K resistors. another IO pin can signal an IRQ to the 6502. The top 256 bytes of RAM are shared between the ATmega and the 6502, but only ONE side can access it at a time.
There is a PAL for address decoding (more to save 2-3 TTL chips) and to turn RWB from the 6502 into /Rd and /Wr signals to the SRAM - which it can also tristate based on the BE output signal from the ATmega into the 6502.
So... Power on: The 6502 is held in reset, the ATmega boots. It lowers BE and holds the 6502 in reset. It then enables the data and address lines and at this point it can see the top 256 bytes of RAM. It writes a small boot program here and sets the vectors to point to $FF00. It releases itself from the RAM and un-resets the 6502.
The 6502 starts, fetches the reset vector and jumps to $FF00. This is about 200 bytes of bootstrap stage zero.
The boot code relocates (copies) itself to lower RAM ($400, but it's not that important) then communicates with the ATmega to pull in the rest of the OS which it loads starting at $C000 then it jumps into the main operating system.
Once booted the 6502 is effectively in control and the ATmega does what's asked of it by the 6502.
The communication mechanism works by the 6502 poking a set of commands and data into the top 132 bytes of RAM from $FF00 through $FF83 then issuing a WAI instruction. At this point the ATmega which has been polling the Rdy signal, "knows" that the 6502 has halted and can /BE the 6502, enable its address and data buses into the RAM, read the RAM, execute the command, using the 128 bytes from $FF00 through $FF7F as a transaction buffer. When it has done the command (which might be "print string") writes a "done" code into the RAM, and releases itself from the RAM, enables the 6502 (brings BE high), and sends an IRQ which causes the 6502 to wake up at the instruction after the WAI.
The ATmega can generate video - and it did in early incarnations. I had it creating a 320x240 pixel display, so 40x30 character display with an 8x8 font, or graphics. The 6502 can send commands to e.g. print a character, or draw a line, rectangle, circle, etc.
However - it proved too slow. Generating the video signal was taking up too much time inside the ATmega - some 60-70% of all CPU cycles, so I abandoned that idea. Now it's essentially a serial terminal and the graphics commands are passed through to the terminal program I use on my Linux workstation. It does other stuff too - acts as a floating point accelerator, a filing system (SD card), timer interrupt source and whatever else I can think of. The filing system is the important part now though.
So that's a brief overview of one way to interface an ATmega (or Arduino) to a 6502. This way with local RAM to the 6502 allows the 6502 to run at full speed with local RAM rather than have the ATmega single step the 6502 and provide emulated RAM and ROM which is another way to do it.
There is a little video demo of it here:
https://www.youtube.com/watch?v=ci_70naIg_Q there is some graphics towards the end.
-Gordon
(also a baker)