<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.gamehacking.org/index.php?action=history&amp;feed=atom&amp;title=NSF</id>
	<title>NSF - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.gamehacking.org/index.php?action=history&amp;feed=atom&amp;title=NSF"/>
	<link rel="alternate" type="text/html" href="https://wiki.gamehacking.org/index.php?title=NSF&amp;action=history"/>
	<updated>2026-06-13T18:10:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=2593&amp;oldid=prev</id>
		<title>MathUser at 18:53, 9 November 2008</title>
		<link rel="alternate" type="text/html" href="https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=2593&amp;oldid=prev"/>
		<updated>2008-11-09T18:53:28Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:53, 9 November 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l197&quot;&gt;Line 197:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 197:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Open any regular game rom, open the hex viewer, then open the NSF file you want with the Hex viewer open. Run another copy of FCEUXDSP, and load the rom of the game you&amp;#039;re working on an NSF of. In the game window, open it&amp;#039;s hex-editor window too. In the emulator with the game running, get some music going, and click-drag downward from 0x200 until you have 0x700 bytes selected, and copy the information to the clipboard. This skips 0x100, where the stack is stored. In the NSF-emulating window&amp;#039;s hex editor, paste the info at 0x200, and see if the NSF plays the music correctly. If it does, you can narrow down the amount of info copied selectively, until you get the bit of information it needs to play, and find what routine needs to be adding this info to RAM. Some fixes can consist of a single byte of difference in RAM between the original, and the repaired version of an NSF. Note that this will require that the right banks be loaded, or it will fail outright. An inaccurate Play address can also result in a lack of sound.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Open any regular game rom, open the hex viewer, then open the NSF file you want with the Hex viewer open. Run another copy of FCEUXDSP, and load the rom of the game you&amp;#039;re working on an NSF of. In the game window, open it&amp;#039;s hex-editor window too. In the emulator with the game running, get some music going, and click-drag downward from 0x200 until you have 0x700 bytes selected, and copy the information to the clipboard. This skips 0x100, where the stack is stored. In the NSF-emulating window&amp;#039;s hex editor, paste the info at 0x200, and see if the NSF plays the music correctly. If it does, you can narrow down the amount of info copied selectively, until you get the bit of information it needs to play, and find what routine needs to be adding this info to RAM. Some fixes can consist of a single byte of difference in RAM between the original, and the repaired version of an NSF. Note that this will require that the right banks be loaded, or it will fail outright. An inaccurate Play address can also result in a lack of sound.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;GSHI pages&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Hacking and Game Info&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MathUser</name></author>
	</entry>
	<entry>
		<id>https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=2457&amp;oldid=prev</id>
		<title>MathUser at 13:51, 17 October 2008</title>
		<link rel="alternate" type="text/html" href="https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=2457&amp;oldid=prev"/>
		<updated>2008-10-17T13:51:20Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:51, 17 October 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l196&quot;&gt;Line 196:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 196:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Open any regular game rom, open the hex viewer, then open the NSF file you want with the Hex viewer open. Run another copy of FCEUXDSP, and load the rom of the game you&amp;#039;re working on an NSF of. In the game window, open it&amp;#039;s hex-editor window too. In the emulator with the game running, get some music going, and click-drag downward from 0x200 until you have 0x700 bytes selected, and copy the information to the clipboard. This skips 0x100, where the stack is stored. In the NSF-emulating window&amp;#039;s hex editor, paste the info at 0x200, and see if the NSF plays the music correctly. If it does, you can narrow down the amount of info copied selectively, until you get the bit of information it needs to play, and find what routine needs to be adding this info to RAM. Some fixes can consist of a single byte of difference in RAM between the original, and the repaired version of an NSF. Note that this will require that the right banks be loaded, or it will fail outright. An inaccurate Play address can also result in a lack of sound.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Open any regular game rom, open the hex viewer, then open the NSF file you want with the Hex viewer open. Run another copy of FCEUXDSP, and load the rom of the game you&amp;#039;re working on an NSF of. In the game window, open it&amp;#039;s hex-editor window too. In the emulator with the game running, get some music going, and click-drag downward from 0x200 until you have 0x700 bytes selected, and copy the information to the clipboard. This skips 0x100, where the stack is stored. In the NSF-emulating window&amp;#039;s hex editor, paste the info at 0x200, and see if the NSF plays the music correctly. If it does, you can narrow down the amount of info copied selectively, until you get the bit of information it needs to play, and find what routine needs to be adding this info to RAM. Some fixes can consist of a single byte of difference in RAM between the original, and the repaired version of an NSF. Note that this will require that the right banks be loaded, or it will fail outright. An inaccurate Play address can also result in a lack of sound.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:GSHI pages]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MathUser</name></author>
	</entry>
	<entry>
		<id>https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=1889&amp;oldid=prev</id>
		<title>Ugetab at 05:28, 20 July 2007</title>
		<link rel="alternate" type="text/html" href="https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=1889&amp;oldid=prev"/>
		<updated>2007-07-20T05:28:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:28, 20 July 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l47&quot;&gt;Line 47:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 47:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If offsets 0070h to 0077h have 00h in them, then bankswitching is *not* used.  If one or more bytes are something other than 00h then bankswitching is used.  If bankswitching is used then the load address is still used, but you now use (ADDRESS AND 0FFFh) to determine where on the first bank to load the data.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If offsets 0070h to 0077h have 00h in them, then bankswitching is *not* used.  If one or more bytes are something other than 00h then bankswitching is used.  If bankswitching is used then the load address is still used, but you now use (ADDRESS AND 0FFFh) to determine where on the first bank to load the data.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Each bank is &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;4K &lt;/del&gt;in size, and that means there are 8 of them for the&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Each bank is &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1K &lt;/ins&gt;in size, and that means there are 8 of them for the&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;entire 08000h-0ffffh range in the 6502&amp;#039;s address space.  You determine where in memory the data goes by setting bytes 070h thru 077h in the file. These determine the inital bank values that will be used, and hence where the data will be loaded into the address space.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;entire 08000h-0ffffh range in the 6502&amp;#039;s address space.  You determine where in memory the data goes by setting bytes 070h thru 077h in the file. These determine the inital bank values that will be used, and hence where the data will be loaded into the address space.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l61&quot;&gt;Line 61:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 61:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since 0070h-0077h are something other than 00h, then we know that this tune uses bankswitching.  The load address for the data is specified as 08000h.  We take this AND 0fffh and get 0000h, so we will load data in at byte 0 of bank 0, since data is loaded into the banks sequentially starting from bank 0 up until the music data is fully loaded.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since 0070h-0077h are something other than 00h, then we know that this tune uses bankswitching.  The load address for the data is specified as 08000h.  We take this AND 0fffh and get 0000h, so we will load data in at byte 0 of bank 0, since data is loaded into the banks sequentially starting from bank 0 up until the music data is fully loaded.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Metroid has 6 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;4K &lt;/del&gt;banks in it, numbered 0 through 5. The 6502&#039;s address space has 8 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;4K &lt;/del&gt;bankswitchable blocks on it, starting at 08000h-08fffh, 09000h-09fffh, 0a000h-0afffh ... 0f000h-0ffffh. In the Metroid NSF header, all banks start out loaded with the 6th &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;4K &lt;/del&gt;bank of data, which is 5. Each one of these is &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;4K &lt;/del&gt;in size, and the current bank is controlled by writes to 05ff8h thru 05fffh, one byte per bank.  So, 05ff8h controls the 08000h-08fffh range, 05ff9h controls the 09000h-09fffh range, etc. up to 05fffh which controls the 0f000h-0ffffh range.  When the song is loaded into RAM, it is loaded into the banks and not the 6502&#039;s address space.  Once this is done, then the bank control registers are written to set up the inital bank values. To do this, the value at 0070h in the file is written to 05ff8h, 0071h is written to 05ff9h, etc. all the way to 0077h is written to 05fffh.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Metroid has 6 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1K &lt;/ins&gt;banks in it, numbered 0 through 5. The 6502&#039;s address space has 8 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1K &lt;/ins&gt;bankswitchable blocks on it, starting at 08000h-08fffh, 09000h-09fffh, 0a000h-0afffh ... 0f000h-0ffffh. In the Metroid NSF header, all banks start out loaded with the 6th &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1K &lt;/ins&gt;bank of data, which is 5. Each one of these is &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1K &lt;/ins&gt;in size, and the current bank is controlled by writes to 05ff8h thru 05fffh, one byte per bank.  So, 05ff8h controls the 08000h-08fffh range, 05ff9h controls the 09000h-09fffh range, etc. up to 05fffh which controls the 0f000h-0ffffh range.  When the song is loaded into RAM, it is loaded into the banks and not the 6502&#039;s address space.  Once this is done, then the bank control registers are written to set up the inital bank values. To do this, the value at 0070h in the file is written to 05ff8h, 0071h is written to 05ff9h, etc. all the way to 0077h is written to 05fffh.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is should be done before every call to the init routine.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is should be done before every call to the init routine.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ugetab</name></author>
	</entry>
	<entry>
		<id>https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=1888&amp;oldid=prev</id>
		<title>Ugetab at 02:22, 17 July 2007</title>
		<link rel="alternate" type="text/html" href="https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=1888&amp;oldid=prev"/>
		<updated>2007-07-17T02:22:35Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:22, 17 July 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l6&quot;&gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(The following is a modified version of the text on the nesdev.parodius.org wiki)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Header Overview ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Header Overview ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l13&quot;&gt;Line 13:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 14:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0005    1   BYTE    Version number (currently 01h)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0005    1   BYTE    Version number (currently 01h)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0006    1   BYTE    Total songs   (1=1 song, 2=2 songs, etc)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0006    1   BYTE    Total songs   (1=1 song, 2=2 songs, etc)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0007    1   BYTE    Starting song (1= 1st song, 2=2nd song, etc)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0007    1   BYTE    Starting song (1=1st song, 2=2nd song, etc)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0008    2   WORD    (lo/hi) load address of data (8000-FFFF)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0008    2   WORD    (lo/hi) load address of data (8000-FFFF)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  000a    2   WORD    (lo/hi) init address of data (8000-FFFF)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  000a    2   WORD    (lo/hi) init address of data (8000-FFFF)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l39&quot;&gt;Line 39:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 40:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0080    nnn ----    The music program/data follows&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  0080    nnn ----    The music program/data follows&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This may look somewhat familiar;  if so that&#039;s because this is somewhat &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;sorta &lt;/del&gt;of based on the PSID file format for C64 music/sound.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This may look somewhat familiar;  if so that&#039;s because this is somewhat &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;sort &lt;/ins&gt;of based on the PSID file format for C64 music/sound.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l60&quot;&gt;Line 60:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 61:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since 0070h-0077h are something other than 00h, then we know that this tune uses bankswitching.  The load address for the data is specified as 08000h.  We take this AND 0fffh and get 0000h, so we will load data in at byte 0 of bank 0, since data is loaded into the banks sequentially starting from bank 0 up until the music data is fully loaded.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since 0070h-0077h are something other than 00h, then we know that this tune uses bankswitching.  The load address for the data is specified as 08000h.  We take this AND 0fffh and get 0000h, so we will load data in at byte 0 of bank 0, since data is loaded into the banks sequentially starting from bank 0 up until the music data is fully loaded.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Metroid has 6 4K banks in it, numbered 0 through 5. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/del&gt;The 6502&#039;s address space has 8 4K bankswitchable blocks on it, starting at 08000h-08fffh, 09000h-09fffh, 0a000h-0afffh ... 0f000h-0ffffh. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/del&gt;Each one of these is 4K in size, and the current bank is controlled by writes to 05ff8h thru 05fffh, one byte per bank.  So, 05ff8h controls the 08000h-08fffh range, 05ff9h controls the 09000h-09fffh range, etc. up to 05fffh which controls the 0f000h-0ffffh range.  When the song is loaded into RAM, it is loaded into the banks and not the 6502&#039;s address space.  Once this is done, then the bank control registers are written to set up the inital bank values. To do this, the value at 0070h in the file is written to 05ff8h, 0071h&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Metroid has 6 4K banks in it, numbered 0 through 5. The 6502&#039;s address space has 8 4K bankswitchable blocks on it, starting at 08000h-08fffh, 09000h-09fffh, 0a000h-0afffh ... 0f000h-0ffffh. &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;In the Metroid NSF header, all banks start out loaded with the 6th 4K bank of data, which is 5. &lt;/ins&gt;Each one of these is 4K in size, and the current bank is controlled by writes to 05ff8h thru 05fffh, one byte per bank.  So, 05ff8h controls the 08000h-08fffh range, 05ff9h controls the 09000h-09fffh range, etc. up to 05fffh which controls the 0f000h-0ffffh range.  When the song is loaded into RAM, it is loaded into the banks and not the 6502&#039;s address space.  Once this is done, then the bank control registers are written to set up the inital bank values. To do this, the value at 0070h in the file is written to 05ff8h, 0071h is written to 05ff9h, etc. all the way to 0077h is written to 05fffh.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;is written to 05ff9h, etc. all the way to 0077h is written to 05fffh.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is should be done before every call to the init routine.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is should be done before every call to the init routine.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l84&quot;&gt;Line 84:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 84:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;per second is determined by offsets 006eh and 006fh in the file.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;per second is determined by offsets 006eh and 006fh in the file.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These bytes denote the speed of playback in 1/1000000ths of a second.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These bytes denote the speed of playback in 1/1000000ths of a second.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;For the &quot;usual&quot; 60Hz playback rate, set this to 411ah. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;For the &quot;usual&quot; 60Hz playback rate, set this to 411ah.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To generate a differing playback rate, use this formula:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To generate a differing playback rate, use this formula:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l126&quot;&gt;Line 126:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 126:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Properly Playing a Tune ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Properly Playing a Tune ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Call the play address of the music at periodic intervals determined by the speed words.  Which word to use is determined by which mode you are in- PAL or NTSC.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Call the play address of the music at periodic intervals determined by &lt;/del&gt;the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;speed words.  Which word to use is determined by which mode you are in- PAL or NTSC&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== Changes Since This Guide Was Written ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Some players no longer use &lt;/ins&gt;the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;playback rate bytes&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Adding DPCM ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Adding DPCM ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l177&quot;&gt;Line 177:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 179:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# There should be 8K of RAM present at 6000-7FFFh. MMC5 tunes need RAM at 5C00-5FF7 to emulate its EXRAM. 8000-FFFF should be read-only (not writable) after a tune has loaded.  The only time this area should be writable is if an FDS tune is being played.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# There should be 8K of RAM present at 6000-7FFFh. MMC5 tunes need RAM at 5C00-5FF7 to emulate its EXRAM. 8000-FFFF should be read-only (not writable) after a tune has loaded.  The only time this area should be writable is if an FDS tune is being played.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Do not assume the state of *anything* on entry to the init routine except A and X.  Y can be anything, as can the flags.   &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Do not assume the state of *anything* on entry to the init routine except A and X.  Y can be anything, as can the flags.   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Do not assume the state of *anything* on entry to the play routine either. Flags, X, A, and Y could be at any state.  I&#039;ve fixed about 10 tunes because of this problem and the problem&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;above.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Do not assume the state of *anything* on entry to the play routine either. Flags, X, A, and Y could be at any state.  I&#039;ve fixed about 10 tunes because of this problem and the problem above.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# The stack sits at 1FFh and grows down.  Make sure the tune does not attempt to use &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1F0h&lt;/del&gt;-1FFh for variables. (Armed Dragon Villigust did and I had to relocate its RAM usage to 2xx)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# The stack sits at 1FFh and grows down &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to 100h&lt;/ins&gt;.  Make sure the tune does not attempt to use &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1E0h&lt;/ins&gt;-1FFh for variables. (Armed Dragon Villigust did and I had to relocate its RAM usage to 2xx) &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tunes that do use this area are likely relying on direct lookup of stack values. Games that do this need to be debugged to find the location that pushes or writes this information.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Variables should sit in the 0000h-07FFh area *only*.  If the tune writes outside this range, say 1400h this is bad and should be relocated. (Terminator 3 did this and I relocated it to 04xx).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Variables should sit in the 0000h-07FFh area *only*.  If the tune writes outside this range, say 1400h this is bad and should be relocated. (Terminator 3 did this and I relocated it to 04xx)&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Note that most recent players also support RAM at 6000h-7FFFh.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# Some games require A/X/Y to be &#039;cleaned&#039; before running some code. This can be required during the Init routine, or before the Play address is run. In one case, all the songs in an NSF wouldn&#039;t loop because the Y register wasn&#039;t zeroed in the init routine&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Using FCEUXDSP ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Using FCEUXDSP ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l188&quot;&gt;Line 188:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 191:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Breaking on writes to $4000 - $400F will usually show you part of the Play routine. Using the &amp;#039;Step Out&amp;#039; option tends to help show the entry point into the routine.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Breaking on writes to $4000 - $400F will usually show you part of the Play routine. Using the &amp;#039;Step Out&amp;#039; option tends to help show the entry point into the routine.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Discovering what part of memory changes to choose the next note is helpful in figuring out where the music init is. Breaking on writes to these addresses helps find the Song Init coding, either by visually &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;disecting &lt;/del&gt;the code, or by using Step Out to try to find a place to breakpoint, and change the A/X/Y registers, in hopes of choosing a different song, which will confirm that it&#039;s a Song Init routine.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Discovering what part of memory changes to choose the next note is helpful in figuring out where the music init is. Breaking on writes to these addresses helps find the Song Init coding, either by visually &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;dissecting &lt;/ins&gt;the code, or by using Step Out to try to find a place to breakpoint, and change the A/X/Y registers, in hopes of choosing a different song, which will confirm that it&#039;s a Song Init routine.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you load an NSF, you can use the debugger to check for errors without much difficulty. You can also use a trick for debugging that lets you use verified Game memory to test the NSF for correct music information, and Play routine...&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you load an NSF, you can use the debugger to check for errors without much difficulty. You can also use a trick for debugging that lets you use verified Game memory to test the NSF for correct music information, and Play routine...&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Open &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/del&gt;regular game rom, &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;and &lt;/del&gt;open the hex viewer, then open the NSF file you want with the Hex viewer open. Run another copy of FCEUXDSP, and load the rom of the game you&#039;re working on an NSF of. In the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;other copy&lt;/del&gt;, open it&#039;s hex-editor window too. In the emulator with the game running, get some music going, and click-drag downward from 0x200 until you have 0x700 bytes selected, and copy the information to the clipboard. This skips 0x100, where the stack is stored. In the NSF-emulating window&#039;s hex editor, paste the info at 0x200, and see if the NSF plays the music correctly. If it does, you can narrow down the amount of info copied selectively, until you get the bit of information it needs to play, and find what routine needs to be adding this info to RAM. Some &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;fixed &lt;/del&gt;can consist of a single byte of difference in RAM between the original, and the repaired version of an NSF.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Open &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;any &lt;/ins&gt;regular game rom, open the hex viewer, then open the NSF file you want with the Hex viewer open. Run another copy of FCEUXDSP, and load the rom of the game you&#039;re working on an NSF of. In the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;game window&lt;/ins&gt;, open it&#039;s hex-editor window too. In the emulator with the game running, get some music going, and click-drag downward from 0x200 until you have 0x700 bytes selected, and copy the information to the clipboard. This skips 0x100, where the stack is stored. In the NSF-emulating window&#039;s hex editor, paste the info at 0x200, and see if the NSF plays the music correctly. If it does, you can narrow down the amount of info copied selectively, until you get the bit of information it needs to play, and find what routine needs to be adding this info to RAM. Some &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;fixes &lt;/ins&gt;can consist of a single byte of difference in RAM between the original, and the repaired version of an NSF&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Note that this will require that the right banks be loaded, or it will fail outright. An inaccurate Play address can also result in a lack of sound&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ugetab</name></author>
	</entry>
	<entry>
		<id>https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=1695&amp;oldid=prev</id>
		<title>Ugetab at 05:29, 12 December 2006</title>
		<link rel="alternate" type="text/html" href="https://wiki.gamehacking.org/index.php?title=NSF&amp;diff=1695&amp;oldid=prev"/>
		<updated>2006-12-12T05:29:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The basic idea is one rips the music/sound code from an NES game and prepends a small header to the data.&lt;br /&gt;
