diff --git a/pcsx2/DEV9/ATA/ATA_State.cpp b/pcsx2/DEV9/ATA/ATA_State.cpp index caaf77561bc4c1..7fff48e792b0a2 100644 --- a/pcsx2/DEV9/ATA/ATA_State.cpp +++ b/pcsx2/DEV9/ATA/ATA_State.cpp @@ -66,6 +66,17 @@ int ATA::Open(const std::string& hddPath) return -1; } + // Open and read the content of the hddid file + std::string hddidPath = Path::ReplaceExtension(hddPath, "hddid"); + std::optional> fileContent = FileSystem::ReadBinaryFile(hddidPath.c_str()); + + if (fileContent.has_value() && fileContent.value().size() <= sizeof(sceSec)) + { + // Copy the content to sceSec + memset(sceSec, 0, sizeof(sceSec)); + std::copy(fileContent.value().begin(), fileContent.value().end(), sceSec); + } + //Store HddImage size for later use hddImageSize = static_cast(size); CreateHDDinfo(hddImageSize / 512); @@ -144,7 +155,7 @@ void ATA::InitSparseSupport(const std::string& hddPath) /* https://askbob.tech/the-ntfs-blog-sparse-and-compressed-file/ * NTFS Sparse Block Size are the same size as a compression unit - * Cluster Size Compression Unit + * Cluster Size Compression Unit * -------------------------------- * 512bytes 8kb (0x02000) * 1kb 16kb (0x04000) diff --git a/pcsx2/DEV9/ATA/Commands/ATA_SCE.cpp b/pcsx2/DEV9/ATA/Commands/ATA_SCE.cpp index f58a514fc3c4ba..935f9cb344fa31 100644 --- a/pcsx2/DEV9/ATA/Commands/ATA_SCE.cpp +++ b/pcsx2/DEV9/ATA/Commands/ATA_SCE.cpp @@ -54,34 +54,36 @@ void ATA::SCE_IDENTIFY_DRIVE() { PreCmd(); - // fill sceSec response with default data - memcpy(sceSec, "Sony Computer Entertainment Inc.", 32); // Always this magic header. - memcpy(sceSec + 0x20, "SCPH-20401", 10); // sometimes this matches HDD model, the rest 6 bytes filles with zeroes, or sometimes with spaces - memcpy(sceSec + 0x30, " 40", 4); // or " 120" for PSX DESR, reference for ps2 area size. The rest bytes filled with zeroes - - sceSec[0x40] = 0; // 0x40 - 0x43 - 4-byte HDD internal SCE serial, does not match real HDD serial, currently hardcoded to 0x1000000 - sceSec[0x41] = 0; - sceSec[0x42] = 0; - sceSec[0x43] = 0x01; + // fill sceSec with default data if hdd id file is not present + if (sceSec[0] == 0) + { + // fill sceSec response with default data + memcpy(sceSec, "Sony Computer Entertainment Inc.", 32); // Always this magic header. + memcpy(sceSec + 0x20, "SCPH-20401", 10); // sometimes this matches HDD model, the rest 6 bytes filles with zeroes, or sometimes with spaces + memcpy(sceSec + 0x30, " 40", 4); // or " 120" for PSX DESR, reference for ps2 area size. The rest bytes filled with zeroes - // purpose of next 12 bytes is unknown - sceSec[0x44] = 0; // always zero - sceSec[0x45] = 0; // always zero - sceSec[0x46] = 0x1a; - sceSec[0x47] = 0x01; - sceSec[0x48] = 0x02; - sceSec[0x49] = 0x20; - sceSec[0x4a] = 0; // always zero - sceSec[0x4b] = 0; // always zero - // next 4 bytes always these values - sceSec[0x4c] = 0x01; - sceSec[0x4d] = 0x03; - sceSec[0x4e] = 0x11; - sceSec[0x4f] = 0x01; - // 0x50 - 0x80 is a random unique block of data - // 0x80 and up - zero filled + sceSec[0x40] = 0; // 0x40 - 0x43 - 4-byte HDD internal SCE serial, does not match real HDD serial, currently hardcoded to 0x1000000 + sceSec[0x41] = 0; + sceSec[0x42] = 0; + sceSec[0x43] = 0x01; - // TODO: if exists *.hddid file (size - 128-512 bytes) along with HDD image, replace generic sceSec with its content + // purpose of next 12 bytes is unknown + sceSec[0x44] = 0; // always zero + sceSec[0x45] = 0; // always zero + sceSec[0x46] = 0x1a; + sceSec[0x47] = 0x01; + sceSec[0x48] = 0x02; + sceSec[0x49] = 0x20; + sceSec[0x4a] = 0; // always zero + sceSec[0x4b] = 0; // always zero + // next 4 bytes always these values + sceSec[0x4c] = 0x01; + sceSec[0x4d] = 0x03; + sceSec[0x4e] = 0x11; + sceSec[0x4f] = 0x01; + // 0x50 - 0x80 is a random unique block of data + // 0x80 and up - zero filled + } pioDRQEndTransferFunc = nullptr; DRQCmdPIODataToHost(sceSec, 256 * 2, 0, 256 * 2, true);