New Documentation: An authoritative reference on the YM2612

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Eke
Very interested
Posts: 820
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Sun Jun 15, 2008 4:58 pm

thanks for the hard work :!:

PS: just finished reading it, this is quite understandable or explain some nice stuff about FM synthethis, definitely what the official YM2612 manual should have been ;)

I notice there was a register to disable CH4-CH6 and only process 3 channels, maybe someone could test it to see how the YM2612 behaves

User avatar
Nemesis
Very interested
Posts: 670
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Post by Nemesis » Wed Jun 18, 2008 6:10 am

Yeah, I noticed that. I have a feeling that register may not exist on the YM2612, as according to this documentation, the register defaults to 0, which would mean the chip would power up in 3 channel mode. It's definitely worth testing though. They might have just changed the default. There's also the interrupt control bits in that same register which I'd be interested in testing, even though the interrupt line of the YM2612 isn't connected in the Mega Drive.

Another thing which is very interesting is the "Priscarar function" (phonetic for something?). It appears that writing to registers 0x2D, 0x2E, and 0x2F in the YM2608 adjusts the clock divider for the FM and SSG sound generation units. I'd be interested in testing whethter these registers have any effect on the YM2612.


The thing I'm most interesting in solving once and for all with this new documentation is the cause of the unusual sound in Flashback, and several other Mega Drive games. There's some discussion about it in the following thread on this forum:
http://www.spritesmind.net/_GenDev/foru ... =2699#2699

What we know is that this problematic instrument uses the channel 3 "special" mode, where a separate frequency is specified for each operator in the channel. I've been going through the documentation trying to get my head around all the implications of this mode, and here's what I've got so far. Here's what the new YM2608 manual says about this mode:

Code: Select all

2-8-4 Setting of mode of CH3

      Channel 3 can set the mode by $27 “D7,D6". 

                       Table 2-1C CH3 mode
------------------------------------------------------------------------
|D7|D6|Mode        |           Function                                |
|--|--|------------|---------------------------------------------------|
| 0| 0|Normality   |It pronounces normally as well as other CH.        |
|--|--|------------|---------------------------------------------------|
| 0| 1|CSM         |It becomes CSM voice synthesis mode, and F-Number  |
|  |  |            |can be set each every of the four slots. Key-on/off|
|  |  |            |at the CSM mode is done with timer A.              |
|--|--|------------|---------------------------------------------------|
| 1| 0|Effect sound|Separate F-Number can be set to each slot as well  |
| 1| 0|            |as CSM.                                            |
------------------------------------------------------------------------
Several things about this table:
1. My reading is that the last entry should apply to bit patterns 10 and 11. I think the fact they list 10 twice for the last entry is an obvious typo.
2. My understanding of the description is that the CSM and "Effect Sound" modes both enable the use of the extra channel 3 registers to specify the frequency/block data for each operator separately. The difference between the two seems to be that in the CSM mode, Timer A is somehow used to automatically toggle key on/off. The text seems to suggest that this does not happen in "Effect sound" mode, it simply activates the separate frequency numbers for each operator.

What I don't know from reading this documentation is how exactly this "key on/off" on Timer A works. Obviously something happens when Timer A expires, but there's a few different ways I could imagine this being implemented. Does it always simply set key on for each Timer A, and never send a key-off? Does it alternate between key on/key off as the timer expires? I'd want to confirm exactly what the behaviour is.

Comparing the table in the YM2608 manual with the one in the Genesis Software Sound Manual, here's what Sega says about this mode:

Code: Select all

-------------------------------------------------------------
|CH 3 Mode |D7|D6|                                          |
|----------|--|--|------------------------------------------|
|NORMAL    | 0| 0|Channel 3 is the same as the others.      |
|----------|--|--|------------------------------------------|
|SPECIAL   | 0| 1|Channel 3 has four separate frequencies.  |
|----------|--|--|------------------------------------------|
|ILLEGAL   | 1| X|                                          |
-------------------------------------------------------------
This would suggest that what we currently call channel 3 "special" mode is in fact CSM mode, and that in order to emulate it, we should be doing the key on/off on Timer A. Perhaps the sound error is due to this feature not being emulated?

