Skip to content

A note of caution about creating NES packs from .NSF files

Technical discussion about the VGM format, and all the software you need to handle VGM files.

Moderator: Staff

A note of caution about creating NES packs from .NSF files

Post by NewRisingSun2 »

Many .NSF files available online fail to include the initialization of the SOFTCLK ($4017) register, potentially causing triangle channel notes to be played incorrectly, among other subtle problems.

I noticed this while creating a pack of Wizards & Warriors, where this makes quite an audible difference. When creating a pack from a .NSF file, be sure to always check whether the game writes something to $4017, and if it does, check whether the .NSF from that game does as well, and if not, then add that instruction to the .NSF file yourself, or look for a "fixed" version of that .NSF, for example on this website.

I have not checked how many existing packs are affected, but if they are, it should be possible to fix them by just adding the appropriate write to the beginning of each .VGM file.
Last edited by NewRisingSun2 on 2017-05-08, 18:31:16, edited 1 time in total.
  • User avatar
  • ValleyBell Offline
  • Posts: 4768
  • Joined: 2011-12-01, 20:20:07
  • Location: Germany

Post by ValleyBell »

Looking at vgm_trim, the register write is probably missing in next to all tracks due to being trimmed off.
I just added it to the list of important commands that vgm_trim restores when trimming them off.

(Most of the VGM tools were written based on the current MAME emulation cores at that time and the MAME NES APU core doesn't do anything with the step_mode variable, so I didn't consider it being important.)

tl;dr: I assume that next to none of the packs has SOFTCLK register writes unless the sound driver resends it when starting a new song.

Post by NewRisingSun2 »

Apparently, value $00 is the default value, so only games that write $80 or $C0 would need to have their packs updated.

Here is the same song with the $4017 write, and with only that write removed.
Attachments
Wizards&Warriors-Potion_With4017.vgm
(2.09 KiB) Downloaded 240 times
Wizards&Warriors-Potion_Without4017.vgm
(2.09 KiB) Downloaded 238 times

Post by NewRisingSun2 »

vgm4017 adds the $4017 write with the value given as the first command line argument in hexadecimal notation to the beginning of each of a set of .VGM or .VGZ files. If the .VGM file already contains a $4017 write, no changes are made to that file.

Example: vgm4017 C0 *.vgz

Unlike the vgm tools, vgm4017 always overwrites files, so keep a backup.

To find out the correct $4017 value for a game, load the game in FCEUX, set a write trap to 4017 in its debugger, and run the game until a write is made. Press "Run" at least a second time to make sure you catch the last $4017 write, not the first one, which may be just a clearing of the entire address space to $00.

Some games do not write to $4017 at all; their .VGMs of course should then contain no such write either. Nintendo's first-party games interestingly write to $4017 during every vblank, so vgm4017 is not needed for them. Most games however write to $4017 only at bootup and then never again; vgm4017 is for them. Famicom Disk System games usually don't write anything to $4017, as the FDS BIOS writes $C0 to the register every time the disk is accessed. This needs to be replicated in FDS .VGM files.

Note that the lack/presence of a $4017 write will only make an audible difference if the game sets $4017 to $80 or $C0 (as the default value seems to be $00), and uses APU envelopes instead of manually setting volumes during each tick of its playback handler.
Attachments
vgm4017.zip
(25.43 KiB) Downloaded 236 times
Post Reply