Page 2 of 2

Re: Problems with YM sound effects on real hardware (works in emulators)

Posted: Wed Mar 12, 2025 9:21 pm
by DragWx
9 NOPs is 18 cycles, are you sure that many are necessary after an address write? Our own documentation recommends 10 cycles, which would just be 5 NOPs.

If it works, it works, I just want to know where these cycle counts and requirements come from. :P


For BUSY (or, delay after writing DATA), I looked at Nuked-OPM and jt51, and they both agree that BUSY takes 32 YM2151 cycles. The YM2151 application manual says the master clock is halved internally, so each YM2151 cycle is actually 1.79MHz.
If you allow (up to) 1 cycle for the YM2151 to poll its async address/data interface, 33 cycles is about 147.5 CPU clocks (at 8MHz), so that matches the "wait 150 cycles" advice.

For the delay after writing ADDRESS, I don't have hard data, but if I assume it takes one cycle to set the address (after allowing up to one cycle to poll that interface again, like above), 2 cycles is about 8.94 CPU clocks, which matches our documentation recommending a 10-cycle delay.

Re: Problems with YM sound effects on real hardware (works in emulators)

Posted: Thu Mar 13, 2025 9:45 pm
by doslogo
ZeroByte wrote: Wed Mar 12, 2025 8:30 pm Glad that fixed it. Once I got thinking about it, I realized how familiar that "works on emu, but not hw" problem was. :D
I knew you would find a solution quite quickly since the music already worked.

Now, while the sound effects are primitive, they give the cycles to the game engine to come up with a queue system etc, so that is good. But converting from ZSM to sound effects is quite a hack at the moment. Your zsm2sfx php script has a line like this:

Code: Select all

$i = 18; // skip ZSM header bytes
Is 18 correct here?

When using the script unmodified, there is always the result:
We've gone off the rails!!!
The switch statement differs quite heavily from the one in zsmdecode.

My modified script managed to get the sound exactly like I wanted it, but that was probably with luck. Also, I don't like that DefleMask instruments are required for dmp2x16. It isn't a free software, like Furnace who has its own instrument format.

Maybe zsm2sfx should be able to export the instrument for function patchym from the ZSM directly instead?
DragWx wrote: Wed Mar 12, 2025 9:21 pm 9 NOPs is 18 cycles, are you sure that many are necessary after an address write? Our own documentation recommends 10 cycles, which would just be 5 NOPs.
I tested it with 5 NOPs on real hardware with success! All updates to the YM registers that were using 9 NOPs were changed to 5, and I am playing that Super Mario 64 ZSM at the same time at as spamming YM ZFX and PSG at the highest channels not to screw up the music. No errors.

It all runs at 60 Hz even at loop points, which is so ridiculous awesome.

I also introduced artificial lag and music and sound effects are still playing at slower rate (because I am not updating in vblank), but there are no errors in the playback, so 5 NOPs (10 cycles) were correct DragWx!
I will later test 5 NOPs on the real hardware with both sound effects and music playing at the same time. I'll post my result then.

EDIT: Works with the Green Hill Zone ZSM as well, spammed sound effects, and doesn't miss a beat. That ZSM have many instruments changes though so it lags every loop, and is a typical example of how to not make music for the X16. The 5 NOPs work perfectly!

Re: Problems with YM sound effects on real hardware (works in emulators)

Posted: Thu Mar 13, 2025 11:52 pm
by DragWx
Nice, I'm happy that helped. :D

I'm also trying to figure out a good way to stream writes to the YM2151 without having to do busy-waiting (in general), it's a challenging puzzle.