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

Method ProcessChunks

source/DiskImageHelper.cpp:1519–1586  ·  view source on GitHub ↗

Pre: already matched the WOZ header

Source from the content-addressed store, hash-verified

1517
1518// Pre: already matched the WOZ header
1519eDetectResult CWOZHelper::ProcessChunks(ImageInfo* pImageInfo, uint32_t& dwOffset)
1520{
1521 UINT32* pImage32 = (uint32_t*) (pImageInfo->pImageBuffer + sizeof(WOZHeader));
1522 int imageSizeRemaining = pImageInfo->uImageSize - sizeof(WOZHeader);
1523 _ASSERT(imageSizeRemaining >= 0);
1524 if (imageSizeRemaining < 0)
1525 return eMismatch;
1526
1527 // A valid WOZ must have exactly one of each of: INFO, TMAP & TRKS chunks (GH#1402)
1528 bool gotINFO = false;
1529 bool gotTMAP = false;
1530 bool gotTRKS = false;
1531
1532 while(imageSizeRemaining >= sizeof(WOZChunkHdr))
1533 {
1534 UINT32 chunkId = *pImage32++;
1535 UINT32 chunkSize = *pImage32++;
1536 imageSizeRemaining -= sizeof(WOZChunkHdr);
1537
1538 switch(chunkId)
1539 {
1540 case INFO_CHUNK_ID:
1541 if (gotINFO) return eMismatch;
1542 gotINFO = true;
1543 m_pInfo = (InfoChunkv2*)pImage32;
1544 if (m_pInfo->v1.diskType != InfoChunk::diskType5_25)
1545 return eMismatch;
1546#ifdef _DEBUG
1547 if (m_pInfo->v1.version >= 3)
1548 {
1549 InfoChunkv3* pInfoV3 = (InfoChunkv3*)pImage32;
1550 LogOutput("WOZ: Largest Flux Track = %d\n", pInfoV3->largestFluxTrack);
1551 }
1552#endif
1553 break;
1554 case TMAP_CHUNK_ID:
1555 if (gotTMAP) return eMismatch;
1556 gotTMAP = true;
1557 pImageInfo->pWOZTrackMap = (BYTE*) pImage32;
1558 break;
1559 case TRKS_CHUNK_ID:
1560 if (gotTRKS) return eMismatch;
1561 gotTRKS = true;
1562 dwOffset = pImageInfo->uOffset = pImageInfo->uImageSize - imageSizeRemaining; // offset into image of track data
1563 break;
1564 case FLUX_CHUNK_ID: // WOZ v3 (todo)
1565 break;
1566 case WRIT_CHUNK_ID: // WOZ v2 (optional)
1567 break;
1568 case META_CHUNK_ID: // (optional)
1569 break;
1570 default: // no idea what this chunk is, so skip it
1571 _ASSERT(0);
1572 break;
1573 }
1574
1575 pImage32 = (UINT32*) ((BYTE*)pImage32 + chunkSize);
1576 imageSizeRemaining -= chunkSize;

Callers 1

WOZUpdateInfoMethod · 0.80

Calls 1

LogOutputFunction · 0.85

Tested by

no test coverage detected