src/lib/formats/dfi_dsk.c
| r15036 | r15037 | |
| 47 | 47 | #define NUMBER_OF_MULTIREADS 3 |
| 48 | 48 | // threshholds for brickwall windowing |
| 49 | 49 | //define MIN_CLOCKS 65 |
| 50 | // number_please apple2 wants 40 min |
| 50 | 51 | #define MIN_CLOCKS 40 |
| 51 | 52 | //define MAX_CLOCKS 260 |
| 52 | 53 | #define MAX_CLOCKS 270 |
| r15036 | r15037 | |
| 132 | 133 | |
| 133 | 134 | int index_time = 0; // what point the last index happened |
| 134 | 135 | int index_count = 0; // number of index pulses per track |
| 135 | | int index_polarity = 0; // current polarity of index |
| 136 | //int index_polarity = 1; // current polarity of index, starts high |
| 136 | 137 | int total_time = 0; // total sampled time per track |
| 137 | 138 | for(int i=0; i<tsize; i++) { |
| 138 | 139 | UINT8 v = data[i]; |
| 139 | | if (v == 0xFF) { fprintf(stderr,"DFI stream contained a 0xFF at t%d, position%d, THIS SHOULD NEVER HAPPEN!\n", track, i); exit(1); } |
| 140 | if (v == 0xFF) { fprintf(stderr,"DFI stream contained a 0xFF at t%d, position%d, THIS SHOULD NEVER HAPPEN! Bailing out!\n", track, i); exit(1); } |
| 140 | 141 | if((v & 0x7f) == 0x7f) |
| 141 | 142 | total_time += 0x7f; |
| 142 | | else { |
| 143 | | if((v & 0x80)==0) total_time += v & 0x7f; |
| 144 | | if(v & 0x80) { |
| 145 | | index_time = total_time; |
| 146 | | if (onerev_time == 0) onerev_time = total_time; |
| 147 | | //index_polarity ^= 1; |
| 148 | | //index_count =+ index_polarity; |
| 149 | | index_count++; |
| 150 | | } |
| 151 | | } |
| 143 | else if(v & 0x80) { |
| 144 | total_time += v & 0x7f; |
| 145 | index_time = total_time; |
| 146 | //index_polarity ^= 1; |
| 147 | //fprintf(stderr,"index state changed to %d at time=%d\n", index_polarity, total_time); |
| 148 | fprintf(stderr,"index rising edge seen at time=%d\n", total_time); |
| 149 | if (onerev_time == 0) onerev_time = total_time; |
| 150 | index_count =+ 1;//index_polarity; |
| 151 | } else // (v & 0x80) == 0 |
| 152 | total_time += v & 0x7f; |
| 152 | 153 | } |
| 153 | 154 | |
| 154 | | if(!track && !head) |
| 155 | //if(!track && !head) |
| 155 | 156 | fprintf(stderr, "%02d:%d tt=%10d it=%10d\n", track, head, total_time, index_time); |
| 156 | 157 | if(!track && !head) { |
| 157 | 158 | fprintf(stderr, "index_count: %d, onerev_time: %d\n", index_count, onerev_time); |
| r15036 | r15037 | |
| 194 | 195 | time_buckets[i] = 0; |
| 195 | 196 | #endif |
| 196 | 197 | index_count = 0; |
| 197 | | index_polarity = 0; |
| 198 | //index_polarity = 0; |
| 198 | 199 | UINT32 mg = floppy_image::MG_A; |
| 199 | 200 | UINT32 *buf = image->get_buffer(track, head); |
| 200 | 201 | int tpos = 0; |
| 201 | 202 | buf[tpos++] = mg; |
| 202 | 203 | for(int i=0; i<tsize; i++) { |
| 203 | 204 | UINT8 v = data[i]; |
| 204 | | if((v & 0x7f) == 0x7f) {// 0x7F or 0xFF: no transition, but a carry |
| 205 | | cur_time += 0x7f; // should this be done if v&80 is also set? |
| 206 | | if(v & 0x80) { // 0xFF an index, note the index (TODO: actually do this!) and do not add number |
| 207 | | index_polarity ^= 1; |
| 208 | | index_count += index_polarity; |
| 209 | | //if (index_count == NUMBER_OF_MULTIREADS) break; |
| 205 | if((v & 0x7f) == 0x7f) // 0x7F : no transition, but a carry (FF is a board-on-fire error and is checked for above) |
| 206 | cur_time += 0x7f; |
| 207 | else if(v & 0x80) { // 0x80 set, note the index (TODO: actually do this!) and add number to count |
| 208 | cur_time += v & 0x7f; |
| 209 | //index_polarity ^= 1; |
| 210 | index_count += 1;//index_polarity; |
| 211 | //if (index_count == NUMBER_OF_MULTIREADS) break; |
| 210 | 212 | } |
| 211 | | } |
| 212 | 213 | else if((v & 0x80) == 0) { // 0x00-0x7E: not an index or carry, add the number and store transition |
| 213 | 214 | cur_time += v & 0x7f; |
| 214 | 215 | int trans_time = cur_time - prev_time; |
| r15036 | r15037 | |
| 219 | 220 | // TODO for 4/22/2012: ACTUALLY DO THIS RESCALING STEP |
| 220 | 221 | // filter out spurious crap |
| 221 | 222 | //if (trans_time <= MIN_THRESH) fprintf(stderr, "DFI: Throwing out short transition of length %d\n", trans_time); |
| 222 | | //if ((prev_time == 0) || ((trans_time > MIN_THRESH))) { |
| 223 | // the normal case: write the transition at the appropriate time |
| 223 | 224 | if ((prev_time == 0) || ((trans_time > MIN_THRESH) && (trans_time <= MAX_THRESH))) { |
| 224 | 225 | mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A; |
| 225 | 226 | buf[tpos++] = mg | UINT32((200000000ULL*cur_time)/index_time); |
| 226 | 227 | prev_time = cur_time; |
| 227 | 228 | } |
| 228 | | if (trans_time > MAX_THRESH) { // we probably missed a transition |
| 229 | // the long case: we probably missed a transition, stuff an extra guessed one in there to see if it helps |
| 230 | if (trans_time > MAX_THRESH) { |
| 229 | 231 | mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A; |
| 230 | 232 | if (((track%2)==0)&&(head==0)) fprintf(stderr,"missed transition, total time for transition is %d\n",trans_time); |
| 231 | | buf[tpos++] = mg | UINT32((200000000ULL*(cur_time-(trans_time/2)))/index_time); // generate imaginary transition at half period |
| 233 | //buf[tpos++] = mg | UINT32((200000000ULL*(cur_time-(trans_time/2)))/index_time); // generate imaginary transition at half period |
| 234 | buf[tpos++] = mg | UINT32((200000000ULL*(cur_time-((trans_time*2)/3)))/index_time); |
| 235 | mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A; |
| 236 | buf[tpos++] = mg | UINT32((200000000ULL*(cur_time-(trans_time/3)))/index_time); |
| 237 | mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A; |
| 232 | 238 | buf[tpos++] = mg | UINT32(200000000ULL*cur_time/index_time); // generate transition now |
| 233 | 239 | prev_time = cur_time; |
| 234 | 240 | } |
| 235 | 241 | } else if(v & 0x80) { // 0x80-0xFF an index, note the index (TODO: actually do this!) and do not add number |
| 236 | | index_polarity ^= 1; |
| 237 | | index_count += index_polarity; |
| 242 | //index_polarity ^= 1; |
| 243 | index_count += 1;//index_polarity; |
| 238 | 244 | if (index_count == NUMBER_OF_MULTIREADS) break; |
| 239 | 245 | } |
| 240 | 246 | } |