示例#1
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            cpu.State.A.Value = cpu.State.Y.Value;

            cpu.State.P.Zero     = cpu.State.A.IsZero;
            cpu.State.P.Negative = cpu.State.A.IsNegative;
        }
示例#2
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte mem = cpu.Target.Read();
            byte a = cpu.State.A.Value;
            int tmp = 0, vCheck = 0;

            if (cpu.State.P.Decimal)
            {
                tmp = (a & 0x0f) + (mem & 0x0f) + cpu.State.P.CarryValue;
                if (tmp > 0x09)
                    tmp += 0x06;

                tmp += (a & 0xf0) + (mem & 0xf0);
                vCheck = tmp;

                if ((tmp & 0x1f0) > 0x90)
                    tmp += 0x60;

                cpu.State.P.Carry = (tmp & 0xff0) > 0xf0;
            }
            else
            {
                vCheck = tmp = a + mem + cpu.State.P.CarryValue;
                cpu.State.P.Carry = (tmp & 0xff00) != 0;
            }

            cpu.State.A.Value = (byte)tmp;

            cpu.State.P.Overflow = ((a ^ mem) & 0x80) == 0 && ((a ^ vCheck) & 0x80) != 0; //(mem & 0x80) == (a & 0x80) && (vCheck  & 0x80) != (a & 0x80);
            cpu.State.P.Zero = cpu.State.A.IsZero;
            cpu.State.P.Negative = cpu.State.A.IsNegative;

            if (cpu.Target.IsPageCrossed(cpu.State.PC.Value))
                clock.Prolong(pageCrossProlong, cpu.Phase);
        }
示例#3
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 0)
     {
         cpu.Memory.Write(cpu.State.S.Value, cpu.State.PC.PCH);
         cpu.State.S.Value--;
     }
     else if (cycle == 1)
     {
         cpu.Memory.Write(cpu.State.S.Value, cpu.State.PC.PCL);
         cpu.State.S.Value--;
     }
     else if (cycle == 2)
     {
         cpu.Memory.Write(cpu.State.S.Value, cpu.State.P.Value);
         cpu.State.S.Value--;
     }
     else if (cycle == 3)
     {
         cpu.Result = cpu.Memory.Read(0xfffe);
     }
     else if (cycle == 4)
     {
         cpu.State.PC.Value   = (ushort)((cpu.Memory.Read(0xffff) << 8) | cpu.Result);
         cpu.State.P.BreakCmd = true;
     }
 }
示例#4
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            int tmp = cpu.State.Y.Value - cpu.Target.Read();

            cpu.State.P.Carry    = (tmp & 0xff00) == 0;
            cpu.State.P.Zero     = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#5
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 1)
     {
         cpu.Memory.Write(cpu.State.S.Value, cpu.State.P.Value);
         cpu.State.S.Value--;
     }
 }
示例#6
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 0)
     {
         cpu.State.S.Value++;
         cpu.State.P.Value = cpu.Memory.Read(cpu.State.S.Value);
     }
 }
示例#7
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte mem = cpu.Target.Read();
            int  tmp = cpu.State.A.Value & mem;

            cpu.State.P.Zero     = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (mem & 0x80) != 0;
            cpu.State.P.Overflow = (mem & 0x40) != 0;
        }
