| 525 | } |
| 526 | |
| 527 | u64 FileMemoryCard::GetCRC(uint slot) |
| 528 | { |
| 529 | std::FILE* mcfp = m_file[slot]; |
| 530 | if (!mcfp) |
| 531 | return 0; |
| 532 | |
| 533 | u64 retval = 0; |
| 534 | |
| 535 | if (m_ispsx[slot]) |
| 536 | { |
| 537 | if (!Seek(mcfp, 0)) |
| 538 | return 0; |
| 539 | |
| 540 | const s64 mcfpsize = m_fileSize[slot]; |
| 541 | if (mcfpsize < 0) |
| 542 | return 0; |
| 543 | |
| 544 | // Process the file in 4k chunks. Speeds things up significantly. |
| 545 | |
| 546 | u64 buffer[528 * 8]; // use 528 (sector size), ensures even divisibility |
| 547 | |
| 548 | const uint filesize = static_cast<uint>(mcfpsize) / sizeof(buffer); |
| 549 | for (uint i = filesize; i; --i) |
| 550 | { |
| 551 | if (std::fread(buffer, sizeof(buffer), 1, mcfp) != 1) |
| 552 | return 0; |
| 553 | |
| 554 | for (uint t = 0; t < std::size(buffer); ++t) |
| 555 | retval ^= buffer[t]; |
| 556 | } |
| 557 | } |
| 558 | else |
| 559 | { |
| 560 | retval = m_chksum[slot]; |
| 561 | } |
| 562 | |
| 563 | return retval; |
| 564 | } |
| 565 | |
| 566 | // -------------------------------------------------------------------------------------- |
| 567 | // MemoryCard Component API Bindings |
no test coverage detected