|
@@ -1,4 +1,4 @@
|
|
|
-const { DecimalPlaceIsNonZero } = require("./common");
|
|
|
+const { DecimalPlaceIsNonZero, GetDecimalInPlace } = require("./common");
|
|
|
|
|
|
module.exports = {
|
|
|
/**
|
|
@@ -15,6 +15,12 @@ module.exports = {
|
|
|
* is interpreted as its literal value.
|
|
|
*/
|
|
|
IMMEDIATE_MODE: 1,
|
|
|
+ /**
|
|
|
+ * Relative Mode
|
|
|
+ *
|
|
|
+ * Unknown.
|
|
|
+ */
|
|
|
+ RELATIVE_MODE: 2,
|
|
|
/**
|
|
|
* Parse an opcode to get the Parameter Mode for an operation's parameter
|
|
|
*
|
|
@@ -31,7 +37,12 @@ module.exports = {
|
|
|
* @returns {number} Either POSITION_MODE or IMMEDIATE_MODE
|
|
|
*/
|
|
|
ParseParameterMode: function (rawOpcode, parameterIndex) {
|
|
|
- if (DecimalPlaceIsNonZero(rawOpcode, parameterIndex + 1)) { return this.IMMEDIATE_MODE; }
|
|
|
- return this.POSITION_MODE;
|
|
|
+ const paramModeFromOpcode = GetDecimalInPlace(rawOpcode, parameterIndex + 1);
|
|
|
+ switch (paramModeFromOpcode) {
|
|
|
+ case 0: return this.POSITION_MODE;
|
|
|
+ case 1: return this.IMMEDIATE_MODE;
|
|
|
+ case 2: return this.RELATIVE_MODE;
|
|
|
+ default: return this.POSITION_MODE;
|
|
|
+ }
|
|
|
},
|
|
|
};
|