Previous 15994 Revisions Next

r6012 Thursday 8th October, 2009 at 01:14:39 UTC by Dirk Best
[WD17XX] Rename wd17xx_t to wd1770_state
[src/mess/machine]wd17xx.c

src/mess/machine/wd17xx.c
r6011r6012
22
33    wd17xx.c
44
5    Implementations of the Western Digitial 17xx and 19xx families of
5    Implementations of the Western Digital 17xx and 19xx families of
66    floppy disk controllers
77
88
r6011r6012
232232    TYPE DEFINITIONS
233233***************************************************************************/
234234
235typedef struct _wd17xx_t wd17xx_t;
236struct _wd17xx_t
235typedef struct _wd1770_state wd1770_state;
236struct _wd1770_state
237237{
238238   /* callbacks */
239239   devcb_resolved_write_line out_intrq_func;
r6011r6012
337337    INLINE FUNCTIONS
338338*****************************************************************************/
339339
340INLINE wd17xx_t *get_safe_token(const device_config *device)
340INLINE wd1770_state *get_safe_token(const device_config *device)
341341{
342342   assert(device != NULL);
343343   assert(device->token != NULL);
344344
345   return (wd17xx_t *)device->token;
345   return (wd1770_state *)device->token;
346346}
347347
348348
r6011r6012
375375
376376static int wd17xx_has_side_select(const device_config *device)
377377{
378   wd17xx_t *w = get_safe_token(device);
378   wd1770_state *w = get_safe_token(device);
379379   return (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_2793);
380380}
381381
r6011r6012
399399/* clear a data request */
400400static void wd17xx_clear_drq(const device_config *device)
401401{
402   wd17xx_t *w = get_safe_token(device);
402   wd1770_state *w = get_safe_token(device);
403403
404404   w->status &= ~STA_2_DRQ;
405405
r6011r6012
410410/* set data request */
411411static void wd17xx_set_drq(const device_config *device)
412412{
413   wd17xx_t *w = get_safe_token(device);
413   wd1770_state *w = get_safe_token(device);
414414
415415   if (w->status & STA_2_DRQ)
416416      w->status |= STA_2_LOST_DAT;
r6011r6012
424424/* clear interrupt request */
425425static void   wd17xx_clear_intrq(const device_config *device)
426426{
427   wd17xx_t *w = get_safe_token(device);
427   wd1770_state *w = get_safe_token(device);
428428
429429   w->intrq = CLEAR_LINE;
430430   devcb_call_write_line(&w->out_intrq_func, w->intrq);
r6011r6012
433433/* set interrupt request */
434434static void   wd17xx_set_intrq(const device_config *device)
435435{
436   wd17xx_t *w = get_safe_token(device);
436   wd1770_state *w = get_safe_token(device);
437437
438438   w->status &= ~STA_2_BUSY;
439439
r6011r6012
446446static TIMER_CALLBACK( wd17xx_busy_callback )
447447{
448448   const device_config *device = ptr;
449   wd17xx_t *w = get_safe_token(device);
449   wd1770_state *w = get_safe_token(device);
450450   wd17xx_set_intrq(device);
451451   timer_reset(w->busy_timer, attotime_never);
452452}
r6011r6012
455455
456456static void wd17xx_set_busy(const device_config *device, attotime duration)
457457{
458   wd17xx_t *w = get_safe_token(device);
458   wd1770_state *w = get_safe_token(device);
459459
460460   w->status |= STA_1_BUSY;
461461   timer_adjust_oneshot(w->busy_timer, duration, 0);
r6011r6012
467467
468468static void wd17xx_restore(const device_config *device)
469469{
470   wd17xx_t *w = get_safe_token(device);
470   wd1770_state *w = get_safe_token(device);
471471   UINT8 step_counter;
472472
473473   if (w->drive == NULL)
r6011r6012
515515/* track writing, converted to format commands */
516516static void write_track(const device_config *device)
517517{
518   wd17xx_t *w = get_safe_token(device);
518   wd1770_state *w = get_safe_token(device);
519519   int i;
520520   for (i=0;i+4<w->data_offset;)
521521   {
r6011r6012
541541/* read an entire track */
542542static void read_track(const device_config *device)
543543{
544   wd17xx_t *w = get_safe_token(device);
544   wd1770_state *w = get_safe_token(device);
545545#if 0
546546   UINT8 *psrc;      /* pointer to track format structure */
547547   UINT8 *pdst;      /* pointer to track buffer */
r6011r6012
680680static void wd17xx_read_id(const device_config *device)
681681{
682682   chrn_id id;
683   wd17xx_t *w = get_safe_token(device);
683   wd1770_state *w = get_safe_token(device);
684684
685685   w->status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND);
686686
r6011r6012
736736
737737static void wd17xx_index_pulse_callback(const device_config *controller, const device_config *img, int state)
738738{
739   wd17xx_t *w = get_safe_token(controller);
739   wd1770_state *w = get_safe_token(controller);
740740
741741   if (img != w->drive)
742742      return;
r6011r6012
753753{
754754   UINT8 revolution_count;
755755   chrn_id id;
756   wd17xx_t *w = get_safe_token(device);
756   wd1770_state *w = get_safe_token(device);
757757
758758   revolution_count = 0;
759759
r6011r6012
798798
799799static int wd17xx_find_sector(const device_config *device)
800800{
801   wd17xx_t *w = get_safe_token(device);
801   wd1770_state *w = get_safe_token(device);
802802   if ( wd17xx_locate_sector(device) )
803803   {
804804      return 1;
r6011r6012
820820/* read a sector */
821821static void wd17xx_read_sector(const device_config *device)
822822{
823   wd17xx_t *w = get_safe_token(device);
823   wd1770_state *w = get_safe_token(device);
824824   w->data_offset = 0;
825825
826826   /* side compare? */
r6011r6012
849849{
850850   const device_config *device = ptr;
851851   int callback_type = param;
852   wd17xx_t *w = get_safe_token(device);
852   wd1770_state *w = get_safe_token(device);
853853
854854   switch(callback_type) {
855855   case MISCCALLBACK_COMMAND:
r6011r6012
879879static void wd17xx_complete_command(const device_config *device, int delay)
880880{
881881   int usecs;
882   wd17xx_t *w = get_safe_token(device);
882   wd1770_state *w = get_safe_token(device);
883883
884884   w->data_count = 0;
885885
r6011r6012
905905
906906static void wd17xx_write_sector(const device_config *device)
907907{
908   wd17xx_t *w = get_safe_token(device);
908   wd1770_state *w = get_safe_token(device);
909909   /* at this point, the disc is write enabled, and data
910910     * has been transfered into our buffer - now write it to
911911     * the disc image or to the real disc
r6011r6012
934934{
935935   UINT8 revolution_count;
936936   chrn_id id;
937   wd17xx_t *w = get_safe_token(device);
937   wd1770_state *w = get_safe_token(device);
938938
939939   revolution_count = 0;
940940
r6011r6012
977977static TIMER_CALLBACK( wd17xx_read_sector_callback )
978978{
979979   const device_config *device = ptr;
980   wd17xx_t *w = get_safe_token(device);
980   wd1770_state *w = get_safe_token(device);
981981
982982   /* ok, start that read! */
983983
r6011r6012
999999static TIMER_CALLBACK(wd17xx_write_sector_callback)
10001000{
10011001   const device_config *device = ptr;
1002   wd17xx_t *w = get_safe_token(device);
1002   wd1770_state *w = get_safe_token(device);
10031003
10041004   /* ok, start that write! */
10051005
r6011r6012
10511051static void wd17xx_timed_data_request(const device_config *device)
10521052{
10531053   int usecs;
1054   wd17xx_t *w = get_safe_token(device);
1054   wd1770_state *w = get_safe_token(device);
10551055
10561056   usecs = wd17xx_get_datarate_in_us(w->density);
10571057
r6011r6012
10651065static void wd17xx_timed_read_sector_request(const device_config *device)
10661066{
10671067   int usecs;
1068   wd17xx_t *w = get_safe_token(device);
1068   wd1770_state *w = get_safe_token(device);
10691069
10701070   usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */
10711071
r6011r6012
10791079static void wd17xx_timed_write_sector_request(const device_config *device)
10801080{
10811081   int usecs;
1082   wd17xx_t *w = get_safe_token(device);
1082   wd1770_state *w = get_safe_token(device);
10831083
10841084   usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */
10851085
r6011r6012
10951095/* use this to determine which drive is controlled by WD */
10961096void wd17xx_set_drive(const device_config *device, UINT8 drive)
10971097{
1098   wd17xx_t *w = get_safe_token(device);
1098   wd1770_state *w = get_safe_token(device);
10991099
11001100   if (VERBOSE)
11011101      logerror("wd17xx_set_drive: $%02x\n", drive);
r6011r6012
11061106
11071107void wd17xx_set_side(const device_config *device, UINT8 head)
11081108{
1109   wd17xx_t *w = get_safe_token(device);
1109   wd1770_state *w = get_safe_token(device);
11101110
11111111   if (VERBOSE)
11121112   {
r6011r6012
11191119
11201120void wd17xx_set_density(const device_config *device, DENSITY density)
11211121{
1122   wd17xx_t *w = get_safe_token(device);
1122   wd1770_state *w = get_safe_token(device);
11231123
11241124   if (VERBOSE)
11251125   {
r6011r6012
11321132
11331133void wd17xx_set_pause_time(const device_config *device, int usec)
11341134{
1135   wd17xx_t *w = get_safe_token(device);
1135   wd1770_state *w = get_safe_token(device);
11361136   w->pause_time = usec;
11371137}
11381138
r6011r6012
11431143
11441144WRITE_LINE_DEVICE_HANDLER( wd17xx_rdy_w )
11451145{
1146   wd17xx_t *w = get_safe_token(device);
1146   wd1770_state *w = get_safe_token(device);
11471147   w->rdy = state;
11481148}
11491149
11501150READ_LINE_DEVICE_HANDLER( wd17xx_mo_r )
11511151{
1152   wd17xx_t *w = get_safe_token(device);
1152   wd1770_state *w = get_safe_token(device);
11531153   return w->mo;
11541154}
11551155
11561156WRITE_LINE_DEVICE_HANDLER( wd17xx_tr00_w )
11571157{
1158   wd17xx_t *w = get_safe_token(device);
1158   wd1770_state *w = get_safe_token(device);
11591159   w->tr00 = state;
11601160}
11611161
11621162WRITE_LINE_DEVICE_HANDLER( wd17xx_idx_w )
11631163{
1164   wd17xx_t *w = get_safe_token(device);
1164   wd1770_state *w = get_safe_token(device);
11651165   w->idx = state;
11661166}
11671167
11681168WRITE_LINE_DEVICE_HANDLER( wd17xx_wprt_w )
11691169{
1170   wd17xx_t *w = get_safe_token(device);
1170   wd1770_state *w = get_safe_token(device);
11711171   w->wprt = state;
11721172}
11731173
11741174READ_LINE_DEVICE_HANDLER( wd17xx_drq_r )
11751175{
1176   wd17xx_t *w = get_safe_token(device);
1176   wd1770_state *w = get_safe_token(device);
11771177   return w->drq;
11781178}
11791179
11801180READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r )
11811181{
1182   wd17xx_t *w = get_safe_token(device);
1182   wd1770_state *w = get_safe_token(device);
11831183   return w->intrq;
11841184}
11851185
11861186/* read the FDC status register. This clears IRQ line too */
11871187READ8_DEVICE_HANDLER( wd17xx_status_r )
11881188{
1189   wd17xx_t *w = get_safe_token(device);
1189   wd1770_state *w = get_safe_token(device);
11901190   int result = w->status;
11911191
11921192   wd17xx_clear_intrq(device);
r6011r6012
12431243/* read the FDC track register */
12441244READ8_DEVICE_HANDLER( wd17xx_track_r )
12451245{
1246   wd17xx_t *w = get_safe_token(device);
1246   wd1770_state *w = get_safe_token(device);
12471247
12481248   if (VERBOSE)
12491249      logerror("wd17xx_track_r: $%02X\n", w->track_reg);
r6011r6012
12541254/* read the FDC sector register */
12551255READ8_DEVICE_HANDLER( wd17xx_sector_r )
12561256{
1257   wd17xx_t *w = get_safe_token(device);
1257   wd1770_state *w = get_safe_token(device);
12581258
12591259   if (VERBOSE)
12601260      logerror("wd17xx_sector_r: $%02X\n", w->sector);
r6011r6012
12651265/* read the FDC data register */
12661266READ8_DEVICE_HANDLER( wd17xx_data_r )
12671267{
1268   wd17xx_t *w = get_safe_token(device);
1268   wd1770_state *w = get_safe_token(device);
12691269
12701270   if (w->data_count >= 1)
12711271   {
r6011r6012
13421342/* write the FDC command register */
13431343WRITE8_DEVICE_HANDLER( wd17xx_command_w )
13441344{
1345   wd17xx_t *w = get_safe_token(device);
1345   wd1770_state *w = get_safe_token(device);
13461346
13471347   floppy_drive_set_motor_state(w->drive, 1);
13481348   floppy_drive_set_ready_state(w->drive, 1,0);
r6011r6012
16521652/* write the FDC track register */
16531653WRITE8_DEVICE_HANDLER( wd17xx_track_w )
16541654{
1655   wd17xx_t *w = get_safe_token(device);
1655   wd1770_state *w = get_safe_token(device);
16561656
16571657   w->track_reg = data;
16581658
r6011r6012
16631663/* write the FDC sector register */
16641664WRITE8_DEVICE_HANDLER( wd17xx_sector_w )
16651665{
1666   wd17xx_t *w = get_safe_token(device);
1666   wd1770_state *w = get_safe_token(device);
16671667
16681668   w->sector = data;
16691669
r6011r6012
16741674/* write the FDC data register */
16751675WRITE8_DEVICE_HANDLER( wd17xx_data_w )
16761676{
1677   wd17xx_t *w = get_safe_token(device);
1677   wd1770_state *w = get_safe_token(device);
16781678
16791679   if (w->data_count > 0)
16801680   {
r6011r6012
17431743
17441744static DEVICE_START( wd1770 )
17451745{
1746   wd17xx_t *w = get_safe_token(device);
1746   wd1770_state *w = get_safe_token(device);
17471747
17481748   assert(device->static_config != NULL);
17491749
r6011r6012
17721772
17731773static DEVICE_START( wd1771 )
17741774{
1775   wd17xx_t *w = get_safe_token(device);
1775   wd1770_state *w = get_safe_token(device);
17761776
17771777   DEVICE_START_CALL(wd1770);
17781778
r6011r6012
17811781
17821782static DEVICE_START( wd1772 )
17831783{
1784   wd17xx_t *w = get_safe_token(device);
1784   wd1770_state *w = get_safe_token(device);
17851785
17861786   DEVICE_START_CALL(wd1770);
17871787
r6011r6012
17951795
17961796static DEVICE_START( wd1773 )
17971797{
1798   wd17xx_t *w = get_safe_token(device);
1798   wd1770_state *w = get_safe_token(device);
17991799
18001800   DEVICE_START_CALL(wd1770);
18011801
r6011r6012
18091809
18101810static DEVICE_START( wd179x )
18111811{
1812   wd17xx_t *w = get_safe_token(device);
1812   wd1770_state *w = get_safe_token(device);
18131813
18141814   DEVICE_START_CALL(wd1770);
18151815
r6011r6012
18181818
18191819static DEVICE_START( wd1793 )
18201820{
1821   wd17xx_t *w = get_safe_token(device);
1821   wd1770_state *w = get_safe_token(device);
18221822
18231823   DEVICE_START_CALL(wd1770);
18241824
r6011r6012
18271827
18281828static DEVICE_START( wd2793 )
18291829{
1830   wd17xx_t *w = get_safe_token(device);
1830   wd1770_state *w = get_safe_token(device);
18311831
18321832   DEVICE_START_CALL(wd1770);
18331833
r6011r6012
18361836
18371837static DEVICE_START( wd177x )
18381838{
1839   wd17xx_t *w = get_safe_token(device);
1839   wd1770_state *w = get_safe_token(device);
18401840
18411841   DEVICE_START_CALL(wd1770);
18421842
r6011r6012
18451845
18461846static DEVICE_START( mb8877 )
18471847{
1848   wd17xx_t *w = get_safe_token(device);
1848   wd1770_state *w = get_safe_token(device);
18491849
18501850   DEVICE_START_CALL(wd1770);
18511851
r6011r6012
18541854
18551855static DEVICE_RESET( wd1770 )
18561856{
1857   wd17xx_t *w = get_safe_token(device);
1857   wd1770_state *w = get_safe_token(device);
18581858   int i;
18591859
18601860   for (i = 0; i < 4; i++)
r6011r6012
18901890static const char DEVTEMPLATE_SOURCE[] = __FILE__;
18911891
18921892#define DEVTEMPLATE_ID(p,s)            p##wd1770##s
1893#define DEVTEMPLATE_STATE            wd17xx_t
18941893#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
18951894#define DEVTEMPLATE_NAME            "WD1770"
18961895#define DEVTEMPLATE_FAMILY            "WD17xx"

Previous 15994 Revisions Next


© 1998-2018 The MESS Team