public void Execute(InstructionDTO instructionData, CPU cpu) { if (cpu.Registers[instructionData.X] == cpu.Registers[instructionData.Y]) { cpu.ProgramCounter += 2; } }
private void ExecuteInstruction(InstructionDTO instructionData, IExecutableInstruction instruction) { ValidateInstruction(instructionData, instruction); instruction.Execute(instructionData, this); RedrawDisplayIfNeeded(instruction); }
public void Execute(InstructionDTO instructionData, CPU cpu) { int yCoordinate = GetYCoordinate(instructionData, cpu); int rows = instructionData.N; cpu.VFRegister = 0; for (int row = 0; row < rows; row++) { int xCoordinate = GetXCoordinate(instructionData, cpu); byte dataOnRow = GetDataToDrawOnRow(cpu, row); for (int bit = 0; bit < 8; bit++) { int currentBit = GetBitFromByte(ref dataOnRow); cpu.VFRegister |= cpu.Display.SetPixel(xCoordinate, yCoordinate, currentBit); xCoordinate--; if (IndexAboveOrBelowScreenSize(xCoordinate, yCoordinate)) { break; } } yCoordinate++; if (IndexAboveOrBelowScreenSize(xCoordinate, yCoordinate)) { break; } } }
public void Execute(InstructionDTO instructionData, CPU cpu) { int registerXValue = cpu.Registers[instructionData.X]; cpu.VFRegister = BinaryHelper.GetMostSignificantBitValue((byte)registerXValue); cpu.Registers[instructionData.X] *= 2; }
public void Execute(InstructionDTO instructionData, CPU cpu) { int registerXValue = cpu.Registers[instructionData.X]; int registerYValue = cpu.Registers[instructionData.Y]; cpu.VFRegister = registerYValue > registerXValue ? 1 : 0; cpu.Registers[instructionData.X] = registerYValue - registerXValue; }
public void Execute(InstructionDTO instructionData, CPU cpu) { int registerX = cpu.Registers[instructionData.X]; int registerY = cpu.Registers[instructionData.Y]; cpu.VFRegister = registerX > registerY ? 1 : 0; cpu.Registers[instructionData.X] = registerX - registerY; }
public void Execute(InstructionDTO instructionData, CPU cpu) { var registerValue = cpu.Registers[instructionData.X]; var currentKey = cpu.CurrentlyPressedKeyboard; if (registerValue != currentKey) { cpu.ProgramCounter += 2; } }
public void Execute(InstructionDTO instructionData, CPU cpu) { if (cpu.CurrentlyPressedKeyboard != -1) { cpu.Registers[instructionData.X] = cpu.CurrentlyPressedKeyboard; } else { cpu.ProgramCounter -= 2; // makes the cpu stuck on this instruction until user input } }
private void ValidateInstruction(InstructionDTO instructionData, IExecutableInstruction instruction) { /* if (instructionData == null || instructionData.RawData.All(x => x == 0)) * { * throw new Exception("Instruction data cannot be null or empty"); * } * if (instruction == null) * { * // throw new Exception("Instruction implementation cannot be null"); * }*/ }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.VFRegister = 0; var result = cpu.Registers[instructionData.X] + cpu.Registers[instructionData.Y]; if (result > 255) { cpu.VFRegister = 1; result &= 0b11111111; } cpu.Registers[instructionData.X] = result; }
public void Execute(InstructionDTO instructionData, CPU cpu) { var value = cpu.Registers[instructionData.X]; var onesDigit = value % 10; cpu.Memory.SetByte(cpu.VIRegister + 2, (byte)onesDigit); value /= 10; var tensDigit = value % 10; cpu.Memory.SetByte(cpu.VIRegister + 1, (byte)tensDigit); value /= 10; var hundretsDigit = value % 10; cpu.Memory.SetByte(cpu.VIRegister, (byte)hundretsDigit); }
private int GetXCoordinate(InstructionDTO instructionData, CPU cpu) { return(cpu.Registers[instructionData.X] % Display.horizontalSize); }
public void Execute(InstructionDTO instructionData, CPU cpu) { BinaryHelper.GetLowerNibbleValue((byte)cpu.Registers[instructionData.X]); }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.ProgramCounter = instructionData.NNN; }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.ProgramCounter = instructionData.NNN + cpu.Registers[0]; }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.CallStack.Push(cpu.ProgramCounter); cpu.ProgramCounter = instructionData.NNN; }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.Registers[instructionData.X] = cpu.Registers[instructionData.X] ^ cpu.Registers[instructionData.Y]; }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.VIRegister = instructionData.NNN; }
public void Execute(InstructionDTO instructionData, CPU cpu) { //do nothing }
private IExecutableInstruction DecodeInstruction(InstructionDTO instruction) { switch (instruction.HexData[0]) { case '0': if (instruction.HexData == "00E0") { return(new CLS()); } else if (instruction.HexData == "00EE") { return(new RET()); } break; case '1': return(new JP()); case '2': return(new CALL()); case '3': return(new SE()); case '4': return(new SNE()); case '5': return(new SERegisterVariant()); case '6': return(new LD()); case '7': return(new ADD()); case '8': switch (instruction.HexData[3]) { case '0': return(new LDRegisterVariant()); case '1': return(new OR()); case '2': return(new AND()); case '3': return(new XOR()); case '4': return(new ADDRegisterVariant()); case '5': return(new SUB()); case '6': return(new SHR()); case '7': return(new SUBN()); case 'E': return(new SHL()); } break; case '9': return(new SNE()); case 'A': return(new LDIndexVariant()); case 'B': return(new JPRegisterVariant()); case 'C': return(new RND()); case 'D': return(new DRW()); case 'E': switch (instruction.KK) { case 0x9E: return(new SKP()); case 0xA1: return(new SKNP()); } break; case 'F': switch (instruction.KK) { case 0x07: return(new LDDelayTimerVariantDTtoVX()); case 0x0A: return(new LDKeyInputVariant()); case 0x15: return(new LDDelayTimerVariantVXtoDT()); case 0x18: return(new LDSoundTimerVariant()); case 0x1E: return(new ADDIRegisterVariant()); case 0x29: return(new LDFontVariant()); case 0x33: return(new LDBcdVariant()); } break; } return(new BlankInstruction()); //Don't want to use 'default' in switch, because it has nested switch statements }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.VIRegister = cpu.DTRegister + cpu.Registers[instructionData.X]; }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.Display.ClearDisplay(); }
private int GetYCoordinate(InstructionDTO instructionData, CPU cpu) { return(cpu.Registers[instructionData.Y] % Display.verticalSize); }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.Registers[instructionData.X] = instructionData.KK + RandomGenerator.GetRandomByte(); }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.Registers[instructionData.X] += instructionData.KK; }
public void Execute(InstructionDTO instructionData, CPU cpu) { cpu.ProgramCounter = cpu.CallStack.Pop(); }