trunk/src/lib/formats/d88_dsk.c
| r19074 | r19075 | |
| 504 | 504 | if(!head_count) |
| 505 | 505 | return false; |
| 506 | 506 | |
| 507 | | UINT32 *track_data = global_alloc_array(UINT32, cell_count+10000); |
| 508 | 507 | UINT32 track_pos[164]; |
| 509 | 508 | io_generic_read(io, track_pos, 32, 164*4); |
| 510 | 509 | |
| r19074 | r19075 | |
| 514 | 513 | if(!pos) |
| 515 | 514 | continue; |
| 516 | 515 | |
| 516 | desc_pc_sector sects[256]; |
| 517 | 517 | UINT8 sect_data[65536]; |
| 518 | | int tpos = 0; |
| 519 | | |
| 520 | | // gap 4a , IAM and gap 1 |
| 521 | | for(int i=0; i<80; i++) mfm_w(track_data, tpos, 8, 0x4e); |
| 522 | | for(int i=0; i<12; i++) mfm_w(track_data, tpos, 8, 0x00); |
| 523 | | for(int i=0; i< 3; i++) raw_w(track_data, tpos, 16, 0x5224); |
| 524 | | mfm_w(track_data, tpos, 8, 0xfc); |
| 525 | | for(int i=0; i<50; i++) mfm_w(track_data, tpos, 8, 0x4e); |
| 526 | | |
| 527 | | // Read all sector headers to compute the available and expected size for gap3 |
| 518 | int sdatapos = 0; |
| 528 | 519 | int sector_count = 1; |
| 529 | | int gap3 = 84; |
| 530 | | int etpos = tpos; |
| 531 | | int rpos = pos; |
| 532 | 520 | for(int i=0; i<sector_count; i++) { |
| 533 | 521 | UINT8 hs[16]; |
| 534 | | io_generic_read(io, hs, rpos, 16); |
| 522 | io_generic_read(io, hs, pos, 16); |
| 523 | pos += 16; |
| 524 | |
| 535 | 525 | UINT16 size = LITTLE_ENDIANIZE_INT16(*(UINT16 *)(hs+14)); |
| 536 | | rpos += 16+size; |
| 537 | | if(i == 0) { |
| 526 | if(i == 0) |
| 538 | 527 | sector_count = LITTLE_ENDIANIZE_INT16(*(UINT16 *)(hs+4)); |
| 539 | | if(size < 512) |
| 540 | | gap3 = form_factor == floppy_image::FF_35 ? 54 : 50; |
| 541 | | else |
| 542 | | gap3 = form_factor == floppy_image::FF_35 ? 84 : 80; |
| 543 | | } |
| 544 | | etpos += (12+3+5+2+22+12+3+1+size+2)*16; |
| 545 | | } |
| 546 | 528 | |
| 547 | | if(etpos > cell_count) |
| 548 | | throw emu_fatalerror("d88_format: Incorrect layout on track %d head %d, expected_size=%d, current_size=%d", track, head, cell_count, etpos); |
| 529 | sects[i].track = hs[0]; |
| 530 | sects[i].head = hs[1]; |
| 531 | sects[i].sector = hs[2]; |
| 532 | sects[i].size = hs[3]; |
| 533 | sects[i].actual_size = size; |
| 534 | sects[i].deleted = hs[7] != 0; |
| 535 | sects[i].bad_crc = false; |
| 549 | 536 | |
| 550 | | if(etpos + gap3*16*(sector_count-1) > cell_count) |
| 551 | | gap3 = (cell_count - etpos) / 16 / (sector_count-1); |
| 552 | | |
| 553 | | // Build the track |
| 554 | | for(int i=0; i<sector_count; i++) { |
| 555 | | UINT8 hs[16]; |
| 556 | | io_generic_read(io, hs, pos, 16); |
| 557 | | UINT16 size = LITTLE_ENDIANIZE_INT16(*(UINT16 *)(hs+14)); |
| 558 | | io_generic_read(io, sect_data, pos+16, size); |
| 559 | | pos += 16+size; |
| 560 | | |
| 561 | | int cpos; |
| 562 | | UINT16 crc; |
| 563 | | // sync and IDAM and gap 2 |
| 564 | | for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00); |
| 565 | | cpos = tpos; |
| 566 | | for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489); |
| 567 | | mfm_w(track_data, tpos, 8, 0xfe); |
| 568 | | mfm_w(track_data, tpos, 8, hs[0]); |
| 569 | | mfm_w(track_data, tpos, 8, hs[1]); |
| 570 | | mfm_w(track_data, tpos, 8, hs[2]); |
| 571 | | mfm_w(track_data, tpos, 8, hs[3]); |
| 572 | | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 573 | | mfm_w(track_data, tpos, 16, crc); |
| 574 | | for(int j=0; j<22; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 575 | | |
| 576 | | // sync, DAM, data and gap 3 |
| 577 | | for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00); |
| 578 | | cpos = tpos; |
| 579 | | for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489); |
| 580 | | mfm_w(track_data, tpos, 8, hs[7] ? 0xf8 : 0xfb); |
| 581 | | for(int j=0; j<size; j++) mfm_w(track_data, tpos, 8, sect_data[j]); |
| 582 | | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 583 | | mfm_w(track_data, tpos, 16, crc); |
| 584 | | for(int j=0; j<gap3; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 537 | if(size) { |
| 538 | sects[i].data = sect_data + sdatapos; |
| 539 | io_generic_read(io, sects[i].data, pos+16, size); |
| 540 | pos += size; |
| 541 | } |
| 585 | 542 | } |
| 586 | 543 | |
| 587 | | // Gap 4b |
| 588 | | |
| 589 | | while(tpos < cell_count-15) mfm_w(track_data, tpos, 8, 0x4e); |
| 590 | | raw_w(track_data, tpos, cell_count-tpos, 0x9254 >> (16+tpos-cell_count)); |
| 591 | | |
| 592 | | generate_track_from_levels(track, head, track_data, cell_count, 0, image); |
| 544 | build_pc_track_mfm(track, head, image, cell_count, sector_count, sects, calc_default_pc_gap3_size(form_factor, sects[0].actual_size)); |
| 593 | 545 | } |
| 594 | 546 | |
| 595 | | global_free(track_data); |
| 596 | 547 | return true; |
| 597 | 548 | } |
| 598 | 549 | |
| 599 | 550 | |
| 600 | 551 | bool d88_format::save(io_generic *io, floppy_image *image) |
| 601 | 552 | { |
| 602 | | return true; |
| 553 | return false; |
| 603 | 554 | } |
| 604 | 555 | |
| 605 | 556 | bool d88_format::supports_save() const |
| 606 | 557 | { |
| 607 | | return true; |
| 558 | return false; |
| 608 | 559 | } |
| 609 | 560 | |
| 610 | 561 | const floppy_format_type FLOPPY_D88_FORMAT = &floppy_image_format_creator<d88_format>; |
trunk/src/lib/formats/flopimg.c
| r19074 | r19075 | |
| 2463 | 2463 | memset(sd, 0, sector_size); |
| 2464 | 2464 | } |
| 2465 | 2465 | } |
| 2466 | |
| 2467 | int floppy_image_format_t::calc_default_pc_gap3_size(UINT32 form_factor, int sector_size) |
| 2468 | { |
| 2469 | return |
| 2470 | form_factor == floppy_image::FF_8 ? 25 : |
| 2471 | sector_size < 512 ? |
| 2472 | (form_factor == floppy_image::FF_35 ? 54 : 50) : |
| 2473 | (form_factor == floppy_image::FF_35 ? 84 : 80); |
| 2474 | } |
| 2475 | |
| 2476 | void floppy_image_format_t::build_wd_track_fm(int track, int head, floppy_image *image, int cell_count, int sector_count, const desc_pc_sector *sects, int gap_3, int gap_1, int gap_2) |
| 2477 | { |
| 2478 | build_pc_track_fm(track, head, image, cell_count, sector_count, sects, gap_3, -1, gap_1, gap_2); |
| 2479 | } |
| 2480 | |
| 2481 | void floppy_image_format_t::build_wd_track_mfm(int track, int head, floppy_image *image, int cell_count, int sector_count, const desc_pc_sector *sects, int gap_3, int gap_1, int gap_2) |
| 2482 | { |
| 2483 | build_pc_track_mfm(track, head, image, cell_count, sector_count, sects, gap_3, -1, gap_1, gap_2); |
| 2484 | } |
| 2485 | |
| 2486 | void floppy_image_format_t::build_pc_track_fm(int track, int head, floppy_image *image, int cell_count, int sector_count, const desc_pc_sector *sects, int gap_3, int gap_4a, int gap_1, int gap_2) |
| 2487 | { |
| 2488 | UINT32 *track_data = global_alloc_array(UINT32, cell_count+10000); |
| 2489 | int tpos = 0; |
| 2490 | |
| 2491 | // gap 4a , IAM and gap 1 |
| 2492 | if(gap_4a != -1) { |
| 2493 | for(int i=0; i<gap_4a; i++) fm_w(track_data, tpos, 8, 0xff); |
| 2494 | for(int i=0; i< 6; i++) fm_w(track_data, tpos, 8, 0x00); |
| 2495 | raw_w(track_data, tpos, 16, 0xf77a); |
| 2496 | } |
| 2497 | for(int i=0; i<gap_1; i++) fm_w(track_data, tpos, 8, 0xff); |
| 2498 | |
| 2499 | int total_size = 0; |
| 2500 | for(int i=0; i<sector_count; i++) |
| 2501 | total_size += sects[i].actual_size; |
| 2502 | |
| 2503 | int etpos = tpos; |
| 2504 | etpos += (sector_count*(6+5+2+11+6+1+2) + total_size)*16; |
| 2505 | |
| 2506 | if(etpos > cell_count) |
| 2507 | throw emu_fatalerror("Incorrect layout on track %d head %d, expected_size=%d, current_size=%d", track, head, cell_count, etpos); |
| 2508 | |
| 2509 | if(etpos + gap_3*16*(sector_count-1) > cell_count) |
| 2510 | gap_3 = (cell_count - etpos) / 16 / (sector_count-1); |
| 2511 | |
| 2512 | // Build the track |
| 2513 | for(int i=0; i<sector_count; i++) { |
| 2514 | int cpos; |
| 2515 | UINT16 crc; |
| 2516 | // sync and IDAM and gap 2 |
| 2517 | for(int j=0; j< 6; j++) fm_w(track_data, tpos, 8, 0x00); |
| 2518 | cpos = tpos; |
| 2519 | raw_w(track_data, tpos, 16, 0xf57e); |
| 2520 | fm_w (track_data, tpos, 8, sects[i].track); |
| 2521 | fm_w (track_data, tpos, 8, sects[i].head); |
| 2522 | fm_w (track_data, tpos, 8, sects[i].sector); |
| 2523 | fm_w (track_data, tpos, 8, sects[i].size); |
| 2524 | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 2525 | fm_w (track_data, tpos, 16, crc); |
| 2526 | for(int j=0; j<gap_2; j++) fm_w(track_data, tpos, 8, 0xff); |
| 2527 | |
| 2528 | if(!sects[i].data) |
| 2529 | for(int j=0; j<6+1+sects[i].actual_size+2+gap_3; j++) fm_w(track_data, tpos, 8, 0xff); |
| 2530 | |
| 2531 | else { |
| 2532 | // sync, DAM, data and gap 3 |
| 2533 | for(int j=0; j< 6; j++) fm_w(track_data, tpos, 8, 0x00); |
| 2534 | cpos = tpos; |
| 2535 | raw_w(track_data, tpos, 16, sects[i].deleted ? 0xf56a : 0xf56f); |
| 2536 | for(int j=0; j<sects[i].actual_size; j++) fm_w(track_data, tpos, 8, sects[i].data[j]); |
| 2537 | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 2538 | if(sects[i].bad_crc) |
| 2539 | crc = 0xffff^crc; |
| 2540 | fm_w(track_data, tpos, 16, crc); |
| 2541 | for(int j=0; j<gap_3; j++) fm_w(track_data, tpos, 8, 0xff); |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | // Gap 4b |
| 2546 | |
| 2547 | while(tpos < cell_count-15) fm_w(track_data, tpos, 8, 0xff); |
| 2548 | raw_w(track_data, tpos, cell_count-tpos, 0xffff >> (16+tpos-cell_count)); |
| 2549 | |
| 2550 | generate_track_from_levels(track, head, track_data, cell_count, 0, image); |
| 2551 | global_free(track_data); |
| 2552 | } |
| 2553 | |
| 2554 | void floppy_image_format_t::build_pc_track_mfm(int track, int head, floppy_image *image, int cell_count, int sector_count, const desc_pc_sector *sects, int gap_3, int gap_4a, int gap_1, int gap_2) |
| 2555 | { |
| 2556 | UINT32 *track_data = global_alloc_array(UINT32, cell_count+10000); |
| 2557 | int tpos = 0; |
| 2558 | |
| 2559 | // gap 4a , IAM and gap 1 |
| 2560 | if(gap_4a != -1) { |
| 2561 | for(int i=0; i<gap_4a; i++) mfm_w(track_data, tpos, 8, 0x4e); |
| 2562 | for(int i=0; i<12; i++) mfm_w(track_data, tpos, 8, 0x00); |
| 2563 | for(int i=0; i< 3; i++) raw_w(track_data, tpos, 16, 0x5224); |
| 2564 | mfm_w(track_data, tpos, 8, 0xfc); |
| 2565 | } |
| 2566 | for(int i=0; i<gap_1; i++) mfm_w(track_data, tpos, 8, 0x4e); |
| 2567 | |
| 2568 | int total_size = 0; |
| 2569 | for(int i=0; i<sector_count; i++) |
| 2570 | total_size += sects[i].actual_size; |
| 2571 | |
| 2572 | int etpos = tpos; |
| 2573 | etpos += (sector_count*(12+3+5+2+gap_2+12+3+1+2) + total_size)*16; |
| 2574 | |
| 2575 | if(etpos > cell_count) |
| 2576 | throw emu_fatalerror("Incorrect layout on track %d head %d, expected_size=%d, current_size=%d", track, head, cell_count, etpos); |
| 2577 | |
| 2578 | if(etpos + gap_3*16*(sector_count-1) > cell_count) |
| 2579 | gap_3 = (cell_count - etpos) / 16 / (sector_count-1); |
| 2580 | |
| 2581 | // Build the track |
| 2582 | for(int i=0; i<sector_count; i++) { |
| 2583 | int cpos; |
| 2584 | UINT16 crc; |
| 2585 | // sync and IDAM and gap 2 |
| 2586 | for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00); |
| 2587 | cpos = tpos; |
| 2588 | for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489); |
| 2589 | mfm_w(track_data, tpos, 8, 0xfe); |
| 2590 | mfm_w(track_data, tpos, 8, sects[i].track); |
| 2591 | mfm_w(track_data, tpos, 8, sects[i].head); |
| 2592 | mfm_w(track_data, tpos, 8, sects[i].sector); |
| 2593 | mfm_w(track_data, tpos, 8, sects[i].size); |
| 2594 | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 2595 | mfm_w(track_data, tpos, 16, crc); |
| 2596 | for(int j=0; j<gap_2; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 2597 | |
| 2598 | if(!sects[i].data) |
| 2599 | for(int j=0; j<12+4+sects[i].actual_size+2+gap_3; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 2600 | |
| 2601 | else { |
| 2602 | // sync, DAM, data and gap 3 |
| 2603 | for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00); |
| 2604 | cpos = tpos; |
| 2605 | for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489); |
| 2606 | mfm_w(track_data, tpos, 8, sects[i].deleted ? 0xf8 : 0xfb); |
| 2607 | for(int j=0; j<sects[i].actual_size; j++) mfm_w(track_data, tpos, 8, sects[i].data[j]); |
| 2608 | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 2609 | if(sects[i].bad_crc) |
| 2610 | crc = 0xffff^crc; |
| 2611 | mfm_w(track_data, tpos, 16, crc); |
| 2612 | for(int j=0; j<gap_3; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | // Gap 4b |
| 2617 | |
| 2618 | while(tpos < cell_count-15) mfm_w(track_data, tpos, 8, 0x4e); |
| 2619 | raw_w(track_data, tpos, cell_count-tpos, 0x9254 >> (16+tpos-cell_count)); |
| 2620 | |
| 2621 | generate_track_from_levels(track, head, track_data, cell_count, 0, image); |
| 2622 | global_free(track_data); |
| 2623 | } |
| 2624 | |
trunk/src/lib/formats/imd_dsk.c
| r19074 | r19075 | |
| 414 | 414 | if(ssize == 0xff) |
| 415 | 415 | throw emu_fatalerror("imd_format: Unsupported variable sector size on track %d head %d", track, head); |
| 416 | 416 | |
| 417 | | UINT32 size = ssize < 7 ? 128 << ssize : 8192; |
| 417 | UINT32 actual_size = ssize < 7 ? 128 << ssize : 8192; |
| 418 | 418 | |
| 419 | 419 | static const int rates[3] = { 500000, 300000, 250000 }; |
| 420 | 420 | bool fm = mode < 3; |
| r19074 | r19075 | |
| 433 | 433 | |
| 434 | 434 | head &= 0x3f; |
| 435 | 435 | |
| 436 | | UINT32 *track_data = global_alloc_array(UINT32, cell_count+10000); |
| 437 | | int tpos = 0; |
| 436 | int gap_3 = calc_default_pc_gap3_size(form_factor, actual_size); |
| 438 | 437 | |
| 439 | | // gap 4a , IAM and gap 1 |
| 440 | | if(fm) { |
| 441 | | for(int i=0; i<40; i++) fm_w(track_data, tpos, 8, 0xff); |
| 442 | | for(int i=0; i< 6; i++) fm_w(track_data, tpos, 8, 0x00); |
| 443 | | raw_w(track_data, tpos, 16, 0xf77a); |
| 444 | | for(int i=0; i<26; i++) fm_w(track_data, tpos, 8, 0xff); |
| 445 | | } else { |
| 446 | | for(int i=0; i<80; i++) mfm_w(track_data, tpos, 8, 0x4e); |
| 447 | | for(int i=0; i<12; i++) mfm_w(track_data, tpos, 8, 0x00); |
| 448 | | for(int i=0; i< 3; i++) raw_w(track_data, tpos, 16, 0x5224); |
| 449 | | mfm_w(track_data, tpos, 8, 0xfc); |
| 450 | | for(int i=0; i<50; i++) mfm_w(track_data, tpos, 8, 0x4e); |
| 451 | | } |
| 438 | desc_pc_sector sects[256]; |
| 452 | 439 | |
| 453 | | // Compute the available and expected size for gap3 |
| 454 | | int gap3 = form_factor == floppy_image::FF_8 ? 25 : |
| 455 | | size < 512 ? |
| 456 | | (form_factor == floppy_image::FF_35 ? 54 : 50) : |
| 457 | | (form_factor == floppy_image::FF_35 ? 84 : 80); |
| 440 | for(int i=0; i<sector_count; i++) { |
| 441 | UINT8 stype = img[pos++]; |
| 442 | sects[i].track = tnum ? tnum[i] : track; |
| 443 | sects[i].head = hnum ? hnum[i] : head; |
| 444 | sects[i].sector = snum[i]; |
| 445 | sects[i].size = ssize; |
| 446 | sects[i].actual_size = actual_size; |
| 458 | 447 | |
| 459 | | int etpos = tpos; |
| 460 | | if(fm) |
| 461 | | etpos += sector_count*(6+5+2+11+6+1+size+2)*16; |
| 462 | | else |
| 463 | | etpos += sector_count*(12+3+5+2+22+12+3+1+size+2)*16; |
| 448 | if(stype == 0 || stype > 8) { |
| 449 | sects[i].data = NULL; |
| 450 | |
| 451 | } else { |
| 452 | sects[i].deleted = stype == 3 || stype == 4 || stype == 7 || stype == 8; |
| 453 | sects[i].bad_crc = stype == 5 || stype == 6 || stype == 7 || stype == 8; |
| 464 | 454 | |
| 465 | | if(etpos > cell_count) |
| 466 | | throw emu_fatalerror("imd_format: Incorrect layout on track %d head %d, expected_size=%d, current_size=%d", track, head, cell_count, etpos); |
| 455 | if(stype == 2 || stype == 4 || stype == 6 || stype == 8) { |
| 456 | sects[i].data = global_alloc_array(UINT8, actual_size); |
| 457 | memset(sects[i].data, img[pos++], actual_size); |
| 467 | 458 | |
| 468 | | if(etpos + gap3*16*(sector_count-1) > cell_count) |
| 469 | | gap3 = (cell_count - etpos) / 16 / (sector_count-1); |
| 470 | | |
| 471 | | // Build the track |
| 472 | | if(fm) { |
| 473 | | for(int i=0; i<sector_count; i++) { |
| 474 | | UINT8 stype = img[pos++]; |
| 475 | | |
| 476 | | int cpos; |
| 477 | | UINT16 crc; |
| 478 | | // sync and IDAM and gap 2 |
| 479 | | for(int j=0; j< 6; j++) fm_w(track_data, tpos, 8, 0x00); |
| 480 | | cpos = tpos; |
| 481 | | raw_w(track_data, tpos, 16, 0xf57e); |
| 482 | | fm_w (track_data, tpos, 8, tnum ? tnum[i] : track); |
| 483 | | fm_w (track_data, tpos, 8, hnum ? hnum[i] : head); |
| 484 | | fm_w (track_data, tpos, 8, snum[i]); |
| 485 | | fm_w (track_data, tpos, 8, ssize); |
| 486 | | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 487 | | fm_w (track_data, tpos, 16, crc); |
| 488 | | for(int j=0; j<11; j++) fm_w(track_data, tpos, 8, 0xff); |
| 489 | | |
| 490 | | if(stype == 0 || stype > 8) |
| 491 | | for(int j=0; j<6+1+size+2+gap3; j++) fm_w(track_data, tpos, 8, 0xff); |
| 492 | | |
| 493 | | else { |
| 494 | | // sync, DAM, data and gap 3 |
| 495 | | for(int j=0; j< 6; j++) fm_w(track_data, tpos, 8, 0x00); |
| 496 | | cpos = tpos; |
| 497 | | raw_w(track_data, tpos, 16, stype == 3 || stype == 4 || stype == 7 || stype == 8 ? 0xf56a : 0xf56f); |
| 498 | | if(stype == 2 || stype == 4 || stype == 6 || stype == 8) { |
| 499 | | for(int j=0; j<size; j++) fm_w(track_data, tpos, 8, img[pos]); |
| 500 | | pos++; |
| 501 | | } else |
| 502 | | for(int j=0; j<size; j++) fm_w(track_data, tpos, 8, img[pos++]); |
| 503 | | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 504 | | if(stype == 5 || stype == 6 || stype == 7 || stype == 8) |
| 505 | | crc = 0xffff^crc; |
| 506 | | fm_w(track_data, tpos, 16, crc); |
| 507 | | for(int j=0; j<gap3; j++) fm_w(track_data, tpos, 8, 0xff); |
| 459 | } else { |
| 460 | sects[i].data = img + pos; |
| 461 | pos += actual_size; |
| 508 | 462 | } |
| 509 | 463 | } |
| 510 | | |
| 511 | | // Gap 4b |
| 512 | | |
| 513 | | while(tpos < cell_count-15) fm_w(track_data, tpos, 8, 0xff); |
| 514 | | raw_w(track_data, tpos, cell_count-tpos, 0xffff >> (16+tpos-cell_count)); |
| 515 | | |
| 516 | | } else { |
| 517 | | for(int i=0; i<sector_count; i++) { |
| 518 | | UINT8 stype = img[pos++]; |
| 519 | | |
| 520 | | int cpos; |
| 521 | | UINT16 crc; |
| 522 | | // sync and IDAM and gap 2 |
| 523 | | for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00); |
| 524 | | cpos = tpos; |
| 525 | | for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489); |
| 526 | | mfm_w(track_data, tpos, 8, 0xfe); |
| 527 | | mfm_w(track_data, tpos, 8, tnum ? tnum[i] : track); |
| 528 | | mfm_w(track_data, tpos, 8, hnum ? hnum[i] : head); |
| 529 | | mfm_w(track_data, tpos, 8, snum[i]); |
| 530 | | mfm_w(track_data, tpos, 8, ssize); |
| 531 | | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 532 | | mfm_w(track_data, tpos, 16, crc); |
| 533 | | for(int j=0; j<22; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 534 | | |
| 535 | | if(stype == 0 || stype > 8) |
| 536 | | for(int j=0; j<12+4+size+2+gap3; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 537 | | |
| 538 | | else { |
| 539 | | // sync, DAM, data and gap 3 |
| 540 | | for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00); |
| 541 | | cpos = tpos; |
| 542 | | for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489); |
| 543 | | mfm_w(track_data, tpos, 8, stype == 3 || stype == 4 || stype == 7 || stype == 8 ? 0xf8 : 0xfb); |
| 544 | | if(stype == 2 || stype == 4 || stype == 6 || stype == 8) { |
| 545 | | for(int j=0; j<size; j++) mfm_w(track_data, tpos, 8, img[pos]); |
| 546 | | pos++; |
| 547 | | } else |
| 548 | | for(int j=0; j<size; j++) mfm_w(track_data, tpos, 8, img[pos++]); |
| 549 | | if(stype == 5 || stype == 6 || stype == 7 || stype == 8) |
| 550 | | crc = 0xffff^crc; |
| 551 | | crc = calc_crc_ccitt(track_data, cpos, tpos); |
| 552 | | mfm_w(track_data, tpos, 16, crc); |
| 553 | | for(int j=0; j<gap3; j++) mfm_w(track_data, tpos, 8, 0x4e); |
| 554 | | } |
| 555 | | } |
| 556 | | |
| 557 | | // Gap 4b |
| 558 | | |
| 559 | | while(tpos < cell_count-15) mfm_w(track_data, tpos, 8, 0x4e); |
| 560 | | raw_w(track_data, tpos, cell_count-tpos, 0x9254 >> (16+tpos-cell_count)); |
| 561 | 464 | } |
| 562 | 465 | |
| 563 | | generate_track_from_levels(track, head, track_data, cell_count, 0, image); |
| 564 | | global_free(track_data); |
| 466 | if(fm) |
| 467 | build_pc_track_fm(track, head, image, cell_count, sector_count, sects, gap_3); |
| 468 | else |
| 469 | build_pc_track_mfm(track, head, image, cell_count, sector_count, sects, gap_3); |
| 470 | |
| 471 | for(int i=0; i<sector_count; i++) |
| 472 | if(sects[i].data && (sects[i].data < img || sects[i].data >= img+size)) |
| 473 | global_free(sects[i].data); |
| 565 | 474 | } |
| 566 | 475 | |
| 567 | 476 | global_free(img); |