Previous 15994 Revisions Next

r7407 Wednesday 17th February, 2010 at 22:15:50 UTC by Fabio Priuli
[CBM] Added support for d64 images with sector error codes (preliminary?)
[src/mess/formats]d64_dsk.c

src/mess/formats/d64_dsk.c
r7406r7407
33    formats/d64_dsk.c
44
55    Floppy format code for Commodore 2040/8050 type disk images
6    and for Commodore 1541 D64 disk images
67
78*********************************************************************/
89
r7406r7407
1314    - disk errors
1415    - variable gaps
1516
17    2010-02 FP: I added partial support for disk images with errors
18    but due to lack of docs I'm not sure if we can do better
1619*/
1720
1821#include "emu.h"
r7406r7407
155158   int dos_tracks;                        /* number of logical tracks */
156159   int track_offset[MAX_HEADS][MAX_TRACKS];   /* offset within image for each physical track */
157160   UINT32 speed_zone[MAX_TRACKS];            /* speed zone for each physical track */
161   bool has_errors;                  /* flag to check for available error codes */
158162   int error[MAX_ERROR_SECTORS];            /* error code for each logical sector */
159163
160164   UINT8 id1, id2;                        /* DOS disk format ID */
r7406r7407
239243}
240244
241245/*-------------------------------------------------
246    d64_get_sectors_per_track - returns the offset
247    of the error correspondent to the 1st sector
248    of a given track
249-------------------------------------------------*/
250
251static int d64_get_error_offset(floppy_image *floppy, int head, int track)
252{
253   struct d64dsk_tag *tag = get_tag(floppy);
254   int i, j;
255   int error_offset = 0;
256
257   for (i = 0; i <= head; i++)
258   {
259      for (j = 0; j < track; j++)
260      {
261         if (tag->dos == DOS25)
262         {
263            error_offset += DOS25_SECTORS_PER_TRACK[j];
264         }
265         else if (tag->dos == DOS2)
266         {
267            if(!(j % 2))
268               error_offset += DOS2_SECTORS_PER_TRACK[j / 2];
269         }
270         else
271         {
272            if(!(j % 2))
273               error_offset += DOS1_SECTORS_PER_TRACK[j / 2];
274         }
275      }
276   }
277
278   return error_offset;
279}
280
281/*-------------------------------------------------
242282    gcr_double_2_gcr - GCR decodes given data
243283-------------------------------------------------*/
244284
r7406r7407
349389      UINT16 gcr_track_size;
350390      UINT8 *gcr_track_data;
351391      UINT64 gcr_pos = G64_DATA_START;
392      int error_offset = 0, tmp1, tmp2;
352393
353394      /* determine logical track number */
354395      int dos_track = get_dos_track(track);
r7406r7407
364405      /* determine number of sectors per track */
365406      sectors_per_track = d64_get_sectors_per_track(floppy, head, track);
366407
408      /* determine the position of the error byte for the first sector of this track */
409      if (tag->has_errors)
410         error_offset = d64_get_error_offset(floppy, head, track);
411
367412      /* allocate D64 track data buffer */
368413      d64_track_size = sectors_per_track * SECTOR_SIZE;
369414      d64_track_data = (UINT8 *)alloca(d64_track_size);
r7406r7407
385430      for (int sector = 0; sector < sectors_per_track; sector++)
386431      {
387432         // here we convert the sector data to gcr directly!
388         // IMPORTANT: we shall implement errors in reading sectors!
389         // these can modify e.g. header info $01 & $05
433         // IMPORTANT: errors in reading sectors can modify e.g. header info $01 & $05
390434
391         // first we set the position at which sector data starts in the image
435         /* first we set the position at which sector data starts in the image */
392436         UINT64 d64_pos = sector * SECTOR_SIZE;
393437         int i;
394438
r7406r7407
401445                6. Inter-sector gap  55 55 55 55...55 55 (4 to 19 bytes, never read)
402446            */
403447
448         if (tag->has_errors)
449         {
450            error_offset += sector;
451
452            if (tag->error[error_offset] == ERROR_29)
453               id1 ^= 0xff;
454         }
455
404456         /* Header sync */
405457         for (i = 0; i < 5; i++)
406458            gcr_track_data[gcr_pos + i] = 0xff;
407459         gcr_pos += 5;
408460
461
409462         /* Header info */
410463         /* These are 8 bytes unencoded, which become 10 bytes encoded */
411464         // $00 - header block ID ($08)                      // this byte can be modified by error code 20 -> 0xff
412465         // $01 - header block checksum (EOR of $02-$05)     // this byte can be modified by error code 27 -> ^ 0xff
413466         // $02 - Sector# of data block
414467         // $03 - Track# of data block
415         gcr_double_2_gcr(0x08, sector ^ dos_track ^ id2 ^ id1, sector, dos_track, gcr_track_data + gcr_pos);
468         tmp1 = (tag->has_errors && tag->error[error_offset] == ERROR_20) ? 0xff : 0x08;
469         tmp2 = sector ^ dos_track ^ id2 ^ id1;
470
471         if (tag->has_errors && tag->error[error_offset] == ERROR_27)
472            tmp2 ^= 0xff;
473
474         gcr_double_2_gcr(tmp1, tmp2, sector, dos_track, gcr_track_data + gcr_pos);
416475         gcr_pos += 5;
417476
418477         // $04 - Format ID byte #2
r7406r7407
623682
624683   int heads = 0, dos_tracks = 0, dos = 0;
625684   bool has_errors;
685   int errors_size = 0;
626686
627687   if (params)
628688   {
r7406r7407
641701   tag->heads = heads;
642702   tag->tracks = MAX_TRACKS;
643703   tag->dos_tracks = dos_tracks;
704   tag->has_errors = has_errors;
644705
645706   if (LOG)
646707   {
r7406r7407
648709      logerror("D64 heads: %u\n", heads);
649710      logerror("D64 tracks: %u\n", dos_tracks);
650711      logerror("D64 DOS version: %s\n", DOS_VERSION[dos]);
712      logerror("D64 error codes: %s\n", has_errors ? "yes" : "no");
651713   }
652714
653715   /* clear track data offsets */
r7406r7407
676738               tag->track_offset[head][track] = track_offset;
677739               track_offset += DOS25_SECTORS_PER_TRACK[track] * SECTOR_SIZE;
678740
741               /* also store an error entry for each sector */
742               errors_size += DOS25_SECTORS_PER_TRACK[track];
743
679744               if (LOG) logerror("D64 head %u track %u data offset: %04x\n", head, track + 1, tag->track_offset[head][track]);
680745            }
681746         }
r7406r7407
692757               tag->track_offset[head][track] = track_offset;
693758
694759               if (dos == DOS1)
760               {
695761                  track_offset += DOS1_SECTORS_PER_TRACK[track / 2] * SECTOR_SIZE;
762                  /* also store an error entry for each sector */
763                  errors_size += DOS1_SECTORS_PER_TRACK[track / 2];
764               }
696765               else
766               {
697767                  track_offset += DOS2_SECTORS_PER_TRACK[track / 2] * SECTOR_SIZE;
768                  /* also store an error entry for each sector */
769                  errors_size += DOS2_SECTORS_PER_TRACK[track / 2];
770               }
698771
699772               if (LOG) logerror("D64 head %u track %.1f data offset: %04x\n", head, get_dos_track(track), tag->track_offset[head][track]);
700773            }
r7406r7407
736809
737810   if (LOG) logerror("D64 format ID: %02x%02x\n", id[0], id[1]);
738811
812   /* read errors */
813   if (tag->has_errors)
814      floppy_image_read(floppy, tag->error, track_offset, errors_size);
815   else
816      memset(tag->error, 0, MAX_ERROR_SECTORS);
817
739818   /* set callbacks */
740819   callbacks = floppy_callbacks(floppy);
741820

Previous 15994 Revisions Next


© 1998-2018 The MESS Team