Use of RDY pin for a VERY slow device

For discussing the 65xx hardware itself or electronics projects.
Post Reply
frikosal
Posts: 7
Joined: 20 Dec 2013

Use of RDY pin for a VERY slow device

Post by frikosal »

Hi,
Just for fun, I'm trying to program a micro controller (arduino MEGA) to emulate the RAM/ROM memory that a 65C02 will need to run. The micro controller is connected to all pins of the 6502 except power, emulating RAM and ROM where needed.
My problem is that the microcontroller is way too slow to behave as a real RAM/ROM chip. Also, I would like to microprocessor to run as slow as I want.
Right now, I have the 65C02 free running and performing RES and NMI, clock is generated by the arduino and pins state output using serial port.

My problem now is: when the 6502 gives a low in R/W pin, the microcontroller should configure the data bus pins as inputs before the 6502 outputs data.
Can I set RDY to LOW, read RW and address pins, prepare the data bus for read or write, then set DRY to HIGH for (say) 1us ? How can this be done ?
I fear to damage the microprocessor if both devices try to write to data bus simultaneously.
Thanks so much !
nyef
Posts: 235
Joined: 28 Jul 2013

Re: Use of RDY pin for a VERY slow device

Post by nyef »

If you're generating your phi2 clock by way of the Arduino, and are using a WDC 'c02, then don't worry overmuch about the timing, don't bother with RDY, just have the clock pin transition only when your data bus pins are in the appropriate state.

Doing this with an '816 could be trickier, to the point where you might want to include the full bank-latch circuit.
frikosal
Posts: 7
Joined: 20 Dec 2013

Re: Use of RDY pin for a VERY slow device

Post by frikosal »

Yes, I'm generating clock in (pin 37) with the Arduino.
But my 65C02 doesn't seem to be the WDC. I just tried setting LOW or HIGH pin 36 (BE in the WDC) and it doesn't make any difference, so I guess it isn't connected and therefore it is not the WDC.
What is a '816 ?
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Use of RDY pin for a VERY slow device

Post by GARTHWILSON »

Quote:
What is a '816 ?
The 65816 is the next one up in the family, with 16-bit registers and 24-bit address. It has more instructions and addressing modes, and is much better at doing things the 6502 is at least clumsy at, if not totally incapable. Newcomers tend to shy away from it; but I would say it's not nearly as complicated as people make it out to be. It's just a more grown-up 6502. You can initially use it as a 6502 and then start learning its extra capabilities little by little. I think it is actually easier to program, if you're frequently dealing with 16-bit quantities. The data sheet is at http://6502.org/documents/datasheets/wd ... 3_2010.pdf (or http://westerndesigncenter.com/wdc/docu ... 5c816s.pdf). The excellent programming manual is at http://6502.org/documents/datasheets/wd ... manual.pdf (or http://65xx.com/wp-content/uploads/2013 ... manual.pdf).
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: Use of RDY pin for a VERY slow device

Post by Dr Jefyll »

frikosal wrote:
I fear to damage the microprocessor if both devices try to write to data bus simultaneously.
You can relax. Even if you do make a mistake, it will probably result in a temporary malfunction, not permanent damage. Although bus contention does stress the chip, it is by no means an automatic death sentence. The other thing protecting you is the fact that with 65c02 it's easy to avoid having both devices drive the data bus simultaneously.

The 6502 and 65C02 never drive the data bus during the first half of each cycle -- the Phase 2 low time. It's a period of guaranteed inactivity. Therefore the Arduino can examine the R/W pin during this time and learn in advance whether the last half of the cycle will belong to the Arduino or to the 65c02. Then after the last half is complete we return to another period of guaranteed inactivity.

