using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using System.Text;
using System.IO;

namespace TwoMbit
{
    public class Config
    {
        string path;

        Settings[] recentSettings;
        Settings[] windowResolutions;
        Settings[] fullscreenResolutions;
        Settings[] speedSettings;

        public Config(string _path)
        {
            path = _path;
            init();
        }

        public uint getSpeed() {
            int pos = get<int>("speed_select");
            return (uint)speedSettings[pos].data;
        }

        public Settings[] getWindowList() {
            return windowResolutions;
        }

        public Settings[] getFullscreenList() {
            return fullscreenResolutions;
        }

        public Settings[] getRecentList() {
            return recentSettings;
        }

        public Settings[] getSpeedList() {
            return speedSettings;
        }

        public void setRecentList(string[] recentlist)
        {
            int idx = 0;
            foreach(string recent in recentlist) {
                recentSettings[idx++].str_data = recent;
            }
        }

        public void toggle(string name)
        {
            Settings setting = findSetting(name);
            setting.toggle();
        }

        public void init(string name) {
            Settings setting = findSetting(name);
            setting.set_init();
        }

        public T get< T >(string name)
        {
            Settings setting = findSetting(name);

            if (typeof(T) == typeof(string)) {
                return (T)(object) setting.str_data;
            } else if (typeof(T) == typeof(int)) {
                return (T)(object) setting.data;
            } else if (typeof(T) == typeof(bool)) {
                return setting.data == 0 ? (T)(object) false : (T)(object) true;
            }
            throw new Exception();
        }

        public void set< T >(string name, T value)
        {
            Settings setting = findSetting(name);

            if (typeof(T) == typeof(string)) {
                setting.str_data = (string)(object) value;
            } else if (typeof(T) == typeof(int)) {
                setting.data = (int)(object) value;
            } else if (typeof(T) == typeof(bool)) {
                setting.data = (bool)(object) value == false ? 0 : 1;
            }
        }

        public bool load()
        {
            System.IO.StreamReader f;
            List<Settings> list = Settings.getList();
            string[] data;
            string buffer;

            try {
                f = new System.IO.StreamReader(path);
            } catch {
                return false;
            }

            while ( null != (buffer = f.ReadLine()) ) {
                buffer = buffer.Replace("\n", string.Empty).Replace("\t", string.Empty).Replace("\"", string.Empty).Replace("\'", string.Empty);

                if ( (buffer.Length == 0) || (buffer.ElementAt(0) == ';') ) continue;
                data = buffer.Split(new Char[] { '=' });
                if (data.Count() < 2) continue;
                data[0] = data[0].Replace(" ", string.Empty);
                data[1] = data[1].Trim();

                foreach (Settings setting in list) {
                    if (data[0].ToLower() == setting.name.ToLower()) {
                        if (setting.type != (int)Settings.Type.STR) {
                            setting.data = string_to_int(setting, data[1]);
                        } else if (Resolution.isResolution(setting.str_init)) {
                            if (Resolution.isResolution(data[1])) {
                                setting.str_data = data[1];
                            }
			            } else {
                            setting.str_data = data[1];
                        }
                        break;
		            }
                }
            }
            f.Close();
            return true;
        }

        public bool save()
        {
            System.IO.StreamWriter f;
            List<Settings> list = Settings.getList();
            string[] lines;

            try {
                f = new System.IO.StreamWriter(path, false);
            } catch {
                return false;
            }

            foreach (Settings setting in list) {
                if (!setting.saveable) continue;
                lines = setting.desc.Split(new Char[] { '\n', '\r' });
                f.WriteLine(";--------------------------------------------------");

                for (int i = 0; i < lines.Count(); i++) {
                    f.WriteLine("; " + lines[i]);
                }

                if (setting.type != (int)Settings.Type.STR) {
                    f.WriteLine("; default = " + int_to_string(setting.type, setting.init));
                    f.WriteLine(";--------------------------------------------------");
                    f.WriteLine(setting.name + " = " + int_to_string(setting.type, setting.data) + "\n");
                } else {
                    f.WriteLine("; default = " + setting.str_init);
                    f.WriteLine(";--------------------------------------------------");
                    f.WriteLine(setting.name + " = " + setting.str_data + "\n");
                }
            }
            f.Close();
            return true;
        }

