|
@@ -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;
|