public void RunMachine(GameSettings gs, InputAdapter ia)
 {
     if (ia == null) {
         ia = new InputAdapter();
     }
     M = Machine.New(gs, Cart.New(gs), ia);
     M.Reset();
     new SDLHost().Run(M);
     M.Done();
 }
 public static Cart New(GameSettings gs)
 {
     BinaryReader rom = new BinaryReader(File.OpenRead(gs.FileInfo.FullName));
     rom.BaseStream.Seek(gs.Offset, SeekOrigin.Begin);
     Console.WriteLine("CartType from database : " + gs.CartType);
     if (gs.CartType == CartType.Default)
         FixCartType(gs);
     Console.WriteLine("I'm gonna use CartType " + gs.CartType);
     return Cart.New(rom, gs.CartType);
 }
 public void SetUp()
 {
     gs = new GameSettings("Bogus MD5 checksum.");
 }
 public GameSettings GetGameSettings(string md5)
 {
     if (md5 == null)
     {
         throw new ArgumentNullException("md5");
     }
     if (PropertyTable == null)
     {
         Load();
     }
     if (!PropertyTable.ContainsKey(md5))
     {
         PropertyTable[md5] = new GameSettings(md5);
     }
     return (GameSettings)PropertyTable[md5];
 }
        public void Load()
        {
            // TODO : atm we just look in the assemblies own directory, which is ok for testing...
            //string fn = Path.Combine(EMU7800App.Instance.Settings.RootDirectory, ROM_PROPERTIES_FN);
            string fn = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,ROM_PROPERTIES_FN);

            Trace.Write("Loading ");
            Trace.Write(fn);
            Trace.Write("... ");

            PropertyTable = new Hashtable();
            StreamReader r = null;
            try
            {
                r = new StreamReader(fn);
            }
            catch (Exception ex)
            {
                if (r != null)
                {
                    r.Close();
                }
                Trace.WriteLine("error");
                Trace.WriteLine(ex.Message);
                return;
            }

            string line = r.ReadLine();

            int colno = 0;
            int colMD5 = 0;
            int colTitle = 0;
            int colManufacturer = 0;
            int colYear = 0;
            int colModelNo = 0;
            int colRarity = 0;
            int colCartType = 0;
            int colMachineType = 0;
            int colLController = 0;
            int colRController = 0;
            int colHelpUri = 0;
            foreach (string colnm in line.Split(','))
            {
                switch (colnm)
                {
                    case "MD5": colMD5 = colno; break;
                    case "Title": colTitle = colno; break;
                    case "Manufacturer": colManufacturer = colno; break;
                    case "Year": colYear = colno; break;
                    case "ModelNo": colModelNo = colno; break;
                    case "Rarity": colRarity = colno; break;
                    case "CartType": colCartType = colno; break;
                    case "MachineType": colMachineType = colno; break;
                    case "LController": colLController = colno; break;
                    case "RController": colRController = colno; break;
                    case "HelpUri": colHelpUri = colno; break;
                }
                colno++;
            }

            if (colno != 11)
            {
                Trace.WriteLine("bad ROMProperties.csv file: not all columns present");
                return;
            }

            string md5;

            while (true)
            {
                line = r.ReadLine();
                if (line == null)
                {
                    break;
                }

                string[] row = line.Split(',');
                md5 = row[colMD5];

                GameSettings gs = new GameSettings(md5);
                gs.Title = row[colTitle];
                gs.Manufacturer = row[colManufacturer];
                gs.Year = row[colYear];
                gs.ModelNo = row[colModelNo];
                gs.Rarity = row[colRarity];

                gs.CartType = EnumCartType(row[colCartType], ref md5);
                gs.MachineType = EnumMachineType(row[colMachineType], ref md5);

                Controller dflt;
                switch (gs.MachineType)
                {
                    default:
                    case MachineType.A2600NTSC:
                    case MachineType.A2600PAL:
                        dflt = Controller.Joystick;
                        break;
                    case MachineType.A7800NTSC:
                    case MachineType.A7800PAL:
                        dflt = Controller.ProLineJoystick;
                        break;
                }
                gs.LController = EnumController(row[colLController], dflt, ref md5);
                gs.RController = EnumController(row[colRController], dflt, ref md5);

                if (colHelpUri < row.Length && row[colHelpUri].Trim().Length > 0)
                {
                    gs.HelpUri = row[colHelpUri].Trim();
                }

                gs.FileInfo = null;

                PropertyTable[md5] = gs;
            }
            r.Close();
            Trace.Write(PropertyTable.Count);
            Trace.Write(" ");
            Trace.Write(ROM_PROPERTIES_FN);
            Trace.WriteLine(" entries loaded");
        }
 // TODO : should probably be in the GameSettings class
 private static void FixCartType(GameSettings gs)
 {
     FileInfo fi = new FileInfo(gs.FileInfo.FullName);
     switch (gs.MachineType) {
         case MachineType.A2600NTSC:
         case MachineType.A2600PAL:
             switch (fi.Length - gs.Offset) {
                 case 2048: gs.CartType = CartType.A2K; break;
                 case 4096: gs.CartType = CartType.A4K; break;
                 case 8192: gs.CartType = CartType.A8K; break;
                 case 16384: gs.CartType = CartType.A16K; break;
                 default:
                     throw new UnknownCartTypeException("Couldn't guess type of cart image " +
                         fi.FullName);
             }
             break;
         case MachineType.A7800NTSC:
         case MachineType.A7800PAL:
             switch (fi.Length - gs.Offset) {
                 case 8192: gs.CartType = CartType.A7808; break;
                 case 16384: gs.CartType = CartType.A7816; break;
                 case 32768: gs.CartType = CartType.A7832; break;
                 case 49152: gs.CartType = CartType.A7848; break;
                 default:
                     throw new UnknownCartTypeException("Couldn't guess type of cart image " +
                         fi.FullName);
             }
             break;
     }
 }