diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs index f0d739c8a3..fec3b56512 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs @@ -1,4 +1,7 @@ using BizHawk.Common; +using BizHawk.Common.BufferExtensions; +using BizHawk.Emulation.Common; +using System; namespace BizHawk.Emulation.Cores.Intellivision { @@ -6,17 +9,22 @@ namespace BizHawk.Emulation.Cores.Intellivision { private ushort[] Data = new ushort[56320]; + // There are 10 mappers Intellivision games use (not counting intellicart which is handled seperately) + // we will pick the mapper from the game DB and default to 0 + private int mapper = 0; + public void SyncState(Serializer ser) { ser.BeginSection("Cart"); - // TODO + ser.Sync("mapper", ref mapper); ser.EndSection(); } public int Parse(byte[] Rom) { + /* // TODO: Determine which loading method, if either, is correct. int index = 0; // Combine every two bytes into a word. @@ -28,9 +36,79 @@ namespace BizHawk.Emulation.Cores.Intellivision for (int index = 0; index < Rom.Length; index++) Data[index + 0x2C00] = Rom[index]; */ + + // Combine every two bytes into a word. + int index = 0; + + while (index + 1 < Rom.Length) + { + Data[(index / 2)] = (ushort)((Rom[index++] << 8) | Rom[index++]); + } + + // look up hash in gamedb to see what mapper to use + // if none found default is zero + string hash_sha1 = null; + string s_mapper = null; + hash_sha1 = "sha1:" + Rom.HashSHA1(16, Rom.Length - 16); + + var gi = Database.CheckDatabase(hash_sha1); + if (gi != null) + { + var dict = gi.GetOptionsDict(); + if (!dict.ContainsKey("board")) + throw new Exception("INTV gamedb entries must have a board identifier!"); + s_mapper = dict["board"]; + Console.WriteLine(mapper); + } + else + { + s_mapper = "0"; + } + + int.TryParse(s_mapper, out mapper); + return Rom.Length; } + public ushort? ReadCart(ushort addr) + { + switch (mapper) + { + case 0: + if (addr>=0x5000 && addr<0x6FFF) + { + return Data[addr-0x5000]; + } + else if (addr>=0xD000 && addr<0xDFFF) + { + return Data[addr - 0xB000]; + } + else if (addr>=0xF000 && addr<0xFFFF) + { + return Data[addr - 0xC000]; + } + break; + case 5: + if (addr >= 0x5000 && addr < 0x7FFF) + { + return Data[addr - 0x5000]; + } + else if (addr >= 0x9000 && addr < 0xBFFF) + { + return Data[addr - 0x6000]; + } + break; + } + + + return null; + } + + public bool WriteCart(ushort addr, ushort value) + { + return false; + } + /* public ushort? ReadCart(ushort addr) { // TODO: Check if address is RAM / ROM. @@ -153,6 +231,7 @@ namespace BizHawk.Emulation.Cores.Intellivision return null; } + public bool WriteCart(ushort addr, ushort value) { int dest; @@ -294,5 +373,6 @@ namespace BizHawk.Emulation.Cores.Intellivision } return false; } + */ } }