Previous 15994 Revisions Next

r15037 Thursday 26th April, 2012 at 04:10:18 UTC by Jonathan Gevaryahu
dfi_dsk.c: fixed a nasty bug when reading df bytes with 0x80
set throwing the timing way off; this makes most disk images
decode a whole heck of a lot better.
ap2_dsk.c: fixed a nasty array-out-of-bounds access problem
if an address mark with an insane sector value in it is read.
[Lord Nightmare, Phil Pemberton]
[src/lib/formats]ap2_dsk.c dfi_dsk.c

src/lib/formats/dfi_dsk.c
r15036r15037
4747#define NUMBER_OF_MULTIREADS 3
4848// threshholds for brickwall windowing
4949//define MIN_CLOCKS 65
50// number_please apple2 wants 40 min
5051#define MIN_CLOCKS 40
5152//define MAX_CLOCKS 260
5253#define MAX_CLOCKS 270
r15036r15037
132133
133134      int index_time = 0; // what point the last index happened
134135      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
136137      int total_time = 0; // total sampled time per track
137138      for(int i=0; i<tsize; i++) {
138139         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); }
140141         if((v & 0x7f) == 0x7f)
141142            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;
152153      }
153154
154      if(!track && !head)
155      //if(!track && !head)
155156         fprintf(stderr, "%02d:%d tt=%10d it=%10d\n", track, head, total_time, index_time);
156157      if(!track && !head) {
157158         fprintf(stderr, "index_count: %d, onerev_time: %d\n", index_count, onerev_time);
r15036r15037
194195         time_buckets[i] = 0;
195196#endif
196197      index_count = 0;
197      index_polarity = 0;
198      //index_polarity = 0;
198199      UINT32 mg = floppy_image::MG_A;
199200      UINT32 *buf = image->get_buffer(track, head);
200201      int tpos = 0;
201202      buf[tpos++] = mg;
202203      for(int i=0; i<tsize; i++) {
203204         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;
210212            }
211         }
212213         else if((v & 0x80) == 0) { // 0x00-0x7E: not an index or carry, add the number and store transition
213214            cur_time += v & 0x7f;
214215            int trans_time = cur_time - prev_time;
r15036r15037
219220            // TODO for 4/22/2012: ACTUALLY DO THIS RESCALING STEP
220221            // filter out spurious crap
221222            //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
223224            if ((prev_time == 0) || ((trans_time > MIN_THRESH) && (trans_time <= MAX_THRESH))) {
224225               mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A;
225226               buf[tpos++] = mg | UINT32((200000000ULL*cur_time)/index_time);
226227               prev_time = cur_time;
227228            }
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) {
229231               mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A;
230232               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;
232238               buf[tpos++] = mg | UINT32(200000000ULL*cur_time/index_time); // generate transition now
233239               prev_time = cur_time;
234240               }
235241         } 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;
238244            if (index_count == NUMBER_OF_MULTIREADS) break;
239245         }
240246      }
src/lib/formats/ap2_dsk.c
r15036r15037
738738                        // sanity check
739739                        if (tr == track/2 && se < nsect) {
740740                        visualgrid[se][track/2] |= ADDRFOUND;
741                        visualgrid[se][track/2] |= (chk ^ vl ^ tr ^ se)==0?ADDRGOOD:0;
742                        }
741                        visualgrid[se][track/2] |= ((chk ^ vl ^ tr ^ se)==0)?ADDRGOOD:0;
743742#ifdef LENIENT_ADDR_CHECK
744                        if ((visualgrid[se][track/2] & ADDRFOUND) == ADDRFOUND) {
743                           if ((visualgrid[se][track/2] & ADDRFOUND) == ADDRFOUND) {
745744#else
746                        if ((visualgrid[se][track/2] & ADDRGOOD) == ADDRGOOD) {
745                           if ((visualgrid[se][track/2] & ADDRGOOD) == ADDRGOOD) {
747746#endif
748747                              int opos = pos;
749748                              int owrap = wrap;
r15036r15037
845844                                    pos = opos;
846845                                    wrap = owrap;
847846                              }
847                           }
848848                        }
849849                        hb = 0;
850850                  }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team