Previous 15994 Revisions Next

r5994 Wednesday 7th October, 2009 at 12:55:13 UTC by Dirk Best
[WD17XX] Cleanups
[src/mess/machine]wd17xx.c wd17xx.h

src/mess/machine/wd17xx.c
r5993r5994
8181
8282
8383/***************************************************************************
84
85    Parameters
86
84    CONSTANTS
8785***************************************************************************/
8886
8987#define VERBOSE         0   /* General logging */
r5993r5994
9391#define DELAY_NOTREADY   1
9492#define DELAY_DATADONE   3
9593
96
97/* enumeration to specify the type of FDC; there are subtle differences */
98typedef enum
99{
100   WD_TYPE_1770,
101   WD_TYPE_1771,
102   WD_TYPE_1772,
103   WD_TYPE_1773,
104   WD_TYPE_179X,
105   WD_TYPE_1793,
106   WD_TYPE_2793,
107
108   /* duplicate constants */
109   WD_TYPE_177X = WD_TYPE_1770,
110   WD_TYPE_MB8877 = WD_TYPE_179X
111} wd17xx_type_t;
112
113
114/***************************************************************************
115
116    Constants
117
118***************************************************************************/
119
12094#define TYPE_I         1
12195#define TYPE_II       2
12296#define TYPE_III      3
r5993r5994
186160/* Type IV commands */
187161#define FDC_FORCE_INT   0xd0   /* force interrupt */
188162
163/* enumeration to specify the type of FDC; there are subtle differences */
164typedef enum
165{
166   WD_TYPE_1770,
167   WD_TYPE_1771,
168   WD_TYPE_1772,
169   WD_TYPE_1773,
170   WD_TYPE_179X,
171   WD_TYPE_1793,
172   WD_TYPE_2793,
189173
174   /* duplicate constants */
175   WD_TYPE_177X = WD_TYPE_1770,
176   WD_TYPE_MB8877 = WD_TYPE_179X
177} wd17xx_type_t;
190178
191/***************************************************************************
179/* structure describing a double density track */
180#define TRKSIZE_DD      6144
181#if 0
182static const UINT8 track_DD[][2] = {
183   {16, 0x4e},    /* 16 * 4E (track lead in)               */
184   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
185   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
192186
193    Structures
187   { 1, 0xfe},    /* *** sector *** FE (DAM)               */
188   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
189   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
190   {22, 0x4e},    /* 22 * 4E (sector lead in)              */
191   {12, 0x00},    /* 12 * 00 (pre AM)                      */
192   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
193   { 1, 0xfb},    /*  1 * FB (AM)                          */
194   { 1, 0x81},    /*  x bytes sector data                  */
195   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
196   {16, 0x4e},    /* 16 * 4E (sector lead out)             */
197   { 8, 0x00},    /*  8 * 00 (post sector)                 */
198   { 0, 0x00},    /* end of data                           */
199};
200#endif
194201
202/* structure describing a single density track */
203#define TRKSIZE_SD      3172
204#if 0
205static const UINT8 track_SD[][2] = {
206   {16, 0xff},    /* 16 * FF (track lead in)               */
207   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
208   { 1, 0xfc},    /*  1 * FC (clear CRC)                   */
209
210   {11, 0xff},    /* *** sector *** 11 * FF                */
211   { 6, 0x00},    /*  6 * 00 (pre DAM)                     */
212   { 1, 0xfe},    /*  1 * FE (DAM)                         */
213   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
214   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
215   {10, 0xff},    /* 10 * FF (sector lead in)              */
216   { 4, 0x00},    /*  4 * 00 (pre AM)                      */
217   { 1, 0xfb},    /*  1 * FB (AM)                          */
218   { 1, 0x81},    /*  x bytes sector data                  */
219   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
220   { 0, 0x00},    /* end of data                           */
221};
222#endif
223
224enum
225{
226   MISCCALLBACK_COMMAND = 0,
227   MISCCALLBACK_DATA
228};
229
230
231/***************************************************************************
232    TYPE DEFINITIONS
195233***************************************************************************/
196234
197235typedef struct _wd17xx_t wd17xx_t;
r5993r5994
201239   devcb_resolved_write_line out_intrq_func;
202240   devcb_resolved_write_line out_drq_func;
203241
242   /* state of output lines */
243   int dirc;     /* direction */
244   int drq;      /* data request */
245   int intrq;    /* interrupt request */
246
204247   DENSITY   density;            /* FM/MFM, single / double density */
205248   wd17xx_type_t type;
206249   UINT8   track_reg;            /* value of track register */
r5993r5994
241284   emu_timer *busy_timer;
242285
243286   /* this is the drive currently selected */
244   UINT8 current_drive;
287   const device_config *drive;
245288
246289   /* this is the head currently selected */
247290   UINT8 hd;
r5993r5994
253296   const wd17xx_interface *intf;
254297};
255298
299
300/***************************************************************************
301    DEFAULT INTERFACES
302***************************************************************************/
303
304const wd17xx_interface default_wd17xx_interface =
305{
306   DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
307};
308
309const wd17xx_interface default_wd17xx_interface_2_drives =
310{
311   DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, NULL, NULL}
312};
313
314
315/***************************************************************************
316    PROTOTYPES
317***************************************************************************/
318
319static void wd17xx_complete_command(const device_config *device, int delay);
320static void wd17xx_timed_data_request(const device_config *device);
321static TIMER_CALLBACK(wd17xx_misc_timer_callback);
322static TIMER_CALLBACK(wd17xx_read_sector_callback);
323static TIMER_CALLBACK(wd17xx_write_sector_callback);
324static void wd17xx_index_pulse_callback(const device_config *controller,const device_config *img, int state);
325
326
327/*****************************************************************************
328    INLINE FUNCTIONS
329*****************************************************************************/
330
256331INLINE wd17xx_t *get_safe_token(const device_config *device)
257332{
258333   assert(device != NULL);
r5993r5994
263338
264339
265340/***************************************************************************
266
267    Read track stuff
268
341    HELPER FUNCTIONS
269342***************************************************************************/
270343
271/* structure describing a double density track */
272#define TRKSIZE_DD      6144
273#if 0
274static const UINT8 track_DD[][2] = {
275   {16, 0x4e},    /* 16 * 4E (track lead in)               */
276   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
277   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
344/* calculate CRC for data address marks or sector data */
345static void calc_crc(UINT16 *crc, UINT8 value)
346{
347   UINT8 l, h;
278348
279   { 1, 0xfe},    /* *** sector *** FE (DAM)               */
280   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
281   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
282   {22, 0x4e},    /* 22 * 4E (sector lead in)              */
283   {12, 0x00},    /* 12 * 00 (pre AM)                      */
284   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
285   { 1, 0xfb},    /*  1 * FB (AM)                          */
286   { 1, 0x81},    /*  x bytes sector data                  */
287   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
288   {16, 0x4e},    /* 16 * 4E (sector lead out)             */
289   { 8, 0x00},    /*  8 * 00 (post sector)                 */
290   { 0, 0x00},    /* end of data                           */
291};
292#endif
293/* structure describing a single density track */
294#define TRKSIZE_SD      3172
295#if 0
296static const UINT8 track_SD[][2] = {
297   {16, 0xff},    /* 16 * FF (track lead in)               */
298   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
299   { 1, 0xfc},    /*  1 * FC (clear CRC)                   */
349   l = value ^ (*crc >> 8);
350   *crc = (*crc & 0xff) | (l << 8);
351   l >>= 4;
352   l ^= (*crc >> 8);
353   *crc <<= 8;
354   *crc = (*crc & 0xff00) | l;
355   l = (l << 4) | (l >> 4);
356   h = l;
357   l = (l << 2) | (l >> 6);
358   l &= 0x1f;
359   *crc = *crc ^ (l << 8);
360   l = h & 0xf0;
361   *crc = *crc ^ (l << 8);
362   l = (h << 1) | (h >> 7);
363   l &= 0xe0;
364   *crc = *crc ^ l;
365}
300366
301   {11, 0xff},    /* *** sector *** 11 * FF                */
302   { 6, 0x00},    /*  6 * 00 (pre DAM)                     */
303   { 1, 0xfe},    /*  1 * FE (DAM)                         */
304   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
305   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
306   {10, 0xff},    /* 10 * FF (sector lead in)              */
307   { 4, 0x00},    /*  4 * 00 (pre AM)                      */
308   { 1, 0xfb},    /*  1 * FB (AM)                          */
309   { 1, 0x81},    /*  x bytes sector data                  */
310   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
311   { 0, 0x00},    /* end of data                           */
312};
313#endif
367static int wd17xx_has_side_select(const device_config *device)
368{
369   wd17xx_t *w = get_safe_token(device);
370   return (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_2793);
371}
314372
373static int wd17xx_get_datarate_in_us(DENSITY density)
374{
375   switch (density)
376   {
377      case DEN_FM_LO:  return 128; break;
378      case DEN_FM_HI:    return  64; break;
379      default:
380      case DEN_MFM_LO: return  32; break;
381      case DEN_MFM_HI: return  16; break;
382   }
383}
315384
316385
317386/***************************************************************************
318
319    Prototypes
320
387    IMPLEMENTATION
321388***************************************************************************/
322389
323static void wd17xx_complete_command(const device_config *device, int delay);
324static void wd17xx_clear_data_request(const device_config *device);
325static void wd17xx_set_data_request(const device_config *device);
326static void wd17xx_timed_data_request(const device_config *device);
327static void wd17xx_set_irq(const device_config *device);
328/**************************************************************************/
329
330static const device_config *wd17xx_current_image(const device_config *device)
390/* clear a data request */
391static void wd17xx_clear_drq(const device_config *device)
331392{
332393   wd17xx_t *w = get_safe_token(device);
333   if (w->intf->floppy_drive_tags[w->current_drive]!=NULL) {
334      return devtag_get_device(device->machine,w->intf->floppy_drive_tags[w->current_drive]);
335   } else {
336      return NULL;
337   }
338}
339394
395   w->status &= ~STA_2_DRQ;
340396
397   w->drq = CLEAR_LINE;
398   devcb_call_write_line(&w->out_drq_func, w->drq);
399}
341400
342/* use this to determine which drive is controlled by WD */
343void wd17xx_set_drive(const device_config *device,UINT8 drive)
401/* set data request */
402static void wd17xx_set_drq(const device_config *device)
344403{
345404   wd17xx_t *w = get_safe_token(device);
346   if (VERBOSE)
347   {
348      if (drive != w->current_drive)
349         logerror("wd17xx_set_drive: $%02x\n", drive);
350   }
351   w->current_drive = drive;
405
406   if (w->status & STA_2_DRQ)
407      w->status |= STA_2_LOST_DAT;
408
409   w->status |= STA_2_DRQ;
410
411   w->drq = ASSERT_LINE;
412   devcb_call_write_line(&w->out_drq_func, w->drq);
352413}
353414
354void wd17xx_set_side(const device_config *device,UINT8 head)
415/* clear interrupt request */
416static void   wd17xx_clear_intrq(const device_config *device)
355417{
356418   wd17xx_t *w = get_safe_token(device);
357   if (VERBOSE)
358   {
359      if (head != w->hd)
360         logerror("wd17xx_set_side: $%02x\n", head);
361   }
362   w->hd = head;
419
420   w->intrq = CLEAR_LINE;
421   devcb_call_write_line(&w->out_intrq_func, w->intrq);
363422}
364423
365
366
367void wd17xx_set_density(const device_config *device,DENSITY density)
424/* set interrupt request */
425static void   wd17xx_set_intrq(const device_config *device)
368426{
369427   wd17xx_t *w = get_safe_token(device);
370428
371   if (VERBOSE)
372   {
373      if (w->density != density)
374         logerror("wd17xx_set_density: $%02x\n", density);
375   }
429   w->status &= ~STA_2_BUSY;
376430
377   w->density = density;
431   w->intrq = ASSERT_LINE;
432   devcb_call_write_line(&w->out_intrq_func, w->intrq);
378433}
379434
380435
381436
382static TIMER_CALLBACK(wd17xx_busy_callback)
437static TIMER_CALLBACK( wd17xx_busy_callback )
383438{
384439   const device_config *device = ptr;
385440   wd17xx_t *w = get_safe_token(device);
386   wd17xx_set_irq(device);
441   wd17xx_set_intrq(device);
387442   timer_reset(w->busy_timer, attotime_never);
388443}
389444
r5993r5994
392447static void wd17xx_set_busy(const device_config *device, attotime duration)
393448{
394449   wd17xx_t *w = get_safe_token(device);
450
395451   w->status |= STA_1_BUSY;
396452   timer_adjust_oneshot(w->busy_timer, duration, 0);
397453}
r5993r5994
402458
403459static void wd17xx_restore(const device_config *device)
404460{
405   UINT8 step_counter;
406461   wd17xx_t *w = get_safe_token(device);
462   UINT8 step_counter;
407463
408   if (w->current_drive >= floppy_get_count(device->machine))
464   if (w->drive == NULL)
409465      return;
410466
411467   step_counter = 255;
r5993r5994
422478   /* reset busy count */
423479   w->busy_count = 0;
424480
425   if (image_slotexists(wd17xx_current_image(device)))
481   if (image_slotexists(w->drive))
426482   {
427483      /* keep stepping until track 0 is received or 255 steps have been done */
428      while (!(floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_HEAD_AT_TRACK_0)) && (step_counter!=0))
484      while (!(floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_HEAD_AT_TRACK_0)) && (step_counter!=0))
429485      {
430486         /* update time to simulate seek time busy signal */
431487         w->busy_count++;
432         floppy_drive_seek(wd17xx_current_image(device), w->direction);
488         floppy_drive_seek(w->drive, w->direction);
433489         step_counter--;
434490      }
435491   }
r5993r5994
441497   w->busy_count = 0;   //w->busy_count * ((w->data & FDC_STEP_RATE) + 1);
442498
443499   /* when command completes set irq */
444   wd17xx_set_irq(device);
500   wd17xx_set_intrq(device);
445501#endif
446502   wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
447503}
448504
449505
450
451static TIMER_CALLBACK(wd17xx_misc_timer_callback);
452static TIMER_CALLBACK(wd17xx_read_sector_callback);
453static TIMER_CALLBACK(wd17xx_write_sector_callback);
454static void wd17xx_index_pulse_callback(const device_config *controller,const device_config *img, int state);
455
456
457506/* track writing, converted to format commands */
458507static void write_track(const device_config *device)
459508{
r5993r5994
470519         //int len     = w->buffer[i+4];
471520         int filler  = 0xe5; /* IBM and Thomson */
472521         int density = w->density;
473         floppy_drive_format_sector(wd17xx_current_image(device),side,sector,track,
522         floppy_drive_format_sector(w->drive,side,sector,track,
474523                  w->hd,sector,density?1:0,filler);
475524         i += 128; /* at least... */
476525      }
r5993r5994
480529}
481530
482531
483
484532/* read an entire track */
485533static void read_track(const device_config *device)
486534{
r5993r5994
609657   else
610658      w->data_count = (w->density) ? TRKSIZE_DD : TRKSIZE_SD;
611659
612   floppy_drive_read_track_data_info_buffer( wd17xx_current_image(device), w->hd, (char *)w->buffer, &(w->data_count) );
660   floppy_drive_read_track_data_info_buffer( w->drive, w->hd, (char *)w->buffer, &(w->data_count) );
613661
614662   w->data_offset = 0;
615663
616   wd17xx_set_data_request(device);
664   wd17xx_set_drq(device);
617665   w->status |= STA_2_BUSY;
618666   w->busy_count = 0;
619667}
620668
621669
622
623/* calculate CRC for data address marks or sector data */
624static void calc_crc(UINT16 * crc, UINT8 value)
625{
626   UINT8 l, h;
627
628   l = value ^ (*crc >> 8);
629   *crc = (*crc & 0xff) | (l << 8);
630   l >>= 4;
631   l ^= (*crc >> 8);
632   *crc <<= 8;
633   *crc = (*crc & 0xff00) | l;
634   l = (l << 4) | (l >> 4);
635   h = l;
636   l = (l << 2) | (l >> 6);
637   l &= 0x1f;
638   *crc = *crc ^ (l << 8);
639   l = h & 0xf0;
640   *crc = *crc ^ (l << 8);
641   l = (h << 1) | (h >> 7);
642   l &= 0xe0;
643   *crc = *crc ^ l;
644}
645
646
647
648670/* read the next data address mark */
649671static void wd17xx_read_id(const device_config *device)
650672{
r5993r5994
654676   w->status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND);
655677
656678   /* get next id from disc */
657   if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id))
679   if (floppy_drive_get_next_id(w->drive, w->hd, &id))
658680   {
659681      UINT16 crc = 0xffff;
660682
r5993r5994
684706      wd17xx_set_busy(device, ATTOTIME_IN_USEC(400));
685707      w->busy_count = 0;
686708
687      wd17xx_set_data_request(device);
709      wd17xx_set_drq(device);
688710
689711      if (VERBOSE)
690712         logerror("read id succeeded.\n");
r5993r5994
706728static void wd17xx_index_pulse_callback(const device_config *controller, const device_config *img, int state)
707729{
708730   wd17xx_t *w = get_safe_token(controller);
709   if ( img != wd17xx_current_image(controller) )
731
732   if (img != w->drive)
710733      return;
734
711735   w->ipl = state;
712736
713737   if (w->hld_count)
r5993r5994
716740
717741
718742
719static int wd17xx_has_side_select(const device_config *device)
720{
721   wd17xx_t *w = get_safe_token(device);
722   return (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_2793);
723}
724
725
726
727743static int wd17xx_locate_sector(const device_config *device)
728744{
729745   UINT8 revolution_count;
r5993r5994
736752
737753   while (revolution_count!=4)
738754   {
739      if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id))
755      if (floppy_drive_get_next_id(w->drive, w->hd, &id))
740756      {
741757         /* compare track */
742758         if (id.C == w->track_reg)
r5993r5994
761777      }
762778
763779       /* index set? */
764      if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_INDEX))
780      if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX))
765781      {
766782         /* update revolution count */
767783         revolution_count++;
r5993r5994
809825      w->data_count = w->sector_length;
810826
811827      /* read data */
812      floppy_drive_read_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
828      floppy_drive_read_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
813829
814830      wd17xx_timed_data_request(device);
815831
r5993r5994
820836
821837
822838
823static void   wd17xx_set_irq(const device_config *device)
824{
825   wd17xx_t *w = get_safe_token(device);
826
827   w->status &= ~STA_2_BUSY;
828   devcb_call_write_line(&w->out_intrq_func, ASSERT_LINE);
829}
830
831
832
833/* 0=command callback; 1=data callback */
834enum
835{
836   MISCCALLBACK_COMMAND,
837   MISCCALLBACK_DATA
838};
839
840
841
842839static TIMER_CALLBACK(wd17xx_misc_timer_callback)
843840{
844841   const device_config *device = ptr;
r5993r5994
848845   switch(callback_type) {
849846   case MISCCALLBACK_COMMAND:
850847      /* command callback */
851      wd17xx_set_irq(device);
848      wd17xx_set_intrq(device);
852849      break;
853850
854851   case MISCCALLBACK_DATA:
855852      /* data callback */
856853      /* ok, trigger data request now */
857      wd17xx_set_data_request(device);
854      wd17xx_set_drq(device);
858855      break;
859856   }
860857
r5993r5994
862859   timer_reset(w->timer, attotime_never);
863860}
864861
865int wd17xx_get_datarate_in_us(DENSITY density)
866{
867   int usecs;
868   /* 64 for single density */
869   switch (density)
870   {
871      case DEN_FM_LO:
872      {
873         usecs = 128;
874      }
875      break;
876862
877      case DEN_FM_HI:
878      {
879         usecs = 64;
880      }
881      break;
882
883      default:
884      case DEN_MFM_LO:
885      {
886         usecs = 32;
887      }
888      break;
889
890      case DEN_MFM_HI:
891      {
892         usecs = 16;
893      }
894      break;
895   }
896
897   return usecs;
898}
899
900863/* called on error, or when command is actually completed */
901864/* KT - I have used a timer for systems that use interrupt driven transfers.
902865A interrupt occurs after the last byte has been read. If it occurs at the time
r5993r5994
951914      w->data_count = w->sector_length;
952915
953916      /* write data */
954      floppy_drive_write_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length, w->write_cmd & 0x01);
917      floppy_drive_write_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length, w->write_cmd & 0x01);
955918   }
956919}
957920
r5993r5994
974937   /* must be found within 5 revolutions otherwise error */
975938   while (revolution_count!=5)
976939   {
977      if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id))
940      if (floppy_drive_get_next_id(w->drive, w->hd, &id))
978941      {
979942         /* compare track */
980943         if (id.C == w->track_reg)
r5993r5994
986949      }
987950
988951       /* index set? */
989      if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_INDEX))
952      if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX))
990953      {
991954         /* update revolution count */
992955         revolution_count++;
r5993r5994
1001964
1002965
1003966
1004/* clear a data request */
1005static void wd17xx_clear_data_request(const device_config *device)
1006{
1007   wd17xx_t *w = get_safe_token(device);
1008
1009//  w->status_drq = 0;
1010   w->status &= ~STA_2_DRQ;
1011   devcb_call_write_line(&w->out_drq_func, CLEAR_LINE);
1012}
1013
1014
1015
1016/* set data request */
1017static void wd17xx_set_data_request(const device_config *device)
1018{
1019   wd17xx_t *w = get_safe_token(device);
1020
1021   if (w->status & STA_2_DRQ)
1022   {
1023      w->status |= STA_2_LOST_DAT;
1024//      return;
1025   }
1026
1027   /* set drq */
1028//  w->status_drq = STA_2_DRQ;
1029   w->status |= STA_2_DRQ;
1030   devcb_call_write_line(&w->out_drq_func, ASSERT_LINE);
1031}
1032
1033
1034
1035967/* callback to initiate read sector */
1036static TIMER_CALLBACK(wd17xx_read_sector_callback)
968static TIMER_CALLBACK( wd17xx_read_sector_callback )
1037969{
1038970   const device_config *device = ptr;
1039971   wd17xx_t *w = get_safe_token(device);
r5993r5994
1043975   if (VERBOSE)
1044976      logerror("wd179x: Read Sector callback.\n");
1045977
1046   if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
978   if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1047979      wd17xx_complete_command(device, DELAY_NOTREADY);
1048980   else
1049981      wd17xx_read_sector(device);
r5993r5994
1065997   if (VERBOSE)
1066998      logerror("wd179x: Write Sector callback.\n");
1067999
1068   if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
1000   if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
10691001      wd17xx_complete_command(device, DELAY_NOTREADY);
10701002   else
10711003   {
10721004
10731005      /* drive write protected? */
1074      if (floppy_drive_get_flag_state(wd17xx_current_image(device),FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
1006      if (floppy_drive_get_flag_state(w->drive,FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
10751007      {
10761008         w->status |= STA_2_WRITE_PRO;
10771009
r5993r5994
10921024            w->data_offset = 0;
10931025            w->data_count = w->sector_length;
10941026
1095            wd17xx_set_data_request(device);
1027            wd17xx_set_drq(device);
10961028
10971029            w->status |= STA_2_BUSY;
10981030            w->busy_count = 0;
r5993r5994
11461078   timer_reset(w->timer_ws, ATTOTIME_IN_USEC(usecs));
11471079}
11481080
1149void wd17xx_set_pause_time(const device_config *device,int usec)
1081
1082/***************************************************************************
1083    INTERFACE
1084***************************************************************************/
1085
1086/* use this to determine which drive is controlled by WD */
1087void wd17xx_set_drive(const device_config *device, UINT8 drive)
11501088{
11511089   wd17xx_t *w = get_safe_token(device);
1090
1091   if (VERBOSE)
1092      logerror("wd17xx_set_drive: $%02x\n", drive);
1093
1094   if (w->intf->floppy_drive_tags[drive] != NULL)
1095      w->drive = devtag_get_device(device->machine, w->intf->floppy_drive_tags[drive]);
1096}
1097
1098void wd17xx_set_side(const device_config *device, UINT8 head)
1099{
1100   wd17xx_t *w = get_safe_token(device);
1101
1102   if (VERBOSE)
1103   {
1104      if (head != w->hd)
1105         logerror("wd17xx_set_side: $%02x\n", head);
1106   }
1107
1108   w->hd = head;
1109}
1110
1111void wd17xx_set_density(const device_config *device, DENSITY density)
1112{
1113   wd17xx_t *w = get_safe_token(device);
1114
1115   if (VERBOSE)
1116   {
1117      if (w->density != density)
1118         logerror("wd17xx_set_density: $%02x\n", density);
1119   }
1120
1121   w->density = density;
1122}
1123
1124void wd17xx_set_pause_time(const device_config *device, int usec)
1125{
1126   wd17xx_t *w = get_safe_token(device);
11521127   w->pause_time = usec;
11531128}
11541129
1130
1131/***************************************************************************
1132    DEVICE HANDLERS
1133***************************************************************************/
1134
1135READ_LINE_DEVICE_HANDLER( wd17xx_drq_r )
1136{
1137   wd17xx_t *w = get_safe_token(device);
1138   return w->drq;
1139}
1140
1141READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r )
1142{
1143   wd17xx_t *w = get_safe_token(device);
1144   return w->intrq;
1145}
1146
11551147/* read the FDC status register. This clears IRQ line too */
1156 READ8_DEVICE_HANDLER ( wd17xx_status_r )
1148READ8_DEVICE_HANDLER( wd17xx_status_r )
11571149{
11581150   wd17xx_t *w = get_safe_token(device);
11591151   int result = w->status;
11601152
1161   devcb_call_write_line(&w->out_intrq_func, CLEAR_LINE);
1153   wd17xx_clear_intrq(device);
11621154
11631155   /* type 1 command or force int command? */
11641156   if ((w->command_type==TYPE_I) || (w->command_type==TYPE_IV))
r5993r5994
11691161
11701162      /* set track 0 state */
11711163      result &=~STA_1_TRACK0;
1172      if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_HEAD_AT_TRACK_0))
1164      if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_HEAD_AT_TRACK_0))
11731165         result |= STA_1_TRACK0;
11741166
1175   //  floppy_drive_set_ready_state(wd17xx_current_image(device), 1,1);
1167   //  floppy_drive_set_ready_state(w->drive, 1,1);
11761168      w->status &= ~STA_1_NOT_READY;
11771169
11781170      /* TODO: What is this?  We need some more info on this */
11791171      if ((w->type == WD_TYPE_179X) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1771))
11801172      {
1181         if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
1173         if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
11821174            w->status |= STA_1_NOT_READY;
11831175      }
11841176      else
11851177      {
1186         if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
1178         if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
11871179            w->status |= STA_1_NOT_READY;
11881180      }
11891181
r5993r5994
12091201   return result;
12101202}
12111203
1212
1213
12141204/* read the FDC track register */
1215READ8_DEVICE_HANDLER ( wd17xx_track_r )
1205READ8_DEVICE_HANDLER( wd17xx_track_r )
12161206{
12171207   wd17xx_t *w = get_safe_token(device);
12181208
r5993r5994
12221212   return w->track_reg;
12231213}
12241214
1225
1226
12271215/* read the FDC sector register */
1228READ8_DEVICE_HANDLER ( wd17xx_sector_r )
1216READ8_DEVICE_HANDLER( wd17xx_sector_r )
12291217{
12301218   wd17xx_t *w = get_safe_token(device);
12311219
r5993r5994
12351223   return w->sector;
12361224}
12371225
1238
1239
12401226/* read the FDC data register */
1241 READ8_DEVICE_HANDLER ( wd17xx_data_r )
1227READ8_DEVICE_HANDLER( wd17xx_data_r )
12421228{
12431229   wd17xx_t *w = get_safe_token(device);
12441230
12451231   if (w->data_count >= 1)
12461232   {
12471233      /* clear data request */
1248      wd17xx_clear_data_request(device);
1234      wd17xx_clear_drq(device);
12491235
12501236      /* yes */
12511237      w->data = w->buffer[w->data_offset++];
r5993r5994
12761262               w->data_count = w->sector_length;
12771263
12781264               /* read data */
1279               floppy_drive_read_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
1265               floppy_drive_read_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
12801266
12811267               wd17xx_timed_data_request(device);
12821268
r5993r5994
13141300   return w->data;
13151301}
13161302
1317
1318
13191303/* write the FDC command register */
1320WRITE8_DEVICE_HANDLER ( wd17xx_command_w )
1304WRITE8_DEVICE_HANDLER( wd17xx_command_w )
13211305{
13221306   wd17xx_t *w = get_safe_token(device);
13231307
1324   floppy_drive_set_motor_state(wd17xx_current_image(device), 1);
1325   floppy_drive_set_ready_state(wd17xx_current_image(device), 1,0);
1308   floppy_drive_set_motor_state(w->drive, 1);
1309   floppy_drive_set_ready_state(w->drive, 1,0);
1310
13261311   /* also cleared by writing command */
1327   devcb_call_write_line(&w->out_intrq_func, CLEAR_LINE);
1312   wd17xx_clear_intrq(device);
13281313
13291314   /* clear write protected. On read sector, read track and read dam, write protected bit is clear */
13301315   w->status &= ~((1<<6) | (1<<5) | (1<<4));
r5993r5994
13391324      w->status &= ~STA_2_BUSY;
13401325      w->status &= ~STA_2_LOST_DAT;
13411326
1342      wd17xx_clear_data_request(device);
1327      wd17xx_clear_drq(device);
13431328
13441329      if (data & 0x0f)
13451330      {
r5993r5994
13711356         w->command_type = TYPE_II;
13721357         w->status &= ~STA_2_LOST_DAT;
13731358         w->status |= STA_2_BUSY;
1374         wd17xx_clear_data_request(device);
1359         wd17xx_clear_drq(device);
13751360
13761361         wd17xx_timed_read_sector_request(device);
13771362
r5993r5994
13881373         w->command_type = TYPE_II;
13891374         w->status &= ~STA_2_LOST_DAT;
13901375         w->status |= STA_2_BUSY;
1391         wd17xx_clear_data_request(device);
1376         wd17xx_clear_drq(device);
13921377
13931378         wd17xx_timed_write_sector_request(device);
13941379
r5993r5994
14031388         w->command = data & ~FDC_MASK_TYPE_III;
14041389         w->command_type = TYPE_III;
14051390         w->status &= ~STA_2_LOST_DAT;
1406         wd17xx_clear_data_request(device);
1391         wd17xx_clear_drq(device);
14071392#if 1
14081393//          w->status = seek(w, w->track, w->head, w->sector);
14091394         if (w->status == 0)
r5993r5994
14191404
14201405         w->command_type = TYPE_III;
14211406         w->status &= ~STA_2_LOST_DAT;
1422         wd17xx_clear_data_request(device);
1407         wd17xx_clear_drq(device);
14231408
1424         if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
1409         if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
14251410         {
14261411            wd17xx_complete_command(device, DELAY_NOTREADY);
14271412         }
r5993r5994
14291414         {
14301415
14311416            /* drive write protected? */
1432            if (floppy_drive_get_flag_state(wd17xx_current_image(device),FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
1417            if (floppy_drive_get_flag_state(w->drive,FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
14331418            {
14341419            /* yes */
14351420               w->status |= STA_2_WRITE_PRO;
r5993r5994
14441429               w->data_count = TRKSIZE_SD;
14451430            else
14461431               w->data_count = (w->density) ? TRKSIZE_DD : TRKSIZE_SD;
1447            wd17xx_set_data_request(device);
1432            wd17xx_set_drq(device);
14481433            w->status |= STA_2_BUSY;
14491434            w->busy_count = 0;
14501435            }
r5993r5994
14591444
14601445         w->command_type = TYPE_III;
14611446         w->status &= ~STA_2_LOST_DAT;
1462           wd17xx_clear_data_request(device);
1447           wd17xx_clear_drq(device);
14631448
1464         if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
1449         if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
14651450            wd17xx_read_id(device);
14661451         else
14671452            wd17xx_complete_command(device, DELAY_NOTREADY);
r5993r5994
15281513         /* update track reg */
15291514         w->track_reg += w->direction;
15301515
1531         floppy_drive_seek(wd17xx_current_image(device), w->direction);
1516         floppy_drive_seek(w->drive, w->direction);
15321517      }
15331518
15341519      /* simulate seek time busy signal */
15351520      w->busy_count = 0;   //w->busy_count * ((data & FDC_STEP_RATE) + 1);
15361521#if 0
1537      wd17xx_set_irq(device);
1522      wd17xx_set_intrq(device);
15381523#endif
15391524      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
15401525
r5993r5994
15501535      /* simulate seek time busy signal */
15511536      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
15521537
1553      floppy_drive_seek(wd17xx_current_image(device), w->direction);
1538      floppy_drive_seek(w->drive, w->direction);
15541539
15551540      if (data & FDC_STEP_UPDATE)
15561541         w->track_reg += w->direction;
15571542
15581543#if 0
1559      wd17xx_set_irq(device);
1544      wd17xx_set_intrq(device);
15601545#endif
15611546      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
15621547
r5993r5994
15731558      /* simulate seek time busy signal */
15741559      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
15751560
1576      floppy_drive_seek(wd17xx_current_image(device), w->direction);
1561      floppy_drive_seek(w->drive, w->direction);
15771562
15781563      if (data & FDC_STEP_UPDATE)
15791564         w->track_reg += w->direction;
15801565#if 0
1581      wd17xx_set_irq(device);
1566      wd17xx_set_intrq(device);
15821567#endif
15831568      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
15841569
r5993r5994
15951580      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
15961581
15971582      /* for now only allows a single drive to be selected */
1598      floppy_drive_seek(wd17xx_current_image(device), w->direction);
1583      floppy_drive_seek(w->drive, w->direction);
15991584
16001585      if (data & FDC_STEP_UPDATE)
16011586         w->track_reg += w->direction;
16021587
16031588#if 0
1604      wd17xx_set_irq(device);
1589      wd17xx_set_intrq(device);
16051590#endif
16061591      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
16071592   }
r5993r5994
16251610   }
16261611}
16271612
1628
1629
16301613/* write the FDC track register */
1631WRITE8_DEVICE_HANDLER ( wd17xx_track_w )
1614WRITE8_DEVICE_HANDLER( wd17xx_track_w )
16321615{
16331616   wd17xx_t *w = get_safe_token(device);
1617
16341618   w->track_reg = data;
16351619
16361620   if (VERBOSE)
16371621      logerror("wd17xx_track_w $%02X\n", data);
16381622}
16391623
1640
1641
16421624/* write the FDC sector register */
1643WRITE8_DEVICE_HANDLER ( wd17xx_sector_w )
1625WRITE8_DEVICE_HANDLER( wd17xx_sector_w )
16441626{
16451627   wd17xx_t *w = get_safe_token(device);
1628
16461629   w->sector = data;
1630
16471631   if (VERBOSE)
16481632      logerror("wd17xx_sector_w $%02X\n", data);
16491633}
16501634
1651
1652
16531635/* write the FDC data register */
1654WRITE8_DEVICE_HANDLER ( wd17xx_data_w )
1636WRITE8_DEVICE_HANDLER( wd17xx_data_w )
16551637{
16561638   wd17xx_t *w = get_safe_token(device);
16571639
16581640   if (w->data_count > 0)
16591641   {
1660      /* clear data request */
1661      wd17xx_clear_data_request(device);
1642      wd17xx_clear_drq(device);
16621643
16631644      /* put byte into buffer */
16641645      if (VERBOSE_DATA)
r5993r5994
16921673   w->data = data;
16931674}
16941675
1695
1696
1697 READ8_DEVICE_HANDLER( wd17xx_r )
1676READ8_DEVICE_HANDLER( wd17xx_r )
16981677{
1699   UINT8 result = 0;
1700
1701   switch(offset % 4) {
1702   case 0:
1703      result = wd17xx_status_r(device, 0);
1704      break;
1705   case 1:
1706      result = wd17xx_track_r(device, 0);
1707      break;
1708   case 2:
1709      result = wd17xx_sector_r(device, 0);
1710      break;
1711   case 3:
1712      result = wd17xx_data_r(device, 0);
1713      break;
1678   switch (offset & 0x03)
1679   {
1680   case 0: return wd17xx_status_r(device, 0);
1681   case 1:   return wd17xx_track_r(device, 0);
1682   case 2:   return wd17xx_sector_r(device, 0);
1683   case 3:   return wd17xx_data_r(device, 0);
17141684   }
1715   return result;
1685
1686   return 0;
17161687}
17171688
1718
1719
17201689WRITE8_DEVICE_HANDLER( wd17xx_w )
17211690{
1722   switch(offset % 4) {
1723   case 0:
1724      wd17xx_command_w(device, 0, data);
1725      break;
1726   case 1:
1727      wd17xx_track_w(device, 0, data);
1728      break;
1729   case 2:
1730      wd17xx_sector_w(device, 0, data);
1731      break;
1732   case 3:
1733      wd17xx_data_w(device, 0, data);
1734      break;
1691   switch (offset & 0x03)
1692   {
1693   case 0: wd17xx_command_w(device, 0, data); break;
1694   case 1:   wd17xx_track_w(device, 0, data);   break;
1695   case 2: wd17xx_sector_w(device, 0, data);  break;
1696   case 3: wd17xx_data_w(device, 0, data);    break;
17351697   }
17361698}
17371699
1738const wd17xx_interface default_wd17xx_interface = { DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3} };
1739const wd17xx_interface default_wd17xx_interface_2_drives = { DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, NULL, NULL} };
17401700
1741/* device interface */
1701/***************************************************************************
1702    MAME DEVICE INTERFACE
1703***************************************************************************/
1704
17421705static void common_start(const device_config *device, wd17xx_type_t device_type)
17431706{
17441707   wd17xx_t *w = get_safe_token(device);
17451708
1746   assert(device != NULL);
1747   assert(device->tag != NULL);
17481709   assert(device->static_config != NULL);
17491710
17501711   w->intf = device->static_config;
r5993r5994
17801741      }
17811742   }
17821743
1783   w->current_drive = 0;
1744   wd17xx_set_drive(device, 0);
1745
17841746   w->hd = 0;
17851747   w->hld_count = 0;
17861748
r5993r5994
18521814   }
18531815}
18541816
1855
18561817DEVICE_GET_INFO( wd1771 )
18571818{
18581819   switch (state)
r5993r5994
18661827      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
18671828   }
18681829}
1830
18691831DEVICE_GET_INFO( wd1772 )
18701832{
18711833   switch (state)
r5993r5994
18791841      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
18801842   }
18811843}
1844
18821845DEVICE_GET_INFO( wd1773 )
18831846{
18841847   switch (state)
r5993r5994
18921855      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
18931856   }
18941857}
1858
18951859DEVICE_GET_INFO( wd179x )
18961860{
18971861   switch (state)
r5993r5994
19051869      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
19061870   }
19071871}
1872
19081873DEVICE_GET_INFO( wd1793 )
19091874{
19101875   switch (state)
r5993r5994
19181883      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
19191884   }
19201885}
1886
19211887DEVICE_GET_INFO( wd2793 )
19221888{
19231889   switch (state)
r5993r5994
19311897      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
19321898   }
19331899}
1900
19341901DEVICE_GET_INFO( wd177x )
19351902{
19361903   switch (state)
r5993r5994
19441911      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
19451912   }
19461913}
1914
19471915DEVICE_GET_INFO( mb8877 )
19481916{
19491917   switch (state)
r5993r5994
19571925      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
19581926   }
19591927}
1960
src/mess/machine/wd17xx.h
r5993r5994
7373void wd17xx_set_side(const device_config *device, UINT8);      /* set side wd179x is accessing */
7474void wd17xx_set_density(const device_config *device, DENSITY);   /* set density */
7575
76void wd17xx_set_pause_time(const device_config *device, int usec); /* default is 40 usec if not set */
77
7678READ8_DEVICE_HANDLER( wd17xx_status_r );
7779READ8_DEVICE_HANDLER( wd17xx_track_r );
7880READ8_DEVICE_HANDLER( wd17xx_sector_r );
r5993r5994
8688READ8_DEVICE_HANDLER( wd17xx_r );
8789WRITE8_DEVICE_HANDLER( wd17xx_w );
8890
89void wd17xx_set_pause_time(const device_config *device, int usec); /* default is 40 usec if not set */
91READ_LINE_DEVICE_HANDLER( wd17xx_drq_r );
92READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r );
9093
9194extern const wd17xx_interface default_wd17xx_interface;
9295extern const wd17xx_interface default_wd17xx_interface_2_drives;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team