Another thing of note, is that the Sega documentation and the YM2608 documentation disagree about which frequency values affect which operators. Here's what it says in the Genesis Software Sound Manual, page 12:
"Channel 3 operator 1's frequency is in Registers A2 and A6. Operators 2 and 4 are in Registers A8 and AC, A9 and AE, and AA and AE, respectively."
Well, for one thing, I assume they meant to say "Operators 2, 3, and 4", and there's the glaring error that they listed register AE twice. The third pair should have been A9, AD. Even if you account for those errors though, that doesn't match up with the register assignments given in the YM2608 manual. The table on page 20 of the YM2608 Application Manual gives the following register allocation:

Code: Select all

------------------
|Operator 1|A9,AD|
|Operator 2|AA,AE|
|Operator 3|A8,AC|
|Operator 4|A2,A6|
------------------
Compared with the numbers they were trying to give in Sega's documentation:

Code: Select all

------------------
|Operator 1|A2,A6|
|Operator 2|A8,AC|
|Operator 3|A9,AD|
|Operator 4|AA,AE|
------------------
We know that the registers for operators 2 and 3 are switched in the Sega documentation, so if you use the same operator numbers as are given in the register list in the Sega documentation, you should reverse operators 2 and 3 in that table. Even if you do that however, the Sega documentation clearly says that the frequency for operator 1 is in A2,A6, while the YM2608 manual says that's the frequency for operator 4. Can anyone who's worked with the YM2612 in hardware, or written a working YM2612 core, confirm which register numbers match up to which operators?

TascoDLX
Very interested
Posts: 246
Joined: Tue Feb 06, 2007 8:18 pm

Post by TascoDLX » Wed Jun 18, 2008 11:13 am

Nemesis wrote:"Priscarar function" (phonetic for something?)
Prescaler.

User avatar
Nemesis
Very interested
Posts: 670
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Post by Nemesis » Wed Jun 18, 2008 12:19 pm

Yeah, that's probably it. I found another phonetic entry in the ADPCM section of "Priscal" which is known to definitely mean prescale. It's the part at the end which is throwing me a bit. It almost seems like it's another word tacked on. I was thinking "priscarar" might mean something along the lines of "Prescale rate", but that doesn't match "Sastenrat" which means "Sustain rate". Maybe it is just supposed to be "prescaler".

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Jun 18, 2008 1:04 pm

Nemesis wrote:Another thing which is very interesting is the "Priscarar function" (phonetic for something?). It appears that writing to registers 0x2D, 0x2E, and 0x2F in the YM2608 adjusts the clock divider for the FM and SSG sound generation units.
Prescaler, also works on YM2203. Don't know about YM2612.
Nemesis wrote:Well, for one thing, I assume they meant to say "Operators 2, 3, and 4", and there's the glaring error that they listed register AE twice. The third pair should have been A9, AD. Even if you account for those errors though, that doesn't match up with the register assignments given in the YM2608 manual.
In MAME OPN emulation code register pairs for multi-frequency mode are A6A2, ACA8, AEAA, ADA9. When I did test of that mode, it worked same in all emulators and on real hardware.

User avatar
Nemesis
Very interested
Posts: 670
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Post by Nemesis » Wed Jun 18, 2008 2:38 pm

Ok, so those register pairs are different again. If that's the correct allocation, that would mean both the documents are wrong.

In your testing on the hardware, did you specifically test and confirm the register allocation, or were you just listening to the sound output for the channel as a whole? It's possible swapped register pairs could have little audible effect on the sound output, depending on how the sound is being created. It seems the best way to test this would be to set algorithm 8 (each operator as a slot), and key-on each individual operator separately, with separate frequencies in each register. By stepping one operator at a time, you could tell which registers were being used for that operator by the tone it creates. I might run this test for my own piece of mind if nothing else. It would seem odd to me that neither document would have the correct info.


