[NES] tinker around with board detection and add a UNIF warning message, but due to some severe problems with exception handling, the exceptions which make it to the GUI as messageboxes is seemingly arbitrary, so youll never know.

This commit is contained in:
zeromus 2011-03-02 06:18:26 +00:00
parent a236477c5b
commit 4bfc610a8a
4 changed files with 41 additions and 24 deletions

View File

@ -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
";
}

View File

@ -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"))

View File

@ -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)]

View File

@ -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();