Exemplo n.º 1
0
        public VBANext(byte[] romfile, CoreComm nextComm)
        {
            CoreComm = nextComm;
            byte[] biosfile = CoreComm.CoreFileProvider.GetFirmware("GBA", "Bios", true, "GBA bios file is mandatory.");

            if (romfile.Length > 32 * 1024 * 1024)
            {
                throw new ArgumentException("ROM is too big to be a GBA ROM!");
            }
            if (biosfile.Length != 16 * 1024)
            {
                throw new ArgumentException("BIOS file is not exactly 16K!");
            }

            Core = LibVBANext.Create();
            if (Core == IntPtr.Zero)
            {
                throw new InvalidOperationException("Create() returned nullptr!");
            }
            try
            {
                if (!LibVBANext.LoadRom(Core, romfile, (uint)romfile.Length, biosfile, (uint)biosfile.Length))
                {
                    throw new InvalidOperationException("LoadRom() returned false!");
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Exemplo n.º 2
0
        public VBANext(byte[] file, CoreComm comm, GameInfo game, bool deterministic, object syncsettings)
        {
            var ser = new BasicServiceProvider(this);

            ser.Register <IDisassemblable>(new ArmV4Disassembler());
            ServiceProvider = ser;

            CoreComm = comm;

            byte[] biosfile = CoreComm.CoreFileProvider.GetFirmware("GBA", "Bios", true, "GBA bios file is mandatory.");
            if (file.Length > 32 * 1024 * 1024)
            {
                throw new ArgumentException("ROM is too big to be a GBA ROM!");
            }
            if (biosfile.Length != 16 * 1024)
            {
                throw new ArgumentException("BIOS file is not exactly 16K!");
            }

            LibVBANext.FrontEndSettings FES = new LibVBANext.FrontEndSettings();
            FES.saveType        = (LibVBANext.FrontEndSettings.SaveType)game.GetInt("saveType", 0);
            FES.flashSize       = (LibVBANext.FrontEndSettings.FlashSize)game.GetInt("flashSize", 0x10000);
            FES.enableRtc       = game.GetInt("rtcEnabled", 0) != 0;
            FES.mirroringEnable = game.GetInt("mirroringEnabled", 0) != 0;

            Console.WriteLine("GameDB loaded settings: saveType={0}, flashSize={1}, rtcEnabled={2}, mirroringEnabled={3}",
                              FES.saveType, FES.flashSize, FES.enableRtc, FES.mirroringEnable);

            _syncSettings          = (SyncSettings)syncsettings ?? new SyncSettings();
            DeterministicEmulation = deterministic;

            FES.skipBios       = _syncSettings.SkipBios;
            FES.RTCUseRealTime = _syncSettings.RTCUseRealTime;
            FES.RTCwday        = (int)_syncSettings.RTCInitialDay;
            FES.RTCyear        = _syncSettings.RTCInitialTime.Year % 100;
            FES.RTCmonth       = _syncSettings.RTCInitialTime.Month - 1;
            FES.RTCmday        = _syncSettings.RTCInitialTime.Day;
            FES.RTChour        = _syncSettings.RTCInitialTime.Hour;
            FES.RTCmin         = _syncSettings.RTCInitialTime.Minute;
            FES.RTCsec         = _syncSettings.RTCInitialTime.Second;
            if (DeterministicEmulation)
            {
                // FES.skipBios = false; // this is OK; it is deterministic and probably accurate
                FES.RTCUseRealTime = false;
            }

            Core = LibVBANext.Create();
            if (Core == IntPtr.Zero)
            {
                throw new InvalidOperationException("Create() returned nullptr!");
            }
            try
            {
                if (!LibVBANext.LoadRom(Core, file, (uint)file.Length, biosfile, (uint)biosfile.Length, FES))
                {
                    throw new InvalidOperationException("LoadRom() returned false!");
                }

                Tracer = new TraceBuffer();
                ser.Register <ITraceable>(Tracer);

                CoreComm.VsyncNum      = 262144;
                CoreComm.VsyncDen      = 4389;
                CoreComm.NominalWidth  = 240;
                CoreComm.NominalHeight = 160;

                GameCode = Encoding.ASCII.GetString(file, 0xac, 4);
                Console.WriteLine("Game code \"{0}\"", GameCode);

                savebuff  = new byte[LibVBANext.BinStateSize(Core)];
                savebuff2 = new byte[savebuff.Length + 13];
                InitMemoryDomains();
                InitRegisters();
                InitCallbacks();

                // todo: hook me up as a setting
                SetupColors();
            }
            catch
            {
                Dispose();
                throw;
            }
        }