Interrupt behaviour of the 6502 in emulation
Posted: Sat Jun 01, 2019 5:48 pm
Mike wrote:Did you try out my raster demo with your emulator in the meantime?
Well I now have support for the 1541 disk drive and .d64 disk images. I was using your mg_raster.d64 disk Mike as the test disk throughout. I didn't know much at all about the 1541 disk drive until I started to add support for it. All I ever had with my original VIC 20 were cartridges and tapes, and I didn't grow up with a C64. So I've certainly learnt a lot over the past week. I delved deep into the various documents online (some of them very good by the way, such as the "Inside Commodore DOS" book), and the 1541 schematics, and the 1541 ROM disassembly. Some of Michael Steil's recent posts on the 1541 disks and the Serial Bus at http://www.pagetable.com were also helpful in solidifying my understanding. I had to extend my 6522 VIA implementation a bit, because I didn't have support for the serial port yet, or for port latching and CA1/CB1 interrupts. It was certainly worth the effort then, because its always good to add in things that weren't previously supported.lance.ewing wrote:I haven't implemented support for disk images yet, or for the disk drive, so at the moment I can only run standalone program files or cartridge images.
The disk drive is probably the next thing on my list to take a look at.
It was pretty easy to get the "1541 machine" itself up and running. I already had the 6502 and 6522 emulation. I just had to define the right memory map, load the ROM image, and then run it cycle by cycle interleaved with the VIC 20 emulation. I also had to write the disk drive logic, including the GCR encoding, head movement, etc. The hard part was getting the serial lines connected up properly to the VIA chips and making them behave as they should. At one point I was getting it to build up timing diagram data that I could visualise on wavedrom.com so I could see what was going on. I understood the Open Collector concept straight away, and emulated the serial bus with that in mind. The bits that tripped me up were mainly with the input latching not being implemented, how ATNA behaves, and then just a few genuine bugs I made along the way where I'd coded it differently than how I thought I had. Glad its working now. I think I'd nearly had enough of trying to work out where in the ROM code it was and what it was trying to do. At one point I could see it was waiting for a SYNC, and I could see that the SYNC was happening, but it wasn't responding to it. That's when I discovered it was reliant on the input latching. I had a latch register for input latching, but didn't have the logic to put anything in it when the CA1 and CB1 interrupts occurred. So reading from the input latch was working, i.e. it returned the input latch value when input latching was enabled, but the value was always 0. - I still have a few 6522 features not implemented, but it seems I've taken it far enough for the 1541 and serial comms to be happy.
So to finally get to answering your question about how the mg_raster demo runs on my emulator: It is clear from having tried it now, and then comparing it to it running in VICE, that I still don't have a few things right with the VIC chip emulation.
Is it correct to say that what I see when it runs on VICE is correct?
I seem to have multiple colour changes partway down the screen that VICE doesn't have. I'll need to take a close look at your source code to see what its doing and think about where I'm going wrong.
Having .d64 support has opened a few more avenues now. I can test out many more demos, and also all the recently released games. Many weeks of testing and hopefully identifying and ironing things out are ahead of me.