Previous 15994 Revisions Next

r13920 Saturday 7th January, 2012 at 20:56:16 UTC by Olivier Galibert
floppy: Add diskferret format support, and a minimal pc support [O. Galibert]
[src/lib]lib.mak
[src/lib/formats]dfi_dsk.c dfi_dsk.h flopimg.c pc_dsk.c pc_dsk.h
[src/mess/tools/floptool]main.c

src/lib/formats/flopimg.c
r13919r13920
20182018      UINT8 head = sbyte_mfm_r(bitstream, pos, track_size);
20192019      UINT8 sector = sbyte_mfm_r(bitstream, pos, track_size);
20202020      UINT8 size = sbyte_mfm_r(bitstream, pos, track_size);
2021
20212022      if(size >= 8)
20222023         continue;
20232024      int ssize = 128 << size;
r13919r13920
20272028         continue;
20282029
20292030      // Start of IDAM and DAM are supposed to be exactly 704 cells
2030      // apart.  Of course the hardware is tolerant, but not that
2031      // tolerant.  Accept +/- 32 cells of shift.
2031      // apart.  Of course the hardware is tolerant.  Accept +/- 128
2032      // cells of shift.
20322033
20332034      int d_index;
20342035      for(d_index = 0; d_index < dblk_count; d_index++) {
20352036         int delta = dblk[d_index] - idblk[i];
2036         if(delta >= 704-32 && delta <= 704+32)
2037         if(delta >= 704-128 && delta <= 704+128)
20372038            break;
20382039      }
20392040      if(d_index == dblk_count)
src/lib/formats/pc_dsk.c
r13919r13920
135135      TRACKS(40/[80])
136136      SECTORS(8/[9]/10/15/18/36))
137137LEGACY_FLOPPY_OPTIONS_END
138
139
140const floppy_image_format_t::desc_e pc_format::pc_desc[] = {
141   { MFM, 0x4e, 80 },
142   { MFM, 0x00, 12 },
143   { RAW, 0x5224, 3 },
144   { MFM, 0xfc, 1 },
145   { MFM, 0x4e, 50 },
146   { MFM, 0x00, 12 },
147   { SECTOR_LOOP_START, 0, 17 },
148   {   CRC_CCITT_START, 1 },
149   {     RAW, 0x4489, 3 },
150   {     MFM, 0xfe, 1 },
151   {     TRACK_ID },
152   {     HEAD_ID },
153   {     SECTOR_ID },
154   {     SIZE_ID },
155   {   CRC_END, 1 },
156   {   CRC, 1 },
157   {   MFM, 0x4e, 22 },
158   {   MFM, 0x00, 12 },
159   {   CRC_CCITT_START, 2 },
160   {     RAW, 0x4489, 3 },
161   {     MFM, 0xfb, 1 },
162   {     SECTOR_DATA, -1 },
163   {   CRC_END, 2 },
164   {   CRC, 2 },
165   {   MFM, 0x4e, 84 },
166   {   MFM, 0x00, 12 },
167   { SECTOR_LOOP_END },
168   { MFM, 0x4e, 498 },
169   { END }
170};
171
172pc_format::pc_format()
173{
174}
175
176const char *pc_format::name() const
177{
178   return "pc";
179}
180
181const char *pc_format::description() const
182{
183   return "PC floppy disk image";
184}
185
186const char *pc_format::extensions() const
187{
188   return "dsk,ima,img,ufi,360";
189}
190
191bool pc_format::supports_save() const
192{
193   return true;
194}
195
196void pc_format::find_size(io_generic *io, UINT32 form_factor, int &track_count, int &head_count, int &sector_count)
197{
198   int size = io_generic_size(io);
199   if(size == 512*18*2*80) {
200      track_count = 80;
201      head_count = 2;
202      sector_count = 18;
203   } else
204      track_count = head_count = sector_count = 0;
205}
206
207int pc_format::identify(io_generic *io, UINT32 form_factor)
208{
209   int track_count, head_count, sector_count;
210   find_size(io, form_factor, track_count, head_count, sector_count);
211
212   if(track_count)
213      return 50;
214   return 0;
215}
216
217bool pc_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
218{
219   int track_count, head_count, sector_count;
220   find_size(io, form_factor, track_count, head_count, sector_count);
221
222   UINT8 sectdata[36*512];
223   desc_s sectors[36];
224   for(int i=0; i<sector_count; i++) {
225      sectors[i].data = sectdata + 512*i;
226      sectors[i].size = 512;
227      sectors[i].sector_id = i + 1;
228   }
229
230   int track_size = sector_count*512;
231   for(int track=0; track < track_count; track++) {
232      for(int head=0; head < head_count; head++) {
233         io_generic_read(io, sectdata, (track*head_count + head)*track_size, track_size);
234         generate_track(pc_desc,
235                     track, head, sectors, sector_count, 200000, image);
236      }
237   }
238
239   image->set_variant(floppy_image::DSHD);
240
241   return true;
242}
243
244bool pc_format::save(io_generic *io, floppy_image *image)
245{
246   int track_count, head_count, sector_count;
247   get_geometry_mfm_pc(image, 1000, track_count, head_count, sector_count);
248
249   if(track_count < 80)
250      track_count = 80;
251   else if(track_count > 82)
252      track_count = 82;
253
254   // Happens for a fully unformatted floppy
255   if(!head_count)
256      head_count = 1;
257
258   if(sector_count > 36)
259      sector_count = 36;
260   else if(sector_count < 9)
261      sector_count = 9;
262
263   UINT8 sectdata[36*512];
264   int track_size = sector_count*512;
265
266   for(int track=0; track < track_count; track++) {
267      for(int head=0; head < head_count; head++) {
268         get_track_data_mfm_pc(track, head, image, 1000, 512, sector_count, sectdata);
269         io_generic_write(io, sectdata, (track*head_count + head)*track_size, track_size);
270      }
271   }
272
273   return true;
274}
275
276const floppy_format_type FLOPPY_PC_FORMAT = &floppy_image_format_creator<pc_format>;
src/lib/formats/pc_dsk.h
r13919r13920
1616
1717LEGACY_FLOPPY_OPTIONS_EXTERN(pc);
1818
19
20class pc_format : public floppy_image_format_t
21{
22public:
23   pc_format();
24
25   virtual int identify(io_generic *io, UINT32 form_factor);
26   virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image);
27   virtual bool save(io_generic *io, floppy_image *image);
28
29   virtual const char *name() const;
30   virtual const char *description() const;
31   virtual const char *extensions() const;
32   virtual bool supports_save() const;
33
34private:
35   static const desc_e pc_desc[];
36
37   void find_size(io_generic *io, UINT32 form_factor, int &track_count, int &head_count, int &sector_count);
38};
39
40extern const floppy_format_type FLOPPY_PC_FORMAT;
41
1942#endif /* PC_DSK_H */
src/lib/formats/dfi_dsk.c
r13919r13920
1#include "emu.h"
2#include "dfi_dsk.h"
3#include <zlib.h>
4
5dfi_format::dfi_format() : floppy_image_format_t()
6{
7}
8
9const char *dfi_format::name() const
10{
11   return "dfi";
12}
13
14const char *dfi_format::description() const
15{
16   return "Diskferret flux dump format";
17}
18
19const char *dfi_format::extensions() const
20{
21   return "dfi";
22}
23
24bool dfi_format::supports_save() const
25{
26   return true;
27}
28
29int dfi_format::identify(io_generic *io, UINT32 form_factor)
30{
31   char sign[4];
32   io_generic_read(io, sign, 0, 4);
33   return memcmp(sign, "DFE2", 4) ? 0 : 100;
34}
35
36bool dfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
37{
38   int size = io_generic_size(io);
39   int pos = 4;
40   UINT8 *data = 0;
41   int data_size = 0;
42
43   while(pos < size) {
44      UINT8 h[10];
45      io_generic_read(io, h, pos, 10);
46      UINT16 track = (h[0] << 8) | h[1];
47      UINT16 head  = (h[2] << 8) | h[3];
48      // Ignore sector
49      UINT32 tsize = (h[6] << 24) | (h[7] << 16) | (h[8] << 8) | h[9];
50
51      if(pos+tsize+10 > size) {
52         if(data)
53            global_free(data);
54         return false;
55      }
56
57      if(tsize > data_size) {
58         if(data)
59            global_free(data);
60         data_size = tsize;
61         data = global_alloc_array(UINT8, data_size);
62      }
63
64      io_generic_read(io, data, pos+16, tsize);
65      pos += tsize+10;
66      tsize--; // Drop the extra 0x00 at the end
67
68      int index_time = 0;
69      int total_time = 0;
70      for(int i=0; i<tsize; i++) {
71         UINT8 v = data[i];
72         if((v & 0x7f) == 0x7f)
73            total_time += 0x7f;
74         else {
75            total_time += v & 0x7f;
76            if((v & 0x80) && !index_time)
77               index_time = total_time;
78         }               
79      }
80
81      if(!index_time)
82         index_time = total_time;
83
84      image->set_track_size(track, head, tsize);
85
86      int cur_time = 0;
87      UINT32 mg = floppy_image::MG_A;
88      UINT32 *buf = image->get_buffer(track, head);
89      int tpos = 0;
90      buf[tpos++] = mg;
91      for(int i=0; i<tsize; i++) {
92         UINT8 v = data[i];
93         if((v & 0x7f) == 0x7f)
94            cur_time += 0x7f;
95         else {
96            cur_time += v & 0x7f;
97            if(v & 0x80)
98               break;
99            mg = mg == floppy_image::MG_A ? floppy_image::MG_B : floppy_image::MG_A;
100            buf[tpos++] = mg | UINT32(200000000ULL*cur_time/index_time);
101         }
102      }
103      image->set_track_size(track, head, tpos);
104   }
105
106   if(data)
107      global_free(data);
108
109   return true;
110}
111
112const floppy_format_type FLOPPY_DFI_FORMAT = &floppy_image_format_creator<dfi_format>;
src/lib/formats/dfi_dsk.h
r13919r13920
1#ifndef DFI_DSK_H
2#define DFI_DSK_H
3
4#include "flopimg.h"
5
6class dfi_format : public floppy_image_format_t
7{
8public:
9   dfi_format();
10
11   virtual int identify(io_generic *io, UINT32 form_factor);
12   virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image);
13   //   virtual bool save(io_generic *io, floppy_image *image);
14
15   virtual const char *name() const;
16   virtual const char *description() const;
17   virtual const char *extensions() const;
18   virtual bool supports_save() const;
19};
20
21extern const floppy_format_type FLOPPY_DFI_FORMAT;
22
23#endif /* DFI_DSK_H */
src/lib/lib.mak
r13919r13920
107107   $(LIBOBJ)/formats/d64_dsk.o      \
108108   $(LIBOBJ)/formats/d81_dsk.o      \
109109   $(LIBOBJ)/formats/d88_dsk.o      \
110   $(LIBOBJ)/formats/dfi_dsk.o      \
110111   $(LIBOBJ)/formats/dim_dsk.o      \
111112   $(LIBOBJ)/formats/dsk_dsk.o      \
112113   $(LIBOBJ)/formats/fdi_dsk.o      \
src/mess/tools/floptool/main.c
r13919r13920
1919#include "corestr.h"
2020
2121#include "formats/mfi_dsk.h"
22#include "formats/dfi_dsk.h"
2223#include "formats/ipf_dsk.h"
2324
2425#include "formats/hxcmfm_dsk.h"
r13919r13920
2930
3031#include "formats/dsk_dsk.h"
3132
33#include "formats/pc_dsk.h"
34
3235static floppy_format_type floppy_formats[] = {
3336   FLOPPY_MFI_FORMAT,
37   FLOPPY_DFI_FORMAT,
3438   FLOPPY_IPF_FORMAT,
3539
3640   FLOPPY_MFM_FORMAT,
r13919r13920
4044   FLOPPY_MSA_FORMAT,
4145   FLOPPY_PASTI_FORMAT,
4246
43   FLOPPY_DSK_FORMAT
47   FLOPPY_DSK_FORMAT,
48
49   FLOPPY_PC_FORMAT,
4450};
4551
4652void CLIB_DECL logerror(const char *format, ...)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team