Previous 15994 Revisions Next

r5988 Tuesday 6th October, 2009 at 16:14:31 UTC by Antoine Mine
[THOMSON] Fix floppy devices & formats, also correcting bug #1870
[src/mess/devices]thomflop.c
[src/mess/drivers]thomson.c
[src/mess/formats]thom_dsk.c

src/mess/devices/thomflop.c
r5987r5988
121121      memset( dst, 0x00, 6 ); /* synchro bytes */
122122      dst[ 6 ] = 0xfb; /* data field mark */
123123      floppy_drive_read_sector_data
124         ( img, id.H, id.R, dst + 7, sector_size );
124         ( img, id.H, id.data_id, dst + 7, sector_size );
125125      dst[ sector_size + 7 ] = 0; /* TODO: CRC */
126126      dst[ sector_size + 8 ] = 0; /* TODO: CRC */
127127      memset( dst + sector_size + 9, 0xff, 22 ); /* end mark */
r5987r5988
133133      memset( dst, 0xa1, 3 ); /* synchro bytes */
134134      dst[ 3 ] = 0xfb; /* data field mark */
135135      floppy_drive_read_sector_data
136         ( img, id.H, id.R, dst + 4, sector_size );
136         ( img, id.H, id.data_id, dst + 4, sector_size );
137137      dst[ sector_size + 4 ] = 0; /* TODO: CRC */
138138      dst[ sector_size + 5 ] = 0; /* TODO: CRC */
139139      memset( dst + sector_size + 6, 0xF7, 74 ); /* end mark */
r5987r5988
330330
331331static void to7_5p14_reset( running_machine *machine )
332332{
333   int i;
334333   const device_config *fdc = devtag_get_device(machine, "wd2793");
335334   LOG(( "to7_5p14_reset: CD 90-640 controller\n" ));
336335   wd17xx_reset(fdc);
337   for ( i = 0; i < floppy_get_count( machine ); i++ )
338   {
339      const device_config * img = floppy_get_device( machine, i );
340      if (img) {
341         floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
342         floppy_drive_set_rpm( img, 300. );
343         floppy_drive_seek( img, - floppy_drive_get_current_track( img ) );
344      }
345   }
346336}
347337
348338
r5987r5988
664654
665655         floppy_drive_format_sector( to7_qdd_image(machine),
666656                      0, sector, 0, 0, sector, 128, filler );
657                        thom_floppy_active( machine, 1 );
667658         to7qdd->start_idx = to7qdd->data_idx;
668659      }
669660
r5987r5988
692683                  attotime_to_double(timer_get_time(machine)), cpu_get_previouspc(cputag_get_cpu(machine, "maincpu")), sector ));
693684
694685            floppy_drive_write_sector_data( to7_qdd_image(machine), 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 );
686                                thom_floppy_active( machine, 1 );
695687         }
696688
697689         to7qdd->start_idx = to7qdd->data_idx;
r5987r5988
918910
919911   UINT8   op;
920912   UINT8   sector;            /* target sector, in [1,16] */
913        UINT32  sector_id;
921914   UINT8   track;             /* current track, in [0,79] */
922915   UINT8   side;              /* current side, 0 or 1 */
923916   UINT8   drive;             /* 0 to 3 */
r5987r5988
989982
990983
991984
992static int thmfc_floppy_find_sector ( running_machine *machine,chrn_id* dst )
985static int thmfc_floppy_find_sector ( running_machine *machine, chrn_id* dst )
993986{
994987   const device_config* img = thmfc_floppy_image(machine);
995988   chrn_id id;
r5987r5988
10341027
10351028   if ( thmfc1->op == THMFC1_OP_WRITE_SECT )
10361029   {
1037      /* TODO: detect ddam (?) */
10381030      const device_config * img = thmfc_floppy_image(machine);
1039      floppy_drive_write_sector_data( img, thmfc1->side, thmfc1->sector, thmfc1->data + 3, thmfc1->data_size - 3, 0 );
1031      floppy_drive_write_sector_data( img, thmfc1->side, thmfc1->sector_id, thmfc1->data + 3, thmfc1->data_size - 3, 0 );
1032                thom_floppy_active( machine, 1 );
10401033   }
10411034   thmfc1->op = THMFC1_OP_RESET;
10421035   thmfc1->stat0 |= THMFC1_STAT0_FINISHED;
r5987r5988
11561149         LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: id field, sector=%i\n", attotime_to_double(timer_get_time(machine)), cpu_get_previouspc(cputag_get_cpu(machine, "maincpu")), sector ));
11571150
11581151         floppy_drive_format_sector( thmfc_floppy_image(machine), 0, sector, 0, 0, sector, 128, filler );
1152                        thom_floppy_active( machine, 1 );
11591153         thmfc1->data_idx = 0;
11601154      }
11611155
r5987r5988
11851179                  attotime_to_double(timer_get_time(machine)), cpu_get_previouspc(cputag_get_cpu(machine, "maincpu")), sector ));
11861180
11871181            floppy_drive_write_sector_data( img, 0, sector, thmfc1->data + thmfc1->data_idx, 128, 0 );
1182                                thom_floppy_active( machine, 1 );
11881183         }
11891184
11901185         thmfc1->data_idx = 0;
r5987r5988
12431238            UINT8 sector = thmfc1->data[6];
12441239            UINT8 length = thmfc1->data[7]; /* actually, log length */
12451240            UINT8 filler = 0xe5;            /* standard Thomson filler */
1246            floppy_drive_format_sector( img, side, sector, track, thmfc1->side, sector, length, filler );
1241                                chrn_id id;
1242                                if ( thmfc_floppy_find_sector( machine, &id ) )
1243                                {                                       
1244                                        floppy_drive_format_sector( img, side, thmfc1->sector_id, track, thmfc1->side, sector, length, filler );
1245                                        thom_floppy_active( machine, 1 );
1246                                }
12471247         }
12481248
12491249         thmfc1->data_idx = 0;
r5987r5988
13531353      case THMFC1_OP_WRITE_SECT:
13541354         if ( qdd )
13551355            logerror( "thmfc_floppy_w: smart operation 1 not supported for QDD\n" );
1356         else if ( thmfc_floppy_find_sector( space->machine, NULL ) )
1356         else if ( thmfc_floppy_find_sector( space->machine, &id ) )
13571357         {
1358                                thmfc1->sector_id = id.data_id;
13581359            thmfc1->data_idx = 0;
13591360            thmfc1->data_size = thmfc1->sector_size + 3; /* A1 A1 FB <data> */
13601361            thmfc1->data_finish = thmfc1->sector_size + 3;
r5987r5988
14471448            seek = (data & 0x20) ? 1 : -1;
14481449         motor =  (data >> 2) & 1;
14491450         thmfc1->drive |= 1 ^ ((data >> 6) & 1);
1451                        img = thmfc_floppy_image(space->machine);
14501452      }
14511453
14521454      thom_floppy_active( space->machine, 0 );
r5987r5988
15651567
15661568   state_save_register_global( machine, thmfc1->op );
15671569   state_save_register_global( machine, thmfc1->sector );
1570   state_save_register_global( machine, thmfc1->sector_id );
15681571   state_save_register_global( machine, thmfc1->track );
15691572   state_save_register_global( machine, thmfc1->side );
15701573   state_save_register_global( machine, thmfc1->drive );
src/mess/formats/thom_dsk.c
r5987r5988
1919
2020
2121static const char sap_header[] =
22   "SYSTEME D'ARCHIVAGE PUKALL S.A.P. "
22   "\001SYSTEME D'ARCHIVAGE PUKALL S.A.P. "
2323   "(c) Alexandre PUKALL Avril 1998";
2424
2525
r5987r5988
3131
3232struct sap_dsk_tag
3333{
34   int heads;
3534   int tracks;
3635   int sector_size;
36        int sector_pos[80][16]; /* remember sector position in file */
3737};
3838
39static UINT16 thom_sap_crc( UINT8* data, int size )
40{
41        int i;
42        UINT16 crc = 0xffff, crc2;
43        for ( i = 0; i < size; i++ )
44        {
45                crc2 = ( crc >> 4 ) ^ sap_crc[ ( crc ^ data[i] ) & 15 ];
46                crc = ( crc2 >> 4 ) ^ sap_crc[ ( crc2 ^ (data[i] >> 4) ) & 15 ];
47        }
48        return crc;
49}
3950
4051static struct sap_dsk_tag *get_tag(floppy_image *floppy)
4152{
r5987r5988
4859static FLOPPY_IDENTIFY(sap_dsk_identify)
4960{
5061   char header[0x100];
51   floppy_image_read(floppy, header, 1, sizeof(sap_header));
62   floppy_image_read(floppy, header, 0, sizeof(sap_header));
5263   if (!memcmp( header, sap_header, sizeof(sap_header) ) )
5364   {
5465      *vote= 100;
r5987r5988
7182static floperr_t get_offset(floppy_image *floppy, int head, int track, int sector, int sector_is_index, UINT64 *offset)
7283{
7384   UINT64 offs;
85        struct sap_dsk_tag *tag = get_tag(floppy);
7486   /* translate the sector to a raw sector */
7587   if (!sector_is_index)
7688   {
7789      sector -= 1;
7890   }
7991   /* check to see if we are out of range */
80   if ((head < 0) || (head >= 1) || (track < 0) || (track >=get_tag(floppy)->tracks)
92   if ((head < 0) || (head >= 1) || (track < 0) || (track >=tag->tracks)
8193         || (sector < 0) || (sector >= 16))
8294      return FLOPPY_ERROR_SEEKERROR;
8395
84   offs = 0x42 + track * ((get_tag(floppy)->sector_size + 6)* 16) + sector * (get_tag(floppy)->sector_size + 6) + 4;
96        offs = tag->sector_pos[track][sector];
97       if (offs <= 0 )
98                return FLOPPY_ERROR_SEEKERROR;
99
85100   if (offset)
86101      *offset = offs;
87102   return FLOPPY_ERROR_SUCCESS;
r5987r5988
99114   if (err)
100115      return err;
101116
102   floppy_image_read(floppy, buffer, offset, buflen);
117   floppy_image_read(floppy, buffer, offset+4, buflen);
103118   buf = (UINT8*)buffer;
104119   for (i=0;i<buflen;i++) {
105120      buf[i] ^= sap_magic_num;
r5987r5988
113128{
114129   UINT64 offset;
115130   floperr_t err;
116   UINT8 *buf;
131   UINT8 buf[256+6];
132        UINT16 crc;
117133   int i;
118
119134   err = get_offset(floppy, head, track, sector, sector_is_index, &offset);
120135   if (err)
121136      return err;
122137
123   buf = (UINT8*)buffer;
138        /* buf = 4-byte header + sector + 2-byte CRC */
139   floppy_image_read(floppy, buf, offset, 4);
124140   for (i=0;i<buflen;i++) {
125      buf[i] ^= sap_magic_num;
126   }
127   floppy_image_write(floppy, buffer, offset, buflen);
141      buf[i+4] = ((UINT8*)buffer)[i];
142   }       
143        crc = thom_sap_crc( buf, buflen+4 );
144        buf[buflen+4] = crc >> 8;
145        buf[buflen+5] = crc & 0xff;
146   for (i=0;i<buflen;i++) {
147      buf[i+4] ^= sap_magic_num;
148   }       
149   floppy_image_write(floppy, buf, offset, buflen+6);
150
128151   return FLOPPY_ERROR_SUCCESS;
129152}
130153
r5987r5988
172195   sector_index += 1;
173196   err = get_offset(floppy, head, track, sector_index, FALSE, &offset);
174197
175   floppy_image_read(floppy, header, offset-4, 4);
198   floppy_image_read(floppy, header, offset, 4);
176199   if (cylinder)
177200      *cylinder = header[2];
178201   if (side)
r5987r5988
187210   return err;
188211}
189212
213static floperr_t sap_post_format(floppy_image *floppy, option_resolution *params)
214{
215        int track,sector;
216        int pos;
217        UINT8 buf[256], header[4];
218   struct sap_dsk_tag *tag;
219        tag = (struct sap_dsk_tag *) floppy_create_tag(floppy, SAP_DSK_TAG, sizeof(struct sap_dsk_tag));
190220
221        /* default options */
222        if ( !tag->tracks )
223        {
224                tag->tracks = 80;       
225                tag->sector_size = 256;
226        }
227
228        /* create SAP file header */
229        floppy_image_write( floppy, sap_header, 0, 66 );
230
231        for ( track = 0; track < 80; track++ )
232                for ( sector = 0; sector < 16; sector++ )
233                        tag->sector_pos[track][sector] = 0;
234
235        /* create all sectors with valid header and CRC */
236    memset(buf, 0xe5, 256);
237        pos = 0x42;
238        header[0] = (tag->sector_size==128) ? 1 : 0;
239        header[1] = 0;
240        for ( track = 0, pos = 0x42; track < tag->tracks; track++ )
241                for ( sector = 0; sector < 16; sector++, pos += tag->sector_size + 6 ) {
242                        tag->sector_pos[track][sector] = pos;
243                        header[2] = track;
244                        header[3] = sector + 1;
245                        floppy_image_write(floppy, header, pos, 4);
246                        sap_write_indexed_sector( floppy, 0, track, sector, buf, tag->sector_size, 0 );
247                }
248       
249        return FLOPPY_ERROR_SUCCESS;
250}
251
252
191253static FLOPPY_CONSTRUCT(sap_dsk_construct)
192254{
193255   struct FloppyCallbacks *callbacks;
194256   struct sap_dsk_tag *tag;
195   int i;
196   UINT8 header[4];
257   int i,j;
258   UINT8 fmt;
197259   tag = (struct sap_dsk_tag *) floppy_create_tag(floppy, SAP_DSK_TAG, sizeof(struct sap_dsk_tag));
198260   if (!tag)
199261      return FLOPPY_ERROR_OUTOFMEMORY;
200262
201   floppy_image_read(floppy, header, 0, 1);
202   if (header[0]==1) tag->sector_size = 256; else tag->sector_size = 128;
263        /* guess format */
264   floppy_image_read(floppy, &fmt, 0x42, 1);
265   if ( fmt==1 ) tag->sector_size = 128; else tag->sector_size = 256;
266
267        /* start with an empty offset table */
268        tag->tracks = 0;
269        for ( i = 0; i < 80; i++ )
270                for ( j = 0; j < 16; j++ )
271                        tag->sector_pos[i][j] = 0;
272
273        /* count tracks & fill sector offset table */
203274   for ( i = 0x42; i+4 < floppy_image_size(floppy); i += tag->sector_size + 6 ) // CRC 2 bytes + 4 bytes sector header
204275   {
205      floppy_image_read(floppy, header, i, 4);
206      tag->tracks = header[2] + 1;
276                UINT8 sector, track;
277      floppy_image_read(floppy, &track, i+2, 1);
278      floppy_image_read(floppy, &sector, i+3, 1);
279                if ( track >= 80 || sector < 1 || sector > 16 ) continue;
280                if ( track > tag->tracks ) tag->tracks = track+1;
281                tag->sector_pos[track][sector-1] = i;
207282   }
208283   callbacks = floppy_callbacks(floppy);
209284   callbacks->read_sector = sap_read_sector;
r5987r5988
214289   callbacks->get_heads_per_disk = sap_get_heads_per_disk;
215290   callbacks->get_tracks_per_disk = sap_get_tracks_per_disk;
216291   callbacks->get_indexed_sector_info = sap_get_indexed_sector_info;
292   callbacks->post_format = sap_post_format;
217293
218294   return FLOPPY_ERROR_SUCCESS;
219295}
r5987r5988
276352/* ----------------------------------------------------------------------- */
277353
278354FLOPPY_OPTIONS_START(thomson)
279   FLOPPY_OPTION(qdd,"qd", "Thomson QDD floppy disk image",   qdd_dsk_identify, qdd_dsk_construct,
355
356   FLOPPY_OPTION(fdmfm2, "fd", "Thomson FD (MFM) 80 tracks disk image (3\"1/2 DD)", basicdsk_identify_default, basicdsk_construct_default,
280357      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,
358      TRACKS([80])
359      SECTORS([16])
360      SECTOR_LENGTH([256])
361      FIRST_SECTOR_ID([1]))
362
363   FLOPPY_OPTION(fdmfm, "fd", "Thomson FD (MFM) 40 tracks disk image (5\"1/4 DD)", basicdsk_identify_default, basicdsk_construct_default,
287364      HEADS([1])
288365      TRACKS([40])
289366      SECTORS([16])
290      SECTOR_LENGTH([128])
367      SECTOR_LENGTH([256])
291368      FIRST_SECTOR_ID([1]))
292   FLOPPY_OPTION(fd2, "fd", "Thomson FD (FM) 80 tracks disk image", basicdsk_identify_default, basicdsk_construct_default,
369
370   FLOPPY_OPTION(fd2, "fd", "Thomson FD (FM) 80 tracks disk image (3\"1/2 SD)", basicdsk_identify_default, basicdsk_construct_default,
293371      HEADS([1])
294372      TRACKS([80])
295373      SECTORS([16])
296374      SECTOR_LENGTH([128])
297375      FIRST_SECTOR_ID([1]))
298   FLOPPY_OPTION(fdmfm, "fd", "Thomson FD (MFM) 40 tracks disk image", basicdsk_identify_default, basicdsk_construct_default,
376
377   FLOPPY_OPTION(fd, "fd", "Thomson FD (FM) 40 tracks disk image (5\"1/4 SD)", basicdsk_identify_default, basicdsk_construct_default,
299378      HEADS([1])
300379      TRACKS([40])
301380      SECTORS([16])
302      SECTOR_LENGTH([256])
381      SECTOR_LENGTH([128])
303382      FIRST_SECTOR_ID([1]))
304   FLOPPY_OPTION(fdmfm2, "fd", "Thomson FD (MFM) 80 tracks disk image", basicdsk_identify_default, basicdsk_construct_default,
383 
384        FLOPPY_OPTION(sap,"sap", "Thomson SAP floppy disk image",   sap_dsk_identify, sap_dsk_construct, NULL)
385
386   FLOPPY_OPTION(qdd,"qd", "Thomson QDD floppy disk image (2\"8 SD)",   qdd_dsk_identify, qdd_dsk_construct,
305387      HEADS([1])
306      TRACKS([80])
307      SECTORS([16])
308      SECTOR_LENGTH([256])
309      FIRST_SECTOR_ID([1]))
388      TRACKS([1])
389      SECTORS([400])
390      SECTOR_LENGTH([128])
391      FIRST_SECTOR_ID([0]))
392
310393FLOPPY_OPTIONS_END
311394
src/mess/drivers/thomson.c
r5987r5988
5454/* TODO (roughly in decreasing priority order):
5555   ----
5656
57   - support all cartridge bank switching methods
58   - THMFC1 support for single density
59   - internal TO9 mouse port (untested)
60   - better state save
61   - support for CD 90-015 floppy controller
57   - internal, keyboard-attached TO9 mouse port (untested)
6258   - floppy: 2-sided or 4-sided .fd images
6359   - printer post-processing => postscript
6460   - RS232 serial port extensions: CC 90-232, RF 57-932
r5987r5988
710706
711707/* floppy */
712708     MDRV_MC6843_ADD( "mc6843", to7_6843_itf )
709     MDRV_WD2793_ADD( "wd2793", default_wd17xx_interface )
710     MDRV_FLOPPY_4_DRIVES_ADD(thomson_floppy_config)
713711
714712/* network */
715713     MDRV_MC6854_ADD( "mc6854", to7_network_iface )
716714
717   /* pia */
718   MDRV_PIA6821_ADD( THOM_PIA_SYS, to7_pia6821_sys )
719   MDRV_PIA6821_ADD( THOM_PIA_IO, to7_pia6821_io )
720   MDRV_PIA6821_ADD( THOM_PIA_GAME, to7_pia6821_game )
721   MDRV_PIA6821_ADD( THOM_PIA_MODEM, to7_pia6821_modem )
722
715/* pia */
716     MDRV_PIA6821_ADD( THOM_PIA_SYS, to7_pia6821_sys )
717     MDRV_PIA6821_ADD( THOM_PIA_IO, to7_pia6821_io )
718     MDRV_PIA6821_ADD( THOM_PIA_GAME, to7_pia6821_game )
719     MDRV_PIA6821_ADD( THOM_PIA_MODEM, to7_pia6821_modem )
720     
723721/* acia */
724    MDRV_ACIA6551_ADD("acia")
725
722     MDRV_ACIA6551_ADD("acia")
723     
726724/* modem */
727    MDRV_ACIA6850_ADD( "acia6850", to7_modem )
725    MDRV_ACIA6850_ADD( "acia6850", to7_modem )
728726
729    MDRV_WD2793_ADD("wd2793", default_wd17xx_interface )
727/* cartridge */
728     MDRV_CARTSLOT_ADD("cart")
729     MDRV_CARTSLOT_EXTENSION_LIST("m7,rom")
730     MDRV_CARTSLOT_NOT_MANDATORY
731     MDRV_CARTSLOT_LOAD(to7_cartridge)
730732
731   MDRV_FLOPPY_4_DRIVES_ADD(thomson_floppy_config)
732
733   /* cartridge */
734   MDRV_CARTSLOT_ADD("cart")
735   MDRV_CARTSLOT_EXTENSION_LIST("m7,rom")
736   MDRV_CARTSLOT_NOT_MANDATORY
737   MDRV_CARTSLOT_LOAD(to7_cartridge)
738733MACHINE_DRIVER_END
739734
740735static MACHINE_DRIVER_START ( t9000 )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team