Example #1
0
        static void Main(string[] args)
        {
            // Working directory
            WorkingFolder     = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            WorkingFolder     = Path.Combine(WorkingFolder, "MyNes");
            ApplicationFolder = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
            Directory.CreateDirectory(WorkingFolder);
            // NES
            NesEmu.WarmUp();
            // Database
            NesCartDatabase.LoadDatabase(Path.Combine(ApplicationFolder, "database.xml"));
            // Load settings !
            Settings.LoadSettings();
            // Execute commands
            Settings.ExecuteCommands(args);

            // Apply settings.
            ApplyEmuSettings();

            // Initialize providers
            InitializeVideo();
            InitializeAudio();
            InitializeInput();
            InitializePalette();
            // Initialize rooms (menus)
            InitializeMenus();
            // Load the rom !
            if (args != null)
            {
                if (args.Length > 0)
                {
                    // First arg must be rom path !
                    if (File.Exists(args[0]))
                    {
                        LoadRom(args[0]);
                    }
                    else
                    {
                        Console.WriteLine("File is not exist at: " + args[0]);
                    }
                }
            }
            // Execute commands of the emulation
            if (NesEmu.EmulationON)
            {
                ExecuteCommands(args);
            }

            // Run SDL
            Events.KeyboardDown       += OnKeyDown;
            Events.JoystickButtonDown += OnJoystickButtonDown;
            Events.JoystickAxisMotion += OnJoystickAxisMove;
            Events.Quit += OnQuit;

            NesEmu.EmulationPaused = false;

            Events.Run();

            // Reached here means everything is done.
            Settings.SaveSettings();
        }