Sunday, December 31, 2017

Connecting a C64 disk drive to the MEGA65 - part 2

The other day I wrote about getting the first communications between the MEGA65 prototype PCB and a real C64 disk drive (my old sick 1581).

At that point, I had it working to be able to read the DOS status exactly once, but then it would hang.  Similarly, trying to LOAD anything (even a disk directory) would cause strange lock ups.  Tracing through where it got stuck using the MEGA65 serial monitor (which I am always so glad I went to the effort of implementing), I found that it was waiting for timer B on the CIA to time out, to determine when it was an EOI condition.  However, timer B never triggered.  This set me on a journey of implementing a pile of missing functionality in our CIA implemenation.

First, I tracked down and fixed the bugs in timer B, and resynthesised the bitstream, to confirm that this indeed fixed the problem I was seeing in C64 mode.

I couldn't tell if it would now work for loading files, as I can't even load a directory on my sick old 1581. Of course, I only got to this point after having borrowed a 1541-II from a local to confirm that I could read the status message only once from that as well -- so even now, I don't know if I would be able to load something or not from C64 mode. However, C65 mode is a different question...

C65 mode, like C128 mode on a C128, uses fast serial when it can.  Long, long ago, I had bodged up the status register on the CIA shift register, that is used for fast serial. This was to work around the start-up code on the C65 that looks for a disk drive, and if present, tries to boot from it.  My bodge was just to always set the shift-register complete flag.  This worked back then, and stopped the boot process hanging like this:

But now that we are trying to talk to real disk drives, it makes the C65 think that every connected disk-drive can do the fast serial mode, which results in hanging.  (Note that while a 1581 can do fast serial, we don't currently have the SRQ line connected on the MEGA65's IEC serial port. This will change in the production versions, so that fast serial mode will be available.)

So, as well as fixing timer B, I spent part of the day implementing the shift-register, at least for sending, so that I could get rid of the bodge, and have, hopefully, both the C65 booting correctly, and working with external drives in C65 mode. This is still a work in progress, but I hope to have it all working in the next couple of days.

There are also some residual bugs I need to track down, which might just be poor timing closure on the FPGA, that cause device not present errors and the occasional corruption of bytes received, such as in the following image. It could also be that my 1581 is sick (it sometimes flashes three blinks on start up, to indicate that it has a problem with its RAM, so this is not out of the realms of possibilities).

The next stages on this will probably have to wait now, until I collect the 1541 that is sitting in the lab at work sometime this coming week.  But I am happy that significant progress has now been made.


  1. Congratulations! I think this is a milestone, because you have now reached the point where the Mega65 connects to the wide world of Commodore pheripherals.

    I think you should try a fastloader once you connect a real 1541. It is only then that you can really test if cycle accuracy of the CPU is correct.

    1. Yes, I quite agree on both points, and we will do this quite soon. Meanwhile, can you poke me on email or skype, so that we can think about the circuitry we need in the M65 to make it work. I am very keen to prototype this up this coming week, if I am able.