Esempio n. 1
0
        public PutSettingsDirtyBits PutSyncSettings(GBSyncSettings o)
        {
            bool ret = GBSyncSettings.NeedsReboot(_syncSettings, o);

            _syncSettings = o;
            return(ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None);
        }
Esempio n. 2
0
        public bool PutSyncSettings(GBSyncSettings o)
        {
            bool ret = GBSyncSettings.NeedsReboot(_syncSettings, o);

            _syncSettings = o;
            return(ret);
        }
Esempio n. 3
0
        public GBHawk(CoreComm comm, GameInfo game, byte[] rom, /*string gameDbFn,*/ GBSettings settings, GBSyncSettings syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            cpu = new LR35902
            {
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                PeekMemory      = PeekMemory,
                DummyReadMemory = ReadMemory,
                OnExecFetch     = ExecFetch,
                SpeedFunc       = SpeedFunc,
                GetIntRegs      = GetIntRegs,
                SetIntRegs      = SetIntRegs
            };

            timer      = new Timer();
            audio      = new Audio();
            serialport = new SerialPort();

            _settings       = (GBSettings)settings ?? new GBSettings();
            _syncSettings   = (GBSyncSettings)syncSettings ?? new GBSyncSettings();
            _controllerDeck = new GBHawkControllerDeck(_syncSettings.Port1);

            byte[] Bios = null;

            // Load up a BIOS and initialize the correct PPU
            if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.Auto)
            {
                if (game.System == "GB")
                {
                    Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                    ppu  = new GB_PPU();
                }
                else
                {
                    Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                    ppu    = new GBC_PPU();
                    is_GBC = true;
                }
            }
            else if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.GB)
            {
                Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                ppu  = new GB_PPU();
            }
            else
            {
                Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                ppu    = new GBC_PPU();
                is_GBC = true;
            }

            if (Bios == null)
            {
                throw new MissingFirmwareException("Missing Gamboy Bios");
            }

            _bios = Bios;

            // set up IR register to off state
            if (is_GBC)
            {
                IR_mask = 0; IR_reg = 0x3E; IR_receive = 2; IR_self = 2; IR_signal = 2;
            }

            // Here we modify the BIOS if GBA mode is set (credit to ExtraTricky)
            if (is_GBC && _syncSettings.GBACGB)
            {
                for (int i = 0; i < 13; i++)
                {
                    _bios[i + 0xF3] = (byte)((GBA_override[i] + _bios[i + 0xF3]) & 0xFF);
                }
                IR_mask = 2;
            }

            // CPU needs to know about GBC status too
            cpu.is_GBC = is_GBC;

            Buffer.BlockCopy(rom, 0x100, header, 0, 0x50);

            if (is_GBC && ((header[0x43] != 0x80) && (header[0x43] != 0xC0)))
            {
                ppu = new GBC_GB_PPU();
            }

            Console.WriteLine("MD5: " + rom.HashMD5(0, rom.Length));
            Console.WriteLine("SHA1: " + rom.HashSHA1(0, rom.Length));
            _rom = rom;
            Setup_Mapper();
            if (cart_RAM != null)
            {
                cart_RAM_vbls = new byte[cart_RAM.Length];
            }

            timer.Core      = this;
            audio.Core      = this;
            ppu.Core        = this;
            serialport.Core = this;

            ser.Register <IVideoProvider>(this);
            ser.Register <ISoundProvider>(audio);
            ServiceProvider = ser;

            _settings     = (GBSettings)settings ?? new GBSettings();
            _syncSettings = (GBSyncSettings)syncSettings ?? new GBSyncSettings();

            _tracer = new TraceBuffer {
                Header = cpu.TraceHeader
            };
            ser.Register <ITraceable>(_tracer);
            ser.Register <IStatable>(new StateSerializer(SyncState));
            SetupMemoryDomains();
            cpu.SetCallbacks(ReadMemory, PeekMemory, PeekMemory, WriteMemory);
            HardReset();

            iptr0 = Marshal.AllocHGlobal(VRAM.Length + 1);
            iptr1 = Marshal.AllocHGlobal(OAM.Length + 1);
            iptr2 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1);
            iptr3 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1);

            _scanlineCallback = null;
        }