To control timing you can just let the Arduino supply the input clock to the 65c02, as nyef suggested. IOW don't bother using RDY; just tie it high. This will allow you to run one cycle at a time, as slowly as you wish. Just be sure to stop the clock in the high state, not the low state. That's because with some 65c02s such as Rockwell the maximum duration of the low state is limited. But the limit is very generous -- listed as 5000 ns (ie; five milliseconds ) for Rockwell, and even that large figure is probably very conservative. IOW there's plenty of time for the Arduino to set the stage before it raises the clock line to the 65c02 for the 2nd half of the cycle.
GARTHWILSON wrote:
Newcomers tend to shy away from [the 65c816]; but I would say it's not nearly as complicated as people make it out to be.
Garth is right, but one area where the '816 is slightly more complicated is in its bus operation. For most people that isn't a problem but for your experiments the '816 would need extra attention.

-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Use of RDY pin for a VERY slow device

Post by BigDumbDinosaur »

frikosal wrote:
Yes, I'm generating clock in (pin 37) with the Arduino.
But my 65C02 doesn't seem to be the WDC. I just tried setting LOW or HIGH pin 36 (BE in the WDC) and it doesn't make any difference, so I guess it isn't connected and therefore it is not the WDC.
A genuine WDC 65C02 will have the WDC logo on it. Perhaps you are misunderstanding the roles of BE and RDY.

When negated, BE brings the MPU's bus and RWB outputs to the high impedance state. Negating BE does not stop the MPU.

When negated, RDY stops the MPU in the Ø2 high state. Negating RDY does not bring the MPU's bus and RWB outputs to the high impedance state, that is, the buses continue to be driven by the MPU if the current cycle is a write cycle.

The usual procedure for interfacing a slow device to the 65C02 is to generate one or more wait-states when that device is selected. The glue logic watches for when the device is selected and when it is, negates RDY for at least one full Ø2 cycle. The 65C02 stops but keeps the buses and RWB in the state that they would be in if RDY were not negated. This gives the slow device time to recognize all relevant signals and react as required. After the wait-state has expired, RDY is released and the 65C02 restarts on the next rise of Ø2.

Since you are attempting to make the Arduino act like a ROM, you need to put it under the control of the MPU, not the other way around.
Quote:
What is a '816 ?
A W65C816S, which is the 16 bit processor produced by WDC. The '816 is dual mode: it can emulate a 65C02 (with some mostly minor differences) or operate in native mode with the ability to load, store and manipulate 16 bit data, as well as address up to 16MB of RAM.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
frikosal
Posts: 7
Joined: 20 Dec 2013

Re: Use of RDY pin for a VERY slow device

Post by frikosal »

Hi guys !!!
It seems it is working, thanks a lot !!!!
I ignored RDY pin and generate clock signals not at constant frequency but when Arduino is ready to do the next operation.
I'm not sure it is correct but it runs a loop with INX, STX in zero page and JMP. Can you see this screen capture ?
https://dl.dropboxusercontent.com/u/249 ... system.png
Later I'll go on trying more complex instructions, I'll also try to capture the signals with my logic analyser
But right now I have to avoid serious familiar problems :)
frikosal
Posts: 7
Joined: 20 Dec 2013

Re: Use of RDY pin for a VERY slow device

Post by frikosal »

Here is my setup as it is now. Yesterday I was having erratic problems so I decided to weld the wires between the Arduino and the Arduino Mega. At the right hand side, the data and address busses. The mega has more than enough IO ports to control all the pins of the 6502 plus a display. Unfortunately, I'm doing something wrong, the 6502 starts doing weird things after some instructions. Lets see if next weekend I can fix it...
https://dl.dropboxusercontent.com/u/249 ... 203403.jpg
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: Use of RDY pin for a VERY slow device

Post by Dr Jefyll »

frikosal wrote:
the 6502 starts doing weird things after some instructions.
"Weird things" can easily be caused by deficiencies in the chip's power supply. For starters it'd be good to verify the correct supply voltage. Can you ascertain what brand of 65c02 you have? The reason I'm asking is because AFAIK the Arduino runs on 3 volts or thereabouts, and that's not acceptable for certain 65c02s such as Rockwell -- they are specified for 5 volts. But 3 volts is OK for WDC.

