Ver código fonte

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 1 ano atrás
pai
commit
b2e7168be8
1 arquivos alterados com 8 adições e 3 exclusões
  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;