EmuCores.GB.ConfigsGB LoadConfigFile( ) { try { if (!System.IO.File.Exists(Application.dataPath + "/../core_GB.cfg")) { return(new EmuCores.GB.ConfigsGB()); } string confFile = System.IO.File.ReadAllText(Application.dataPath + "/../core_GB.cfg"); EmuCores.GB.ConfigsGB confData = JsonUtility.FromJson <EmuCores.GB.ConfigsGB>(confFile); return(confData); } catch (System.Exception e) { EmuEnvironment.ShowErrorBox("GB Emu Error", "Invalid data in config file \"core_gb.cfg\"\n\n" + e.Message); if (!Application.isEditor) { Application.Quit(); return(null); } return(new EmuCores.GB.ConfigsGB()); } }
MappedButton ParseBtnCode(string aCode) { if (string.IsNullOrEmpty(aCode)) { return(new DigitalButton((int)KeyCode.None)); } // Analogic button if (aCode.StartsWith("(")) { string[] analogicParts = aCode.Substring(1, aCode.Length - 2).Split(new char[] { '|' }); if (analogicParts.Length != 3) { EmuEnvironment.ShowErrorBox("Config file error", "Invalid data found in Profile Input section: " + aCode); return(new DigitalButton((int)KeyCode.None)); } int axisNum = 0; float axisDir = 1.0f; float neutralState = 0.0f; if (!int.TryParse(analogicParts[0], out axisNum)) { EmuEnvironment.ShowErrorBox("Config file error", "Invalid data found in Profile Input section: " + aCode); return(new DigitalButton((int)KeyCode.None)); } if (!float.TryParse(analogicParts[0], out axisDir)) { EmuEnvironment.ShowErrorBox("Config file error", "Invalid data found in Profile Input section: " + aCode); return(new DigitalButton((int)KeyCode.None)); } if (!float.TryParse(analogicParts[0], out neutralState)) { EmuEnvironment.ShowErrorBox("Config file error", "Invalid data found in Profile Input section: " + aCode); return(new DigitalButton((int)KeyCode.None)); } return(new AnalogicButton(axisNum, axisDir, neutralState)); } // Digital button else { int k = (int)KeyCode.None; if (!int.TryParse(aCode, out k)) { EmuEnvironment.ShowErrorBox("Config file error", "Invalid data found in Profile Input section: " + aCode); } return(new DigitalButton(k)); } }
public void TakeScreenshot(string aFilePath) { try { byte[] png = gbDisplay.FrameBufferTexture.EncodeToPNG(); System.IO.File.WriteAllBytes(aFilePath, png); } catch (System.Exception e) { EmuEnvironment.ShowErrorBox("Screenshot saving failed", e.Message); } }
void SaveConfigFile(EmuCores.BytePusher.ConfigsBytePusher aConfigs) { try { string confFile = JsonUtility.ToJson(aConfigs, prettyPrint: true); System.IO.File.WriteAllText(Application.dataPath + "/../core_BytePusher.cfg", confFile); } catch (System.Exception e) { EmuEnvironment.ShowErrorBox("BytePusher Emu Error", e.Message); } }
void LoadBootRom( ) { // Use internal boot rom if (!m_emuGB.Configs.bootRomDMG.customEnabled || string.IsNullOrEmpty(m_emuGB.Configs.bootRomDMG.path)) { byte[] devBootROM = Resources.Load <TextAsset>("GB/DMG_CustomBootRom").bytes; // Patch Anim Type const int kAnimTypeOffset = 0x00FD; switch (m_emuGB.Configs.bootRomDMG.internalAnimType) { case 0x03: // Quick Anim devBootROM[kAnimTypeOffset] = 0x03; break; case 0xAA: // Full Anim devBootROM[kAnimTypeOffset] = 0xAA; break; default: // No Anim devBootROM[kAnimTypeOffset] = 0x00; break; } m_emuGB.SetBootRom(devBootROM); } else { try { byte[] bootROM = System.IO.File.ReadAllBytes(m_emuGB.Configs.bootRomDMG.path); if (bootROM.Length != 0x100) // 256 bytes { throw new System.ArgumentException("Invalid BootROM format. Expected " + 0x100 + " bytes.\nFound " + bootROM.Length + ". File: " + m_emuGB.Configs.bootRomDMG.path + "\nThe internal BootROM will be used."); } m_emuGB.SetBootRom(bootROM); } catch (System.Exception e) { EmuEnvironment.ShowErrorBox("GB Emu Error", "BootROM error:\n" + e.Message); // Fallback to internal boot rom byte[] devBootROM = Resources.Load <TextAsset>("GB/DMG_CustomBootRom").bytes; m_emuGB.SetBootRom(devBootROM); } } }
public override void ApplyCustomMappings(EmuCores.GB.ConfigsGB.InputProfile aProfile) { if (aProfile.inputType != "xinput") { return; } try { m_mappedButtons[(int)GBButtons.A] = new DigitalButton(int.Parse(aProfile.buttonA)); m_mappedButtons[(int)GBButtons.B] = new DigitalButton(int.Parse(aProfile.buttonB)); m_mappedButtons[(int)GBButtons.Select] = new DigitalButton(int.Parse(aProfile.buttonSelect)); m_mappedButtons[(int)GBButtons.Start] = new DigitalButton(int.Parse(aProfile.buttonStart)); } catch (System.Exception e) { EmuEnvironment.ShowErrorBox("Config file error", "Invalid data in Profile Input section: " + e.Message); } }
void LoadROM() { try { string path = EmuEnvironment.RomFilePath; byte[] romData = System.IO.File.ReadAllBytes(path); EmuCores.GB.HW.CartridgeHeader cartridgeHeader = new EmuCores.GB.HW.CartridgeHeader(romData); EmuCores.GB.HW.Cartridge cart = EmuCores.GB.HW.Cartridge.Mount(cartridgeHeader, romData); m_emuGB.LoadCart(cart); } catch (System.Exception e) { EmuEnvironment.ShowErrorBox("GB Emu Error", "Failed loading rom:\n" + e.Message); m_emuGB.LoadNoCart(); } }
void Start() { EmuCores.BytePusher.ConfigsBytePusher configsBytePusher = LoadConfigFile(); // Running direct from scene if (EmuEnvironment.EmuCore == EmuEnvironment.Cores._Unknown) { EmuEnvironment.RomFilePath = frontendConfigs.romsPath[frontendConfigs.selectedRomIndex]; OverrideConfigsWithFrontend(configsBytePusher); } emuDisplay.displayWidth = 256; emuDisplay.displayHeight = 256; emuDisplay.displayZoomFactor = configsBytePusher.graphics.displayZoom; emuDisplay.SetScreenStandard(); m_emuBytePusher = new EmuCores.BytePusher.EmuBytePusher(configsBytePusher); m_emuBytePusher.DrawDisplay = DisplayRenderer; m_emuBytePusher.PlayAudio = PlayAudio; m_emuBytePusher.UpdateInputKeys = UpdateKeys; try { byte[] romData = System.IO.File.ReadAllBytes(EmuEnvironment.RomFilePath); if (!m_emuBytePusher.LoadRom(romData)) { throw new System.ArgumentException("Invalid ROM format"); } } catch (System.Exception e) { EmuEnvironment.ShowErrorBox("BytePusher Emu Error", "Failed loading rom:\n" + e.Message); Application.Quit(); } SaveConfigFile(configsBytePusher); }
static public IEnumerable <byte> EnvGetMemoryDatas(EmuEnvironment env, ushort segment, ushort offset, int length) => EnvGetMemoryDatas(env, segment, offset).Take(length);
/// Mem ///////////////////////////////////// static public IEnumerable <byte> EnvGetMemoryDatas(EmuEnvironment env, ushort segment, ushort offset) { var addr = GetMemoryAddr(segment, offset).addr; return(env.OneMegaMemory_.Skip((int)addr)); }