/// <summary> /// Initializes a new instance of the <see cref="OpCodeDecoder"/> class. /// </summary> /// <param name="platformConfig">The platform configuration.</param> /// <param name="prefetch">The prefetch.</param> public OpCodeDecoder(IPlatformConfig platformConfig, IPrefetchQueue prefetch) { _cpuMode = platformConfig.CpuMode; _undefinedInstruction = GetUndefinedInstructionFunction(platformConfig.UndefinedInstructionBehaviour); _prefetch = prefetch; _timer = new InstructionTimingsBuilder(); _indexRegisterOperands = new Dictionary <IndexRegister, IndexRegisterOperands> { { IndexRegister.HL, new IndexRegisterOperands( Operand.HL, Operand.mHL, Operand.L, Operand.H, false) } }; if (_cpuMode == CpuMode.Z80) { // Initialize Z80 specific index register operands. _indexRegisterOperands.Add(IndexRegister.IX, new IndexRegisterOperands(Operand.IX, Operand.mIXd, Operand.IXl, Operand.IXh, true)); _indexRegisterOperands.Add(IndexRegister.IY, new IndexRegisterOperands(Operand.IY, Operand.mIYd, Operand.IYl, Operand.IYh, true)); } }
public void Reset() { for (int i = 0; i < _cpsr.Length; i++) { _cpsr[i] = false; } _mode = CpuMode.usr; for (int j = 0; j < _registers.Length; j++) { _registers[j] = 0; } _mar = "Empty"; _mbr = 0; _alu.Reset(); _bm.Reset(); _bs.Reset(); _doneEvent.Reset(); CPSR_C = false; CPSR_F = false; CPSR_I = false; CPSR_N = false; CPSR_V = false; CPSR_Z = false; _opResult = true; _memory.Clear(); }
/// <summary> /// Decodes an instruction. /// </summary> /// <param name="code">Code buffer.</param> /// <param name="startIndex">Location of first byte of instruction. /// </param> /// <param name="location">CS:IP of the instruction to decode.</param> /// <param name="cpuMode">CPU operating mode.</param> /// <returns>The decoded instruction.</returns> /// <exception cref="InvalidInstructionException">If decoding fails. /// </exception> public static Instruction Decode( byte[] code, int startIndex, CpuMode cpuMode) { return Decode(new ArraySegment<byte>(code, startIndex, code.Length - startIndex), cpuMode); }
/// <summary> /// Decodes an instruction. /// </summary> /// <param name="code">Code buffer.</param> /// <param name="cpuMode">CPU operating mode.</param> /// <returns>The decoded instruction.</returns> /// <exception cref="InvalidInstructionException">If decoding fails. /// </exception> public static Instruction Decode(ArraySegment<byte> code, CpuMode cpuMode) { if (cpuMode != CpuMode.RealAddressMode) throw new NotSupportedException(); DecoderContext context = new DecoderContext(); context.AddressSize = CpuSize.Use16Bit; context.OperandSize = CpuSize.Use16Bit; X86Codec.Decoder decoder = new X86Codec.Decoder(); return decoder.Decode(code.Array, code.Offset, code.Count, context); }
public ARM6CPU() { //set registers etc to defaults _registers = new UInt32[16]; //32-bits _cpsr = new bool[32]; //Mode its bits 0..4 of CPSR _mode = CpuMode.usr; _alu = new ALU(); _bm = new BoothMultiplier(); _bs = new BarrelShifter(); _mar = "Empty"; _mbr = 0; _opResult = true; }
public DolphinOptions(FpsMode fpsSelection, CpuMode cpuModeSelection, string dolphinVersion) { FpsSelection = fpsSelection; CpuModeSelection = cpuModeSelection; DolphinVersion = dolphinVersion; }
/// <summary> /// Initializes a new instance of the <see cref="Interpreter"/> class. /// </summary> /// <param name="platformConfig">The platform configuration.</param> /// <param name="runtimeConfig">The runtime configuration.</param> public Interpreter(IPlatformConfig platformConfig, IRuntimeConfig runtimeConfig) { _cpuMode = platformConfig.CpuMode; _debug = runtimeConfig.DebugMode; }
private IEnumerable <Action> Test(CpuMode cpuMode) { using (var mock = AutoMock.GetLoose()) { var expected = Expected.Build(); var data = _halt ? _data.Concat(new object[] { PrimaryOpCode.HALT }).ToArray() : _data; var config = mock.Mock <IPlatformConfig>(); config.Setup(x => x.UndefinedInstructionBehaviour).Returns(UndefinedInstructionBehaviour.Throw); config.Setup(x => x.CpuMode).Returns(cpuMode); // Simulate a prefetch queue from the specified data. var queue = new Queue(data); var prefetch = mock.Mock <IPrefetchQueue>(); prefetch.Setup(x => x.NextByte()).Returns(() => { var value = queue.Dequeue(); switch (value) { case byte b: return(b); case sbyte b: return(unchecked ((byte)b)); case PrimaryOpCode op: return((byte)op); case PrefixCbOpCode op: return((byte)op); case PrefixEdOpCode op: return((byte)op); case GameBoyPrimaryOpCode op: return((byte)op); case GameBoyPrefixCbOpCode op: return((byte)op); default: throw new ArgumentOutOfRangeException(nameof(value), value, $"{value.GetType()} not supported"); } }); prefetch.Setup(x => x.NextWord()).Returns(() => (ushort)queue.Dequeue()); var expectedWordsRead = data.Count(x => x is ushort); var expectedBytesRead = data.Length - expectedWordsRead; // everything else is a byte. var totalBytesRead = expectedWordsRead * 2 + expectedBytesRead; prefetch.Setup(x => x.TotalBytesRead).Returns(() => totalBytesRead); // Run. var decoder = mock.Create <OpCodeDecoder>(); if (_throwOn.Contains(cpuMode)) { yield return(() => Should.Throw <InvalidOperationException>(() => decoder.DecodeNextBlock(_address))); yield break; } var block = decoder.DecodeNextBlock(_address); yield return(() => block.Address.ShouldBe(_address, nameof(block.Address))); yield return(() => block.Length.ShouldBe(totalBytesRead, nameof(block.Length))); yield return(() => block.Operations.FirstOrDefault().ShouldBe(expected)); // Timings, adjusted for the extra HALT. var timings = block.Timings; if (_halt) { // Remove tiumings generated by the HALT. timings -= new InstructionTimings(1, 4); } yield return(() => timings.ShouldBe(_expectedTimings)); // Make sure the correct mix of bytes and words were read. yield return(() => queue.Count.ShouldBe(0, () => $"Didn't read some data: {string.Join(", ", queue.ToArray())}")); yield return(() => prefetch.Verify(x => x.NextWord(), Times.Exactly(expectedWordsRead), $"Should have read {expectedWordsRead} words")); yield return(() => prefetch.Verify(x => x.NextByte(), Times.Exactly(expectedBytesRead), $"Should have read {expectedBytesRead} bytes")); if (_halt) { yield return(() => block.Operations.Count.ShouldBe(2, "Should have a single operation and a HALT")); } else { yield return(() => block.Operations.Count.ShouldBe(1, "Should have a single operation")); } } }
void UpdateCsprModeBits(CpuMode mode) { CPSR |= (UInt32)mode; }
/// <summary> /// Initializes a new instance of the <see cref="DynaRec"/> class. /// </summary> /// <param name="platformConfig">The platform configuration.</param> /// <param name="runtimeConfig">The runtime configuration.</param> public DynaRec(IPlatformConfig platformConfig, IRuntimeConfig runtimeConfig) : this() { _cpuMode = platformConfig.CpuMode; _debug = runtimeConfig.DebugMode; }