diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardDetector.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardDetector.cs index 280351f4f3..c8b0998706 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardDetector.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardDetector.cs @@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo { public static string Detect(RomInfo romInfo) { - string key = string.Format("{0} {1} {2}",romInfo.MapperNumber,romInfo.PRG_Size,romInfo.CHR_Size); + string key = string.Format("{0} {1} {2} {3}",romInfo.MapperNumber,romInfo.PRG_Size,romInfo.CHR_Size,romInfo.PRAM_Size); string board; Table.TryGetValue(key, out board); return board; @@ -30,27 +30,31 @@ namespace BizHawk.Emulation.Consoles.Nintendo while ((line = sr.ReadLine()) != null) { var parts = line.Split('\t'); - if (parts.Length < 4) continue; - line = line.Replace(parts[3],""); - line = line.TrimEnd('\t'); - Table[line] = parts[3]; + if (parts.Length < 5) continue; + string key = parts[0] + "\t" + parts[1] + "\t" + parts[2] + "\t" + parts[3]; + string board = line.Replace(key, ""); + board = board.TrimStart('\t'); + if (board.IndexOf(';') != -1) + board = board.Substring(0, board.IndexOf(';')); + Table[key] = board; } } -//MAP PRG CHR BOARD +//MAP PRG CHR PRAM BOARD static string ClassifyTable = @" -0 1 1 NROM -0 2 1 NROM -2 8 0 UNROM -2 16 0 UOROM -3 2 2 CNROM -3 2 4 CNROM -7 8 0 ANROM -7 16 0 AOROM -11 4 2 Discrete_74x377 -11 2 4 Discrete_74x377 -13 2 0 CPROM -66 4 2 GxROM -66 8 4 GxROM +0 1 1 0 NROM +0 2 1 0 NROM +1 8 0 8 SNROM; this handles zelda, +2 8 0 0 UNROM +2 16 0 0 UOROM +3 2 2 0 CNROM +3 2 4 0 CNROM +7 8 0 0 ANROM +7 16 0 0 AOROM +11 4 2 0 Discrete_74x377 +11 2 4 0 Discrete_74x377 +13 2 0 0 CPROM +66 4 2 0 GxROM +66 8 4 0 GxROM "; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index 86e5d2b399..988e9ef446 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Diagnostics; using System.Globalization; using System.IO; @@ -20,12 +21,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo //the main rom class that contains all information necessary for the board to operate public class RomInfo { - public enum EHeaderType + public enum EInfoSource { - None, INes + None, INesHeader, GameDatabase } - public EHeaderType HeaderType; + public EInfoSource InfoSource; public int PRG_Size = -1, CHR_Size = -1; public int CRAM_Size = -1, PRAM_Size = -1; public string BoardName; @@ -587,12 +588,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo } } + //turning this off probably doesnt work right now due to asserts in boards finding things set by the iNES header parsing + //need to separate those fields const bool ENABLE_DB = true; public unsafe void LoadGame(IGame game) { byte[] file = game.GetFileData(); - if (file.Length < 16) throw new InvalidOperationException("Alleged NES rom too small to be anything useful"); + if (file.Length < 16) throw new Exception("Alleged NES rom too small to be anything useful"); + if (file.Take(4).SequenceEqual(System.Text.Encoding.ASCII.GetBytes("UNIF"))) + throw new Exception("You've tried to open a UNIF rom. We don't have any UNIF roms to test with. Please consult the developers."); fixed (byte* bfile = &file[0]) { var header = (iNES_HEADER*)bfile; @@ -620,11 +625,13 @@ namespace BizHawk.Emulation.Consoles.Nintendo throw new InvalidOperationException("Couldn't detect board type"); romInfo.BoardName = board; Console.WriteLine("board detected as " + board); + romInfo.InfoSource = RomInfo.EInfoSource.INesHeader; } else { Console.WriteLine("found game in database: {0}", gi.Name); romInfo = new RomInfo(); + romInfo.InfoSource = RomInfo.EInfoSource.GameDatabase; romInfo.MD5 = hash; var dict = gi.ParseOptionsDictionary(); if (dict.ContainsKey("board")) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index ec9a75a804..72cb123edf 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -419,6 +419,11 @@ namespace BizHawk.MultiClient break; } + if (Global.Emulator is NullEmulator) + { + throw new Exception(); + } + Global.Emulator.LoadGame(game); Text = DisplayNameForSystem(game.System) + " - " + game.Name; ResetRewindBuffer(); @@ -474,6 +479,7 @@ namespace BizHawk.MultiClient writer.Write(Global.Emulator.SaveRam, 0, len); writer.Close(); } + Global.Emulator = new NullEmulator(); } [System.Security.SuppressUnmanagedCodeSecurity, DllImport("User32.dll", CharSet = CharSet.Auto)] diff --git a/BizHawk.MultiClient/Program.cs b/BizHawk.MultiClient/Program.cs index 45bfaaaf1e..0625cb9c22 100644 --- a/BizHawk.MultiClient/Program.cs +++ b/BizHawk.MultiClient/Program.cs @@ -29,7 +29,7 @@ namespace BizHawk.MultiClient mf.Show(); mf.ProgramRunLoop(); } catch (Exception e) { - MessageBox.Show(e.ToString(), "Oh, no, a terrible thing happened!"); + MessageBox.Show(e.ToString(), "Oh, no, a terrible thing happened!\n\n" + e.ToString()); } finally { if (Global.DSound != null && Global.DSound.Disposed == false) Global.DSound.Dispose();