Parcourir la source

Add isOutput param to Get function

When getting a value off the stack, if that value is going to be the
memory address of the output for another function, then we never want it
in immediate mode. In this case, only the value at the next pointer, or
that value + the Relative Base Offset should be returned.
ApisNecros il y a 1 an
Parent
commit
b2e7168be8
1 fichiers modifiés avec 8 ajouts et 3 suppressions
  1. 8 3
      IntComp/Stack.js

+ 8 - 3
IntComp/Stack.js

@@ -40,16 +40,21 @@ module.exports = class Stack {
     /**
      * Get the value from the stack by the pointer's current position
      *
+     * When `isOutput` is set to `true`, then a value retrieved in Immediate Mode,
+     * or the result of a Relative Mode offset is returned.
+     *
      * @param {number} [parameterMode=0] The Parameter Mode to use to retrieve the value
+     * @param {boolean} [isOutput=false] Is the parameter going to be an output position
      * @returns {number} The value at the current pointer position on the stack
      */
-    Get(parameterMode = ComputerParameterMode.POSITION_MODE) {
+    Get(parameterMode = ComputerParameterMode.POSITION_MODE, isOutput = false) {
         let value = this._stack[this.pointer];
-        if (parameterMode == ComputerParameterMode.POSITION_MODE) {
+        if (!isOutput && parameterMode == ComputerParameterMode.POSITION_MODE) {
             value = this._stack[value];
         }
         else if (parameterMode == ComputerParameterMode.RELATIVE_MODE) {
-            value = this._stack[value + this.relativeBaseOffset];
+            const newPointer = value + this.relativeBaseOffset;
+            value = isOutput ? newPointer : this._stack[newPointer];
         }
 
         return value ?? 0;