Previous 199869 Revisions Next

r32586 Wednesday 8th October, 2014 at 20:49:24 UTC by Wilbert Pol
(MESS) msx.c: Added support for DMK floppy images.  [Wilbert Pol]
[src/lib/formats]dmk_dsk.c* dmk_dsk.h*
[src/mess/drivers]msx.c

trunk/src/lib/formats/dmk_dsk.c
r0r32586
1// license:BSD-3-Clause
2// copyright-holders:Wilbert Pol
3/*********************************************************************
4
5    formats/dmk_dsk.h
6
7    DMK disk images
8
9TODO:
10- Add write/format support.
11- Add single density support.
12- Check support on other drivers besides msx.
13
14*********************************************************************/
15
16#include "emu.h"
17#include "dmk_dsk.h"
18
19
20dmk_format::dmk_format()
21{
22}
23
24
25const char *dmk_format::name() const
26{
27   return "dmk";
28}
29
30
31const char *dmk_format::description() const
32{
33   return "DMK disk image";
34}
35
36
37const char *dmk_format::extensions() const
38{
39   return "dmk";
40}
41
42
43int dmk_format::identify(io_generic *io, UINT32 form_factor)
44{
45   const int header_size = 16;
46   UINT8 header[header_size];
47
48   UINT64 size = io_generic_size(io);
49
50   io_generic_read(io, header, 0, header_size);
51
52   int tracks = header[1];
53   int track_size = ( header[3] << 8 ) | header[2];
54   int heads = (header[4] & 0x10) ? 1 : 2;
55
56   // The first header byte must be 00 or FF
57   if (header[0] != 0x00 && header[0] != 0xff)
58   {
59      return 0;
60   }
61
62   // Bytes C-F must be zero
63   if (header[0x0c] != 0 || header[0xd] != 0 || header[0xe] != 0 || header[0xf] != 0)
64   {
65      return 0;
66   }
67
68   // Check track size within limits
69   if (track_size < 0x80 || track_size > 0x3FFF )
70   {
71      return 0;
72   }
73
74   if (size == header_size + heads * tracks * track_size)
75   {
76      return 70;
77   }
78
79   return 0;
80}
81
82
83bool dmk_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
84{
85   const int header_size = 16;
86   UINT8 header[header_size];
87
88   io_generic_read(io, header, 0, header_size);
89
90   const int tracks = header[1];
91   const int track_size = ( header[3] << 8 ) | header[2];
92   const int heads = (header[4] & 0x10) ? 1 : 2;
93   const bool is_sd = (header[4] & 0x40) ? true : false;
94   const int raw_track_size = 2 * 8 * ( track_size - 0x80 );
95
96   if (is_sd)
97   {
98      if (heads == 2)
99      {
100         image->set_variant(floppy_image::DSSD);
101      }
102      else
103      {
104         image->set_variant(floppy_image::SSSD);
105      }
106   }
107   else
108   {
109      if (heads == 2)
110      {
111         image->set_variant(floppy_image::DSDD);
112      }
113      else
114      {
115         image->set_variant(floppy_image::SSDD);
116      }
117   }
118
119   for (int track = 0; track < tracks; track++)
120   {
121      for (int head = 0; head < heads; head++)
122      {
123         dynamic_array<UINT8> track_data(track_size);
124         dynamic_array<UINT32> raw_track_data(raw_track_size);
125         int iam_location = -1;
126         int idam_location[64];
127         int dam_location[64];
128         int tpos = 0;
129
130         // Read track
131         io_generic_read(io, track_data, header_size + ( heads * track + head ) * track_size, track_size);
132
133         for (int i = 0; i < 64; i++)
134         {
135            idam_location[i] = -1;
136            dam_location[i] = -1;
137         }
138
139         // Find IDAM locations
140         UINT16 track_header_offset = 0;
141         UINT16 track_offset = ( ( track_data[track_header_offset + 1] << 8 ) | track_data[track_header_offset] ) & 0x3fff;
142         track_header_offset += 2;
143
144         while ( track_offset != 0 && track_offset >= 0x83 && track_offset < track_size && track_header_offset < 0x80 )
145         {
146            // Assume 3 bytes before IDAM pointers are the start of IDAM indicators
147            idam_location[(track_header_offset/2) - 1] = track_offset - 3;
148
149            // Scan for DAM location
150            for (int i = track_offset + 53; i > track_offset + 10; i--)
151            {
152               if ((track_data[i] == 0xfb || track_data[i] == 0xf8) && track_data[i-1] == 0xa1 && track_data[i-2] == 0xa1)
153               {
154                  dam_location[(track_header_offset/2) - 1] = i - 3;
155                  break;
156               }
157            }
158
159            track_offset = ( ( track_data[track_header_offset + 1] << 8 ) | track_data[track_header_offset] ) & 0x3fff;
160            track_header_offset += 2;
161         };
162
163         // Find IAM location
164         for(int i = idam_location[0] - 1; i >= 3; i--)
165         {
166            // It's usually 3 bytes but several dumped tracks seem to contain only 2 bytes
167            if (track_data[i] == 0xfc && track_data[i-1] == 0xc2 && track_data[i-2] == 0xc2)
168            {
169               iam_location = i - 3;
170               break;
171            }
172         }
173
174         int idam_index = 0;
175         int dam_index = 0;
176         for (int offset = 0x80; offset < track_size; offset++)
177         {
178            if (offset == iam_location)
179            {
180               // Write IAM
181               raw_w(raw_track_data, tpos, 16, 0x5224);
182               raw_w(raw_track_data, tpos, 16, 0x5224);
183               raw_w(raw_track_data, tpos, 16, 0x5224);
184               offset += 3;
185            }
186
187            if (offset == idam_location[idam_index])
188            {
189               raw_w(raw_track_data, tpos, 16, 0x4489);
190               raw_w(raw_track_data, tpos, 16, 0x4489);
191               raw_w(raw_track_data, tpos, 16, 0x4489);
192               idam_index += 1;
193               offset += 3;
194            }
195
196            if (offset == dam_location[dam_index])
197            {
198               raw_w(raw_track_data, tpos, 16, 0x4489);
199               raw_w(raw_track_data, tpos, 16, 0x4489);
200               raw_w(raw_track_data, tpos, 16, 0x4489);
201               dam_index += 1;
202               offset += 3;
203            }
204
205            mfm_w(raw_track_data, tpos, 8, track_data[offset]);
206         }
207
208         generate_track_from_levels(track, head, raw_track_data, raw_track_size, 0, image);
209      }
210   }
211
212   return true;
213}
214
215
216bool dmk_format::save(io_generic *io, floppy_image *image)
217{
218   return false;
219}
220
221
222bool dmk_format::supports_save() const
223{
224   return false;
225}
226
227
228const floppy_format_type FLOPPY_DMK_FORMAT = &floppy_image_format_creator<dmk_format>;
229
Property changes on: trunk/src/lib/formats/dmk_dsk.c
Added: svn:eol-style
   + native