And speaking of key on/off, I've noticed something that's either wrong in the Yamaha documentation, or a lot of emulators probably get wrong. Both the Sega and Yamaha documentation agree that when it comes to setting key on/off for individual operators in reg $28, D7=op4, D6=op3, D5=op2, and D4=op1. When it comes to all the other registers however, the Sega documentation has operators 2 and 3 switched.

I'm pretty sure in the past with only the Sega document as a reference, most people have switched the operator numbers in the algorithm table, assuming that's where the error was. We can see in this document from Yamaha however that the numbers in the algorithm tables were correct, and that it was the register locations which were switched. The correct order of the operators is op1, op3, op2, op4 in the register blocks. The Yamaha docs agree that the operator numbers come sequentially in the key on/off register however. If the Yamaha docs are correct, and an emulator has been written assuming the registers came sequentially in the register block, then the bits for operator 2 and 3 would have to be switched in the key on/off register, otherwise the wrong operator would be affected. This might not be easily noticed either, as operators aren't usually controlled separately.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Jun 18, 2008 2:55 pm

Nemesis wrote:Ok, so those register pairs are different again. If that's the correct allocation, that would mean both the documents are wrong.
Actually, order which I said is same as in YM2608 doc, just reversed by some reason.
Nemesis wrote:In your testing on the hardware, did you specifically test and confirm the register allocation, or were you just listening to the sound output for the channel as a whole?
Main goal of test was to check if second bank of YM2612 has multi-frequency mode (it does not). But I used algo #7 (all operators are slots) and separate Key On/Off for each operator in that test. You can check it by yourself.
Nemesis wrote:If the Yamaha docs are correct, and an emulator has been written assuming..
I highly doubt that any of YM2612 emulators was written with info from docs only, without very many tests on real hardware.

Eke
Very interested
Posts: 820
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Wed Jun 18, 2008 6:28 pm

The emulators are correct regarding operator order and register addresses, even for CH3 special mode,

it's just that the YM2612 doc is wrong...

but this new doc seems correct for me, this is exactly the same order as in MAME emu (S1>S3>S2>S4 for common registers and S4>S3>S1>S2 for CH3 frequencies)

the operator bits in KEYON/OFF register is also the same
What I don't know from reading this documentation is how exactly this "key on/off" on Timer A works. Obviously something happens when Timer A expires, but there's a few different ways I could imagine this being implemented. Does it always simply set key on for each Timer A, and never send a key-off? Does it alternate between key on/key off as the timer expires? I'd want to confirm exactly what the behaviour is.
in emulators (MAME for example), it only set KEY ON for all operators
while reading the new doc, it seems to me it could be that
the first time it occurs, key ON is set than the next time, Key OFF is set (and so on...)

still, I 'm not sure to understand the difference between the 2 special mode, is that only the Timer A behaviour ? Also note that in emulators, the TimerA Key ON (CSMKeyControll in MAME core) only happen when the last bit is set, which is in contradiction with this doc...
Last edited by Eke on Wed Jun 18, 2008 6:56 pm, edited 3 times in total.

AamirM
Very interested
Posts: 469
Joined: Mon Feb 18, 2008 8:23 am
Contact:

Post by AamirM » Wed Jun 18, 2008 6:28 pm

Hi,
Nemesis wrote:The thing I'm most interesting in solving once and for all with this new documentation is the cause of the unusual sound in Flashback, and several other Mega Drive games.
I have spent many tens of hours trying to figure out this one but unable to do so. I've looked into (and tried) every possible reasoning there is. I remember that I once changed operator order and it sounded very close Kega (but not exact, I don't have MD anymore to test real hardware recording) but it broke sound in Todd's Slime World. But if we have gotten the operator order wrong and Steve Snake has it right then why does it is only corrected in SuperHQ mode? I also tried various things with Key On/Off using Timer A but no success there either.

Game Music Emu by Blargg has a modified Gens core in which this is fixed (possibly using FIR filtering which it has) but I haven't gotten any time to figure out how its done. If anybody else could use that core in some emu to see if it is in fact the FIR filtering or something in that pirticular version of Gens core, then that would be awesome.

Also, this blip sound doesn't only happen in one pirticular setting which Eke described in another topic. This blip sound is also present in Vector Man 2 in music called 'Planet Fall Dig' using a slightly different setting.