示例#8
0
        void Run()
        {
            _ram = new RAM64K();
            _cpu = new MOS6502(_ram);

            _updateThread = new Thread(Updater);
            _updateThread.Start();

            Console.Clear();
            Console.CursorVisible = false;
            Console.WriteLine("6502 Test Suite");
            Console.WriteLine("---------------\n");

            /*
             * _ram.Write(0x1000, 0x58); //CLI
             * _ram.Write(0x1001, 0xF8); //SED
             * _ram.Write(0x1002, 0x18); //CLC
             * _ram.Write(0x1003, 0xA9); //LDA
             * _ram.Write(0x1004, 0x99); //    #$99
             * _ram.Write(0x1005, 0x69); //ADC
             * _ram.Write(0x1006, 0x01); //    #$01
             *
             * _ram.Write16(0xFFFC, 0x1000); //RESET
             * _cpu.Reset();
             *
             * //Display = true;
             * while (_cpu.PC != 0x1007)
             * {
             *  _cpu.Process();
             *  Console.WriteLine(_cpu.Opcode.ToString("X2"));
             * }
             * UpdateDisplay();
             * //Display = false;
             */
            if (!TestQuick())
            {
                goto END;
            }
            if (!TestFull())
            {
                goto END;
            }
            if (!TestDecimalQuick())
            {
                goto END;
            }
            if (!TestDecimalFull())
            {
                goto END;
            }

END:
            _updateThread.Abort();
            Console.WriteLine("\nPress any key to exit...");
            Console.CursorVisible = true;
            Console.ReadKey();
        }
示例#9
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte tmp = (byte)(cpu.Target.Read() + 1);

            cpu.Result = tmp;

            cpu.State.P.Zero     = tmp == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#10
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            cpu.State.A.Value &= cpu.Target.Read();

            cpu.State.P.Zero = cpu.State.A.IsZero;
            cpu.State.P.Negative = cpu.State.A.IsNegative;

            if (cpu.Target.IsPageCrossed(cpu.State.PC.Value))
                clock.Prolong(pageCrossProlong, cpu.Phase);
        }
示例#11
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            cpu.State.A.Value &= cpu.Target.Read();

            cpu.State.P.Zero     = cpu.State.A.IsZero;
            cpu.State.P.Negative = cpu.State.A.IsNegative;

            if (cpu.Target.IsPageCrossed(cpu.State.PC.Value))
            {
                clock.Prolong(pageCrossProlong, cpu.Phase);
            }
        }
示例#12
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte value = cpu.Target.Read();

            cpu.State.P.Carry = (value & 0x01) != 0;

            value    >>= 1;
            cpu.Result = value;

            cpu.State.P.Zero     = (value & 0xff) == 0;
            cpu.State.P.Negative = (value & 0x80) != 0;
        }
示例#13
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte carry = cpu.State.P.CarryValue;

            int tmp = (cpu.Target.Read() << 1) | carry;

            cpu.Result = (byte)tmp;

            cpu.State.P.Carry    = (tmp & 0xff00) != 0;
            cpu.State.P.Zero     = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#14
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            uint tmp = (uint)(cpu.State.A.Value - cpu.Target.Read());

            cpu.State.P.Carry    = (tmp & 0xff00) == 0;
            cpu.State.P.Zero     = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;

            if (cpu.Target.IsPageCrossed(cpu.State.PC.Value))
            {
                clock.Prolong(pageCrossProlong, cpu.Phase);
            }
        }
示例#15
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 1)
     {
         cpu.State.S.Value++;
         cpu.Result = cpu.Memory.Read(cpu.State.S.Value);
     }
     else if (cycle == 2)
     {
         cpu.State.S.Value++;
         cpu.State.PC.Value = (ushort)((cpu.Result | (cpu.Memory.Read(cpu.State.S.Value) << 8)) + 1);
     }
 }
示例#16
0
        void ISystemBase.setupBase()
        {
            // inititalize system components
            m_cpu = new MOS6502();

            if (m_bLoadHELLO)
            {
                m_cpu.installRAMBank(60); // memory needs to go up to EFFF
            }
            else
            {
                m_cpu.installRAMBank(8);
            }

            m_pia = new MC6820("PIA", m_cpu, 0xD010);

            // note: Apple 1 has no interrupt lines connected
            m_pia.OutputB = receiveDsp;

            // setup display
            m_VideoInfo            = new VideoInfoStruct();
            m_VideoInfo.Rows       = 24;
            m_VideoInfo.Cols       = 40;
            m_VideoInfo.CharHeight = 8;
            m_VideoInfo.CharWidth  = 8;
            m_VideoInfo.FontColor  = Color.Green;
            m_VideoInfo.BackColor  = Color.Black;

            m_iCursorX = m_iCursorY = 0;

            m_ScreenBuffer = new char[m_VideoInfo.Rows][];
            for (int r = 0; r < m_VideoInfo.Rows; r++)
            {
                m_ScreenBuffer[r] = new char[m_VideoInfo.Cols];
                for (int c = 0; c < m_VideoInfo.Cols; c++)
                {
                    m_ScreenBuffer[r][c] = ' ';
                }
            }
            m_bNeedRefresh = false;

            m_DisplayQueue = new Queue <byte>(10);

            // setup keyboard
            m_keymap = Apple1KeyMapFactory.Build("DE");

            // load ROMs
            loadROMs();

            m_cpu.Reset();
        }
