Previous 15994 Revisions Next

r15000 Sunday 22nd April, 2012 at 17:33:15 UTC by Jonathan Gevaryahu
More work on dfi and apple2 modern disk stuff; most of the auto speed recognition stuff is in the dfi handler now but the actual data scaling to match the internal mfi 200mhz sample rate stream is not done yet. There are also some likely issues with beginnings and ends of index pulses.
Brickwall windowing has been implemented for dfi for regeneration of missed transitions from marginal reads as well as discarding of noise.
A histogram has been added (disabled by default) for dfi format as well.
[Lord Nightmare, Phil Pemberton, Balrog]
[src/lib/formats]ap2_dsk.c dfi_dsk.c

src/lib/formats/dfi_dsk.c
r14999r15000
3131
3232****************************************************************************/
3333
34/* TODO:
35 * Support auto-identification heuristics for determining disk image speed,
36   capture clock rate, and number of multireads per image.
37 * Handle 0xFF bytes properly
38 * Correctly note exact index timing.
39 */
40
3441#include "emu.h"
3542#include "dfi_dsk.h"
3643#include <zlib.h>
37#define NUMBER_OF_MULTIREADS 1
44#define NUMBER_OF_MULTIREADS 3
45// clockspeed: 100mhz = 4, 50mhz = 2, 25mhz = 1
46#define CLOCKSPEED 4
47// 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)
52// constants to help guess clockrate and rpm
53// constant is 25mhz / 6 revolutions per second (360rpm) = 4166667 +- 2.5%
54#define REV25_MIN 4062500
55#define REV25_MAX 4270833
56// define the following to show a histogram per track
57#undef TRACK_HISTOGRAM
3858
3959dfi_format::dfi_format() : floppy_image_format_t()
4060{
r14999r15000
6484{
6585   char sign[4];
6686   io_generic_read(io, sign, 0, 4);
87   if (memcmp(sign, "DFER", 4))
88      fatalerror("Old type Discferret image detected; the mess Discferret decoder will not handle this properly, bailing out!\n");
6789   return memcmp(sign, "DFE2", 4) ? 0 : 100;
6890}
6991
r14999r15000
7395   int pos = 4;
7496   UINT8 *data = 0;
7597   int data_size = 0;
76
98   int onerev_time = 0; // time for one revolution, used to guess clock and rpm for DFE2 files
99   unsigned long clock_rate = 100000000; // sample clock rate in megahertz
100   int rpm = 360; // drive rpm
77101   while(pos < size) {
78102      UINT8 h[10];
79103      io_generic_read(io, h, pos, 10);
r14999r15000
99123      pos += tsize+10;
100124      tsize--; // Drop the extra 0x00 at the end
101125
102      int index_time = 0;
103      int index_count = 0;
104      int total_time = 0;
126      int index_time = 0; // what point the last index happened
127      int index_count = 0; // number of index pulses per track
128      int index_polarity = 0; // current polarity of index
129      int total_time = 0; // total sampled time per track
105130      for(int i=0; i<tsize; i++) {
106131         UINT8 v = data[i];
107         if((v & 0x7f) == 0x7f)
132         //if((v & 0x7f) == 0x7f)
133         if (v == 0x7f)
108134            total_time += 0x7f;
109135         else {
110            total_time += v & 0x7f;
111            if((v & 0x80) && (index_count<NUMBER_OF_MULTIREADS)) {
112               index_time = total_time;///NUMBER_OF_MULTIREADS;
136            if((v & 0x80)==0) total_time += v & 0x7f;
137            if(v & 0x80) {
138               index_time = total_time;
139               if (onerev_time == 0) onerev_time = total_time;
140               //index_polarity ^= 1;
141               //index_count =+ index_polarity;
113142               index_count++;
114143            }
115144         }
r14999r15000
117146
118147      if(!track && !head)
119148         fprintf(stderr, "%02d:%d tt=%10d it=%10d\n", track, head, total_time, index_time);
149      if(!track && !head) {
150         fprintf(stderr, "index_count: %d, onerev_time: %d\n", index_count, onerev_time);
151         if ((onerev_time > REV25_MIN) && (onerev_time < REV25_MAX)) {
152            fprintf(stderr, "Guess: speed: 360rpm, clock 25MHz\n");
153            clock_rate = 25000000; rpm = 360;
154         } else if ((onerev_time > REV25_MIN*1.2) && (onerev_time < REV25_MAX*1.2)) {
155            fprintf(stderr, "Guess: speed: 300rpm, clock 25MHz\n");
156            clock_rate = 25000000; rpm = 300;
157         } else if ((onerev_time > REV25_MIN*2) && (onerev_time < REV25_MAX*2)) {
158            fprintf(stderr, "Guess: speed: 360rpm, clock 50MHz\n");
159            clock_rate = 50000000; rpm = 360;
160         } else if ((onerev_time > (REV25_MIN*2)*1.2) && (onerev_time < (REV25_MAX*2)*1.2)) {
161            fprintf(stderr, "Guess: speed: 300rpm, clock 50MHz\n");
162            clock_rate = 50000000; rpm = 300;
163         } else if ((onerev_time > REV25_MIN*4) && (onerev_time < REV25_MAX*4)) {
164            fprintf(stderr, "Guess: speed: 360rpm, clock 100MHz\n");
165            clock_rate = 100000000; rpm = 360;
166         } else if ((onerev_time > (REV25_MIN*4)*1.2) && (onerev_time < (REV25_MAX*4)*1.2)) {
167            fprintf(stderr, "Guess: speed: 300rpm, clock 100MHz\n");
168            clock_rate = 100000000; rpm = 300;
169         } else
170            fprintf(stderr, "WARNING: Cannot Guess Speed! Assuming 360rpm, 100Mhz clock!\n");
171         fprintf(stderr,"Actual rpm based on index: %f\n", ((double)clock_rate/(double)onerev_time)*60);
172      }
120173
121174      if(!index_time)
122175         index_time = total_time;
r14999r15000
124177      image->set_track_size(track, head, tsize);
125178
126179      int cur_time = 0;
180      int prev_time = 0;
181#ifdef TRACK_HISTOGRAM
182      // histogram
183      int time_buckets[4096];
184      for (int i = 0; i < 4096; i++)
185         time_buckets[i] = 0;
186#endif
127187      index_count = 0;
128      int index_polarity = 0;
188      index_polarity = 0;
129189      UINT32 mg = floppy_image::MG_A;
130190      UINT32 *buf = image->get_buffer(track, head);
131191      int tpos = 0;
132192      buf[tpos++] = mg;
133193      for(int i=0; i<tsize; i++) {
134194         UINT8 v = data[i];
135         if((v & 0x7f) == 0x7f) // 0x7F or 0xFF: no transition, but a carry
136            cur_time += 0x7f;
195         //if((v & 0x7f) == 0x7f) {// 0x7F or 0xFF: no transition, but a carry
196         if (v == 0x7f) {
197            cur_time += 0x7f; // should this be done if v&80 is also set?
198            if(v & 0x80) { // 0xFF an index, note the index (TODO: actually do this!) and do not add number
199               index_polarity ^= 1;
200               index_count += index_polarity;
201               if (index_count == NUMBER_OF_MULTIREADS) break;
202            }
203         }
137204         else if((v & 0x80) == 0) { // 0x00-0x7E: not an index or carry, add the number and store transition
138205            cur_time += v & 0x7f;
139            mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A;
140            buf[tpos++] = mg | UINT32(200000000ULL*cur_time/index_time);
206            int trans_time = cur_time - prev_time;
207#ifdef TRACK_HISTOGRAM
208            time_buckets[(trans_time<4096)?trans_time:4095]++;
209#endif
210            // cur_time and onerev_time need to be converted to something standard, so we'll stick with 300rpm at the standard 200mhz rate that mfi uses internally
211            // TODO for 4/22/2012: ACTUALLY DO THIS RESCALING STEP
212            // filter out spurious crap
213            //if (trans_time <= MIN_THRESH) fprintf(stderr, "DFI: Throwing out short transition of length %d\n", trans_time);
214            //if ((prev_time == 0) || ((trans_time > MIN_THRESH))) {
215            if ((prev_time == 0) || ((trans_time > MIN_THRESH) && (trans_time <= MAX_THRESH))) {
216               mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A;
217               buf[tpos++] = mg | UINT32((200000000ULL*cur_time)/index_time);
218               prev_time = cur_time;
219            }
220            if (trans_time > MAX_THRESH) { // we probably missed a transition
221               mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A;
222               //fprintf(stderr,"missed transition, total time for transition is %d\n",trans_time);
223               buf[tpos++] = mg | UINT32((200000000ULL*(cur_time-(trans_time/2)))/index_time); // generate imaginary transition at half period
224               buf[tpos++] = mg | UINT32(200000000ULL*cur_time/index_time); // generate transition now
225               prev_time = cur_time;
226               }
141227         } else if(v & 0x80) { // 0x80-0xFF an index, note the index (TODO: actually do this!) and do not add number
142228            index_polarity ^= 1;
143229            index_count += index_polarity;
144230            if (index_count == NUMBER_OF_MULTIREADS) break;
145231         }
146232      }
233#ifdef TRACK_HISTOGRAM
234      if (((track%2)==0)&&(head==0)) {
235         for (int i = 0; i < 4096; i++) {
236            fprintf(stderr,"%4d:%4d ", i, time_buckets[i]);
237            if (((i+1)%10)==0) fprintf(stderr,"\n");
238         }
239      }
240#endif
241      index_count = 0;
147242      image->set_track_size(track, head, tpos);
148243   }
149244
src/lib/formats/ap2_dsk.c
r14999r15000
687687            UINT8 buf[130000]; // originally 13000, multiread dfi disks need larger
688688            int ts;
689689fprintf(stderr,"DEBUG: a2_16sect_format::save() about to generate bitstream from physical track %d (logical %d)...", track, track/2);
690            generate_bitstream_from_track(track, head, 200000000/(3104*nsect*1), buf, ts, image); // 3104 needs tweaking, *3 is 3x multiread from a dfi disk
690            //~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
691692fprintf(stderr,"done.\n");
692693            int pos = 0;
693694            int wrap = 0;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team