I think its the FIR filtering which will fix this.

stay safe,

AamirM

Eke
Very interested
Posts: 820
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Wed Jun 18, 2008 6:49 pm

Also, did you notice that the Key-Code calculation is also wrong in YM2612 doc ?

it said it was made from the 3 bits of BLOCK and from the 2 high frequency bits which is not what this new doc tells us:

KEY CODE is made of BLOCK data 3 bits (OK) but then with N3 and N4 bits where:
N4 = last bit of frequency (OK)
N3 is a strange combination of the 4 last frequency bits


Some other stuff different from the original doc:

- DETUNE varies with KEY CODE value also

- when using KEYSCALE formula (FINAL RATE = 2*RATE + KS_RATE):

FINAL RATE will be 0 if RATE is 0, regardless of KS_RATE value
the maximal RATE value is bounded to 63
RR is different from the others (normal, it's one bit less), RATE=2*RR+1


I didn't looked into emulator to see if they emulate this correctly (probably yes)

User avatar
Nemesis
Very interested
Posts: 670
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Post by Nemesis » Thu Jun 19, 2008 12:49 am

Shiru wrote:
Nemesis wrote:Ok, so those register pairs are different again. If that's the correct allocation, that would mean both the documents are wrong.
Actually, order which I said is same as in YM2608 doc, just reversed by some reason.
Actually, after checking again, the order of the registers you confirmed in your hardware tests, and the order currently used in MAME, both match the YM2608 documentation. It is just the Sega documentation that's wrong. You might have read the operator bits backwards in the key on/off register. From a post of yours in the thread you linked to:
D7 - operator, which frequency defined by A6A2
D6 - .. ACA8
D5 - .. AEAA
D4 - .. ADA9
Where D7=op4, D6=op3, D5=op2, and D4=op1. That matches the YM2608 document. At least that's confirmed then.
I highly doubt that any of YM2612 emulators was written with info from docs only, without very many tests on real hardware.
I must say, I didn't expect to find this many errors and omissions in the Sega documentation, and there are some big ones in there. No wonder YM2612 emulation is the last thing Mega Drive emulators tend to get right, if ever. You're probably right, I don't think it would have been possible to get a YM2612 core off the ground at all without tests in hardware, and only the Sega document as a reference.
still, I 'm not sure to understand the difference between the 2 special mode, is that only the Timer A behaviour ? Also note that in emulators, the TimerA Key ON (CSMKeyControll in MAME core) only happen when the last bit is set, which is in contradiction with this doc...
I must say, I'm a bit unclear on the distinction between the two as well. It seems to me to be saying that the "Effect Sound" mode is just the separate frequency part of the CSM mode, without key on/off on timer A. There is a bit of ambiguity in the translated text however. I might get the text in this particular section professionally translated, just to be sure of the meaning. It would have been nice to have at least a good paragraph describing the channel 3 modes though. A few sentences in a table really isn't enough to sum up all the details of these modes.

It does sound a bit sus that MAME only enables CSM mode when D7 is set. The Sega documentation certainly doesn't mention anything about key on/off on timer A, they simply describe the separate frequency values for each slot. I would be surprised if every Mega Drive game has been using CSM mode without having the information about the timer A key on/off control. It's possible the Yamaha documentation has these bits switched. This definitely needs to be tested in hardware.

Game Music Emu by Blargg has a modified Gens core in which this is fixed (possibly using FIR filtering which it has) but I haven't gotten any time to figure out how its done. If anybody else could use that core in some emu to see if it is in fact the FIR filtering or something in that pirticular version of Gens core, then that would be awesome.
I might look into that. I'm at the stage of planning the YM2612 core for my emulator, and it would be good to know the answer to this mystery before I repeat the same mistakes.

Also, did you notice that the Key-Code calculation is also wrong in YM2612 doc ?
I actually hadn't spotted that. It's a subtle difference, which means it's probably wrong in a few different emulators.
Some other stuff different from the original doc:

- DETUNE varies with KEY CODE value also

- when using KEYSCALE formula (FINAL RATE = 2*RATE + KS_RATE):

FINAL RATE will be 0 if RATE is 0, regardless of KS_RATE value
the maximal RATE value is bounded to 63
RR is different from the others (normal, it's one bit less), RATE=2*RR+1
Good finds. I'd noticed all those special case rules for the keyscale formula, but I hadn't compared to the Sega documentation to see if it covered them. Seems it doesn't. I actually thought the Sega documentation had mentioned detune being affected by rate scaling, but looking back over it, it seems I was wrong about that.

bobthebuilder
Interested
Posts: 22
Joined: Thu Jun 19, 2008 4:36 am

Post by bobthebuilder » Thu Jun 19, 2008 4:43 am

I think it would be a great idea if the manual was submitted to romhacking.net.

Nemesis, you can have the guys at romhacking.net help translate any parts that need clarification (several of them are professionals). Here is a link to the forum that can help: http://www.romhacking.net/forum/index.p ... d,9.0.html

User avatar
Nemesis
Very interested
Posts: 670
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Post by Nemesis » Thu Jun 19, 2008 4:59 am

Am I the only one who finds the formula for the N3 bit of the keycode confusing? Here's how the YM2608 manual says the N3 bit is calculated, on page 25:

N3=F11・( F10+F9+F8 ) + !F11・F10・F9・F8

This is a boolean calculation, so their operator symbols are confusing me a bit. I don't see how addition has any place in this operation, and I haven't seen that dot symbol used in this context before. I somehow doubt they're talking about vector dot product. Fortunately they've given us some sample data above.

Code: Select all

------------------
|F11|F10|F9|F8|N3|
|----------------|
| 0 | 1 | 0| 1| 0|
| 0 | 1 | 1| 0| 0|
| 0 | 1 | 1| 1| 1|
| 1 | 0 | 0| 0| 0|
| 1 | 0 | 0| 1| 1|
------------------
So given those combinations of F11, F10, F9, and F8, that's the resulting N3 bit they're somehow getting using that above equation. Can anyone figure out how to actually interpret that formula to get these results?

User avatar
Nemesis
Very interested
Posts: 670
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Post by Nemesis » Thu Jun 19, 2008 5:15 am

bobthebuilder wrote:I think it would be a great idea if the manual was submitted to romhacking.net.

Nemesis, you can have the guys at romhacking.net help translate any parts that need clarification (several of them are professionals). Here is a link to the forum that can help: http://www.romhacking.net/forum/index.p ... d,9.0.html
Looks good to me. I might submit the original. I won't enter my transcription just yet though. Now that I've finished the transcription and I actually have time to read the document, I've found a number of errors in the transcription and the OCR that I missed in my initial checks. I've also been translating phonetic words into their proper English equivalents as I confirm them. In a week or so once the corrections settle down, I'll release an updated document and submit it to romhacking.net.

TascoDLX
Very interested
Posts: 246
Joined: Tue Feb 06, 2007 8:18 pm

Post by TascoDLX » Thu Jun 19, 2008 5:51 am

Nemesis wrote:Am I the only one who finds the formula for the N3 bit of the keycode confusing? Here's how the YM2608 manual says the N3 bit is calculated, on page 25:

N3=F11・( F10+F9+F8 ) + !F11・F10・F9・F8

This is a boolean calculation, so their operator symbols are confusing me a bit. I don't see how addition has any place in this operation, and I haven't seen that dot symbol used in this context before. I somehow doubt they're talking about vector dot product. Fortunately they've given us some sample data above.
It's boolean algebra: + is OR, ・ is AND, ! is NOT. Order of operations (ignoring parentheses) is NOT then AND then OR.

This formula can be split into two cases:

* If F11 is set (1), then only one of the other three ( F10, F9, F8 ) need be set (1). [1001, 1010, 1011, 1100, 1101, 1110, 1111]
* If F11 is not set (0), then the other three ( F10, F9, F8 ) must all be set (1). [0111]

The formula can be rewritten thusly:

N3 = F11・( F10+F9+F8 ) + !F11・( F10・F9・F8 )

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest