protected int[] setVariable(int[] input, int index, int newValue, PARAMETER_MODES mode = PARAMETER_MODES.POSITION) { if (mode == PARAMETER_MODES.POSITION) { return(this.setVariableFromPositionMode(input, index, newValue)); } else { return(this.setVariableFromImidiateMode(input, index, newValue)); } }
public override int[] Execute(int[] input, int index) { int code = input[index]; PARAMETER_MODES inputOnePosMode = this.getModeByParameterPos(code, 1); PARAMETER_MODES inputTwoPosMode = this.getModeByParameterPos(code, 2); PARAMETER_MODES inputThreePosMode = this.getModeByParameterPos(code, 3); int newValue = this.getVariable(input, index + 1, inputOnePosMode) * this.getVariable(input, index + 2, inputTwoPosMode); input = this.setVariable(input, index + 3, newValue, inputThreePosMode); return(input); }
/// <summary> /// /// </summary> /// <param name="opcode"></param> /// <param name="parameter"> The xth parameterm, 1, 2, 3 etc</param> /// <returns></returns> protected PARAMETER_MODES getModeByParameterPos(int opcode, int parameter) { string code = opcode.ToString("D5"); // int opcodeLength = code.Length; PARAMETER_MODES returnValue = PARAMETER_MODES.POSITION; //default mode is position mode //calculate the index needed //e.g. parameter required = 3, 3 - 3 = 0 //parameter required = 1, 3 - 1 = 2 int index = 3 - parameter; if (code[index] == '1') //set mode to imidiate { returnValue = PARAMETER_MODES.IMIDIATE; } return(returnValue); }
public OpCodeParameter(PARAMETER_MODES newParamMode, long curVal, IntComputer computer) { paramMode = newParamMode; paramData = curVal; curComputer = computer; }