示例#17
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte carry = cpu.State.P.CarryValue;

            byte tmp = cpu.Target.Read();

            cpu.State.P.Carry = (tmp & 0x01) != 0;

            tmp        = (byte)((tmp >> 1) | (carry << 7));
            cpu.Result = (byte)tmp;

            cpu.State.P.Zero     = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#18
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 0)
     {
         cpu.Memory.Write(cpu.State.S.Value, (byte)((cpu.State.PC.Value - 1) >> 8));
         cpu.State.S.Value--;
     }
     else if (cycle == 1)
     {
         cpu.Memory.Write(cpu.State.S.Value, (byte)((cpu.State.PC.Value - 1)));
         cpu.State.S.Value--;
     }
     else
     {
         cpu.State.PC.Value = cpu.Target.Address;
     }
 }
示例#19
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte prolong = 0;

            if (cpu.State.P.Overflow)
            {
                prolong++;
                ushort newAddress = cpu.Target.Address;
                if ((newAddress & 0xff00) != (cpu.State.PC.Value & 0xff00))
                {
                    prolong++;
                }

                cpu.State.PC.Value = newAddress;
            }

            clock.Prolong(prolong, cpu.Phase);
        }
示例#20
0
    void Awake()
    {
        _screenTexture         = new Texture2D(320, 200, TextureFormat.RGB24, false);
        _ram                   = new RAM64K();
        _ram.ioRead           += HandleIORead;
        _ram.ioWrite          += HandleIOWrite;
        _processor             = new MOS6502(_ram);
        _processor.kernalTrap += HandleKernalTrap;
        _vic2                  = new VIC2(_screenTexture, _ram);
        _sid                   = new SID(_ram);

        _screenTexture.wrapMode = TextureWrapMode.Clamp;
        screenRect.sprite       = Sprite.Create(_screenTexture, new Rect(0, 0, _screenTexture.width, _screenTexture.height), new Vector2(0.5f, 0.5f));
        screenRect.material.SetTexture("_MainTex", _screenTexture);
        screenRect.transform.localScale = new Vector2(1f, -1f);

        InitMemory();
        BootGame();
    }
示例#21
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte mem = cpu.Target.Read();
            byte a = cpu.State.A.Value;
            int  tmp = 0, vCheck = 0;

            if (cpu.State.P.Decimal)
            {
                tmp = (a & 0x0f) + (mem & 0x0f) + cpu.State.P.CarryValue;
                if (tmp > 0x09)
                {
                    tmp += 0x06;
                }

                tmp   += (a & 0xf0) + (mem & 0xf0);
                vCheck = tmp;

                if ((tmp & 0x1f0) > 0x90)
                {
                    tmp += 0x60;
                }

                cpu.State.P.Carry = (tmp & 0xff0) > 0xf0;
            }
            else
            {
                vCheck            = tmp = a + mem + cpu.State.P.CarryValue;
                cpu.State.P.Carry = (tmp & 0xff00) != 0;
            }

            cpu.State.A.Value = (byte)tmp;

            cpu.State.P.Overflow = ((a ^ mem) & 0x80) == 0 && ((a ^ vCheck) & 0x80) != 0;             //(mem & 0x80) == (a & 0x80) && (vCheck  & 0x80) != (a & 0x80);
            cpu.State.P.Zero     = cpu.State.A.IsZero;
            cpu.State.P.Negative = cpu.State.A.IsNegative;

            if (cpu.Target.IsPageCrossed(cpu.State.PC.Value))
            {
                clock.Prolong(pageCrossProlong, cpu.Phase);
            }
        }
示例#22
0
        void ISystemBase.setupBase()
        {
            // inititalize system components
            m_cpu = new MOS6502();

            m_cpu.installRAMBank(64);

            m_cpu.registerMemoryAccess(0xF001, readDsp, writeDsp);
            m_cpu.registerMemoryAccess(0xF004, readKbd, writeKbd);

            // setup display
            m_VideoInfo            = new VideoInfoStruct();
            m_VideoInfo.Rows       = 25;
            m_VideoInfo.Cols       = 40;
            m_VideoInfo.CharHeight = 8;
            m_VideoInfo.CharWidth  = 8;
            m_VideoInfo.FontColor  = Color.Orange;
            m_VideoInfo.BackColor  = Color.Black;

            m_iCursorX     = m_iCursorY = 0;
            m_ScreenBuffer = new char[m_VideoInfo.Rows][];
            for (int r = 0; r < m_VideoInfo.Rows; r++)
            {
                m_ScreenBuffer[r] = new char[m_VideoInfo.Cols];
                for (int c = 0; c < m_VideoInfo.Cols; c++)
                {
                    m_ScreenBuffer[r][c] = ' ';
                }
            }
            m_bNeedRefresh = false;

            m_DisplayQueue  = new Queue <byte>(10);
            m_KeyboardQueue = new Queue <byte>(5);

            // load ROMs
            loadROMs();

            m_cpu.Reset();
        }
示例#23
0
        void ISystemBase.setupBase()
        {
            // inititalize system components
            m_cpu = new MOS6502();
            m_cpu.installRAMBank(32);
            RAMextension ram = new RAMextension(m_cpu, 0xE800, 2); // for BASIC v2

            m_pia1 = new MOS6520("PIA1", m_cpu, 0xE810);
            m_pia2 = new MOS6520("PIA2", m_cpu, 0xE820);
            m_via  = new MOS6522("VIA", m_cpu, 0xE840);

            // set I/O and interupt lines
            m_pia1.OutputA       = receive_PIA1_A;
            m_pia1.InterruptLine = m_cpu.signalInterrupt;
            m_pia2.InterruptLine = m_cpu.signalInterrupt;
            m_via.InterruptLine  = m_cpu.signalInterrupt;

            initKeyboard();

            // setup display
            m_VideoInfo            = new VideoInfoStruct();
            m_VideoInfo.Rows       = 25;
            m_VideoInfo.Cols       = 40;
            m_VideoInfo.CharHeight = 8;
            m_VideoInfo.CharWidth  = 8;
            m_VideoInfo.FontColor  = Color.Green;
            m_VideoInfo.BackColor  = Color.Black;


            // setup screen buffer
            m_ScreenBuffer = new byte[0x0800];
            m_cpu.registerMemoryAccess(0x8000, 0x8800, read, write);

            // load ROMs
            loadROMs();

            m_cpu.Reset();
        }
示例#24
0
        /// <summary>
        /// test MOS6502
        /// http://codegolf.stackexchange.com/questions/12844/emulate-a-mos-6502-cpu
        /// </summary>
        public void MOS6502_AllSuiteA()
        {
            MOS6502 cpu = new MOS6502();

            cpu.installRAMBank(64);

            cpu.loadProgram("ROMs\\MOS6502_AllSuiteA.bin", 0x4000);

            // point reset vector to test routine
            cpu.writeMemByte(0xFFFC, 0x00);
            cpu.writeMemByte(0xFFFD, 0x40);

            cpu.Reset();

            cpu.Flag_B = true;

            cpu.runUntil(0x45C0);

            byte bResult = cpu.readMemByte(0x0210);

            Assert.AreEqual(0xFF, bResult);
            Assert.AreEqual(0x45C0, cpu.PC);
        }
