MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / inputdevice_devicechange

Function inputdevice_devicechange

src/inputdevice.cpp:8326–8507  ·  view source on GitHub ↗

called when devices get inserted or removed * store old devices temporarily, enumerate all devices * restore old devices back (order may have changed) */

Source from the content-addressed store, hash-verified

8324* restore old devices back (order may have changed)
8325*/
8326bool inputdevice_devicechange (struct uae_prefs *prefs)
8327{
8328 int acc = input_acquired;
8329 int idx;
8330 TCHAR *jports_name[MAX_JPORTS];
8331 TCHAR *jports_configname[MAX_JPORTS];
8332 int jportskb[MAX_JPORTS], jportscustom[MAX_JPORTS];
8333 int jportsmode[MAX_JPORTS];
8334 int jportssubmode[MAX_JPORTS];
8335 int jportid[MAX_JPORTS], jportaf[MAX_JPORTS];
8336 bool changed = false;
8337
8338 for (i = 0; i < MAX_JPORTS; i++) {
8339 jportskb[i] = -1;
8340 jportscustom[i] = -1;
8341 jportid[i] = prefs->jports[i].id;
8342 jportaf[i] = prefs->jports[i].autofire;
8343 jports_name[i] = NULL;
8344 jports_configname[i] = NULL;
8345 idx = inputdevice_getjoyportdevice (i, prefs->jports[i].id);
8346 if (idx >= JSEM_LASTKBD + inputdevice_get_device_total(IDTYPE_MOUSE) + inputdevice_get_device_total(IDTYPE_JOYSTICK)) {
8347 jportscustom[i] = idx - (JSEM_LASTKBD + inputdevice_get_device_total(IDTYPE_MOUSE) + inputdevice_get_device_total(IDTYPE_JOYSTICK));
8348 } else if (idx >= JSEM_LASTKBD) {
8349 if (prefs->jports[i].idc.name[0] == 0 && prefs->jports[i].idc.configname[0] == 0) {
8350 struct inputdevice_functions *idf;
8351 int devidx;
8352 idx -= JSEM_LASTKBD;
8353 idf = getidf (idx);
8354 devidx = inputdevice_get_device_index (idx);
8355 jports_name[i] = my_strdup (idf->get_friendlyname (devidx));
8356 jports_configname[i] = my_strdup (idf->get_uniquename (devidx));
8357 }
8358 } else {
8359 jportskb[i] = idx;
8360 }
8361 jportsmode[i] = prefs->jports[i].mode;
8362 jportssubmode[i] = prefs->jports[i].submode;
8363 if (jports_name[i] == NULL)
8364 jports_name[i] = my_strdup(prefs->jports[i].idc.name);
8365 if (jports_configname[i] == NULL)
8366 jports_configname[i] = my_strdup(prefs->jports[i].idc.configname);
8367 }
8368
8369 // store old devices
8370 struct inputdevconfig devcfg[MAX_INPUT_DEVICES][IDTYPE_MAX] = { 0 };
8371 int dev_nums[IDTYPE_MAX];
8372 for (int j = 0; j <= IDTYPE_KEYBOARD; j++) {
8373 struct inputdevice_functions *inf = &idev[j];
8374 dev_nums[j] = inf->get_num();
8375 for (int i = 0; i < dev_nums[j]; i++) {
8376 const TCHAR *un = inf->get_uniquename(i);
8377 const TCHAR *fn = inf->get_friendlyname(i);
8378 _tcscpy(devcfg[i][j].name, fn);
8379 _tcscpy(devcfg[i][j].configname, un);
8380 }
8381 }
8382
8383 inputdevice_unacquire();

Callers 1

handle_joy_device_eventFunction · 0.85

Calls 15

getidfFunction · 0.85
inputdevice_unacquireFunction · 0.85
matchdevices_allFunction · 0.85
freejportFunction · 0.85

Tested by

no test coverage detected