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

Function inputdevice_store_used_device

src/inputdevice.cpp:663–723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

661}
662
663static void inputdevice_store_used_device(struct jport *jps, int portnum, bool defaultports)
664{
665 if (jps->id == JPORT_NONE)
666 return;
667
668 // already added? if custom or kbr layout: delete all old
669 for (int i = 0; i < MAX_STORED_JPORTS; i++) {
670 struct stored_jport *jp = &stored_jports[portnum][i];
671 if (jp->inuse && ((jps->id == jp->jp.id) || (jps->idc.configname[0] != 0 && jp->jp.idc.configname[0] != 0 && !_tcscmp(jps->idc.configname, jp->jp.idc.configname)))) {
672 if (!jp->defaultports) {
673 jp->inuse = false;
674 }
675 }
676 }
677
678 // delete from other ports
679 for (int j = 0; j < MAX_JPORTS; j++) {
680 for (int i = 0; i < MAX_STORED_JPORTS; i++) {
681 struct stored_jport *jp = &stored_jports[j][i];
682 if (jp->inuse && ((jps->id == jp->jp.id) || (jps->idc.configname[0] != 0 && jp->jp.idc.configname[0] != 0 && !_tcscmp(jps->idc.configname, jp->jp.idc.configname)))) {
683 if (!jp->defaultports) {
684 jp->inuse = false;
685 }
686 }
687 }
688 }
689 // delete oldest if full
690 for (int i = 0; i < MAX_STORED_JPORTS; i++) {
691 struct stored_jport *jp = &stored_jports[portnum][i];
692 if (!jp->inuse)
693 break;
694 if (i == MAX_STORED_JPORTS - 1) {
695 uae_u32 age = 0xffffffff;
696 int idx = -1;
697 for (int j = 0; j < MAX_STORED_JPORTS; j++) {
698 struct stored_jport *jp = &stored_jports[portnum][j];
699 if (jp->age < age && !jp->defaultports) {
700 age = jp->age;
701 idx = j;
702 }
703 }
704 if (idx >= 0) {
705 struct stored_jport *jp = &stored_jports[portnum][idx];
706 jp->inuse = false;
707 }
708 }
709 }
710 // add new
711 for (int i = 0; i < MAX_STORED_JPORTS; i++) {
712 struct stored_jport *jp = &stored_jports[portnum][i];
713 if (!jp->inuse) {
714 memcpy(&jp->jp, jps, sizeof(struct jport));
715 write_log(_T("Stored port %d/%d d=%d: added %d %d %s %s\n"), portnum, i, defaultports, jp->jp.id, jp->jp.mode, jp->jp.idc.name, jp->jp.idc.configname);
716 jp->inuse = true;
717 jp->defaultports = defaultports;
718 stored_jport_cnt++;
719 jp->age = stored_jport_cnt;
720 return;

Callers 4

inputdevice_updateconfigFunction · 0.85
inputdevice_fix_prefsFunction · 0.85

Calls 1

write_logFunction · 0.70

Tested by

no test coverage detected