Преглед изворни кода

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 година
родитељ
комит
e3f5a2eaa9
1 измењених фајлова са 6 додато и 3 уклоњено
  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;