示例#25
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte mem = cpu.Target.Read();
            byte a = cpu.State.A.Value;
            int  tmp = 0, vCheck = 0;

            if (cpu.State.P.Decimal)
            {
                tmp = (a & 0x0f) - (mem & 0x0f) - (1 - cpu.State.P.CarryValue);
                tmp = (tmp & 0x10) != 0 ? ((tmp - 6) & 0x0f) | ((a & 0xf0) - (mem & 0xf0) - 0x10) : tmp | ((a & 0xf0) - (mem & 0xf0));

                vCheck = tmp;

                if ((tmp & 0xff00) != 0)
                {
                    tmp -= 0x60;
                }

                cpu.State.P.Carry = (tmp & 0xff00) == 0;
            }
            else
            {
                vCheck            = tmp = a - mem - (1 - cpu.State.P.CarryValue);
                cpu.State.P.Carry = (tmp & 0xff00) == 0;
            }

            cpu.State.A.Value = (byte)tmp;

            cpu.State.P.Overflow = ((a ^ mem) & 0x80) != 0 && ((a ^ vCheck) & 0x80) != 0;             //(mem & 0x80) != (a & 0x80) && (tmp & 0x80) != (a & 0x80);
            cpu.State.P.Zero     = cpu.State.A.IsZero;
            cpu.State.P.Negative = cpu.State.A.IsNegative;

            if (cpu.Target.IsPageCrossed(cpu.State.PC.Value))
            {
                clock.Prolong(pageCrossProlong, cpu.Phase);
            }
        }
示例#26
0
 public MOS6502_OpFactory(MOS6502 cpu)
 {
     _cpu = cpu;
 }
示例#27
0
 public ResetOp(MOS6502 cpu)
 {
     _cpu = cpu;
 }
示例#28
0
 public ExecuteOpcodeOp(MOS6502 cpu, C64Interfaces.IFile stateFile)
     : this(cpu, null, stateFile.ReadByte())
 {
     _instruction = DecodingTable.Opcodes[cpu.Opcode]._instruction;
 }
示例#29
0
 public InterruptOp(MOS6502 cpu, C64Interfaces.IFile stateFile)
     : this(cpu, stateFile.ReadWord())
 {
     _readBuffer = stateFile.ReadByte();
 }
示例#30
0
        internal MOS6502 AttachCPU()
        {
            _cpu = new MOS6502(CPU_Read, CPU_Write);

            return(_cpu);
        }
示例#31
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.State.P.IrqMask = true;
 }
示例#32
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
 }
示例#33
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.State.P.Overflow = false;
 }
示例#34
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte prolong = 0;
            if (cpu.State.P.Overflow)
            {
                prolong++;
                ushort newAddress = cpu.Target.Address;
                if ((newAddress & 0xff00) != (cpu.State.PC.Value & 0xff00))
                    prolong++;

                cpu.State.PC.Value = newAddress;
            }

            clock.Prolong(prolong, cpu.Phase);
        }
示例#35
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 1)
     {
         cpu.Memory.Write(cpu.State.S.Value, cpu.State.P.Value);
         cpu.State.S.Value--;
     }
 }
示例#36
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.State.PC.Value = cpu.Target.Address;
 }
示例#37
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 0)
     {
         cpu.State.S.Value++;
         cpu.State.P.Value = cpu.Memory.Read(cpu.State.S.Value);
     }
 }
示例#38
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.State.P.Overflow = false;
 }
示例#39
0
 public WriteResultOp(MOS6502 cpu)
 {
     _cpu = cpu;
 }
示例#40
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
 }
示例#41
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.State.PC.Value = cpu.Target.Address;
     clock.Halt();
 }
示例#42
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte value = cpu.Target.Read();

            cpu.State.P.Carry = (value & 0x01) != 0;

            value >>= 1;
            cpu.Result = value;

            cpu.State.P.Zero = (value & 0xff) == 0;
            cpu.State.P.Negative = (value & 0x80) != 0;
        }