&lt;br /&gt;
A program of some form (6502/sound emulator) then takes the data and loads it into the proper place into the 6502&amp;#039;s address space, then inits and plays the tune.&lt;br /&gt;
&lt;br /&gt;
Many of the same methods used for finding cheat codes are compatible with finding sound information. The extra work of getting the right code into the right place and setting up the header is the primary difference between ripping and cheat making.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header Overview ==&lt;br /&gt;
&lt;br /&gt;
 offset  # of bytes   Function&lt;br /&gt;
 ----------------------------&lt;br /&gt;
 0000    5   STRING  &amp;quot;NESM&amp;quot;,01Ah  ; denotes an NES sound format file&lt;br /&gt;
 0005    1   BYTE    Version number (currently 01h)&lt;br /&gt;
 0006    1   BYTE    Total songs   (1=1 song, 2=2 songs, etc)&lt;br /&gt;
 0007    1   BYTE    Starting song (1= 1st song, 2=2nd song, etc)&lt;br /&gt;
 0008    2   WORD    (lo/hi) load address of data (8000-FFFF)&lt;br /&gt;
 000a    2   WORD    (lo/hi) init address of data (8000-FFFF)&lt;br /&gt;
 000c    2   WORD    (lo/hi) play address of data (8000-FFFF)&lt;br /&gt;
 000e    32  STRING  The name of the song, null terminated&lt;br /&gt;
 002e    32  STRING  The artist, if known, null terminated&lt;br /&gt;
 004e    32  STRING  The Copyright holder, null terminated&lt;br /&gt;
 006e    2   WORD    (lo/hi) speed, in 1/1000000th sec ticks, NTSC (see text)&lt;br /&gt;
 0070    8   BYTE    Bankswitch Init Values (see text, and FDS section)&lt;br /&gt;
 0078    2   WORD    (lo/hi) speed, in 1/1000000th sec ticks, PAL (see text)&lt;br /&gt;
 007a    1   BYTE    PAL/NTSC bits:&lt;br /&gt;
                 bit 0: if clear, this is an NTSC tune&lt;br /&gt;
                 bit 0: if set, this is a PAL tune&lt;br /&gt;
                 bit 1: if set, this is a dual PAL/NTSC tune&lt;br /&gt;
                 bits 2-7: not used. they *must* be 0&lt;br /&gt;
 007b    1   BYTE    Extra Sound Chip Support&lt;br /&gt;
                 bit 0: if set, this song uses VRCVI&lt;br /&gt;
                 bit 1: if set, this song uses VRCVII&lt;br /&gt;
                 bit 2: if set, this song uses FDS Sound&lt;br /&gt;
                 bit 3: if set, this song uses MMC5 audio&lt;br /&gt;
                 bit 4: if set, this song uses Namco 106&lt;br /&gt;
                 bit 5: if set, this song uses Sunsoft FME-07&lt;br /&gt;
                 bits 6,7: future expansion: they *must* be 0&lt;br /&gt;
 007c    4   ----    4 extra bytes for expansion (must be 00h)&lt;br /&gt;
 0080    nnn ----    The music program/data follows&lt;br /&gt;
