src/lib/formats/dfi_dsk.c
| r15002 | r15003 | |
| 31 | 31 | |
| 32 | 32 | ****************************************************************************/ |
| 33 | 33 | |
| 34 | | /* TODO: |
| 34 | /* DONE: |
| 35 | 35 | * Support auto-identification heuristics for determining disk image speed, |
| 36 | 36 | capture clock rate, and number of multireads per image. |
| 37 | * TODO: |
| 38 | * Scale captured data based on the guessed clock rate and samplerate to match |
| 39 | the internal 200mhz representation |
| 37 | 40 | * Handle 0xFF bytes properly |
| 38 | 41 | * Correctly note exact index timing. |
| 39 | 42 | */ |
| r15002 | r15003 | |
| 42 | 45 | #include "dfi_dsk.h" |
| 43 | 46 | #include <zlib.h> |
| 44 | 47 | #define NUMBER_OF_MULTIREADS 3 |
| 45 | | // clockspeed: 100mhz = 4, 50mhz = 2, 25mhz = 1 |
| 46 | | #define CLOCKSPEED 4 |
| 47 | 48 | // threshholds for brickwall windowing |
| 48 | | #define MIN_CLOCKS 65 |
| 49 | | #define MAX_CLOCKS 260 |
| 50 | | #define MIN_THRESH (MIN_CLOCKS*CLOCKSPEED) |
| 51 | | #define MAX_THRESH (MAX_CLOCKS*CLOCKSPEED) |
| 49 | //define MIN_CLOCKS 65 |
| 50 | #define MIN_CLOCKS 40 |
| 51 | //define MAX_CLOCKS 260 |
| 52 | #define MAX_CLOCKS 270 |
| 53 | #define MIN_THRESH (MIN_CLOCKS*(clock_rate/25000000)) |
| 54 | #define MAX_THRESH (MAX_CLOCKS*(clock_rate/25000000)) |
| 52 | 55 | // constants to help guess clockrate and rpm |
| 53 | 56 | // constant is 25mhz / 6 revolutions per second (360rpm) = 4166667 +- 2.5% |
| 54 | 57 | #define REV25_MIN 4062500 |
| 55 | 58 | #define REV25_MAX 4270833 |
| 56 | 59 | // define the following to show a histogram per track |
| 60 | //define TRACK_HISTOGRAM 1 |
| 57 | 61 | #undef TRACK_HISTOGRAM |
| 58 | 62 | |
| 59 | 63 | dfi_format::dfi_format() : floppy_image_format_t() |
| r15002 | r15003 | |
| 200 | 204 | if(v & 0x80) { // 0xFF an index, note the index (TODO: actually do this!) and do not add number |
| 201 | 205 | index_polarity ^= 1; |
| 202 | 206 | index_count += index_polarity; |
| 203 | | if (index_count == NUMBER_OF_MULTIREADS) break; |
| 207 | //if (index_count == NUMBER_OF_MULTIREADS) break; |
| 204 | 208 | } |
| 205 | 209 | } |
| 206 | 210 | else if((v & 0x80) == 0) { // 0x00-0x7E: not an index or carry, add the number and store transition |
| r15002 | r15003 | |
| 221 | 225 | } |
| 222 | 226 | if (trans_time > MAX_THRESH) { // we probably missed a transition |
| 223 | 227 | mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A; |
| 224 | | //fprintf(stderr,"missed transition, total time for transition is %d\n",trans_time); |
| 228 | if (((track%2)==0)&&(head==0)) fprintf(stderr,"missed transition, total time for transition is %d\n",trans_time); |
| 225 | 229 | buf[tpos++] = mg | UINT32((200000000ULL*(cur_time-(trans_time/2)))/index_time); // generate imaginary transition at half period |
| 226 | 230 | buf[tpos++] = mg | UINT32(200000000ULL*cur_time/index_time); // generate transition now |
| 227 | 231 | prev_time = cur_time; |
| r15002 | r15003 | |
| 239 | 243 | if (((i+1)%10)==0) fprintf(stderr,"\n"); |
| 240 | 244 | } |
| 241 | 245 | } |
| 246 | fprintf(stderr,"\n"); |
| 242 | 247 | #endif |
| 243 | 248 | index_count = 0; |
| 244 | 249 | image->set_track_size(track, head, tpos); |
src/lib/formats/ap2_dsk.c
| r15002 | r15003 | |
| 613 | 613 | |
| 614 | 614 | bool a2_16sect_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) |
| 615 | 615 | { |
| 616 | | |
| 616 | /* TODO: rewrite me properly |
| 617 | 617 | UINT8 sector_data[(256)*16]; |
| 618 | 618 | memset(sector_data, 0, sizeof(sector_data)); |
| 619 | 619 | |
| r15002 | r15003 | |
| 637 | 637 | generate_track(mac_gcr, track, head, sectors, 16, 3104*16, image); |
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | | return true; |
| 640 | return true;*/ |
| 641 | return false; // I hope that throws an error... |
| 641 | 642 | } |
| 642 | 643 | |
| 643 | 644 | UINT8 a2_16sect_format::gb(const UINT8 *buf, int ts, int &pos, int &wrap) |
| r15002 | r15003 | |
| 664 | 665 | int g_tracks, g_heads; |
| 665 | 666 | int visualgrid[16][35]; // visualizer grid, cleared/initialized below |
| 666 | 667 | #define NOTFOUND 0 |
| 668 | // address mark was found |
| 667 | 669 | #define ADDRFOUND 1 |
| 670 | // address checksum is good |
| 668 | 671 | #define ADDRGOOD 2 |
| 672 | // data mark was found (requires addrfound and sane values) |
| 669 | 673 | #define DATAFOUND 4 |
| 674 | // data checksum is good |
| 670 | 675 | #define DATAGOOD 8 |
| 676 | // data postamble is good |
| 671 | 677 | #define DATAPOST 16 |
| 672 | 678 | for (int i = 0; i < 16; i++) { |
| 673 | 679 | for (int j = 0; j < 35; j++) { |
| r15002 | r15003 | |
| 686 | 692 | int nsect = 16; |
| 687 | 693 | UINT8 buf[130000]; // originally 13000, multiread dfi disks need larger |
| 688 | 694 | int ts; |
| 689 | | fprintf(stderr,"DEBUG: a2_16sect_format::save() about to generate bitstream from physical track %d (logical %d)...", track, track/2); |
| 695 | //fprintf(stderr,"DEBUG: a2_16sect_format::save() about to generate bitstream from physical track %d (logical %d)...", track, track/2); |
| 690 | 696 | //~332 samples per cell, times 3+8+3 (14) for address mark, 24 for sync, 3+343+3 (349) for data mark, 24 for sync is around 743, near 776 expected |
| 691 | | generate_bitstream_from_track(track, head, 200000000/(1552*nsect*2), buf, ts, image); // 3104 needs tweaking, *3 is 3x multiread from a dfi disk |
| 692 | | fprintf(stderr,"done.\n"); |
| 697 | generate_bitstream_from_track(track, head, 200000000/(3104*nsect*3), buf, ts, image); // 3104 needs tweaking, *3 is 3x multiread from a dfi disk |
| 698 | //fprintf(stderr,"done.\n"); |
| 693 | 699 | int pos = 0; |
| 694 | 700 | int wrap = 0; |
| 695 | 701 | int hb = 0; |
| r15002 | r15003 | |
| 767 | 773 | // now decode it into 256 bytes |
| 768 | 774 | // but only write it if the bitfield of the track shows datagood is NOT set. |
| 769 | 775 | // if it is set we don't want to overwrite a guaranteed good read with a bad one |
| 770 | | if ((visualgrid[se][track/2]&DATAGOOD)==0) { |
| 771 | | // TODO: |
| 772 | | // if the current read is good but the postamble isn't, write it in. |
| 773 | | // if the current read isn't good but the postamble is, its better than nothing. |
| 776 | // if past read had a bad checksum or bad postamble... |
| 777 | #ifndef USE_OLD_BEST_SECTOR_PRIORITY |
| 778 | if (((visualgrid[se][track/2]&DATAGOOD)==0)||((visualgrid[se][track/2]&DATAPOST)==0)) { |
| 779 | // if the current read is good, and postamble is good, write it in, no matter what. |
| 780 | // if the current read is good and the current postamble is bad, write it in unless the postamble was good before |
| 781 | // if the current read is bad and the current postamble is good and the previous read had neither good, write it in |
| 774 | 782 | // if the current read isn't good and neither is the postamble but nothing better |
| 775 | 783 | // has been written before, write it anyway. |
| 776 | | for(int i=0x56; i<0x156; i++) { |
| 777 | | UINT8 dv = data[i]; |
| 778 | | *dest++ = dv; |
| 784 | if ( ((data[0x156] == c) && (dpost&0xFFFF00)==0xDEAA00) || |
| 785 | (((data[0x156] == c) && (dpost&0xFFFF00)!=0xDEAA00) && ((visualgrid[se][track/2]&DATAPOST)==0)) || |
| 786 | (((data[0x156] != c) && (dpost&0xFFFF00)==0xDEAA00) && (((visualgrid[se][track/2]&DATAGOOD)==0)&&(visualgrid[se][track/2]&DATAPOST)==0)) || |
| 787 | (((data[0x156] != c) && (dpost&0xFFFF00)!=0xDEAA00) && (((visualgrid[se][track/2]&DATAGOOD)==0)&&(visualgrid[se][track/2]&DATAPOST)==0)) |
| 788 | ) { |
| 789 | for(int i=0x56; i<0x156; i++) { |
| 790 | UINT8 dv = data[i]; |
| 791 | *dest++ = dv; |
| 792 | } |
| 779 | 793 | } |
| 780 | 794 | } |
| 795 | #else |
| 796 | if ((visualgrid[se][track/2]&DATAGOOD)==0) { |
| 797 | for(int i=0x56; i<0x156; i++) { |
| 798 | UINT8 dv = data[i]; |
| 799 | *dest++ = dv; |
| 800 | } |
| 801 | } |
| 802 | #endif |
| 781 | 803 | // do some checking |
| 782 | | if ((data[0x156] != c) || (dpost&0xFFFF00)!=0xDEAA00) { |
| 783 | | printf("Data Mark:\tChecksum xpctd %d found %d: %s, Postamble %03X: %s\n", data[0x156], c, (data[0x156]==c)?"OK":"BAD", dpost, (dpost&0xFFFF00)==0xDEAA00?"OK":"BAD"); |
| 784 | | } |
| 785 | | else visualgrid[se][track/2] |= DATAGOOD; |
| 804 | if ((data[0x156] != c) || (dpost&0xFFFF00)!=0xDEAA00) |
| 805 | fprintf(stderr,"Data Mark:\tChecksum xpctd %d found %d: %s, Postamble %03X: %s\n", data[0x156], c, (data[0x156]==c)?"OK":"BAD", dpost, (dpost&0xFFFF00)==0xDEAA00?"OK":"BAD"); |
| 806 | if (data[0x156] == c) visualgrid[se][track/2] |= DATAGOOD; |
| 807 | if ((dpost&0xFFFF00)==0xDEAA00) visualgrid[se][track/2] |= DATAPOST; |
| 786 | 808 | } else { |
| 787 | 809 | pos = opos; |
| 788 | 810 | wrap = owrap; |
| r15002 | r15003 | |
| 805 | 827 | for (int j = 0; j < 35; j++) { |
| 806 | 828 | printf("T%2d: ",j); |
| 807 | 829 | for (int i = 0; i < 16; i++) { |
| 808 | | if (visualgrid[i][j] == NOTFOUND) printf("-NF-"); |
| 830 | if (visualgrid[i][j] == NOTFOUND) printf("-NF- "); |
| 809 | 831 | else { |
| 810 | 832 | if (visualgrid[i][j] & ADDRFOUND) printf("a"); else printf(" "); |
| 811 | 833 | if (visualgrid[i][j] & ADDRGOOD) printf("A"); else printf(" "); |
| 812 | 834 | if (visualgrid[i][j] & DATAFOUND) printf("d"); else printf(" "); |
| 813 | 835 | if (visualgrid[i][j] & DATAGOOD) printf("D"); else printf(" "); |
| 836 | if (visualgrid[i][j] & DATAPOST) printf("."); else printf(" "); |
| 814 | 837 | } |
| 815 | | printf(" "); |
| 816 | 838 | } |
| 817 | 839 | printf("\n"); |
| 818 | 840 | } |