12345678910111213141516171819202122232425262728293031323334353637 |
- const { DecimalPlaceIsNonZero } = require("./common");
- module.exports = {
- /**
- * Position Mode
- *
- * When the int computer is in Position mode, the value at the pointer
- * is interpretted as another address in memory.
- */
- POSITION_MODE: 0,
- /**
- * Immediate Mode
- *
- * When the int computer is in Immediate Mode, the value at the pointer
- * is interpretted as its literal value.
- */
- IMMEDIATE_MODE: 1,
- /**
- * Parse an opcode to get the Parameter Mode for an operation's parameter
- *
- * Note: `parameterIndex` is a 1-based index, not 0-based.
- *
- * @example
- * // POSITION_MODE
- * const firstParamMode = ComputerParameterMode.ParseParameterMode(1002, 1);
- * // IMMEDIATE_MODE
- * const secondParamMode = ComputerParameterMode.ParseParameterMode(1002, 2);
- *
- * @param {number} rawOpcode The opcode in memory
- * @param {number} parameterIndex The index of the parameter in the function arguments
- * @returns {number} Either POSITION_MODE or IMMEDITATE_MODE
- */
- ParseParameterMode: function (rawOpcode, parameterIndex) {
- if (DecimalPlaceIsNonZero(rawOpcode, parameterIndex + 1)) { return this.IMMEDIATE_MODE; }
- return this.POSITION_MODE;
- },
- };
|