<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[ChipMusic.org - Mapping Hex Values in ASM]]></title>
	<link rel="self" href="https://chipmusic.org:80/forums/feed/atom/topic/23752/"/>
	<updated>2018-10-27T00:24:10Z</updated>
	<generator>PunBB</generator>
	<id>https://chipmusic.org/forums/topic/23752/mapping-hex-values-in-asm/</id>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260320/#p260320"/>
			<content type="html"><![CDATA[<p>Another small optimization. Instead of<br /></p><div class="codebox"><pre><code>    ld a,[hl] ; A reg has high 3 bits.
    set 7,a ; when set, sound restarts.</code></pre></div><p>you can do<br /></p><div class="codebox"><pre><code>   ld a,$80
   or [hl]</code></pre></div><p>to save another 4 cycles <img src="https://chipmusic.org/forums/img/smilies/wink.png" width="15" height="15" alt="wink" /><br />If you reorganize the whole block to set HL first, you can save another 8 cycles because you&#039;ll need to set A=$80 only once.</p>]]></content>
			<author>
				<name><![CDATA[irrlichtproject]]></name>
				<uri>https://chipmusic.org/irrlichtproject</uri>
			</author>
			<updated>2018-10-27T00:24:10Z</updated>
			<id>https://chipmusic.org/forums/post/260320/#p260320</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260319/#p260319"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>Orgia Mode wrote:</cite><blockquote><div class="quotebox"><cite>irrlichtproject wrote:</cite><blockquote><p>You need an opcode table that lists instruction timings. I used this one: <a href="http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html" target="_blank">http://www.pastraiser.com/cpu/gameboy/g &#133; codes.html</a><br />Not the best but it does the job. The timings are listed below the opcode names; the number to the left is the instruction size in bytes, and the one to the right is the cycle count.</p></blockquote></div><p>That is very helpful. I think I came across that page ears ago, but didn&#039;t need it at the time. Thanks!</p><p>Can anyone elaborate on these bullet points:<br /><a href="http://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware#Obscure_Behavior" target="_blank">source</a></p><p>&gt;&gt;If the wave channel is enabled, accessing any byte from $FF30-$FF3F is equivalent to accessing the current byte selected by the waveform position. Further, on the DMG accesses will only work in this manner if made within a couple of clocks of the wave channel accessing wave RAM; if made at any other time, reads return $FF and writes have no effect.</p><p>&gt;&gt;Triggering the wave channel on the DMG while it reads a sample byte will alter the first four bytes of wave RAM. If the channel was reading one of the first four bytes, the only first byte will be rewritten with the byte being read. If the channel was reading one of the later 12 bytes, the first FOUR bytes of wave RAM will be rewritten with the four aligned bytes that the read was from (bytes 4-7, 8-11, or 12-15); for example if it were reading byte 9 when it was retriggered, the first four bytes would be rewritten with the contents of bytes 8-11. To avoid this corruption you should stop the wave by writing 0 then $80 to NR30 before triggering it again. The game Duck Tales encounters this issue part way through most songs.</p></blockquote></div><br /><p>Alright, I think I figured it out. <br />When I reload $FF30 - $FF3F, have to turn it off, then load it and then re-enable it and then re-start the wave form, like so:</p><br /><div class="quotebox"><blockquote><p>updateWaveSample:<br />; check if a new sample was selected, other wise skip it.<br />.tstOldWave:<br />&nbsp; &nbsp; ld a, [AUD3wave_RAM]<br />&nbsp; &nbsp; ld hl, AUD3wave_RAMold<br />&nbsp; &nbsp; cp [hl]<br />&nbsp; &nbsp; jp z, .noWaveUpdate ; skip if they are exactly the same<br />; otherwise, choose which sample to load<br />&nbsp; &nbsp; ld h, waveTables&gt;&gt;8 ; its currently at $3200<br />&nbsp; &nbsp; ld a, [AUD3wave_RAM] ; $00-$FF<br />&nbsp; &nbsp; and %11110000 ; clear lower 4-bits, leaving 16 values for the user to select.<br />&nbsp; &nbsp; ld l,a ; hl now points to the selected sample.<br />&nbsp; &nbsp; ld a,$30<br />&nbsp; &nbsp; ld c,a&nbsp; &nbsp; ; C is the counter <br />&nbsp; &nbsp; xor a<br />&nbsp; &nbsp; ld [rAUD3ENA],a ; disable the wave channel here... test<br />.waveLoad:<br />&nbsp; &nbsp; ld a,[hl+] ; load the first byte sample, then increment the pointer<br />&nbsp; &nbsp; ld [c],a ; Put A into address $FF00 + C<br />&nbsp; &nbsp; inc bc ; c = $30,31 ... 3F<br />&nbsp; &nbsp; ld a,c<br />&nbsp; &nbsp; cp ($3F+1)<br />&nbsp; &nbsp; jp nz,.waveLoad<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; ld a, $80<br />&nbsp; &nbsp; ld [rAUD3ENA],a ; re-enable the wave channel here... test<br />&nbsp; &nbsp; ; also need to re-start the wave channel with rAUD3HIGH bit 7<br />&nbsp; &nbsp; ; get the current upper 3-bits of the frequency again. (it cannot simply be read from the register.)<br />&nbsp; &nbsp; ld h, expoTable&gt;&gt;8<br />&nbsp; &nbsp; ld a, [AUD3freq_RAM]<br />&nbsp; &nbsp; ld l,a<br />&nbsp; &nbsp; ld a,[hl] ; A reg has high 3 bits.<br />&nbsp; &nbsp; set 7,a ; when set, sound restarts.<br />&nbsp; &nbsp; ld [rAUD3HIGH],a<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <br />; waveLoading finished when $3F is loaded<br />&nbsp; &nbsp; ld a, [AUD3wave_RAM]<br />&nbsp; &nbsp; ld [AUD3wave_RAMold],a ; update the old user&#039;s input for wave ram selection<br />.noWaveUpdate:</p><br /><p>; other irrelevant stuff removed for brevity</p><p>ret</p></blockquote></div><p>it seems to test correctly in several emulators, simulating a variety of CPU&#039;s.</p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-26T22:58:55Z</updated>
			<id>https://chipmusic.org/forums/post/260319/#p260319</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260315/#p260315"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>irrlichtproject wrote:</cite><blockquote><p>You need an opcode table that lists instruction timings. I used this one: <a href="http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html" target="_blank">http://www.pastraiser.com/cpu/gameboy/g &#133; codes.html</a><br />Not the best but it does the job. The timings are listed below the opcode names; the number to the left is the instruction size in bytes, and the one to the right is the cycle count.</p></blockquote></div><p>That is very helpful. I think I came across that page ears ago, but didn&#039;t need it at the time. Thanks!</p><p>Can anyone elaborate on these bullet points:<br /><a href="http://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware#Obscure_Behavior" target="_blank">source</a></p><p>&gt;&gt;If the wave channel is enabled, accessing any byte from $FF30-$FF3F is equivalent to accessing the current byte selected by the waveform position. Further, on the DMG accesses will only work in this manner if made within a couple of clocks of the wave channel accessing wave RAM; if made at any other time, reads return $FF and writes have no effect.</p><p>&gt;&gt;Triggering the wave channel on the DMG while it reads a sample byte will alter the first four bytes of wave RAM. If the channel was reading one of the first four bytes, the only first byte will be rewritten with the byte being read. If the channel was reading one of the later 12 bytes, the first FOUR bytes of wave RAM will be rewritten with the four aligned bytes that the read was from (bytes 4-7, 8-11, or 12-15); for example if it were reading byte 9 when it was retriggered, the first four bytes would be rewritten with the contents of bytes 8-11. To avoid this corruption you should stop the wave by writing 0 then $80 to NR30 before triggering it again. The game Duck Tales encounters this issue part way through most songs.</p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-26T20:19:35Z</updated>
			<id>https://chipmusic.org/forums/post/260315/#p260315</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260309/#p260309"/>
			<content type="html"><![CDATA[<p>You need an opcode table that lists instruction timings. I used this one: <a href="http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html" target="_blank">http://www.pastraiser.com/cpu/gameboy/g &#133; codes.html</a><br />Not the best but it does the job. The timings are listed below the opcode names; the number to the left is the instruction size in bytes, and the one to the right is the cycle count.</p>]]></content>
			<author>
				<name><![CDATA[irrlichtproject]]></name>
				<uri>https://chipmusic.org/irrlichtproject</uri>
			</author>
			<updated>2018-10-26T08:21:05Z</updated>
			<id>https://chipmusic.org/forums/post/260309/#p260309</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260307/#p260307"/>
			<content type="html"><![CDATA[<p>NICE!! Thats 4-cycles per CALL and I actually call it several times in the full loop.</p><p>Hey hey, how did you calculate the cycles saved?</p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-25T22:29:30Z</updated>
			<id>https://chipmusic.org/forums/post/260307/#p260307</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260306/#p260306"/>
			<content type="html"><![CDATA[<p>Save 4 cycles: ld hl, expoTable -&gt; ld h,expoTable&gt;&gt;8</p>]]></content>
			<author>
				<name><![CDATA[irrlichtproject]]></name>
				<uri>https://chipmusic.org/irrlichtproject</uri>
			</author>
			<updated>2018-10-25T21:24:08Z</updated>
			<id>https://chipmusic.org/forums/post/260306/#p260306</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260305/#p260305"/>
			<content type="html"><![CDATA[<p>Finally figured it out...ish.</p><p>As I stated before, I was taking a number between 0 and 255 and assigning a frequency value, but the gameboy needs an 11-bit number for the registers&nbsp; AUD1LOW and AUD1HIGH (and others). So I then took my frequency table and converted it BACK into a digital value with x=2048-(131072/Hz).</p><div class="quotebox"><blockquote><p>expoTable EQU $3000</p><p>SECTION &quot;expotable&quot;,HOME[$3000]<br />;expoTable ;&nbsp; 512 bytes (256 integers)<br />; This table is not perfect by any means. I&#039;ll make the final &quot;tuning&quot; adjustments later.<br />DW 44, 98, 150, 201, 250, 299, 346, 391, 436, 479, 521, 562, 602, 641, 678, 715, 751, 786, 819, 852, 884, 916, 946, 976, 1004, 1032, 1060, 1086, 1112, 1137, 1161, 1185, 1208, 1231, 1253, 1274, 1295, 1315, 1335, 1354, 1372, 1391, 1408, 1425, 1442, 1458, 1474, 1489, 1504, 1519, 1533, 1547, 1560, 1574, 1586, 1599, 1611, 1622, 1634, 1645, 1656, 1666, 1676, 1686, 1696, 1706, 1715, 1724, 1732, 1741, 1749, 1757, 1765, 1773, 1780, 1787, 1794, 1801, 1808, 1814, 1820, 1826, 1832, 1838, 1844, 1849, 1855, 1860, 1865, 1870, 1874, 1879, 1884, 1888, 1892, 1897, 1901, 1905, 1908, 1912, 1916, 1919, 1923, 1926, 1929, 1933, 1936, 1939, 1942, 1944, 1947, 1950, 1953, 1955, 1958, 1960, 1962, 1965, 1967, 1969, 1971, 1973, 1975, 1977, 1979, 1981, 1983, 1985, 1986, 1988, 1989, 1991, 1993, 1994, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2018, 2019, 2020, 2021, 2021, 2022, 2023, 2023, 2024, 2025, 2025, 2026, 2027, 2027, 2028, 2028, 2029, 2029, 2030, 2030, 2031, 2031, 2032, 2032, 2033, 2033, 2033, 2034, 2034, 2035, 2035, 2035, 2036, 2036, 2036, 2037, 2037, 2037, 2037, 2038, 2038, 2038, 2039, 2039, 2039, 2039, 2040, 2040, 2040, 2040, 2040, 2041, 2041, 2041, 2041, 2041, 2042, 2042, 2042, 2042, 2042, 2042, 2043, 2043, 2043, 2043, 2043, 2043, 2043, 2043, 2044, 2044, 2044, 2044, 2044, 2044, 2044, 2044, 2044, 2045, 2045, 2045, 2045, 2045, 2045, 2045, 2045, 2045, 2045, 2045, 2045, 2046, 2046, 2046, 2046, 2046, 2046, 2046, 2046, 2046, 2046</p></blockquote></div><p>Then to grab a number in my update code:</p><div class="quotebox"><blockquote><p>updateFreq12:<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; ld hl, expoTable<br />&nbsp; &nbsp; ld a, [AUD1freq_RAM] ; the 8-bit number from 0-255; located at $D00x for the record<br />&nbsp; &nbsp; ld l,a<br />&nbsp; &nbsp; ld a,[hl+] ; A reg has high 3 bits. HL points to lower 8 now<br />&nbsp; &nbsp; ld [rAUD1HIGH],a<br />&nbsp; &nbsp; ld a,[hl]<br />&nbsp; &nbsp; ld [rAUD1LOW],a<br />&nbsp; &nbsp; <br />ret</p></blockquote></div><p>Alternatively, I can get the 16-bit number from my table and shift the top 3 bits into AUD1HIGH, then load the remaining number into AUD1LOW. This process more closesly answers my original question. <img src="https://chipmusic.org/forums/img/smilies/tongue.png" width="15" height="15" alt="tongue" /><br /> I&#039;ll code it up and see which compiles to the fewest lines.</p><p>Thanks so much for your help, guys!</p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-25T20:59:03Z</updated>
			<id>https://chipmusic.org/forums/post/260305/#p260305</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260289/#p260289"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>Orgia Mode wrote:</cite><blockquote><p>@nitro, is that what shit wave does? Just inject horseshit into the polynomial counter?</p></blockquote></div><p>Nope. Shitwave is actually using the wave channel and the shift register it&#039;s using is all software.</p><div class="quotebox"><cite>Orgia Mode wrote:</cite><blockquote><p>EDIT: Shower thought, why is NR20 unused while NR10 (sweep) is present? The corresponding bytes in I/O are simply ignored, along with several other bytes, but this one in particular seems to have been planned ahead. A missed opportunity.</p></blockquote></div><p>That would be to save silicon space on the chip. Though I&#039;m not sure how much difference it would have made.</p>]]></content>
			<author>
				<name><![CDATA[nitro2k01]]></name>
				<uri>https://chipmusic.org/nitro2k01</uri>
			</author>
			<updated>2018-10-23T22:17:59Z</updated>
			<id>https://chipmusic.org/forums/post/260289/#p260289</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260285/#p260285"/>
			<content type="html"><![CDATA[<p>Alright, I finally figured out the math I needed. Now all I have to do is shift the bass note around until I get the notes I want to hear I guess.<br /></p><div class="spoilerbox" id="spoiler1883319"><h3 onclick="$('#spoilerbox1883319').css('display','block');$('#spoiler1883319').css('display','none')">&#8250; Show Spoiler</h3></div><div class="spoilerbox" id="spoilerbox1883319" style="display:none"><h3 onclick="$('#spoilerbox1883319').css('display','none');$('#spoiler1883319').css('display','block')">&#8249; Hide Spoiler</h3><p>dw expoTable<br />expoTableLen EQU 256<br />; exponential mapping<br />; Made in OpenOffice Calc</p><p>expoTable ;&nbsp; bytes (256 integers)<br />&nbsp; &nbsp; DW 65,67,69,71,73,75,77,79,81,84,86,88,91,93,96,98,101,104,107,110,113,116,119,122,126,129,133,136,140,144,148,152,156,160,165,169,174,179,184,189,194,199,205,210,216,222,228,235,241,248,255,262,269,276,284,292,300,308,316,325,334,343,353,363,373,383,393,404,415,427,439,451,463,476,489,502,516,530,545,560,575,591,608,624,642,659,677,696,715,735,755,776,797,819,842,865,889,914,939,965,991,1018,1047,1075,1105,1135,1167,1199,1232,1266,1301,1337,1373,1411,1450,1490,1531,1573,1617,1661,1707,1754,1802,1852,1903,1955,2009,2065,2122,2180,2240,2302,2365,2431,2497,2566,2637,2710,2784,2861,2940,3021,3104,3190,3278,3368,3461,3556,3654,3755,3858,3965,4074,4186,4301,4420,4542,4667,4795,4928,5063,5203,5346,5494,5645,5800,5960,6125,6293,6467,6645,6828,7016,7209,7408,7612,7822,8038,8259,8487,8720,8961,9208,9461,9722,9990,10265,10548,10839,11137,11444,11760,12084,12417,12759,13110,13472,13843,14224,14616,15019,15433,15858,16295,16744,17205,17680,18167,18667,19182,19710,20253,20811,21385,21974,22580,23202,23841,24498,25173,25867,26580,27312,28064,28838,29632,30449,31288,32150,33036,33946,34882,35843,36831,37845,38888,39960,41061,42192,43355,44550,45777,47039,48335,49667,51035,52441,53886,55371,56897,58465,60076,61731,63432,65180,66976</p></div><p>I have primed all of the registers to be ready for user input and found that the noise channel is the most fun to play with! <img src="https://chipmusic.org/forums/img/smilies/tongue.png" width="15" height="15" alt="tongue" /><br />Most noteable the AUD4POLY register. The broad range sund taht it can produce is outstanding. </p><p>@nitro, is that what shit wave does? Just inject horseshit into the polynomial counter?</p><p>EDIT: Shower thought, why is NR20 unused while NR10 (sweep) is present? The corresponding bytes in I/O are simply ignored, along with several other bytes, but this one in particular seems to have been planned ahead. A missed opportunity.</p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-23T19:08:44Z</updated>
			<id>https://chipmusic.org/forums/post/260285/#p260285</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260253/#p260253"/>
			<content type="html"><![CDATA[<p>I just threw this together in excel and I think it should work for me, if not at least for initial tests. It is 2048 numbers, increasing from 0 - 2047 exponentially (rounded up to the next whole number). I might need to shift it to align with a scale, but I&#039;m currently happy although its bigger than I originally planned.</p><p>Text wall:<br /></p><div class="spoilerbox" id="spoiler5059835"><h3 onclick="$('#spoilerbox5059835').css('display','block');$('#spoiler5059835').css('display','none')">&#8250; Show Spoiler</h3></div><div class="spoilerbox" id="spoilerbox5059835" style="display:none"><h3 onclick="$('#spoilerbox5059835').css('display','none');$('#spoiler5059835').css('display','block')">&#8249; Hide Spoiler</h3><p>dw expoTable<br />expoTableLen EQU 2048<br />; Exponential mapping</p><p>expoTable ; 4096 bytes (2048 integers)<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 12,13,13,13,13,13,13,13,14,14,14,14,14,14,15,15,15,15,15,15,16,16,16,16,16,17,17,17,17,17,17,18,18,18,18,18,19,19<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 19,19,19,20,20,20,20,20,21,21,21,21,21,22,22,22,22,22,23,23,23,23,23,24,24,24,24,25,25,25,25,25,26,26,26,26,27,27<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34,35,35,35,35,36,36,36<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 36,37,37,37,37,38,38,38,39,39,39,39,40,40,40,41,41,41,41,42,42,42,43,43,43,43,44,44,44,45,45,45,45,46,46,46,47,47<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 47,48,48,48,48,49,49,49,50,50,50,51,51,51,52,52,52,53,53,53,54,54,54,54,55,55,55,56,56,56,57,57,57,58,58,58,59,59<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 60,60,60,61,61,61,62,62,62,63,63,63,64,64,64,65,65,65,66,66,67,67,67,68,68,68,69,69,69,70,70,71,71,71,72,72,72,73<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 73,74,74,74,75,75,75,76,76,77,77,77,78,78,79,79,79,80,80,81,81,81,82,82,83,83,83,84,84,85,85,85,86,86,87,87,87,88<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 88,89,89,89,90,90,91,91,92,92,92,93,93,94,94,95,95,95,96,96,97,97,98,98,98,99,99,100,100,101,101,102,102,102,103<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 103,104,104,105,105,106,106,107,107,107,108,108,109,109,110,110,111,111,112,112,113,113,113,114,114,115,115,116<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 116,117,117,118,118,119,119,120,120,121,121,122,122,123,123,124,124,125,125,126,126,127,127,128,128,129,129,130<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 130,131,131,132,132,133,133,134,134,135,135,136,136,137,137,138,138,139,139,140,140,141,141,142,142,143,144,144<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 145,145,146,146,147,147,148,148,149,149,150,150,151,152,152,153,153,154,154,155,155,156,157,157,158,158,159,159<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 160,160,161,162,162,163,163,164,164,165,165,166,167,167,168,168,169,169,170,171,171,172,172,173,174,174,175,175<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 176,176,177,178,178,179,179,180,181,181,182,182,183,184,184,185,185,186,187,187,188,188,189,190,190,191,191,192<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 193,193,194,195,195,196,196,197,198,198,199,199,200,201,201,202,203,203,204,204,205,206,206,207,208,208,209,210<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 210,211,212,212,213,213,214,215,215,216,217,217,218,219,219,220,221,221,222,223,223,224,225,225,226,227,227,228<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 229,229,230,231,231,232,233,233,234,235,235,236,237,237,238,239,239,240,241,241,242,243,243,244,245,246,246,247<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 248,248,249,250,250,251,252,253,253,254,255,255,256,257,257,258,259,260,260,261,262,262,263,264,265,265,266,267<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 268,268,269,270,270,271,272,273,273,274,275,276,276,277,278,278,279,280,281,281,282,283,284,284,285,286,287,287<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 288,289,290,290,291,292,293,293,294,295,296,296,297,298,299,300,300,301,302,303,303,304,305,306,306,307,308,309<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 310,310,311,312,313,313,314,315,316,317,317,318,319,320,321,321,322,323,324,324,325,326,327,328,328,329,330,331<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 332,332,333,334,335,336,337,337,338,339,340,341,341,342,343,344,345,346,346,347,348,349,350,350,351,352,353,354<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 355,355,356,357,358,359,360,360,361,362,363,364,365,366,366,367,368,369,370,371,371,372,373,374,375,376,377,377<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 378,379,380,381,382,383,383,384,385,386,387,388,389,390,390,391,392,393,394,395,396,397,397,398,399,400,401,402<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 403,404,405,405,406,407,408,409,410,411,412,413,413,414,415,416,417,418,419,420,421,422,423,423,424,425,426,427<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 428,429,430,431,432,433,433,434,435,436,437,438,439,440,441,442,443,444,445,446,446,447,448,449,450,451,452,453<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 454,455,456,457,458,459,460,461,462,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 481,482,483,484,485,486,487,488,489,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,536<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,565<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,583,584,585,586,587,588,589,590,591,592,593,594<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 595,596,598,599,600,601,602,603,604,605,606,607,608,610,611,612,613,614,615,616,617,618,619,620,622,623,624,625<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 626,627,628,629,630,632,633,634,635,636,637,638,639,640,642,643,644,645,646,647,648,649,651,652,653,654,655,656<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 657,658,660,661,662,663,664,665,666,668,669,670,671,672,673,674,676,677,678,679,680,681,683,684,685,686,687,688<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 689,691,692,693,694,695,696,698,699,700,701,702,703,705,706,707,708,709,711,712,713,714,715,716,718,719,720,721<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 722,724,725,726,727,728,729,731,732,733,734,735,737,738,739,740,741,743,744,745,746,748,749,750,751,752,754,755<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 756,757,758,760,761,762,763,765,766,767,768,769,771,772,773,774,776,777,778,779,781,782,783,784,785,787,788,789<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 790,792,793,794,795,797,798,799,800,802,803,804,805,807,808,809,810,812,813,814,815,817,818,819,821,822,823,824<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 826,827,828,829,831,832,833,835,836,837,838,840,841,842,843,845,846,847,849,850,851,852,854,855,856,858,859,860<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 862,863,864,865,867,868,869,871,872,873,875,876,877,878,880,881,882,884,885,886,888,889,890,892,893,894,896,897<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 898,900,901,902,904,905,906,908,909,910,912,913,914,916,917,918,920,921,922,924,925,926,928,929,930,932,933,934<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 936,937,938,940,941,943,944,945,947,948,949,951,952,953,955,956,957,959,960,962,963,964,966,967,968,970,971,973<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 974,975,977,978,980,981,982,984,985,986,988,989,991,992,993,995,996,998,999,1000,1002,1003,1005,1006,1007,1009<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1010,1012,1013,1014,1016,1017,1019,1020,1021,1023,1024,1026,1027,1029,1030,1031,1033,1034,1036,1037,1038,1040<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1041,1043,1044,1046,1047,1048,1050,1051,1053,1054,1056,1057,1059,1060,1061,1063,1064,1066,1067,1069,1070,1072<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1073,1074,1076,1077,1079,1080,1082,1083,1085,1086,1087,1089,1090,1092,1093,1095,1096,1098,1099,1101,1102,1104<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1105,1107,1108,1109,1111,1112,1114,1115,1117,1118,1120,1121,1123,1124,1126,1127,1129,1130,1132,1133,1135,1136<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1138,1139,1141,1142,1144,1145,1147,1148,1150,1151,1153,1154,1156,1157,1159,1160,1162,1163,1165,1166,1168,1169<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1171,1172,1174,1175,1177,1178,1180,1181,1183,1184,1186,1187,1189,1190,1192,1193,1195,1196,1198,1200,1201,1203<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1204,1206,1207,1209,1210,1212,1213,1215,1216,1218,1220,1221,1223,1224,1226,1227,1229,1230,1232,1233,1235,1237<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1238,1240,1241,1243,1244,1246,1247,1249,1251,1252,1254,1255,1257,1258,1260,1262,1263,1265,1266,1268,1269,1271<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1273,1274,1276,1277,1279,1280,1282,1284,1285,1287,1288,1290,1292,1293,1295,1296,1298,1300,1301,1303,1304,1306<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1308,1309,1311,1312,1314,1316,1317,1319,1320,1322,1324,1325,1327,1328,1330,1332,1333,1335,1336,1338,1340,1341<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1343,1345,1346,1348,1349,1351,1353,1354,1356,1358,1359,1361,1362,1364,1366,1367,1369,1371,1372,1374,1376,1377<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1379,1380,1382,1384,1385,1387,1389,1390,1392,1394,1395,1397,1399,1400,1402,1404,1405,1407,1409,1410,1412,1413<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1415,1417,1418,1420,1422,1423,1425,1427,1428,1430,1432,1433,1435,1437,1439,1440,1442,1444,1445,1447,1449,1450<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1452,1454,1455,1457,1459,1460,1462,1464,1465,1467,1469,1471,1472,1474,1476,1477,1479,1481,1482,1484,1486,1488<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1489,1491,1493,1494,1496,1498,1500,1501,1503,1505,1506,1508,1510,1512,1513,1515,1517,1518,1520,1522,1524,1525<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1527,1529,1530,1532,1534,1536,1537,1539,1541,1543,1544,1546,1548,1550,1551,1553,1555,1557,1558,1560,1562,1564<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1565,1567,1569,1571,1572,1574,1576,1578,1579,1581,1583,1585,1586,1588,1590,1592,1593,1595,1597,1599,1600,1602<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1604,1606,1608,1609,1611,1613,1615,1616,1618,1620,1622,1624,1625,1627,1629,1631,1632,1634,1636,1638,1640,1641<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1643,1645,1647,1649,1650,1652,1654,1656,1658,1659,1661,1663,1665,1667,1668,1670,1672,1674,1676,1677,1679,1681<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1683,1685,1686,1688,1690,1692,1694,1696,1697,1699,1701,1703,1705,1706,1708,1710,1712,1714,1716,1717,1719,1721<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1723,1725,1727,1728,1730,1732,1734,1736,1738,1740,1741,1743,1745,1747,1749,1751,1752,1754,1756,1758,1760,1762<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1764,1765,1767,1769,1771,1773,1775,1777,1778,1780,1782,1784,1786,1788,1790,1792,1793,1795,1797,1799,1801,1803<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1805,1807,1808,1810,1812,1814,1816,1818,1820,1822,1823,1825,1827,1829,1831,1833,1835,1837,1839,1840,1842,1844<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1846,1848,1850,1852,1854,1856,1858,1860,1861,1863,1865,1867,1869,1871,1873,1875,1877,1879,1881,1882,1884,1886<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1888,1890,1892,1894,1896,1898,1900,1902,1904,1906,1907,1909,1911,1913,1915,1917,1919,1921,1923,1925,1927,1929<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1931,1933,1935,1937,1938,1940,1942,1944,1946,1948,1950,1952,1954,1956,1958,1960,1962,1964,1966,1968,1970,1972<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 1974,1976,1978,1980,1982,1984,1985,1987,1989,1991,1993,1995,1997,1999,2001,2003,2005,2007,2009,2011,2013,2015<br />&nbsp; &nbsp; dw&nbsp; &nbsp; 2017,2019,2021,2023,2025,2027,2029,2031,2033,2035,2037,2039,2041,2043,2045,2047</p></div><p>EDIT: Crap...I did taht wrong. I have to translate an 8-bit number to an 11 bit number, not 11 to 11. <img src="https://chipmusic.org/forums/img/smilies/sad.png" width="15" height="15" alt="sad" /></p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-20T01:06:01Z</updated>
			<id>https://chipmusic.org/forums/post/260253/#p260253</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260251/#p260251"/>
			<content type="html"><![CDATA[<p>Thats very helpful, nitro. I will shoot for all 6-octaves, however I do want my program to be able to produce every possible frequency within the constrains of the cpu (64-131072Hz), given user&#039;s input. And yes, it is for musical purposes.<br />When you say &quot;pure tones&quot; do you mean only the classically tuned notes within the ET12? After C#10 can it no longer precisely maintain the 12 tones?</p><p>I am just about to the point in code to begin using the lookup table.</p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-19T22:18:05Z</updated>
			<id>https://chipmusic.org/forums/post/260251/#p260251</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260234/#p260234"/>
			<content type="html"><![CDATA[<p>What&#039;s the goal here? Are you trying to build something that is musically useful? If so, you may wish to make it tunable to the standard ET12 (equal temperament, 12 tone) scale. Gameboy has about 6 octaves of useful range. Lower than C3, and the hardware can&#039;t reproduce it. Higher than octave 8, an the pitch precision becomes so low that you can no longer produce pure tones. That gives you about 70 notes that you&#039;d want to hit, and then you can fill in the rest of the values between those, and/or extend the scale upward. </p><p>For example Imagine that every third value (0,3,6,9...) is a semitone, and the other values are pitches in-between. This gives about 256/3=85 available semitones, ranging from C3 to C#10 (~8.7 kHz) and 2 additional untuned values between each semitone.</p><p>Example Python code:<br /></p><div class="codebox"><pre><code>import math

# MIDI index to frequency
def m2f(m):
    return 440*math.pow(2,(m-69)/12.)

# Frequency in Hz to GB pitch value
def f2g(f):
    return 2048-(131072./f)

# GB pitch value to frequency in Hz
def g2f(g):
    return 131072./(2048-g)

print (&quot;Oct\tNote\tFreq (Hz)\tGB value&quot;)

# Print example data for human consumption
for i in range(256):
    print &quot;{0}\t{1}\t{2}\t{3}&quot;.format(i/3/12, ((i/3)%12)+1, m2f(36+i/3.), int(round(f2g(m2f(36+i/3.)))))

# Print assembly data
for i in range(256):
    print &quot;\tdw\t{0}&quot;.format(int(round(f2g(m2f(36+i/3.)))))</code></pre></div>]]></content>
			<author>
				<name><![CDATA[nitro2k01]]></name>
				<uri>https://chipmusic.org/nitro2k01</uri>
			</author>
			<updated>2018-10-16T23:55:44Z</updated>
			<id>https://chipmusic.org/forums/post/260234/#p260234</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260232/#p260232"/>
			<content type="html"><![CDATA[<p>Table lookup will win hands down in terms of cycle count, since calculating note frequencies involves several very costly mathematical operations.<br />Expanding the table to 512 bytes will help squeeze a few more cycles, if needed. Generally the idea is to split low and high bytes of the lookup values, and align each table to a 256 byte border, so you can directly translate the indices, like so<br /></p><div class="codebox"><pre><code>   ld h,table_base_lo_bytes&gt;&gt;8
   ld l,a     ; set index
   ld c,(hl)   ; load lo-byte
   ld h,table_base_hi_bytes&gt;&gt;8   ; or just inc h if hi-byte lut follows on next page
   ld b,(hl)    ; load hi-byte, frequency divider now in BC</code></pre></div>]]></content>
			<author>
				<name><![CDATA[irrlichtproject]]></name>
				<uri>https://chipmusic.org/irrlichtproject</uri>
			</author>
			<updated>2018-10-16T21:33:04Z</updated>
			<id>https://chipmusic.org/forums/post/260232/#p260232</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260231/#p260231"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>irrlichtproject wrote:</cite><blockquote><p>What exactly do you want to do? Sounds like you&#039;re trying to generate note frequency dividers. If that&#039;s the case I&#039;d definately recommend using a lookup table. It&#039;s gonna cost you 512 bytes at most.</p><p>Otherwise, just ld a,n, add a,a, rotate the carry into another register, rinse and repeat.</p></blockquote></div><p>Thanks for the reply! <br />I am trying to receive serial data and convert it to a frequency, yes.<br />Now that I think about the size of a lookup table in actual quantized bytes, it may not be as large as I had originally thought. Since I have to worry about two registers, one 8-bits and one 3-bits (11-bits in total) that can equate to 256+8 numbers, so 512 was a very generous guess. </p><p>Now the next question: which method would require the fewest cpu cycles? <br />Once I get to this point in the code, I will write up both routines and add up the cpu cycles for each. <br />Again, thanks for the input!</p><p>-Cheers,<br />-Fox</p>]]></content>
			<author>
				<name><![CDATA[Orgia Mode]]></name>
				<uri>https://chipmusic.org/Orgia+Mode</uri>
			</author>
			<updated>2018-10-16T21:17:12Z</updated>
			<id>https://chipmusic.org/forums/post/260231/#p260231</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Mapping Hex Values in ASM]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/260229/#p260229"/>
			<content type="html"><![CDATA[<p>What exactly do you want to do? Sounds like you&#039;re trying to generate note frequency dividers. If that&#039;s the case I&#039;d definately recommend using a lookup table. It&#039;s gonna cost you 512 bytes at most.</p><p>Otherwise, just ld a,n, add a,a, rotate the carry into another register, rinse and repeat.</p>]]></content>
			<author>
				<name><![CDATA[irrlichtproject]]></name>
				<uri>https://chipmusic.org/irrlichtproject</uri>
			</author>
			<updated>2018-10-16T20:16:39Z</updated>
			<id>https://chipmusic.org/forums/post/260229/#p260229</id>
		</entry>
</feed>
