src/lib/formats/flopimg.c
| r13919 | r13920 | |
| 2018 | 2018 | UINT8 head = sbyte_mfm_r(bitstream, pos, track_size); |
| 2019 | 2019 | UINT8 sector = sbyte_mfm_r(bitstream, pos, track_size); |
| 2020 | 2020 | UINT8 size = sbyte_mfm_r(bitstream, pos, track_size); |
| 2021 | |
| 2021 | 2022 | if(size >= 8) |
| 2022 | 2023 | continue; |
| 2023 | 2024 | int ssize = 128 << size; |
| r13919 | r13920 | |
| 2027 | 2028 | continue; |
| 2028 | 2029 | |
| 2029 | 2030 | // Start of IDAM and DAM are supposed to be exactly 704 cells |
| 2030 | | // apart. Of course the hardware is tolerant, but not that |
| 2031 | | // tolerant. Accept +/- 32 cells of shift. |
| 2031 | // apart. Of course the hardware is tolerant. Accept +/- 128 |
| 2032 | // cells of shift. |
| 2032 | 2033 | |
| 2033 | 2034 | int d_index; |
| 2034 | 2035 | for(d_index = 0; d_index < dblk_count; d_index++) { |
| 2035 | 2036 | int delta = dblk[d_index] - idblk[i]; |
| 2036 | | if(delta >= 704-32 && delta <= 704+32) |
| 2037 | if(delta >= 704-128 && delta <= 704+128) |
| 2037 | 2038 | break; |
| 2038 | 2039 | } |
| 2039 | 2040 | if(d_index == dblk_count) |
src/lib/formats/pc_dsk.c
| r13919 | r13920 | |
| 135 | 135 | TRACKS(40/[80]) |
| 136 | 136 | SECTORS(8/[9]/10/15/18/36)) |
| 137 | 137 | LEGACY_FLOPPY_OPTIONS_END |
| 138 | |
| 139 | |
| 140 | const floppy_image_format_t::desc_e pc_format::pc_desc[] = { |
| 141 | { MFM, 0x4e, 80 }, |
| 142 | { MFM, 0x00, 12 }, |
| 143 | { RAW, 0x5224, 3 }, |
| 144 | { MFM, 0xfc, 1 }, |
| 145 | { MFM, 0x4e, 50 }, |
| 146 | { MFM, 0x00, 12 }, |
| 147 | { SECTOR_LOOP_START, 0, 17 }, |
| 148 | { CRC_CCITT_START, 1 }, |
| 149 | { RAW, 0x4489, 3 }, |
| 150 | { MFM, 0xfe, 1 }, |
| 151 | { TRACK_ID }, |
| 152 | { HEAD_ID }, |
| 153 | { SECTOR_ID }, |
| 154 | { SIZE_ID }, |
| 155 | { CRC_END, 1 }, |
| 156 | { CRC, 1 }, |
| 157 | { MFM, 0x4e, 22 }, |
| 158 | { MFM, 0x00, 12 }, |
| 159 | { CRC_CCITT_START, 2 }, |
| 160 | { RAW, 0x4489, 3 }, |
| 161 | { MFM, 0xfb, 1 }, |
| 162 | { SECTOR_DATA, -1 }, |
| 163 | { CRC_END, 2 }, |
| 164 | { CRC, 2 }, |
| 165 | { MFM, 0x4e, 84 }, |
| 166 | { MFM, 0x00, 12 }, |
| 167 | { SECTOR_LOOP_END }, |
| 168 | { MFM, 0x4e, 498 }, |
| 169 | { END } |
| 170 | }; |
| 171 | |
| 172 | pc_format::pc_format() |
| 173 | { |
| 174 | } |
| 175 | |
| 176 | const char *pc_format::name() const |
| 177 | { |
| 178 | return "pc"; |
| 179 | } |
| 180 | |
| 181 | const char *pc_format::description() const |
| 182 | { |
| 183 | return "PC floppy disk image"; |
| 184 | } |
| 185 | |
| 186 | const char *pc_format::extensions() const |
| 187 | { |
| 188 | return "dsk,ima,img,ufi,360"; |
| 189 | } |
| 190 | |
| 191 | bool pc_format::supports_save() const |
| 192 | { |
| 193 | return true; |
| 194 | } |
| 195 | |
| 196 | void pc_format::find_size(io_generic *io, UINT32 form_factor, int &track_count, int &head_count, int §or_count) |
| 197 | { |
| 198 | int size = io_generic_size(io); |
| 199 | if(size == 512*18*2*80) { |
| 200 | track_count = 80; |
| 201 | head_count = 2; |
| 202 | sector_count = 18; |
| 203 | } else |
| 204 | track_count = head_count = sector_count = 0; |
| 205 | } |
| 206 | |
| 207 | int pc_format::identify(io_generic *io, UINT32 form_factor) |
| 208 | { |
| 209 | int track_count, head_count, sector_count; |
| 210 | find_size(io, form_factor, track_count, head_count, sector_count); |
| 211 | |
| 212 | if(track_count) |
| 213 | return 50; |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | bool pc_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 218 | { |
| 219 | int track_count, head_count, sector_count; |
| 220 | find_size(io, form_factor, track_count, head_count, sector_count); |
| 221 | |
| 222 | UINT8 sectdata[36*512]; |
| 223 | desc_s sectors[36]; |
| 224 | for(int i=0; i<sector_count; i++) { |
| 225 | sectors[i].data = sectdata + 512*i; |
| 226 | sectors[i].size = 512; |
| 227 | sectors[i].sector_id = i + 1; |
| 228 | } |
| 229 | |
| 230 | int track_size = sector_count*512; |
| 231 | for(int track=0; track < track_count; track++) { |
| 232 | for(int head=0; head < head_count; head++) { |
| 233 | io_generic_read(io, sectdata, (track*head_count + head)*track_size, track_size); |
| 234 | generate_track(pc_desc, |
| 235 | track, head, sectors, sector_count, 200000, image); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | image->set_variant(floppy_image::DSHD); |
| 240 | |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | bool pc_format::save(io_generic *io, floppy_image *image) |
| 245 | { |
| 246 | int track_count, head_count, sector_count; |
| 247 | get_geometry_mfm_pc(image, 1000, track_count, head_count, sector_count); |
| 248 | |
| 249 | if(track_count < 80) |
| 250 | track_count = 80; |
| 251 | else if(track_count > 82) |
| 252 | track_count = 82; |
| 253 | |
| 254 | // Happens for a fully unformatted floppy |
| 255 | if(!head_count) |
| 256 | head_count = 1; |
| 257 | |
| 258 | if(sector_count > 36) |
| 259 | sector_count = 36; |
| 260 | else if(sector_count < 9) |
| 261 | sector_count = 9; |
| 262 | |
| 263 | UINT8 sectdata[36*512]; |
| 264 | int track_size = sector_count*512; |
| 265 | |
| 266 | for(int track=0; track < track_count; track++) { |
| 267 | for(int head=0; head < head_count; head++) { |
| 268 | get_track_data_mfm_pc(track, head, image, 1000, 512, sector_count, sectdata); |
| 269 | io_generic_write(io, sectdata, (track*head_count + head)*track_size, track_size); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | return true; |
| 274 | } |
| 275 | |
| 276 | const floppy_format_type FLOPPY_PC_FORMAT = &floppy_image_format_creator<pc_format>; |
src/lib/formats/pc_dsk.h
| r13919 | r13920 | |
| 16 | 16 | |
| 17 | 17 | LEGACY_FLOPPY_OPTIONS_EXTERN(pc); |
| 18 | 18 | |
| 19 | |
| 20 | class pc_format : public floppy_image_format_t |
| 21 | { |
| 22 | public: |
| 23 | pc_format(); |
| 24 | |
| 25 | virtual int identify(io_generic *io, UINT32 form_factor); |
| 26 | virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image); |
| 27 | virtual bool save(io_generic *io, floppy_image *image); |
| 28 | |
| 29 | virtual const char *name() const; |
| 30 | virtual const char *description() const; |
| 31 | virtual const char *extensions() const; |
| 32 | virtual bool supports_save() const; |
| 33 | |
| 34 | private: |
| 35 | static const desc_e pc_desc[]; |
| 36 | |
| 37 | void find_size(io_generic *io, UINT32 form_factor, int &track_count, int &head_count, int §or_count); |
| 38 | }; |
| 39 | |
| 40 | extern const floppy_format_type FLOPPY_PC_FORMAT; |
| 41 | |
| 19 | 42 | #endif /* PC_DSK_H */ |
src/lib/formats/dfi_dsk.c
| r13919 | r13920 | |
| 1 | #include "emu.h" |
| 2 | #include "dfi_dsk.h" |
| 3 | #include <zlib.h> |
| 4 | |
| 5 | dfi_format::dfi_format() : floppy_image_format_t() |
| 6 | { |
| 7 | } |
| 8 | |
| 9 | const char *dfi_format::name() const |
| 10 | { |
| 11 | return "dfi"; |
| 12 | } |
| 13 | |
| 14 | const char *dfi_format::description() const |
| 15 | { |
| 16 | return "Diskferret flux dump format"; |
| 17 | } |
| 18 | |
| 19 | const char *dfi_format::extensions() const |
| 20 | { |
| 21 | return "dfi"; |
| 22 | } |
| 23 | |
| 24 | bool dfi_format::supports_save() const |
| 25 | { |
| 26 | return true; |
| 27 | } |
| 28 | |
| 29 | int dfi_format::identify(io_generic *io, UINT32 form_factor) |
| 30 | { |
| 31 | char sign[4]; |
| 32 | io_generic_read(io, sign, 0, 4); |
| 33 | return memcmp(sign, "DFE2", 4) ? 0 : 100; |
| 34 | } |
| 35 | |
| 36 | bool dfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 37 | { |
| 38 | int size = io_generic_size(io); |
| 39 | int pos = 4; |
| 40 | UINT8 *data = 0; |
| 41 | int data_size = 0; |
| 42 | |
| 43 | while(pos < size) { |
| 44 | UINT8 h[10]; |
| 45 | io_generic_read(io, h, pos, 10); |
| 46 | UINT16 track = (h[0] << 8) | h[1]; |
| 47 | UINT16 head = (h[2] << 8) | h[3]; |
| 48 | // Ignore sector |
| 49 | UINT32 tsize = (h[6] << 24) | (h[7] << 16) | (h[8] << 8) | h[9]; |
| 50 | |
| 51 | if(pos+tsize+10 > size) { |
| 52 | if(data) |
| 53 | global_free(data); |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | if(tsize > data_size) { |
| 58 | if(data) |
| 59 | global_free(data); |
| 60 | data_size = tsize; |
| 61 | data = global_alloc_array(UINT8, data_size); |
| 62 | } |
| 63 | |
| 64 | io_generic_read(io, data, pos+16, tsize); |
| 65 | pos += tsize+10; |
| 66 | tsize--; // Drop the extra 0x00 at the end |
| 67 | |
| 68 | int index_time = 0; |
| 69 | int total_time = 0; |
| 70 | for(int i=0; i<tsize; i++) { |
| 71 | UINT8 v = data[i]; |
| 72 | if((v & 0x7f) == 0x7f) |
| 73 | total_time += 0x7f; |
| 74 | else { |
| 75 | total_time += v & 0x7f; |
| 76 | if((v & 0x80) && !index_time) |
| 77 | index_time = total_time; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if(!index_time) |
| 82 | index_time = total_time; |
| 83 | |
| 84 | image->set_track_size(track, head, tsize); |
| 85 | |
| 86 | int cur_time = 0; |
| 87 | UINT32 mg = floppy_image::MG_A; |
| 88 | UINT32 *buf = image->get_buffer(track, head); |
| 89 | int tpos = 0; |
| 90 | buf[tpos++] = mg; |
| 91 | for(int i=0; i<tsize; i++) { |
| 92 | UINT8 v = data[i]; |
| 93 | if((v & 0x7f) == 0x7f) |
| 94 | cur_time += 0x7f; |
| 95 | else { |
| 96 | cur_time += v & 0x7f; |
| 97 | if(v & 0x80) |
| 98 | break; |
| 99 | mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A; |
| 100 | buf[tpos++] = mg | UINT32(200000000ULL*cur_time/index_time); |
| 101 | } |
| 102 | } |
| 103 | image->set_track_size(track, head, tpos); |
| 104 | } |
| 105 | |
| 106 | if(data) |
| 107 | global_free(data); |
| 108 | |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | const floppy_format_type FLOPPY_DFI_FORMAT = &floppy_image_format_creator<dfi_format>; |