Nes ROM with 5b sound

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Nes ROM with 5b sound
by on (#240917)
Hi, i've got a project going on where im planning to make a YM2149 expansion port sound module.
But i can not figure out a way to create a rom file that i would be able to flash to a cartridge.

I do not have a powerpak or similar and neither do i have a gimmick cart.

All i want is a nes rom with 2A03+5b music starting directly. preferrably with mapper 0 or mmc3 (got a modded mother cart i could use)


How do i manage this? :)
Re: Nes ROM with 5b sound
by on (#240918)
You have to use mapper 69. That's the 5B mapper. You can't just put 5B mapper sound on a different mapper.

https://wiki.nesdev.com/w/index.php/Sunsoft_FME-7

(Your flash cartridge won't have 5B sound on it either, unless it was made with that hardware.)
Re: Nes ROM with 5b sound
by on (#240919)
"But i can not figure out a way to create a rom file that i would be able to flash to a cartridge. I do not have a powerpak or similar and neither do i have a gimmick cart."

There are ways to solve this, but not ways to solve your next dilemma:

"All i want is a nes rom with 2A03+5b music starting directly. preferrably with mapper 0 or mmc3 (got a modded mother cart i could use). How do i manage this? :)"

In short: you can't. The end.
Re: Nes ROM with 5b sound
by on (#240920)
What i am doing is creating a expansion port sound card/module.
So i am not using the 5B chip per say.

So i am not able to select and write to $C000 and $E000 without a 69 mapper?
because thats all i need to do from what i understand (well ofc write correct info to create sound)
Re: Nes ROM with 5b sound
by on (#240922)
Perkka wrote:
What i am doing is creating a expansion port sound card/module.
So i am not using the 5B chip per say.

So i am not able to select and write to $C000 and $E000 without a 69 mapper?
because thats all i need to do from what i understand (well ofc write correct info to create sound)

You mean the NES Expansion Port? https://wiki.nesdev.com/w/index.php/Expansion_port#NES
If you're planning on attaching a YM2149 to the expansion port you will need to create the hardware to connect it. The Sunsoft 5B chip has the hardware inside it to translate writes at C000 and E000 to what the YM2149 inside it expects. If you aren't planning on using an actual 5B, you will need to create this yourself. And whether or not it responds to C000 or E000 will depend on how your circuit is designed (and you will need to route the appropriate signals to the EXP0-9 signals in your cart). If you want to use C000 and E000, for example, you'll probably need to route at least A14/A13 (A15 is already there) and CPU R/W. You will also need to account for bus conflicts if your donor is an MMC0 (MMC3 already has registers throughout 8000-FFFF so you can't use those ranges).
Re: Nes ROM with 5b sound
by on (#240923)
GreyRogue wrote:
Perkka wrote:
What i am doing is creating a expansion port sound card/module.
So i am not using the 5B chip per say.

So i am not able to select and write to $C000 and $E000 without a 69 mapper?
because thats all i need to do from what i understand (well ofc write correct info to create sound)

You mean the NES Expansion Port? https://wiki.nesdev.com/w/index.php/Expansion_port#NES
If you're planning on attaching a YM2149 to the expansion port you will need to create the hardware to connect it. The Sunsoft 5B chip has the hardware inside it to translate writes at C000 and E000 to what the YM2149 inside it expects. If you aren't planning on using an actual 5B, you will need to create this yourself. And whether or not it responds to C000 or E000 will depend on how your circuit is designed (and you will need to route the appropriate signals to the EXP0-9 signals in your cart). If you want to use C000 and E000, for example, you'll probably need to route at least A14/A13 (A15 is already there) and CPU R/W. You will also need to account for bus conflicts if your donor is an MMC0 (MMC3 already has registers throughout 8000-FFFF so you can't use those ranges).


Yes this is what i was planning to do. And yes i were aware of the rerouting needed to be done, i believe i need to reroute 4 lines. A14, A13,R/W and CE.
I had missed the part with bus conflicts though. What would happen if i wrote to those on an MMC3 mapper if i had the sound chip connected?
And do you know what mappers that would not conflict?

I want to make this as compatible as possible with existing hardware and emus.

my plans started when i stumbled over this: https://mikejmoffitt.com/articles/0043- ... mmick.html
i wanted to create an expansion port sound card that could be used without the need of a chip in the cartridge.
Re: Nes ROM with 5b sound
by on (#240924)
Perkka wrote:
And do you know what mappers that would not conflict?

Start going through the mapper list one by one: https://wiki.nesdev.com/w/index.php/Mapper . Sometimes there will be an infobox in the upper right listing off bus conflicts, other times not, but you will most likely have to read the descriptions to get a full understanding.

Do not rely on https://wiki.nesdev.com/w/index.php/Cat ... _conflicts as it is incomplete (many mappers are missing the proper Category to place them there). Above paragraph is what needs to be done.
Re: Nes ROM with 5b sound
by on (#240925)
Perkka wrote:
Yes this is what i was planning to do. And yes i were aware of the rerouting needed to be done, i believe i need to reroute 4 lines. A14, A13,R/W and CE.
I had missed the part with bus conflicts though. What would happen if i wrote to those on an MMC3 mapper if i had the sound chip connected?
And do you know what mappers that would not conflict?

Actually, looking a little closer, you might be able to get away with MMC3. As long as your code doesn't need IRQs, and you ensure you only write to even addresses (e.g. C000 and E000 and not E001), it should work without bus conflicts. The writes to c000 and e000 will update the irq registers on the MMC3, but as long as you don't enable them, it shouldn't matter.
Re: Nes ROM with 5b sound
by on (#240926)
koitsu wrote:
Perkka wrote:
And do you know what mappers that would not conflict?

Start going through the mapper list one by one: https://wiki.nesdev.com/w/index.php/Mapper . Sometimes there will be an infobox in the upper right listing off bus conflicts, other times not, but you will most likely have to read the descriptions to get a full understanding.

Do not rely on https://wiki.nesdev.com/w/index.php/Cat ... _conflicts as it is incomplete (many mappers are missing the proper Category to place them there). Above paragraph is what needs to be done.

What exactly do i look for, i am sadly not very knowledgeable in how this works.

GreyRogue wrote:
Perkka wrote:
Yes this is what i was planning to do. And yes i were aware of the rerouting needed to be done, i believe i need to reroute 4 lines. A14, A13,R/W and CE.
I had missed the part with bus conflicts though. What would happen if i wrote to those on an MMC3 mapper if i had the sound chip connected?
And do you know what mappers that would not conflict?

Actually, looking a little closer, you might be able to get away with MMC3. As long as your code doesn't need IRQs, and you ensure you only write to even addresses (e.g. C000 and E000 and not E001), it should work without bus conflicts. The writes to c000 and e000 will update the irq registers on the MMC3, but as long as you don't enable them, it shouldn't matter.


Ok, that sounds promising i guess :)
I guess Mapper 0 would work without issues also?

still i have no knowledge at all with programming to the nes etc. But i felt that building the circuit to make it all work looked really simple and it would be fun if it somehow could benefit people to make games with extra sound channels.

I have seen rainwarriors sound test roms ans were thinking i could flash them to a cart of some kind. but i do not know, especially when i suspected it to work in an emu to begin with and it feels like it's not.
Then i do not know if i simply have issues with the rom or if it's my circuit when testing.

I have not built anything yet for it, just ordered the YM2149 and waiting for it to arrive.
Re: Nes ROM with 5b sound
by on (#240930)
For mapper 0, it might be helpful to make a ROM that runs correctly as either mapper 0 with a YM2149 or mapper 69. That can be done by adding a bit of code to the reset process somewhere above $E000:
Code:
; Poke in the values to make mapper 69 map PRG and CHR ROM
; the same way as to mapper 0
sunsoft5_init_nrom:
  ldx #13
  loop:
    stx $8000
    lda sunsoft5_nrom_values,x
    sta $A000
    dex
    bpl loop
  jmp old_reset

sunsoft5_nrom_values:
  .byte 0, 1, 2, 3, 4, 5, 6, 7  ; CHR banks
  .byte $C0, 0, 1, 2            ; PRG banks
  .byte 0, 0                    ; Mirroring/IRQ

Once you work through a few 6502 tutorials, what this does will make sense.
Re: Nes ROM with 5b sound
by on (#240936)
There's a simple definition that is compatible with every existing mapper, and requires only signals that are already on the expansion port.

Note that top-loading NESes don't have an expansion port.

In the NES, writes to $4016 keep track of the bottom three bits, but only the bottom one bit is normally accessible. The other two bits are only on the expansion port, and could be used as a signal to latch the upper five bits.

So a simple design, using the other major PSG of the era (the SN76494) might latch D7-D4 on a rising edge of OUT2, latch D7-D4 (save as the lower half byte) on a falling edge of OUT2, and connect OUT1 to /WE and /CE. A game would do something like

Code:
lda #$76 ; 1789773Hz÷110Hz = 508 = 0b0111_1111_00 ; four msbits here, out2 rising edge, out1 high
sta $4016
lda #$10 ; select register 0, "tone 1 frequency", and out2 and out1 falling edges
sta $4016
ldx #6
delay1: dex
bpl delay1
lda #$F6 ; four middle bits of period here, out2 rising edge, out1 high
sta $4016
lda #0 ; two lsbits here, and out2 and out1 falling edges
sta $4016
ldx #6
delay2: dex
bpl delay2
lda #2 ; prevent re-write of register
sta $4016


The AY-3-8910 requires nine bits, not eight, but a similar division is possible. The expansion port even provides the user with access to the 4MHz CIC clock, but it's a low-quality clock source and probably wouldn't be in tune with the crystal used by the NES itself.

Some existing games that were also released in Japan might already use OUT1 and OUT2 for other purposes.
Re: Nes ROM with 5b sound
by on (#240937)
I managed to get a NES rom with 5b sound after searching a lot more, got it by using eznsf.
the rom seem to call the right addresses but it wont output sound on the 5b chip (atleast not in mesen). This led me to think, it will never work with other mappers then 69 in emulators if not custom support is added.
The rom will most likely work on the real hardware once i built it. but it sort of defeats the purpose that i wanted to build something that would have good support from the get go.

Now if i create this maybe i should take an other approach of some kind. sure i still think YM2149 is a good choice because of famitracker support. maybe still the best choice.
should i still try to make it using the same addresses for example, and other things to consider?

lidnariq wrote:
There's a simple definition that is compatible with every existing mapper, and requires only signals that are already on the expansion port.

Note that top-loading NESes don't have an expansion port.

In the NES, writes to $4016 keep track of the bottom three bits, but only the bottom one bit is normally accessible. The other two bits are only on the expansion port, and could be used as a signal to latch the upper five bits.

So a simple design, using the other major PSG of the era (the SN76494) might latch D7-D4 on a rising edge of OUT2, latch D7-D4 (save as the lower half byte) on a falling edge of OUT2, and connect OUT1 to /WE and /CE. A game would do something like

Code:
lda #$76 ; 1789773Hz÷110Hz = 508 = 0b0111_1111_00 ; four msbits here, out2 rising edge, out1 high
sta $4016
lda #$10 ; select register 0, "tone 1 frequency", and out2 and out1 falling edges
sta $4016
ldx #6
delay1: dex
bpl delay1
lda #$F6 ; four middle bits of period here, out2 rising edge, out1 high
sta $4016
lda #0 ; two lsbits here, and out2 and out1 falling edges
sta $4016
ldx #6
delay2: dex
bpl delay2
lda #2 ; prevent re-write of register
sta $4016


The AY-3-8910 requires nine bits, not eight, but a similar division is possible. The expansion port even provides the user with access to the 4MHz CIC clock, but it's a low-quality clock source and probably wouldn't be in tune with the crystal used by the NES itself.

Some existing games that were also released in Japan might already use OUT1 and OUT2 for other purposes.



So that solution wouldnt need hardware modifications to cartridges at all? just work OOB if the software support it?
I were planning to use the 4mhz clock the port uses. trying to minimize the hardware needed. but if a crystal is needed then I'll add it.
Re: Nes ROM with 5b sound
by on (#240938)
Perkka wrote:
but it sort of defeats the purpose that i wanted to build something that would have good support from the get go.
You're not going to get expansion audio on anything other than NSFs and the mappers that originally had that specific expansion audio.

Quote:
should i still try to make it using the same addresses for example, and other things to consider?
There are too many variables here, really. You can attempt to come up with something that'll be compatible with most known hardware, but there's always going to be the oddball exceptions.

Quote:
So that solution wouldn't need hardware modifications to cartridges at all? just work OOB if the software support it?
Yeah. Personally, I think I'd rather attach a global volume control to the expansion port instead of more square waves.

But the SN76494 is also the only major tone generator from the era that didn't see its way into a Famicom cart, so I also have a soft spot for trying to fit it in.

And it probably needs some kind of mute, so that games that do do something with the upper bits written to $4016 don't break things.

Quote:
I were planning to use the 4mhz clock the port uses. trying to minimize the hardware needed. but if a crystal is needed then I'll add it.
I'd add a crystal or other clock generator. The 4MHz CIC clock will vary from console to console, and with time.
Re: Nes ROM with 5b sound
by on (#240952)
lidnariq wrote:
Perkka wrote:
So that solution wouldn't need hardware modifications to cartridges at all? just work OOB if the software support it?
Yeah. Personally, I think I'd rather attach a global volume control to the expansion port instead of more square waves.

But the SN76494 is also the only major tone generator from the era that didn't see its way into a Famicom cart, so I also have a soft spot for trying to fit it in.

And it probably needs some kind of mute, so that games that do do something with the upper bits written to $4016 don't break things.

Perkka wrote:
I were planning to use the 4mhz clock the port uses. trying to minimize the hardware needed. but if a crystal is needed then I'll add it.
I'd add a crystal or other clock generator. The 4MHz CIC clock will vary from console to console, and with time.

The SN76494 does not look to be in abundance, there seems to be a lot of one of the derivatives though, namely the SN76489.
I still think i want to do something with the YM2149, just waiting for it to arrive by post.

About the volume control, were you thinking a software controlled one? or simply a knob on the console?

I were also planning to not use the RCA outputs on the NES for sound but to have 2 of the on the expansion module, mainly because then i could reroute sound trough famicom cartridges the correct way which i guess would help with having sound levels the way it was intended. i guess it will make a difference atleast.
Re: Nes ROM with 5b sound
by on (#240953)
Perkka wrote:
About the volume control, were you thinking a software controlled one?
Yes, software controlled.
Re: Nes ROM with 5b sound
by on (#240972)
Perkka wrote:
I were also planning to not use the RCA outputs on the NES for sound but to have 2 of the on the expansion module, mainly because then i could reroute sound trough famicom cartridges the correct way which i guess would help with having sound levels the way it was intended. i guess it will make a difference at least.
That would require significant rework of the console. The two signals on the expansion port are "input to NES: mix audio in" and "output from NES: final mix" - there's no place for the Famicom's "amplified audio from 2A03" or "audio input to RF modulator" for a cartridge to stick its audio hardware in the middle.

If you compare the Famicom and NES schematic, "output from NES: final mix" is almost the same as "amplified audio from 2A03", but that's not useful without a place to re-inject audio afterwards.
Re: Nes ROM with 5b sound
by on (#240973)
lidnariq wrote:
Perkka wrote:
I were also planning to not use the RCA outputs on the NES for sound but to have 2 of the on the expansion module, mainly because then i could reroute sound trough famicom cartridges the correct way which i guess would help with having sound levels the way it was intended. i guess it will make a difference at least.
That would require significant rework of the console. The two signals on the expansion port are "input to NES: mix audio in" and "output from NES: final mix" - there's no place for the Famicom's "amplified audio from 2A03" or "audio input to RF modulator" for a cartridge to stick its audio hardware in the middle.

If you compare the Famicom and NES schematic, "output from NES: final mix" is almost the same as "amplified audio from 2A03", but that's not useful without a place to re-inject audio afterwards.


Wouldnt that mean:
"output from nes: final mix" ->exp port reroute -> famicom cartridge -> exp port rca connector (possible with amp circuit) -> TV/Aplifier
be more or less like on a famicom?
Re: Nes ROM with 5b sound
by on (#240974)
Er. Yes.

How are you handling carts that haven't been modified for this, though?
Re: Nes ROM with 5b sound
by on (#240975)
lidnariq wrote:
Er. Yes.

How are you handling carts that haven't been modified for this, though?


Possibly a switch that i can use when playing famicom games and when im not.

so ill be able to switch between
"output from nes: final mix" -> exp port reroute -> famicom cartridge -> exp port rca connector (possible with amp circuit) -> TV/Aplifier
and
"output from nes: final mix" -> exp port rca connector (possible with amp circuit) -> TV/Aplifier

Dunno if i could make something sense if the famicom adapter is connected and then have a relay switch between the two routes.


Because wouldn't this way of outputting famicom sound be more correct then the 47ohm resistor mod most people do?
Re: Nes ROM with 5b sound
by on (#240976)
Perkka wrote:
Wouldn't this way of outputting famicom sound be more correct then the 47ohm resistor mod most people do?
47 kiloohm.

But meh? It doesn't really matter how the audio is mixed as long as the balance is close enough to correct: you're unlikely to hear a difference between a properly set mixing resistor and recapitulating the Famicom's audio pathway. There's only one exception I can think of – it seems that one game that uses Namco's 163 puts a lowpass filter in the cartridge. This filter would also affect the 2A03's audio in a Famicom, but would only affect the 163's sound in a modified NES. But this pedantic increase in accuracy would sound muddier: subjectively worse.

Speaking of recapitulating the Famicom's audio pathway, the original Famicom is RF-only, and RF-modulated TV audio has so-called "75µs preemphasis", which requires deemphasis hardware (a lowpass filter at 2kHz) inside the TV. I believe I don't see anything to add this preemphasis inside reverse-engineered schematics of the RF modulator, so audio via an RF stage will be muddier than audio via the front-loader's RCA output.
Re: Nes ROM with 5b sound
by on (#240977)
lidnariq wrote:
Perkka wrote:
Wouldn't this way of outputting famicom sound be more correct then the 47ohm resistor mod most people do?
47 kiloohm.

But meh? It doesn't really matter how the audio is mixed as long as the balance is close enough to correct: you're unlikely to hear a difference between a properly set mixing resistor and recapitulating the Famicom's audio pathway. There's only one exception I can think of – it seems that one game that uses Namco's 163 puts a lowpass filter in the cartridge. This filter would also affect the 2A03's audio in a Famicom, but would only affect the 163's sound in a modified NES. But this pedantic increase in accuracy would sound muddier: subjectively worse.

Speaking of recapitulating the Famicom's audio pathway, the original Famicom is RF-only, and RF-modulated TV audio has so-called "75µs preemphasis", which requires deemphasis hardware (a lowpass filter at 2kHz) inside the TV. I believe I don't see anything to add this preemphasis inside reverse-engineered schematics of the RF modulator, so audio via an RF stage will be muddier than audio via the front-loader's RCA output.



Ok, i thought there was more issues with the mixing and different volumes, but maybe that was only faulted by the everdrive being bad at reproducing it and not an issue with real carts?
Just know there is some people adding a potentiometer instead so they can tune the volume per game basis because of different volumes, and i thought that was because of the way it was mixed was not as its intended.
Re: Nes ROM with 5b sound
by on (#240978)
Well, expansion audio via modded NES needs a configurable volume. Period. Otherwise there will be mismatched mix levels. (Edit: Mismatched when using different cartridges, I mean.)

The 47k fixed resistor was an idea from years ago, at a time when we had a lot less information than we do now about expansion audio. (A maybe naive assumption that the problem could be dealt with at the mapper implementation level... which did not work out, in the end.)

Everdrive and HD-NES both have software level adjustments at this point. PowerPak doesn't have one, but it hasn't been revised/updated in about a decade. In the absence of a software control, you can install a pot instead of a fixed resistor. Solves the same problem, just at a different point in the chain.


If you're building new hardware to support your new mapper idea, for the most widely compatible results I guess you want to build a device that will have the proper mix when a 47k resistor is applied.
Re: Nes ROM with 5b sound
by on (#240981)
rainwarrior wrote:
Well, expansion audio via modded NES needs a configurable volume. Period. Otherwise there will be mismatched mix levels.
But that's the entire point of his idea. Recapitulate the mix circuit at the point where they differ (namely: in the original Famicom, cartridge pin 45 is almost identical to the original NES's expansion port pin 22), and export it out the bottom instead of trying to re-inject it.

Or if the NES's use of a 74HCU04 produces too much of a volume difference relative to the 40H368 in the Famicom, maybe instead tap NES expansion port pin 3 instead and rebuild the 40H368-based amplifier instead.

Then again, we already have the problem that the first- and second- party Famicom models from the original runs have different mix levels anyway, so maybe this is still doomed. But I don't have enough domain knowledge to say.
Re: Nes ROM with 5b sound
by on (#240996)
lidnariq wrote:
rainwarrior wrote:
Well, expansion audio via modded NES needs a configurable volume. Period. Otherwise there will be mismatched mix levels.
But that's the entire point of his idea. Recapitulate the mix circuit at the point where they differ (namely: in the original Famicom, cartridge pin 45 is almost identical to the original NES's expansion port pin 22), and export it out the bottom instead of trying to re-inject it.

Or if the NES's use of a 74HCU04 produces too much of a volume difference relative to the 40H368 in the Famicom, maybe instead tap NES expansion port pin 3 instead and rebuild the 40H368-based amplifier instead.

Then again, we already have the problem that the first- and second- party Famicom models from the original runs have different mix levels anyway, so maybe this is still doomed. But I don't have enough domain knowledge to say.


Exactly :)
because i believe the first Famicom at least should have correct volume matching, would be quite sad if it didn't.
I have another issue and that is creating a working expo port connector, but that's a whole different story :P

I believe this project with all parts involved will take quite a long time :) (not to talk about my other NES projects)