trunk/src/emu/imagedev/floppy.c
r241515 | r241516 | |
623 | 623 | if(!image || mon) |
624 | 624 | return attotime::never; |
625 | 625 | |
626 | | int cells = image->get_track_size(cyl, ss); |
| 626 | int cells = image->get_track_size(cyl, ss, subcyl); |
627 | 627 | if(cells <= 1) |
628 | 628 | return attotime::never; |
629 | 629 | |
630 | 630 | attotime base; |
631 | 631 | UINT32 position = find_position(base, from_when); |
632 | 632 | |
633 | | const UINT32 *buf = image->get_buffer(cyl, ss); |
| 633 | const UINT32 *buf = image->get_buffer(cyl, ss, subcyl); |
634 | 634 | int index = find_index(position, buf, cells); |
635 | 635 | |
636 | 636 | if(index == -1) |
r241515 | r241516 | |
661 | 661 | for(int i=0; i != transition_count; i++) |
662 | 662 | trans_pos[i] = find_position(base, transitions[i]); |
663 | 663 | |
664 | | int cells = image->get_track_size(cyl, ss); |
665 | | UINT32 *buf = image->get_buffer(cyl, ss); |
| 664 | int cells = image->get_track_size(cyl, ss, subcyl); |
| 665 | UINT32 *buf = image->get_buffer(cyl, ss, subcyl); |
666 | 666 | |
667 | 667 | int index; |
668 | 668 | if(cells) |
669 | 669 | index = find_index(start_pos, buf, cells); |
670 | 670 | else { |
671 | 671 | index = 0; |
672 | | image->set_track_size(cyl, ss, 1); |
673 | | buf = image->get_buffer(cyl, ss); |
| 672 | image->set_track_size(cyl, ss, 1, subcyl); |
| 673 | buf = image->get_buffer(cyl, ss, subcyl); |
674 | 674 | buf[cells++] = floppy_image::MG_N; |
675 | 675 | } |
676 | 676 | |
r241515 | r241516 | |
684 | 684 | UINT32 pos = start_pos; |
685 | 685 | int ti = 0; |
686 | 686 | while(pos != end_pos) { |
687 | | if(image->get_track_size(cyl, ss) < cells+10) { |
688 | | image->set_track_size(cyl, ss, cells+200); |
689 | | buf = image->get_buffer(cyl, ss); |
| 687 | if(image->get_track_size(cyl, ss, subcyl) < cells+10) { |
| 688 | image->set_track_size(cyl, ss, cells+200, subcyl); |
| 689 | buf = image->get_buffer(cyl, ss, subcyl); |
690 | 690 | } |
691 | 691 | UINT32 next_pos; |
692 | 692 | if(ti != transition_count) |
r241515 | r241516 | |
704 | 704 | cur_mg = cur_mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A; |
705 | 705 | } |
706 | 706 | |
707 | | image->set_track_size(cyl, ss, cells); |
| 707 | image->set_track_size(cyl, ss, cells, subcyl); |
708 | 708 | } |
709 | 709 | |
710 | 710 | void floppy_image_device::write_zone(UINT32 *buf, int &cells, int &index, UINT32 spos, UINT32 epos, UINT32 mg) |
r241515 | r241516 | |
812 | 812 | image_dirty = true; |
813 | 813 | attotime base; |
814 | 814 | int splice_pos = find_position(base, when); |
815 | | image->set_write_splice_position(cyl, ss, splice_pos); |
| 815 | image->set_write_splice_position(cyl, ss, splice_pos, subcyl); |
816 | 816 | } |
817 | 817 | } |
818 | 818 | |
trunk/src/lib/formats/ap2_dsk.c
r241515 | r241516 | |
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | const floppy_format_type FLOPPY_RWTS18_FORMAT = &floppy_image_format_creator<a2_rwts18_format>; |
| 1516 | |
| 1517 | a2_edd_format::a2_edd_format() : floppy_image_format_t() |
| 1518 | { |
| 1519 | } |
| 1520 | |
| 1521 | const char *a2_edd_format::name() const |
| 1522 | { |
| 1523 | return "a2_edd"; |
| 1524 | } |
| 1525 | |
| 1526 | const char *a2_edd_format::description() const |
| 1527 | { |
| 1528 | return "Apple II EDD Image"; |
| 1529 | } |
| 1530 | |
| 1531 | const char *a2_edd_format::extensions() const |
| 1532 | { |
| 1533 | return "edd"; |
| 1534 | } |
| 1535 | |
| 1536 | bool a2_edd_format::supports_save() const |
| 1537 | { |
| 1538 | return true; |
| 1539 | } |
| 1540 | |
| 1541 | int a2_edd_format::identify(io_generic *io, UINT32 form_factor) |
| 1542 | { |
| 1543 | return io_generic_size(io) == 2244608 ? 50 : 0; |
| 1544 | } |
| 1545 | |
| 1546 | UINT8 a2_edd_format::pick(const UINT8 *data, int pos) |
| 1547 | { |
| 1548 | return ((data[pos>>3] << 8) | data[(pos>>3)+1]) >> (8-(pos & 7)); |
| 1549 | } |
| 1550 | |
| 1551 | bool a2_edd_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 1552 | { |
| 1553 | UINT8 img[2244608]; |
| 1554 | UINT8 nibble[16384], stream[16384]; |
| 1555 | int npos[16384]; |
| 1556 | io_generic_read(io, img, 0, 2244608); |
| 1557 | |
| 1558 | for(int i=0; i<137; i++) { |
| 1559 | const UINT8 *trk = img + 16384*i; |
| 1560 | int pos = 0; |
| 1561 | int wpos = 0; |
| 1562 | while(pos < 16383*8) { |
| 1563 | UINT8 acc = pick(trk, pos); |
| 1564 | pos += 8; |
| 1565 | while(!(acc & 0x80) && pos < 16384*8) { |
| 1566 | acc <<= 1; |
| 1567 | if(trk[pos >> 3] & (0x80 >> (pos & 7))) |
| 1568 | acc |= 0x01; |
| 1569 | pos++; |
| 1570 | } |
| 1571 | if(acc & 0x80) { |
| 1572 | nibble[wpos] = acc; |
| 1573 | npos[wpos] = pos; |
| 1574 | wpos++; |
| 1575 | } |
| 1576 | } |
| 1577 | int nm = 0, nmj = 0, nmk = 0; |
| 1578 | for(int j=0; j<wpos-1; j++) |
| 1579 | for(int k=j+6200; k<wpos && k<j+6400; k++) { |
| 1580 | int m = 0; |
| 1581 | for(int l=0; k+l<wpos && nibble[j+l] == nibble[k+l]; l++) |
| 1582 | m++; |
| 1583 | if(m > nm) { |
| 1584 | nm = m; |
| 1585 | nmj = j; |
| 1586 | nmk = k; |
| 1587 | } |
| 1588 | } |
| 1589 | int delta = nmk - nmj; |
| 1590 | int spos = (wpos-delta)/2; |
| 1591 | int zpos = npos[spos]; |
| 1592 | int epos = npos[spos+delta]; |
| 1593 | int len = epos-zpos; |
| 1594 | int part1_size = zpos % len; |
| 1595 | int part1_bsize = part1_size >> 3; |
| 1596 | int part1_spos = epos-part1_size; |
| 1597 | int part2_offset = zpos - part1_size; |
| 1598 | int total_bsize = (len+7) >> 3; |
| 1599 | |
| 1600 | for(int j=0; j<part1_bsize; j++) |
| 1601 | stream[j] = pick(trk, part1_spos + 8*j); |
| 1602 | stream[part1_bsize] = |
| 1603 | (pick(trk, part1_spos + 8*part1_bsize) & (0xff00 >> (part1_size & 7))) | |
| 1604 | (pick(trk, part2_offset + 8*part1_bsize) & (0x00ff >> (part1_size & 7))); |
| 1605 | for(int j=part1_bsize+1; j<total_bsize; j++) |
| 1606 | stream[j] = pick(trk, part2_offset + 8*j); |
| 1607 | |
| 1608 | bool odd = false; |
| 1609 | for(int j=0; j<len; j++) |
| 1610 | if(stream[j>>3] & (0x80 >> (j & 7))) |
| 1611 | odd = !odd; |
| 1612 | |
| 1613 | int splice_byte = spos; |
| 1614 | while(splice_byte < spos+delta && (npos[splice_byte+1] - npos[splice_byte] != 8 || npos[splice_byte+2] - npos[splice_byte+1] == 8 || npos[splice_byte+2] - npos[splice_byte+2] == 8)) |
| 1615 | splice_byte++; |
| 1616 | int splice = (npos[splice_byte+2]-1) % len; |
| 1617 | if(odd) |
| 1618 | stream[splice >> 3] ^= 0x80 >> (splice & 7); |
| 1619 | |
| 1620 | generate_track_from_bitstream(i >> 2, 0, stream, len, image, i & 3); |
| 1621 | image->set_write_splice_position(i >> 2, 0, UINT32(U64(200000000)*splice/len), i & 3); |
| 1622 | } |
| 1623 | return true; |
| 1624 | } |
| 1625 | |
| 1626 | const floppy_format_type FLOPPY_EDD_FORMAT = &floppy_image_format_creator<a2_edd_format>; |
trunk/src/lib/formats/ap2_dsk.h
r241515 | r241516 | |
80 | 80 | |
81 | 81 | extern const floppy_format_type FLOPPY_RWTS18_FORMAT; |
82 | 82 | |
| 83 | |
| 84 | class a2_edd_format : public floppy_image_format_t |
| 85 | { |
| 86 | public: |
| 87 | a2_edd_format(); |
| 88 | |
| 89 | virtual int identify(io_generic *io, UINT32 form_factor); |
| 90 | virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image); |
| 91 | virtual bool supports_save() const; |
| 92 | |
| 93 | virtual const char *name() const; |
| 94 | virtual const char *description() const; |
| 95 | virtual const char *extensions() const; |
| 96 | |
| 97 | private: |
| 98 | static UINT8 pick(const UINT8 *data, int pos); |
| 99 | }; |
| 100 | |
| 101 | extern const floppy_format_type FLOPPY_EDD_FORMAT; |
| 102 | |
83 | 103 | #endif /* AP2_DISK_H */ |
trunk/src/lib/formats/flopimg.c
r241515 | r241516 | |
1647 | 1647 | } |
1648 | 1648 | } |
1649 | 1649 | |
1650 | | void floppy_image_format_t::generate_track_from_bitstream(int track, int head, const UINT8 *trackbuf, int track_size, floppy_image *image) |
| 1650 | void floppy_image_format_t::generate_track_from_bitstream(int track, int head, const UINT8 *trackbuf, int track_size, floppy_image *image, int subtrack) |
1651 | 1651 | { |
1652 | 1652 | // Maximal number of cells which happens when the buffer is all 1 |
1653 | | image->set_track_size(track, head, track_size+1); |
1654 | | UINT32 *dest = image->get_buffer(track, head); |
| 1653 | image->set_track_size(track, head, track_size+1, subtrack); |
| 1654 | UINT32 *dest = image->get_buffer(track, head, subtrack); |
1655 | 1655 | UINT32 *base = dest; |
1656 | 1656 | |
1657 | 1657 | UINT32 cbit = floppy_image::MG_A; |
r241515 | r241516 | |
1669 | 1669 | |
1670 | 1670 | int size = dest - base; |
1671 | 1671 | normalize_times(base, size); |
1672 | | image->set_track_size(track, head, size); |
1673 | | image->set_write_splice_position(track, head, 0); |
| 1672 | image->set_track_size(track, head, size, subtrack); |
| 1673 | image->set_write_splice_position(track, head, 0, subtrack); |
1674 | 1674 | } |
1675 | 1675 | |
1676 | 1676 | void floppy_image_format_t::generate_track_from_levels(int track, int head, UINT32 *trackbuf, int track_size, int splice_pos, floppy_image *image) |
r241515 | r241516 | |
2166 | 2166 | { END } |
2167 | 2167 | }; |
2168 | 2168 | |
2169 | | void floppy_image_format_t::generate_bitstream_from_track(int track, int head, int cell_size, UINT8 *trackbuf, int &track_size, floppy_image *image) |
| 2169 | void floppy_image_format_t::generate_bitstream_from_track(int track, int head, int cell_size, UINT8 *trackbuf, int &track_size, floppy_image *image, int subtrack) |
2170 | 2170 | { |
2171 | | int tsize = image->get_track_size(track, head); |
| 2171 | int tsize = image->get_track_size(track, head, subtrack); |
2172 | 2172 | if(!tsize || tsize == 1) { |
2173 | 2173 | // Unformatted track |
2174 | 2174 | track_size = 200000000/cell_size; |
r241515 | r241516 | |
2177 | 2177 | } |
2178 | 2178 | |
2179 | 2179 | // Start at the write splice |
2180 | | const UINT32 *tbuf = image->get_buffer(track, head); |
2181 | | UINT32 splice = image->get_write_splice_position(track, head); |
| 2180 | const UINT32 *tbuf = image->get_buffer(track, head, subtrack); |
| 2181 | UINT32 splice = image->get_write_splice_position(track, head, subtrack); |
2182 | 2182 | int cur_pos = splice; |
2183 | 2183 | int cur_entry = 0; |
2184 | 2184 | while(cur_entry < tsize-1 && (tbuf[cur_entry+1] & floppy_image::TIME_MASK) < cur_pos) |
trunk/src/lib/formats/flopimg.h
r241515 | r241516 | |
381 | 381 | @param track_size in cells, not bytes. |
382 | 382 | @param image |
383 | 383 | */ |
384 | | void generate_track_from_bitstream(int track, int head, const UINT8 *trackbuf, int track_size, floppy_image *image); |
| 384 | void generate_track_from_bitstream(int track, int head, const UINT8 *trackbuf, int track_size, floppy_image *image, int subtrack = 0); |
385 | 385 | |
386 | 386 | //! @brief Generate a track from cell level values (0/1/W/D/N). |
387 | 387 | |
r241515 | r241516 | |
477 | 477 | @endverbatim |
478 | 478 | */ |
479 | 479 | |
480 | | void generate_bitstream_from_track(int track, int head, int cell_size, UINT8 *trackbuf, int &track_size, floppy_image *image); |
| 480 | void generate_bitstream_from_track(int track, int head, int cell_size, UINT8 *trackbuf, int &track_size, floppy_image *image, int subtrack = 0); |
481 | 481 | |
482 | 482 | //! Defines a standard sector for extracting. |
483 | 483 | struct desc_xs { |