diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index d6050867be..860612dc7b 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; namespace BizHawk.Emulation.Consoles.Nintendo.SNES { + //TODO - wrap around some kind of library-accessing interface so that it doesnt malfunction if the dll is unavailable public unsafe static class LibsnesDll { [DllImport("snes.dll", CallingConvention = CallingConvention.Cdecl)] @@ -52,6 +53,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES [DllImport("snes.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void snes_set_audio_sample(snes_audio_sample_t audio_sample); + [DllImport("snes.dll", CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool snes_check_cartridge( + [MarshalAs(UnmanagedType.LPArray)] byte[] rom_data, + int rom_size); + public enum Device : uint { None, diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 3fb30fb5f1..c60c8e0e4d 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1309,20 +1309,31 @@ namespace BizHawk.MultiClient rom = new RomGame(file); game = rom.GameInfo; + //use some heuristics to figure out what game type it might be if (game.NotInDatabase) { - //try to load based on extension - switch (file.Extension.ToUpper()) + //try asking the snes core + if (LibsnesDll.snes_check_cartridge(rom.FileData, rom.FileData.Length)) + game.System = "SNES"; + else { - case ".SMC": - nextEmulator = new BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesCore(rom.FileData); - game.System = "SNES"; - break; + //try and use the extension + switch (file.Extension.ToUpper()) + { + case ".SFC": + case ".SMC": + game.System = "SNES"; + break; + } } } switch (game.System) { + case "SNES": + nextEmulator = new LibsnesCore(rom.FileData); + game.System = "SNES"; + break; case "SMS": case "SG": if (Global.Config.SmsEnableFM) game.AddOption("UseFM"); @@ -1380,10 +1391,10 @@ namespace BizHawk.MultiClient SMS c = new SMS(game, rom.RomData);//new ColecoVision(game, rom.FileData); nextEmulator = c; break; - case "INTV": - Intellivision intv = new Intellivision(game, rom.RomData); - nextEmulator = intv; - break; + case "INTV": + Intellivision intv = new Intellivision(game, rom.RomData); + nextEmulator = intv; + break; } } diff --git a/BizHawk.MultiClient/output/snes.dll b/BizHawk.MultiClient/output/snes.dll index 8285f85a1d..70ce922b53 100644 Binary files a/BizHawk.MultiClient/output/snes.dll and b/BizHawk.MultiClient/output/snes.dll differ diff --git a/libsnes/bsnes/target-libsnes/libsnes.cpp b/libsnes/bsnes/target-libsnes/libsnes.cpp index 54ec814cdf..b725e1225e 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.cpp +++ b/libsnes/bsnes/target-libsnes/libsnes.cpp @@ -209,6 +209,14 @@ void snes_cheat_set(unsigned index, bool enable, const char *code) { SNES::cheat.synchronize(); } +//zeromus additions +bool snes_check_cartridge(const uint8_t *rom_data, unsigned rom_size) +{ + //tries to determine whether this rom is a snes rom + SnesCartridge temp(rom_data, rom_size); + return temp.type != SnesCartridge::TypeUnknown && temp.type != SnesCartridge::TypeGameBoy; +} + bool snes_load_cartridge_normal( const char *rom_xml, const uint8_t *rom_data, unsigned rom_size ) { diff --git a/libsnes/bsnes/target-libsnes/libsnes.hpp b/libsnes/bsnes/target-libsnes/libsnes.hpp index 30daf0a300..f7e4d1bfea 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.hpp +++ b/libsnes/bsnes/target-libsnes/libsnes.hpp @@ -128,7 +128,8 @@ bool snes_get_region(void); uint8_t* snes_get_memory_data(unsigned id); unsigned snes_get_memory_size(unsigned id); -//zeromus additions (TBD) +//zeromus additions +bool snes_check_cartridge(const uint8_t *rom_data, unsigned rom_size); #ifdef __cplusplus }