]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Trying to set input device to <none> reverted back to previous selection.
authorToni Wilen <twilen@winuae.net>
Sun, 21 Feb 2016 12:03:17 +0000 (14:03 +0200)
committerToni Wilen <twilen@winuae.net>
Sun, 21 Feb 2016 12:03:17 +0000 (14:03 +0200)
inputdevice.cpp

index 6adb48a25abc6471b795ad0bcb36d7a598d9ddc2..57010f4be47821368fee0bea757fdae133505608 100644 (file)
@@ -166,13 +166,6 @@ static struct temp_uids temp_uid;
 static int temp_uid_index[MAX_INPUT_DEVICES][IDTYPE_MAX];
 static int temp_uid_cnt[IDTYPE_MAX];
 
-struct jport_config {
-       struct inputdevconfig idc;
-       TCHAR id[MAX_JPORTNAME];
-       int mode;
-};
-static struct jport_config jport_config_store[MAX_JPORTS];
-
 static int isdevice (struct uae_input_device *id)
 {
        int i, j;
@@ -417,7 +410,7 @@ static int inputdevice_get_unplugged_device(struct inputdevconfig *idc)
        for (int portnum = 0; portnum < MAX_JPORTS; portnum++) {
                for (int i = 0; i < MAX_STORED_JPORTS; i++) {
                        struct stored_jport *jp = &stored_jports[portnum][i];
-                       if (jp->inuse && jp->jp.id == -2) {
+                       if (jp->inuse && jp->jp.id == JPORT_UNPLUGGED) {
                                if (!_tcscmp(idc->name, jp->jp.idc.name) && !_tcscmp(idc->configname, jp->jp.idc.configname)) {
                                        jp->inuse = false;
                                        return portnum;
@@ -433,7 +426,7 @@ void inputdevice_forget_unplugged_device(int portnum)
 {
        for (int i = 0; i < MAX_STORED_JPORTS; i++) {
                struct stored_jport *jp = &stored_jports[portnum][i];
-               if (jp->inuse && jp->jp.id == -2) {
+               if (jp->inuse && jp->jp.id == JPORT_UNPLUGGED) {
                        jp->inuse = false;
                }
        }
@@ -487,8 +480,9 @@ static void inputdevice_set_newest_used_device(int portnum, struct jport *jps)
 
 static void inputdevice_store_used_device(struct jport *jps, int portnum, bool defaultports)
 {
-       if (jps->id == -1)
+       if (jps->id == JPORT_NONE)
                return;
+
        // already added? if custom or kbr layout: delete all old
        for (int i = 0; i < MAX_STORED_JPORTS; i++) {
                struct stored_jport *jp = &stored_jports[portnum][i];
@@ -498,6 +492,7 @@ static void inputdevice_store_used_device(struct jport *jps, int portnum, bool d
                        }
                }
        }
+
        // delete from other ports
        for (int j = 0; j < MAX_JPORTS; j++) {
                for (int i = 0; i < MAX_STORED_JPORTS; i++) {
@@ -550,7 +545,7 @@ static void inputdevice_store_unplugged_port(struct uae_prefs *p, struct inputde
        struct jport jpt = { 0 };
        _tcscpy(jpt.idc.configname, idc->configname);
        _tcscpy(jpt.idc.name, idc->name);
-       jpt.id = -2;
+       jpt.id = JPORT_UNPLUGGED;
        for (int i = 0; i < MAX_JPORTS; i++) {
                struct jport *jp = &p->jports[i];
                if (!_tcscmp(jp->idc.name, idc->name) && !_tcscmp(jp->idc.configname, idc->configname)) {
@@ -1024,10 +1019,6 @@ void reset_inputdevice_config (struct uae_prefs *prefs, bool reset)
        reset_inputdevice_config_temp();
 
        if (reset) {
-               for (int i = 0; i < MAX_JPORTS; i++) {
-                       struct jport_config *jp = &jport_config_store[i];
-                       memset(jp, 0, sizeof(struct jport_config));
-               }
                inputdevice_store_clear();
        }
 }
@@ -8298,15 +8289,17 @@ static bool fixjport (struct jport *port, int add, bool always)
                vv += JSEM_CUSTOM;
        }
        if (port->id != vv || always) {
+               port->idc.shortid[0] = 0;
+               port->idc.configname[0] = 0;
+               port->idc.name[0] = 0;
                if (vv >= JSEM_JOYS && vv < JSEM_MICE) {
                        _tcscpy(port->idc.name, inputdevice_get_device_name (IDTYPE_JOYSTICK, vv - JSEM_JOYS));
                        _tcscpy(port->idc.configname, inputdevice_get_device_unique_name (IDTYPE_JOYSTICK, vv - JSEM_JOYS));
                } else if (vv >= JSEM_MICE && vv < JSEM_END) {
                        _tcscpy(port->idc.name, inputdevice_get_device_name (IDTYPE_MOUSE, vv - JSEM_MICE));
                        _tcscpy(port->idc.configname, inputdevice_get_device_unique_name (IDTYPE_MOUSE, vv - JSEM_MICE));
-               } else {
-                       port->idc.name[0] = 0;
-                       port->idc.configname[0] = 0;
+               } else if (vv >= JSEM_KBDLAYOUT && vv < JSEM_CUSTOM) {
+                       _stprintf(port->idc.shortid, _T("kbd%d"), vv - JSEM_KBDLAYOUT + 1);
                }
                wasinvalid = true;
 #if 0
@@ -8328,7 +8321,7 @@ static void inputdevice_get_previous_joy(struct uae_prefs *p, int portnum)
                        break;
                if (jp->idc.configname[0]) {
                        found = inputdevice_joyport_config(p, jp->idc.name, jp->idc.configname, portnum, jp->mode, 1, true) != 0;
-                       if (!found && jp->id == -2)
+                       if (!found && jp->id == JPORT_UNPLUGGED)
                                found = inputdevice_joyport_config(p, jp->idc.name, NULL, portnum, jp->mode, 1, true) != 0;
                } else if (jp->id < JSEM_JOYS && jp->id >= 0) {
                        jpx->id = jp->id;
@@ -8429,13 +8422,13 @@ void restore_inputdevice_config (struct uae_prefs *p, int portnum)
 
 void inputdevice_joyport_config_store(struct uae_prefs *p, const TCHAR *value, int portnum, int mode, int type)
 {
-       struct jport_config *jp = &jport_config_store[portnum];
+       struct jport *jp = &p->jports[portnum];
        if (type == 2) {
                _tcscpy(jp->idc.name, value);
        } else if (type == 1) {
                _tcscpy(jp->idc.configname, value);
        } else {
-               _tcscpy(jp->id, value);
+               _tcscpy(jp->idc.shortid, value);
        }
        jp->mode = mode;
 }
@@ -8633,6 +8626,12 @@ int inputdevice_getjoyportdevice (int port, int val)
 
 void inputdevice_fix_prefs(struct uae_prefs *p, bool userconfig)
 {
+       struct jport jport_config_store[MAX_JPORTS];
+
+       for (int i = 0; i < MAX_JPORTS; i++) {
+               memcpy(&jport_config_store[i], &p->jports[i], sizeof(struct jport));
+       }
+
        bool defaultports = userconfig == false;
        // Convert old style custom mapping to new style
        for (int i = 0; i < MAX_JPORTS_CUSTOM; i++) {
@@ -8647,25 +8646,27 @@ void inputdevice_fix_prefs(struct uae_prefs *p, bool userconfig)
        bool matched[MAX_JPORTS];
        // configname+friendlyname first
        for (int i = 0; i < MAX_JPORTS; i++) {
-               struct jport_config *jp = &jport_config_store[i];
+               struct jport *jp = &jport_config_store[i];
                matched[i] = false;
                if (jp->idc.configname[0] && jp->idc.name[0]) {
                        if (inputdevice_joyport_config(p, jp->idc.name, jp->idc.configname, i, jp->mode, 1, userconfig)) {
                                inputdevice_validate_jports(p, i, matched);
                                inputdevice_store_used_device(&p->jports[i], i, defaultports);
                                matched[i] = true;
+                               write_log(_T("Port%d: COMBO '%s' + '%s' matched\n"), i, jp->idc.name, jp->idc.configname);
                        }
                }
        }
        // configname next
        for (int i = 0; i < MAX_JPORTS; i++) {
                if (!matched[i]) {
-                       struct jport_config *jp = &jport_config_store[i];
+                       struct jport *jp = &jport_config_store[i];
                        if (jp->idc.configname[0]) {
                                if (inputdevice_joyport_config(p, NULL, jp->idc.configname, i, jp->mode, 1, userconfig)) {
                                        inputdevice_validate_jports(p, i, matched);
                                        inputdevice_store_used_device(&p->jports[i], i, defaultports);
                                        matched[i] = true;
+                                       write_log(_T("Port%d: CONFIG '%s' matched\n"), i, jp->idc.configname);
                                }
                        }
                }
@@ -8673,12 +8674,13 @@ void inputdevice_fix_prefs(struct uae_prefs *p, bool userconfig)
        // friendly name next
        for (int i = 0; i < MAX_JPORTS; i++) {
                if (!matched[i]) {
-                       struct jport_config *jp = &jport_config_store[i];
+                       struct jport *jp = &jport_config_store[i];
                        if (jp->idc.name[0]) {
                                if (inputdevice_joyport_config(p, jp->idc.name, NULL, i, jp->mode, 1, userconfig)) {
                                        inputdevice_validate_jports(p, i, matched);
                                        inputdevice_store_used_device(&p->jports[i], i, defaultports);
                                        matched[i] = true;
+                                       write_log(_T("Port%d: NAME '%s' matched\n"), i, jp->idc.name);
                                }
                        }
                }
@@ -8686,19 +8688,20 @@ void inputdevice_fix_prefs(struct uae_prefs *p, bool userconfig)
        // joyportX last and only if no name/configname
        for (int i = 0; i < MAX_JPORTS; i++) {
                if (!matched[i]) {
-                       struct jport_config *jp = &jport_config_store[i];
-                       if (jp->id[0] && !jp->idc.name[0] && !jp->idc.configname[0]) {
-                               if (inputdevice_joyport_config(p, jp->id, NULL, i, jp->mode, 0, userconfig)) {
+                       struct jport *jp = &jport_config_store[i];
+                       if (jp->idc.shortid[0] && !jp->idc.name[0] && !jp->idc.configname[0]) {
+                               if (inputdevice_joyport_config(p, jp->idc.shortid, NULL, i, jp->mode, 0, userconfig)) {
                                        inputdevice_validate_jports(p, i, matched);
                                        inputdevice_store_used_device(&p->jports[i], i, defaultports);
                                        matched[i] = true;
+                                       write_log(_T("Port%d: ID '%s' matched\n"), i, jp->idc.shortid);
                                }
                        }
                        if (!matched[i]) {
                                if (jp->idc.configname[0] && jp->idc.name[0]) {
                                        struct jport jpt = { 0 };
                                        memcpy(&jpt.idc, &jp->idc, sizeof(struct inputdevconfig));
-                                       jpt.id = -2;
+                                       jpt.id = JPORT_UNPLUGGED;
                                        write_log(_T("Unplugged stored, port %d '%s' (%s)\n"), i, jp->idc.name, jp->idc.configname);
                                        inputdevice_store_used_device(&jpt, i, defaultports);
                                        freejport(p, i);
@@ -8708,11 +8711,15 @@ void inputdevice_fix_prefs(struct uae_prefs *p, bool userconfig)
        }
        for (int i = 0; i < MAX_JPORTS; i++) {
                if (!matched[i]) {
+                       struct jport *jp = &jport_config_store[i];
                        freejport(p, i);
-                       inputdevice_get_previous_joy(p, i);
+                       if (jp->id != JPORT_NONE) {
+                               inputdevice_get_previous_joy(p, i);
+                               write_log(_T("Port%d: ID=%d getting previous: %d\n"), i, jp->id, p->jports[i].id);
+                       } else {
+                               write_log(_T("Port%d: NONE\n"), i);
+                       }
                }
-               struct jport_config *jp = &jport_config_store[i];
-               memset(jp, 0, sizeof(struct jport_config));
        }
 }