示例#43
0
        void Run()
        {
            _ram = new RAM64K();
            _cpu = new MOS6502(_ram);

            Console.Title           = "6502";
            Console.BackgroundColor = (ConsoleColor)6;
            Console.ForegroundColor = (ConsoleColor)14;
            Console.SetWindowSize(40, 26);
            Console.SetBufferSize(40, 26);
            Console.CursorSize = 100;

            //TestB();
            //return;

            //_ram.Write(0x0000, 0x2F);
            //_ram.Write(0x0001, 0x37);

            //_ram.Write(0xD018, 21);

            using (FileStream file = new FileStream("BASIC.ROM", FileMode.Open, FileAccess.Read))
                _ram.Load(file, 0xA000, 8192);

            using (FileStream file = new FileStream("CHAR.ROM", FileMode.Open, FileAccess.Read))
                _ram.Load(file, 0xD000, 4096);

            using (FileStream file = new FileStream("KERNAL.ROM", FileMode.Open, FileAccess.Read))
                _ram.Load(file, 0xE000, 8192);

            byte[] screenbuffer = new byte[1000];

            byte raster = 0;

            while (true)
            {
                _cpu.Process();
                //Console.WriteLine(cpu.PC.ToString("X4"));
                _ram.Write(0xD012, raster);
                raster++;// if (raster == 312) raster = 0;
                //Console.Clear();
                if (_cpu.Cycles % 10000 == 0)
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo key = Console.ReadKey(true);
                        _ram.Write16(0xDC00, (ushort)key.Key);
                    }
                    else
                    {
                        _ram.Write16(0xDC00, 0x0);
                    }

                    //Console.Title = _cpu.PC.ToString("X4");
                    Console.Title = _ram.Read16(0xDC00).ToString();

                    // Address where the C64 character screen buffer is located
                    ushort screenAddress = (ushort)(_ram[0x0288] << 8);

                    for (ushort i = 0; i < 1000; i++)
                    {
                        byte data = _ram.Read((ushort)(i + screenAddress));
                        if (data < 0x20)
                        {
                            data += 0x40;
                        }
                        //data &= 0x7F; // Reverse
                        if (data != screenbuffer[i])
                        {
                            Console.CursorVisible = false;
                            if ((data & 0x80) != 0)
                            {
                                Console.BackgroundColor = (ConsoleColor)14;
                                Console.ForegroundColor = (ConsoleColor)6;
                            }
                            Console.SetCursorPosition(i % 40, i / 40);
                            Console.Write((char)(data));
                            if ((data & 0x80) != 0)
                            {
                                Console.BackgroundColor = (ConsoleColor)6;
                                Console.ForegroundColor = (ConsoleColor)14;
                            }
                        }
                        screenbuffer[i] = data;
                    }
                    if (_ram[0x00CC] == 0) // Draw cursor when visible
                    {
                        int x = _ram[0x00CA];
                        int y = _ram[0x00C9];
                        if (Console.CursorLeft != x || Console.CursorTop != y)
                        {
                            Console.SetCursorPosition(x, y);
                        }
                        if (!Console.CursorVisible)
                        {
                            Console.CursorVisible = true;
                        }
                    }
                }
                //System.Threading.Thread.Sleep(50);

                /*
                 * cpu.Op();
                 * Console.WriteLine("test00: " + ram.Read(0x022A).ToString("X2"));
                 * Console.WriteLine("test01: " + ram.Read(0xA9).ToString("X2"));
                 * Console.WriteLine("test02: " + ram.Read(0x71).ToString("X2"));
                 * System.Threading.Thread.Sleep(50);
                 * if (cpu.PC == 0x45C0)
                 * {
                 *
                 *  Console.WriteLine("FINAL: " + ram.Read(0x0210).ToString("X2"));
                 *  System.Threading.Thread.Sleep(50);
                 * }
                 */
            }
        }
