6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Jun 26, 2024 7:15 am

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Fri Feb 27, 2015 7:24 pm 
Offline

Joined: Fri Dec 20, 2013 8:21 am
Posts: 7
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 !


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 27, 2015 8:46 pm 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 27, 2015 10:10 pm 
Offline

Joined: Fri Dec 20, 2013 8:21 am
Posts: 7
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 ?


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 27, 2015 10:45 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8460
Location: Southern California
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?


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 27, 2015 11:32 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3366
Location: Ontario, Canada
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


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 27, 2015 11:35 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8230
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 28, 2015 11:12 am 
Offline

Joined: Fri Dec 20, 2013 8:21 am
Posts: 7
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 :)


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 01, 2015 7:42 pm 
Offline

Joined: Fri Dec 20, 2013 8:21 am
Posts: 7
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 2:18 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3366
Location: Ontario, Canada
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 2:37 am 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 5:04 am 
Offline

Joined: Wed Feb 12, 2014 1:39 am
Posts: 172
Location: Sweden
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 8:38 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3366
Location: Ontario, Canada
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 9:08 am 
Offline

Joined: Fri Dec 20, 2013 8:21 am
Posts: 7
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 84 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: