protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { ushort result = arg; result <<= 1; var byteResult = (byte) (result & 0xFF); write(byteResult); cpuState.SetNegativeFlag(byteResult); cpuState.SetZeroFlag(byteResult); cpuState.SetFlag(CpuState.Flags.Carry, result & 0xFF00); switch (Variants[memory[cpuState.Pc]]) { case AddressingMode.Accumulator: cycles = 2; break; case AddressingMode.ZeroPage: cycles = 5; break; case AddressingMode.ZeroPageXIndexed: cycles = 6; break; case AddressingMode.Absolute: cycles = 6; break; case AddressingMode.AbsoluteX: cycles = 7; break; } }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { bool carry = cpuState.IsFlagSet(CpuState.Flags.Carry); cpuState.SetFlag(CpuState.Flags.Carry, arg & 0x80); arg <<= 1; if (carry) { arg |= 1; } write(arg); cpuState.SetNegativeFlag(arg); cpuState.SetZeroFlag(arg); switch (Variants[memory[cpuState.Pc]]) { case AddressingMode.Accumulator: cycles = 2; break; case AddressingMode.ZeroPage: cycles = 5; break; case AddressingMode.ZeroPageXIndexed: cycles = 6; break; case AddressingMode.Absolute: cycles = 6; break; case AddressingMode.AbsoluteX: cycles = 7; break; } }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { var breakSet = cpuState.IsFlagSet(CpuState.Flags.Break); cpuState.StatusRegister = cpuState.PopStack(memory); cpuState.StatusRegister |= 1 << 5; cpuState.SetFlag(CpuState.Flags.Break, breakSet); cycles = 4; }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { var comparer = cpuState.A; var cmp = comparer - arg; cpuState.SetFlag(CpuState.Flags.Carry, cmp >= 0); cpuState.SetNegativeFlag((byte) (cmp & 0xFF)); cpuState.SetZeroFlag((byte) (cmp & 0xFF)); }
public int Execute(CpuState cpuState, IMemory memory) { var breakSet = cpuState.IsFlagSet(CpuState.Flags.Break); cpuState.StatusRegister = cpuState.PopStack(memory); cpuState.SetFlag(CpuState.Flags.Break, breakSet); cpuState.StatusRegister |= 1 << 5; var low = cpuState.PopStack(memory); var high = cpuState.PopStack(memory); cpuState.Pc = (ushort)((high << 8) | low); return 6; }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { var sum = (ushort) (arg + cpuState.A); if (cpuState.IsFlagSet(CpuState.Flags.Carry)) { ++sum; } var byteSum = (byte)(sum & 0xFF); cpuState.SetOverflow(cpuState.A, arg, byteSum); cpuState.A = byteSum; cpuState.SetZeroFlag(cpuState.A); cpuState.SetNegativeFlag(cpuState.A); cpuState.SetFlag(CpuState.Flags.Carry, sum & 0xFF00); }
public void Reset() { CpuState.SetRegister("PC", MemoryMap.Payload.Address); CpuState.SetRegister("SP", MemoryMap.Stack.Address); for (int i = 0; i < 13; i++) { CpuState.SetRegister("R" + i, 0); } CpuState.SetRegister("LR", 0); CpuState.SetFlag("C", false); CpuState.SetFlag("N", false); CpuState.SetFlag("V", false); CpuState.SetFlag("Z", false); }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { // A - M - C -> A N Z C I D V // + + + - - + int a = cpuState.A; arg ^= 0xFF; a += arg; if (cpuState.IsFlagSet(CpuState.Flags.Carry)) { ++a; } var byteResult = (byte) (a & 0xFF); cpuState.SetOverflow(cpuState.A, arg, byteResult); cpuState.A = byteResult; cpuState.SetNegativeFlag(cpuState.A); cpuState.SetZeroFlag(cpuState.A); cpuState.SetFlag(CpuState.Flags.Carry, (byteResult & 0x80) == 0); }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { cpuState.SetFlag(CpuState.Flags.DecimalMode, false); }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, ref int cycles) { cpuState.SetFlag(CpuState.Flags.InterruptDisable, true); }
protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles) { cpuState.SetZeroFlag((byte) (arg & cpuState.A)); cpuState.SetFlag(CpuState.Flags.Negative, arg & 0x80); cpuState.SetFlag(CpuState.Flags.Overflow, arg & 0x40); }