MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / LoadSnapshotHDDUnit

Method LoadSnapshotHDDUnit

source/Harddisk.cpp:1340–1417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1338}
1339
1340bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, const UINT unit, const UINT version)
1341{
1342 const UINT baseUnitNum = (version >= 5) ? 1 : 0;
1343
1344 std::string hddUnitName = std::string(SS_YAML_KEY_HDDUNIT) + (char)('0' + baseUnitNum + unit);
1345 if (!yamlLoadHelper.GetSubMap(hddUnitName))
1346 return false; // No HDD plugged in for this unit#
1347
1348 m_hardDiskDrive[unit].m_fullname.clear();
1349 m_hardDiskDrive[unit].m_imagename.clear();
1350 m_hardDiskDrive[unit].m_imageloaded = false; // Default to false (until image is successfully loaded below)
1351 m_hardDiskDrive[unit].m_status_next = DISK_STATUS_OFF;
1352 m_hardDiskDrive[unit].m_status_prev = DISK_STATUS_OFF;
1353
1354 const std::string simpleFilename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME);
1355 const std::string absolutePath = version >= 6 ? yamlLoadHelper.LoadString(SS_YAML_KEY_ABSOLUTE_PATH) : "";
1356 m_hardDiskDrive[unit].m_error = yamlLoadHelper.LoadUint(SS_YAML_KEY_ERROR);
1357 m_hardDiskDrive[unit].m_memblock = yamlLoadHelper.LoadUint(SS_YAML_KEY_MEMBLOCK);
1358 m_hardDiskDrive[unit].m_diskblock = yamlLoadHelper.LoadUint(SS_YAML_KEY_DISKBLOCK);
1359 yamlLoadHelper.LoadBool(SS_YAML_KEY_IMAGELOADED); // Consume
1360 Disk_Status_e diskStatusNext = (Disk_Status_e) yamlLoadHelper.LoadUint(SS_YAML_KEY_STATUS_NEXT);
1361 Disk_Status_e diskStatusPrev = (Disk_Status_e) yamlLoadHelper.LoadUint(SS_YAML_KEY_STATUS_PREV);
1362 m_hardDiskDrive[unit].m_buf_ptr = yamlLoadHelper.LoadUint(SS_YAML_KEY_BUF_PTR);
1363 if (m_hardDiskDrive[unit].m_buf_ptr >= sizeof(m_hardDiskDrive[unit].m_buf)) // pre-v3 save-states would leave m_buf_ptr==0x200 after reading a block
1364 m_hardDiskDrive[unit].m_buf_ptr = sizeof(m_hardDiskDrive[unit].m_buf) - 1;
1365
1366 if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_BUF))
1367 throw std::runtime_error(hddUnitName + ": Missing: " + SS_YAML_KEY_BUF);
1368 yamlLoadHelper.LoadMemory(m_hardDiskDrive[unit].m_buf, HD_BLOCK_SIZE);
1369 yamlLoadHelper.PopMap();
1370
1371 yamlLoadHelper.PopMap();
1372
1373 //
1374
1375 bool userSelectedImageFolder = false;
1376
1377 std::string filename = simpleFilename;
1378 if (!filename.empty())
1379 {
1380 DWORD dwAttributes = GetFileAttributes(filename.c_str());
1381 if (dwAttributes == INVALID_FILE_ATTRIBUTES && !absolutePath.empty())
1382 {
1383 // try the absolute path if present
1384 filename = absolutePath;
1385 dwAttributes = GetFileAttributes(filename.c_str());
1386 }
1387
1388 if (dwAttributes == INVALID_FILE_ATTRIBUTES)
1389 {
1390 // ignore absolute name when opening the file dialog
1391 filename = simpleFilename;
1392 // Get user to browse for file
1393 userSelectedImageFolder = SelectImage(unit, filename.c_str());
1394
1395 dwAttributes = GetFileAttributes(filename.c_str());
1396 }
1397

Callers

nothing calls this directly

Calls 7

LoadStringMethod · 0.80
LoadUintMethod · 0.80
LoadBoolMethod · 0.80
LoadMemoryMethod · 0.80
PopMapMethod · 0.80
GetSubMapMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected