N163 Sound RAM Initialisation Behaviour

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
TakuikaNinja
Posts: 87
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

N163 Sound RAM Initialisation Behaviour

Post by TakuikaNinja »

Hi, this is my first post on this forum. I've been making some ROM hacks to fix stuff like DPCM bit-reversal and other obscure glitches.

A while ago, one of my online friends acquired a cart for Erika to Satoru no Yume Bouken and discovered that the title music has glitched wavetables in the accompaniment when starting from power on. This does not seem to be documented well as I could only find one clear-cut instance of it occurring online: https://youtu.be/8pXWpZ4cvQk

After checking the code in Mesen's debugger, I found out that the game neglects to initialise all of the N163's Sound RAM, yet the music driver seems to rely on some sections of it being filled with static values. I then decided to check the Sound RAM initialisation behaviour in various emulators. Here is what I know so far based on empirical testing with this game:
  • Mesen (+ Mesen-X) initialises Sound RAM with unknown static values regardless of the RAM init setting. (cannot view Sound RAM)
  • puNES initialises it with unknown static values. (cannot view memory let alone set the RAM init value)
  • BizHawk initialises it with unknown static values regardless of the RAM init override. (only checked with NesHawk so far)
  • FCEUX correctly initialises the Sound RAM in accordance with the RAM init setting.
I have not tested the behaviour on flashcarts as I do not own any myself. However, I assume the Sound RAM is initialised with static values.
Because FCEUX emulates the behaviour correctly, I was able to produce a patch for the game which fixes the Sound RAM initialisation. It has been attached to this post (I plan on submitting this to RHDN eventually). The accompaniment wavetables should sound correct (i.e. the same as it would when the song also plays at the station) regardless of the RAM init setting.

Help with investigating this behaviour on flashcarts, "emulation-box" systems, and other emulators would be very helpful.
Adding this information to the NESdev Wiki would also be nice: https://www.nesdev.org/wiki/Game_bugs#R ... ter_values

(I honestly wasn't expecting FCEUX to get something like this right...)
Attachments
erika_init_test.ips
(63 Bytes) Downloaded 27 times
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: N163 Sound RAM Initialisation Behaviour

Post by rainwarrior »

I recently wrote a test to investigate whether N163-internal-RAM writing and reading works, to help when working on a flash cart implementation. It doesn't check the contents at startup, but you could probably modify it to do so, by just removing the code that writes to it first before reading back: viewtopic.php?p=284414#p284414

Could you explain what that video is documenting? I'm not sure where I should be looking within the 6 hours, and I don't understand enough Japanese to follow a lot of what they are saying.

I don't remember finding weird power-on behaviour with my Erika cart, but I have noticed that in hotswap tests, the sound can sometimes begin immediately playing garbage tones when the cartridge is inserted into the already powered-on Famicom.

Could you explain how to produce the problem on the cart? Should it just sounds weird some amount of the time?
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: N163 Sound RAM Initialisation Behaviour

Post by rainwarrior »

Went and tried my Erika cart, and it was extremely easy to reproduce. Just turn on, wait for the bubbles to appear, the star descends, then the music starts and one of the channels will either be very buzzy or not.

Seems to occur on about 50% of power-ons. If you start the game, then hit reset, the intro song will have fixed it and it will sound fine. If you reset before starting the game, the sound remains.

I guess I never noticed, probably just figured I hadn't inserted the cart right or something when it happened in the past and never paid it mind.

Incidentally I actually wrote the memory randomization for FCEUX. ;) I didn't do anything specifically for N163 though, it had shared functions for allocating and clearing memory buffers and I just made those use the randomizer, which I guess must have applied to the N163 sound RAM (as it should!).
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: N163 Sound RAM Initialisation Behaviour

Post by rainwarrior »

Here's a test ROM that just dumps the contents of N163 sound RAM. This will tell you how your emulator has initialized it.

n163_soundram_init.zip
(4.27 KiB) Downloaded 48 times

I've also added a few notes to the wiki about this.
User avatar
TakuikaNinja
Posts: 87
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: N163 Sound RAM Initialisation Behaviour

Post by TakuikaNinja »

I was going to clarify some info after the post was approved but it seems like you got it down. Thank you very much for the test ROM - I'll use that to check the behaviour on other emulators and report any inaccuracies on their issue trackers.
User avatar
TakuikaNinja
Posts: 87
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: N163 Sound RAM Initialisation Behaviour

Post by TakuikaNinja »

Ok, I've set up a spreadsheet documenting the test ROM outputs from various emulators (+ one flashcart I got a friend to test on):
https://docs.google.com/spreadsheets/d/ ... sp=sharing
I've also added some notes regarding the regular RAM initialisation, tested via Coredump.
Results from the Everdrive N8 Pro & PowerPak are missing at the moment. If anyone has them, please run the test ROM and report the results here. Thanks in advance.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: N163 Sound RAM Initialisation Behaviour

Post by rainwarrior »

Older PowerPak N163 mappers will not read back the sound RAM, so they won't display a valid result.

I recently wrote a new PowerPak N163 mapper that can, however: thread link

From this test it appears that when the PowerPak's FPGA is programmed, the internal block RAM is reset to 0, so it is consistently all zero after game load.


The old mappers would also have been reset to 0, but the result displayed by this test would have likely been one consistent value repeated and not an actual RAM read result. The write-and-readback test would demonstrate the unavailability of read-back, which has to pass before the init read-back test can be considered valid.

If an emulator or flash cart doesn't implement read-back, most games will still play, but the ones that save to sound RAM won't save. Namco Classic II is an outlier that will lock up when trying to select a caddy if there is no read-back capability.
User avatar
forple
Posts: 29
Joined: Sat Dec 30, 2017 2:09 pm

Re: N163 Sound RAM Initialisation Behaviour

Post by forple »

Bit of a thread bump but I finally tested this on an N8 Pro. Unsurprisingly the results are pretty generic; all entries are initialized with $00 upon being booted up.
N163 RAM init test on a N8 Pro.
N163 RAM init test on a N8 Pro.
Post Reply