src/emu/imagedev/floppy.c
| r13734 | r13735 | |
| 12 | 12 | const device_type FLOPPY_CONNECTOR = &device_creator<floppy_connector>; |
| 13 | 13 | const device_type FLOPPY_35_DD = &device_creator<floppy_35_dd>; |
| 14 | 14 | const device_type FLOPPY_35_HD = &device_creator<floppy_35_hd>; |
| 15 | const device_type FLOPPY_35_ED = &device_creator<floppy_35_ed>; |
| 15 | 16 | const device_type FLOPPY_525_DD = &device_creator<floppy_525_dd>; |
| 16 | 17 | |
| 17 | 18 | floppy_connector::floppy_connector(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| r13734 | r13735 | |
| 136 | 137 | void floppy_image_device::device_start() |
| 137 | 138 | { |
| 138 | 139 | rpm = 0; |
| 139 | | setup_limits(); |
| 140 | setup_characteristics(); |
| 140 | 141 | |
| 141 | 142 | idx = 0; |
| 142 | 143 | |
| r13734 | r13735 | |
| 174 | 175 | int best = 0; |
| 175 | 176 | floppy_image_format_t *best_format = 0; |
| 176 | 177 | for(floppy_image_format_t *format = fif_list; format; format = format->next) { |
| 177 | | int score = format->identify(&io); |
| 178 | int score = format->identify(&io, form_factor); |
| 178 | 179 | if(score > best) { |
| 179 | 180 | best = score; |
| 180 | 181 | best_format = format; |
| r13734 | r13735 | |
| 184 | 185 | if(!best_format) |
| 185 | 186 | return IMAGE_INIT_FAIL; |
| 186 | 187 | |
| 187 | | image = global_alloc(floppy_image(tracks, sides)); |
| 188 | | best_format->load(&io, image); |
| 188 | image = global_alloc(floppy_image(tracks, sides, form_factor)); |
| 189 | best_format->load(&io, form_factor, image); |
| 189 | 190 | |
| 190 | 191 | revolution_start_time = attotime::never; |
| 191 | 192 | revolution_count = 0; |
| r13734 | r13735 | |
| 538 | 539 | { |
| 539 | 540 | } |
| 540 | 541 | |
| 541 | | void floppy_35_dd::setup_limits() |
| 542 | void floppy_35_dd::setup_characteristics() |
| 542 | 543 | { |
| 544 | form_factor = floppy_image::FF_35; |
| 543 | 545 | tracks = 84; |
| 544 | 546 | sides = 2; |
| 545 | 547 | set_rpm(300); |
| r13734 | r13735 | |
| 554 | 556 | { |
| 555 | 557 | } |
| 556 | 558 | |
| 557 | | void floppy_35_hd::setup_limits() |
| 559 | void floppy_35_hd::setup_characteristics() |
| 558 | 560 | { |
| 561 | form_factor = floppy_image::FF_35; |
| 559 | 562 | tracks = 84; |
| 560 | 563 | sides = 2; |
| 561 | 564 | set_rpm(300); |
| 562 | 565 | } |
| 563 | 566 | |
| 567 | floppy_35_ed::floppy_35_ed(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 568 | floppy_image_device(mconfig, FLOPPY_35_ED, "3.5\" extended density floppy drive", tag, owner, clock) |
| 569 | { |
| 570 | } |
| 564 | 571 | |
| 572 | floppy_35_ed::~floppy_35_ed() |
| 573 | { |
| 574 | } |
| 575 | |
| 576 | void floppy_35_ed::setup_characteristics() |
| 577 | { |
| 578 | form_factor = floppy_image::FF_35; |
| 579 | tracks = 84; |
| 580 | sides = 2; |
| 581 | set_rpm(300); |
| 582 | } |
| 583 | |
| 584 | |
| 565 | 585 | floppy_525_dd::floppy_525_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 566 | 586 | floppy_image_device(mconfig, FLOPPY_525_DD, "5.25\" double density floppy drive", tag, owner, clock) |
| 567 | 587 | { |
| r13734 | r13735 | |
| 571 | 591 | { |
| 572 | 592 | } |
| 573 | 593 | |
| 574 | | void floppy_525_dd::setup_limits() |
| 594 | void floppy_525_dd::setup_characteristics() |
| 575 | 595 | { |
| 596 | form_factor = floppy_image::FF_525; |
| 576 | 597 | tracks = 42; |
| 577 | 598 | sides = 1; |
| 578 | 599 | set_rpm(300); |
src/emu/imagedev/floppy.h
| r13734 | r13735 | |
| 75 | 75 | attotime time_next_index(); |
| 76 | 76 | attotime get_next_transition(attotime from_when); |
| 77 | 77 | void write_flux(attotime start, attotime end, int transition_count, const attotime *transitions); |
| 78 | void set_write_splice(attotime when); |
| 79 | UINT32 get_form_factor() const; |
| 80 | UINT32 get_variant() const; |
| 78 | 81 | |
| 79 | 82 | protected: |
| 80 | 83 | // device-level overrides |
| r13734 | r13735 | |
| 83 | 86 | virtual void device_reset(); |
| 84 | 87 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 85 | 88 | |
| 86 | | virtual void setup_limits() = 0; |
| 89 | virtual void setup_characteristics() = 0; |
| 87 | 90 | |
| 88 | 91 | image_device_format format; |
| 89 | 92 | floppy_image *image; |
| r13734 | r13735 | |
| 91 | 94 | floppy_image_format_t *fif_list; |
| 92 | 95 | emu_timer *index_timer; |
| 93 | 96 | |
| 94 | | /* Physical characteristics, filled by setup_limits */ |
| 97 | /* Physical characteristics, filled by setup_characteristics */ |
| 95 | 98 | int tracks; /* addressable tracks */ |
| 96 | 99 | int sides; /* number of heads */ |
| 100 | UINT32 form_factor; /* 3"5, 5"25, etc */ |
| 97 | 101 | |
| 98 | 102 | /* state of input lines */ |
| 99 | 103 | int dir; /* direction */ |
| r13734 | r13735 | |
| 130 | 134 | virtual ~floppy_35_dd(); |
| 131 | 135 | |
| 132 | 136 | protected: |
| 133 | | virtual void setup_limits(); |
| 137 | virtual void setup_characteristics(); |
| 134 | 138 | }; |
| 135 | 139 | |
| 136 | 140 | class floppy_35_hd : public floppy_image_device { |
| r13734 | r13735 | |
| 139 | 143 | virtual ~floppy_35_hd(); |
| 140 | 144 | |
| 141 | 145 | protected: |
| 142 | | virtual void setup_limits(); |
| 146 | virtual void setup_characteristics(); |
| 143 | 147 | }; |
| 144 | 148 | |
| 149 | class floppy_35_ed : public floppy_image_device { |
| 150 | public: |
| 151 | floppy_35_ed(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 152 | virtual ~floppy_35_ed(); |
| 153 | |
| 154 | protected: |
| 155 | virtual void setup_characteristics(); |
| 156 | }; |
| 157 | |
| 145 | 158 | class floppy_525_dd : public floppy_image_device { |
| 146 | 159 | public: |
| 147 | 160 | floppy_525_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 148 | 161 | virtual ~floppy_525_dd(); |
| 149 | 162 | |
| 150 | 163 | protected: |
| 151 | | virtual void setup_limits(); |
| 164 | virtual void setup_characteristics(); |
| 152 | 165 | }; |
| 153 | 166 | |
| 154 | 167 | class floppy_connector: public device_t, |
| r13734 | r13735 | |
| 174 | 187 | extern const device_type FLOPPY_CONNECTOR; |
| 175 | 188 | extern const device_type FLOPPY_35_DD; |
| 176 | 189 | extern const device_type FLOPPY_35_HD; |
| 190 | extern const device_type FLOPPY_35_ED; |
| 177 | 191 | extern const device_type FLOPPY_525_DD; |
| 178 | 192 | |
| 179 | 193 | #endif /* FLOPPY_H */ |
src/lib/formats/flopimg.c
| r13734 | r13735 | |
| 942 | 942 | /// New implementation |
| 943 | 943 | ////////////////////////////////////////////////////////// |
| 944 | 944 | |
| 945 | | floppy_image::floppy_image(int _tracks, int _heads) |
| 945 | floppy_image::floppy_image(int _tracks, int _heads, UINT32 _form_factor) |
| 946 | 946 | { |
| 947 | 947 | tracks = _tracks; |
| 948 | 948 | heads = _heads; |
| 949 | 949 | |
| 950 | form_factor = _form_factor; |
| 951 | variant = 0; |
| 952 | |
| 950 | 953 | memset(cell_data, 0, sizeof(cell_data)); |
| 951 | 954 | memset(track_size, 0, sizeof(track_size)); |
| 952 | 955 | memset(track_alloc_size, 0, sizeof(track_alloc_size)); |
| 956 | memset(write_splice, 0, sizeof(write_splice)); |
| 953 | 957 | } |
| 954 | 958 | |
| 955 | 959 | floppy_image::~floppy_image() |
| r13734 | r13735 | |
| 992 | 996 | |
| 993 | 997 | void floppy_image::ensure_alloc(int track, int head) |
| 994 | 998 | { |
| 995 | | int idx = (track << 1) + head; |
| 996 | | if(track_size[idx] > track_alloc_size[idx]) { |
| 997 | | UINT32 new_size = track_size[idx]*11/10; |
| 999 | if(track_size[track][head] > track_alloc_size[track][head]) { |
| 1000 | UINT32 new_size = track_size[track][head]*11/10; |
| 998 | 1001 | UINT32 *new_array = global_alloc_array(UINT32, new_size); |
| 999 | | if(track_alloc_size[idx]) { |
| 1000 | | memcpy(new_array, cell_data[idx], track_alloc_size[idx]*4); |
| 1001 | | global_free(cell_data[idx]); |
| 1002 | if(track_alloc_size[track][head]) { |
| 1003 | memcpy(new_array, cell_data[track][head], track_alloc_size[track][head]*4); |
| 1004 | global_free(cell_data[track][head]); |
| 1002 | 1005 | } |
| 1003 | | cell_data[idx] = new_array; |
| 1004 | | track_alloc_size[idx] = new_size; |
| 1006 | cell_data[track][head] = new_array; |
| 1007 | track_alloc_size[track][head] = new_size; |
| 1005 | 1008 | } |
| 1006 | 1009 | } |
| 1007 | 1010 | |
| r13734 | r13735 | |
| 1375 | 1378 | int size = dest - base; |
| 1376 | 1379 | normalize_times(base, size); |
| 1377 | 1380 | image->set_track_size(track, head, size); |
| 1381 | image->set_write_splice_position(track, head, 0); |
| 1378 | 1382 | } |
| 1379 | 1383 | |
| 1380 | 1384 | void floppy_image_format_t::generate_track_from_levels(int track, int head, UINT32 *trackbuf, int track_size, int splice_pos, floppy_image *image) |
| 1381 | 1385 | { |
| 1386 | // Retrieve the angular splice pos before messing with the data |
| 1387 | splice_pos = splice_pos % track_size; |
| 1388 | UINT32 splice_angular_pos = trackbuf[splice_pos] & floppy_image::TIME_MASK; |
| 1389 | |
| 1382 | 1390 | // Check if we need to invert a cell to get an even number of |
| 1383 | 1391 | // transitions on the whole track |
| 1384 | 1392 | // |
| r13734 | r13735 | |
| 1406 | 1414 | } |
| 1407 | 1415 | |
| 1408 | 1416 | if(transition_count & 1) { |
| 1409 | | splice_pos = splice_pos % track_size; |
| 1410 | 1417 | int pos = splice_pos; |
| 1411 | 1418 | while((trackbuf[pos] & floppy_image::MG_MASK) != MG_0 && (trackbuf[pos] & floppy_image::MG_MASK) != MG_1) { |
| 1412 | 1419 | pos++; |
| r13734 | r13735 | |
| 1457 | 1464 | int size = dest - base; |
| 1458 | 1465 | normalize_times(base, size); |
| 1459 | 1466 | image->set_track_size(track, head, size); |
| 1467 | image->set_write_splice_position(track, head, splice_angular_pos); |
| 1460 | 1468 | } |
| 1461 | 1469 | |
| 1462 | 1470 | // Atari ST Fastcopy Pro layouts |
| r13734 | r13735 | |
| 1792 | 1800 | { END } |
| 1793 | 1801 | }; |
| 1794 | 1802 | |
| 1803 | const floppy_image_format_t::desc_e floppy_image_format_t::amiga_22[] = { |
| 1804 | { SECTOR_LOOP_START, 0, 21 }, |
| 1805 | { MFM, 0x00, 2 }, |
| 1806 | { RAW, 0x4489, 2 }, |
| 1807 | { CRC_AMIGA_START, 1 }, |
| 1808 | { MFMBITS, 0xf, 4 }, |
| 1809 | { OFFSET_ID_O }, |
| 1810 | { SECTOR_ID_O }, |
| 1811 | { REMAIN_O, 11 }, |
| 1812 | { MFMBITS, 0xf, 4 }, |
| 1813 | { OFFSET_ID_E }, |
| 1814 | { SECTOR_ID_E }, |
| 1815 | { REMAIN_E, 11 }, |
| 1816 | { MFM, 0x00, 16 }, |
| 1817 | { CRC_END, 1 }, |
| 1818 | { CRC, 1 }, |
| 1819 | { CRC, 2 }, |
| 1820 | { CRC_AMIGA_START, 2 }, |
| 1821 | { SECTOR_DATA_O, -1 }, |
| 1822 | { SECTOR_DATA_E, -1 }, |
| 1823 | { CRC_END, 2 }, |
| 1824 | { SECTOR_LOOP_END }, |
| 1825 | { MFM, 0x00, 532 }, |
| 1826 | { END } |
| 1827 | }; |
| 1828 | |
| 1795 | 1829 | void floppy_image_format_t::generate_bitstream_from_track(int track, int head, int cell_size, UINT8 *trackbuf, int &track_size, floppy_image *image) |
| 1796 | 1830 | { |
| 1797 | 1831 | int tsize = image->get_track_size(track, head); |
| r13734 | r13735 | |
| 1802 | 1836 | return; |
| 1803 | 1837 | } |
| 1804 | 1838 | |
| 1805 | | // Start a little before the end of the track to pre-synchronize |
| 1806 | | // the pll |
| 1839 | // Start at the write splice |
| 1807 | 1840 | const UINT32 *tbuf = image->get_buffer(track, head); |
| 1808 | | int cur_pos = 190000000; |
| 1809 | | int cur_entry = tsize-1; |
| 1810 | | while((tbuf[cur_entry] & floppy_image::TIME_MASK) > cur_pos) |
| 1811 | | cur_entry--; |
| 1812 | | cur_entry++; |
| 1813 | | if(cur_entry == tsize) |
| 1814 | | cur_entry = 0; |
| 1841 | UINT32 splice = image->get_write_splice_position(track, head); |
| 1842 | int cur_pos = splice; |
| 1843 | int cur_entry = 0; |
| 1844 | while(cur_entry < tsize-1 && (tbuf[cur_entry+1] & floppy_image::TIME_MASK) < cur_pos) |
| 1845 | cur_entry++; |
| 1815 | 1846 | |
| 1816 | | int cur_bit = -1; |
| 1847 | int cur_bit = 0; |
| 1817 | 1848 | |
| 1818 | 1849 | int period = cell_size; |
| 1819 | 1850 | int period_adjust_base = period * 0.05; |
| r13734 | r13735 | |
| 1823 | 1854 | int phase_adjust = 0; |
| 1824 | 1855 | int freq_hist = 0; |
| 1825 | 1856 | |
| 1826 | | for(;;) { |
| 1857 | UINT32 scanned = 0; |
| 1858 | while(scanned < 200000000) { |
| 1827 | 1859 | // Note that all magnetic cell type changes are considered |
| 1828 | 1860 | // edges. No randomness added for neutral/damaged cells |
| 1829 | 1861 | int edge = tbuf[cur_entry] & floppy_image::TIME_MASK; |
| 1830 | 1862 | if(edge < cur_pos) |
| 1831 | 1863 | edge += 200000000; |
| 1832 | 1864 | int next = cur_pos + period + phase_adjust; |
| 1865 | scanned += period + phase_adjust; |
| 1833 | 1866 | |
| 1834 | 1867 | if(edge >= next) { |
| 1835 | 1868 | // No transition in the window means 0 and pll in free run mode |
| 1836 | | if(cur_bit >= 0) { |
| 1837 | | trackbuf[cur_bit >> 3] &= ~(0x80 >> (cur_bit & 7)); |
| 1838 | | cur_bit++; |
| 1839 | | } |
| 1869 | trackbuf[cur_bit >> 3] &= ~(0x80 >> (cur_bit & 7)); |
| 1870 | cur_bit++; |
| 1840 | 1871 | phase_adjust = 0; |
| 1841 | 1872 | |
| 1842 | 1873 | } else { |
| 1843 | 1874 | // Transition in the window means 1, and the pll is adjusted |
| 1844 | | if(cur_bit >= 0) { |
| 1845 | | trackbuf[cur_bit >> 3] |= 0x80 >> (cur_bit & 7); |
| 1846 | | cur_bit++; |
| 1847 | | } |
| 1875 | trackbuf[cur_bit >> 3] |= 0x80 >> (cur_bit & 7); |
| 1876 | cur_bit++; |
| 1848 | 1877 | |
| 1849 | 1878 | int delta = edge - (next - period/2); |
| 1850 | 1879 | |
| r13734 | r13735 | |
| 1881 | 1910 | |
| 1882 | 1911 | cur_pos = next; |
| 1883 | 1912 | if(cur_pos >= 200000000) { |
| 1884 | | if(cur_bit >= 0) |
| 1885 | | break; |
| 1886 | | cur_bit = 0; |
| 1887 | 1913 | cur_pos -= 200000000; |
| 1888 | 1914 | cur_entry = 0; |
| 1889 | 1915 | } |
src/lib/formats/flopimg.h
| r13734 | r13735 | |
| 225 | 225 | floppy_image_format_t(); |
| 226 | 226 | virtual ~floppy_image_format_t(); |
| 227 | 227 | |
| 228 | | virtual int identify(io_generic *io) = 0; |
| 229 | | virtual bool load(io_generic *io, floppy_image *image) = 0; |
| 228 | virtual int identify(io_generic *io, UINT32 form_factor) = 0; |
| 229 | virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image) = 0; |
| 230 | 230 | virtual bool save(io_generic *io, floppy_image *image); |
| 231 | 231 | |
| 232 | 232 | virtual const char *name() const = 0; |
| r13734 | r13735 | |
| 346 | 346 | // Standard 11 sectors per track format |
| 347 | 347 | static const desc_e amiga_11[]; |
| 348 | 348 | |
| 349 | // Standard 22 sectors per track format (guessed, to check w.r.t the real thing) |
| 350 | static const desc_e amiga_22[]; |
| 349 | 351 | |
| 352 | |
| 350 | 353 | // **** Writer helpers **** |
| 351 | 354 | |
| 352 | 355 | // Rebuild a cell bitstream for a track. Takes the cell standard |
| r13734 | r13735 | |
| 473 | 476 | // The last cell implicit end position is of course 200,000,000. |
| 474 | 477 | // |
| 475 | 478 | // Unformatted tracks are encoded as zero-size. |
| 479 | // |
| 480 | // The "track splice" information indicates where to start writing |
| 481 | // if you try to rewrite a physical disk with the data. Some |
| 482 | // preservation formats encode that information, it is guessed for |
| 483 | // others. The write track function of fdcs should set it. The |
| 484 | // representation is the angular position relative to the index. |
| 485 | // |
| 486 | // The media type is divided in two parts. The first half |
| 487 | // indicate the physical form factor, i.e. all medias with that |
| 488 | // form factor can be physically inserted in a reader that handles |
| 489 | // it. The second half indicates the variants which are usually |
| 490 | // detectable by the reader, such as density and number of sides. |
| 476 | 491 | |
| 477 | 492 | enum { |
| 478 | 493 | TIME_MASK = 0x0fffffff, |
| r13734 | r13735 | |
| 485 | 500 | MG_D = (3 << MG_SHIFT) |
| 486 | 501 | }; |
| 487 | 502 | |
| 503 | // Form factors |
| 504 | enum { |
| 505 | FF_35 = 0x20203533, // "35 " |
| 506 | FF_525 = 0x20353235, // "525 " |
| 507 | }; |
| 508 | |
| 509 | // Variants |
| 510 | enum { |
| 511 | DSDD = 0x44445344, // "DSDD", |
| 512 | DSHD = 0x44485344, // "DSHD", |
| 513 | DSED = 0x44455344, // "DSED", |
| 514 | }; |
| 515 | |
| 488 | 516 | // construction/destruction |
| 489 | | floppy_image(int tracks, int heads); |
| 517 | floppy_image(int tracks, int heads, UINT32 form_factor); |
| 490 | 518 | virtual ~floppy_image(); |
| 491 | 519 | |
| 492 | | void set_track_size(int track, int head, UINT32 size) { track_size[(track << 1) + head] = size; ensure_alloc(track, head); } |
| 493 | | UINT32 *get_buffer(int track, int head) { return cell_data[(track << 1) + head]; } |
| 494 | | UINT32 get_track_size(int track, int head) { return track_size[(track << 1) + head]; } |
| 520 | UINT32 get_form_factor() { return form_factor; } |
| 521 | UINT32 get_variant() { return variant; } |
| 522 | void set_variant(UINT32 v) { variant = v; } |
| 495 | 523 | |
| 524 | void set_track_size(int track, int head, UINT32 size) { track_size[track][head] = size; ensure_alloc(track, head); } |
| 525 | UINT32 *get_buffer(int track, int head) { return cell_data[track][head]; } |
| 526 | UINT32 get_track_size(int track, int head) { return track_size[track][head]; } |
| 527 | void set_write_splice_position(int track, int head, UINT32 pos) { write_splice[track][head] = pos; } |
| 528 | UINT32 get_write_splice_position(int track, int head) const { return write_splice[track][head]; } |
| 496 | 529 | void get_maximal_geometry(int &tracks, int &heads); |
| 497 | 530 | void get_actual_geometry(int &tracks, int &heads); |
| 498 | 531 | |
| r13734 | r13735 | |
| 504 | 537 | |
| 505 | 538 | int tracks, heads; |
| 506 | 539 | |
| 507 | | UINT32 *cell_data[MAX_FLOPPY_HEADS * MAX_FLOPPY_TRACKS]; |
| 508 | | UINT32 track_size[MAX_FLOPPY_HEADS * MAX_FLOPPY_TRACKS]; |
| 509 | | UINT32 track_alloc_size[MAX_FLOPPY_HEADS * MAX_FLOPPY_TRACKS]; |
| 540 | UINT32 form_factor, variant; |
| 510 | 541 | |
| 542 | UINT32 *cell_data[MAX_FLOPPY_TRACKS][MAX_FLOPPY_HEADS]; |
| 543 | UINT32 track_size[MAX_FLOPPY_TRACKS][MAX_FLOPPY_HEADS]; |
| 544 | UINT32 track_alloc_size[MAX_FLOPPY_TRACKS][MAX_FLOPPY_HEADS]; |
| 545 | UINT32 write_splice[MAX_FLOPPY_TRACKS][MAX_FLOPPY_HEADS]; |
| 546 | |
| 511 | 547 | void ensure_alloc(int track, int head); |
| 512 | 548 | }; |
| 513 | 549 | |
src/lib/formats/mfi_dsk.c
| r13734 | r13735 | |
| 48 | 48 | An unformatted track is equivalent to one big MG_N cell covering a |
| 49 | 49 | whole turn, but is encoded as zero-size. |
| 50 | 50 | |
| 51 | | TODO: big-endian support, cleanup pll, move it where it belongs. |
| 51 | The "track splice" information indicates where to start writing |
| 52 | if you try to rewrite a physical disk with the data. Some |
| 53 | preservation formats encode that information, it is guessed for |
| 54 | others. The write track function of fdcs should set it. The |
| 55 | representation is the angular position relative to the index. |
| 56 | |
| 57 | The media type is divided in two parts. The first half |
| 58 | indicate the physical form factor, i.e. all medias with that |
| 59 | form factor can be physically inserted in a reader that handles |
| 60 | it. The second half indicates the variants which are usually |
| 61 | detectable by the reader, such as density and number of sides. |
| 62 | |
| 63 | TODO: big-endian support |
| 52 | 64 | */ |
| 53 | 65 | |
| 54 | 66 | const char mfi_format::sign[16] = "MESSFLOPPYIMAGE"; // Includes the final \0 |
| r13734 | r13735 | |
| 77 | 89 | return true; |
| 78 | 90 | } |
| 79 | 91 | |
| 80 | | int mfi_format::identify(io_generic *io) |
| 92 | int mfi_format::identify(io_generic *io, UINT32 form_factor) |
| 81 | 93 | { |
| 82 | 94 | header h; |
| 83 | 95 | |
| 84 | 96 | io_generic_read(io, &h, 0, sizeof(header)); |
| 85 | 97 | if(memcmp( h.sign, sign, 16 ) == 0 && |
| 86 | 98 | h.cyl_count > 0 && h.cyl_count <= 84 && |
| 87 | | h.head_count > 0 && h.head_count <= 2) |
| 99 | h.head_count > 0 && h.head_count <= 2 && |
| 100 | h.form_factor == form_factor) |
| 88 | 101 | return 100; |
| 89 | 102 | return 0; |
| 90 | 103 | } |
| 91 | 104 | |
| 92 | | bool mfi_format::load(io_generic *io, floppy_image *image) |
| 105 | bool mfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 93 | 106 | { |
| 94 | 107 | header h; |
| 95 | 108 | entry entries[84*2]; |
| 96 | 109 | io_generic_read(io, &h, 0, sizeof(header)); |
| 97 | 110 | io_generic_read(io, &entries, sizeof(header), h.cyl_count*h.head_count*sizeof(entry)); |
| 98 | 111 | |
| 112 | image->set_variant(h.variant); |
| 113 | |
| 99 | 114 | UINT8 *compressed = 0; |
| 100 | 115 | int compressed_size = 0; |
| 101 | 116 | |
| r13734 | r13735 | |
| 161 | 176 | memcpy(h.sign, sign, 16); |
| 162 | 177 | h.cyl_count = tracks; |
| 163 | 178 | h.head_count = heads; |
| 179 | h.form_factor = image->get_form_factor(); |
| 180 | h.variant = image->get_variant(); |
| 164 | 181 | |
| 165 | 182 | io_generic_write(io, &h, 0, sizeof(header)); |
| 166 | 183 | |
| r13734 | r13735 | |
| 194 | 211 | entries[epos].offset = pos; |
| 195 | 212 | entries[epos].uncompressed_size = tsize*4; |
| 196 | 213 | entries[epos].compressed_size = csize; |
| 214 | entries[epos].write_splice = image->get_write_splice_position(track, head); |
| 197 | 215 | epos++; |
| 198 | 216 | |
| 199 | 217 | io_generic_write(io, postcomp, pos, csize); |
src/lib/formats/ami_dsk.c
| r13734 | r13735 | |
| 32 | 32 | return true; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | | int adf_format::identify(io_generic *io) |
| 35 | int adf_format::identify(io_generic *io, UINT32 form_factor) |
| 36 | 36 | { |
| 37 | 37 | UINT64 size = io_generic_size(io); |
| 38 | 38 | if ((size == 901120) || (size == 1802240)) |
| r13734 | r13735 | |
| 42 | 42 | return 0; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | | bool adf_format::load(io_generic *io, floppy_image *image) |
| 45 | bool adf_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 46 | 46 | { |
| 47 | | desc_s sectors[11]; |
| 48 | | UINT8 sectdata[512*11]; |
| 49 | | for(int i=0; i<11; i++) { |
| 47 | desc_s sectors[22]; |
| 48 | UINT8 sectdata[512*22]; |
| 49 | for(int i=0; i<22; i++) { |
| 50 | 50 | sectors[i].data = sectdata + 512*i; |
| 51 | 51 | sectors[i].size = 512; |
| 52 | 52 | sectors[i].sector_id = i; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | | for(int track=0; track < 80; track++) { |
| 56 | | for(int side=0; side < 2; side++) { |
| 57 | | io_generic_read(io, sectdata, (track*2 + side)*512*11, 512*11); |
| 58 | | generate_track(amiga_11, track, side, sectors, 11, 100000, image); |
| 55 | UINT64 size = io_generic_size(io); |
| 56 | if(size == 901120) { |
| 57 | image->set_variant(floppy_image::DSDD); |
| 58 | for(int track=0; track < 80; track++) { |
| 59 | for(int side=0; side < 2; side++) { |
| 60 | io_generic_read(io, sectdata, (track*2 + side)*512*11, 512*11); |
| 61 | generate_track(amiga_11, track, side, sectors, 11, 100000, image); |
| 62 | } |
| 59 | 63 | } |
| 64 | } else { |
| 65 | image->set_variant(floppy_image::DSHD); |
| 66 | for(int track=0; track < 80; track++) { |
| 67 | for(int side=0; side < 2; side++) { |
| 68 | io_generic_read(io, sectdata, (track*2 + side)*512*22, 512*22); |
| 69 | generate_track(amiga_22, track, side, sectors, 22, 200000, image); |
| 70 | } |
| 71 | } |
| 60 | 72 | } |
| 61 | 73 | |
| 62 | 74 | return true; |
| r13734 | r13735 | |
| 94 | 106 | |
| 95 | 107 | bool adf_format::save(io_generic *io, floppy_image *image) |
| 96 | 108 | { |
| 97 | | // TODO: HD support |
| 98 | | UINT8 sectdata[512*11]; |
| 99 | | UINT8 trackbuf[150000/8]; |
| 109 | UINT8 sectdata[512*22]; |
| 110 | UINT8 trackbuf[300000/8]; |
| 111 | |
| 112 | bool hd = image->get_variant() == floppy_image::DSHD; |
| 113 | |
| 114 | fprintf(stderr, "format is %s\n", hd ? "hd" : "dd"); |
| 115 | |
| 116 | int data_track_size = hd ? 512*22 : 512*11; |
| 117 | |
| 100 | 118 | for(int track=0; track < 80; track++) { |
| 101 | 119 | for(int side=0; side < 2; side++) { |
| 102 | 120 | int track_size; |
| 103 | | generate_bitstream_from_track(track, side, 2000, trackbuf, track_size, image); |
| 121 | generate_bitstream_from_track(track, side, hd ? 1000 : 2000, trackbuf, track_size, image); |
| 104 | 122 | |
| 105 | 123 | for(int i=0; i<track_size; i++) |
| 106 | 124 | if(g32(trackbuf, track_size, i) == 0x44894489 && |
| r13734 | r13735 | |
| 109 | 127 | |
| 110 | 128 | UINT32 head = ((g32(trackbuf, track_size, i+32) & 0x55555555) << 1) | (g32(trackbuf, track_size, i+64) & 0x55555555); |
| 111 | 129 | int sect = (head >> 8) & 0xff; |
| 112 | | if(sect > 11) |
| 130 | if(sect > (hd ? 22 : 11)) |
| 113 | 131 | continue; |
| 114 | 132 | |
| 115 | 133 | UINT8 *dest = sectdata + 512*sect; |
| r13734 | r13735 | |
| 121 | 139 | *dest++ = val; |
| 122 | 140 | } |
| 123 | 141 | |
| 124 | | io_generic_write(io, sectdata, (track*2 + side)*512*11, 512*11); |
| 142 | io_generic_write(io, sectdata, (track*2 + side)*data_track_size, data_track_size); |
| 125 | 143 | } |
| 126 | 144 | } |
| 127 | 145 | } |
src/lib/formats/st_dsk.c
| r13734 | r13735 | |
| 44 | 44 | track_count = head_count = sector_count = 0; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | | int st_format::identify(io_generic *io) |
| 47 | int st_format::identify(io_generic *io, UINT32 form_factor) |
| 48 | 48 | { |
| 49 | 49 | int track_count, head_count, sector_count; |
| 50 | 50 | find_size(io, track_count, head_count, sector_count); |
| r13734 | r13735 | |
| 54 | 54 | return 0; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | | bool st_format::load(io_generic *io, floppy_image *image) |
| 57 | bool st_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 58 | 58 | { |
| 59 | 59 | int track_count, head_count, sector_count; |
| 60 | 60 | find_size(io, track_count, head_count, sector_count); |
| r13734 | r13735 | |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | image->set_variant(floppy_image::DSDD); |
| 80 | |
| 79 | 81 | return true; |
| 80 | 82 | } |
| 81 | 83 | |
| r13734 | r13735 | |
| 201 | 203 | return dst < usize; |
| 202 | 204 | } |
| 203 | 205 | |
| 204 | | int msa_format::identify(io_generic *io) |
| 206 | int msa_format::identify(io_generic *io, UINT32 form_factor) |
| 205 | 207 | { |
| 206 | 208 | UINT16 sign, sect, head, strack, etrack; |
| 207 | 209 | read_header(io, sign, sect, head, strack, etrack); |
| r13734 | r13735 | |
| 215 | 217 | return 0; |
| 216 | 218 | } |
| 217 | 219 | |
| 218 | | bool msa_format::load(io_generic *io, floppy_image *image) |
| 220 | bool msa_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 219 | 221 | { |
| 220 | 222 | UINT16 sign, sect, heads, strack, etrack; |
| 221 | 223 | read_header(io, sign, sect, heads, strack, etrack); |
| r13734 | r13735 | |
| 248 | 250 | } |
| 249 | 251 | } |
| 250 | 252 | |
| 253 | image->set_variant(floppy_image::DSDD); |
| 251 | 254 | return true; |
| 252 | 255 | } |
| 253 | 256 | |
src/lib/formats/ipf_dsk.c
| r13734 | r13735 | |
| 27 | 27 | return false; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | | int ipf_format::identify(io_generic *io) |
| 30 | int ipf_format::identify(io_generic *io, UINT32 form_factor) |
| 31 | 31 | { |
| 32 | 32 | static const UINT8 refh[12] = { 0x43, 0x41, 0x50, 0x53, 0x00, 0x00, 0x00, 0x0c, 0x1c, 0xd5, 0x73, 0xba }; |
| 33 | 33 | UINT8 h[12]; |
| r13734 | r13735 | |
| 39 | 39 | return 0; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | | bool ipf_format::load(io_generic *io, floppy_image *image) |
| 42 | bool ipf_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 43 | 43 | { |
| 44 | 44 | UINT32 size = io_generic_size(io); |
| 45 | 45 | UINT8 *data = global_alloc_array(UINT8, size); |
| r13734 | r13735 | |
| 80 | 80 | |
| 81 | 81 | bool ipf_format::parse(UINT8 *data, UINT32 size, floppy_image *image) |
| 82 | 82 | { |
| 83 | image->set_variant(floppy_image::DSDD); // Not handling anything else yet |
| 83 | 84 | tcount = 84*2+1; // Usual max |
| 84 | 85 | tinfos = global_alloc_array_clear(track_info, tcount); |
| 85 | 86 | bool res = scan_all_tags(data, size); |