Esempio n. 4
0
 public static bool NeedsReboot(GBSyncSettings x, GBSyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 5
0
        public GBHawk(CoreComm comm, GameInfo game, byte[] rom, /*string gameDbFn,*/ GBSettings settings, GBSyncSettings syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            cpu = new LR35902
            {
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                PeekMemory      = PeekMemory,
                DummyReadMemory = ReadMemory,
                OnExecFetch     = ExecFetch,
                SpeedFunc       = SpeedFunc,
                GetButtons      = GetButtons,
                GetIntRegs      = GetIntRegs,
                SetIntRegs      = SetIntRegs
            };

            timer      = new Timer();
            audio      = new Audio();
            serialport = new SerialPort();

            _settings     = (GBSettings)settings ?? new GBSettings();
            _syncSettings = (GBSyncSettings)syncSettings ?? new GBSyncSettings();

            byte[] Bios = null;

            // Load up a BIOS and initialize the correct PPU
            if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.Auto)
            {
                if (game.System == "GB")
                {
                    Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                    ppu  = new GB_PPU();
                }
                else
                {
                    Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                    ppu    = new GBC_PPU();
                    is_GBC = true;
                }
            }
            else if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.GB)
            {
                Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                ppu  = new GB_PPU();
            }
            else
            {
                Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                ppu    = new GBC_PPU();
                is_GBC = true;
            }

            if (Bios == null)
            {
                throw new MissingFirmwareException("Missing Gamboy Bios");
            }

            _bios = Bios;

            // set up IR register to off state
            if (is_GBC)
            {
                IR_mask = 0; IR_reg = 0x3E; IR_receive = 2; IR_self = 2; IR_signal = 2;
            }

            // Here we modify the BIOS if GBA mode is set (credit to ExtraTricky)
            if (is_GBC && _syncSettings.GBACGB)
            {
                for (int i = 0; i < 13; i++)
                {
                    _bios[i + 0xF3] = (byte)((GBA_override[i] + _bios[i + 0xF3]) & 0xFF);
                }
                IR_mask = 2;
            }

            // CPU needs to know about GBC status too
            cpu.is_GBC = is_GBC;

            Buffer.BlockCopy(rom, 0x100, header, 0, 0x50);

            if (is_GBC && ((header[0x43] != 0x80) && (header[0x43] != 0xC0)))
            {
                ppu = new GBC_GB_PPU();
            }

            Console.WriteLine("MD5: " + rom.HashMD5(0, rom.Length));
            Console.WriteLine("SHA1: " + rom.HashSHA1(0, rom.Length));
            _rom = rom;
            string mppr = Setup_Mapper();

            if (cart_RAM != null)
            {
                cart_RAM_vbls = new byte[cart_RAM.Length];
            }

            if (mppr == "MBC7")
            {
                _controllerDeck = new GBHawkControllerDeck(_syncSettings.Port1);
            }
            else
            {
                _controllerDeck = new GBHawkControllerDeck(GBHawkControllerDeck.DefaultControllerName);
            }

            timer.Core      = this;
            audio.Core      = this;
            ppu.Core        = this;
            serialport.Core = this;

            ser.Register <IVideoProvider>(this);
            ser.Register <ISoundProvider>(audio);
            ServiceProvider = ser;

            _settings     = (GBSettings)settings ?? new GBSettings();
            _syncSettings = (GBSyncSettings)syncSettings ?? new GBSyncSettings();

            _tracer = new TraceBuffer {
                Header = cpu.TraceHeader
            };
            ser.Register <ITraceable>(_tracer);
            ser.Register <IStatable>(new StateSerializer(SyncState));
            SetupMemoryDomains();
            cpu.SetCallbacks(ReadMemory, PeekMemory, PeekMemory, WriteMemory);
            HardReset();

            iptr0 = Marshal.AllocHGlobal(VRAM.Length + 1);
            iptr1 = Marshal.AllocHGlobal(OAM.Length + 1);
            iptr2 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1);
            iptr3 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1);

            _scanlineCallback = null;

            for (int i = 0; i < ZP_RAM.Length; i++)
            {
                ZP_RAM[i] = 0;
            }

            if (is_GBC)
            {
                if (_syncSettings.GBACGB)
                {
                    // on GBA, initial RAM is mostly random, choosing 0 allows for stable clear and hotswap for games that encounter
                    // uninitialized RAM
                    for (int i = 0; i < RAM.Length; i++)
                    {
                        RAM[i] = 0;
                    }
                }
                else
                {
                    for (int i = 0; i < 0x800; i++)
                    {
                        if ((i & 0xF) < 8)
                        {
                            RAM[i]          = 0xFF;
                            RAM[i + 0x1000] = 0xFF;
                            RAM[i + 0x2000] = 0xFF;
                            RAM[i + 0x3000] = 0xFF;
                            RAM[i + 0x4000] = 0xFF;
                            RAM[i + 0x5000] = 0xFF;
                            RAM[i + 0x6000] = 0xFF;
                            RAM[i + 0x7000] = 0xFF;

                            RAM[i + 0x800]  = 0;
                            RAM[i + 0x1800] = 0;
                            RAM[i + 0x2800] = 0;
                            RAM[i + 0x3800] = 0;
                            RAM[i + 0x4800] = 0;
                            RAM[i + 0x5800] = 0;
                            RAM[i + 0x6800] = 0;
                            RAM[i + 0x7800] = 0;
                        }
                        else
                        {
                            RAM[i]          = 0;
                            RAM[i + 0x1000] = 0;
                            RAM[i + 0x2000] = 0;
                            RAM[i + 0x3000] = 0;
                            RAM[i + 0x4000] = 0;
                            RAM[i + 0x5000] = 0;
                            RAM[i + 0x6000] = 0;
                            RAM[i + 0x7000] = 0;

                            RAM[i + 0x800]  = 0xFF;
                            RAM[i + 0x1800] = 0xFF;
                            RAM[i + 0x2800] = 0xFF;
                            RAM[i + 0x3800] = 0xFF;
                            RAM[i + 0x4800] = 0xFF;
                            RAM[i + 0x5800] = 0xFF;
                            RAM[i + 0x6800] = 0xFF;
                            RAM[i + 0x7800] = 0xFF;
                        }
                    }

                    // some bytes are like this is Gambatte, hardware anomoly? Is it consistent across versions?

                    /*
                     * for (int i = 0; i < 16; i++)
                     * {
                     *      RAM[0xE02 + (16 * i)] = 0;
                     *      RAM[0xE0A + (16 * i)] = 0xFF;
                     *
                     *      RAM[0x1E02 + (16 * i)] = 0;
                     *      RAM[0x1E0A + (16 * i)] = 0xFF;
                     *
                     *      RAM[0x2E02 + (16 * i)] = 0;
                     *      RAM[0x2E0A + (16 * i)] = 0xFF;
                     *
                     *      RAM[0x3E02 + (16 * i)] = 0;
                     *      RAM[0x3E0A + (16 * i)] = 0xFF;
                     *
                     *      RAM[0x4E02 + (16 * i)] = 0;
                     *      RAM[0x4E0A + (16 * i)] = 0xFF;
                     *
                     *      RAM[0x5E02 + (16 * i)] = 0;
                     *      RAM[0x5E0A + (16 * i)] = 0xFF;
                     *
                     *      RAM[0x6E02 + (16 * i)] = 0;
                     *      RAM[0x6E0A + (16 * i)] = 0xFF;
                     *
                     *      RAM[0x7E02 + (16 * i)] = 0;
                     *      RAM[0x7E0A + (16 * i)] = 0xFF;
                     * }
                     */
                }
            }
            else
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int i = 0; i < 0x100; i++)
                    {
                        RAM[j * 0x1000 + i]         = 0;
                        RAM[j * 0x1000 + i + 0x100] = 0xFF;
                        RAM[j * 0x1000 + i + 0x200] = 0;
                        RAM[j * 0x1000 + i + 0x300] = 0xFF;
                        RAM[j * 0x1000 + i + 0x400] = 0;
                        RAM[j * 0x1000 + i + 0x500] = 0xFF;
                        RAM[j * 0x1000 + i + 0x600] = 0;
                        RAM[j * 0x1000 + i + 0x700] = 0xFF;
                        RAM[j * 0x1000 + i + 0x800] = 0;
                        RAM[j * 0x1000 + i + 0x900] = 0xFF;
                        RAM[j * 0x1000 + i + 0xA00] = 0;
                        RAM[j * 0x1000 + i + 0xB00] = 0xFF;
                        RAM[j * 0x1000 + i + 0xC00] = 0;
                        RAM[j * 0x1000 + i + 0xD00] = 0xFF;
                        RAM[j * 0x1000 + i + 0xE00] = 0;
                        RAM[j * 0x1000 + i + 0xF00] = 0xFF;
                    }
                }
            }
        }