Also regarding the matter of the supply, I suggest you verify the voltage by measuring right at the 65c02 chip. This is just good basic troubleshooting. Another issue -- more of a design question -- is providing a supply bypass capacitor close to the 65c02. In the photo I can't see whether you've taken care of that.

cheers,
Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
nyef
Posts: 235
Joined: 28 Jul 2013

Re: Use of RDY pin for a VERY slow device

Post by nyef »

frikosal wrote:
Here is my setup as it is now. Yesterday I was having erratic problems so I decided to weld the wires between the Arduino and the Arduino Mega. At the right hand side, the data and address busses. The mega has more than enough IO ports to control all the pins of the 6502 plus a display. Unfortunately, I'm doing something wrong, the 6502 starts doing weird things after some instructions. Lets see if next weekend I can fix it...
https://dl.dropboxusercontent.com/u/249 ... 203403.jpg
Well, now I'm kicking myself for not having thought of doing something similar for one of my projects. What are you using on the Arduino side of that lash-up, a small strip of veroboard with breaks down the middle and some soldered-in pin headers?
LIV2
Posts: 173
Joined: 12 Feb 2014
Location: Sweden

Re: Use of RDY pin for a VERY slow device

Post by LIV2 »

Dr Jefyll wrote:
frikosal wrote:
the 6502 starts doing weird things after some instructions.
"Weird things" can easily be caused by deficiencies in the chip's power supply. For starters it'd be good to verify the correct supply voltage. Can you ascertain what brand of 65c02 you have? The reason I'm asking is because AFAIK the Arduino runs on 3 volts or thereabouts, and that's not acceptable for certain 65c02s such as Rockwell -- they are specified for 5 volts. But 3 volts is OK for WDC.
I believe AVR/MEGA based Arduinos all operate at 5V while the ARM based boards operate at 3.3v so this shouldn't be an issue for him
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: Use of RDY pin for a VERY slow device

Post by Dr Jefyll »

LIV2 wrote:
I believe AVR/MEGA based Arduinos all operate at 5V while the ARM based boards operate at 3.3v so this shouldn't be an issue for him
Hmm, looks like there are more flavors of Arduino than I was aware of! Thanks for setting me straight.

I'd still like to know what kind of 65c02 frikosal is using, and whether it has a supply bypass capacitor connected close by.

-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
frikosal
Posts: 7
Joined: 20 Dec 2013

Re: Use of RDY pin for a VERY slow device

Post by frikosal »

Hi guys,
I'm using a Rockwell 65c02, or so it seems according to its logo. I bought it on Ebay so who knowns.. Just ordered what seems a WD.
I'm powering it, as well as the arduino, from the USB.
No, I'm not using the capacitor. Can you please suggest me the capacitor to use ?
Before welding it, it could run a single loop. I implemented a 8 digits 7 segments LED display. It was red, to look like a KIM 1 :)
Arduino copied the contents of adresses 0x300 to 0x303 to the display, so it could see it running. It was cute !!
I also wrote a small program to transfer the xa output to the Arduino. It can save 4kb in its own internal eeprom.
Now I'm using a small PCB to bring the Arduino 24 lines to the Adafruit permaproto board where the 6502 is.
Choosing carefully the Mega pins, you can write data bus with a single instruction and address bus with two instructions, bypassing the very slow arduino libraries.
My final goal would be to have a Mega shield (a PCB on top of the Mega) with the 6502, a display and some keys.
That would be single chip 6502 system :)
It would be very nice to design a PCB and order it, with a 2 layers it should be enough.
This can be very interesting to experiment with the 6502, also to attract young people from the Arduino community to our beloved 6502.
What do you think ?
Manel
Post Reply