public static byte DEY(I6502 cpu) { cpu.Y--; UpdateNegative(cpu, cpu.Y); UpdateZero(cpu, cpu.Y); return(0); }
public static byte LDA(I6502 cpu) { UpdateNegative(cpu, cpu.Fetched); UpdateZero(cpu, cpu.Fetched); cpu.A = cpu.Fetched; return(1); }
public static byte ROR(I6502 cpu) { UInt16 shifted = cpu.Fetched; // Add carry to bit 8 if set if (cpu.GetFlag(Flags.C)) { shifted |= 0x100; } // Update carry flag if bit 0 is 1. cpu.SetFlag(Flags.C, (shifted & 0x01) == 0x01); // Shift shifted = (byte)(shifted >> 1); UpdateZero(cpu, (byte)shifted); UpdateNegative(cpu, shifted); if (cpu.ImpliedAddress) { cpu.A = (byte)(shifted & 0x00FF); } else { cpu.Bus.Write(cpu.Address, (byte)shifted); } return(0); }
public static byte CPY(I6502 cpu) { cpu.SetFlag(Flags.C, cpu.Y >= cpu.Fetched); cpu.SetFlag(Flags.Z, cpu.Y == cpu.Fetched); cpu.SetFlag(Flags.N, ((cpu.Y - cpu.Fetched) & 0x80) == 0x80); return(0); }
public static byte CMP(I6502 cpu) { cpu.SetFlag(Flags.C, cpu.A >= cpu.Fetched); cpu.SetFlag(Flags.Z, cpu.A == cpu.Fetched); cpu.SetFlag(Flags.N, ((cpu.A - cpu.Fetched) & 0x80) == 0x80); return(1); }
public static byte ORA(I6502 cpu) { cpu.A |= cpu.Fetched; UpdateNegative(cpu, cpu.A); UpdateZero(cpu, cpu.A); return(1); }
public static byte TAY(I6502 cpu) { cpu.Y = cpu.A; UpdateNegative(cpu, cpu.Y); UpdateZero(cpu, cpu.Y); return(0); }
public static byte INX(I6502 cpu) { cpu.X++; UpdateNegative(cpu, cpu.X); UpdateZero(cpu, cpu.X); return(0); }
public static byte DEC(I6502 cpu) { byte decrementedValue = (byte)(cpu.Fetched - 1); cpu.Bus.Write(cpu.Address, decrementedValue); UpdateNegative(cpu, decrementedValue); UpdateZero(cpu, decrementedValue); return(0); }
public static byte TSX(I6502 cpu) { cpu.X = cpu.StackPointer; UpdateNegative(cpu, cpu.X); UpdateZero(cpu, cpu.X); return(0); }
public static byte TYA(I6502 cpu) { cpu.A = cpu.Y; UpdateNegative(cpu, cpu.A); UpdateZero(cpu, cpu.A); return(0); }
public static byte PLA(I6502 cpu) { cpu.StackPointer++; cpu.A = cpu.Bus.Read(cpu.GetFullStackAddress()); UpdateZero(cpu, cpu.A); UpdateNegative(cpu, cpu.A); return(0); }
public static byte BIT(I6502 cpu) { byte test = (byte)(cpu.A & cpu.Fetched); UpdateZero(cpu, test); UpdateNegative(cpu, cpu.Fetched); cpu.SetFlag(Flags.V, (cpu.Fetched & 0x40) == 0x40); return(0); }
public static byte JSR(I6502 cpu) { cpu.Bus.Write(cpu.GetFullStackAddress(), (byte)((cpu.ProgramCounter - 1 >> 8) & 0x00FF)); cpu.StackPointer--; cpu.Bus.Write(cpu.GetFullStackAddress(), (byte)(cpu.ProgramCounter - 1 & 0x00FF)); cpu.StackPointer--; cpu.ProgramCounter = cpu.Address; return(0); }
static void PrintMe(I6502 mos6502) { Console.WriteLine("ProgramCounter = " + mos6502.ProgramCounter); Console.WriteLine("StackPointer = " + mos6502.StackPointer); Console.WriteLine("Accumulator = " + mos6502.Accumulator); Console.WriteLine("IndexX = " + mos6502.IndexX); Console.WriteLine("IndexY = " + mos6502.IndexY); Console.WriteLine("Status = " + Convert.ToString(mos6502.Status, 2)); Console.WriteLine("Clock = " + mos6502.Clock); Console.WriteLine(); }
public static byte RTS(I6502 cpu) { cpu.StackPointer++; UInt16 lo = cpu.Bus.Read(cpu.GetFullStackAddress()); cpu.StackPointer++; UInt16 hi = cpu.Bus.Read(cpu.GetFullStackAddress()); cpu.ProgramCounter = (UInt16)(((hi << 8) | lo) + 1); return(0); }
public static byte ADC(I6502 cpu) { UInt16 sum = (UInt16)(cpu.A + cpu.Fetched + (cpu.GetFlag(Flags.C) ? 1 : 0)); UpdateCarry(cpu, sum); UpdateZero(cpu, sum); UpdateNegative(cpu, sum); cpu.SetFlag(Flags.V, ((cpu.A ^ (byte)sum) & ~(cpu.A ^ cpu.Fetched) & 0x0080) == 0x0080); cpu.A = (byte)(sum & 0x00FF); return(1); }
/** * Mirror of OLC add Overflow truth table for subtraction * A M ~A ~M R | V | A^M | A^R | ~M^R | M^R | * -------------------------------------------- * 0 0 1 1 0 | 0 | 0 | 0 | 1 | 0 * 0 0 1 1 1 | 0 | 0 | 1 | 0 | 1 * 0 1 1 0 0 | 0 | 1 | 0 | 0 | 1 * 0 1 1 0 1 | 1 | 1 | 1 | 1 | 0 * 1 0 0 1 0 | 0 | 1 | 1 | 1 | 0 * 1 0 0 1 1 | 1 | 1 | 0 | 0 | 1 * 1 1 0 0 0 | 0 | 0 | 1 | 0 | 1 * 1 1 0 0 1 | 0 | 0 | 0 | 1 | 0 */ public static byte SBC(I6502 cpu) { UInt16 inverse = (byte)~cpu.Fetched; UInt16 difference = (UInt16)(cpu.A + inverse + (cpu.GetFlag(Flags.C) ? 1 : 0)); cpu.SetFlag(Flags.C, difference > 255); cpu.SetFlag(Flags.Z, (difference & 0x00FF) == 0); cpu.SetFlag(Flags.N, (difference & 0x0080) == 0x0080); cpu.SetFlag(Flags.V, ((cpu.A ^ difference) & (cpu.A ^ cpu.Fetched) & 0x0080) == 0x0080); cpu.A = (byte)(difference & 0x00FF); return(1); }
public EmulationShell(INesRomReader romReader, INesVideoOut videoOut) { m_cpu = new Nmos6502(m_sync); m_ppu = new NesPpu(m_sync) { Cpu = m_cpu, VideoOut = videoOut }; InitializeSpriteMemory(romReader); InitializeCpuMemory(romReader); InitializePpuMemory(romReader); m_cpu.BeginRun(); m_ppu.BeginRun(); }
public static byte RTI(I6502 cpu) { cpu.StackPointer++; cpu.Status = cpu.Bus.Read(cpu.GetFullStackAddress()); cpu.StackPointer++; UInt16 lo = cpu.Bus.Read(cpu.GetFullStackAddress()); cpu.StackPointer++; UInt16 hi = cpu.Bus.Read(cpu.GetFullStackAddress()); cpu.ProgramCounter = (UInt16)((hi << 8) | lo); cpu.SetFlag(Flags.I, false); return(0); }
public static byte LSR(I6502 cpu) { byte shifted = (byte)(cpu.Fetched >> 1); cpu.SetFlag(Flags.C, (cpu.Fetched & 0x01) == 0x01); cpu.SetFlag(Flags.N, false); UpdateZero(cpu, shifted); if (cpu.ImpliedAddress) { cpu.A = shifted; } else { cpu.Bus.Write(cpu.Address, shifted); } return(0); }
public static byte ASL(I6502 cpu) { UInt16 shiftedValue = (UInt16)(cpu.Fetched << 1); UpdateCarry(cpu, shiftedValue); UpdateZero(cpu, shiftedValue); UpdateNegative(cpu, shiftedValue); if (cpu.ImpliedAddress) { cpu.A = (byte)(shiftedValue & 0x00FF); } else { cpu.Bus.Write(cpu.Address, (byte)shiftedValue); } return(0); }
public static byte BCS(I6502 cpu) { byte extraCycles = 0; if (cpu.GetFlag(Flags.C)) { extraCycles++; cpu.Address = (UInt16)(cpu.ProgramCounter + cpu.BranchRelativeAddress); if ((cpu.Address & 0xFF00) != (cpu.ProgramCounter & 0xFF00)) { extraCycles++; } cpu.ProgramCounter = cpu.Address; } return(extraCycles); }
public static byte ROL(I6502 cpu) { UInt16 shifted = (UInt16)(cpu.Fetched << 1); if (cpu.GetFlag(Flags.C)) { shifted++; } UpdateCarry(cpu, shifted); UpdateZero(cpu, (byte)shifted); UpdateNegative(cpu, shifted); if (cpu.ImpliedAddress) { cpu.A = (byte)(shifted & 0x00FF); } else { cpu.Bus.Write(cpu.Address, (byte)shifted); } return(0); }
public static byte PLP(I6502 cpu) { cpu.StackPointer++; cpu.Status = cpu.Bus.Read(cpu.GetFullStackAddress()); return(0); }
public static byte XXX(I6502 cpu) { throw new NotImplementedException("Invalid Op code"); }
public static byte PHP(I6502 cpu) { cpu.Bus.Write(cpu.GetFullStackAddress(), (byte)(cpu.Status | (byte)Flags.B | (byte)Flags.U)); cpu.StackPointer--; return(0); }
public static byte TXS(I6502 cpu) { cpu.StackPointer = cpu.X; return(0); }
public static byte SEI(I6502 cpu) { cpu.SetFlag(Flags.I, true); return(0); }
public static byte STY(I6502 cpu) { cpu.Bus.Write(cpu.Address, cpu.Y); return(0); }