public GameBoy(string biosFile, string romFile, SpeedupFlags speedupFlags = SpeedupFlags.None) { ROM = new ROM(romFile); Debug.Assert(ROM.HeaderChecksumMatches(), "Cartridge header checksum mismatch!"); Handle = Libgambatte.gambatte_create(); Debug.Assert(Libgambatte.gambatte_loadbios(Handle, biosFile, 0x900, 0x31672598) == 0, "Unable to load BIOS!"); Debug.Assert(Libgambatte.gambatte_load(Handle, romFile, LoadFlags.GbaFlag | LoadFlags.GcbMode | LoadFlags.ReadOnlySav) == 0, "Unable to load ROM!"); VideoBuffer = new byte[160 * 144 * 4]; AudioBuffer = new byte[(SamplesPerFrame + 2064) * 2 * 2]; // Stereo 16-bit samples InputGetter = () => CurrentJoypad; Libgambatte.gambatte_setinputgetter(Handle, InputGetter); string symPath = "symfiles/" + Path.GetFileNameWithoutExtension(romFile) + ".sym"; if (File.Exists(symPath)) { SYM = new SYM(symPath); ROM.Symbols = SYM; } SetSpeedupFlags(speedupFlags); StateSize = Libgambatte.gambatte_savestate(Handle, null, 160, null); SaveStateLabels = new Dictionary <string, int>(); byte[] state = SaveState(); ByteStream data = new ByteStream(state); data.Seek(3); data.Seek(data.u24be()); while (data.Position < state.Length) { string label = ""; byte character; while ((character = data.u8()) != 0x00) { label += Convert.ToChar(character); } int size = data.u24be(); SaveStateLabels[label] = (int)data.Position; data.Seek(size); } }
public GameBoy(string biosFile, string romFile, string savFile = null, SpeedupFlags speedupFlags = SpeedupFlags.None) { ROM = new ROM(romFile); Debug.Assert(ROM.HeaderChecksumMatches(), "Cartridge header checksum mismatch!"); string romName = Path.GetFileNameWithoutExtension(romFile); if (savFile == null || savFile == "") { File.Delete("roms/" + romName + ".sav"); } else { File.WriteAllBytes("roms/" + romName + ".sav", File.ReadAllBytes(savFile)); } Handle = Libgambatte.gambatte_create(); Debug.Assert(Libgambatte.gambatte_loadbios(Handle, biosFile, 0x900, 0x31672598) == 0, "Unable to load BIOS!"); Debug.Assert(Libgambatte.gambatte_load(Handle, romFile, LoadFlags.GbaFlag | LoadFlags.GcbMode | LoadFlags.ReadOnlySav) == 0, "Unable to load ROM!"); VideoBuffer = new byte[160 * 144 * 4]; AudioBuffer = new byte[(SamplesPerFrame + 2064) * 2 * 2]; // Stereo 16-bit samples InputGetter = () => CurrentJoypad; Libgambatte.gambatte_setinputgetter(Handle, InputGetter); string symPath = "symfiles/" + romName + ".sym"; if (File.Exists(symPath)) { SYM = new SYM(symPath); ROM.Symbols = SYM; } SetSpeedupFlags(speedupFlags); StateSize = Libgambatte.gambatte_savestate(Handle, null, 160, null); }