        Settings findSetting(string name)
        {
            List<Settings> list = Settings.getList();
            foreach(Settings setting in list) {
                if (name == setting.name) {
                    return setting;
                }
            }
            throw new Exception("Setting name: " + name + " is not found");
        }

        string int_to_string(int type, int input)
        {
            switch(type) {
                case (int)Settings.Type.BIN:
                    return input == 1 ? "true" : "false";
                default:
                case (int)Settings.Type.DEC:
                    return input.ToString();
                case (int)Settings.Type.HEX:
                    return "0x" + input.ToString("X4");
            }
        }

        int string_to_int(Settings setting, string data)
        {
            int value;

            switch(setting.type) {
                case (int)Settings.Type.BIN:
                    if ((data == "true") || (data == "enabled") || (data == "on") || (data == "yes") || (data == "1"))
                        return 1;
                    if ((data == "false") || (data == "disabled") || (data == "off") || (data == "no") || (data == "0"))
                        return 0;

                    break;
                case (int)Settings.Type.HEX:
                    if (data.Substring(0, 2) == "0x") {
                        data = data.Substring(2);
                    }
                    try {
                        value = Convert.ToInt16(data, 16);
                        return value;
                    } catch {
                        break;
                    }
                case (int)Settings.Type.DEC:
                    try {
                        value = Convert.ToInt32(data);
                    } catch {
                        break;
                    }
                    if (value <= setting.limit) return value;
                    break;
            }
            return setting.init;
        }

