Previous 15994 Revisions Next

r7137 Friday 22nd January, 2010 at 22:29:26 UTC by Curt Coder
Added preliminary D67/D80/D82 floppy image read support.
[src/mess/formats]d64_dsk.c d64_dsk.h
[src/mess/machine]c2040.c

src/mess/machine/c2040.c
r7136r7137
1111#include "c2040.h"
1212#include "cpu/m6502/m6502.h"
1313#include "devices/flopdrv.h"
14#include "formats/d64_dsk.h"
1415#include "formats/g64_dsk.h"
1516#include "machine/6522via.h"
1617#include "machine/6532riot.h"
r7136r7137
792793-------------------------------------------------*/
793794
794795static FLOPPY_OPTIONS_START( c2040 )
795//   FLOPPY_OPTION( c2040, "d67", "Commodore 2040 (DOS 1) Disk Image", d67_dsk_identify, d67_dsk_construct, NULL )
796//  FLOPPY_OPTION( c2040, "d64", "Commodore 1541 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
797   FLOPPY_OPTION( c2040, "g64", "Commodore 1541 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
796   FLOPPY_OPTION( c2040, "d67", "Commodore 2040 (DOS 1) Disk Image", d67_dsk_identify, d64_dsk_construct, NULL )
798797FLOPPY_OPTIONS_END
799798
800799/*-------------------------------------------------
r7136r7137
802801-------------------------------------------------*/
803802
804803static FLOPPY_OPTIONS_START( c3040 )
805//  FLOPPY_OPTION( c3040, "d64", "Commodore 1541 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
804   FLOPPY_OPTION( c3040, "d64", "Commodore 1541 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
806805   FLOPPY_OPTION( c3040, "g64", "Commodore 1541 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
807806FLOPPY_OPTIONS_END
808807
r7136r7137
811810-------------------------------------------------*/
812811
813812static FLOPPY_OPTIONS_START( c8050 )
814//   FLOPPY_OPTION( c8050, "d80", "Commodore 8050 Disk Image", d80_dsk_identify, d80_dsk_construct, NULL )
813   FLOPPY_OPTION( c8050, "d80", "Commodore 8050 Disk Image", d80_dsk_identify, d64_dsk_construct, NULL )
815814FLOPPY_OPTIONS_END
816815
817816/*-------------------------------------------------
r7136r7137
819818-------------------------------------------------*/
820819
821820static FLOPPY_OPTIONS_START( c8250 )
822//   FLOPPY_OPTION( c8250, "d80", "Commodore 8050 Disk Image", d80_dsk_identify, d80_dsk_construct, NULL )
823//   FLOPPY_OPTION( c8250, "d82", "Commodore 8250/SFD1001 Disk Image", d82_dsk_identify, d82_dsk_construct, NULL )
821   FLOPPY_OPTION( c8250, "d80", "Commodore 8050 Disk Image", d80_dsk_identify, d64_dsk_construct, NULL )
822   FLOPPY_OPTION( c8250, "d82", "Commodore 8250/SFD1001 Disk Image", d82_dsk_identify, d64_dsk_construct, NULL )
824823FLOPPY_OPTIONS_END
825824
826825/*-------------------------------------------------
src/mess/formats/d64_dsk.c
r7136r7137
2828*/
2929
3030/*
31    Code  Error  Type   1541 error description
32    ----  -----  ----   ------------------------------
33     01    00    N/A    No error, Sektor ok.
34     02    20    Read   Header block not found
35     03    21    Seek   No sync character
36     04    22    Read   Data block not present
37     05    23    Read   Checksum error in data block
38     06    24    Write  Write verify (on format)
39     07    25    Write  Write verify error
40     08    26    Write  Write protect on
41     09    27    Seek   Checksum error in header block
42     0A    28    Write  Write error
43     0B    29    Seek   Disk ID mismatch
44     0F    74    Read   Disk Not Ready (no device 1)
45*/
4631
47/*
48
4932    TODO:
5033
51   - cleanup
52   - dos2_encode_gcr() function
5334    - disk errors
54   - D80/D82
5535   - variable gaps
5636
5737*/
r7136r7137
6343
6444#define LOG 1
6545
66#define MAX_HEADS      2
67#define MAX_TRACKS      84
68#define MAX_SECTORS      802
69#define SECTOR_SIZE      256
46#define MAX_HEADS         2
47#define MAX_TRACKS         84
48#define MAX_ERROR_SECTORS   802
49#define SECTOR_SIZE         256
50#define SECTOR_SIZE_GCR      368
7051
71#define OFFSET_INVALID   0xbadbad
52#define INVALID_OFFSET      0xbadbad
7253
73#define D71_MAX_TRACKS      70
74#define D81_MAX_TRACKS      80
75#define D80_MAX_TRACKS      77
76/* Still have to investigate if these are read as 154 or as 77 in the drive... */
77/* For now we assume it's 154, but I'm not sure */
78#define D82_MAX_TRACKS      154
54enum
55{
56   DOS1,
57   DOS2,
58   DOS27
59};
7960
80#define D64_SIZE_35_TRACKS            174848
81#define D64_SIZE_35_TRACKS_WITH_ERRORS   175531
82#define D64_SIZE_40_TRACKS            196608
83#define D64_SIZE_40_TRACKS_WITH_ERRORS   197376
84#define D64_SIZE_42_TRACKS            205312
85#define D64_SIZE_42_TRACKS_WITH_ERRORS   206114
86#define D71_SIZE_70_TRACKS            349696
87#define D71_SIZE_70_TRACKS_WITH_ERRORS   351062
61enum
62{
63   ERROR_00 = 1,
64   ERROR_20,      /* header block not found */
65   ERROR_21,      /* no sync character */
66   ERROR_22,      /* data block not present */
67   ERROR_23,      /* checksum error in data block */
68   ERROR_24,      /* write verify (on format) */
69   ERROR_25,      /* write verify error */
70   ERROR_26,      /* write protect on */
71   ERROR_27,      /* checksum error in header block */
72   ERROR_28,      /* write error */
73   ERROR_29,      /* disk ID mismatch */
74   ERROR_74,      /* disk not ready (no device 1) */
75};
8876
89static const int D64_SECTORS_PER_TRACK[] =
77#define D64_SIZE_35_TRACKS             174848
78#define D64_SIZE_35_TRACKS_WITH_ERRORS    175531
79#define D64_SIZE_40_TRACKS             196608
80#define D64_SIZE_40_TRACKS_WITH_ERRORS    197376
81#define D64_SIZE_42_TRACKS             205312
82#define D64_SIZE_42_TRACKS_WITH_ERRORS    206114
83#define D67_SIZE_35_TRACKS             176640
84#define D71_SIZE_70_TRACKS             349696
85#define D71_SIZE_70_TRACKS_WITH_ERRORS    351062
86#define D80_SIZE_77_TRACKS             533248
87#define D82_SIZE_154_TRACKS            1066496
88
89static const int DOS1_SECTORS_PER_TRACK[] =
9090{
9191   21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
92   19, 19, 19, 19, 19, 19, 19,
92   20, 20, 20, 20, 20, 20, 20,
9393   18, 18, 18, 18, 18, 18,
9494   17, 17, 17, 17, 17,
9595   17, 17, 17, 17, 17,
9696   17, 17
9797};
9898
99static const int D64_SPEED_ZONE[] =
99static const int DOS1_SPEED_ZONE[] =
100100{
101101   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
102102   2, 2, 2, 2, 2, 2, 2,
103103   1, 1, 1, 1, 1, 1,
104   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
104   0, 0, 0, 0, 0,
105   0, 0, 0, 0, 0,
106   0, 0
105107};
106108
107#if 0
109static const int DOS2_SECTORS_PER_TRACK[] =
110{
111   21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
112   19, 19, 19, 19, 19, 19, 19,
113   18, 18, 18, 18, 18, 18,
114   17, 17, 17, 17, 17,
115   17, 17, 17, 17, 17,
116   17, 17
117};
108118
109/*
110
111   CBM8050/8250 Format
112
113   29sectors/track for track 1-39/78-116
114   27sectors/track for track 40-53/117-130
115   25sectors/track for track 54-64/131-141
116   23sectors/track for track 65-77/142-154
117
118   BAM on track 38 (8050 2 blocks, 8250 4 blocks, rest is free for files)
119   DIR on track 39 (1 block for header, 28 blocks for dir entries)
120
121*/
122
123static const int D80_SECTORS_PER_TRACK[] =
119static const int DOS27_SECTORS_PER_TRACK[] =
124120{
125121   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
126   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
127   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
128   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
129   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
122   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,      /* 1-39 */
123   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,                     /* 40-53 */
124   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,                              /* 54-64 */
125   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,                        /* 65-77 */
126   23, 23, 23, 23, 23, 23, 23                                          /* 78-84 */
130127};
131128
132static const int D82_SECTORS_PER_TRACK[] =
129static const int DOS27_SPEED_ZONE[] =
133130{
134   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
135   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
136   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
138   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
139   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
140   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
141   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
142   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
143   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
131   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
132   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,   /* 1-39 */
133   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,               /* 40-53 */
134   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,                     /* 54-64 */
135   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                  /* 65-77 */
136   0, 0, 0, 0, 0, 0, 0                                 /* 78-84 */
144137};
145#endif
146138
147139struct d64dsk_tag
148140{
141   int dos;                           /* CBM DOS version */
149142   int heads;                           /* number of physical heads */
150143   int tracks;                           /* number of physical tracks */
151144   int dos_tracks;                        /* number of logical tracks */
152145   int track_offset[MAX_HEADS][MAX_TRACKS];   /* offset within image for each physical track */
153146   UINT32 speed_zone[MAX_TRACKS];            /* speed zone for each physical track */
154   int error[MAX_SECTORS];                  /* error code for each logical sector */
147   int error[MAX_ERROR_SECTORS];            /* error code for each logical sector */
155148
156149   UINT8 id1, id2;                        /* DOS disk format ID */
157150};
158151
159INLINE float get_track_index(int track)
152INLINE float get_dos_track(int track)
160153{
161154   return ((float)track / 2) + 1;
162155}
r7136r7137
178171   return get_tag(floppy)->tracks;
179172}
180173
174static int d64_get_sectors_per_track(floppy_image *floppy, int head, int track)
175{
176   int sectors_per_track = 0;
177   
178   switch (get_tag(floppy)->dos)
179   {
180   case DOS1:   sectors_per_track = DOS1_SECTORS_PER_TRACK[track / 2]; break;
181   case DOS2:   sectors_per_track = DOS2_SECTORS_PER_TRACK[track / 2]; break;
182   case DOS27:   sectors_per_track = DOS27_SECTORS_PER_TRACK[track];     break;
183   }
184
185   return sectors_per_track;
186}
187
181188static floperr_t get_track_offset(floppy_image *floppy, int head, int track, UINT64 *offset)
182189{
183190   struct d64dsk_tag *tag = get_tag(floppy);
r7136r7137
244251
245252static floperr_t d64_read_track(floppy_image *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen)
246253{
254   struct d64dsk_tag *tag = get_tag(floppy);
247255   floperr_t err;
248256   UINT64 track_offset;
249257
r7136r7137
253261   if (err)
254262      return err;
255263
256   if (track_offset != OFFSET_INVALID)
264   if (track_offset != INVALID_OFFSET)
257265   {
258      int gcr_pos = 2, i, sector, d64_pos;
259      int id1 = get_tag(floppy)->id1;
260      int id2 = get_tag(floppy)->id2;
261      int full_track = track / 2;
262      int dos_track = full_track + 1;
263      int sectors_per_track = D64_SECTORS_PER_TRACK[full_track];
266      UINT8 id1 = tag->id1;
267      UINT8 id2 = tag->id2;
264268
265      UINT16 d64_track_size = sectors_per_track * 256;
266      UINT16 gcr_track_size = 2 + (sectors_per_track * 368);
269      /* determine logical track number */
270      int dos_track = get_dos_track(track);
271     
272      if (tag->dos == DOS27)
273      {
274         dos_track = track + 1;
275      }
267276
268      UINT8 d64_track_data[d64_track_size];
269      UINT8 gcr_track_data[gcr_track_size];
277      /* logical track numbers continue on the flip side */
278      if (head == 1) dos_track += tag->dos_tracks;
270279
271      UINT8 sector_checksum;
280      /* determine number of sectors per track */
281      int sectors_per_track = d64_get_sectors_per_track(floppy, head, track);
272282
273      /* track numbers continue on the flip side */
274      if (head == 1) dos_track += get_tag(floppy)->dos_tracks;
283      /* allocate D64 track data buffer */
284      UINT16 d64_track_size = sectors_per_track * SECTOR_SIZE;
285      UINT8 d64_track_data[d64_track_size];
275286
287      /* allocate temporary GCR track data buffer */
288      UINT16 gcr_track_size = 2 + (sectors_per_track * SECTOR_SIZE_GCR);
289      UINT8 gcr_track_data[gcr_track_size];
290      UINT64 gcr_pos = 2;
291     
276292      if (buflen < gcr_track_size) fatalerror("D64 track buffer too small: %u!\n", (UINT32)buflen);
277293
278      /* set GCR track size to buffer */
294      /* prepend GCR track data buffer with GCR track size */
279295      gcr_track_data[0] = gcr_track_size & 0xff;
280296      gcr_track_data[1] = gcr_track_size >> 8;
281297
298      /* read D64 track data */
282299      floppy_image_read(floppy, d64_track_data, track_offset, d64_track_size);
283300
284      for (sector = 0; sector < sectors_per_track; sector++)
301      /* GCR encode D64 sector data */
302      for (int sector = 0; sector < sectors_per_track; sector++)
285303      {
286304         // here we convert the sector data to gcr directly!
287305         // IMPORTANT: we shall implement errors in reading sectors!
288306         // these can modify e.g. header info $01 & $05
289307
290308         // first we set the position at which sector data starts in the image
291         d64_pos = sector * 256;
309         UINT64 d64_pos = sector * SECTOR_SIZE;
310         int i;
292311
293312         /*
294313                1. Header sync       FF FF FF FF FF (40 'on' bits, not GCR encoded)
r7136r7137
332351
333352         /* Data block */
334353         // we first need to calculate the checksum of the 256 bytes of the sector
335         sector_checksum = d64_track_data[d64_pos];
354         UINT8 sector_checksum = d64_track_data[d64_pos];
336355         for (i = 1; i < 256; i++)
337356            sector_checksum ^= d64_track_data[d64_pos + i];
338357
r7136r7137
380399   return FLOPPY_ERROR_UNSUPPORTED;
381400}
382401
383static void d64_identify(floppy_image *floppy, int *heads, int *tracks, bool *has_errors)
402static void d64_identify(floppy_image *floppy, int *dos, int *heads, int *tracks, bool *has_errors)
384403{
385404   switch (floppy_image_size(floppy))
386405   {
387   case D64_SIZE_35_TRACKS:            *heads = 1;   *tracks = 35; *has_errors = false; break;
388   case D64_SIZE_35_TRACKS_WITH_ERRORS:   *heads = 1;   *tracks = 35; *has_errors = true;  break;
389   case D64_SIZE_40_TRACKS:            *heads = 1; *tracks = 40; *has_errors = false; break;
390   case D64_SIZE_40_TRACKS_WITH_ERRORS:   *heads = 1;   *tracks = 40; *has_errors = true;  break;
391   case D64_SIZE_42_TRACKS:            *heads = 1;   *tracks = 42; *has_errors = false; break;
392   case D64_SIZE_42_TRACKS_WITH_ERRORS:   *heads = 1;   *tracks = 42; *has_errors = true;  break;
393   case D71_SIZE_70_TRACKS:            *heads = 2;   *tracks = 35; *has_errors = false; break;
394   case D71_SIZE_70_TRACKS_WITH_ERRORS:   *heads = 2;   *tracks = 35; *has_errors = true;  break;
406   /* 2040/3040 */
407   case D67_SIZE_35_TRACKS:            *dos = DOS1;  *heads = 1; *tracks = 35; *has_errors = false; break;
408
409   /* 4040/2031/1541/1551 */
410   case D64_SIZE_35_TRACKS:            *dos = DOS2;  *heads = 1; *tracks = 35; *has_errors = false; break;
411   case D64_SIZE_35_TRACKS_WITH_ERRORS:   *dos = DOS2;  *heads = 1; *tracks = 35; *has_errors = true;  break;
412   case D64_SIZE_40_TRACKS:            *dos = DOS2;  *heads = 1; *tracks = 40; *has_errors = false; break;
413   case D64_SIZE_40_TRACKS_WITH_ERRORS:   *dos = DOS2;  *heads = 1; *tracks = 40; *has_errors = true;  break;
414   case D64_SIZE_42_TRACKS:            *dos = DOS2;  *heads = 1; *tracks = 42; *has_errors = false; break;
415   case D64_SIZE_42_TRACKS_WITH_ERRORS:   *dos = DOS2;  *heads = 1; *tracks = 42; *has_errors = true;  break;
416
417   /* 1571 */
418   case D71_SIZE_70_TRACKS:            *dos = DOS2;  *heads = 2; *tracks = 35; *has_errors = false; break;
419   case D71_SIZE_70_TRACKS_WITH_ERRORS:   *dos = DOS2;  *heads = 2; *tracks = 35; *has_errors = true;  break;
420
421   /* 8050 */
422   case D80_SIZE_77_TRACKS:            *dos = DOS27; *heads = 1; *tracks = 77; *has_errors = false; break;
423
424   /* 8250/SFD1001 */
425   case D82_SIZE_154_TRACKS:            *dos = DOS27; *heads = 2; *tracks = 77; *has_errors = false; break;
395426   }
396427}
397428
398429FLOPPY_IDENTIFY( d64_dsk_identify )
399430{
400   int heads = 0, tracks = 0;
431   int dos = 0, heads, tracks;
401432   bool has_errors = false;
402433
403434   *vote = 0;
404435
405   d64_identify(floppy, &heads, &tracks, &has_errors);
436   d64_identify(floppy, &dos, &heads, &tracks, &has_errors);
406437
407   if (heads == 1 && (tracks == 35 || tracks == 40 || tracks == 42))
438   if (dos == DOS2 && heads == 1)
408439   {
409440      *vote = 100;
410441   }
r7136r7137
412443   return FLOPPY_ERROR_SUCCESS;
413444}
414445
446FLOPPY_IDENTIFY( d67_dsk_identify )
447{
448   *vote = 0;
449
450   if (floppy_image_size(floppy) == D67_SIZE_35_TRACKS)
451   {
452      *vote = 100;
453   }
454
455   return FLOPPY_ERROR_SUCCESS;
456}
457
415458FLOPPY_IDENTIFY( d71_dsk_identify )
416459{
417   int heads = 0, tracks = 0;
460   int heads = 0, tracks = 0, dos;
418461   bool has_errors = false;
419462
420463   *vote = 0;
421464
422   d64_identify(floppy, &heads, &tracks, &has_errors);
465   d64_identify(floppy, &dos, &heads, &tracks, &has_errors);
423466
424   if (heads == 2 && tracks == 35)
467   if (dos == DOS2 && heads == 2)
425468   {
426469      *vote = 100;
427470   }
r7136r7137
429472   return FLOPPY_ERROR_SUCCESS;
430473}
431474
475FLOPPY_IDENTIFY( d80_dsk_identify )
476{
477   *vote = 0;
478
479   if (floppy_image_size(floppy) == D80_SIZE_77_TRACKS)
480   {
481      *vote = 100;
482   }
483
484   return FLOPPY_ERROR_SUCCESS;
485}
486
487FLOPPY_IDENTIFY( d82_dsk_identify )
488{
489   *vote = 0;
490
491   if (floppy_image_size(floppy) == D82_SIZE_154_TRACKS)
492   {
493      *vote = 100;
494   }
495
496   return FLOPPY_ERROR_SUCCESS;
497}
498
432499FLOPPY_CONSTRUCT( d64_dsk_construct )
433500{
434501   struct FloppyCallbacks *callbacks;
r7136r7137
438505   int track_offset = 0;
439506   int head, track;
440507   
441   int heads = 0, dos_tracks = 0;
508   int heads = 0, dos_tracks = 0, dos = 0;
442509   bool has_errors;
443510
444511   if (params)
r7136r7137
452519   if (!tag) return FLOPPY_ERROR_OUTOFMEMORY;
453520
454521   /* identify image type */
455   d64_identify(floppy, &heads, &dos_tracks, &has_errors);
522   d64_identify(floppy, &dos, &heads, &dos_tracks, &has_errors);
456523
524   tag->dos = dos;
457525   tag->heads = heads;
458526   tag->tracks = MAX_TRACKS;
459527   tag->dos_tracks = dos_tracks;
460528
461   /* read format ID from directory */
462   floppy_image_read(floppy, id, get_tag(floppy)->track_offset[0][34] + 0xa2, 2);
463
464   get_tag(floppy)->id1 = id[0];
465   get_tag(floppy)->id2 = id[1];
466
467529   if (LOG)
468530   {
469531      logerror("D64 size: %04x\n", (UINT32)floppy_image_size(floppy));
470532      logerror("D64 heads: %u\n", heads);
471533      logerror("D64 tracks: %u\n", dos_tracks);
472      logerror("D64 format ID: %02x%02x\n", id[0], id[1]);
473534   }
474535
475   /* data offsets */
536   /* determine track data offsets */
476537   for (head = 0; head < heads; head++)
477538   {
478539      for (track = 0; track < tag->tracks; track++)
479540      {
480         if ((track % 2) || ((track / 2) >= dos_tracks))
541         if (dos == DOS27)
481542         {
482            /* half track or out of range */
483            tag->track_offset[head][track] = OFFSET_INVALID;
543            if (track >= dos_tracks)
544            {
545               /* track out of range */
546               tag->track_offset[head][track] = INVALID_OFFSET;
547            }
548            else
549            {
550               tag->track_offset[head][track] = track_offset;
551               track_offset += DOS27_SECTORS_PER_TRACK[track] * SECTOR_SIZE;
552   
553               if (LOG) logerror("D64 head %u track %u data offset: %04x\n", head, track, tag->track_offset[head][track]);
554            }
484555         }
485556         else
486557         {
487            /* full track */
488            tag->track_offset[head][track] = track_offset;
489            track_offset += D64_SECTORS_PER_TRACK[track / 2] * SECTOR_SIZE;
558            if ((track % 2) || ((track / 2) >= dos_tracks))
559            {
560               /* half track or out of range */
561               tag->track_offset[head][track] = INVALID_OFFSET;
562            }
563            else
564            {
565               /* full track */
566               tag->track_offset[head][track] = track_offset;
567               
568               if (dos == DOS1)
569                  track_offset += DOS1_SECTORS_PER_TRACK[track / 2] * SECTOR_SIZE;
570               else
571                  track_offset += DOS2_SECTORS_PER_TRACK[track / 2] * SECTOR_SIZE;
572
573               if (LOG) logerror("D64 head %u track %.1f data offset: %04x\n", head, get_dos_track(track), tag->track_offset[head][track]);
574            }
490575         }
491
492         if (LOG) logerror("D64 head %u track %.1f data offset: %04x\n", head, get_track_index(track), tag->track_offset[head][track]);
493576      }
494577   }
495578
496   /* speed zones */
579   /* determine speed zones */
497580   for (track = 0; track < tag->tracks; track++)
498581   {
499      tag->speed_zone[track] = D64_SPEED_ZONE[track / 2];
582      if (dos == DOS27)
583      {
584         tag->speed_zone[track] = DOS27_SPEED_ZONE[track];
500585
501      if (LOG) logerror("D64 track %.1f speed zone: %u\n", get_track_index(track), tag->speed_zone[track]);
586         if (LOG) logerror("D64 track %u speed zone: %u\n", track, tag->speed_zone[track]);
587      }
588      else
589      {
590         tag->speed_zone[track] = DOS1_SPEED_ZONE[track / 2];
591
592         if (LOG) logerror("D64 track %.1f speed zone: %u\n", get_dos_track(track), tag->speed_zone[track]);
593      }
502594   }
503595
596   /* read format ID from directory */
597   if (dos == DOS27)
598      floppy_image_read(floppy, id, tag->track_offset[0][39] + 0x18, 2);
599   else
600      floppy_image_read(floppy, id, tag->track_offset[0][34] + 0xa2, 2);
601   
602   tag->id1 = id[0];
603   tag->id2 = id[1];
604
605   if (LOG) logerror("D64 format ID: %02x%02x\n", id[0], id[1]);
606
504607   /* set callbacks */
505608   callbacks = floppy_callbacks(floppy);
506609
src/mess/formats/d64_dsk.h
r7136r7137
1212#include "formats/flopimg.h"
1313
1414FLOPPY_IDENTIFY( d64_dsk_identify );
15FLOPPY_IDENTIFY( d67_dsk_identify );
1516FLOPPY_IDENTIFY( d71_dsk_identify );
17FLOPPY_IDENTIFY( d80_dsk_identify );
18FLOPPY_IDENTIFY( d82_dsk_identify );
19
1620FLOPPY_CONSTRUCT( d64_dsk_construct );
1721
1822#endif

Previous 15994 Revisions Next


© 1998-2018 The MESS Team