Browse Source

Update Operation_Output to use 3 digit opcode

Updated the output function to take a 3-digit opcode telling the
function with Parameter Mode to use.
ApisNecros 1 year ago
parent
commit
3641667e27
1 changed files with 6 additions and 4 deletions
  1. 6 4
      IntComp/Computer.js

+ 6 - 4
IntComp/Computer.js

@@ -95,7 +95,7 @@ module.exports = class Computer {
                 break;
             }
             case this.OPCODES.OUTPUT: {
-                this.Operation_Output();
+                this.Operation_Output(rawOpcode);
                 break;
             }
             case this.OPCODES.JUMP_IF_TRUE: {
@@ -201,13 +201,15 @@ module.exports = class Computer {
     /**
      * Execute the OUTPUT opcode
      *
+     * @param {number} rawOpcode The opcode in memory used to make this call
      * @returns {void}
      */
-    Operation_Output() {
+    Operation_Output(rawOpcode) {
         const currAddress = this.stack.pointer;
-        const outputPosition = this.stack.Next().Get(ComputerParameterMode.IMMEDIATE_MODE);
+        const outputPositionMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 1);
+        const output = this.stack.Next().Get(outputPositionMode);
 
-        console.log(`OUTPUT FROM ADDRESS ${currAddress}: ${this.stack.GetAtIndex(outputPosition, ComputerParameterMode.IMMEDIATE_MODE)}`);
+        console.log(`OUTPUT FROM ADDRESS ${currAddress}: ${output}`);
     }
 
     /**