Previous 15994 Revisions Next

r5703 Saturday 12th September, 2009 at 07:21:03 UTC by Miodrag Milanović
Thomson floppy rewrite
[src/mess/devices]thomflop.c
[src/mess/drivers]thomson.c
[src/mess/formats]basicdsk.c thom_dsk.c thom_dsk.h
[src/mess/includes]thomson.h

src/mess/includes/thomson.h
r5702r5703
2626#include "machine/mc6846.h"
2727#include "machine/mc6854.h"
2828#include "formats/thom_cas.h"
29#include "formats/thom_dsk.h"
2930#include "devices/thomflop.h"
30#include "formats/thom_dsk.h"
3131
3232
3333/*----------- defined in machine/thomson.c -----------*/
src/mess/devices/thomflop.c
r5702r5703
306306      }
307307
308308      dens = (data & 0x80) ? DEN_FM_LO : DEN_MFM_LO;
309      thom_floppy_set_density( dens );
310309      wd17xx_set_density( fdc, dens );
311310
312311      to7_5p14_select = data;
r5702r5703
333332   int i;
334333   const device_config *fdc = devtag_get_device(machine, "wd2793");
335334   LOG(( "to7_5p14_reset: CD 90-640 controller\n" ));
336   thom_floppy_set_density( DEN_MFM_LO );
337335   wd17xx_reset(fdc);
338336   for ( i = 0; i < device_count( machine, IO_FLOPPY ); i++ )
339337   {
r5702r5703
436434{
437435   int i;
438436   LOG(( "to7_5p14sd_reset: CD 90-015 controller\n" ));
439   thom_floppy_set_density( DEN_FM_LO );
440437   for ( i = 0; i < device_count( machine, IO_FLOPPY ); i++ )
441438   {
442439      const device_config * img = image_from_devtype_and_index( machine, IO_FLOPPY, i );
r5702r5703
842839   int i;
843840   LOG(( "to7_qdd_reset: CQ 90-028 controller\n" ));
844841
845   thom_floppy_set_density( DEN_MFM_LO );
846
847842   for ( i = 0; i < device_count( machine, IO_FLOPPY ); i++ )
848843   {
849844      const device_config * img = image_from_devtype_and_index( machine, IO_FLOPPY, i );
r5702r5703
949944
950945
951946
952static int thmfc_floppy_is_qdd ( void )
947static int thmfc_floppy_is_qdd ( const device_config *image )
953948{
954   return thom_floppy_get_type( thmfc1->drive & 2 ) == THOM_FLOPPY_QDD;
949   if (image==NULL) return 0;
950   if (!image_exists(image)) return 0;
951   return image_length(image)==51200; // idf QDD
955952}
956953
957954
r5702r5703
961958   if ( image != thmfc_floppy_image(image->machine) )
962959      return;
963960
964   if ( thmfc_floppy_is_qdd() )
961   if ( thmfc_floppy_is_qdd(image) )
965962   {
966963      /* pulse each time the whole-disk spiraling track ends */
967964      floppy_drive_set_rpm( image, 16.92f /* 423/25 */ );
r5702r5703
10821079   /* rebuild track if needed */
10831080   if ( ! thmfc1->data_raw_size )
10841081   {
1085      if ( thmfc_floppy_is_qdd() )
1082      if ( thmfc_floppy_is_qdd(thmfc_floppy_image(machine)) )
10861083         /* QDD: track = whole disk */
10871084         thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(machine), thmfc1->data );
10881085      else
r5702r5703
12661263      UINT8 data = 0;
12671264      const device_config * img = thmfc_floppy_image(space->machine);
12681265      int flags = floppy_drive_get_flag_state( img, -1 );
1269      if ( thmfc_floppy_is_qdd() )
1266      if ( thmfc_floppy_is_qdd(img) )
12701267      {
12711268         if ( ! image_exists(img) )
12721269            data |= 0x40; /* disk present */
r5702r5703
13271324   {
13281325      DENSITY dens = (data & 0x20) ? DEN_FM_LO : DEN_MFM_LO;
13291326      int wsync = (data >> 4) & 1;
1330      int qdd = thmfc_floppy_is_qdd();
1327      int qdd = thmfc_floppy_is_qdd(thmfc_floppy_image(space->machine));
13311328      chrn_id id;
1332      thom_floppy_set_density( dens );
13331329      thmfc1->formatting = (data >> 2) & 1;
13341330      LOG (( "%f $%04x thmfc_floppy_w: CMD0=$%02X dens=%s wsync=%i dsync=%i fmt=%i op=%i\n",
13351331             attotime_to_double(timer_get_time(space->machine)), cpu_get_previouspc(cputag_get_cpu(space->machine, "maincpu")), data,
r5702r5703
14331429      int seek = 0, motor;
14341430      thmfc1->drive = data & 2;
14351431
1436      if ( thmfc_floppy_is_qdd() )
1432      img = thmfc_floppy_image(space->machine);
1433      if ( thmfc_floppy_is_qdd(img) )
14371434      {
14381435         motor = !(data & 0x40);
14391436         /* no side select & no seek for QDD */
r5702r5703
14461443         thmfc1->drive |= 1 ^ ((data >> 6) & 1);
14471444      }
14481445
1449      img = thmfc_floppy_image(space->machine);
14501446      thom_floppy_active( space->machine, 0 );
14511447
14521448      LOG (( "%f $%04x thmfc_floppy_w: CMD2=$%02X drv=%i step=%i motor=%i\n",
r5702r5703
14701466
14711467   case 3: /* WDATA */
14721468      thmfc1->wsync = data;
1473      if ( thmfc_floppy_is_qdd() )
1469      if ( thmfc_floppy_is_qdd(thmfc_floppy_image(space->machine)) )
14741470         thmfc_floppy_qdd_write_byte( space->machine, data );
14751471      else if ( thmfc1->op==THMFC1_OP_WRITE_SECT )
14761472         thmfc_floppy_write_byte( space->machine, data );
r5702r5703
15321528      floppy_drive_seek( img, - floppy_drive_get_current_track( img ) );
15331529   }
15341530
1535   thom_floppy_set_density( DEN_MFM_LO );
15361531   thmfc1->op = THMFC1_OP_RESET;
15371532   thmfc1->track = 0;
15381533   thmfc1->sector = 0;
src/mess/formats/thom_dsk.c
r5702r5703
1/**********************************************************************
1/*********************************************************************
22
3  Copyright (C) Antoine Mine' 2006
3   formats/thom_dsk.c
44
5  Thomson 8-bit computers
5   Thomson disk images
6   
7   Based on work of  Antoine Mine'
68
7**********************************************************************/
9*********************************************************************/
810
11#include <string.h>
912#include "driver.h"
10#include "device.h"
1113#include "formats/thom_dsk.h"
12#include "includes/thomson.h"
14#include "formats/basicdsk.h"
1315
14#define VERBOSE 0  /* 0, 1 or 2 */
16#define SAP_DSK_TAG   "sapdsktag"
1517
16#define PRINT(x) mame_printf_info x
18static const int sap_magic_num = 0xB3; /* simple XOR crypt */
1719
18#define LOG(x)   do { if (VERBOSE > 0) logerror x; } while (0)
19#define VLOG(x)   do { if (VERBOSE > 1) logerror x; } while (0)
2020
21static const char sap_header[] =
22   "SYSTEME D'ARCHIVAGE PUKALL S.A.P. "
23   "(c) Alexandre PUKALL Avril 1998";
2124
22/********************* floppy image / drive *********************/
2325
24
25/* sector flags */
26#define THOM_SECT_OK       0
27#define THOM_SECT_INVALID  1 /* invalid header */
28
29
30typedef struct
26static const UINT16 sap_crc[] =
3127{
28   0x0000, 0x1081, 0x2102, 0x3183,   0x4204, 0x5285, 0x6306, 0x7387,
29   0x8408, 0x9489, 0xa50a, 0xb58b,   0xc60c, 0xd68d, 0xe70e, 0xf78f,
30};
3231
33   /* disk info */
34   thom_floppy_type type;
35   UINT8*  data;            /* raw contents */
36   UINT8   sides;           /* 1 or 2 */
37   DENSITY density;
38   UINT16  sector_size;     /* 128 or 256 */
39   UINT16  sectors;         /* sectors per track: 16 or 400 (QDD) */
40   UINT16  tracks;          /* tracks per side: 40, 80, or 1 */
41   UINT8   sect_flag[2560]; /* one flag per sector */
42
43   /* current state */
44   UINT8  cur_track;
45
46   /* for write-back */
47   const device_config* image;
48   UINT8       has_changed;
49
50} thom_floppy_drive;
51
52static thom_floppy_drive thom_floppy_drives[4];
53
54static DENSITY thom_density;
55
56
57
58/*********************** floppy access ************************/
59
60/* default interlacing factor for floppies */
61static const int thom_floppy_interlace = 7;
62
63/* fixed interlacing map for QDDs */
64static int thom_qdd_map[400];
65
66
67static void thom_qdd_compute_map ( void )
32struct sap_dsk_tag
6833{
69   /* this map is hardcoded in the QDD BIOS */
70   static const int p[6][4] =
71   {
72      { 20,  2, 14,  8 }, { 21, 19, 13,  7 },
73      { 22, 18, 12,  6 }, { 23, 17, 11,  5 },
74      { 24, 16, 10,  4 }, {  1, 15,  9,  3 }
75   };
76   static const int q[4] = { 0, 8, 4, 12 };
77   int t, s;
78   for ( t = 0; t < 24; t++ )
79   {
80      for ( s = 0; s < 16; s++ )
81      {
82         thom_qdd_map[ t*16 + s ] = p[ t/4 ][ s%4 ] * 16 + (s/4) + 4*(t%4);
83      }
84   }
85   for ( s = 0; s < 16; s++ )
86   {
87      thom_qdd_map[ 24*16 + s ] = q[ s%4 ] + (s/4);
88   }
89   LOG(( "thom_qdd_compute_map: QDD sector map\n" ));
90   for ( s = 0; s < 25; s++ )
91   {
92      for ( t = 0; t < 16; t++ )
93      {
94         VLOG(( "%03i,", thom_qdd_map[ s*16 + t ] + 1 ));
95      }
96      VLOG(( "\n" ));
97   }
98}
34   int heads;
35   int tracks;
36   int sector_size;
37};
9938
10039
101
102static UINT8* thom_floppy_sector_ptr ( thom_floppy_drive* d, int sector, int track, int side )
40static struct sap_dsk_tag *get_tag(floppy_image *floppy)
10341{
104   if ( track >= d->tracks )
105      track =  d->tracks - 1;
106   if ( track < 0 )
107      track = 0;
108
109   if ( d->data && sector >= 1 && sector <= d->sectors && side >= 0 && side < d->sides )
110   {
111      int s = track * d->sectors + sector - 1;
112      if ( d -> type == THOM_FLOPPY_QDD )
113      {
114         if ( s >= 0 && s < 400 )
115            s = thom_qdd_map[ s ];
116         else
117            return NULL;
118      }
119      return d->data + ( side * d->tracks * d->sectors + s ) * d->sector_size;
120   }
121   else
122      return NULL;
42   struct sap_dsk_tag *tag;
43   tag = floppy_tag(floppy, SAP_DSK_TAG);
44   return tag;
12345}
12446
12547
126
127static UINT8* thom_floppy_sector_flag ( thom_floppy_drive* d,
128               int sector, int track, int side )
48static FLOPPY_IDENTIFY(sap_dsk_identify)
12949{
130   int s = track * d->sectors + sector - 1;
131   if ( d -> type == THOM_FLOPPY_QDD )
132      s = thom_qdd_map[ s ];
133   return
134      d->sect_flag + side * d->tracks * d->sectors + s;
135}
136
137
138
139/* dump some info on the floppy for the user */
140static void thom_floppy_show ( thom_floppy_drive* d )
141{
142   /* format */
143   PRINT (( "thom_floppy: drive %li, %s floppy, %s-sided, %i-byte sectors, %s, %i track(s), %i sectors, %i KB\n",
144       (long) (d - thom_floppy_drives),
145       (d->type == THOM_FLOPPY_5_1_4) ? "5\"1/4" :
146       (d->type == THOM_FLOPPY_3_1_2) ? "3\"1/2" :
147       (d->type == THOM_FLOPPY_QDD) ? "QDD" : "unknown type",
148       (d->sides == 1) ? "one" : "two",
149       d->sector_size,
150       (d->density == DEN_FM_LO) ? "FM" : "MFM",
151       d->tracks, d->sectors,
152       (d->sides * d->tracks * d->sectors * d->sector_size) / 1024 ));
153   LOG (( "thom_floppy: drive %d loaded\n", (int)(FPTR)(d - thom_floppy_drives) ));
154
155   if ( d->data )
156   {
157      UINT8* dir = d->data + 20 * 16 * d->sector_size;
158      char name[] = "01234567";
159      int i, j;
160
161      /* BASIC name */
162      memcpy( name, dir, 8 );
163      for ( i = 0; name[i]; i++ )
164      {
165         if ( name[i] < ' ' || name[i] >= 127 )
166            name[i] = '?';
167      }
168      PRINT (( "thom_floppy: floppy name \"%s\"\n", name ));
169
170      /* BASIC directory */
171      dir += d->sector_size*2;
172      for ( j = 0; j < d->sector_size * 14 / 32; j++, dir += 32 )
173      {
174         char name[] = "01234567.ABC";
175         char comment[] = "01234567";
176         if ( *dir == 255 )
177            break; /* end of directory */
178         if ( *dir < ' ' || *dir > 127 )
179            continue; /* empty entry */
180         memcpy( name, dir, 8 );
181         memcpy( name+9, dir+8, 3 );
182         for ( i = 0; name[i]; i++)
183         {
184            if ( name[i] < ' ' || name[i] >= 127 )
185               name[i] = '?';
186         }
187         memcpy( comment, dir + 16, 8 );
188         for ( i = 0; comment[i]; i++)
189         {
190            if ( comment[i] < ' ' || comment[i] >= 127 )
191               comment[i] = '?';
192         }
193         PRINT (( "thom_floppy: file \"%s\" type=%s,%s comment=\"%s\"\n", name,
194             (dir[11] == 0) ? "bas" : (dir[11] == 1) ? "dat" :
195             (dir[11] == 2) ? "bin" : (dir[11] == 3) ? "asm" : "???",
196             (dir[12] == 0) ? "a" : (dir[12] == 0xff) ? "b" : "?", comment ));
197      }
50   char header[0x100];
51   floppy_image_read(floppy, header, 1, sizeof(sap_header));
52   if (!memcmp( header, sap_header, sizeof(sap_header) ) )
53   {     
54      *vote= 100;
55   } else {
56      *vote = 0;
19857   }
58   return FLOPPY_ERROR_SUCCESS;
19959}
200
201
202
203static thom_floppy_drive* thom_floppy_drive_of_image ( const device_config *image )
60static int sap_get_heads_per_disk(floppy_image *floppy)
20461{
205   return thom_floppy_drives + image_index_in_device( image );
62   return 1;
20663}
20764
208
209
210static void thom_floppy_seek ( const device_config *image, int physical_track )
65static int sap_get_tracks_per_disk(floppy_image *floppy)
21166{
212   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
213   thom_floppy_active( image->machine, 0 );
214   if ( physical_track < 0 )
215      physical_track = 0;
216   if ( physical_track >= 80 )
217      physical_track = 79;
218   //LOG(( "%f thom_floppy_seek: dev=%d track=%i\n", attotime_to_double(timer_get_time(machine)), (int)(FPTR)(d - thom_floppy_drives), physical_track ));
219   d->cur_track = physical_track;
67   return get_tag(floppy)->tracks;
22068}
22169
22270
223
224static int thom_floppy_get_sectors_per_track( const device_config *image, int side )
71static floperr_t get_offset(floppy_image *floppy, int head, int track, int sector, int sector_is_index, UINT64 *offset)
22572{
226   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
227   VLOG(( "thom_floppy_get_sectors_per_track: track=%i/%i dens=%s/%s\n", d->cur_track, d->tracks,
228          (thom_density == DEN_FM_LO) ? "FM" : "MFM",
229          (d->density == DEN_FM_LO) ? "FM" : "MFM" ));
230   return d->sectors;
231}
232
233
234
235static void thom_floppy_get_id ( const device_config* image, chrn_id* id,
236             int id_index, int physical_side )
237{
238   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
239   int trk =  d->cur_track;
240   if ( trk >= d->tracks )
241      trk = d->tracks - 1;
242   VLOG(( "thom_floppy_get_id: dev=%d track=%i idx=%i phy-side=%i dens=%s/%s\n",
243          (int)(FPTR)(d - thom_floppy_drives), trk, id_index, physical_side,
244          (thom_density == DEN_FM_LO) ? "FM" : "MFM",
245          (d->density == DEN_FM_LO) ? "FM" : "MFM" ));
246   thom_floppy_active( image->machine, 0 );
247   if ( thom_floppy_sector_ptr( d, id_index+1, trk, 0 ) &&
248#if 0
249        /* fails with bobwinter */
250        * thom_floppy_sector_flag( d, id_index+1, trk, 0 ) ==
251        THOM_SECT_OK &&
252#endif
253        thom_density == d->density )
73   UINT64 offs;
74   /* translate the sector to a raw sector */
75   if (!sector_is_index)
25476   {
255      int index = ( id_index * thom_floppy_interlace ) % d->sectors;
256      id->C = d->cur_track;
257      id->H = physical_side;
258      id->R = 1 + index;
259      id->N = (d->sector_size == 256) ? 1 : 0;
260      id->data_id = 1 + index;
261      id->flags = 0;
77      sector -= 1;
26278   }
263   else
264   {
265      /* error */
266      id->C = 0;
267      id->H = 0;
268      id->R = 0;
269      id->N = 0;
270      id->data_id = 0;
271      id->flags = 0;
272      logerror( "thom_floppy_get_id: invalid operation dev=%li track=%i idx=%i phy-side=%i dens=%s/%s\n",
273           (long) (d - thom_floppy_drives), d->cur_track, id_index, physical_side,
274           (thom_density == DEN_FM_LO) ? "FM" : "MFM",
275           (d->density == DEN_FM_LO) ? "FM" : "MFM" );
276   }
277}
79   /* check to see if we are out of range */
80   if ((head < 0) || (head >= 1) || (track < 0) || (track >=get_tag(floppy)->tracks)
81         || (sector < 0) || (sector >= 16))
82      return FLOPPY_ERROR_SEEKERROR;
27883
279
280
281static void thom_floppy_read_sector_data_into_buffer ( const device_config* image, int side, int index1, char *ptr, int length )
282{
283   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
284   UINT8* src = thom_floppy_sector_ptr( d, index1, d->cur_track, 0 );
285   thom_floppy_active( image->machine, 0 );
286   LOG(( "thom_floppy_read_sector_data_into_buffer: dev=%d track=%i idx=%i side=%i len=%i\n", (int)(FPTR)(d - thom_floppy_drives), d->cur_track, index1, side, length ));
287   if ( length > d->sector_size )
288   {
289      logerror( "thom_floppy_read_sector_data_into_buffer: sector size %i truncated to %i\n", length, d->sector_size );
290      length = d->sector_size;
291   }
292   if ( src )
293      memcpy( ptr, src, length );
84   offs = 0x42 + track * ((get_tag(floppy)->sector_size + 6)* 16) + sector * (get_tag(floppy)->sector_size + 6) + 4;
85   if (offset)
86      *offset = offs;
87   return FLOPPY_ERROR_SUCCESS;
29488}
29589
29690
29791
298static void thom_floppy_write_sector_data_from_buffer ( const device_config *image, int side, int data_id, const char *ptr, int length, int ddam )
92static floperr_t internal_sap_read_sector(floppy_image *floppy, int head, int track, int sector, int sector_is_index, void *buffer, size_t buflen)
29993{
300   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
301   UINT8* dst = thom_floppy_sector_ptr( d, data_id, d->cur_track, 0 );
302   thom_floppy_active( image->machine, 1 );
303   LOG(( "thom_floppy_write_sector_data_into_buffer: dev=%d track=%i idx=%i side=%i ddam=%i len=%i\n", (int)(FPTR)(d - thom_floppy_drives), d->cur_track, data_id, side, ddam, length ));
304   if ( length > d->sector_size )
305   {
306      logerror( "thom_floppy_write_sector_data_from_buffer: sector size %i truncated to %i\n", length, d->sector_size );
307      length = d->sector_size;
94   UINT64 offset;
95   floperr_t err;
96   int i;   
97   UINT8 *buf;
98   err = get_offset(floppy, head, track, sector, sector_is_index, &offset);
99   if (err)
100      return err;
101
102   floppy_image_read(floppy, buffer, offset, buflen);
103   buf = (UINT8*)buffer;
104   for (i=0;i<buflen;i++) {
105      buf[i] ^= sap_magic_num;
308106   }
309   if ( dst )
310   {
311      memcpy( dst, ptr, length );
312      d->has_changed = 1;
313   }
107   return FLOPPY_ERROR_SUCCESS;
314108}
315109
316110
317111
318static void thom_floppy_format_sector ( const device_config *image, int side, int sector_index, int c, int h, int r, int n, int filler )
112static floperr_t internal_sap_write_sector(floppy_image *floppy, int head, int track, int sector, int sector_is_index, const void *buffer, size_t buflen, int ddam)
319113{
320   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
321   int sector_size = 128 << n;
322   UINT8* dst;
323   thom_floppy_active( image->machine, 1 );
324   LOG(( "thom_floppy_format_sector: dev=%d track=%i/%i side=%i/%i idx=%i/%i c=%i h=%i r=%i n=%i filler=$%02X\n",
325         (int)(FPTR)(d - thom_floppy_drives),
326         d->cur_track, d->tracks, side, d->sides, sector_index, d->sectors,
327         c, h, r, n, filler ));
114   UINT64 offset;
115   floperr_t err;
116   UINT8 *buf;
117   int i;
328118
329   if ( d -> type != THOM_FLOPPY_QDD )
330   {
331      if ( sector_size != d->sector_size || ( d->cur_track >= d->tracks && d->tracks == 40 ) )
332      {
333         /* need to change image params */
334         if ( d->cur_track >= 40 )
335            d->tracks = 80;
336         d->sector_size = sector_size;
337         d->density = thom_density;
338         d->data = realloc( d->data, d->sides * d->tracks * d->sectors * d->sector_size );
339         LOG (( "thom_floppy_format_sector: image enlarged to sides=%i tracks=%i sectors=%i sector_size=%i\n",d->sides, d->tracks, d->sectors, d->sector_size  ));
340         assert( d->data );
341      }
342   }
119   err = get_offset(floppy, head, track, sector, sector_is_index, &offset);
120   if (err)
121      return err;
343122
344   dst = thom_floppy_sector_ptr( d, r, d->cur_track, 0 );
345   if ( dst )
346   {
347      memset( dst, filler, d->sector_size );
348      * thom_floppy_sector_flag( d, r, d->cur_track, 0 ) = THOM_SECT_OK;
349      d->has_changed = 1;
123   buf = (UINT8*)buffer;
124   for (i=0;i<buflen;i++) {
125      buf[i] ^= sap_magic_num;
350126   }
351   else
352      logerror( "thom_floppy_format_sector: invalid operation\n" );
127   floppy_image_write(floppy, buffer, offset, buflen);
128   return FLOPPY_ERROR_SUCCESS;
353129}
354130
355131
356
357static const floppy_interface thom_floppy_interface =
132static floperr_t sap_read_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen)
358133{
359   thom_floppy_seek,
360   thom_floppy_get_sectors_per_track,
361   thom_floppy_get_id,
362   thom_floppy_read_sector_data_into_buffer,
363   thom_floppy_write_sector_data_from_buffer,
364   NULL,
365   NULL,
366   thom_floppy_format_sector
367};
368
369
370
371/*********************** .fd format ************************/
372
373
374static int thom_floppy_fd_load ( const device_config* image )
375{
376   thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image );
377   int size = image_length( image );
378
379   /* O-sized => create */
380   if ( !size )
381   {
382      PRINT(( "new image created in drive %i\n", image_index_in_device( image ) ));
383      d->sides = 1;
384      d->sectors = 16;
385      d->tracks = 40;
386      d->sector_size = 128;
387      d->density = DEN_FM_LO;
388      d->type = THOM_FLOPPY_5_1_4;
389      d->data = malloc( d->sector_size * d->sectors * d->tracks * d->sides );
390      assert( d->data );
391      memset( d->data, 0xff, d->sector_size * d->sectors * d->tracks * d->sides );
392      return INIT_PASS;
393   }
394
395   /* load */
396   d->data = malloc( size );
397   assert( d->data );
398   if ( image_fread( image, d->data, size ) != size )
399   {
400      logerror( "thom_floppy_fd_load: read error\n" );
401      goto error;
402   }
403
404   /* guess format: TODO two-sided images */
405   if ( size == 81920 )
406   {
407      d->type = THOM_FLOPPY_5_1_4;
408      d->tracks = 40;
409      d->sectors = 16;
410      d->sides = 1;
411      d->density = DEN_FM_LO;
412      d->sector_size = 128;
413   }
414   else if ( size == 163840 )
415   {
416#if 0
417      /* this undocumented case can actually be built by the TO9 */
418      d->type = THOM_FLOPPY_3_1_2;
419      d->tracks = 80;
420      d->sectors = 16;
421      d->sides = 1;
422      d->density = DEN_FM_LO;
423      d->sector_size = 128;
424#endif
425      d->type = THOM_FLOPPY_5_1_4;
426      d->tracks = 40;
427      d->sectors = 16;
428      d->sides = 1;
429      d->density = DEN_MFM_LO;
430      d->sector_size = 256;
431   }
432   else if ( size == 327680 )
433   {
434      d->type = THOM_FLOPPY_3_1_2;
435      d->tracks = 80;
436      d->sectors = 16;
437      d->sides = 1;
438      d->density = DEN_MFM_LO;
439      d->sector_size = 256;
440   }
441   else
442   {
443      logerror( "thom_floppy_fd_load: disk format not recognized\n" );
444      goto error;
445   }
446
447   memset( d->sect_flag, THOM_SECT_OK, sizeof( d->sect_flag ) );
448
449   thom_floppy_show( d );
450   assert( size == d->sides * d->tracks * d->sectors * d->sector_size );
451
452   return INIT_PASS;
453
454error:
455   PRINT(( "could not load floppy image in drive %i\n", image_index_in_device( image ) ));
456   if ( d->data )
457      free( d->data );
458   d->data = NULL;
459   d->type = THOM_FLOPPY_NONE;
460   return INIT_FAIL;
134   return internal_sap_read_sector(floppy, head, track, sector, FALSE, buffer, buflen);
461135}
462136
463
464
465static void thom_floppy_fd_save ( const device_config* image )
137static floperr_t sap_write_sector(floppy_image *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam)
466138{
467   thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image );
468   unsigned size = d->sides * d->tracks * d->sectors * d->sector_size;
469   if ( !d->data )
470      return;
471   if ( !d->has_changed )
472      return;
473   PRINT (( "thom_floppy_fd_save: saving floppy %li, %i KB\n", (long) (d - thom_floppy_drives), size / 1024 ));
474
475   /* TODO: truncation */
476   image_fseek( image, 0, SEEK_SET );
477   image_fwrite( image, d->data, size );
139   return internal_sap_write_sector(floppy, head, track, sector, FALSE, buffer, buflen, ddam);
478140}
479141
480
481
482/*********************** .qd format ************************/
483
484/* quick-disks (QDD) are Thomson-specific 2"8 disks, with 50 KB capacity:
485   - one spiraling physical track, with 400 128-byte sectors
486   - all 400 sectors are stepped on each pass
487   - the interlacing of tracks / sectors is fixed, it is optimized so that
488   many contiguous sectors can be read in one pass
489*/
490
491
492static int thom_floppy_qd_load ( const device_config* image )
142static floperr_t sap_read_indexed_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen)
493143{
494   thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image );
495   int size = image_length( image );
496
497   /* only one format, TODO two-sided images */
498   if ( size == 51200 || size == 0 )
499   {
500      d->type = THOM_FLOPPY_QDD;
501      d->tracks = 1;
502      d->sectors = 400;
503      d->sides = 1;
504      d->density = DEN_MFM_LO;
505      d->sector_size = 128;
506   }
507   else
508   {
509      logerror( "thom_floppy_qd_load: disk format not recognized\n" );
510      return INIT_FAIL;
511   }
512
513   d->data = malloc( d->sector_size * d->sectors * d->tracks * d->sides );
514   assert( d->data );
515   memset( d->data, 0xff, d->sector_size * d->sectors * d->tracks * d->sides );
516   memset( d->sect_flag, THOM_SECT_OK, sizeof( d->sect_flag ) );
517
518   if  ( !size )
519   {
520      PRINT(( "new image created in drive %i\n", image_index_in_device( image ) ));
521      return INIT_PASS;
522   }
523
524   if ( image_fread( image, d->data, size ) != size )
525   {
526      logerror( "thom_floppy_qd_load: read error\n" );
527      goto error;
528   }
529   thom_floppy_show( d );
530   assert( size == d->sides * d->tracks * d->sectors * d->sector_size );
531
532   return INIT_PASS;
533
534error:
535   PRINT(( "could not load floppy image in drive %i\n", image_index_in_device( image ) ));
536   if ( d->data )
537      free( d->data );
538   d->data = NULL;
539   d->type = THOM_FLOPPY_NONE;
540   return INIT_FAIL;
144   return internal_sap_read_sector(floppy, head, track, sector, TRUE, buffer, buflen);
541145}
542146
543
544
545static void thom_floppy_qd_save ( const device_config* image )
147static floperr_t sap_write_indexed_sector(floppy_image *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam)
546148{
547   thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image );
548   unsigned size = d->sides * d->tracks * d->sectors * d->sector_size;
549   if ( !d->data )
550      return;
551   if ( !d->has_changed )
552      return;
553   PRINT (( "thom_floppy_qd_save: saving floppy %li, %i KB\n", (long) (d - thom_floppy_drives), size / 1024 ));
554   /* TODO: truncation */
555   image_fseek( image, 0, SEEK_SET );
556   image_fwrite( image, d->data, size );
149   return internal_sap_write_sector(floppy, head, track, sector, TRUE, buffer, buflen, ddam);
557150}
558151
559
560
561/*********************** .sap format ************************/
562
563/* SAP format, Copyright 1998 by Alexandre Pukall */
564
565static const int sap_magic_num = 0xB3; /* simple XOR crypt */
566
567
568static const char sap_header[] =
569   "\001SYSTEME D'ARCHIVAGE PUKALL S.A.P. "
570   "(c) Alexandre PUKALL Avril 1998";
571
572
573static const UINT16 sap_crc[] =
152static floperr_t sap_get_sector_length(floppy_image *floppy, int head, int track, int sector, UINT32 *sector_length)
574153{
575   0x0000, 0x1081, 0x2102, 0x3183,   0x4204, 0x5285, 0x6306, 0x7387,
576   0x8408, 0x9489, 0xa50a, 0xb58b,   0xc60c, 0xd68d, 0xe70e, 0xf78f,
577};
154   floperr_t err;
155   err = get_offset(floppy, head, track, sector, FALSE, NULL);
156   if (err)
157      return err;
578158
579
580
581static UINT16 thom_sap_crc( UINT8* data, int size )
582{
583   int i;
584   UINT16 crc = 0xffff, crc2;
585   for ( i = 0; i < size; i++ )
586   {
587      crc2 = ( crc >> 4 ) ^ sap_crc[ ( crc ^ data[i] ) & 15 ];
588      crc = ( crc2 >> 4 ) ^ sap_crc[ ( crc2 ^ (data[i] >> 4) ) & 15 ];
159   if (sector_length) {
160      *sector_length = get_tag(floppy)->sector_size;
589161   }
590   return crc;
162   return FLOPPY_ERROR_SUCCESS;
591163}
592164
593165
594166
595/* TODO: protection */
596static int thom_floppy_sap_load ( const device_config* image )
167static floperr_t sap_get_indexed_sector_info(floppy_image *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, UINT32 *sector_length, unsigned long *flags)
597168{
598   int drive = image_index_in_device( image );
599   thom_floppy_drive* d = thom_floppy_drives + drive;
600   UINT8 buf[262];
601   int size = image_length( image );
602   int i, format;
603
604   /* O-sized => create */
605   if ( !size )
606   {
607      PRINT(( "new image created in drive %i\n", image_index_in_device( image ) ));
608      d->sides = 1;
609      d->sectors = 16;
610      d->tracks = 80;
611      d->sector_size = 256;
612      d->density = DEN_MFM_LO;
613      d->type = THOM_FLOPPY_3_1_2;
614      d->data = malloc( d->sector_size * d->sectors * d->tracks * d->sides );
615      assert( d->data );
616      memset( d->data, 0xff, d->sector_size * d->sectors * d->tracks * d->sides );
617      return INIT_PASS;
618   }
619
620   /* check header */
621   image_fread( image, buf, 66 );
622   if ( memcmp( buf+1, sap_header+1, 65 ) )
623   {
624      logerror( "thom_floppy_sap_load: invalid sap header\n" );
625      return INIT_FAIL;
626   }
627
628   /* guess format */
629   image_fread( image, buf, 4 );
630   format = buf[0];
631   d->sides = 1; /* always one side per sap file */
632   d->density = (format==1) ? DEN_FM_LO : DEN_MFM_LO;
633   d->sector_size = (format==1) ? 128 : 256;
634   d->tracks = 0;
635   d->sectors = 16;
636   for ( i = 66; i+4 < size; i += d->sector_size + 6 )
637   {
638      int fmt, prot, track, sector;
639      image_fseek( image, i, SEEK_SET );
640      image_fread( image, buf, 4 );
641      fmt    = buf[0];
642      prot   = buf[1];
643      track  = buf[2];
644      sector = buf[3];
645      LOG(( "thom_floppy_sap_load: drive %i found sector %i on track %i, fmt=%i, prot=%i\n", drive, sector, track, fmt, prot ));
646      if ( sector < 1 || sector > d->sectors )
647      {
648         logerror( "thom_floppy_sap_load: invalid sector %i (must be in 1..16)\n", sector );
649         goto error;
650      }
651      if ( track >= d->tracks )
652         d->tracks = track+1;
653   }
654
655   switch ( d->tracks )
656   {
657   case 40: d->type = THOM_FLOPPY_5_1_4; break;
658   case 80: d->type = THOM_FLOPPY_3_1_2; break;
659   default:
660      logerror( "thom_floppy_sap_load: invalid track number %i\n", d->tracks );
661      goto error;
662   }
663
664   /* load */
665   d->data = malloc( d->tracks * d->sectors * d->sector_size );
666   assert( d->data );
667   for ( i = 0; i < d->tracks * d->sectors; i++ )
668   {
669      UINT16 crc;
670      int j, fmt, /*prot,*/ track, sector;
671
672      /* load */
673      image_fseek( image, i * (d->sector_size + 6) + 66, SEEK_SET  );
674      image_fread( image, buf, d->sector_size + 6 );
675      fmt    = buf[0];
676      /* prot   = buf[1]; */
677      track  = buf[2];
678      sector = buf[3];
679
680      /* decrypt */
681      for ( j = 0; j < d->sector_size; j++ )
682         buf[ j + 4 ] ^= sap_magic_num;
683
684      memcpy( thom_floppy_sector_ptr( d, sector, track, 0 ),
685         buf + 4, d->sector_size );
686
687      * thom_floppy_sector_flag( d, sector, track, 0 ) =
688         (fmt == 4) ? THOM_SECT_INVALID : THOM_SECT_OK;
689
690      /* check CRC */
691      crc = thom_sap_crc( buf, d->sector_size + 4 );
692      if ( ( (crc >> 8)   != buf[ d->sector_size + 4 ] ) ||
693           ( (crc & 0xff) != buf[ d->sector_size + 5 ] ) )
694      {
695         logerror( "thom_floppy_sap_load: CRC error for track %i, sector %i\n", track, sector );
696      }
697
698
699   }
700
701   thom_floppy_show( d );
702
703   return INIT_PASS;
704
705error:
706   PRINT(( "could not load floppy image in drive %i\n", image_index_in_device( image ) ));
707   if ( d->data ) free( d->data );
708   d->data = NULL;
709   d->type = THOM_FLOPPY_NONE;
710   return INIT_FAIL;
169   floperr_t err;
170   UINT8 header[4];
171   UINT64 offset;
172   sector_index += 1;
173   err = get_offset(floppy, head, track, sector_index, FALSE, &offset);
174   
175   floppy_image_read(floppy, header, offset-4, 4);
176   if (cylinder)
177      *cylinder = header[2];
178   if (side)
179      *side = head;
180   if (sector)
181      *sector = header[3];
182   if (sector_length)
183      *sector_length = get_tag(floppy)->sector_size;
184   if (flags)
185      /* TODO: read DAM or DDAM and determine flags */
186      *flags = 0;
187   return err;
711188}
712189
713190
714
715static void thom_floppy_sap_save ( const device_config* image )
191static FLOPPY_CONSTRUCT(sap_dsk_construct)
716192{
717   thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image );
718   unsigned size = d->sides * d->tracks * d->sectors * d->sector_size;
719   int format, sector, track, i;
720   UINT8 buf[262];
721   if ( !d->data )
722      return;
723   if ( !d->has_changed )
724      return;
725   PRINT (( "thom_floppy_sap_save: saving floppy %li, %i KB\n", (long) (d - thom_floppy_drives), size / 1024 ));
193   struct FloppyCallbacks *callbacks;
194   struct sap_dsk_tag *tag;
195   int i;
196   UINT8 header[4];
197   tag = (struct sap_dsk_tag *) floppy_create_tag(floppy, SAP_DSK_TAG, sizeof(struct sap_dsk_tag));
198   if (!tag)
199      return FLOPPY_ERROR_OUTOFMEMORY;
726200
727   /* TODO: truncation */
728
729   /* write header*/
730   image_fseek( image, 0, SEEK_SET );
731   image_fwrite( image, sap_header, 66 );
732
733   /* get format */
734   format = (d->sector_size == 128) ? 1 : 0;
735
736   /* write sectors */
737   for ( track = 0; track < d->tracks; track++ )
201   floppy_image_read(floppy, header, 0, 1);
202   if (header[0]==1) tag->sector_size = 256; else tag->sector_size = 128;
203   for ( i = 0x42; i+4 < floppy_image_size(floppy); i += tag->sector_size + 6 ) // CRC 2 bytes + 4 bytes sector header
738204   {
739      for ( sector = 1; sector <= d->sectors; sector++ )
740      {
741         UINT8 *p = thom_floppy_sector_ptr( d, sector, track, 0 );
742         UINT16 crc;
743
744         /* sector header */
745         buf[ 0 ] = format;
746         buf[ 1 ] = 0;
747         buf[ 2 ] = track;
748         buf[ 3 ] = sector;
749
750         memcpy( buf + 4, p, d->sector_size );
751
752         /* CRC */
753         crc = thom_sap_crc( buf, d->sector_size + 4 );
754         buf[ d->sector_size + 4 ] = crc >> 8;
755         buf[ d->sector_size + 5 ] = crc & 0xff;
756
757         /* crypt data */
758         for ( i = 0; i < d->sector_size; i++ )
759            buf[ i + 4 ] ^= sap_magic_num;
760
761         image_fwrite( image, buf, d->sector_size + 6 );
762      }
205      floppy_image_read(floppy, header, i, 4);
206      tag->tracks = header[2] + 1;
763207   }
208   callbacks = floppy_callbacks(floppy);
209   callbacks->read_sector = sap_read_sector;
210   callbacks->write_sector = sap_write_sector;
211   callbacks->read_indexed_sector = sap_read_indexed_sector;
212   callbacks->write_indexed_sector = sap_write_indexed_sector;
213   callbacks->get_sector_length = sap_get_sector_length;
214   callbacks->get_heads_per_disk = sap_get_heads_per_disk;
215   callbacks->get_tracks_per_disk = sap_get_tracks_per_disk;
216   callbacks->get_indexed_sector_info = sap_get_indexed_sector_info;
217   
218   return FLOPPY_ERROR_SUCCESS;   
764219}
765220
766
767
768/*********************** device ** ************************/
769
770
771
772static void thom_floppy_reset ( thom_floppy_drive* d )
221static FLOPPY_IDENTIFY(qdd_dsk_identify)
773222{
774   if ( d->data )
775      free( d->data );
776   d->data = NULL;
777   d->cur_track = 0;
778   d->tracks = 0;
779   d->type = THOM_FLOPPY_NONE;
780   memset( d->sect_flag, THOM_SECT_INVALID, sizeof( d->sect_flag ) );
223   *vote = (floppy_image_size(floppy) == (51200)) ? 100 : 0;
224   return FLOPPY_ERROR_SUCCESS;
781225}
782226
227/* fixed interlacing map for QDDs */
228static int thom_qdd_map[400];
783229
784
785DEVICE_START( thom_floppy )
230static int qdd_translate_sector(floppy_image *floppy, int sector)
786231{
787   thom_qdd_compute_map();
788   thom_floppy_reset( thom_floppy_drive_of_image( device  ) );
789   floppy_drive_init( device, &thom_floppy_interface );
232   return thom_qdd_map[sector-1];
790233}
791234
792
793
794DEVICE_IMAGE_LOAD( thom_floppy )
235static void thom_qdd_compute_map ( void )
795236{
796   const char* typ = image_filetype( image );
797   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
798   thom_floppy_reset( d );
799
800   d->image = image;
801   d->has_changed = 0;
802   d->cur_track = 0;
803
804   /* dispatch according to extension */
805   if ( typ )
237   /* this map is hardcoded in the QDD BIOS */
238   static const int p[6][4] =
806239   {
807      if ( !mame_stricmp( typ, "sap" ) )
808         return thom_floppy_sap_load( image );
809      else if ( !mame_stricmp( typ, "fd" ) )
810         return thom_floppy_fd_load( image );
811      else if ( !mame_stricmp( typ, "qd" ) )
812         return thom_floppy_qd_load( image );
813   }
814
815   return INIT_FAIL;
816}
817
818
819
820DEVICE_IMAGE_UNLOAD(thom_floppy)
821{
822   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
823   const char* typ = image_filetype( image );
824   if ( typ )
240      { 20,  2, 14,  8 }, { 21, 19, 13,  7 },
241      { 22, 18, 12,  6 }, { 23, 17, 11,  5 },
242      { 24, 16, 10,  4 }, {  1, 15,  9,  3 }
243   };
244   static const int q[4] = { 0, 8, 4, 12 };
245   int t, s;
246   for ( t = 0; t < 24; t++ )
825247   {
826      if ( !mame_stricmp( typ, "sap" ) )
827         thom_floppy_sap_save( image );
828      else if ( !mame_stricmp( typ, "fd" ) )
829         thom_floppy_fd_save( image );
830      else if ( !mame_stricmp( typ, "qd" ) )
831         thom_floppy_qd_save( image );
248      for ( s = 0; s < 16; s++ )
249      {
250         thom_qdd_map[ t*16 + s ] = p[ t/4 ][ s%4 ] * 16 + (s/4) + 4*(t%4);
251      }
832252   }
833   thom_floppy_reset( d );
834}
835
836
837
838DEVICE_IMAGE_CREATE( thom_floppy )
839{
840   thom_floppy_drive* d = thom_floppy_drive_of_image( image );
841   const char* typ = image_filetype( image );
842   thom_floppy_reset( d );
843
844   d->image = image;
845   d->cur_track = 0;
846   if ( typ && !mame_stricmp( typ, "qd" ) )
253   for ( s = 0; s < 16; s++ )
847254   {
848      d->sides = 1;
849      d->sectors = 400;
850      d->tracks = 1;
851      d->sector_size = 128;
852      d->density = DEN_MFM_LO;
853      d->type = THOM_FLOPPY_QDD;
255      thom_qdd_map[ 24*16 + s ] = q[ s%4 ] + (s/4);
854256   }
855   else if ( typ && !mame_stricmp( typ, "fd" ) )
856   {
857      d->sides = 1;
858      d->sectors = 16;
859      d->tracks = 40;
860      d->sector_size = 128;
861      d->density = DEN_FM_LO;
862      d->type = THOM_FLOPPY_5_1_4;
863   }
864   else
865   {
866      d->sides = 1;
867      d->sectors = 16;
868      d->tracks = 40;
869      d->sector_size = 256;
870      d->density = DEN_MFM_LO;
871      d->type = THOM_FLOPPY_5_1_4;
872   }
873
874   d->data = malloc( d->sector_size * d->sectors * d->tracks * d->sides );
875   assert( d->data );
876   memset( d->data, 0xff, d->sector_size * d->sectors * d->tracks * d->sides );
877
878   PRINT(( "new image created in drive %i\n", image_index_in_device( image ) ));
879
880   /* not much to do:
881      - the image is created in memory upon formatting
882      - it is stored to the file-system upon unload
883   */
884
885   return INIT_PASS;
886257}
887258
888
889
890void thom_floppy_set_density ( DENSITY density )
259static FLOPPY_CONSTRUCT(qdd_dsk_construct)
891260{
892   thom_density = density;
261   struct basicdsk_geometry geometry;
262   
263   thom_qdd_compute_map();
264   
265   memset(&geometry, 0, sizeof(geometry));
266   geometry.heads = 1;
267   geometry.first_sector_id = 1;
268   geometry.sector_length = 128;
269   geometry.tracks = 1;
270   geometry.sectors = 400;
271   geometry.translate_sector =  qdd_translate_sector;
272   return basicdsk_construct(floppy, &geometry);   
893273}
894274
895275
276/* ----------------------------------------------------------------------- */
896277
897DENSITY thom_floppy_get_density ( void )
898{
899   return thom_density;
900}
278FLOPPY_OPTIONS_START(thomson)
279   FLOPPY_OPTION(qdd,"qd", "Thomson QDD floppy disk image",   qdd_dsk_identify, qdd_dsk_construct,
280      HEADS([1])
281      TRACKS([1])
282      SECTORS([400])
283      SECTOR_LENGTH([128])
284      FIRST_SECTOR_ID([0]))
285   FLOPPY_OPTION(sap,"sap", "Thomson SAP floppy disk image",   sap_dsk_identify, sap_dsk_construct, NULL)
286   FLOPPY_OPTION(fd, "fd", "Thomson FD (FM) 40 tracks disk image", basicdsk_identify_default, basicdsk_construct_default,
287      HEADS([1])
288      TRACKS([40])
289      SECTORS([16])
290      SECTOR_LENGTH([128])
291      FIRST_SECTOR_ID([1]))
292   FLOPPY_OPTION(fd2, "fd", "Thomson FD (FM) 80 tracks disk image", basicdsk_identify_default, basicdsk_construct_default,
293      HEADS([1])
294      TRACKS([80])
295      SECTORS([16])
296      SECTOR_LENGTH([128])
297      FIRST_SECTOR_ID([1]))
298   FLOPPY_OPTION(fdmfm, "fd", "Thomson FD (MFM) 40 tracks disk image", basicdsk_identify_default, basicdsk_construct_default,
299      HEADS([1])
300      TRACKS([40])
301      SECTORS([16])
302      SECTOR_LENGTH([256])
303      FIRST_SECTOR_ID([1]))
304   FLOPPY_OPTION(fdmfm2, "fd", "Thomson FD (MFM) 80 tracks disk image", basicdsk_identify_default, basicdsk_construct_default,
305      HEADS([1])
306      TRACKS([80])
307      SECTORS([16])
308      SECTOR_LENGTH([256])
309      FIRST_SECTOR_ID([1]))
310FLOPPY_OPTIONS_END
901311
902
903
904thom_floppy_type thom_floppy_get_type ( int drive )
905{
906   if ( drive < 0 || drive >= 4 )
907      return THOM_FLOPPY_NONE;
908   else
909      return thom_floppy_drives[ drive ].type;
910}
911
912
913
914void thom_floppy_getinfo( const mess_device_class *devclass, UINT32 state, union devinfo *info )
915{
916   switch ( state )
917   {
918   case MESS_DEVINFO_INT_TYPE:
919      info->i = IO_FLOPPY;
920      break;
921   case MESS_DEVINFO_INT_READABLE:
922      info->i = 1;
923      break;
924   case MESS_DEVINFO_INT_WRITEABLE:
925      info->i = 1;
926      break;
927   case MESS_DEVINFO_INT_CREATABLE:
928      info->i = 1;
929      break;
930   case MESS_DEVINFO_PTR_START:
931      info->start = DEVICE_START_NAME(thom_floppy);
932      break;
933   case MESS_DEVINFO_PTR_LOAD:
934      info->load = DEVICE_IMAGE_LOAD_NAME(thom_floppy);
935      break;
936   case MESS_DEVINFO_PTR_UNLOAD:
937      info->unload = DEVICE_IMAGE_UNLOAD_NAME(thom_floppy);
938      break;
939   case MESS_DEVINFO_PTR_CREATE:
940      info->create = DEVICE_IMAGE_CREATE_NAME(thom_floppy);
941      break;
942   case MESS_DEVINFO_INT_COUNT:
943      info->i = 4;
944      break;
945   case MESS_DEVINFO_STR_NAME+0:
946   case MESS_DEVINFO_STR_NAME+1:
947   case MESS_DEVINFO_STR_NAME+2:
948   case MESS_DEVINFO_STR_NAME+3:
949      strcpy( info->s = device_temp_str(), "floppydisk0" );
950      info->s[ strlen( info->s ) - 1 ] += state - MESS_DEVINFO_STR_NAME;
951      break;
952   case MESS_DEVINFO_STR_SHORT_NAME+0:
953   case MESS_DEVINFO_STR_SHORT_NAME+1:
954   case MESS_DEVINFO_STR_SHORT_NAME+2:
955   case MESS_DEVINFO_STR_SHORT_NAME+3:
956      strcpy( info->s = device_temp_str(), "flop0");
957      info->s[ strlen( info->s ) - 1 ] += state - MESS_DEVINFO_STR_SHORT_NAME;
958      break;
959   case MESS_DEVINFO_STR_DESCRIPTION+0:
960   case MESS_DEVINFO_STR_DESCRIPTION+1:
961   case MESS_DEVINFO_STR_DESCRIPTION+2:
962   case MESS_DEVINFO_STR_DESCRIPTION+3:
963      strcpy( info->s = device_temp_str(), "Floppy #0" );
964      info->s[ strlen( info->s ) - 1 ] += state - MESS_DEVINFO_STR_DESCRIPTION;
965      break;
966   case MESS_DEVINFO_STR_DEV_FILE:
967      strcpy( info->s = device_temp_str(), __FILE__ );
968      break;
969   case MESS_DEVINFO_STR_FILE_EXTENSIONS:
970      strcpy( info->s = device_temp_str(), "fd,qd,sap" );
971      break;
972   }
973}
src/mess/formats/thom_dsk.h
r5702r5703
1/**********************************************************************
2
3  Copyright (C) Antoine Mine' 2006
4
5  Thomson 8-bit computers
6
7**********************************************************************/
8
91#ifndef THOM_DSK
102#define THOM_DSK
113
r5702r5703
1810   - .sap   one-side double-density 5"1/4, 3"1/2
1911*/
2012
21typedef enum {
22  THOM_FLOPPY_NONE,
23  THOM_FLOPPY_5_1_4,
24  THOM_FLOPPY_3_1_2,
25  THOM_FLOPPY_QDD,     /* 2"8 */
26} thom_floppy_type;
13FLOPPY_OPTIONS_EXTERN(thomson);
2714
28extern DEVICE_START( thom_floppy );
29extern DEVICE_IMAGE_LOAD( thom_floppy );
30extern DEVICE_IMAGE_UNLOAD( thom_floppy );
31extern DEVICE_IMAGE_CREATE( thom_floppy );
32
33extern void    thom_floppy_set_density( DENSITY density );
34extern DENSITY thom_floppy_get_density( void );
35
36extern thom_floppy_type thom_floppy_get_type( int drive );
37
38extern void thom_floppy_getinfo( const mess_device_class *devclass,
39             UINT32 state, union devinfo *info );
40
4115#endif
src/mess/formats/basicdsk.c
r5702r5703
8585   /* translate the sector to a raw sector */
8686   if (!sector_is_index)
8787   {
88      if (geom->translate_sector)
89         sector = geom->translate_sector(floppy, sector);
9088      sector -= geom->first_sector_id;
9189   }
9290
91   if (geom->translate_sector)
92      sector = geom->translate_sector(floppy, sector);
93
9394   /* check to see if we are out of range */
9495   if ((head < 0) || (head >= geom->heads) || (track < 0) || (track >= geom->tracks)
9596         || (sector < 0) || (sector >= geom->sectors))
r5702r5703
124125   err = get_offset(floppy, head, track, sector, sector_is_index, &offset);
125126   if (err)
126127      return err;
127
128128   floppy_image_read(floppy, buffer, offset, buflen);
129129   return FLOPPY_ERROR_SUCCESS;
130130}
src/mess/drivers/thomson.c
r5702r5703
7575#include "includes/thomson.h"
7676#include "machine/6821pia.h"
7777#include "machine/ctronics.h"
78#include "devices/mflopimg.h"
79#include "formats/basicdsk.h"
7880
79
8081/**************************** common *******************************/
8182
8283/* layout */
r5702r5703
634635     PORT_INCLUDE ( to7 )
635636INPUT_PORTS_END
636637
638static void thom_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
639{
640   /* floppy */
641   switch(state)
642   {
643      /* --- the following bits of info are returned as 64-bit signed integers --- */
644      case MESS_DEVINFO_INT_COUNT:                     info->i = 4; break;
637645
646      /* --- the following bits of info are returned as pointers to data or functions --- */
647      case MESS_DEVINFO_PTR_FLOPPY_OPTIONS:            info->p = (void *) floppyoptions_thomson; break;
648
649      default:                              floppy_device_getinfo(devclass, state, info); break;
650   }
651}
652
638653/* ------------ config ------------ */
639654
640655static SYSTEM_CONFIG_START ( to )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team