Also, when forced interleave between the CPUs affects the timing, it's time to get rid of it, and just sync the CPUs whenever they access a shared resource, which is how things generally *should* work anyway... batrider and battle bakraid seem to let the Z80 trigger interrupts on the 68K as well as the other way around, so you can't get it perfect unless you have per-instruction interleave, but you can get close enough.
Thanks, that did the trick. The interleave for batrider is back to 8 (from 128) and the sound timing is perfect now. I synchronized the z80 cycles to the 68k before setting the soundlatches, and got rid of those silly zetrun's after the nmi.edit:
regarding bgaregga and the ToaScanlineRegister, I did many tests between your more advanced version and fba's current simplified version of the function. I also tested a super-simplified version of this from Raine, which basically just returns 0x8000 | (counter++&0x1ff), and another ported from MAME which somewhat resembles yours. Between them all there really is no difference at all in the lag at the second boss. Then I tested different emulators: yours vs. FBA vs. MAME and many-a-time, and really there is no difference in the lag when the ship blows up. I found that the laser attack of the second level boss causes the most lag when your ship blows up, so I used that as the testcase.
... so.. at this point I think the best thing for people not willing to deal with that lag is to bump up the cpu speed. Or buy the PCB