Added: svn:mime-type
   + text/plain
trunk/src/lib/formats/dmk_dsk.h
r0r32586
1/*********************************************************************
2
3    formats/dmk_dsk.h
4
5    DMK disk images
6
7*********************************************************************/
8
9#ifndef DMK_DSK_H
10#define DMK_DSK_H
11
12#include "flopimg.h"
13
14/**************************************************************************/
15
16class dmk_format : public floppy_image_format_t
17{
18public:
19   dmk_format();
20
21   virtual int identify(io_generic *io, UINT32 form_factor);
22   virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image);
23   virtual bool save(io_generic *io, floppy_image *image);
24
25   virtual const char *name() const;
26   virtual const char *description() const;
27   virtual const char *extensions() const;
28   virtual bool supports_save() const;
29};
30
31extern const floppy_format_type FLOPPY_DMK_FORMAT;
32
33#endif /* DMK_DSK_H */
34
Property changes on: trunk/src/lib/formats/dmk_dsk.h
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native
trunk/src/mess/drivers/msx.c
r32585r32586
521521#include "includes/msx.h"
522522#include "bus/centronics/covox.h"
523523#include "formats/dsk_dsk.h"
524#include "formats/dmk_dsk.h"
524525#include "machine/msx_matsushita.h"
525526#include "machine/msx_s1985.h"
526527#include "machine/msx_systemflags.h"
r32585r32586
12581259MACHINE_CONFIG_END
12591260
12601261FLOPPY_FORMATS_MEMBER( msx_state::floppy_formats )
1261   FLOPPY_MSX_FORMAT
1262   FLOPPY_MSX_FORMAT,
1263   FLOPPY_DMK_FORMAT
12621264FLOPPY_FORMATS_END
12631265
12641266static SLOT_INTERFACE_START( msx_floppies )

Previous 199869 Revisions Next


© 1997-2024 The MAME Team