&lt;br /&gt;
This may look somewhat familiar;  if so that&amp;#039;s because this is somewhat sorta of based on the PSID file format for C64 music/sound.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Loading a tune into RAM ==&lt;br /&gt;
&lt;br /&gt;
If offsets 0070h to 0077h have 00h in them, then bankswitching is *not* used.  If one or more bytes are something other than 00h then bankswitching is used.  If bankswitching is used then the load address is still used, but you now use (ADDRESS AND 0FFFh) to determine where on the first bank to load the data.&lt;br /&gt;
&lt;br /&gt;
Each bank is 4K in size, and that means there are 8 of them for the&lt;br /&gt;
entire 08000h-0ffffh range in the 6502&amp;#039;s address space.  You determine where in memory the data goes by setting bytes 070h thru 077h in the file. These determine the inital bank values that will be used, and hence where the data will be loaded into the address space.&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s an example:&lt;br /&gt;
&lt;br /&gt;
METROID.NSF will be used for the following explaination.&lt;br /&gt;
&lt;br /&gt;
 The file is set up like so:  (starting at 070h in the file)&lt;br /&gt;
 &lt;br /&gt;
 0070: 05 05 05 05 05 05 05 05 - 00 00 00 00 00 00 00 00&lt;br /&gt;
 0080: ... music data goes here...&lt;br /&gt;
