YM2612 programming warning

Published on 2020-jan-03

I've already seen at least a couple of homebrew games trip over this so I think this deserves a warning.

Do not rely on undefined behavior when reading the YM2612 status. The behavior differs between hardware revisions, and your game will break on a lot of consoles if you don't follow this advice.

If you're using one of the popular sound drivers this shouldn't be an issue, but if you're making your own sound code, mind the following:

In particular, always make sure to read only from $4000 (or $A04000 if accessing from 68000), and to not expect a particular byte value to show up. If you're waiting for the YM2612 to stop being busy, only check bit 7 and ignore the rest, if you're waiting for the timers then only check the relevant bit.

Just because it works on your console doesn't mean it will work on all of them. If you can't afford to test multiple revisions then at the very least follow the above advice to get you out of trouble.

Explanation

The Mega Drive underwent several hardware revisions over time to reduce costs. In particular, there are two major variants of the YM2612 in use (the original discrete YM2612 and a later YM3438-based variant integrated into the main ASIC). On top of that the Teradrive uses a discrete YM3438.

These variants differ in how they handle reading the status port in undocumented ways. Some variants only return a valid status value on the first address ($4000), and on top of that the values of bits 6-2 may be either zeroes or a previously written value depending on which variant it is (which is why you should ignore their value).