示例#44
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 0)
     {
         cpu.Memory.Write(cpu.State.S.Value, (byte)((cpu.State.PC.Value - 1) >> 8));
         cpu.State.S.Value--;
     }
     else if (cycle == 1)
     {
         cpu.Memory.Write(cpu.State.S.Value, (byte)((cpu.State.PC.Value - 1)));
         cpu.State.S.Value--;
     }
     else
         cpu.State.PC.Value = cpu.Target.Address;
 }
示例#45
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     if (cycle == 1)
     {
         cpu.State.S.Value++;
         cpu.Result = cpu.Memory.Read(cpu.State.S.Value);
     }
     else if (cycle == 2)
     {
         cpu.State.S.Value++;
         cpu.State.PC.Value = (ushort)((cpu.Result | (cpu.Memory.Read(cpu.State.S.Value) << 8)) + 1);
     }
 }
示例#46
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte tmp = (byte)(cpu.Target.Read() + 1);
            cpu.Result = tmp;

            cpu.State.P.Zero = tmp == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#47
0
 public ExecuteOpcodeOp(MOS6502 cpu, Instruction instruction, byte pageCrossProlong)
 {
     _cpu = cpu;
     _instruction = instruction;
     _pageCrossProlong = pageCrossProlong;
 }
示例#48
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            int tmp = cpu.State.Y.Value - cpu.Target.Read();

            cpu.State.P.Carry = (tmp & 0xff00) == 0;
            cpu.State.P.Zero = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#49
0
 public InterruptOp(MOS6502 cpu, ushort isrPointer)
 {
     _cpu = cpu;
     _isrPointer = isrPointer;
 }
示例#50
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte carry = cpu.State.P.CarryValue;

            byte tmp = cpu.Target.Read();

            cpu.State.P.Carry = (tmp & 0x01) != 0;

            tmp = (byte)((tmp >> 1) | (carry << 7));
            cpu.Result = (byte)tmp;

            cpu.State.P.Zero = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#51
0
 public DecodeAddressOp(MOS6502 cpu, AddressingMode addressing)
 {
     _cpu = cpu;
     _addressing = addressing;
 }
示例#52
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            cpu.State.Y.Value = cpu.State.A.Value;

            cpu.State.P.Zero = cpu.State.Y.IsZero;
            cpu.State.P.Negative = cpu.State.Y.IsNegative;
        }
示例#53
0
 public DecodeAddressOp(MOS6502 cpu, C64Interfaces.IFile stateFile)
     : this(cpu, (AddressingMode)null)
 {
     _addressing = DecodingTable.Opcodes[cpu.Opcode]._addressing;
 }
示例#54
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.State.S.Value = cpu.State.X.Value;
 }
示例#55
0
 public ResetOp(MOS6502 cpu, C64Interfaces.IFile stateFile)
     : this(cpu)
 {
     _readBuffer = stateFile.ReadByte();
 }
示例#56
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            uint tmp = (uint)(cpu.State.A.Value - cpu.Target.Read());

            cpu.State.P.Carry = (tmp & 0xff00) == 0;
            cpu.State.P.Zero = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;

            if (cpu.Target.IsPageCrossed(cpu.State.PC.Value))
                clock.Prolong(pageCrossProlong, cpu.Phase);
        }
示例#57
0
 public DecodeOpcodeOp(MOS6502 cpu)
 {
     _cpu = cpu;
 }
示例#58
0
        public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
        {
            byte carry = cpu.State.P.CarryValue;

            int tmp = (cpu.Target.Read() << 1) | carry;
            cpu.Result = (byte)tmp;

            cpu.State.P.Carry = (tmp & 0xff00) != 0;
            cpu.State.P.Zero = (tmp & 0xff) == 0;
            cpu.State.P.Negative = (tmp & 0x80) != 0;
        }
示例#59
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.State.P.IrqMask = true;
 }
示例#60
0
 public virtual void Execute(Clock.Clock clock, MOS6502 cpu, byte pageCrossProlong, byte cycle)
 {
     cpu.Result = cpu.State.Y.Value;
 }