Forráskód Böngészése

Update output Parameter Modes to include isOutput

Set the `isOutput` value for all output position fetching to `true` so
that the correct values get returned.
ApisNecros 1 éve
szülő
commit
e3f5a2eaa9
1 módosított fájl, 6 hozzáadás és 3 törlés
  1. 6 3
      IntComp/Computer.js

+ 6 - 3
IntComp/Computer.js

@@ -261,10 +261,11 @@ module.exports = class Computer {
     Operation_Add(rawOpcode) {
         const operandLeftMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 1);
         const operandRightMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 2);
+        const outputMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 3) || 1;
 
         const operandLeft = this.stack.Next().Get(operandLeftMode);
         const operandRight = this.stack.Next().Get(operandRightMode);
-        const outputPosition = this.stack.Next().Get(ComputerParameterMode.IMMEDIATE_MODE);
+        const outputPosition = this.stack.Next().Get(outputMode, true);
 
         const newValue = operandLeft + operandRight;
         this.stack.Put(outputPosition, newValue);
@@ -283,10 +284,11 @@ module.exports = class Computer {
     Operation_Multiply(rawOpcode) {
         const operandLeftMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 1);
         const operandRightMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 2);
+        const outputMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 3) || 1;
 
         const operandLeft = this.stack.Next().Get(operandLeftMode);
         const operandRight = this.stack.Next().Get(operandRightMode);
-        const outputPosition = this.stack.Next().Get(ComputerParameterMode.IMMEDIATE_MODE);
+        const outputPosition = this.stack.Next().Get(outputMode, true);
 
         const newValue = operandLeft * operandRight;
         this.stack.Put(outputPosition, newValue);
@@ -414,10 +416,11 @@ module.exports = class Computer {
     Operation_Equality(rawOpcode, testCondition) {
         const operandLeftMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 1);
         const operandRightMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 2);
+        const outputMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 3) || 1;
 
         const operandLeft = this.stack.Next().Get(operandLeftMode);
         const operandRight = this.stack.Next().Get(operandRightMode);
-        const outputPosition = this.stack.Next().Get(ComputerParameterMode.IMMEDIATE_MODE);
+        const outputPosition = this.stack.Next().Get(outputMode, true);
 
         let testPassed = false;