<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -3,3 +3,4 @@ Change log started July 2009.
 July 2009
 ================================================================================
  + Set the Z Machine Spec version header
+ + The optimised storew opcode would not correctly account for negative addresses.</diff>
      <filename>CHANGES</filename>
    </modified>
    <modified>
      <diff>@@ -602,38 +602,38 @@ function handleZ_call_vs(engine, a) {
 }
 
 ////////////////////////////////////////////////////////////////
-
+/***
 function handleZ_store_w(engine, a) {
     return &quot;setWord(&quot;+a[2]+&quot;,1*&quot;+a[0]+&quot;+2*&quot;+a[1]+&quot;)&quot;;
   }
+***/
 
-/***
 // Store a value in an array
 function handleZ_store_w(engine, a)
 {
 	// Calculate the address
 	if (isNotConst.test(a[0]) || isNotConst.test(a[1]))
-		var code = 'var tmp_' + (++temp_var) + ' = ' + a[0] + ' + 2 * ' + a[1] + ';', add = 'tmp_' + temp_var;
+		var code = 'var tmp_' + (++temp_var) + ' = (' + a[0] + ' + 2 * ' + a[1] + ') &amp; 0xFFFF;', addr = 'tmp_' + temp_var;
 	else
-		var code = '', add = a[0] + 2 * a[1];
+		var code = '', addr = (a[0] + 2 * a[1]) &amp; 0xFFFF;
 
 	// If we are setting a constant get the high and low bytes at compile time
 	if (!isNotConst.test(a[2]))
 	{
 		var value = (a[2] &amp; 0x8000 ? ~0xFFFF : 0) | a[2];
-		return code + 'm_memory[' + add + '] = ' + ((value &gt;&gt; 8) &amp; 0xFF) + ';' +
-			'm_memory[' + add + ' + 1] = ' + (value &amp; 0xFF);
+		return code + 'm_memory[' + addr + '] = ' + ((value &gt;&gt; 8) &amp; 0xFF) + ';' +
+			'm_memory[' + addr + ' + 1] = ' + (value &amp; 0xFF);
 	}
 	else
 	{
 		var tmp = 'tmp_' + (++temp_var);
 		return code + 'var ' + tmp + ' = ' + a[2] + ';' +
 			tmp + ' = (' + tmp + ' &amp; 0x8000 ? ~0xFFFF : 0) | ' + tmp + ';' +
-			'm_memory[' + add + '] = (' + tmp + ' &gt;&gt; 8) &amp; 0xFF;' +
-			'm_memory[' + add + ' + 1] = ' + tmp + ' &amp; 0xFF;';
+			'm_memory[' + addr + '] = (' + tmp + ' &gt;&gt; 8) &amp; 0xFF;' +
+			'm_memory[' + addr + ' + 1] = ' + tmp + ' &amp; 0xFF;';
 	}
 }
-***/
+
 function handleZ_storeb(engine, a) {
     return &quot;setByte(&quot;+a[2]+&quot;,1*&quot;+a[0]+&quot;+1*&quot;+a[1]+&quot;)&quot;;
   }</diff>
      <filename>gnusto-engine.js</filename>
    </modified>
    <modified>
      <diff>@@ -8,12 +8,13 @@
 	&lt;script src=&quot;testrunner.js&quot;&gt;&lt;/script&gt;
 	&lt;script src=&quot;../gnusto-engine.js&quot;&gt;&lt;/script&gt;
 	&lt;script&gt;
+FatalError = new Error();
 $(document).ready(function(){
 
 	test(&quot;Opcode storew&quot;, function() {
 		var arrays = {&quot;test_array&quot;: 64};
 		var zcode = [5,0,0,1,0,0,0,81,0,0,0,64,0,64,0,0,0,0,48,57,48,55,50,55,0,64,0,41,0,0,0,0,0,0,0,0,0,0,0,0,0,80,0,80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,78,70,65,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,225,83,64,0,12,34,232,63,12,34,225,91,64,1,0,232,127,2,225,99,64,0,12,34,232,63,12,34,232,127,3,225,107,64,0,0,232,127,64,225,147,0,4,12,34,232,63,12,34,232,127,64,225,155,0,5,0,232,127,6,232,127,64,225,163,0,0,12,34,232,63,12,34,232,127,7,232,127,64,225,171,0,0,0,186];
-		var engine = new GnustoEngine(console.log);
+		var engine = new GnustoEngine();
 		engine.loadStory(zcode);
 		engine.run();
 		same(engine.m_memory.slice(arrays.test_array, arrays.test_array + 16), [12,34,12,34,12,34,12,34,12,34,12,34,12,34,12,34]);</diff>
      <filename>tests/opcodes.html</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,7 @@ template = '''&lt;!DOCTYPE HTML&gt;
 	&lt;script src=&quot;testrunner.js&quot;&gt;&lt;/script&gt;
 	&lt;script src=&quot;../gnusto-engine.js&quot;&gt;&lt;/script&gt;
 	&lt;script&gt;
+FatalError = new Error();
 $(document).ready(function(){'''
 template_after = '''\n\n});
 	&lt;/script&gt;
@@ -53,7 +54,7 @@ for test in tests:
 
 		# Output the Gnusto running code
 		output.write('''
-		var engine = new GnustoEngine(console.log);
+		var engine = new GnustoEngine();
 		engine.loadStory(zcode);
 		engine.run();''')
 </diff>
      <filename>tests/opcodes.py</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,9 @@
 ! VAR:225 1 storew array word-index value
 ! array--&gt;word-index = value, i.e. stores the given value in the word at address array+2*word-index (which must lie in dynamic memory). (See loadw.)
 
+! Gnusto used to fail to correctly set addresses to unsigned values, and this array would show that. But it makes the test page too big so it's commented out now.
+!Array aaa --&gt; 17000;
+
 Array test_array --&gt; 8;
 Constant VALUE $C22;
 </diff>
      <filename>tests/opcodes/225.inf</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8a9122bfa672385af67ef5a67e85e231f36998a2</id>
    </parent>
  </parents>
  <author>
    <name>Dannii Willis</name>
    <email>curiousdannii@gmail.com</email>
  </author>
  <url>http://github.com/curiousdannii/gnusto/commit/c2ed96d131c7c982b2064a5288fccdcc397d2bd0</url>
  <id>c2ed96d131c7c982b2064a5288fccdcc397d2bd0</id>
  <committed-date>2009-07-26T19:54:32-07:00</committed-date>
  <authored-date>2009-07-26T19:54:32-07:00</authored-date>
  <message> + The optimised storew opcode would not correctly account for negative addresses.</message>
  <tree>11dc70c15af516f35cd683789740e918aa11aa2e</tree>
  <committer>
    <name>Dannii Willis</name>
    <email>curiousdannii@gmail.com</email>
  </committer>
</commit>