        void init()
        {
            new Settings("save_slot", 0);
            new Settings("video_mode_window", "window size at startup", 0, (int)Settings.Type.DEC, 4);
            new Settings("video_mode_fullscreen", "active fullscreen resolution", 0, (int)Settings.Type.DEC, 4);
            new Settings("fullscreen", 0);

            windowResolutions = new Settings[] {
                new Settings("window_mode_0", "window mode 0",   "300x225"),
                new Settings("window_mode_1", "window mode 1",   "600x450"),
                new Settings("window_mode_2", "window mode 2",   "900x675"),
                new Settings("window_mode_3", "window mode 3",   "1200x900"),
                new Settings("window_mode_4", "window mode 4 ",  "1500x1125")
            };

            fullscreenResolutions = new Settings[] {
                new Settings("fullscreen_mode_0", "fullscreen mode 0", "800x600"),
                new Settings("fullscreen_mode_1", "fullscreen mode 1", "1024x768"),
                new Settings("fullscreen_mode_2", "fullscreen mode 2", "1600x900"),
                new Settings("fullscreen_mode_3", "fullscreen mode 3", "1680x1050"),
                new Settings("fullscreen_mode_4", "fullscreen mode 4", "1920x1080")
            };

            new Settings("video_vsync", "Use Vsync", 0, (int)Settings.Type.BIN);

            if (App.isSystemInitialized(Cart._System.SNES)) {
                new Settings("snes_audio_frequency",
			                "Adjust snes audio frequency\n",
			                300, (int)Settings.Type.DEC, 600);
            }

            new Settings("sms_audio_frequency",
                        "Adjust sms audio frequency\n",
                        300, (int)Settings.Type.DEC, 600);

            new Settings("audio_volume",
                        "Adjust audio volume\n",
                        50, (int)Settings.Type.DEC, 100);

            new Settings(	"video_region",
		            "Select video region usage\n"
		            +"  0 = auto\n"
		            +"  1 = usa\n"
		            +"  2 = japanese\n"
                    + " 3 = europe",
		            0, (int)Settings.Type.DEC, 3);

            new Settings(	"video_filter_hw",
				            "Select hardware filter for video\n"
				            +"  0 = Point\n"
				            +"  1 = Linear",
				            0, (int)Settings.Type.DEC, 1);

            new Settings(	"video_filter_sw",
				            "Select software filter for video\n"
				            +"  0 = Normal (no filter)\n"
				            +"  1 = NTSC",
				            0, (int)Settings.Type.DEC, 1);



            new Settings("ntsc_filter_merge", "merge fields", 1, (int)Settings.Type.BIN);

            new Settings(	"ntsc_filter",
					            "Select ntsc filter output\n"
					            +"  0 = Composite TV cable\n"
					            +"  1 = SVideo TV cable\n"
					            +"  2 = RGB TV cable",
					            0, (int)Settings.Type.DEC, 2);

            new Settings("video_scanlines", "Enable Scanlines", 0, (int)Settings.Type.BIN);

            new Settings("video_scanline_intensity", "Set Scanline intensity in %", 0, (int)Settings.Type.DEC, 100);

            new Settings(	"video_contrast",
			            "Set Contrast\n"
			            +"  range 0 - 200\n"
			            +"  < 100 = lower contrast\n"
			            +"  > 100 = higher contrast", 
			            100, (int)Settings.Type.DEC, 200);

            new Settings(	"video_brightness",
			            "Set Brightness\n"
			            +"  range 0 - 200\n"
			            +"  < 100 = darker image\n"
			            +"  > 100 = brighter image", 
			            100, (int)Settings.Type.DEC, 200);

            new Settings(	"video_gamma",
		            "Set Gamme\n"
		            +"  range 0.5 - 3.5\n"
		            +"  multiply value with 100",
		            100, (int)Settings.Type.DEC, 350);

            new Settings("audio_active", "Enable audio output", 1, (int)Settings.Type.BIN);

            new Settings("show_fps", "Show framerate bottom right", 1, (int)Settings.Type.BIN);

            new Settings("speed_select", 0);

            speedSettings = new Settings[] {
                new Settings("speed_0", 100),
                new Settings("speed_1", "custom speed in %", 50, (int)Settings.Type.DEC, 500),
                new Settings("speed_2", "custom speed in %", 75, (int)Settings.Type.DEC, 500),
                new Settings("speed_3", "custom speed in %", 150, (int)Settings.Type.DEC, 500),
                new Settings("speed_4", "custom speed in %", 200, (int)Settings.Type.DEC, 500)
            };

            new Settings("language_file", "setup a language file\n"
                + "all language files must be stored in a folder named language, relative to the emu path", App.LANGUAGE_FILE);

            //snes
            if (App.isSystemInitialized(Cart._System.SNES)) {
                new Settings("snes_joypad_1_up", "Joypad1 up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_down", "Joypad1 down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_left", "Joypad1 left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_right", "Joypad1 right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_a", "Joypad1 A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_b", "Joypad1 B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_x", "Joypad1 X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_y", "Joypad1 Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_l", "Joypad1 L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_r", "Joypad1 R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_select", "Joypad1 select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_1_start", "Joypad1 start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_joypad_2_up", "Joypad2 up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_down", "Joypad2 down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_left", "Joypad2 left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_right", "Joypad2 right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_a", "Joypad2 A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_b", "Joypad2 B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_x", "Joypad2 X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_y", "Joypad2 Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_l", "Joypad2 L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_r", "Joypad2 R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_select", "Joypad2 select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_joypad_2_start", "Joypad2 start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapa_1_up", "MultiTap1a up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_down", "MultiTap1a down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_left", "MultiTap1a left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_right", "MultiTap1a right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_a", "MultiTap1a A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_b", "MultiTap1a B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_x", "MultiTap1a X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_y", "MultiTap1a Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_l", "MultiTap1a L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_r", "MultiTap1a R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_select", "MultiTap1a select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_1_start", "MultiTap1a start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapb_1_up", "MultiTap1b up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_down", "MultiTap1b down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_left", "MultiTap1b left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_right", "MultiTap1b right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_a", "MultiTap1b A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_b", "MultiTap1b B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_x", "MultiTap1b X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_y", "MultiTap1b Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_l", "MultiTap1b L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_r", "MultiTap1b R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_select", "MultiTap1b select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_1_start", "MultiTap1b start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapc_1_up", "MultiTap1c up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_down", "MultiTap1c down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_left", "MultiTap1c left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_right", "MultiTap1c right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_a", "MultiTap1c A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_b", "MultiTap1c B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_x", "MultiTap1c X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_y", "MultiTap1c Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_l", "MultiTap1c L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_r", "MultiTap1c R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_select", "MultiTap1c select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_1_start", "MultiTap1c start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapd_1_up", "MultiTap1d up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_down", "MultiTap1d down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_left", "MultiTap1d left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_right", "MultiTap1d right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_a", "MultiTap1d A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_b", "MultiTap1d B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_x", "MultiTap1d X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_y", "MultiTap1d Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_l", "MultiTap1d L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_r", "MultiTap1d R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_select", "MultiTap1d select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_1_start", "MultiTap1d start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapa_2_up", "MultiTap2a up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_down", "MultiTap2a down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_left", "MultiTap2a left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_right", "MultiTap2a right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_a", "MultiTap2a A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_b", "MultiTap2a B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_x", "MultiTap2a X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_y", "MultiTap2a Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_l", "MultiTap2a L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_r", "MultiTap2a R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_select", "MultiTap2a select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapa_2_start", "MultiTap2a start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapb_2_up", "MultiTap2b up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_down", "MultiTap2b down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_left", "MultiTap2b left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_right", "MultiTap2b right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_a", "MultiTap2b A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_b", "MultiTap2b B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_x", "MultiTap2b X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_y", "MultiTap2b Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_l", "MultiTap2b L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_r", "MultiTap2b R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_select", "MultiTap2b select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapb_2_start", "MultiTap2b start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapc_2_up", "MultiTap2c up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_down", "MultiTap2c down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_left", "MultiTap2c left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_right", "MultiTap2c right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_a", "MultiTap2c A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_b", "MultiTap2c B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_x", "MultiTap2c X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_y", "MultiTap2c Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_l", "MultiTap2c L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_r", "MultiTap2c R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_select", "MultiTap2c select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapc_2_start", "MultiTap2c start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_multitapd_2_up", "MultiTap2d up", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_down", "MultiTap2d down", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_left", "MultiTap2d left", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_right", "MultiTap2d right", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_a", "MultiTap2d A", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_b", "MultiTap2d B", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_x", "MultiTap2d X", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_y", "MultiTap2d Y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_l", "MultiTap2d L", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_r", "MultiTap2d R", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_select", "MultiTap2d select", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_multitapd_2_start", "MultiTap2d start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_mouse_1_x", "Mouse1 x", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_mouse_1_y", "Mouse1 y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_mouse_1_l", "Mouse1 l", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_mouse_1_r", "Mouse1 r", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_mouse_2_x", "Mouse2 x", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_mouse_2_y", "Mouse2 y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_mouse_2_l", "Mouse2 l", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_mouse_2_r", "Mouse2 r", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_superscope_2_x", "SuperScope x", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_superscope_2_y", "SuperScope y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_superscope_2_trigger", "SuperScope trigger", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_superscope_2_cursor", "SuperScope cursor", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_superscope_2_turbo", "SuperScope turbo", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_superscope_2_pause", "SuperScope pause", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_justifier1_2_x", "Justifier1 x", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_justifier1_2_y", "Justifier1 y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_justifier1_2_trigger", "Justifier1 trigger", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_justifier1_2_start", "Justifier1 start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_justifier2_2_x", "Justifier2 x", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_justifier2_2_y", "Justifier2 y", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_justifier2_2_trigger", "Justifier2 trigger", 0x0000, (int)Settings.Type.HEX);
                new Settings("snes_justifier2_2_start", "Justifier2 start", 0x0000, (int)Settings.Type.HEX);

                new Settings("snes_port_1",
                        "Select Controller for Port 1\n",
                        0x0001, (int)Settings.Type.HEX);

                new Settings("snes_port_2",
                                    "Select Controller for Port 2\n",
                                    0x0000, (int)Settings.Type.HEX);

                new Settings("snes_path_rom", "setup standard path for rom (game) files", "");
                new Settings("snes_path_sram", "setup path for sram (battery) files\n"
                            + "no path means sram folder relative to app", "");
                new Settings("snes_path_savestate", "setup path for savestate files\n"
                            + "no path means savestate folder relative to app", "");
                new Settings("snes_path_cheat", "setup path for cheat files\n"
                            + "no path means cheat folder relative to app", "");
                new Settings("snes_path_sufami_turbo_bios", "Bios file for Sufami Turbo", "");
                new Settings("snes_path_bsx_bios", "Bios file for BS-X", "");
            }
            //SMS
            new Settings("sms_joypad_1_up", "Joypad1 up", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_1_down", "Joypad1 down", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_1_left", "Joypad1 left", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_1_right", "Joypad1 right", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_1_a", "Joypad1 A", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_1_b", "Joypad1 B", 0x0000, (int)Settings.Type.HEX);

            new Settings("sms_joypad_2_up", "Joypad2 up", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_2_down", "Joypad2 down", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_2_left", "Joypad2 left", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_2_right", "Joypad2 right", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_2_a", "Joypad2 A", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_joypad_2_b", "Joypad2 B", 0x0000, (int)Settings.Type.HEX);

            new Settings("sms_lightgun_1_x-axis", "Lightgun1 x", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_lightgun_1_y-axis", "Lightgun1 y", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_lightgun_1_trigger", "Lightgun1 trigger", 0x0000, (int)Settings.Type.HEX);

            new Settings("sms_lightgun_2_x-axis", "Lightgun2 x", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_lightgun_2_y-axis", "Lightgun2 y", 0x0000, (int)Settings.Type.HEX);
            new Settings("sms_lightgun_2_trigger", "Lightgun2 trigger", 0x0000, (int)Settings.Type.HEX);

            new Settings("sms_pause_0_pause", "Pause", 0x0000, (int)Settings.Type.HEX);

            new Settings("sms_port_1",
                                "Select Controller for Port 1\n",
                                0x0001, (int)Settings.Type.HEX);

            new Settings("sms_port_2",
                                "Select Controller for Port 2\n",
                                0x0000, (int)Settings.Type.HEX);

            new Settings("sms_path_rom", "setup standard path for rom (game) files", "");
            new Settings("sms_path_sram", "setup path for sram (battery) files\n"
            + "no path means sram folder relative to app", "");
            new Settings("sms_path_jp_bios", "japanese/korean Bios file for SMS", "");
            new Settings("sms_path_us_bios", "us/eu Bios file for SMS", "");
            new Settings("sms_path_savestate", "setup path for savestate files\n"
            + "no path means savestate folder relative to app", "");
            new Settings("sms_path_cheat", "setup path for cheat files\n"
            + "no path means cheat folder relative to app", "");

            new Settings("sms_unit",
                "Select SMS Base Unit\n"
                +"  0 = SMS Unit 1"
                +"  1 = SMS Unit 2",
                1, (int)Settings.Type.DEC, 1);

            new Settings("sms_use_bios",
                "Use prepared Bios files\n"
                + "  0 = off"
                + "  1 = on",
                1, (int)Settings.Type.BIN);

            recentSettings = new Settings[] {
                new Settings("recent0", "recently loaded roms", "" ),
                new Settings("recent1", "recently loaded roms", "" ),
                new Settings("recent2", "recently loaded roms", "" ),
                new Settings("recent3", "recently loaded roms", "" ),
                new Settings("recent4", "recently loaded roms", "" ),
                new Settings("recent5", "recently loaded roms", "" ),
                new Settings("recent6", "recently loaded roms", "" ),
                new Settings("recent7", "recently loaded roms", "" ),
                new Settings("recent8", "recently loaded roms", "" ),
                new Settings("recent9", "recently loaded roms", "" )
            };

            new Settings("lock", "dont change current rom list", 0, (int)Settings.Type.BIN);
        }
    }
    
}
