12 minutes ago, Elektron72 said:
I know this isn't implemented in the emulator yet, but would it be possible to use one of the VIA timers to trigger an interrupt when the YM2151 would be ready to receive more data?
Not exactly. There's no way for the VIA to know what the state of the YM is - the only way to know that is to poll the YM status flag. The only way to do that automatically would be to have some circuit which did this. If I were going to build some kind of HW-based acceleration like this, I'd just make a circuit that had its own little RAM buffer. Obviously there's no WAY such a circuit would be in the X16 as they're trying to keep costs as low as possible. Heck, the YM2151 itself doesn't have a "notify when ready" feature. It does have an IRQ line, but that's only triggered by the 2 timers available in the YM.
What you _can_ do with the VIA is set a timer to a value just right for this task - say 145 cycles so that by the time the IRQ handler has figured out that the VIA is the IRQ source, the YM will have just finished the previous write. I'd suggest using one-shot timer mode. That way, you write the YM and then start the clock again - it will keep the same latched value (using the correct timer and timer mode CTL settings). However, this is expensive too because the overhead of setting up and returning from an IRQ burns cycles.
I used a VIA timer to regulate the VGM playback speed for Kevin's YM2151 testing on Proto#1. It worked well. The challenge there was my prog had to run on bare metal, as it WAS the ROM (no kernal, etc). Since VGM assumes 44.1KHz sample rate for chip msg playback, if you do the math, 1/44.1KHz > 68/3.5Mhz so it was guaranteed to not hit the chip when it was still busy from the last write. Not having VIA in the emu made debugging pretty tough since I'd never written any code for VIA before, so I had to poke around in the VIC20 on WinVice to make sure I was setting it up right.
Anyway, writing to the YM @ 44.1KHz intervals via IRQ was pretty expensive on the CPU - I forget how I derived the number, but I estimated it was taking around 25% CPU to do that, which is pretty heavy for just streaming bytes into a register.
The good news is that you don't really have to spam the YM @ 44KHz to play music on it. Most X16 VGM players I've seen on Github seem to clump the writes up into batches and time them with VSYNC instead and they come out fine.