Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Sonic FM hack: enabling PSG/FM mixing

Reply to topic
Author Message
  • Joined: 25 Feb 2013
  • Posts: 205
  • Location: Osaka
Reply with quote
Sonic FM hack: enabling PSG/FM mixing
Post Posted: Sat Aug 30, 2014 9:09 am
[Admin: technical stuff split from http://www.smspower.org/forums/viewtopic.php?t=14984 ]

It sound really nice!!!

I do not know if it is due to the timing isssue already discussed, but on the japanese master system the psg sound (rings, bees shooting, doors, point count, bounces in the bonus stages, etc) disappear.
  View user's profile Send private message
  • Joined: 15 Sep 2009
  • Posts: 368
Reply with quote
Post Posted: Mon Sep 01, 2014 6:09 am
The PSG sound shouldn't disappear at all, so this is weird.
Unfortunately I don't have any hardware I can test this with and don't know what even could cause this bug.
  View user's profile Send private message
  • Joined: 14 Jul 2008
  • Posts: 133
Reply with quote
Post Posted: Tue Sep 02, 2014 12:38 am
True, I have a Japanese Master System too and I'm getting quite the same problem as kamillebidan with the missing PSG sound. Unfortunately I'm getting FM music only.

There also seems to be another problem with FM music playing wrong notes in a random manner, something which is not related to the fact of being a Japanese Master System because it can be noticed too in this video by db-electronics using a Mega Drive (00:52 for example).

https://www.youtube.com/watch?v=Zqj2UpERHcs
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11875
  • Location: London
Reply with quote
Post Posted: Tue Sep 02, 2014 9:15 am
That's probably the timing issue. I'm not sure what's up with the missing PSG though.
  View user's profile Send private message Visit poster's website
  • Joined: 06 Feb 2009
  • Posts: 104
  • Location: Toulouse, France
Reply with quote
Post Posted: Tue Sep 02, 2014 10:06 am
Could it be that the Japanese Master System specific I/O chip has a feature to disable/enable PSG output mixing ?

I don't have access to my notes right now but I once analyzed the board scans available here to figure I/O chip pinout and I think I noticed the PSG output from VDP goes through a 74HC00 NAND gate which is controlled by the 315-5297 I/O chip.

Maybe it is automatically disabled when FM is accessed or there is some bit somewhere to enable/disable it ?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11875
  • Location: London
Reply with quote
Post Posted: Tue Sep 02, 2014 10:42 am
There are only two pieces of software I know of which use the both chips at the same time - the Japanese BIOS music, and Alex Kidd: The Lost stars which uses the PSG for voices and YM2413 for music, but not at the same time (there may be more like this). Maybe we need to investigate if they do some magic to enable both chips? I don't recall seeing anything special happening to disable the PSG when using FM.
  View user's profile Send private message Visit poster's website
  • Joined: 14 Jul 2008
  • Posts: 133
Reply with quote
Post Posted: Tue Sep 02, 2014 9:09 pm
The PSG output is completely disabled by something on game boot and there's no way to enable it during the game. If you hit Pause in the title screen to change to PSG music, then the game goes totally silent.

There's always the possibility of rewriting the sound effects to the FM chip too, but I suppose it's a lot of additional work and maybe the results are not worth it compared to the PSG sounds (there's several games which I prefer with PSG sound effects over its FM equivalents).
  View user's profile Send private message
  • Joined: 25 Feb 2013
  • Posts: 205
  • Location: Osaka
Reply with quote
Post Posted: Thu Sep 04, 2014 5:39 am
Some time ago I disassembled the bios file (thanks to the meka and emulicious tools), isolating the parts that produce music and deleting all the graphics stuff (I added some on my own), and commenting some stuff. I attach it hoping it helps.
extract.tgz (9.78 KB)

  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11875
  • Location: London
Reply with quote
Post Posted: Thu Sep 04, 2014 10:55 am
Interestingly, it accesses the FM chip too fast as well:
  ld c, FM_REG
  outi                ; 16
  rst $18             ; 42
  ld c, FM_DATA       ;  7
  outi                ; Time between writes = 65 cycles, docs say 84 is needed

If we assume that the FM and PSG chip ports are not relevant to the PSG muting, all that's left is $3e (I/O chip) and $f2 (FM detection):
  ld  a,%10101111
  out ($3e),a
  ld a, %00000011
  out ($f2), a

This is a bit odd, was it modified to build to a cartridge-slot-runnable version? Anyway, it seems Sonic FM is setting the unknown bits in port $3E, but setting fewer bits in $f2 - maybe bit 1 is important?
  View user's profile Send private message Visit poster's website
  • Joined: 15 Sep 2009
  • Posts: 368
Reply with quote
Post Posted: Thu Sep 04, 2014 4:33 pm
Can you please try the following ROM patch on hardware?

007FFA: BE -> C0
00C039: 01 -> 03

That should make it write the "bit 1" that was missing before.
If that's the issue, we'll need to fix the FM detection wiki page.
  View user's profile Send private message
  • Joined: 25 Feb 2013
  • Posts: 205
  • Location: Osaka
Reply with quote
Post Posted: Thu Sep 04, 2014 4:39 pm
Maxim wrote
Interestingly, it accesses the FM chip too fast as well:
  ld c, FM_REG
  outi                ; 16
  rst $18             ; 42
  ld c, FM_DATA       ;  7
  outi                ; Time between writes = 65 cycles, docs say 84 is needed

If we assume that the FM and PSG chip ports are not relevant to the PSG muting, all that's left is $3e (I/O chip) and $f2 (FM detection):
  ld  a,%10101111
  out ($3e),a
  ld a, %00000011
  out ($f2), a

This is a bit odd, was it modified to build to a cartridge-slot-runnable version?


Yes, sorry, I modified it but I didn't add a comment on that
  View user's profile Send private message
  • Joined: 14 Jul 2008
  • Posts: 133
Reply with quote
Post Posted: Thu Sep 04, 2014 10:44 pm
ValleyBell wrote
Can you please try the following ROM patch on hardware?

007FFA: BE -> C0
00C039: 01 -> 03

That should make it write the "bit 1" that was missing before.
If that's the issue, we'll need to fix the FM detection wiki page.


Right! This allows the Japanese Master System to play both FM music and PSG sound effects at the same time, and you can also switch to PSG music and sound effects in the title screen. Problem solved.

On an unrelated note, there's still the timing thing with the wrong notes being played randomly.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11875
  • Location: London
Reply with quote
Post Posted: Fri Sep 05, 2014 7:17 am
Awesome, we discovered something new. Looking at the FM chip detection code, it seems there's a third bit which is settable, I wonder what it does?

ValleyBell said timing fixes are on the way... Maybe someone will add FM chip timing checks to an emulator?
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11875
  • Location: London
Reply with quote
Post Posted: Fri Sep 05, 2014 10:11 am
Looking through old forum posts, it seems people had discovered that the low bit enables the FM chip, while in other places it's thought just to be a detection mechanism. In a few places people suggest they always see zeroes on the next two bits, but the FM detection code seems to suggest that's wrong? The Mark III FM unit schematics only show connections on the low two bits for the other chips than the YM2413, but is port $f2 handled by the I/O chip or the FM support chips?

I guess viletim's FM add-on might need an update to enable the software-controlled switching?

Does the audio level change for the different mixing options? i.e. does the PSG level change when FM is mixed in, and vice versa?
  View user's profile Send private message Visit poster's website
  • Joined: 06 Feb 2009
  • Posts: 104
  • Location: Toulouse, France
Reply with quote
Post Posted: Fri Sep 05, 2014 1:53 pm
Great finding.

About the FM detection code snippet, I think there is some confusion in the wiki, the value output to port $f2 is always ANDED with 0x01 apparently so bits 2-1 are always zero, only bit0 is switching between 0 and 1.

FM unit schematics on Enri website clearly shows that port $F2 access is handled by the FM unit board (afaik, there is no I/O chip on Mark III hardware, only discrete signals): bit 0 is latched but also enable/disable YM2413 output (through 4466 switch). Bit 1 is forced to zero and bit 2 is left undriven.

In the Japanese Master System, they likely bundled FM unit circuitry into the I/O chip, retained bit 0 behavior and added bit 1 to control PSG output as well since it was already used. Not sure about bit 2 but the fact it is not driven by the original FM unit would indicate it has no significant use, not sure why the FM detection routine do not mask it.

Port $F2 access is being decoded by 315-5297 I/O chip, YM2413 /CS line is connected to it and, as said before, both PSG and YM2413 sound output are going through a NAND gate multiplexer which is controlled by a few signals coming from I/O chip.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11875
  • Location: London
Reply with quote
Post Posted: Fri Sep 05, 2014 4:53 pm
Yes, the comment on the FM detection page is wrong - it would match an OR, not an AND. What the code is really doing is:

Bit 0: check that you read back what you write (within
Bits 1-2: check that you read back a 0 when you write a 0
Bits 3-7: ignored

...and it checks a total of 7 times, four times with a 0 and three times with a 1 in bit 0. The last value written is a 0 so the code would need to enable FM later as needed.

I guess we need to find out the behaviour of bits 1-7 on a Japanese SMS. It would be nice if bit 1 was readable, but maybe it reads as low for compatibility.

Edit: I edited http://www.smspower.org/Development/FMChipDetection to be less wrong, and added http://www.smspower.org/Development/AudioControlPort to document port $f2 a bit more.
  View user's profile Send private message Visit poster's website
  • Joined: 15 Sep 2009
  • Posts: 368
Reply with quote
Post Posted: Sat Sep 06, 2014 7:45 pm
I don't think it's so simple.
We know that value $01 enables FM and value $03 enables FM + PSG.
So the values left are $02 and $00.

Phantasy Star (and I assume lots of other games, too) writes $00 if no FM chip is detected. But with our current assumption that would also mean that all output gets disabled and I don't think they would do that.

Someone would need to test that though.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11875
  • Location: London
Reply with quote
Post Posted: Sat Sep 06, 2014 8:47 pm
Good call. I added a qualifier but it really needs some experimentation to clear things up.
  View user's profile Send private message Visit poster's website
  • Joined: 08 Dec 2013
  • Posts: 184
Reply with quote
Post Posted: Sat Sep 06, 2014 10:08 pm
My theory is that the FM unit is in control of disabling the PSG. Therefore the PSG can only be disabled, if the FM is enabled; this may have been done for compatibility reasons to prevent accidental disabling of the PSG by existing software, or something along those lines.
  View user's profile Send private message Visit poster's website
  • Joined: 06 Feb 2009
  • Posts: 104
  • Location: Toulouse, France
Reply with quote
Post Posted: Sun Sep 07, 2014 9:34 am
ValleyBell wrote
I don't think it's so simple.
We know that value $01 enables FM and value $03 enables FM + PSG.
So the values left are $02 and $00.

Phantasy Star (and I assume lots of other games, too) writes $00 if no FM chip is detected. But with our current assumption that would also mean that all output gets disabled and I don't think they would do that.

Someone would need to test that though.


I think it is.

Keep in mind that this "bit 1" function is only a thing implemented by the 315-5297 I/O chip, which can only be found in Master System equipped with a FM chip. The external FM unit on Mark III does nothing with bit 1 and there is no way to disable the PSG output through it anyway.

Consequently, FM chip will always been detected on a Japanese Master System and the only thing written to port $F2 by official software after the initial detection will be $01 (or $03 with Master System BIOS and maybe others knowing about that feature).

Software without FM support are not going to write to this port so it's safe to assume the default state on power-on is $02 with PSG output enabled or $03 with both output enabled (since FM would not produce any sound if not accessed).
  View user's profile Send private message
  • Joined: 16 May 2002
  • Posts: 1088
  • Location: italy
Reply with quote
Post Posted: Thu Oct 16, 2014 4:35 pm
Since I can't comment on Youtube anymore because I don't want to surrender to that Google+ crap, can anyone reply to this guy (he said: "I thought the YM2413 soundchip disables the SN76489 soundchip?") with the information from this topic, please?
  View user's profile Send private message Visit poster's website
  • Joined: 17 Aug 2015
  • Posts: 4
  • Location: Japan
Reply with quote
Post Posted: Mon Aug 17, 2015 3:04 pm
Wesker wrote
ValleyBell wrote
Can you please try the following ROM patch on hardware?

007FFA: BE -> C0
00C039: 01 -> 03

That should make it write the "bit 1" that was missing before.
If that's the issue, we'll need to fix the FM detection wiki page.


Right! This allows the Japanese Master System to play both FM music and PSG sound effects at the same time, and you can also switch to PSG music and sound effects in the title screen. Problem solved.

On an unrelated note, there's still the timing thing with the wrong notes being played randomly.


Hi everyone! ValleyBell, Sonic with FM is amazing! :) However, I'm still having an issue with my Mark III.

I tried burning the Sonic 1 FM v1.2 ROM file to an AT27C040 EPROM to test in my Japanese Mark III with FM Sound Unit. With the FM Unit connected, I'm getting the exact same issue with disabled PSG sounds (the pause button switching at the title only plays FM or silence).

I checked this code: "007FFA: BE -> C0 and 00C039: 01 -> 03" in a hex editor and found that at address 00C039 the value was already set at 03 in version 1.2 of the ROM file. Address 007FFA was set at value 02. I understand that the 00C039 bit value sets the FM detection mode, but what does 007FFA actually do? In version 1.1 of the ROM 007FFA is set at 1B and version 1.0 the value is set at BE.

On the FM Detection info page, it says "The SN76489 enable bit only works on a Japanese Master System. On the Mark III with FM unit, it has no effect: it is always enabled." If this is the case, why doesn't my Mark III play FM and PSG in this rom? Or, is the information incorrect and the Mark III CAN'T enable both sound chips at the same time?...
  View user's profile Send private message
  • Joined: 15 Sep 2009
  • Posts: 368
Reply with quote
Post Posted: Mon Aug 17, 2015 4:21 pm
The value at 007FFA is part of the checksum. It's just a fix to make it work properly with the US/EU BIOS. (The Japanese BIOS doesn't verify the checksum IIRC.)

The note on the wiki sounds more like it shouldn't be possible to disable the PSG chip at all on the Mark III.
Maybe one more knowledgeable with the hardware can give some advise?
  View user's profile Send private message
  • Joined: 21 Oct 2014
  • Posts: 38
  • Location: Guarulhos-SP-Brasil
Reply with quote
Post Posted: Sun Dec 13, 2015 1:41 am
Eke wrote
Great finding.

About the FM detection code snippet, I think there is some confusion in the wiki, the value output to port $f2 is always ANDED with 0x01 apparently so bits 2-1 are always zero, only bit0 is switching between 0 and 1.

FM unit schematics on Enri website clearly shows that port $F2 access is handled by the FM unit board (afaik, there is no I/O chip on Mark III hardware, only discrete signals): bit 0 is latched but also enable/disable YM2413 output (through 4466 switch). Bit 1 is forced to zero and bit 2 is left undriven.

In the Japanese Master System, they likely bundled FM unit circuitry into the I/O chip, retained bit 0 behavior and added bit 1 to control PSG output as well since it was already used. Not sure about bit 2 but the fact it is not driven by the original FM unit would indicate it has no significant use, not sure why the FM detection routine do not mask it.

Port $F2 access is being decoded by 315-5297 I/O chip, YM2413 /CS line is connected to it and, as said before, both PSG and YM2413 sound output are going through a NAND gate multiplexer which is controlled by a few signals coming from I/O chip.


Sorry for posting in old topic but I have some notes about FM Sound Unit.

About Enri website schematic of FM Sound Unit:
Can we have different FM Sound Unit or his schematic is incorrect? because in Enri schematic D0 had different conections to CI 74HC4066 and in Enri Schematic D2 is only connected to YM2413 and in FM Sound Unit which I have followed traces D2 is connected to 74HC4066 too.

I have made and attached pictures of FM Sound Unit Board and you can see traces connected into D0, D1 and D2.

Sorry, for my English. I am brazilian.
Sega Mark 3 FM module PCB Trás.png (142.65 KB)
FM Sound Unit PCB Solder Side
Sega Mark 3 FM module PCB Trás.png
Sega Mark 3 FM module PCB Frente Componentes.png (158.05 KB)
FM Sound Unit PCB Component Side
Sega Mark 3 FM module PCB Frente Componentes.png
Sega Mark 3 FM module PCB Frente Componentes #2.png (170.44 KB)
FM Sound Unit PCB Component Side 2
Sega Mark 3 FM module PCB Frente Componentes #2.png

  View user's profile Send private message Visit poster's website
  • Joined: 30 Jan 2007
  • Posts: 262
  • Location: San Jose, CA
Reply with quote
Post Posted: Sat Aug 19, 2017 4:33 am
Bumping this since I'd like to know if it's possible at all to get FM and PSG audio mixed together on a Mark III+FM Unit combo.
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!