Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
    public VIC2(Texture2D screenTexture, RAM64K ram)
    {
        _screenTexture = screenTexture;
        _ram           = ram;
        _pixels        = new Color[320 * 200];

        for (int i = 0; i < 320 * 200; ++i)
        {
            _pixels[i] = _palette[0];
        }

        UpdateTexture();
    }
Exemplo n.º 3
0
    public SID(RAM64K ram)
    {
        _ram = ram;
        for (int i = 0; i < 3; ++i)
        {
            _channels.Add(new SIDChannel());
        }
        _channels[0].syncTarget = _channels[1];
        _channels[1].syncTarget = _channels[2];
        _channels[2].syncTarget = _channels[0];
        _channels[0].syncSource = _channels[2];
        _channels[1].syncSource = _channels[0];
        _channels[2].syncSource = _channels[1];

        _cyclesPerSample = (63f * 312f * 50f) / AudioSettings.outputSampleRate;
        _cutoffRatio     = -2f * Mathf.PI * (18000f / 256f) / AudioSettings.outputSampleRate; // 6581 filter
    }
Exemplo n.º 4
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();
    }
Exemplo n.º 5
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);
                 * }
                 */
            }
        }