Ejemplo n.º 1
0
        public MGBAHawk(byte[] file, CoreComm comm, SyncSettings syncSettings, Settings settings, bool deterministic, GameInfo game)
        {
            _syncSettings          = syncSettings ?? new SyncSettings();
            _settings              = settings ?? new Settings();
            DeterministicEmulation = deterministic;

            var bios = comm.CoreFileProvider.GetFirmware(new("GBA", "Bios"));

            DeterministicEmulation &= bios != null;

            if (DeterministicEmulation != deterministic)
            {
                throw new MissingFirmwareException("A BIOS is required for deterministic recordings!");
            }

            if (!DeterministicEmulation && bios != null && !_syncSettings.RTCUseRealTime && !_syncSettings.SkipBios)
            {
                // in these situations, this core is deterministic even though it wasn't asked to be
                DeterministicEmulation = true;
            }

            if (bios != null && bios.Length != 16384)
            {
                throw new InvalidOperationException("BIOS must be exactly 16384 bytes!");
            }

            var skipBios = !DeterministicEmulation && _syncSettings.SkipBios;

            Core = LibmGBA.BizCreate(bios, file, file.Length, GetOverrideInfo(_syncSettings), skipBios);
            if (Core == IntPtr.Zero)
            {
                throw new InvalidOperationException($"{nameof(LibmGBA.BizCreate)}() returned NULL!  Bad BIOS? and/or ROM?");
            }

            try
            {
                CreateMemoryDomains(file.Length);
                var ser = new BasicServiceProvider(this);
                ser.Register <IDisassemblable>(new ArmV4Disassembler());
                ser.Register <IMemoryDomains>(_memoryDomains);

                ServiceProvider = ser;
                PutSettings(_settings);

                const string TRACE_HEADER = "ARM7: PC, machine code, mnemonic, operands, registers";
                Tracer   = new TraceBuffer(TRACE_HEADER);
                _tracecb = msg => Tracer.Put(_traceInfo(msg));
                ser.Register(Tracer);
                MemoryCallbacks = new MGBAMemoryCallbackSystem(this);
            }
            catch
            {
                LibmGBA.BizDestroy(Core);
                throw;
            }

            InputCallback = new LibmGBA.InputCallback(InputCb);
            LibmGBA.BizSetInputCallback(Core, InputCallback);
        }