&lt;br /&gt;
Since 0070h-0077h are something other than 00h, then we know that this tune uses bankswitching.  The load address for the data is specified as 08000h.  We take this AND 0fffh and get 0000h, so we will load data in at byte 0 of bank 0, since data is loaded into the banks sequentially starting from bank 0 up until the music data is fully loaded.&lt;br /&gt;
&lt;br /&gt;
Metroid has 6 4K banks in it, numbered 0 through 5.  The 6502&amp;#039;s address space has 8 4K bankswitchable blocks on it, starting at 08000h-08fffh, 09000h-09fffh, 0a000h-0afffh ... 0f000h-0ffffh.  Each one of these is 4K in size, and the current bank is controlled by writes to 05ff8h thru 05fffh, one byte per bank.  So, 05ff8h controls the 08000h-08fffh range, 05ff9h controls the 09000h-09fffh range, etc. up to 05fffh which controls the 0f000h-0ffffh range.  When the song is loaded into RAM, it is loaded into the banks and not the 6502&amp;#039;s address space.  Once this is done, then the bank control registers are written to set up the inital bank values. To do this, the value at 0070h in the file is written to 05ff8h, 0071h&lt;br /&gt;
is written to 05ff9h, etc. all the way to 0077h is written to 05fffh.&lt;br /&gt;
This is should be done before every call to the init routine.&lt;br /&gt;
&lt;br /&gt;
If the tune was not bankswitched, then it is simply loaded in at the &lt;br /&gt;
specified load address, until EOF&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Initalizing a tune ==&lt;br /&gt;
&lt;br /&gt;
This is pretty simple.  Load the desired song # into the accumulator,&lt;br /&gt;
minus 1 and set the X register to specify PAL (X=1) or NTSC (X=0).&lt;br /&gt;
If this is a single standard tune (i.e. PAL *or* NTSC but not both)&lt;br /&gt;
then the X register contents should not matter.  Once the song # and&lt;br /&gt;
optional PAL/NTSC standard are loaded, simply call the INIT address.&lt;br /&gt;
Once init is done, it should perform an RTS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Playing a tune ==&lt;br /&gt;
&lt;br /&gt;
Once the tune has been initalized, it can now be played.  To do this,&lt;br /&gt;
simply call the play address several times a second.  How many times&lt;br /&gt;
per second is determined by offsets 006eh and 006fh in the file.&lt;br /&gt;
These bytes denote the speed of playback in 1/1000000ths of a second. &lt;br /&gt;
For the &amp;quot;usual&amp;quot; 60Hz playback rate, set this to 411ah.  &lt;br /&gt;
&lt;br /&gt;
To generate a differing playback rate, use this formula:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          1000000&lt;br /&gt;
 PBRATE= ---------&lt;br /&gt;
           speed&lt;br /&gt;
