7800: integrate the existing emu7800 gamedb as a core-private gamedb (not unlike bootgod), and use that to drive decision making. emu7800 should now be able to correctly load 7800PAL and 2600 games.

This commit is contained in:
goyuken 2012-12-12 03:40:18 +00:00
parent fb7873a6a7
commit f32fc83d96
8 changed files with 2486 additions and 14 deletions

View File

@ -214,6 +214,8 @@
<Compile Include="Consoles\Atari\7800\EMU7800\TIA.cs" />
<Compile Include="Consoles\Atari\7800\EMU7800\TIASound.cs" />
<Compile Include="Consoles\Atari\7800\EMU7800\TIATables.cs" />
<Compile Include="Consoles\Atari\7800\GameProgram.cs" />
<Compile Include="Consoles\Atari\7800\GameProgramLibrary.cs" />
<Compile Include="Consoles\Calculator\TI83.cs" />
<Compile Include="Consoles\Coleco\ColecoVision.cs" />
<Compile Include="Consoles\Coleco\Input.cs" />

View File

@ -10,10 +10,13 @@ namespace BizHawk
partial class Atari7800
{
public byte[] rom;
Bios7800 NTSC_BIOS;
Bios7800 PAL_BIOS;
//Bios7800 NTSC_BIOS;
//Bios7800 PAL_BIOS;
public byte[] hsbios;
public byte[] bios;
Cart cart;
Machine7800NTSC theMachine; //TODO: PAL support
MachineBase theMachine;
EMU7800.Win.GameProgram GameInfo;
}
}

View File

@ -124,10 +124,19 @@ namespace BizHawk
}
}
public Atari7800(CoreComm comm, GameInfo game, byte[] rom, byte[] ntsc_bios, byte[] pal_bios, byte[] highscoreBIOS)
public Atari7800(CoreComm comm, GameInfo game, byte[] rom, byte[] ntsc_bios, byte[] pal_bios, byte[] highscoreBIOS, string GameDBfn)
{
CoreComm = comm;
if (EMU7800.Win.GameProgramLibrary.EMU7800DB == null)
{
EMU7800.Win.GameProgramLibrary.EMU7800DB = new EMU7800.Win.GameProgramLibrary(new StreamReader(GameDBfn));
}
GameInfo = EMU7800.Win.GameProgramLibrary.EMU7800DB.TryRecognizeRom(rom);
CoreComm.RomStatusDetails = GameInfo.ToString();
Console.WriteLine("Rom Determiniation from 7800DB:");
Console.WriteLine(GameInfo.ToString());
//TODO: store both the ntsc bios and the pal bios
var domains = new List<MemoryDomain>(1);
domains.Add(new MemoryDomain("Main RAM", 1, Endian.Little, addr => 0xFF, null)); //TODO
@ -135,8 +144,7 @@ namespace BizHawk
this.rom = rom;
this.game = game;
this.hsbios = highscoreBIOS;
NTSC_BIOS = new Bios7800(ntsc_bios);
PAL_BIOS = new Bios7800(pal_bios);
this.bios = GameInfo.MachineType == MachineType.A7800PAL ? pal_bios : ntsc_bios;
HardReset();
}
@ -144,27 +152,42 @@ namespace BizHawk
{
_lagcount = 0;
// show mapper class on romstatusdetails
/*
CoreComm.RomStatusDetails =
string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\nMapper Impl \"{3}\"",
game.Name,
Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(rom)),
Util.BytesToHexString(System.Security.Cryptography.MD5.Create().ComputeHash(rom)),
"TODO");
"TODO");*/
cart = Cart.Create(rom, CartType.A7848); //TODO: mapper selection system
cart = Cart.Create(rom, GameInfo.CartType);
int[] bob = new int[] { 0, 0, 0 };
//int[] bob = new int[] { 0, 0, 0 };
//FileStream fs = new FileStream("C:\\dummy", FileMode.Create, FileAccess.ReadWrite); //TODO: I don't see what this context is used for, see if it can be whacked or pass in a null
//BinaryReader blah = new BinaryReader(fs);
//DeserializationContext george = new DeserializationContext(blah);
ILogger logger = new ConsoleLogger();
HSC7800 hsc7800 = new HSC7800(hsbios, new byte[2048]); //TODO: why should I have to feed it ram? how much?
theMachine = new Machine7800NTSC(cart, NTSC_BIOS, hsc7800, logger);
Bios7800 bios7800 = new Bios7800(bios);
theMachine = MachineBase.Create
(GameInfo.MachineType,
cart,
bios7800,
hsc7800,
GameInfo.LController,
GameInfo.RController,
logger);
//theMachine = new Machine7800NTSC(cart, null, null, logger);
//TODO: clean up, the hs and bios are passed in, the bios has an object AND byte array in the core, and naming is inconsistent
theMachine.Reset();
if (avProvider != null)
avProvider.Dispose();
avProvider = new MyAVProvider(theMachine);
// to sync exactly with audio as this emulator creates and times it, the frame rate should be exactly 60:1 or 50:1
CoreComm.VsyncNum = theMachine.FrameHZ;
CoreComm.VsyncDen = 1;
}
void SyncState(Serializer ser) //TODO

