public void Register() { RegisterHandler handler = RegisterHandler.Register; const CpuRegister DontCare = null; CheckRegister(handler, 0, true, m_registerSet.GR[0], "r/r1=0 => GR0"); CheckRegister(handler, 7, true, m_registerSet.GR[7], "r/r1=7 => GR7"); CheckRegister(handler, 8, false, DontCare, "r/r1=8 => エラー"); }
public void TotalFetchBytes(FetchByte fetchByte, CpuRegister cpu, int expectFetchByte) { // 適当なOpcodeを生成 var opcode = new OpCode(0x00, Instruction.ADC, Addressing.Absolute, fetchByte, 1, CycleOption.None); var actual = opcode.GetTotalArrangeBytes(cpu); Assert.Equal(expectFetchByte, actual); }
public void TotalCycles(CycleOption options, CpuRegister cpu, int expectCycles) { // default 1cycのテスト用のOpCodeを設定 var opcode = new OpCode(0x00, Instruction.ADC, Addressing.Implied, new FetchByte(1), 1, options); var cylces = opcode.GetTotalCycles(cpu); Assert.Equal(expectCycles, cylces); }
private void CheckPush(UInt16 spValue, UInt16 oprValue, UInt16 expectedSp, String message) { CpuRegister sp = m_registerSet.SP; sp.Value = spValue; Operate(Operator.Push, DontCareUInt16, oprValue); CheckRegister(sp, expectedSp, "SP の値が 1 減る: " + message); CheckMemory(expectedSp, oprValue, "SP の指すアドレスにオペランドの値が書き込まれる: " + message); }
public void TestInitialize() { m_registerSet = new CpuRegisterSet(); m_memory = new Memory(); m_gr = m_registerSet.GR[1]; m_pr = m_registerSet.PR; m_fr = m_registerSet.FR; m_logger = new TestLogger(); Operator.ReturningFromSubroutine += OnReturningFromSubroutine; Operator.CallingSuperVisor += OnCallingSuperVisor; }
private void CheckPop(UInt16 spValue, UInt16 memValue, UInt16 expectedSp, String message) { CpuRegister sp = m_registerSet.SP; sp.Value = spValue; m_memory.Write(spValue, memValue); Operate(Operator.Pop, DontCareUInt16, DontCareUInt16); CheckRegister(m_gr, memValue, "SP の指すアドレスから値が指定のレジスタに読み込まれる: " + message); CheckRegister(sp, expectedSp, "SP の値が 1 増える: " + message); }
private void CheckIndexerGrNumberRange(Int32 grNumber, Boolean success, String message) { try { CpuRegister notUsed = m_gr[grNumber]; Assert.IsTrue(success, message); } catch (Casl2SimulatorException) { Assert.IsFalse(success, message); } }
private void CheckRegister( RegisterHandler handler, UInt16 rR1Field, Boolean success, CpuRegister expected, String message) { try { CpuRegister actual = handler.GetRegister(rR1Field, m_registerSet); Assert.IsTrue(success, message); Assert.AreSame(expected, actual, message); } catch (Casl2SimulatorException) { Assert.IsFalse(success, message); } }
public Cpu6510(Computer mb) { #region OPCODE_DEBUGGING foreach (var oc in Enum.GetValues(typeof(OpCode)) as OpCode[]) { _opcodeStr[(int)oc] = oc.ToString().Split('_')[0]; } #endregion _mb = mb; _memory = mb.MainMemory; Reg = new CpuRegister(); SetupOpcodeDictionary(); }
public CpuFlags(CpuRegister cpuRegister) { _reg = cpuRegister; }
/// <summary> /// ROMの内容をDisassembleします /// systemAddrにResetAddrを使用します。引数のCpuRegisterは内容が変更されるのでCopyされたものを指定します /// </summary> /// <param name="c"></param> public static IEnumerable <(OpCode, byte[], uint, uint)> Disassemble(this Cartridge cartridge, CpuRegister cpu) => cartridge.Disassemble(cpu, cartridge.ResetAddrInEmulation);
public void TestInitialize() { m_pr = new CpuRegister(RegisterDef.PR); m_memory = new Memory(); }
private void CheckRegister(CpuRegister reg, UInt16 expected, String message) { CpuRegisterTest.Check(reg, expected, message); }
/// <summary> /// 引数に指定されたバイナリをすべて展開します /// </summary> /// <param name="src">データソース</param> /// <param name="cpuReg">CPUの事前状態、未指定の場合はReset状態の値が使われる。引数に指定した場合、継続して呼び出せるように状態は変更される。変更されたくない場合はDeepCloneした値を渡す</param> /// <param name="cpuReg">CPU Regの値を解析中も固定したい場合はtrue</param> /// <returns>(OpCode, Operand, offset)の組み合わせ</returns> public static IEnumerable <(OpCode, byte[], int)> Parse(IEnumerable <byte> src, CpuRegister cpuReg = null, bool isFixedReg = false) { // 指定されてなければ初期値を使う if (cpuReg == null) { cpuReg = new CpuRegister(); cpuReg.Reset(); } // 順番に読み出す IEnumerator <byte> e = src.GetEnumerator(); for (int offset = 0; e.MoveNext(); offset++) { // get opcode var rawOpCode = e.Current; if (!OpCodeDefs.OpCodes.TryGetValue(rawOpCode, out OpCode opcode)) { throw new FormatException($"Opcode:{rawOpCode:02X}が見つかりませんでした. {nameof(offset)}={offset}"); } // get operand var operandLength = opcode.GetTotalArrangeBytes(cpuReg) - 1; var operandList = new List <byte>(); for (int i = 0; i < operandLength; i++) { if (!e.MoveNext()) { throw new FormatException($"Opcode:{opcode}のOperandを取得中にデータソースが枯渇しました, {nameof(offset)}={offset}"); } operandList.Add(e.Current); } // 命令内容を見てX,M,E flagを更新し、次回以降の動的にフェッチサイズを変える // SEP/REPはOperandが1だったフラグをSET/RESETするので直接Valueに上書きしてない... if (!isFixedReg) { switch (opcode.Inst) { case Instruction.SEP: { // SEP #u8 var flags = (ProcessorStatusFlag)operandList[0]; if (flags.HasFlag(ProcessorStatusFlag.M)) { cpuReg.P.UpdateFlag(ProcessorStatusFlag.M, true); } if (flags.HasFlag(ProcessorStatusFlag.X)) { cpuReg.P.UpdateFlag(ProcessorStatusFlag.X, true); } break; } case Instruction.REP: { // REP #u8 var flags = (ProcessorStatusFlag)operandList[0]; if (flags.HasFlag(ProcessorStatusFlag.M)) { cpuReg.P.UpdateFlag(ProcessorStatusFlag.M, false); } if (flags.HasFlag(ProcessorStatusFlag.X)) { cpuReg.P.UpdateFlag(ProcessorStatusFlag.X, false); } break; } case Instruction.XCE: // Exchange Carry and Emulation Flags, --MX---CE cpuReg.P.UpdateFlag(ProcessorStatusFlag.M | ProcessorStatusFlag.X | ProcessorStatusFlag.E, false); break; default: break; } } // 今回の結果 yield return(opcode, operandList.ToArray(), offset); // Operand分もfetchしているのでアドレス進める offset += operandLength; } }
[DllImport(DllPath)] public static extern void SetSa1Register(CpuRegister reg, UInt16 value);
public static ulong VscxGetRegisterValue64(this DkmStackWalkFrame frame, CpuRegister reg) { byte[] buffer = new byte[8]; frame.Registers.GetRegisterValue((uint)reg, buffer); return(BitConverter.ToUInt64(buffer, 0)); }
public void TestInitialize() { m_register = new CpuRegister(RegisterDef.GR0); }
internal static void Check(CpuRegister reg, UInt16 expected, String message) { UInt16 actual = reg.Value.GetAsUnsigned(); Assert.AreEqual(expected, actual, message); }
public static ulong VscxGetRegisterValue64(this DkmStackWalkFrame frame, CpuRegister reg) { byte[] buffer = new byte[8]; frame.Registers.GetRegisterValue((uint)reg, buffer); return BitConverter.ToUInt64(buffer, 0); }