&lt;br /&gt;
Where PBRATE is the value you stick into 006e/006fh in the file, and&lt;br /&gt;
speed is the desired speed in hertz. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Properly Loading a Tune ==&lt;br /&gt;
&lt;br /&gt;
* If the tune is bankswitched, go to #3.&lt;br /&gt;
&lt;br /&gt;
* Load the data into the 6502&amp;#039;s address space starting at the specified load address. Go to #4.&lt;br /&gt;
&lt;br /&gt;
* Load the data into a RAM area, starting at (start_address AND 0fffh).&lt;br /&gt;
&lt;br /&gt;
* Tune load is done.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Properly Initializing a Tune ==&lt;br /&gt;
&lt;br /&gt;
* Clear all RAM at 0000h-07ffh.&lt;br /&gt;
&lt;br /&gt;
* Clear all RAM at 6000h-7fffh.&lt;br /&gt;
&lt;br /&gt;
* Init the sound registers by writing 00h to 04000-0400Fh, 10h to 4010h, and 00h to 4011h-4013h.&lt;br /&gt;
&lt;br /&gt;
* Set volume register 04015h to 00fh.&lt;br /&gt;
&lt;br /&gt;
* If this is a banked tune, load the bank values from the header into 5ff8-5fffh.&lt;br /&gt;
&lt;br /&gt;
* Set the accumulator and X registers for the desired song.&lt;br /&gt;
&lt;br /&gt;
* Call the music init routine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Properly Playing a Tune ==&lt;br /&gt;
&lt;br /&gt;
Call the play address of the music at periodic intervals determined by the speed words.  Which word to use is determined by which mode you are in- PAL or NTSC.&lt;br /&gt;
&lt;br /&gt;
== Adding DPCM ==&lt;br /&gt;
There is a large section on how to deal with DPCM samples in the [http://www.zophar.net/tech/files/NESAudioRipping.TXT NES Music Ripping Guide], but the basic information on DPCM is that writes to $4012 and $4013 access sample data stored at and between $c000 and $ffff.&lt;br /&gt;
&lt;br /&gt;
Writes to $4012 determine the location of the sample data. The value written to $4012, multiplied by 0040h, plus 0c000h, is the point in ROM space the sample starts.&lt;br /&gt;
&lt;br /&gt;
Writes to $4013 determine the length of the sample data. The value written to $4013, multiplied by 0010h, plus 1, is the length of the sample data.&lt;br /&gt;
&lt;br /&gt;
If 00h is written to $4012 and $4013, the sample would be located at $c000, and would be 1 byte in length. If 0080h is written to $4012 and $4013, the sample would be located at $e000, and would be 0x801 bytes in length.&lt;br /&gt;
&lt;br /&gt;
DPCM samples can be attached to an NSF by either relocating the neccesary data, or by including the banks with the DPCM data in the NSF. Relocating the data correctly will often lead to a smaller file size, but including the original data in it&amp;#039;s original location is usually easier to do.&lt;br /&gt;
&lt;br /&gt;
== Sound Chip Support ==&lt;br /&gt;
Byte 007bh of the file stores the sound chip flags.  If a particular flag is set, those sound registers should be enabled.  If the flag is clear, then those registers should be disabled. All I/O registers within 8000-FFFF are &amp;#039;&amp;#039;write only&amp;#039;&amp;#039; and must not disrupt music code that happens to be stored there.&lt;br /&gt;
&lt;br /&gt;
=== VRCVI ===&lt;br /&gt;
* Uses registers 9000-9002, A000-A002, and B000-B002, write only. See [[VRC6 Audio]] for more information.&lt;br /&gt;
* Note: The A0 and A1 lines are flipped on a few games! If you rip the music and it sounds all funny, flip around  the xxx1 and xxx2 register pairs.  (i.e. 9001 and 9002)  9000 and 9003 can be left untouched.  I decided to do this since it  would make things easier all around, and this means you only will have to change the music code in a very few places (6).  Esper2 and Madara will need this change, while Castlevania 3j will not for instance.&lt;br /&gt;
&lt;br /&gt;
=== VRCVII ===&lt;br /&gt;
* Uses registers 9010 and 9030, write only. See [[VRC7 Audio]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== FDS Sound ===&lt;br /&gt;
* Uses registers from 4040 through 4092. See [[FDS Audio]] for more information.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* 6000-DFFF is assumed to be RAM, since 6000-DFFF is RAM on the FDS.  E000-FFFF is usually not included in FDS games because it is the BIOS ROM.  However, it can be used on FDS rips to help the ripper (for modified play/init addresses).&lt;br /&gt;
* Bankswitching operates slightly different on FDS tunes.  5FF6 and 5FF7 control the banks 6000-6FFF and 7000-7FFF respectively.  NSF header offsets 76h and 77h correspond to *both* 6000-7FFF *AND* E000-FFFF.  Keep this in mind!&lt;br /&gt;
&lt;br /&gt;
=== MMC5 Sound ===&lt;br /&gt;
* Uses registers 5000-5015, write only as well as 5205 and 5206, and 5C00-5FF5. see [[MMC5 Audio]] for more information.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* 5205 and 5206 are a hardware 8*8 multiplier.  The idea being you write your two bytes to be multiplied into 5205 and 5206 and after doing so, you read the result back out.&lt;br /&gt;
* 5C00-5FF5 should be RAM to emulate EXRAM while in MMC5 mode.&lt;br /&gt;
&lt;br /&gt;
=== Namco 106 Sound ===&lt;br /&gt;
* Uses registers 4800 and F800. See [[Namco 106 Audio]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Sunsoft FME-07 Sound ===&lt;br /&gt;
* Uses registers C000 and E000. See [[Sunsoft Audio]] for more information.&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
# The starting song number and maximum song numbers start counting at 1, while the init address of the tune starts counting at 0.  To &amp;quot;fix&amp;quot;, simply pass the desired song number minus 1 to the init routine.&lt;br /&gt;
# The NTSC speed word is used *only* for NTSC tunes, or dual PAL/NTSC tunes. The PAL speed word is used *only* for PAL tunes, or dual PAL/NTSC tunes.&lt;br /&gt;
# The length of the text in the name, artist, and copyright fields must be 31 characters or less!  There has to be at least a single NULL byte (00h) after the text, between fields.&lt;br /&gt;
# If a field is not known (name, artist, copyright) then the field must contain the string &amp;quot;&amp;lt;?&amp;gt;&amp;quot; (without quotes).  &lt;br /&gt;
# There should be 8K of RAM present at 6000-7FFFh. MMC5 tunes need RAM at 5C00-5FF7 to emulate its EXRAM. 8000-FFFF should be read-only (not writable) after a tune has loaded.  The only time this area should be writable is if an FDS tune is being played.&lt;br /&gt;
# Do not assume the state of *anything* on entry to the init routine except A and X.  Y can be anything, as can the flags.  &lt;br /&gt;
# Do not assume the state of *anything* on entry to the play routine either. Flags, X, A, and Y could be at any state.  I&amp;#039;ve fixed about 10 tunes because of this problem and the problem, above.&lt;br /&gt;
# The stack sits at 1FFh and grows down.  Make sure the tune does not attempt to use 1F0h-1FFh for variables. (Armed Dragon Villigust did and I had to relocate its RAM usage to 2xx)&lt;br /&gt;
# Variables should sit in the 0000h-07FFh area *only*.  If the tune writes outside this range, say 1400h this is bad and should be relocated. (Terminator 3 did this and I relocated it to 04xx).&lt;br /&gt;
&lt;br /&gt;
== Using FCEUXDSP ==&lt;br /&gt;
Ripping can be made much easier by using this relatively new NES debugging emulator.&lt;br /&gt;
&lt;br /&gt;
By breakpointing writes to $4015, then resetting the game, you can often find the part of code that initializes the sound registers(Sound Init), and see if it&amp;#039;s doing anything unusual at that point.&lt;br /&gt;
&lt;br /&gt;
Breaking on writes to $4000 - $400F will usually show you part of the Play routine. Using the &amp;#039;Step Out&amp;#039; option tends to help show the entry point into the routine.&lt;br /&gt;
&lt;br /&gt;
Discovering what part of memory changes to choose the next note is helpful in figuring out where the music init is. Breaking on writes to these addresses helps find the Song Init coding, either by visually disecting the code, or by using Step Out to try to find a place to breakpoint, and change the A/X/Y registers, in hopes of choosing a different song, which will confirm that it&amp;#039;s a Song Init routine.&lt;br /&gt;
&lt;br /&gt;
If you load an NSF, you can use the debugger to check for errors without much difficulty. You can also use a trick for debugging that lets you use verified Game memory to test the NSF for correct music information, and Play routine...&lt;br /&gt;
&lt;br /&gt;
Open a regular game rom, and open the hex viewer, then open the NSF file you want with the Hex viewer open. Run another copy of FCEUXDSP, and load the rom of the game you&amp;#039;re working on an NSF of. In the other copy, open it&amp;#039;s hex-editor window too. In the emulator with the game running, get some music going, and click-drag downward from 0x200 until you have 0x700 bytes selected, and copy the information to the clipboard. This skips 0x100, where the stack is stored. In the NSF-emulating window&amp;#039;s hex editor, paste the info at 0x200, and see if the NSF plays the music correctly. If it does, you can narrow down the amount of info copied selectively, until you get the bit of information it needs to play, and find what routine needs to be adding this info to RAM. Some fixed can consist of a single byte of difference in RAM between the original, and the repaired version of an NSF.&lt;/div&gt;</summary>
		<author><name>Ugetab</name></author>
	</entry>
</feed>