MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / cartScan

Method cartScan

3ds/source/loader.cpp:652–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

650}
651
652void TitleCatalog::cartScan(void)
653{
654 TitleCatalog& self = get();
655
656 bool oldCardIn;
657 FSUSER_CardSlotIsInserted(&oldCardIn);
658
659 while (self.mDoCartScan.test_and_set()) {
660 // Someone is driving the card bus directly. Querying the slot now would
661 // make Process9 take the controller away mid-transfer.
662 if (self.mCartScanPaused.load() > 0) {
663 self.mCartScanQuiet.store(true);
664 svcSleepThread(1'000'000);
665 continue;
666 }
667 self.mCartScanQuiet.store(false);
668
669 bool cardIn = false;
670
671 FSUSER_CardSlotIsInserted(&cardIn);
672 if (cardIn != oldCardIn) {
673 bool power;
674 FSUSER_CardSlotGetCardIFPowerStatus(&power);
675 if (cardIn) {
676 if (!power) {
677 FSUSER_CardSlotPowerOn(&power);
678 }
679 while (!power && self.mDoCartScan.test_and_set()) {
680 FSUSER_CardSlotGetCardIFPowerStatus(&power);
681 }
682 svcSleepThread(500'000'000);
683 for (size_t i = 0; i < 10; i++) {
684 if ((oldCardIn = self.scanCard())) {
685 break;
686 }
687 }
688 }
689 else {
690 FSUSER_CardSlotPowerOff(&power);
691 if (!self.mLoading) {
692 {
693 std::lock_guard<std::mutex> lock(self.mMutex);
694 if (!self.mSaves.empty() && self.mSaves.at(0).mediaType() == MEDIATYPE_GAME_CARD) {
695 self.mIcons.erase(self.mSaves.at(0).id());
696 self.mSaves.erase(self.mSaves.begin());
697 }
698 if (!self.mExtdatas.empty() && self.mExtdatas.at(0).mediaType() == MEDIATYPE_GAME_CARD) {
699 self.mIcons.erase(self.mExtdatas.at(0).id());
700 self.mExtdatas.erase(self.mExtdatas.begin());
701 }
702 }
703 self.mGeneration.fetch_add(1);
704 }
705 oldCardIn = false;
706 }
707 }
708 }
709}

Callers

nothing calls this directly

Calls 10

scanCardMethod · 0.95
getFunction · 0.85
storeMethod · 0.80
mediaTypeMethod · 0.80
atMethod · 0.80
loadMethod · 0.45
emptyMethod · 0.45
eraseMethod · 0.45
idMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected