Previous 15994 Revisions Next

r6720 Tuesday 22nd December, 2009 at 10:35:09 UTC by Dirk Best
[WD17XX] Clean up timer usage
[src/mess/machine]wd17xx.c

src/mess/machine/wd17xx.c
r6719r6720
247247};
248248#endif
249249
250enum
251{
252   MISCCALLBACK_COMMAND = 0,
253   MISCCALLBACK_DATA
254};
255250
256
257251/***************************************************************************
258252    TYPE DEFINITIONS
259253***************************************************************************/
r6719r6720
316310
317311   UINT8   ddam;               /* ddam of sector found - used when reading */
318312   UINT8   sector_data_id;
319   emu_timer   *timer, *timer_rs, *timer_ws, *timer_rid;
320313   int      data_direction;
321314
322315   int     hld_count;            /* head loaded counter */
323316
324   emu_timer *busy_timer;
325
326317   /* this is the drive currently selected */
327318   const device_config *drive;
328319
r6719r6720
358349
359350static void wd17xx_complete_command(const device_config *device, int delay);
360351static void wd17xx_timed_data_request(const device_config *device);
361static TIMER_CALLBACK(wd17xx_misc_timer_callback);
362static TIMER_CALLBACK(wd17xx_read_sector_callback);
363static TIMER_CALLBACK(wd17xx_write_sector_callback);
364static void wd17xx_index_pulse_callback(const device_config *controller,const device_config *img, int state);
352static void wd17xx_index_pulse_callback(const device_config *controller, const device_config *img, int state);
365353
366354
367355/*****************************************************************************
r6719r6720
471459   devcb_call_write_line(&w->out_intrq_func, w->intrq);
472460}
473461
474
475
476static TIMER_CALLBACK( wd17xx_busy_callback )
462/* set intrq after delay */
463static TIMER_CALLBACK( wd17xx_command_callback )
477464{
478465   const device_config *device = ptr;
479   wd1770_state *w = get_safe_token(device);
480466   wd17xx_set_intrq(device);
481   timer_reset(w->busy_timer, attotime_never);
482467}
483468
469/* set drq after delay */
470static TIMER_CALLBACK( wd17xx_data_callback )
471{
472   const device_config *device = ptr;
473   wd17xx_set_drq(device);
474}
484475
485476
486477static void wd17xx_set_busy(const device_config *device, attotime duration)
r6719r6720
488479   wd1770_state *w = get_safe_token(device);
489480
490481   w->status |= STA_1_BUSY;
491   timer_adjust_oneshot(w->busy_timer, duration, 0);
482
483   timer_set(device->machine, duration, (void *)device, 0, wd17xx_command_callback);
492484}
493485
494486
495
496487/* BUSY COUNT DOESN'T WORK PROPERLY! */
497488
498489static void wd17xx_command_restore(const device_config *device)
r6719r6720
892883}
893884
894885
895
896static TIMER_CALLBACK(wd17xx_misc_timer_callback)
897{
898   const device_config *device = ptr;
899   int callback_type = param;
900   wd1770_state *w = get_safe_token(device);
901
902   switch(callback_type) {
903   case MISCCALLBACK_COMMAND:
904      /* command callback */
905      wd17xx_set_intrq(device);
906      break;
907
908   case MISCCALLBACK_DATA:
909      /* data callback */
910      /* ok, trigger data request now */
911      wd17xx_set_drq(device);
912      break;
913   }
914
915   /* stop it, but don't allow it to be free'd */
916   timer_reset(w->timer, attotime_never);
917}
918
919
920886/* called on error, or when command is actually completed */
921887/* KT - I have used a timer for systems that use interrupt driven transfers.
922888A interrupt occurs after the last byte has been read. If it occurs at the time
r6719r6720
946912   usecs = 12;
947913
948914   /* set new timer */
949   timer_adjust_oneshot(w->timer, ATTOTIME_IN_USEC(usecs), MISCCALLBACK_COMMAND);
915   timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_command_callback);
950916}
951917
952918
r6719r6720
10361002      wd17xx_complete_command(device, DELAY_NOTREADY);
10371003   else
10381004      wd17xx_read_sector(device);
1039
1040   /* stop it, but don't allow it to be free'd */
1041   timer_reset(w->timer_rs, attotime_never);
10421005}
10431006
10441007
r6719r6720
10881051         }
10891052      }
10901053   }
1091
1092   /* stop it, but don't allow it to be free'd */
1093   timer_reset(w->timer_ws, attotime_never);
10941054}
10951055
10961056
r6719r6720
11041064   usecs = wd17xx_get_datarate_in_us(w->density);
11051065
11061066   /* set new timer */
1107   timer_adjust_oneshot(w->timer, ATTOTIME_IN_USEC(usecs), MISCCALLBACK_DATA);
1067   timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_data_callback);
11081068}
11091069
11101070
r6719r6720
11181078   usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */
11191079
11201080   /* set new timer */
1121   timer_reset(w->timer_rs, ATTOTIME_IN_USEC(usecs));
1081   timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_read_sector_callback);
11221082}
11231083
11241084
r6719r6720
11321092   usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */
11331093
11341094   /* set new timer */
1135   timer_reset(w->timer_ws, ATTOTIME_IN_USEC(usecs));
1095   timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_write_sector_callback);
11361096}
11371097
11381098
r6719r6720
18401800
18411801   w->status = STA_1_TRACK0;
18421802   w->density = DEN_MFM_LO;
1843   w->busy_timer = timer_alloc(device->machine, wd17xx_busy_callback, (void*)device);
1844   w->timer = timer_alloc(device->machine, wd17xx_misc_timer_callback, (void*)device);
1845   w->timer_rs = timer_alloc(device->machine, wd17xx_read_sector_callback, (void*)device);
1846   w->timer_ws = timer_alloc(device->machine, wd17xx_write_sector_callback, (void*)device);
18471803   w->pause_time = 40;
18481804
18491805   /* resolve callbacks */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team