소스 검색

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;