Wrapping this up:
The above scheme of qualifying Rdy with ph2 wasn't a 100% success - the 6502/816 would still crash, seemingly at random, and lacking the tools (a fast logic analyser) I went for a plan B (although more like D by this stage!)
The issue appears to be an incoming IRQ when the 6502/816 executes the WAI instructions. This causes the CPU to re-start after the WAI instruction (by design - that's the fast IRQ mechanism)
This is not quite what I want, so as all incoming IRQs go through a GAL (just acting as a 3-input OR gate), then I added in another term to AND them with the Rdy signal which is now an output only signal from the CPU, I'm no longer driving it from the ATmega host. The idea being the when Rdy is low, then IRQs will be held off, so the host (ATmega) processor can do its thing then it sends an NMI to the 6502/816 which causes it to carry on (NMI just points to an RTI). At that point, any pending IRQ can get through and execute as normal, although with a slight delay. (Which is fine and I put up with lack of proper high speed interrupts as I'm using NMI here).
That worked - most of the time, but I was seeing the very occasional glitch - which I eventually worked out was manifesting itself as a missing packet of data from the CPU to the host.
I worked out what was happening was that an IRQ would come in (from the T1 timer in the VIA) at the exact point the SEI instruction (or possibly the start of the WAI instruction) was executing in the
Code:
SEI
WAI
CLI
sequence. This caused the WAI to essentially act as a NOP. Rdy didn't go low, so the ATmega never saw the signal. Probably for the best at this point as the next thing the ATmega would do is pull BE low which 100% crashes the 6502 when Rdy is high.
My solution was to check to see if the host communication had actually taken place via the shared RAM page and if-not then re-do it.
Code:
; hostCall:
; Initiate a data transfer with the host.
; Entry: A contains the code.
; Additional data passed in sBuf ($FF00-$FF7F), sBufCmd and sBufParam
;********************************************************************************
_hostCall:
sta sBufCmd
: sei ; Disable IRQs
wai ; All STOP until the host pokes us.
cli
lda sBufCmd ; Check to see if the host actually did something
bne :- ; ... if not
rts
This has now been working with my stress test (passing data back and forth to the host as fast as it can), for over 12 hours now with T1 running 100x faster than normal and I'm happy. (and I've just realised the SEI/CLI is now superfluous too, so removed them and running the test again and so far, so good..)
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/