MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / parsemds

Function parsemds

src/blkdev_cdimage.cpp:1476–1568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1474#pragma pack()
1475
1476static int parsemds (struct cdunit *cdu, struct zfile *zmds, const TCHAR *img, const TCHAR *curdir, const TCHAR *occurdir)
1477{
1478 MDS_Header *head;
1479 struct cdtoc *t;
1480 uae_u8 *mds = NULL;
1481 uae_u32 size;
1482 MDS_SessionBlock *sb;
1483
1484 if (curdir)
1485 my_setcurrentdir(occurdir, NULL);
1486
1487 write_log (_T("MDS TOC: '%s'\n"), img);
1488 size = zfile_size32(zmds);
1489 mds = xmalloc (uae_u8, size);
1490 if (!mds)
1491 goto end;
1492 if (zfile_fread (mds, size, 1, zmds) != 1)
1493 goto end;
1494
1495 head = (MDS_Header*)mds;
1496 if (!memcmp (head->signature, MEDIA_DESCRIPTOR, sizeof(MEDIA_DESCRIPTOR)))
1497 goto end;
1498 if (head->version[0] != 1) {
1499 write_log (_T("unsupported MDS version %d, only v.1 supported\n"), head->version[0]);
1500 goto end;
1501 }
1502
1503 sb = (MDS_SessionBlock*)(mds + head->sessions_blocks_offset);
1504 cdu->tracks = sb->last_track - sb->first_track + 1;
1505 for (int i = 0; i < sb->num_all_blocks; i++) {
1506 MDS_TrackBlock *tb = (MDS_TrackBlock*)(mds + sb->tracks_blocks_offset + i * sizeof (MDS_TrackBlock));
1507 int point = tb->point;
1508 int tracknum = -1;
1509 if (point == 0xa2)
1510 tracknum = cdu->tracks;
1511 else if (point >= 1 && point <= 99)
1512 tracknum = point - 1;
1513 if (tracknum >= 0) {
1514 MDS_Footer *footer = tb->footer_offset == 0 ? NULL : (MDS_Footer*)(mds + tb->footer_offset);
1515 MDS_TrackExtraBlock *teb = tb->extra_offset == 0 ? NULL : (MDS_TrackExtraBlock*)(mds + tb->extra_offset);
1516 t = &cdu->toc[tracknum];
1517 t->adr = tb->adr_ctl >> 4;
1518 t->ctrl = tb->adr_ctl & 15;
1519 if (point == 0xa2)
1520 t->address = sb->session_end;
1521 else
1522 t->address = tb->start_sector;
1523 t->track = point;
1524 t->offset = tb->start_offset;
1525 t->size = tb->sector_size;
1526
1527 if (point >= 100)
1528 continue;
1529
1530 if (footer) {
1531 TCHAR *fname = NULL;
1532 if (footer->widechar_filename == 0)
1533 fname = au ((char*)(mds + footer->filename_offset));

Callers 1

parse_imageFunction · 0.85

Calls 8

my_setcurrentdirFunction · 0.85
zfile_size32Function · 0.85
zfile_freadFunction · 0.85
auFunction · 0.85
zfile_fopenFunction · 0.85
zfile_sizeFunction · 0.85
zfile_dupFunction · 0.85
write_logFunction · 0.70

Tested by

no test coverage detected