View File

@ -0,0 +1,76 @@
/*
* GameProgram.cs
*
* Represents attribute data associated with ROMs
*
* Copyright 2003, 2004, 2010 © Mike Murphy
*
*/
/*
* unlike EMU7800 Core stuff, this has been hacked around a bit
*/
using System.Text;
using EMU7800.Core;
namespace EMU7800.Win
{
public class GameProgram
{
public string MD5 { get; set; }
public string Title { get; set; }
public string Manufacturer { get; set; }
public string Author { get; set; }
public string Year { get; set; }
public string ModelNo { get; set; }
public string Rarity { get; set; }
public CartType CartType { get; set; }
public MachineType MachineType { get; set; }
public Controller LController { get; set; }
public Controller RController { get; set; }
public string HelpUri { get; set; }
public string DiscoveredRomFullName { get; set; }
public override string ToString()
{
var s = new StringBuilder("GameSettings:\n");
s.AppendFormat(" MD5: {0}\n", MD5);
s.AppendFormat(" Title: {0}\n", Title);
s.AppendFormat(" Manufacturer: {0}\n", Manufacturer);
s.AppendFormat(" Author: {0}\n", Author);
s.AppendFormat(" Year: {0}\n", Year);
s.AppendFormat(" ModelNo: {0}\n", ModelNo);
s.AppendFormat(" Rarity: {0}\n", Rarity);
s.AppendFormat(" CartType: {0}\n", CartType);
s.AppendFormat(" MachineType: {0}\n", MachineType);
s.AppendFormat(" LController: {0}\n", LController);
s.AppendFormat(" RController: {0}\n", RController);
s.AppendFormat(" HelpUri: {0}", HelpUri);
if (DiscoveredRomFullName != null) s.AppendFormat("\n Discovered Rom Filename: {0}", DiscoveredRomFullName);
return s.ToString();
}
public GameProgram(string md5)
{
MD5 = md5;
}
/// <summary>
/// not in db, so guess
/// </summary>
/// <param name="md5"></param>
/// <returns></returns>
public static GameProgram GetCompleteGuess(string md5)
{
GameProgram ret = new GameProgram(md5);
ret.Title = "UNKNOWN";
//ret.CartType = CartType.A7848; // will be guessed for us
ret.MachineType = MachineType.A7800NTSC;
ret.LController = Controller.Joystick;
ret.RController = Controller.Joystick;
return ret;
}
}
}

View File

