private void TurnOn() { if (_backend != null) { return; } var buffers = new Buffers(UnityEngine.SystemInfo.SupportsTextureFormat(TextureFormat.RGB565)); _backend = new Backend(buffers); _backend.On(Rom.bytes); var w = Convert.ToInt32(Backend.SystemAvInfo.geometry.base_width); var h = Convert.ToInt32(Backend.SystemAvInfo.geometry.base_height); Texture = new Texture2D(w, h, buffers.VideoSupport16Bit ? TextureFormat.RGB565 : TextureFormat.RGB24, false) { filterMode = FilterMode.Point }; Display.material.mainTexture = Texture; AudioSource.clip = AudioClip.Create(name, buffers.AudioBufferSize / 2, 2, 44100, true, OnAudioRead); AudioSource.playOnAwake = false; AudioSource.spatialBlend = 0; AudioSource.loop = true; Bridges.SetupExternalInput(); }
public void SaveState(string filepath) { var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(Buffers.StateBuffer, 0); Bridges.retro_serialize(ptr, Buffers.StateBufferSize); using (var file = File.OpenWrite(filepath)) file.Write(Buffers.StateBuffer, 0, Buffers.StateBuffer.Length); }
public void LoadState(string filepath) { using (var file = File.OpenRead(filepath)) file.Read(Buffers.StateBuffer, 0, Buffers.StateBuffer.Length); var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(Buffers.StateBuffer, 0); Bridges.retro_unserialize(ptr, Buffers.StateBufferSize); }
private void SaveMemory(string filepath, uint memoryType) { var size = Bridges.retro_get_memory_size(memoryType); var ptr = Bridges.retro_get_memory_data(memoryType); if (size <= 0) { return; } var bytes = new byte[size]; Marshal.Copy(ptr, bytes, 0, (int)size); using (var file = File.OpenWrite(filepath)) file.Write(bytes, 0, (int)size); }
public unsafe void LoadGame(byte[] bytes) { if (bytes == null || bytes.Length == 0) { return; } var offset = (0x400 << bytes[0x7FD7] == bytes.Length) ? 0x7000 : 0xF000; RomHeader = new RomHeader { GameTitle = System.Text.Encoding.GetEncoding("iso-2022-jp").GetString(bytes, offset | 0xFC0, 21).Trim(), RomType = bytes[offset | 0xFD6], RomSize = 0x400 << bytes[offset | 0xFD7], SaveRamSize = 0x400 << bytes[offset | 0xFD8], CountryCode = bytes[offset | 0xFD9], License = bytes[offset | 0xFDA], Version = bytes[offset | 0xFDB] }; var arrayPointer = Marshal.AllocHGlobal(bytes.Length * Marshal.SizeOf(typeof(byte))); Marshal.Copy(bytes, 0, arrayPointer, bytes.Length); GameInfo = new GameInfo { path = (char *)Marshal.StringToHGlobalUni(Path.Combine(Buffers.TemporaryDataPath, "temp.bytes")).ToPointer(), size = (uint)bytes.Length, data = arrayPointer.ToPointer() }; Bridges.retro_unload_game(); if (!Bridges.retro_load_game(ref GameInfo)) { throw new ArgumentException(); } SystemAvInfo = new SystemAvInfo(); Bridges.retro_get_system_av_info(ref SystemAvInfo); Buffers.SetSystemAvInfo(SystemAvInfo); Buffers.SetStateSize(Bridges.retro_serialize_size()); }
private void LoadMemory(string filepath, uint memoryType) { if (!File.Exists(filepath)) { return; } var size = Bridges.retro_get_memory_size(memoryType); var ptr = Bridges.retro_get_memory_data(memoryType); if (size <= 0) { return; } var bytes = new byte[size]; using (var file = File.OpenRead(filepath)) file.Read(bytes, 0, (int)size); Marshal.Copy(bytes, 0, ptr, (int)size); }
public unsafe void Init() { _environment = RetroEnvironment; _videoRefresh = RetroVideoRefresh; _audioSample = RetroAudioSample; _audioSampleBatch = RetroAudioSampleBatch; _inputPoll = RetroInputPoll; _inputState = RetroInputState; _controllerPortDevide = RetroControllerPortDevide; SystemInfo = new SystemInfo(); Bridges.retro_get_system_info(ref SystemInfo); Bridges.retro_set_environment(_environment); Bridges.retro_set_video_refresh(_videoRefresh); Bridges.retro_set_audio_sample(_audioSample); Bridges.retro_set_audio_sample_batch(_audioSampleBatch); Bridges.retro_set_input_poll(_inputPoll); Bridges.retro_set_input_state(_inputState); Bridges.retro_set_controller_port_device(_controllerPortDevide); Bridges.retro_init(); }
private unsafe void LoadGame(byte[] bytes) { var arrayPointer = Marshal.AllocHGlobal(bytes.Length * Marshal.SizeOf(typeof(byte))); Marshal.Copy(bytes, 0, arrayPointer, bytes.Length); GameInfo = new GameInfo { path = (char *)Marshal.StringToHGlobalUni(Path.GetTempFileName()).ToPointer(), size = (uint)bytes.Length, data = arrayPointer.ToPointer() }; if (!Bridges.retro_load_game(ref GameInfo)) { throw new ArgumentException(); } SystemAvInfo = new SystemAvInfo(); Bridges.retro_get_system_av_info(ref SystemAvInfo); Buffers.SetSystemAvInfo(SystemAvInfo); Buffers.SetStateSize(Bridges.retro_serialize_size()); }
public void TurnOn(string filename = "") { if (_backend != null) { return; } var buffers = new Buffers() { VideoSupport16Bit = UnityEngine.SystemInfo.SupportsTextureFormat(TextureFormat.RGB565), SystemDirectory = Application.persistentDataPath, PersistentDataPath = Application.persistentDataPath, TemporaryDataPath = Application.temporaryCachePath, StreamingAssets = Application.streamingAssetsPath }; _backend = new Backend(buffers); _backend.Init(); _backend.LoadGame(GetRom(filename)); _backend.LoadSram(GetSramFilePaths()); _backend.LoadRtc(GetRtcFilePaths()); Debug.Log($"load game: {Backend.RomHeader.GameTitle}"); _texture = new Texture2D(buffers.VideoUnitSize, buffers.VideoUnitSize, buffers.VideoSupport16Bit ? TextureFormat.RGB565 : TextureFormat.RGBA32, false) { filterMode = FilterMode.Point }; InputMapper = new InputMapper(); InputMapper.SetKeyAsICade(); Display.material.mainTexture = _texture; AudioSource.clip = AudioClip.Create(name, buffers.AudioBufferSize / 2, 2, 44100, true, OnAudioRead); AudioSource.playOnAwake = false; AudioSource.spatialBlend = 0; AudioSource.loop = true; Bridges.SetupExternalInput(); }
private static void RetroEnvironmentShutdown() { Bridges.retro_unload_game(); Bridges.retro_deinit(); }
public void Reset() { Bridges.retro_reset(); }
public void Loop() { Bridges.retro_run(); }
public void DeInit() { Bridges.retro_unload_game(); Bridges.retro_deinit(); }