src/lib/formats/flopimg.h
| r14144 | r14145 | |
| 213 | 213 | /* misc */ |
| 214 | 214 | const char *floppy_error(floperr_t err); |
| 215 | 215 | |
| 216 | |
| 216 | 217 | ////////////////////////////////////////////////////////// |
| 217 | | /// New implementation |
| 218 | // New implementation |
| 218 | 219 | ////////////////////////////////////////////////////////// |
| 219 | 220 | |
| 220 | 221 | class floppy_image; |
| 221 | 222 | |
| 223 | //! Class representing a floppy image format. |
| 222 | 224 | class floppy_image_format_t |
| 223 | 225 | { |
| 224 | 226 | public: |
| 225 | 227 | floppy_image_format_t(); |
| 226 | 228 | virtual ~floppy_image_format_t(); |
| 227 | | |
| 229 | |
| 230 | /*! @brief Identify an image. |
| 231 | The identify function tests if the image is valid |
| 232 | for this particular format. |
| 233 | @param io buffer containing the image data. |
| 234 | @param form_factor Physical form factor of disk, from the enum |
| 235 | in floppy_image |
| 236 | @return 1 if image valid, 0 otherwise. |
| 237 | */ |
| 228 | 238 | virtual int identify(io_generic *io, UINT32 form_factor) = 0; |
| 229 | | virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image) = 0; |
| 239 | |
| 240 | /*! @brief Load an image. |
| 241 | The load function opens an image file and converts it to the |
| 242 | internal MESS floppy representation. |
| 243 | @param io source buffer containing the image data. |
| 244 | @param form_factor Physical form factor of disk, from the enum |
| 245 | in floppy_image |
| 246 | @param image output buffer for data in MESS internal format. |
| 247 | @return true on success, false otherwise. |
| 248 | */ |
| 249 | virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image) = 0; |
| 250 | |
| 251 | /*! @brief Save an image. |
| 252 | The save function writes back an image from the MESS internal |
| 253 | floppy representation to the appropriate format on disk. |
| 254 | @param io output buffer for the data in the on-disk format. |
| 255 | @param image source buffer containing data in MESS internal format. |
| 256 | @return true on success, false otherwise. |
| 257 | */ |
| 230 | 258 | virtual bool save(io_generic *io, floppy_image *image); |
| 231 | 259 | |
| 260 | //! @returns string containing name of format. |
| 232 | 261 | virtual const char *name() const = 0; |
| 262 | //! @returns string containing description of format. |
| 233 | 263 | virtual const char *description() const = 0; |
| 264 | //! @returns string containing comma-separated list of file |
| 265 | //! extensions the format may use. |
| 234 | 266 | virtual const char *extensions() const = 0; |
| 267 | //! @returns true if format supports saving. |
| 235 | 268 | virtual bool supports_save() const = 0; |
| 236 | 269 | |
| 270 | //! Used if a linked list of formats is needed |
| 237 | 271 | floppy_image_format_t *next; |
| 272 | //! This appends a format to the linked list of formats, needed for floppy_image_device(). |
| 238 | 273 | void append(floppy_image_format_t *_next); |
| 239 | | |
| 274 | //! This checks if the file has the proper extension for this format. |
| 275 | //! @param file_name |
| 276 | //! @returns true if file matches the extension. |
| 240 | 277 | bool extension_matches(const char *file_name) const; |
| 241 | | |
| 278 | |
| 242 | 279 | protected: |
| 243 | | // Input for convert_to_edge |
| 280 | //! Input for convert_to_edge |
| 244 | 281 | enum { |
| 245 | 282 | MG_SHIFT = 28, |
| 246 | 283 | |
| r14144 | r14145 | |
| 251 | 288 | |
| 252 | 289 | // **** Reader helpers **** |
| 253 | 290 | |
| 254 | | // Struct designed for easy track data description |
| 255 | | // Optional, you can always do things by hand, but useful nevertheless |
| 256 | | // A vector of these structures describes one track. |
| 257 | | |
| 291 | //! Struct designed for easy track data description. Contains an opcode and two params. |
| 292 | |
| 293 | //! Optional, you can always do things by hand, but useful nevertheless. |
| 294 | //! A vector of these structures describes one track. |
| 295 | |
| 258 | 296 | struct desc_e { |
| 259 | | int type, p1, p2; |
| 297 | int type, //!< An opcode |
| 298 | p1, //!< first param |
| 299 | p2; //!< second param |
| 260 | 300 | }; |
| 261 | | |
| 301 | |
| 302 | //! Opcodes of the format description language used by generate_track() |
| 262 | 303 | enum { |
| 263 | | END, // End of description |
| 264 | | MFM, // One byte in p1 to be mfm-encoded, msb first, repeated p2 times |
| 265 | | MFMBITS, // A value of p2 bits in p1 to be mfm-encoded, msb first |
| 266 | | RAW, // One 16 bits word in p1 to be written raw, msb first, repeated p2 times |
| 267 | | RAWBITS, // A value of p2 bits in p1 to be copied as-is, msb first |
| 268 | | TRACK_ID, // Track id byte, mfm-encoded |
| 269 | | TRACK_ID_GCR6, // Track id low 6 bits, gcr6-encoded |
| 270 | | HEAD_ID, // Head id byte, mfm-encoded |
| 271 | | TRACK_HEAD_ID_GCR6, // Track id 7th bit + head, gc6-encoded |
| 272 | | SECTOR_ID, // Sector id byte, mfm-encoded |
| 273 | | SECTOR_ID_GCR6, // Sector id byte, gcr6-encoded |
| 274 | | SIZE_ID, // Sector size code on one byte [log2(size/128)], mfm-encoded |
| 275 | | SECTOR_INFO_GCR6, // Sector info byte, gcr6-encoded |
| 276 | | OFFSET_ID_O, // Offset (track*2+head) byte, odd bits, mfm-encoded |
| 277 | | OFFSET_ID_E, // Offset (track*2+head) byte, even bits, mfm-encoded |
| 278 | | SECTOR_ID_O, // Sector id byte, odd bits, mfm-encoded |
| 279 | | SECTOR_ID_E, // Sector id byte, even bits, mfm-encoded |
| 280 | | REMAIN_O, // Remaining sector count, odd bits, mfm-encoded, total sector count in p1 |
| 281 | | REMAIN_E, // Remaining sector count, even bits, mfm-encoded, total sector count in p1 |
| 304 | END, //!< End of description |
| 305 | MFM, //!< One byte in p1 to be mfm-encoded, msb first, repeated p2 times |
| 306 | MFMBITS, //!< A value of p2 bits in p1 to be mfm-encoded, msb first |
| 307 | RAW, //!< One 16 bits word in p1 to be written raw, msb first, repeated p2 times |
| 308 | RAWBITS, //!< A value of p2 bits in p1 to be copied as-is, msb first |
| 309 | TRACK_ID, //!< Track id byte, mfm-encoded |
| 310 | TRACK_ID_GCR6, //!< Track id low 6 bits, gcr6-encoded |
| 311 | HEAD_ID, //!< Head id byte, mfm-encoded |
| 312 | TRACK_HEAD_ID_GCR6, //!< Track id 7th bit + head, gc6-encoded |
| 313 | SECTOR_ID, //!< Sector id byte, mfm-encoded |
| 314 | SECTOR_ID_GCR6, //!< Sector id byte, gcr6-encoded |
| 315 | SIZE_ID, //!< Sector size code on one byte [log2(size/128)], mfm-encoded |
| 316 | SECTOR_INFO_GCR6, //!< Sector info byte, gcr6-encoded |
| 317 | OFFSET_ID_O, //!< Offset (track*2+head) byte, odd bits, mfm-encoded |
| 318 | OFFSET_ID_E, //!< Offset (track*2+head) byte, even bits, mfm-encoded |
| 319 | SECTOR_ID_O, //!< Sector id byte, odd bits, mfm-encoded |
| 320 | SECTOR_ID_E, //!< Sector id byte, even bits, mfm-encoded |
| 321 | REMAIN_O, //!< Remaining sector count, odd bits, mfm-encoded, total sector count in p1 |
| 322 | REMAIN_E, //!< Remaining sector count, even bits, mfm-encoded, total sector count in p1 |
| 282 | 323 | |
| 283 | | SECTOR_DATA, // Sector data to mfm-encode, which in p1, -1 for the current one per the sector id |
| 284 | | SECTOR_DATA_O, // Sector data to mfm-encode, odd bits only, which in p1, -1 for the current one per the sector id |
| 285 | | SECTOR_DATA_E, // Sector data to mfm-encode, even bits only, which in p1, -1 for the current one per the sector id |
| 286 | | SECTOR_DATA_MAC, // Transformed sector data + checksum, mac style, id in p1, -1 for the current one per the sector id |
| 324 | SECTOR_DATA, //!< Sector data to mfm-encode, which in p1, -1 for the current one per the sector id |
| 325 | SECTOR_DATA_O, //!< Sector data to mfm-encode, odd bits only, which in p1, -1 for the current one per the sector id |
| 326 | SECTOR_DATA_E, //!< Sector data to mfm-encode, even bits only, which in p1, -1 for the current one per the sector id |
| 327 | SECTOR_DATA_MAC, //!< Transformed sector data + checksum, mac style, id in p1, -1 for the current one per the sector id |
| 287 | 328 | |
| 288 | | CRC_CCITT_START, // Start a CCITT CRC calculation, with the usual x^16 + x^12 + x^5 + 1 (11021) polynomial, p1 = crc id |
| 289 | | CRC_AMIGA_START, // Start an amiga checksum calculation, p1 = crc id |
| 290 | | CRC_MACHEAD_START, // Start of the mac gcr6 sector header checksum calculation (xor of pre-encode 6-bits values, gcr6-encoded) |
| 291 | | CRC_END, // End the checksum, p1 = crc id |
| 292 | | CRC, // Write a checksum in the apporpriate format, p1 = crc id |
| 329 | CRC_CCITT_START, //!< Start a CCITT CRC calculation, with the usual x^16 + x^12 + x^5 + 1 (11021) polynomial, p1 = crc id |
| 330 | CRC_AMIGA_START, //!< Start an amiga checksum calculation, p1 = crc id |
| 331 | CRC_MACHEAD_START, //!< Start of the mac gcr6 sector header checksum calculation (xor of pre-encode 6-bits values, gcr6-encoded) |
| 332 | CRC_END, //!< End the checksum, p1 = crc id |
| 333 | CRC, //!< Write a checksum in the apporpriate format, p1 = crc id |
| 293 | 334 | |
| 294 | | SECTOR_LOOP_START, // Start of the per-sector loop, sector number goes from p1 to p2 inclusive |
| 295 | | SECTOR_LOOP_END, // End of the per-sector loop |
| 296 | | SECTOR_INTERLEAVE_SKEW, // Defines interleave and skew for sector counting |
| 335 | SECTOR_LOOP_START, //!< Start of the per-sector loop, sector number goes from p1 to p2 inclusive |
| 336 | SECTOR_LOOP_END, //!< End of the per-sector loop |
| 337 | SECTOR_INTERLEAVE_SKEW, //!< Defines interleave and skew for sector counting |
| 297 | 338 | }; |
| 298 | 339 | |
| 299 | | // Sector data description |
| 340 | //! Sector data description |
| 300 | 341 | struct desc_s { |
| 301 | | int size; // Sector size, int bytes |
| 302 | | const UINT8 *data; // Sector data |
| 303 | | UINT8 sector_id; // Sector ID |
| 304 | | UINT8 sector_info; // Sector free byte |
| 342 | int size; //!< Sector size, int bytes |
| 343 | const UINT8 *data; //!< Sector data |
| 344 | UINT8 sector_id; //!< Sector ID |
| 345 | UINT8 sector_info; //!< Sector free byte |
| 305 | 346 | }; |
| 306 | 347 | |
| 307 | 348 | |
| 308 | | // Generate one track according to the description vector |
| 309 | | // "sect" is a vector indexed by sector id |
| 310 | | // "track_size" is in _cells_, i.e. 100000 for a usual 2us-per-cell track at 300rpm |
| 311 | | |
| 349 | /*! @brief Generate one track according to the description vector. |
| 350 | @param desc track data description |
| 351 | @param track |
| 352 | @param head |
| 353 | @param sect a vector indexed by sector id. |
| 354 | @param sect_count number of sectors. |
| 355 | @param track_size in _cells_, i.e. 100000 for a usual 2us-per-cell track at 300rpm. |
| 356 | @param image |
| 357 | */ |
| 312 | 358 | void generate_track(const desc_e *desc, int track, int head, const desc_s *sect, int sect_count, int track_size, floppy_image *image); |
| 313 | 359 | |
| 314 | | // Generate a track from cell binary values, MSB-first, size in cells and not bytes |
| 360 | /*! @brief Generate a track from cell binary values, MSB-first. |
| 361 | @param track |
| 362 | @param head |
| 363 | @param trackbuf track input buffer. |
| 364 | @param track_size in cells, not bytes. |
| 365 | @param image |
| 366 | */ |
| 315 | 367 | void generate_track_from_bitstream(int track, int head, const UINT8 *trackbuf, int track_size, floppy_image *image); |
| 316 | 368 | |
| 317 | | // Generate a track from cell level values (0/1/W/D/N) |
| 318 | | // |
| 319 | | // Splice pos is the position of the track splice. For normal |
| 320 | | // formats, use -1. For protected formats, you're supposed to |
| 321 | | // know. trackbuf may be modified at that position or after. |
| 322 | | // |
| 323 | | // Note that this function needs to be able to split cells in two, |
| 324 | | // so no time value should be less than 2, and even values are a |
| 325 | | // good idea. |
| 326 | | |
| 369 | //! @brief Generate a track from cell level values (0/1/W/D/N). |
| 370 | |
| 371 | /*! Note that this function needs to be able to split cells in two, |
| 372 | so no time value should be less than 2, and even values are a |
| 373 | good idea. |
| 374 | */ |
| 375 | /*! @param track |
| 376 | @param head |
| 377 | @param trackbuf track input buffer. |
| 378 | @param track_size in cells, not bytes. |
| 379 | @param splice_pos is the position of the track splice. For normal |
| 380 | formats, use -1. For protected formats, you're supposed to |
| 381 | know. trackbuf may be modified at that position or after. |
| 382 | @param image |
| 383 | */ |
| 327 | 384 | void generate_track_from_levels(int track, int head, UINT32 *trackbuf, int track_size, int splice_pos, floppy_image *image); |
| 328 | 385 | |
| 329 | | // Normalize the times in a cell buffer to sum up to 200000000 |
| 386 | //! Normalize the times in a cell buffer to sum up to 200000000 |
| 330 | 387 | void normalize_times(UINT32 *buffer, int bitlen); |
| 331 | 388 | |
| 332 | | // Some conversion tables |
| 389 | // Some conversion tables for gcr6 |
| 333 | 390 | static const UINT8 gcr6fw_tb[0x40], gcr6bw_tb[0x100]; |
| 334 | 391 | |
| 335 | 392 | // Some useful descriptions shared by multiple formats |
| r14144 | r14145 | |
| 343 | 400 | |
| 344 | 401 | // Fastcopy Pro optimized formats, with fake sector header for |
| 345 | 402 | // faster verify and skew/interleave where appropriate |
| 346 | | static const desc_e atari_st_fcp_9[]; |
| 403 | static const desc_e atari_st_fcp_9[]; |
| 347 | 404 | static const desc_e *const atari_st_fcp_10[10]; |
| 348 | 405 | static const desc_e atari_st_fcp_11[]; |
| 349 | 406 | |
| r14144 | r14145 | |
| 363 | 420 | |
| 364 | 421 | // **** Writer helpers **** |
| 365 | 422 | |
| 366 | | // Rebuild a cell bitstream for a track. Takes the cell standard |
| 367 | | // angular size as a parameter, gives out a msb-first bitstream. |
| 368 | | // Beware that fuzzy bits will always give out the same value. |
| 369 | | // |
| 370 | | // Output buffer size should be 34% more than the nominal number |
| 371 | | // of cells (the dpll tolerates a cell size down to 75% of the |
| 372 | | // nominal one, with gives a cell count of 1/0.75=1.333... times |
| 373 | | // the nominal one). |
| 374 | | // |
| 375 | | // Output size is given in bits (cells). |
| 376 | | // |
| 377 | | // Computing the standard angular size of a cell is |
| 378 | | // simple. Noting: |
| 379 | | // d = standard cell duration in microseconds |
| 380 | | // r = motor rotational speed in rpm |
| 381 | | // then: |
| 382 | | // a = r * d * 10 / 3 |
| 383 | | // |
| 384 | | // Some values: |
| 385 | | // Type Cell RPM Size |
| 423 | /*! @brief Rebuild a cell bitstream for a track. |
| 424 | Takes the cell standard |
| 425 | angular size as a parameter, gives out a msb-first bitstream. |
| 386 | 426 | |
| 387 | | // C1541 tr 1-17 3.25 300 3250 |
| 388 | | // C1541 tr 18-24 3.50 300 3500 |
| 389 | | // C1541 tr 25-30 3.75 300 3750 |
| 390 | | // C1541 tr 31+ 4.00 300 4000 |
| 391 | | // 5.25" SD 4 300 4000 |
| 392 | | // 5.25" DD 2 300 2000 |
| 393 | | // 5.25" HD 1 360 1200 |
| 394 | | // 3.5" SD 4 300 4000 |
| 395 | | // 3.5" DD 2 300 2000 |
| 396 | | // 3.5" HD 1 300 1000 |
| 397 | | // 3.5" ED 0.5 300 500 |
| 427 | Beware that fuzzy bits will always give out the same value. |
| 428 | @param track |
| 429 | @param head |
| 430 | @param cell_size |
| 431 | @param trackbuf Output buffer size should be 34% more than the nominal number |
| 432 | of cells (the dpll tolerates a cell size down to 75% of the |
| 433 | nominal one, with gives a cell count of 1/0.75=1.333... times |
| 434 | the nominal one). |
| 435 | @param track_size Output size is given in bits (cells). |
| 436 | @param image |
| 437 | */ |
| 438 | /*! @verbatim |
| 439 | Computing the standard angular size of a cell is |
| 440 | simple. Noting: |
| 441 | d = standard cell duration in microseconds |
| 442 | r = motor rotational speed in rpm |
| 443 | then: |
| 444 | a = r * d * 10 / 3. |
| 445 | Some values: |
| 446 | Type Cell RPM Size |
| 398 | 447 | |
| 448 | C1541 tr 1-17 3.25 300 3250 |
| 449 | C1541 tr 18-24 3.50 300 3500 |
| 450 | C1541 tr 25-30 3.75 300 3750 |
| 451 | C1541 tr 31+ 4.00 300 4000 |
| 452 | 5.25" SD 4 300 4000 |
| 453 | 5.25" DD 2 300 2000 |
| 454 | 5.25" HD 1 360 1200 |
| 455 | 3.5" SD 4 300 4000 |
| 456 | 3.5" DD 2 300 2000 |
| 457 | 3.5" HD 1 300 1000 |
| 458 | 3.5" ED 0.5 300 500 |
| 459 | @endverbatim |
| 460 | */ |
| 461 | |
| 399 | 462 | void generate_bitstream_from_track(int track, int head, int cell_size, UINT8 *trackbuf, int &track_size, floppy_image *image); |
| 400 | | |
| 463 | |
| 464 | //! Defines a standard sector for extracting. |
| 401 | 465 | struct desc_xs { |
| 402 | | int track, head, size; |
| 403 | | const UINT8 *data; |
| 466 | int track, //!< Track for this sector |
| 467 | head, //!< Head for this sector |
| 468 | size; //!< Size of this sector |
| 469 | const UINT8 *data; //!< Data within this sector |
| 404 | 470 | }; |
| 405 | 471 | |
| 406 | | // Extract standard sectors from a regenerated bitstream |
| 407 | | // sectors must point to an array of 256 desc_xs |
| 408 | | // An existing sector is reconizable by having ->data non-null |
| 409 | | // Sector data is written in sectdata up to sectdata_size bytes |
| 472 | //! @brief Extract standard sectors from a regenerated bitstream. |
| 473 | //! Sectors must point to an array of 256 desc_xs. |
| 410 | 474 | |
| 411 | | // The ones implemented here are the ones used by multiple |
| 412 | | // systems. |
| 475 | //! An existing sector is recognizable by having ->data non-null. |
| 476 | //! Sector data is written in sectdata up to sectdata_size bytes. |
| 413 | 477 | |
| 414 | | // PC-type sectors with MFM encoding, sector size can go from 128 bytes to 16K |
| 478 | //! The ones implemented here are the ones used by multiple |
| 479 | //! systems. |
| 480 | |
| 481 | //! PC-type sectors with MFM encoding, sector size can go from 128 bytes to 16K. |
| 415 | 482 | void extract_sectors_from_bitstream_mfm_pc(const UINT8 *bitstream, int track_size, desc_xs *sectors, UINT8 *sectdata, int sectdata_size); |
| 416 | 483 | |
| 417 | 484 | |
| 418 | | // Get a geometry (including sectors) from an image |
| 419 | | // PC-type sectors with MFM encoding |
| 485 | //! @brief Get a geometry (including sectors) from an image. |
| 486 | |
| 487 | //! PC-type sectors with MFM encoding |
| 420 | 488 | void get_geometry_mfm_pc(floppy_image *image, int cell_size, int &track_count, int &head_count, int §or_count); |
| 421 | 489 | |
| 422 | 490 | |
| 423 | | // Regenerate the data for a full track |
| 424 | | // PC-type sectors with MFM encoding and fixed-size |
| 491 | //! Regenerate the data for a full track. |
| 492 | //! PC-type sectors with MFM encoding and fixed-size. |
| 425 | 493 | void get_track_data_mfm_pc(int track, int head, floppy_image *image, int cell_size, int sector_size, int sector_count, UINT8 *sectdata); |
| 426 | 494 | |
| 495 | //! Look up a bit in a level-type stream. |
| 427 | 496 | bool bit_r(const UINT32 *buffer, int offset); |
| 497 | //! Look up multiple bits |
| 428 | 498 | UINT32 bitn_r(const UINT32 *buffer, int offset, int count); |
| 499 | //! Write a bit with a given size. |
| 429 | 500 | void bit_w(UINT32 *buffer, int offset, bool val, UINT32 size = 1000); |
| 501 | //! Calculate a CCITT-type CRC. |
| 430 | 502 | UINT16 calc_crc_ccitt(const UINT32 *buffer, int start, int end); |
| 503 | //! Write a series of (raw) bits and increment the offset. |
| 431 | 504 | void raw_w(UINT32 *buffer, int &offset, int n, UINT32 val, UINT32 size = 1000); |
| 505 | //! MFM-encode and write a series of bits |
| 432 | 506 | void mfm_w(UINT32 *buffer, int &offset, int n, UINT32 val, UINT32 size = 1000); |
| 507 | //! MFM-encode every two bits and write |
| 433 | 508 | void mfm_half_w(UINT32 *buffer, int &offset, int start_bit, UINT32 val, UINT32 size = 1000); |
| 509 | //! GCR6 encode (Apple II 16-sector and Mac-style GCR) |
| 434 | 510 | UINT32 gcr6_encode(UINT8 va, UINT8 vb, UINT8 vc); |
| 511 | //! GCR6 decode |
| 435 | 512 | void gcr6_decode(UINT8 e0, UINT8 e1, UINT8 e2, UINT8 e3, UINT8 &va, UINT8 &vb, UINT8 &vc); |
| 436 | 513 | |
| 437 | 514 | private: |
| 438 | 515 | enum { CRC_NONE, CRC_AMIGA, CRC_CCITT, CRC_MACHEAD }; |
| 439 | 516 | enum { MAX_CRC_COUNT = 64 }; |
| 517 | |
| 518 | //! Holds data used internally for generating CRCs. |
| 440 | 519 | struct gen_crc_info { |
| 441 | | int type, start, end, write; |
| 442 | | bool fixup_mfm_clock; |
| 520 | int type, //!< Type of CRC |
| 521 | start, //!< Start position |
| 522 | end, //!< End position |
| 523 | write; //!< where to write the CRC |
| 524 | bool fixup_mfm_clock; //!< would the MFM clock bit after the CRC need to be fixed? |
| 443 | 525 | }; |
| 444 | 526 | |
| 445 | 527 | bool type_no_data(int type) const; |
| r14144 | r14145 | |
| 459 | 541 | int calc_sector_index(int num, int interleave, int skew, int total_sectors, int track_head); |
| 460 | 542 | }; |
| 461 | 543 | |
| 462 | | // a device_type is simply a pointer to its alloc function |
| 544 | // a dce_type is simply a pointer to its alloc function |
| 463 | 545 | typedef floppy_image_format_t *(*floppy_format_type)(); |
| 464 | 546 | |
| 465 | 547 | // this template function creates a stub which constructs a image format |
| r14144 | r14145 | |
| 471 | 553 | |
| 472 | 554 | // ======================> floppy_image |
| 473 | 555 | |
| 474 | | // class representing floppy image |
| 556 | //! Class representing floppy image |
| 557 | |
| 558 | //! Internal format is close but not identical to the mfi format. |
| 559 | //! |
| 560 | //! |
| 561 | //! Track data consists of a series of 32-bits lsb-first values |
| 562 | //! representing magnetic cells. Bits 0-27 indicate the absolute |
| 563 | //! position of the start of the cell (not the size), and bits |
| 564 | //! 28-31 the type. Type can be: |
| 565 | //! - 0, MG_A -> Magnetic orientation A |
| 566 | //! - 1, MG_B -> Magnetic orientation B |
| 567 | //! - 2, MG_N -> Non-magnetized zone (neutral) |
| 568 | //! - 3, MG_D -> Damaged zone, reads as neutral but cannot be changed by writing |
| 569 | //! |
| 570 | //! The position is in angular units of 1/200,000,000th of a turn. |
| 571 | //! The last cell implicit end position is of course 200,000,000. |
| 572 | //! |
| 573 | //! Unformatted tracks are encoded as zero-size. |
| 574 | //! |
| 575 | //! The "track splice" information indicates where to start writing |
| 576 | //! if you try to rewrite a physical disk with the data. Some |
| 577 | //! preservation formats encode that information, it is guessed for |
| 578 | //! others. The write track function of fdcs should set it. The |
| 579 | //! representation is the angular position relative to the index. |
| 580 | //! |
| 581 | //! The media type is divided in two parts. The first half |
| 582 | //! indicates the physical form factor, i.e. all medias with that |
| 583 | //! form factor can be physically inserted in a reader that handles |
| 584 | //! it. The second half indicates the variants which are usually |
| 585 | //! detectable by the reader, such as density and number of sides. |
| 586 | |
| 587 | |
| 475 | 588 | class floppy_image |
| 476 | 589 | { |
| 477 | 590 | public: |
| 478 | | // Internal format is close but not identical to the mfi format. |
| 479 | | // |
| 480 | | // |
| 481 | | // Track data consists of a series of 32-bits lsb-first values |
| 482 | | // representing magnetic cells. Bits 0-27 indicate the absolute |
| 483 | | // position of the start of the cell (not the size), and bits |
| 484 | | // 28-31 the type. Type can be: |
| 485 | | // - 0, MG_A -> Magnetic orientation A |
| 486 | | // - 1, MG_B -> Magnetic orientation B |
| 487 | | // - 2, MG_N -> Non-magnetized zone (neutral) |
| 488 | | // - 3, MG_D -> Damaged zone, reads as neutral but cannot be changed by writing |
| 489 | | // |
| 490 | | // The position is in angular units of 1/200,000,000th of a turn. |
| 491 | | // The last cell implicit end position is of course 200,000,000. |
| 492 | | // |
| 493 | | // Unformatted tracks are encoded as zero-size. |
| 494 | | // |
| 495 | | // The "track splice" information indicates where to start writing |
| 496 | | // if you try to rewrite a physical disk with the data. Some |
| 497 | | // preservation formats encode that information, it is guessed for |
| 498 | | // others. The write track function of fdcs should set it. The |
| 499 | | // representation is the angular position relative to the index. |
| 500 | | // |
| 501 | | // The media type is divided in two parts. The first half |
| 502 | | // indicate the physical form factor, i.e. all medias with that |
| 503 | | // form factor can be physically inserted in a reader that handles |
| 504 | | // it. The second half indicates the variants which are usually |
| 505 | | // detectable by the reader, such as density and number of sides. |
| 506 | | |
| 591 | //! Floppy format data |
| 507 | 592 | enum { |
| 508 | 593 | TIME_MASK = 0x0fffffff, |
| 509 | 594 | MG_MASK = 0xf0000000, |
| 510 | | MG_SHIFT = 28, |
| 511 | | |
| 512 | | MG_A = (0 << MG_SHIFT), |
| 513 | | MG_B = (1 << MG_SHIFT), |
| 514 | | MG_N = (2 << MG_SHIFT), |
| 515 | | MG_D = (3 << MG_SHIFT) |
| 595 | MG_SHIFT = 28, //!< Bitshift constant for magnetic orientation data |
| 596 | MG_A = (0 << MG_SHIFT), //!< - 0, MG_A -> Magnetic orientation A |
| 597 | MG_B = (1 << MG_SHIFT), //!< - 1, MG_B -> Magnetic orientation B |
| 598 | MG_N = (2 << MG_SHIFT), //!< - 2, MG_N -> Non-magnetized zone (neutral) |
| 599 | MG_D = (3 << MG_SHIFT) //!< - 3, MG_D -> Damaged zone, reads as neutral but cannot be changed by writing |
| 516 | 600 | }; |
| 517 | 601 | |
| 518 | | // Form factors |
| 602 | |
| 603 | //! Form factors |
| 519 | 604 | enum { |
| 520 | | FF_UNKNOWN = 0x00000000, // Unknown, useful when converting |
| 521 | | FF_35 = 0x20203533, // "35 " |
| 522 | | FF_525 = 0x20353235, // "525 " |
| 605 | FF_UNKNOWN = 0x00000000, //!< Unknown, useful when converting |
| 606 | FF_35 = 0x20203533, //!< "35 " 3.5 inch disk |
| 607 | FF_525 = 0x20353235, //!< "525 " 5.25 inch disk |
| 523 | 608 | }; |
| 524 | 609 | |
| 525 | | // Variants |
| 610 | //! Variants |
| 526 | 611 | enum { |
| 527 | | SSSD = 0x44535353, // "SSSD", |
| 528 | | SSDD = 0x44445353, // "DSSD", |
| 529 | | DSDD = 0x44445344, // "DSDD", |
| 530 | | DSHD = 0x44485344, // "DSHD", |
| 531 | | DSED = 0x44455344, // "DSED", |
| 612 | SSSD = 0x44535353, //!< "SSSD", Single-sided single-density |
| 613 | SSDD = 0x44445353, //!< "DSSD", Double-sided single-density |
| 614 | DSDD = 0x44445344, //!< "DSDD", Double-sided double-density (720K) |
| 615 | DSHD = 0x44485344, //!< "DSHD", Double-sided high-density (1440K) |
| 616 | DSED = 0x44455344, //!< "DSED", Double-sided extra-density (2880K) |
| 532 | 617 | }; |
| 533 | 618 | |
| 534 | | // construction/destruction |
| 619 | // construction/destruction |
| 620 | |
| 621 | |
| 622 | //! floppy_image constructor |
| 623 | /*! |
| 624 | @param _tracks number of tracks. |
| 625 | @param _heads number of heads. |
| 626 | @param _form_factor form factor of drive (from enum) |
| 627 | */ |
| 535 | 628 | floppy_image(int tracks, int heads, UINT32 form_factor); |
| 536 | 629 | virtual ~floppy_image(); |
| 537 | | |
| 630 | |
| 631 | //! @return the form factor. |
| 538 | 632 | UINT32 get_form_factor() { return form_factor; } |
| 633 | //! @return the variant. |
| 539 | 634 | UINT32 get_variant() { return variant; } |
| 540 | | void set_variant(UINT32 v) { variant = v; } |
| 635 | //! @param v the variant. |
| 636 | void set_variant(UINT32 v) { variant = v; } |
| 541 | 637 | |
| 638 | /*! |
| 639 | @param track |
| 640 | @param head |
| 641 | @param size size of this track |
| 642 | */ |
| 542 | 643 | void set_track_size(int track, int head, UINT32 size) { track_size[track][head] = size; ensure_alloc(track, head); } |
| 644 | |
| 645 | /*! |
| 646 | @param track track number |
| 647 | @param head head number |
| 648 | @return a pointer to the data buffer for this track and head |
| 649 | */ |
| 543 | 650 | UINT32 *get_buffer(int track, int head) { return cell_data[track][head]; } |
| 651 | //! @return the track size |
| 652 | //! @param track |
| 653 | //! @param head |
| 544 | 654 | UINT32 get_track_size(int track, int head) { return track_size[track][head]; } |
| 655 | |
| 656 | //! Sets the write splice position. |
| 657 | //! The "track splice" information indicates where to start writing |
| 658 | //! if you try to rewrite a physical disk with the data. Some |
| 659 | //! preservation formats encode that information, it is guessed for |
| 660 | //! others. The write track function of fdcs should set it. The |
| 661 | //! representation is the angular position relative to the index. |
| 662 | |
| 663 | /*! @param track |
| 664 | @param head |
| 665 | @param pos the position |
| 666 | */ |
| 545 | 667 | void set_write_splice_position(int track, int head, UINT32 pos) { write_splice[track][head] = pos; } |
| 668 | //! @return the current write splice position. |
| 546 | 669 | UINT32 get_write_splice_position(int track, int head) const { return write_splice[track][head]; } |
| 670 | //! @return the maximal geometry supported by thie format. |
| 547 | 671 | void get_maximal_geometry(int &tracks, int &heads); |
| 672 | //! @return the current geometry of the loaded image. |
| 548 | 673 | void get_actual_geometry(int &tracks, int &heads); |
| 549 | | |
| 674 | //! Returns the variant name for the particular disk form factor/variant |
| 675 | //! @param form_factor |
| 676 | //! @param variant |
| 677 | //! @param returns a string containing the variant name. |
| 550 | 678 | static const char *get_variant_name(UINT32 form_factor, UINT32 variant); |
| 551 | 679 | |
| 552 | 680 | private: |
| 681 | |
| 553 | 682 | enum { |
| 554 | 683 | MAX_FLOPPY_HEADS = 2, |
| 555 | 684 | MAX_FLOPPY_TRACKS = 84 |