@ -0,0 +1,383 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using EMU7800.Core;
/*
* unlike EMU7800 Core stuff, this has been hacked around significantly
*/
namespace EMU7800.Win
{
public class GameProgramLibrary : Dictionary<string, GameProgram>
{
#region Fields
const string
BIOS78_NTSC_MD5 = "0763f1ffb006ddbe32e52d497ee848ae",
BIOS78_NTSC_ALTERNATE_MD5 = "b32526ea179dc9ab9b2e5f8a2662b298",
BIOS78_PAL_MD5 = "397bb566584be7b9764e7a68974c4263",
HSC78_MD5 = "c8a73288ab97226c52602204ab894286";
/*
readonly IDictionary<string, string> _misc7800DiscoveredRoms = new Dictionary<string, string>();
*/
// these enums are used for matching column names in the .csv file
enum Column
{
None,
MD5,
Title,
Manufacturer,
Author,
Year,
ModelNo,
Rarity,
CartType,
MachineType,
LController,
RController,
HelpUri
};
//const string RomPropertiesFileName = "ROMProperties.csv";
static readonly Dictionary<Column, int> _columnPositions = new Dictionary<Column, int>
{
{ Column.MD5, -1},
{ Column.Title, -1},
{ Column.Manufacturer, -1},
{ Column.Author, -1 },
{ Column.Year, - 1},
{ Column.ModelNo, -1},
{ Column.Rarity, -1},
{ Column.CartType, -1},
{ Column.MachineType, -1},
{ Column.LController, -1},
{ Column.RController, -1},
{ Column.HelpUri, -1},
};
//readonly RomFileAccessor _romFileAccessor = new RomFileAccessor();
readonly MD5CryptoServiceProvider _cryptoProvider = new MD5CryptoServiceProvider();
readonly StringBuilder _sb = new StringBuilder();
//readonly ILogger _logger;
#endregion
public static GameProgramLibrary EMU7800DB = null;
#region Constructors
private GameProgramLibrary()
{
}
public GameProgramLibrary(TextReader r)//, ILogger logger)
{
//if (logger == null)
// throw new ArgumentNullException("logger");
//_logger = logger;
//var settings = new GlobalSettings(logger);
//var fn = Path.Combine(settings.BaseDirectory, RomPropertiesFileName);
Clear();
//StreamReader r = null;
try
{
//r = new StreamReader(fn);
InitializeColumnPos(r.ReadLine());
while (true)
{
var line = r.ReadLine();
if (line == null)
break;
var gp = CreateGameSettingsFromLine(line);
if (gp == null)
continue;
if (ContainsKey(gp.MD5))
Console.WriteLine("7800DB: Duplicate MD5 key found: {0}", gp.MD5); else Add(gp.MD5, gp);
}
r.Close();
}
catch (Exception ex)
{
//if (Util.IsCriticalException(ex))
throw;
//_logger.WriteLine(ex);
}
finally
{
if (r != null)
r.Dispose();
}
Console.WriteLine("7800DB: {0} entries loaded.", Count);
}
#endregion
#region Game Program Accessors
public GameProgram TryRecognizeRom(byte[] bytes)
{
//if (string.IsNullOrWhiteSpace(fullName))
// throw new ArgumentException("fullName");
//var bytes = _romFileAccessor.GetRomBytes(fullName);
if (bytes == null)
return null;
var md5 = ComputeMD5Digest(bytes);
if (string.IsNullOrWhiteSpace(md5))
return null;
var gp = GetGameProgramFromMd5(md5);
if (gp == null)
gp = GameProgram.GetCompleteGuess(md5);
//gp.DiscoveredRomFullName = fullName;
if (gp.CartType == CartType.None)
{
switch (gp.MachineType)
{
case MachineType.A2600NTSC:
case MachineType.A2600PAL:
switch (bytes.Length)
{
case 2048: gp.CartType = CartType.A2K; break;
case 4096: gp.CartType = CartType.A4K; break;
case 8192: gp.CartType = CartType.A8K; break;
case 16384: gp.CartType = CartType.A16K; break;
}
break;
case MachineType.A7800NTSC:
case MachineType.A7800PAL:
switch (bytes.Length)
{
case 8192: gp.CartType = CartType.A7808; break;
case 16384: gp.CartType = CartType.A7816; break;
case 32768: gp.CartType = CartType.A7832; break;
case 49152: gp.CartType = CartType.A7848; break;
}
break;
}
}
return gp;
/*
if (md5.Equals(HSC78_MD5, StringComparison.OrdinalIgnoreCase))
{
if (!_misc7800DiscoveredRoms.ContainsKey(md5))
_misc7800DiscoveredRoms.Add(md5, fullName);
_logger.WriteLine("Found 7800 Highscore Cart: {0}", fullName);
return null;
}
if (md5.Equals(BIOS78_NTSC_MD5, StringComparison.OrdinalIgnoreCase))
{
if (!_misc7800DiscoveredRoms.ContainsKey(md5))
_misc7800DiscoveredRoms.Add(md5, fullName);
_logger.WriteLine("Found 7800 NTSC BIOS: {0}", fullName);
return null;
}
if (md5.Equals(BIOS78_NTSC_ALTERNATE_MD5, StringComparison.OrdinalIgnoreCase))
{
if (!_misc7800DiscoveredRoms.ContainsKey(md5))
_misc7800DiscoveredRoms.Add(md5, fullName);
_logger.WriteLine("Found incorrect but widely used 7800 NTSC BIOS: {0}", fullName);
return null;
}
if (md5.Equals(BIOS78_PAL_MD5, StringComparison.OrdinalIgnoreCase))
{
if (!_misc7800DiscoveredRoms.ContainsKey(md5))
_misc7800DiscoveredRoms.Add(md5, fullName);
_logger.WriteLine("Found 7800 PAL BIOS: {0}", fullName);
return null;
}
*/
}
/*
public GameProgram GetGameProgramFromFullName(string fullName)
{
var bytes = _romFileAccessor.GetRomBytes(fullName);
if (bytes == null)
throw new ArgumentException("File not readable: {0}", fullName);
var md5 = ComputeMD5Digest(bytes);
return !string.IsNullOrWhiteSpace(md5) ? GetGameProgramFromMd5(md5) : null;
}
*/
public GameProgram GetGameProgramFromMd5(string md5)
{
if (string.IsNullOrWhiteSpace(md5))
throw new ArgumentNullException("md5");
GameProgram gp;
return TryGetValue(md5, out gp) ? gp : null;
}
/*
public byte[] GetRomBytes(string fullName)
{
return _romFileAccessor.GetRomBytes(fullName);
}
public byte[] Get78HighScoreCartBytes()
{
string fullName;
if (!_misc7800DiscoveredRoms.TryGetValue(HSC78_MD5, out fullName))
return null;
return _romFileAccessor.GetRomBytes(fullName);
}
public byte[] Get78BiosBytes(MachineType machineType)
{
string fullName = null;
switch (machineType)
{
case MachineType.A7800NTSC:
if (!_misc7800DiscoveredRoms.TryGetValue(BIOS78_NTSC_MD5, out fullName))
_misc7800DiscoveredRoms.TryGetValue(BIOS78_NTSC_ALTERNATE_MD5, out fullName);
break;
case MachineType.A7800PAL:
_misc7800DiscoveredRoms.TryGetValue(BIOS78_PAL_MD5, out fullName);
break;
}
if (string.IsNullOrWhiteSpace(fullName))
return null;
return _romFileAccessor.GetRomBytes(fullName);
}*/
#endregion
#region Game Progam Related Utilities
/*
public string ComputeMD5Digest(string fullName)
{
var bytes = _romFileAccessor.GetRomBytes(fullName);
if (bytes == null)
throw new ArgumentException("File not readable: {0}", fullName);
return ComputeMD5Digest(bytes);
}
*/
#endregion
#region Helpers
static void InitializeColumnPos(string line)
{
var colno = 0;
var columnNames = line.Split(',');
foreach (var columnName in columnNames)
{
var col = ToColumn(columnName);
if (col != Column.None)
_columnPositions[col] = colno;
colno++;
}
if (_columnPositions[Column.MD5] < 0)
throw new ApplicationException("ROMProperties.csv: Required column missing: MD5");
if (_columnPositions[Column.CartType] < 0)
throw new ApplicationException("ROMProperties.csv: Required column missing: CartType");
if (_columnPositions[Column.MachineType] < 0)
throw new ApplicationException("ROMProperties.csv: Required column missing: MachineType");
if (_columnPositions[Column.LController] < 0)
throw new ApplicationException("ROMProperties.csv: Required column missing: LController");
if (_columnPositions[Column.RController] < 0)
throw new ApplicationException("ROMProperties.csv: Required column missing: RController");
}
static GameProgram CreateGameSettingsFromLine(string line)
{
var row = new string[13];
var linesplit = line.Split(',');
for (var i = 0; i < row.Length && i < linesplit.Length; i++)
row[i] = linesplit[i];
var md5 = row[_columnPositions[Column.MD5]];
var gp = new GameProgram(md5)
{
Title = _columnPositions[Column.Title] >= 0 ? row[_columnPositions[Column.Title]] : string.Empty,
Manufacturer = _columnPositions[Column.Manufacturer] >= 0 ? row[_columnPositions[Column.Manufacturer]] : string.Empty,
Author = _columnPositions[Column.Author] >= 0 ? row[_columnPositions[Column.Author]] : string.Empty,
Year = _columnPositions[Column.Year] >= 0 ? row[_columnPositions[Column.Year]] : string.Empty,
ModelNo = _columnPositions[Column.ModelNo] >= 0 ? row[_columnPositions[Column.ModelNo]] : string.Empty,
Rarity = _columnPositions[Column.Rarity] >= 0 ? row[_columnPositions[Column.Rarity]] : string.Empty,
CartType = ToCartType(row[_columnPositions[Column.CartType]]),
MachineType = ToMachineType(row[_columnPositions[Column.MachineType]])
};
gp.LController = ToController(row[_columnPositions[Column.LController]]);
gp.RController = ToController(row[_columnPositions[Column.RController]]);
if (gp.LController == Controller.None)
gp.LController = GetDefaultController(gp.MachineType);
if (gp.RController == Controller.None)
gp.RController = GetDefaultController(gp.MachineType);
if (_columnPositions[Column.HelpUri] < row.Length)
{
var helpUri = row[_columnPositions[Column.HelpUri]].Trim();
if (!helpUri.Length.Equals(0))
gp.HelpUri = helpUri;
}
return gp;
}
static Controller GetDefaultController(MachineType machineType)
{
switch (machineType)
{
case MachineType.A7800NTSC:
case MachineType.A7800PAL:
return Controller.ProLineJoystick;
default:
return Controller.Joystick;
}
}
static Column ToColumn(string columnName)
{
Column result;
return Enum.TryParse(columnName, true, out result) ? result : Column.None;
}
static CartType ToCartType(string cartType)
{
CartType result;
return Enum.TryParse(cartType, true, out result) ? result : CartType.None;
}
static MachineType ToMachineType(string machineType)
{
MachineType result;
return Enum.TryParse(machineType, true, out result) ? result : MachineType.None;
}
static Controller ToController(string controller)
{
Controller result;
return Enum.TryParse(controller, true, out result) ? result : Controller.None;
}
string ComputeMD5Digest(byte[] bytes)
{
return (bytes != null) ? StringifyMD5(_cryptoProvider.ComputeHash(bytes)) : null;
}
string StringifyMD5(byte[] bytes)
{
if (bytes == null || bytes.Length < 16)
return string.Empty;
_sb.Length = 0;
for (var i = 0; i < 16; i++)
_sb.AppendFormat("{0:x2}", bytes[i]);
return _sb.ToString();
}
#endregion
}
}

View File

@ -48,8 +48,15 @@ namespace BizHawk.MultiClient
StringBuilder sbLog = new StringBuilder();
public void Append(string str)
{
Lines.Add(str);
virtualListView1.ItemCount++;
var ss = str.Split('\n');
foreach (var s in ss)
{
if (!string.IsNullOrWhiteSpace(s))
{
Lines.Add(s);
virtualListView1.ItemCount++;
}
}
}
private void btnClear_Click(object sender, EventArgs e)

View File

@ -1905,7 +1905,9 @@ namespace BizHawk.MultiClient
byte[] PAL_BIOS7800 = File.ReadAllBytes(pal_biospath);
byte[] HighScoreBIOS = File.ReadAllBytes(hsbiospath);
Atari7800 a78 = new Atari7800(nextComm, game, rom.RomData, NTSC_BIOS7800, PAL_BIOS7800, HighScoreBIOS);
string gamedbpath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "EMU7800.csv");
Atari7800 a78 = new Atari7800(nextComm, game, rom.RomData, NTSC_BIOS7800, PAL_BIOS7800, HighScoreBIOS, gamedbpath);
nextEmulator = a78;
break;
case "C64":

File diff suppressed because it is too large Load Diff