Thanks a lot for your answers, I'm not alone anymore
But now I have more questions and I must rephrase some points of my initial post
Wilson, I know
http://wilsonminesco.com/6502primer and theses pages are very valuable, I've read most of them during the last weeks but I still struggle to understand all the articles
1) Just to be sure about the signal names
PHI0 is the clock input, pin 37 - This one is an OUTPUT on MCU side and generated by the MCU (interrupt routine or not)
PHI1 is PHI0 inverted, pin 3 - This is an INPUT on MCU side
PHI2 is PHI0 with a slight propagation delay, pin 39 - This is an INPUT on MCU side
2) Andrew, about the pseudo code
When I started this experiment, I did not used any interrupt routine - I just tried to experiment with the main() loop even like many hobbyist did with slow Arduinos but most of the time I only got erratic behavior from the 6502.
In the pseudo code you use PHI2, so I presume you're talking about clock OUTPUT on MCU side, the signal that is fed on pin 37, should I stop using PHI0 as a valid term and stick with PHI1 and PHI2 (no matter if I speak about pin 39 or pin 37 ?
What is the first loop for ?
Code:
for 64 iterations
set PHI2 LO
delay 500nS
set PHI2 HI
delay 500nS
end-for
set RESB HI
I understand the RESET, but not the loop : Is it to stabilize the CPU before entering the main loop ?
Then, in the main loop
Code:
set PHI2 LO
set DATA_BUS input
set PHI2 HI
That means
- Generate clock LO
- Generate clock HI
- Then during clock HI I should have access to ADDR BUS, DATA BUS and R/W provided that I have the right nano seconds delays
The delay is a problem, the MCU is very very fast and the core might optimize the code execution so well that I did not found a way (I mean an article on the web) to have nano seconds delay using assembly "NOP". Not related with the 6502 but I should try to find a solution, may be putting a pin HIGH and LOW with NOP instructions in between and check the elapsed time with my chinese logic analyzer
I see that you set IRQ to HI, I presume it's the same that happen when IRQ pin is tied to VCC through a 5K resistor ?
Last point : I discovered the concept of "tri-state" few days ago and it confuses me a lot. 0, 1 and something else (the famous HI-Z) - Is tri state concept important/necessary to drive the 6502 ? Should I try again to understand what tri-state is ?
3) Chromatix
Yes, I'm aware that some NMOS 6502 could have problems with 3.3v - I will switch to the 65C02 in last resort, because I dream about partially emulating an old NMOS 6502 computer (an Oric Atmos) and may be the ROM original code could not run with a 65C02.
While typing the line above I did a quick search and found that using a 65C02 in an Oric Atmos is possible :
http://forum.defence-force.org/viewtopi ... 44&p=19622So that might change my plans
About the clock remaining HI see below
4) Interrupt flip flop
GARTHWILSON wrote:
I took it to mean he has a timer interrupt on the microcontroller that hits two million times per second, and it flips the 6502's clock input each time, generating a 1MHz clock input, which is fine as long as the microcontroller emulating the other parts is fast enough to make them play nicely with that clock rate, meeting the setup times.
Yes, this is how it works.
Pseudo code is
Code:
if flag
write HI to PHI0
read address bus
store address value to volatile v_addr variable
// The operations below are not yet implemented because until now my main concern is having $FFFC/$FFFD on addr bus which I never got with the interrupt routine (and very few times otherwise)
read RW signal
if RW is READ
write RAM/ROM content on data bus
store TRUE to volatile v_read_operation variable
else
write data bus content to RAM
store FALSE to volatile v_read_operation variable
else
write LO to PHI0
toggle flag
I arranged the connections between the 6502 pins and the MCU pins so I can read/write D0..D7 in one operation, read A15..A8 in one operation, read A7..A0 in one operation + 3 bits logical instructions
So it's pretty fast.
Then on the main loop I would
Code:
loop
cli // disable interrupts
copy v_addr and v_read_operation to local variables
sei
emulate simple things (keyboard, text mode ?)
If the code in the main loop is fast enough that could work.
BTW I should try to find an ARM disassembly tool that can give me cycle timing for each assembly instruction.
And I should do some maths to correlate the 180MHZ speed of the MPU and the 2MHZ interrupt to determine the maximum nano seconds I can spend in one main loop iteration
5) Last notes
- I already have two versions of the code, one with an interrupt timer, one without so I can easily check Andrew's pseudo code provided I can wait for nano seconds
From
http://laughtonelectronics.com/Arcana/V ... iming.htmlWhen the 6502 wants to read from memory
or when the 6502 wants to write to memory
In both cases the address bus is valid when PHI2 is high so I don't need any delay
But I need a few nano seconds delay before I read or write to the data bus, or am I wrong and there's no need to wait at all ?
Thanks again for your help, I hope this post is not too much confuse