Ejemplo n.º 1
0
        private void PrintState()
        {
            Console.SetCursorPosition(0, 0);
            string[] dumpLines = _ram.HexDump(0, 0x0800, 32).Split('\n', '\r');

            dumpLines[0] += "  Status Flags:";
            dumpLines[1] += "  N  V  U  B  D  I  Z  C";
            dumpLines[2] += String.Format("  {0}  {1}  {2}  {3}  {4}  {5}  {6}  {7}",
                                          _cpu.GetFlag(Flags.N) ? 1 : 0,
                                          _cpu.GetFlag(Flags.V) ? 1 : 0,
                                          _cpu.GetFlag(Flags.U) ? 1 : 0,
                                          _cpu.GetFlag(Flags.B) ? 1 : 0,
                                          _cpu.GetFlag(Flags.D) ? 1 : 0,
                                          _cpu.GetFlag(Flags.I) ? 1 : 0,
                                          _cpu.GetFlag(Flags.Z) ? 1 : 0,
                                          _cpu.GetFlag(Flags.C) ? 1 : 0);

            dumpLines[4] += String.Format("  A:       ${0:X2}", _cpu.A);
            dumpLines[5] += String.Format("  X:       ${0:X2}", _cpu.X);
            dumpLines[6] += String.Format("  Y:       ${0:X2}", _cpu.Y);
            dumpLines[7] += String.Format("  Stack P: ${0:X2}", _cpu.StackPointer);
            dumpLines[8] += String.Format("  PC:      ${0:X4}", _cpu.ProgramCounter);

            //dumpLines[12] += String.Format("  Master Freq: {0}", _masterFps);
            dumpLines[13] += String.Format("  Dots:        {0}", _ppu.RemainingDotsInFrame);

            Console.WriteLine();
            Console.WriteLine(" Zeropage:");

            foreach (string dumpLine in dumpLines)
            {
                Console.WriteLine(dumpLine);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /**
         * 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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        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);
        }