public unsafe void Setup() { ScreenTexture = new Texture2D(256, 240, TextureFormat.BGRA32, false); ScreenTexture.wrapMode = TextureWrapMode.Mirror; LibRetro.retro_set_environment(environment_callback); log("set_environment"); LibRetro.retro_set_video_refresh(video_refresh_callback); log("set_video_refresh"); LibRetro.retro_set_audio_sample_batch(audio_sample_batch_callback); log("set_audio_sample_batch"); LibRetro.retro_set_input_poll(input_poll_callback); LibRetro.retro_set_input_state(input_state_callback); LibRetro.retro_init(); log("retro_init"); string path = Path.Combine(Application.persistentDataPath, "castle.nes"); byte[] rom = System.IO.File.ReadAllBytes(path); LibRetro.retro_game_info gameInfo = new LibRetro.retro_game_info { path = path, data = rom, size = (UInt64)rom.Length, meta = new byte[0] }; if (LibRetro.retro_load_game(gameInfo) == 0) { Debug.LogError("Load failed"); } }
public void SaveState() { var len = LibRetro.retro_serialize_size(); var buf = new byte[len]; if (!LibRetro.retro_serialize(buf, len)) { throw new Exception("Serialize failed"); } File.WriteAllBytes(savePath(), buf); Debug.Log($"save len={len}"); }
public void RunOneFrame() { Profiler.BeginSample("retro_run"); LibRetro.retro_run(); Profiler.EndSample(); //Debug.Log("retru_run"); // Clear inputs. for (int i = 0; i < KeyInputs.Length; i++) { KeyInputs[i] = 0; } }
public void LoadState() { if (!File.Exists(savePath())) { return; } var len = LibRetro.retro_serialize_size(); var buf = File.ReadAllBytes(savePath()); if (!LibRetro.retro_unserialize(buf, len)) { throw new Exception("Unserialize failed"); } Debug.Log($"load len={len}"); }
public void ResetMachine() { LibRetro.retro_reset(); }