Previous 199869 Revisions Next

r29180 Wednesday 2nd April, 2014 at 11:59:10 UTC by Miodrag Milanović
modernized access for legacy floppy, quite straight forward thing (nw)
[src/emu/bus/bml3]bml3mp1802.c bml3mp1805.c
[src/emu/bus/coco]coco_fdc.c
[src/emu/bus/ieee488]c8050.c c8050.h
[src/emu/bus/ti99_peb]bwg.c bwg.h hfdc.c hfdc.h peribox.c ti_fdc.c ti_fdc.h
[src/emu/imagedev]flopdrv.c flopdrv.h
[src/emu/machine]i8271.c i8271.h mc6843.c mc6843.h smc92x4.c smc92x4.h wd17xx.c wd17xx.h
[src/mess/drivers]apf.c fm7.c mbc200.c ms0515.c myb3k.c mz2000.c mz2500.c rainbow.c smc777.c thomson.c unixpc.c vtech1.c x1.c z100.c
[src/mess/includes]thomson.h
[src/mess/machine]appldriv.c atarifdc.c atarifdc.h beta.c concept_exp.c hec2hrp.c micropolis.c micropolis.h nes.c osborne1.c partner.c pk8020.c rmnimbus.c rx01.c rx01.h sonydriv.c svi318.c swtpc09.c thomflop.c trs80.c
[src/mess/machine/ti99]990_dk.c 990_dk.h

trunk/src/mess/drivers/mz2000.c
r29179r29180
360360   {
361361      case 0xdc:
362362         m_mb8877a->set_drive(data & 3);
363         floppy_mon_w(floppy_get_device(machine(), data & 3), (data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
364         floppy_drive_set_ready_state(floppy_get_device(machine(), data & 3), 1,0);
363         floppy_get_device(machine(), data & 3)->floppy_mon_w((data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
364         floppy_get_device(machine(), data & 3)->floppy_drive_set_ready_state(1,0);
365365         break;
366366      case 0xdd:
367367         m_mb8877a->set_side((data & 1));
trunk/src/mess/drivers/fm7.c
r29179r29180
492492         else
493493         {
494494            m_fdc->set_drive(data & 0x03);
495            floppy_mon_w(floppy_get_device(machine(), data & 0x03), !BIT(data, 7));
496            floppy_drive_set_ready_state(floppy_get_device(machine(), data & 0x03), data & 0x80,0);
495            floppy_get_device(machine(), data & 0x03)->floppy_mon_w(!BIT(data, 7));
496            floppy_get_device(machine(), data & 0x03)->floppy_drive_set_ready_state(data & 0x80,0);
497497            logerror("FDC: wrote %02x to 0x%04x (drive)\n",data,offset+0xfd18);
498498         }
499499         break;
trunk/src/mess/drivers/rainbow.c
r29179r29180
326326   virtual void machine_reset();
327327
328328   int m_unit;
329   device_t *m_image[4];
329   legacy_floppy_image_device *m_image[4];
330330
331331   int m_irq_high;
332332   UINT32 m_irq_mask;
r29179r29180
335335
336336void rainbow_state::machine_start()
337337{
338   m_image[0] = subdevice(FLOPPY_0);
339   m_image[1] = subdevice(FLOPPY_1);
340   m_image[2] = subdevice(FLOPPY_2);
341   m_image[3] = subdevice(FLOPPY_3);
338   m_image[0] = subdevice<legacy_floppy_image_device>(FLOPPY_0);
339   m_image[1] = subdevice<legacy_floppy_image_device>(FLOPPY_1);
340   m_image[2] = subdevice<legacy_floppy_image_device>(FLOPPY_2);
341   m_image[3] = subdevice<legacy_floppy_image_device>(FLOPPY_3);
342342
343343   COLD_BOOT = 1;
344344
r29179r29180
863863NOTES: ALL LOW ACTIVE - EXCEPT TR00
864864*/
865865   // * TRACK 00 *  signal for current drive
866   int tk00 = ( floppy_tk00_r( m_image[m_unit] ) == CLEAR_LINE ) ? 0x20 : 0x00;
866   int tk00 = ( m_image[m_unit]->floppy_tk00_r() == CLEAR_LINE ) ? 0x20 : 0x00;
867867
868   int fdc_ready = floppy_drive_get_flag_state( m_image[m_unit] , FLOPPY_DRIVE_READY);
868   int fdc_ready = m_image[m_unit]->floppy_drive_get_flag_state( FLOPPY_DRIVE_READY);
869869
870870   int data=(   0x80                    |   // (STEP L)
871871//           (  (fdc_write_gate) )       |
r29179r29180
958958
959959   int selected_drive = 255;
960960
961   if (flopimg_get_image( floppy_get_device( machine(), drive ) ) != NULL)
961   if (floppy_get_device( machine(), drive )->flopimg_get_image() != NULL)
962962   {   selected_drive = drive;
963963      m_fdc->set_drive(selected_drive);
964964   }
r29179r29180
987987         {
988988            // Although 1773 does not feature 'motor on' this statement is required:
989989            // CLEAR_LINE = turn motor on -
990            floppy_mon_w(m_image[f_num], (f_num == selected_drive) ? CLEAR_LINE : ASSERT_LINE);
990            m_image[f_num]->floppy_mon_w((f_num == selected_drive) ? CLEAR_LINE : ASSERT_LINE);
991991
992992            // Parameters: DRIVE, STATE, FLAG
993            floppy_drive_set_ready_state( m_image[f_num],
993            m_image[f_num]->floppy_drive_set_ready_state(
994994                                    (f_num == selected_drive) ? 1 : 0,
995995                                    (f_num == selected_drive) ? force_ready : 0
996996                                 );
trunk/src/mess/drivers/ms0515.c
r29179r29180
126126   m_video_ram = ram + 0000000 + 0340000;
127127   m_blink = 0;
128128
129   floppy_mon_w(machine().device(FLOPPY_0), 0); // turn it on
129   machine().device<legacy_floppy_image_device>(FLOPPY_0)->floppy_mon_w(0); // turn it on
130130}
131131
132132/* Input ports */
trunk/src/mess/drivers/mbc200.c
r29179r29180
127127
128128void mbc200_state::machine_start()
129129{
130   floppy_mon_w(m_floppy0, CLEAR_LINE);
131   floppy_mon_w(m_floppy1, CLEAR_LINE);
132   floppy_drive_set_ready_state(m_floppy0, 1, 1);
133   floppy_drive_set_ready_state(m_floppy1, 1, 1);
130   m_floppy0->floppy_mon_w(CLEAR_LINE);
131   m_floppy1->floppy_mon_w(CLEAR_LINE);
132   m_floppy0->floppy_drive_set_ready_state(1, 1);
133   m_floppy1->floppy_drive_set_ready_state(1, 1);
134134}
135135
136136MC6845_UPDATE_ROW( mbc200_update_row )
trunk/src/mess/drivers/unixpc.c
r29179r29180
117117{
118118   logerror("disk_control_w: %04x\n", data);
119119
120   floppy_mon_w(m_floppy, !BIT(data, 5));
120   m_floppy->floppy_mon_w(!BIT(data, 5));
121121
122122   // bit 6 = floppy selected / not selected
123123   m_wd2797->set_drive(0);
trunk/src/mess/drivers/smc777.c
r29179r29180
389389   /* FIXME: floppy drive 1 doesn't work? */
390390   for(f_num=0;f_num<2;f_num++)
391391   {
392      floppy = flopimg_get_image(floppy_get_device(machine(), f_num));
393      floppy_mon_w(floppy_get_device(machine(), f_num), (floppy != NULL) ? 0 : 1);
394      floppy_drive_set_ready_state(floppy_get_device(machine(), f_num), (floppy != NULL) ? 1 : 0,0);
392      floppy = floppy_get_device(machine(), f_num)->flopimg_get_image();
393      floppy_get_device(machine(), f_num)->floppy_mon_w((floppy != NULL) ? 0 : 1);
394      floppy_get_device(machine(), f_num)->floppy_drive_set_ready_state((floppy != NULL) ? 1 : 0,0);
395395   }
396396}
397397
trunk/src/mess/drivers/mz2500.c
r29179r29180
11901190   {
11911191      case 0xdc:
11921192         fdc->set_drive(data & 3);
1193         floppy_mon_w(floppy_get_device(machine(), data & 3), (data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
1194         floppy_drive_set_ready_state(floppy_get_device(machine(), data & 3), 1,0);
1193         floppy_get_device(machine(), data & 3)->floppy_mon_w((data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
1194         floppy_get_device(machine(), data & 3)->floppy_drive_set_ready_state(1,0);
11951195         break;
11961196      case 0xdd:
11971197         fdc->set_side((data & 1));
trunk/src/mess/drivers/x1.c
r29179r29180
10371037         break;
10381038      case 0x0ffc:
10391039         m_fdc->set_drive(data & 3);
1040         floppy_mon_w(floppy_get_device(machine(), data & 3), !BIT(data, 7));
1041         floppy_drive_set_ready_state(floppy_get_device(machine(), data & 3), data & 0x80,0);
1040         floppy_get_device(machine(), data & 3)->floppy_mon_w(!BIT(data, 7));
1041         floppy_get_device(machine(), data & 3)->floppy_drive_set_ready_state(data & 0x80,0);
10421042         m_fdc->set_side(BIT(data, 4));
10431043         break;
10441044      case 0x0ffd:
trunk/src/mess/drivers/vtech1.c
r29179r29180
669669
670670   for(id=0;id<2;id++)
671671   {
672      floppy_install_load_proc(floppy_get_device(machine(), id), vtech1_load_proc);
672      floppy_get_device(machine(), id)->floppy_install_load_proc(vtech1_load_proc);
673673   }
674674}
675675
trunk/src/mess/drivers/myb3k.c
r29179r29180
127127{
128128   /* TODO: complete guesswork! (it just does a 0x24 -> 0x20 in there) */
129129   m_fdc->set_drive(data & 3);
130   floppy_mon_w(floppy_get_device(machine(), data & 3), !(data & 4) ? 1: 0);
131   floppy_drive_set_ready_state(floppy_get_device(machine(), data & 3), data & 0x4,0);
130   floppy_get_device(machine(), data & 3)->floppy_mon_w(!(data & 4) ? 1: 0);
131   floppy_get_device(machine(), data & 3)->floppy_drive_set_ready_state(data & 0x4,0);
132132   //m_fdc->set_side((data & 0x10)>>4);
133133}
134134
trunk/src/mess/drivers/z100.c
r29179r29180
380380         m_z207_cur_drive = data & 3;
381381         break;
382382      case 5: // aux control
383         floppy_mon_w(floppy_get_device(machine(), m_z207_cur_drive), !BIT(data, 1));
384         floppy_drive_set_ready_state(floppy_get_device(machine(), m_z207_cur_drive), data & 2,0);
383         floppy_get_device(machine(), m_z207_cur_drive)->floppy_mon_w(!BIT(data, 1));
384         floppy_get_device(machine(), m_z207_cur_drive)->floppy_drive_set_ready_state(data & 2,0);
385385         break;
386386
387387   }
trunk/src/mess/drivers/apf.c
r29179r29180
260260
261261   m_fdc->set_drive(drive);
262262   floppy_image_legacy *floppy;
263   floppy = flopimg_get_image(floppy_get_device(machine(), drive));
264   floppy_mon_w(floppy_get_device(machine(), drive), (floppy != NULL) ? 0 : 1);
265   floppy_drive_set_ready_state(floppy_get_device(machine(), drive), (floppy != NULL) ? 1 : 0,0);
263   floppy = floppy_get_device(machine(), drive)->flopimg_get_image();
264   floppy_get_device(machine(), drive)->floppy_mon_w((floppy != NULL) ? 0 : 1);
265   floppy_get_device(machine(), drive)->floppy_drive_set_ready_state((floppy != NULL) ? 1 : 0,0);
266266
267267
268268   logerror("disc w %04x %04x\n",offset,data);
trunk/src/mess/drivers/thomson.c
r29179r29180
566566
567567WRITE_LINE_MEMBER( thomson_state::fdc_index_0_w )
568568{
569  thomson_index_callback(machine().device(FLOPPY_0), state);
569  thomson_index_callback(machine().device<legacy_floppy_image_device>(FLOPPY_0), state);
570570}
571571
572572WRITE_LINE_MEMBER( thomson_state::fdc_index_1_w )
573573{
574  thomson_index_callback(machine().device(FLOPPY_1), state);
574  thomson_index_callback(machine().device<legacy_floppy_image_device>(FLOPPY_1), state);
575575}
576576
577577WRITE_LINE_MEMBER( thomson_state::fdc_index_2_w )
578578{
579  thomson_index_callback(machine().device(FLOPPY_2), state);
579  thomson_index_callback(machine().device<legacy_floppy_image_device>(FLOPPY_2), state);
580580}
581581
582582WRITE_LINE_MEMBER( thomson_state::fdc_index_3_w )
583583{
584  thomson_index_callback(machine().device(FLOPPY_3), state);
584  thomson_index_callback(machine().device<legacy_floppy_image_device>(FLOPPY_3), state);
585585}
586586
587587static const floppy_interface thomson_floppy_interface_0 =
trunk/src/mess/machine/beta.c
r29179r29180
158158      }
159159      // bit 3 connected to pin 23 "HRDY" of FDC
160160      // TEMP HACK, FDD motor and RDY FDC pin controlled by HLD pin of FDC
161      device_t *flop = subdevice(beta_wd17xx_interface.floppy_drive_tags[data & 3]);
162      floppy_mon_w(flop, CLEAR_LINE);
163      floppy_drive_set_ready_state(flop, 1, 0);
161      legacy_floppy_image_device *flop = subdevice<legacy_floppy_image_device>(beta_wd17xx_interface.floppy_drive_tags[data & 3]);
162      flop->floppy_mon_w(CLEAR_LINE);
163      flop->floppy_drive_set_ready_state(1, 0);
164164   }
165165}
166166
trunk/src/mess/machine/pk8020.c
r29179r29180
840840WRITE8_MEMBER(pk8020_state::pk8020_portb_w)
841841{
842842   // Turn all motors off
843   floppy_mon_w(floppy_get_device(machine(), 0), 1);
844   floppy_mon_w(floppy_get_device(machine(), 1), 1);
845   floppy_mon_w(floppy_get_device(machine(), 2), 1);
846   floppy_mon_w(floppy_get_device(machine(), 3), 1);
843   floppy_get_device(machine(), 0)->floppy_mon_w(1);
844   floppy_get_device(machine(), 1)->floppy_mon_w(1);
845   floppy_get_device(machine(), 2)->floppy_mon_w(1);
846   floppy_get_device(machine(), 3)->floppy_mon_w(1);
847847   m_wd1793->set_side(BIT(data,4));
848848   if (BIT(data,0)) {
849849      m_wd1793->set_drive(0);
850      floppy_mon_w(floppy_get_device(machine(), 0), 0);
851      floppy_drive_set_ready_state(floppy_get_device(machine(), 0), 1, 1);
850      floppy_get_device(machine(), 0)->floppy_mon_w(0);
851      floppy_get_device(machine(), 0)->floppy_drive_set_ready_state(1, 1);
852852   } else if (BIT(data,1)) {
853853      m_wd1793->set_drive(1);
854      floppy_mon_w(floppy_get_device(machine(), 1), 0);
855      floppy_drive_set_ready_state(floppy_get_device(machine(), 1), 1, 1);
854      floppy_get_device(machine(), 1)->floppy_mon_w(0);
855      floppy_get_device(machine(), 1)->floppy_drive_set_ready_state(1, 1);
856856   } else if (BIT(data,2)) {
857857      m_wd1793->set_drive(2);
858      floppy_mon_w(floppy_get_device(machine(), 2), 0);
859      floppy_drive_set_ready_state(floppy_get_device(machine(), 2), 1, 1);
858      floppy_get_device(machine(), 2)->floppy_mon_w(0);
859      floppy_get_device(machine(), 2)->floppy_drive_set_ready_state(1, 1);
860860   } else if (BIT(data,3)) {
861861      m_wd1793->set_drive(3);
862      floppy_mon_w(floppy_get_device(machine(), 3), 0);
863      floppy_drive_set_ready_state(floppy_get_device(machine(), 3), 1, 1);
862      floppy_get_device(machine(), 3)->floppy_mon_w(0);
863      floppy_get_device(machine(), 3)->floppy_drive_set_ready_state(1, 1);
864864   }
865865}
866866
trunk/src/mess/machine/thomflop.c
r29179r29180
115115
116116
117117/* build a sector, with header & space */
118int thomson_state::thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size )
118int thomson_state::thom_floppy_make_sector( legacy_floppy_image_device* img, chrn_id id, UINT8* dst, int sector_size )
119119{
120120   if ( sector_size == 128 )
121121   {
122122      /* single density */
123123      memset( dst, 0x00, 6 ); /* synchro bytes */
124124      dst[ 6 ] = 0xfb; /* data field mark */
125      floppy_drive_read_sector_data
126         ( img, id.H, id.data_id, dst + 7, sector_size );
125      img->floppy_drive_read_sector_data
126         (  id.H, id.data_id, dst + 7, sector_size );
127127      dst[ sector_size + 7 ] = 0; /* TODO: CRC */
128128      dst[ sector_size + 8 ] = 0; /* TODO: CRC */
129129      memset( dst + sector_size + 9, 0xff, 22 ); /* end mark */
r29179r29180
134134      /* double density */
135135      memset( dst, 0xa1, 3 ); /* synchro bytes */
136136      dst[ 3 ] = 0xfb; /* data field mark */
137      floppy_drive_read_sector_data
138         ( img, id.H, id.data_id, dst + 4, sector_size );
137      img->floppy_drive_read_sector_data
138         (  id.H, id.data_id, dst + 4, sector_size );
139139      dst[ sector_size + 4 ] = 0; /* TODO: CRC */
140140      dst[ sector_size + 5 ] = 0; /* TODO: CRC */
141141      memset( dst + sector_size + 6, 0xF7, 74 ); /* end mark */
r29179r29180
146146
147147
148148/* build a whole track */
149int thomson_state::thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side )
149int thomson_state::thom_floppy_make_track( legacy_floppy_image_device* img, UINT8* dst, int sector_size, int side )
150150{
151151   UINT8 space = ( sector_size == 128 ) ? 0xff : 0;
152152   UINT8* org = dst;
r29179r29180
154154   int nb;
155155
156156   /* go to start of track */
157   while ( ! floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) )
157   while ( ! img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) )
158158   {
159      if ( ! floppy_drive_get_next_id( img, side, &id ) )
159      if ( ! img->floppy_drive_get_next_id( side, &id ) )
160160         return 0;
161161   }
162162
163163   /* for each sector... */
164164   for ( nb = 0; nb < 16; nb++ )
165165   {
166      if ( ! floppy_drive_get_next_id( img, side, &id ) )
166      if ( ! img->floppy_drive_get_next_id( side, &id ) )
167167         break;
168168
169169      memset( dst, space, THOM_SIZE_SYNCHRO ); dst += THOM_SIZE_SYNCHRO;
r29179r29180
171171      memset( dst, space, THOM_SIZE_SYNCHRO ); dst += THOM_SIZE_SYNCHRO;
172172      dst += thom_floppy_make_sector( img, id, dst, sector_size );
173173
174      if ( floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) )
174      if ( img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) )
175175         break;
176176   }
177177   return dst - org;
r29179r29180
222222
223223
224224/* build a sector, with header */
225int thomson_state::thom_qdd_make_sector( device_t* img, int sector, UINT8* dst )
225int thomson_state::thom_qdd_make_sector( legacy_floppy_image_device* img, int sector, UINT8* dst )
226226{
227227   int i;
228228   dst[ 0 ] = 0x5a;
229   floppy_drive_read_sector_data ( img, 0, sector, dst + 1, 128 );
229   img->floppy_drive_read_sector_data (  0, sector, dst + 1, 128 );
230230   dst[ 129 ] = 0;
231231   for ( i = 0; i < 129; i++ )
232232      dst[ 129 ] += dst[ i ];
r29179r29180
236236
237237
238238/* build a whole disk */
239int thomson_state::thom_qdd_make_disk ( device_t* img, UINT8* dst )
239int thomson_state::thom_qdd_make_disk ( legacy_floppy_image_device* img, UINT8* dst )
240240{
241241   UINT8* org = dst;
242242   int i;
r29179r29180
418418            machine().time().as_double(), m_maincpu->pc(), offset, data );
419419}
420420
421void thomson_state::to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state )
421void thomson_state::to7_5p14_index_pulse_callback( device_t *controller,legacy_floppy_image_device *image, int state )
422422{
423423   m_mc6843->set_index_pulse( state );
424424}
r29179r29180
429429   LOG(( "to7_5p14sd_reset: CD 90-015 controller\n" ));
430430   for ( i = 0; i < floppy_get_count( machine() ); i++ )
431431   {
432      device_t * img = floppy_get_device( machine(), i );
432      legacy_floppy_image_device * img = floppy_get_device( machine(), i );
433433      if (img) {
434         floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
435         floppy_drive_set_rpm( img, 300. );
436         floppy_drive_seek( img, - floppy_drive_get_current_track( img ) );
434         img->floppy_drive_set_ready_state( FLOPPY_DRIVE_READY, 0 );
435         img->floppy_drive_set_rpm( 300. );
436         img->floppy_drive_seek( - img->floppy_drive_get_current_track() );
437437      }
438438   }
439439}
r29179r29180
515515
516516
517517
518void thomson_state::to7_qdd_index_pulse_cb( device_t *controller,device_t *image, int state )
518void thomson_state::to7_qdd_index_pulse_cb( device_t *controller,legacy_floppy_image_device *image, int state )
519519{
520520   to7qdd->index_pulse = state;
521521
r29179r29180
532532
533533
534534
535device_t * thomson_state::to7_qdd_image()
535legacy_floppy_image_device * thomson_state::to7_qdd_image()
536536{
537537   return floppy_get_device( machine(), 0 );
538538}
r29179r29180
548548      to7qdd->status |= QDD_S_PE;
549549
550550   /* write-protect */
551   if (floppy_wpt_r(to7_qdd_image()) == CLEAR_LINE)
551   if (to7_qdd_image()->floppy_wpt_r() == CLEAR_LINE)
552552      to7qdd->status |= QDD_S_NCTS;
553553
554554   /* sticky reset conditions */
r29179r29180
644644         LOG(( "%f $%04x to7_qdd_write_byte: got id field for sector=%i\n",
645645               machine().time().as_double(), m_maincpu->pc(), sector ));
646646
647         floppy_drive_format_sector( to7_qdd_image(),
647         to7_qdd_image()->floppy_drive_format_sector(
648648                     0, sector, 0, 0, sector, 128, filler );
649649                  thom_floppy_active( 1 );
650650         to7qdd->start_idx = to7qdd->data_idx;
r29179r29180
673673            LOG(( "%f $%04x to7_qdd_write_byte: goto data field for sector=%i\n",
674674                  machine().time().as_double(), m_maincpu->pc(), sector ));
675675
676            floppy_drive_write_sector_data( to7_qdd_image(), 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 );
676            to7_qdd_image()->floppy_drive_write_sector_data( 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 );
677677                        thom_floppy_active( 1 );
678678         }
679679
r29179r29180
825825
826826   for ( i = 0; i < floppy_get_count( machine() ); i++ )
827827   {
828      device_t * img = floppy_get_device( machine(), i );
828      legacy_floppy_image_device * img = floppy_get_device( machine(), i );
829829      if (img) {
830         floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
830         img->floppy_drive_set_ready_state(  FLOPPY_DRIVE_READY, 0 );
831831
832832         motor_on = CLEAR_LINE;
833         floppy_mon_w(img, motor_on);
833         img->floppy_mon_w( motor_on);
834834
835835         /* pulse each time the whole-disk spiraling track ends */
836836         /* at 90us per byte read, the disk can be read in 6s */
837         floppy_drive_set_rpm( img, 60. / 6. );
837         img->floppy_drive_set_rpm( 60. / 6. );
838838      }
839839   }
840840
r29179r29180
927927
928928
929929
930device_t * thomson_state::thmfc_floppy_image()
930legacy_floppy_image_device * thomson_state::thmfc_floppy_image()
931931{
932932   return floppy_get_device( machine(), thmfc1->drive );
933933}
934934
935935
936936
937int thomson_state::thmfc_floppy_is_qdd ( device_image_interface *image )
937int thomson_state::thmfc_floppy_is_qdd ( legacy_floppy_image_device *image )
938938{
939939   if (image==NULL) return 0;
940940   if (!image->exists()) return 0;
r29179r29180
943943
944944
945945
946void thomson_state::thmfc_floppy_index_pulse_cb ( device_t *controller,device_t *image, int state )
946void thomson_state::thmfc_floppy_index_pulse_cb ( device_t *controller,legacy_floppy_image_device *image, int state )
947947{
948948   if ( image != thmfc_floppy_image())
949949      return;
950950
951   if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(image)))
951   if ( thmfc_floppy_is_qdd(image))
952952   {
953953      /* pulse each time the whole-disk spiraling track ends */
954      floppy_drive_set_rpm( image, 16.92f /* 423/25 */ );
954      image->floppy_drive_set_rpm( 16.92f /* 423/25 */ );
955955      thmfc1->ipl = state;
956956      if ( state )
957957      {
r29179r29180
962962   }
963963   else
964964   {
965      floppy_drive_set_rpm( image, 300. );
965      image->floppy_drive_set_rpm( 300. );
966966      thmfc1->ipl = state;
967967      if ( state  )
968968         thmfc1->data_raw_idx = 0;
r29179r29180
975975
976976int thomson_state::thmfc_floppy_find_sector( chrn_id* dst )
977977{
978   device_t* img = thmfc_floppy_image();
978   legacy_floppy_image_device* img = thmfc_floppy_image();
979979   chrn_id id;
980980   int r = 0;
981981
982982   /* scan track, try 4 revolutions */
983983   while ( r < 4 )
984984   {
985      if ( floppy_drive_get_next_id( img, thmfc1->side, &id ) )
985      if ( img->floppy_drive_get_next_id( thmfc1->side, &id ) )
986986      {
987987         if ( id.C == thmfc1->track &&
988988               id.R == thmfc1->sector &&
r29179r29180
997997         }
998998      }
999999
1000      if ( floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) )
1000      if ( img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) )
10011001         r++;
10021002   }
10031003
10041004   thmfc1->stat0 = THMFC1_STAT0_CRC_ERROR | THMFC1_STAT0_FINISHED;
1005   LOG (( "thmfc_floppy_find_sector: sector not found drive=%i track=%i sector=%i\n", floppy_get_drive( img ), thmfc1->track, thmfc1->sector ));
1005   LOG (( "thmfc_floppy_find_sector: sector not found drive=%i track=%i sector=%i\n", floppy_get_drive(img), thmfc1->track, thmfc1->sector ));
10061006   return 0;
10071007}
10081008
r29179r29180
10171017
10181018   if ( thmfc1->op == THMFC1_OP_WRITE_SECT )
10191019   {
1020      device_t * img = thmfc_floppy_image();
1021      floppy_drive_write_sector_data( img, thmfc1->side, thmfc1->sector_id, thmfc1->data + 3, thmfc1->data_size - 3, 0 );
1020      legacy_floppy_image_device * img = thmfc_floppy_image();
1021      img->floppy_drive_write_sector_data( thmfc1->side, thmfc1->sector_id, thmfc1->data + 3, thmfc1->data_size - 3, 0 );
10221022            thom_floppy_active( 1 );
10231023   }
10241024   thmfc1->op = THMFC1_OP_RESET;
r29179r29180
10681068   /* rebuild track if needed */
10691069   if ( ! thmfc1->data_raw_size )
10701070   {
1071      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image())))
1071      if ( thmfc_floppy_is_qdd(thmfc_floppy_image()))
10721072         /* QDD: track = whole disk */
10731073         thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data );
10741074      else
r29179r29180
11361136
11371137         LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: id field, sector=%i\n", machine().time().as_double(), m_maincpu->pc(), sector ));
11381138
1139         floppy_drive_format_sector( thmfc_floppy_image(), 0, sector, 0, 0, sector, 128, filler );
1139         thmfc_floppy_image()->floppy_drive_format_sector( 0, sector, 0, 0, sector, 128, filler );
11401140         thom_floppy_active( 1 );
11411141         thmfc1->data_idx = 0;
11421142      }
r29179r29180
11581158         if ( i >= 0 )
11591159         {
11601160            /* got an id & a data field => write */
1161            device_t * img = thmfc_floppy_image();
1161            legacy_floppy_image_device * img = thmfc_floppy_image();
11621162            int sector = (int) thmfc1->data[ i + 1 ] * 256 +
11631163               (int) thmfc1->data[ i + 2 ];
11641164
11651165            LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: data field, sector=%i\n",
11661166                  machine().time().as_double(), m_maincpu->pc(), sector ));
11671167
1168            floppy_drive_write_sector_data( img, 0, sector, thmfc1->data + thmfc1->data_idx, 128, 0 );
1168            img->floppy_drive_write_sector_data( 0, sector, thmfc1->data + thmfc1->data_idx, 128, 0 );
11691169            thom_floppy_active( 1 );
11701170         }
11711171
r29179r29180
12181218         if ( !memcmp ( thmfc1->data, header, sizeof( header ) ) )
12191219         {
12201220            /* got id field => format */
1221            device_t * img = thmfc_floppy_image();
1221            legacy_floppy_image_device * img = thmfc_floppy_image();
12221222            UINT8 track  = thmfc1->data[4];
12231223            UINT8 side   = thmfc1->data[5];
12241224            UINT8 sector = thmfc1->data[6];
r29179r29180
12271227                        chrn_id id;
12281228                        if ( thmfc_floppy_find_sector( &id ) )
12291229                        {
1230                              floppy_drive_format_sector( img, side, thmfc1->sector_id, track, thmfc1->side, sector, length, filler );
1230                              img->floppy_drive_format_sector( side, thmfc1->sector_id, track, thmfc1->side, sector, length, filler );
12311231                              thom_floppy_active( 1 );
12321232                        }
12331233         }
r29179r29180
12521252   case 1: /* STAT1 */
12531253   {
12541254      UINT8 data = 0;
1255      device_image_interface * img = dynamic_cast<device_image_interface *>(thmfc_floppy_image());
1256      int flags = floppy_drive_get_flag_state( &img->device(), -1 );
1255      legacy_floppy_image_device * img = thmfc_floppy_image();
1256      int flags = img->floppy_drive_get_flag_state(-1 );
12571257      if ( thmfc_floppy_is_qdd(img) )
12581258      {
12591259         if ( ! img->exists() )
r29179r29180
12691269         if ( img->exists() )
12701270            data |= 0x20; /* disk change (?) */
12711271
1272         data |= !floppy_tk00_r(&img->device()) << 3;
1272         data |= !img->floppy_tk00_r() << 3;
12731273
12741274         if ( flags & FLOPPY_DRIVE_READY )
12751275            data |= 0x02;
12761276      }
12771277      if (!motor_on)
12781278         data |= 0x10;
1279      if (!floppy_wpt_r(&img->device()))
1279      if (!img->floppy_wpt_r())
12801280         data |= 0x04;
12811281      VLOG(( "%f $%04x thmfc_floppy_r: STAT1=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
12821282      return data;
r29179r29180
13141314   case 0: /* CMD0 */
13151315   {
13161316      int wsync = (data >> 4) & 1;
1317      int qdd = thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image()));
1317      int qdd = thmfc_floppy_is_qdd(thmfc_floppy_image());
13181318      chrn_id id;
13191319      thmfc1->formatting = (data >> 2) & 1;
13201320      LOG (( "%f $%04x thmfc_floppy_w: CMD0=$%02X dens=%s wsync=%i dsync=%i fmt=%i op=%i\n",
r29179r29180
14151415
14161416   case 2: /* CMD2 */
14171417   {
1418      device_t * img;
1418      legacy_floppy_image_device * img;
14191419      int seek = 0, motor;
14201420      thmfc1->drive = data & 2;
14211421
1422      img = thmfc_floppy_image();
1423      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(img)))
1422      img  = thmfc_floppy_image();
1423      if ( thmfc_floppy_is_qdd(img))
14241424      {
14251425         motor = !(data & 0x40);
14261426         /* no side select & no seek for QDD */
r29179r29180
14431443      if ( seek )
14441444      {
14451445         thmfc1->data_raw_size = 0;
1446         floppy_drive_seek( img, seek );
1446         img->floppy_drive_seek( seek );
14471447      }
14481448
14491449      /* in real life, to keep the motor running, it is sufficient to
r29179r29180
14511451         instead of counting, we assume the motor is always running...
14521452      */
14531453      motor_on = CLEAR_LINE /* motor */;
1454      floppy_mon_w(img, motor_on);
1454      img->floppy_mon_w(motor_on);
14551455   }
14561456   break;
14571457
14581458
14591459   case 3: /* WDATA */
14601460      thmfc1->wsync = data;
1461      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image())))
1461      if ( thmfc_floppy_is_qdd(thmfc_floppy_image()))
14621462         thmfc_floppy_qdd_write_byte( data );
14631463      else if ( thmfc1->op==THMFC1_OP_WRITE_SECT )
14641464         thmfc_floppy_write_byte( data );
r29179r29180
14901490      thmfc1->track = data;
14911491      LOG (( "%f $%04x thmfc_floppy_w: WTRCK=%i (real=%i)\n",
14921492            machine().time().as_double(), m_maincpu->pc(), data,
1493            floppy_drive_get_current_track( thmfc_floppy_image() ) ));
1493            thmfc_floppy_image()->floppy_drive_get_current_track()));
14941494      break;
14951495
14961496   case 7: /* WCELL */
r29179r29180
15141514
15151515   for ( i = 0; i < floppy_get_count( machine() ); i++ )
15161516   {
1517      device_t * img = floppy_get_device( machine(), i );
1517      legacy_floppy_image_device * img = floppy_get_device( machine(), i );
15181518      if (img) {
1519         floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
1520         floppy_drive_seek( img, - floppy_drive_get_current_track( img ) );
1519         img->floppy_drive_set_ready_state( FLOPPY_DRIVE_READY, 0 );
1520         img->floppy_drive_seek(  - img->floppy_drive_get_current_track() );
15211521      }
15221522   }
15231523
r29179r29180
19121912      to7_5p14_w( space, offset, data, mem_mask );
19131913}
19141914
1915void thomson_state::thomson_index_callback(device_t *device, int state)
1915void thomson_state::thomson_index_callback(legacy_floppy_image_device *device, int state)
19161916{
19171917   switch ( to7_controller_type )
19181918   {
trunk/src/mess/machine/concept_exp.c
r29179r29180
243243         // floppy_drive_set_motor_state(floppy_get_device(machine(),  current_drive), (data & LC_MOTOROF_mask) == 0 ? 1 : 0);
244244         /*flp_8in = (data & LC_FLP8IN_mask) != 0;*/
245245         m_wd179x->dden_w(BIT(data, 7));
246         floppy_drive_set_ready_state(floppy_get_device(machine(), current_drive), 1, 0);
246         floppy_get_device(machine(), current_drive)->floppy_drive_set_ready_state(1, 0);
247247         break;
248248
249249      case  8:    // FDC COMMAMD REG
trunk/src/mess/machine/swtpc09.c
r29179r29180
154154       case 0x0e:
155155          m_fdc->set_drive(0);
156156           // need to set drive ready as sw checks before doing anything
157          floppy_drive_set_ready_state(machine().device("floppy0"), 1,0);
157          machine().device<legacy_floppy_image_device>("floppy0")->floppy_drive_set_ready_state(1,0);
158158         break;
159159       case 0x0d:
160160          m_fdc->set_drive(1);
161          floppy_drive_set_ready_state(machine().device("floppy1"), 1,0);
161          machine().device<legacy_floppy_image_device>("floppy1")->floppy_drive_set_ready_state(1,0);
162162         break;
163163
164164       case 0x0b:
165165          m_fdc->set_drive(2);
166          floppy_drive_set_ready_state(machine().device("floppy2"), 1,0);
166          machine().device<legacy_floppy_image_device>("floppy2")->floppy_drive_set_ready_state(1,0);
167167           break;
168168
169169       case 0x07:
170170          m_fdc->set_drive(3);
171          floppy_drive_set_ready_state(machine().device("floppy3"), 1,0);
171          machine().device<legacy_floppy_image_device>("floppy3")->floppy_drive_set_ready_state(1,0);
172172           break;
173173
174174      default:
r29179r29180
422422       case 0x01:
423423          m_fdc->set_drive(0);
424424           // need to set drive ready as sw checks before doing anything
425          floppy_drive_set_ready_state(machine().device("floppy0"), 1,0);
425          machine().device<legacy_floppy_image_device>("floppy0")->floppy_drive_set_ready_state(1,0);
426426         break;
427427       case 0x02:
428428          m_fdc->set_drive(1);
429          floppy_drive_set_ready_state(machine().device("floppy1"), 1,0);
429          machine().device<legacy_floppy_image_device>("floppy1")->floppy_drive_set_ready_state(1,0);
430430         break;
431431
432432       case 0x04:
433433          m_fdc->set_drive(2);
434          floppy_drive_set_ready_state(machine().device("floppy2"), 1,0);
434          machine().device<legacy_floppy_image_device>("floppy2")->floppy_drive_set_ready_state(1,0);
435435           break;
436436
437437       case 0x08:
438438          m_fdc->set_drive(3);
439          floppy_drive_set_ready_state(machine().device("floppy3"), 1,0);
439          machine().device<legacy_floppy_image_device>("floppy3")->floppy_drive_set_ready_state(1,0);
440440           break;
441441
442442      default:
r29179r29180
476476       case 0x00:
477477          m_fdc->set_drive(0);
478478           // need to set drive ready as sw checks before doing anything
479          floppy_drive_set_ready_state(machine().device("floppy0"), 1,0);
479          machine().device<legacy_floppy_image_device>("floppy0")->floppy_drive_set_ready_state(1,0);
480480         break;
481481       case 0x01:
482482          m_fdc->set_drive(1);
483          floppy_drive_set_ready_state(machine().device("floppy1"), 1,0);
483          machine().device<legacy_floppy_image_device>("floppy1")->floppy_drive_set_ready_state(1,0);
484484         break;
485485
486486       case 0x02:
487487          m_fdc->set_drive(2);
488          floppy_drive_set_ready_state(machine().device("floppy2"), 1,0);
488          machine().device<legacy_floppy_image_device>("floppy2")->floppy_drive_set_ready_state(1,0);
489489           break;
490490
491491       case 0x03:
492492          m_fdc->set_drive(3);
493          floppy_drive_set_ready_state(machine().device("floppy3"), 1,0);
493          machine().device<legacy_floppy_image_device>("floppy3")->floppy_drive_set_ready_state(1,0);
494494           break;
495495
496496      default:
trunk/src/mess/machine/sonydriv.c
r29179r29180
103103static void load_track_data(device_t *device,int floppy_select)
104104{
105105   int track_size;
106   device_image_interface *cur_image;
106   legacy_floppy_image_device *cur_image;
107107   UINT8 *new_data;
108108   floppy_t *f;
109109
110110   f = &sony.floppy[floppy_select];
111   cur_image = dynamic_cast<device_image_interface *>(floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, floppy_select));
111   cur_image = floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, floppy_select);
112112
113   floppy_image_legacy *fimg = flopimg_get_image(&cur_image->device());
113   floppy_image_legacy *fimg = cur_image->flopimg_get_image();
114114
115115   if (!fimg)
116116   {
117117      return;
118118   }
119119
120   track_size = floppy_get_track_size(fimg, f->head, floppy_drive_get_current_track(&cur_image->device()));
120   track_size = floppy_get_track_size(fimg, f->head, cur_image->floppy_drive_get_current_track());
121121   if (f->loadedtrack_data) auto_free(device->machine(),f->loadedtrack_data);
122122   new_data = auto_alloc_array(device->machine(),UINT8,track_size);
123123   if (!new_data)
r29179r29180
125125      return;
126126   }
127127
128   floppy_drive_read_track_data_info_buffer(&cur_image->device(), f->head, new_data, &track_size);
128   cur_image->floppy_drive_read_track_data_info_buffer(f->head, new_data, &track_size);
129129   f->loadedtrack_valid = 1;
130130   f->loadedtrack_dirty = 0;
131131   f->loadedtrack_size = track_size;
r29179r29180
137137
138138static void save_track_data(device_t *device, int floppy_select)
139139{
140   device_image_interface *cur_image;
140   legacy_floppy_image_device *cur_image;
141141   floppy_t *f;
142142   int len;
143143
144144   f = &sony.floppy[floppy_select];
145   cur_image = dynamic_cast<device_image_interface *>(floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, floppy_select));
145   cur_image = floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, floppy_select);
146146
147147   if (f->loadedtrack_dirty)
148148   {
149149      len = f->loadedtrack_size;
150      floppy_drive_write_track_data_info_buffer(&cur_image->device(), f->head, f->loadedtrack_data, &len);
150      cur_image->floppy_drive_write_track_data_info_buffer(f->head, f->loadedtrack_data, &len);
151151      f->loadedtrack_dirty = 0;
152152   }
153153}
r29179r29180
157157UINT8 sony_read_data(device_t *device)
158158{
159159   UINT8 result = 0;
160   device_image_interface *cur_image;
160   legacy_floppy_image_device *cur_image;
161161   floppy_t *f;
162162
163163   if (sony_enable2() || (! sony.floppy_enable))
164164      return 0xFF;            /* right ??? */
165165
166166   f = &sony.floppy[sony.floppy_select];
167   cur_image = dynamic_cast<device_image_interface *>(floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, sony.floppy_select));
167   cur_image = floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, sony.floppy_select);
168168   if (!cur_image->exists())
169169      return 0xFF;
170170
r29179r29180
206206
207207
208208
209static int sony_rpm(floppy_t *f, device_t *cur_image)
209static int sony_rpm(floppy_t *f, legacy_floppy_image_device *cur_image)
210210{
211211   int result = 0;
212   device_image_interface *image =dynamic_cast<device_image_interface *>(cur_image);
213212   /*
214213    * The Mac floppy controller was interesting in that its speed was adjusted
215214    * while the thing was running.  On the tracks closer to the rim, it was
r29179r29180
253252         439     /* 64-79:   timing value ???? (acceptable range {021E-0222} */
254253      };
255254#endif
256      if (cur_image && image->exists())
257         result = speeds[floppy_drive_get_current_track(cur_image) / 16];
255      if (cur_image && cur_image->exists())
256         result = speeds[cur_image->floppy_drive_get_current_track() / 16];
258257   }
259258   return result;
260259}
r29179r29180
264263   int result = 1;
265264   int action;
266265   floppy_t *f;
267   device_image_interface *cur_image;
266   legacy_floppy_image_device *cur_image;
268267
269268   action = ((sony.lines & (SONY_CA1 | SONY_CA0)) << 2) | (sony.sel_line << 1) | ((sony.lines & SONY_CA2) >> 2);
270269
r29179r29180
277276   if ((! sony_enable2()) && sony.floppy_enable)
278277   {
279278      f = &sony.floppy[sony.floppy_select];
280      cur_image = dynamic_cast<device_image_interface *>(floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, sony.floppy_select));
279      cur_image = floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, sony.floppy_select);
281280      if (!cur_image->exists())
282281         cur_image = NULL;
283282
r29179r29180
314313         break;
315314      case 0x06:  /* Disk is locked 0=locked 1=unlocked */
316315         if (cur_image)
317            result = floppy_wpt_r(&cur_image->device());
316            result = cur_image->floppy_wpt_r();
318317         else
319318            result = 0;
320319         break;
r29179r29180
324323      case 0x09:  /* Number of sides: 0=single sided, 1=double sided */
325324         if (cur_image)
326325         {
327            floppy_image_legacy *fimg = flopimg_get_image(&cur_image->device());
326            floppy_image_legacy *fimg = cur_image->flopimg_get_image();
328327            if (fimg)
329328            {
330329               result = floppy_get_heads_per_disk(fimg) - 1;
r29179r29180
335334      case 0x0a:  /* At track 0: 0=track zero 1=not track zero */
336335         logerror("%s sony.status(): reading Track 0\n", device->machine().describe_context());
337336         if (cur_image)
338            result = floppy_tk00_r(&cur_image->device());
337            result = cur_image->floppy_tk00_r();
339338         else
340339            result = 0;
341340         break;
r29179r29180
346345         {
347346            if (cur_image)
348347            {
349               if (!floppy_dskchg_r(&cur_image->device()))
348               if (!cur_image->floppy_dskchg_r())
350349               {
351350                  f->disk_switched = 1;
352351               }
r29179r29180
372371         /* (time in seconds) / (60 sec/minute) * (rounds/minute) * (60 pulses) * (2 pulse phases) */
373372         if (cur_image)
374373         {
375            result = ((int) (device->machine().time().as_double() / 60.0 * sony_rpm(f, &cur_image->device()) * 60.0 * 2.0)) & 1;
374            result = ((int) (device->machine().time().as_double() / 60.0 * sony_rpm(f, cur_image) * 60.0 * 2.0)) & 1;
376375         }
377376         break;
378377      case 0x0f:  /* 400k/800k: Drive installed: 0=drive connected, 1=drive not connected */
r29179r29180
400399{
401400   int action;
402401   floppy_t *f;
403   device_image_interface *cur_image;
402   legacy_floppy_image_device *cur_image;
404403
405404   action = ((sony.lines & (SONY_CA1 | SONY_CA0)) << 2) | ((sony.lines & SONY_CA2) >> 2) | (sony.sel_line << 1);
406405
r29179r29180
413412   if (sony.floppy_enable)
414413   {
415414      f = &sony.floppy[sony.floppy_select];
416      cur_image = dynamic_cast<device_image_interface *>(floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, sony.floppy_select));
415      cur_image = floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_SONY, sony.floppy_select);
417416      if (!cur_image->exists())
418417         cur_image = NULL;
419418
r29179r29180
433432         {
434433            save_track_data(device,sony.floppy_select);
435434            if (f->step)
436               floppy_drive_seek(&cur_image->device(), -1);
435               cur_image->floppy_drive_seek(-1);
437436            else
438               floppy_drive_seek(&cur_image->device(), +1);
437               cur_image->floppy_drive_seek(+1);
439438            f->loadedtrack_valid = 0;
440439         }
441440         break;
442441      case 0x08:  /* Turn motor on */
443442         f->motor_on = CLEAR_LINE;
444443         if (cur_image)
445            floppy_mon_w(&cur_image->device(), f->motor_on);
444            cur_image->floppy_mon_w(f->motor_on);
446445         break;
447446      case 0x09:  /* Turn motor off */
448447         f->motor_on = ASSERT_LINE;
449448         if (cur_image)
450            floppy_mon_w(&cur_image->device(), f->motor_on);
449            cur_image->floppy_mon_w(f->motor_on);
451450         break;
452451      case 0x0d:  /* Eject disk */
453452         if (cur_image)
r29179r29180
542541void sonydriv_floppy_image_device::device_start()
543542{
544543   legacy_floppy_image_device::device_start();
545   floppy_set_type(this, FLOPPY_TYPE_SONY);
544   floppy_set_type(FLOPPY_TYPE_SONY);
546545
547546   sony.floppy[0].is_fdhd = 0;
548547   sony.floppy[1].is_fdhd = 0;
trunk/src/mess/machine/ti99/990_dk.c
r29179r29180
1616#include "emu.h"
1717
1818#include "formats/basicdsk.h"
19#include "imagedev/flopdrv.h"
2019#include "990_dk.h"
2120
2221/* status bits */
r29179r29180
110109
111110   /*while (revolution_count < 2)*/
112111   /*{*/
113      if (floppy_drive_get_next_id(&m_drv[unit].img->device(), head, &id))
112      if (m_drv[unit].img->floppy_drive_get_next_id(head, &id))
114113      {
115114         if (cylinder_id)
116115            *cylinder_id = id.C;
r29179r29180
142141
143142   while (revolution_count < 2)
144143   {
145      if (floppy_drive_get_next_id(&m_drv[unit].img->device(), head, &id))
144      if (m_drv[unit].img->floppy_drive_get_next_id(head, &id))
146145      {
147146         /* compare id */
148147         if ((id.R == sector) && (id.N == 0))
r29179r29180
199198   }
200199   for (retries=0; retries<10; retries++)
201200   {   /* seek to requested track */
202      floppy_drive_seek(&m_drv[unit].img->device(), cylinder-m_drv[unit].log_cylinder[head]);
201      m_drv[unit].img->floppy_drive_seek(cylinder-m_drv[unit].log_cylinder[head]);
203202      /* update physical track position */
204203      if (m_drv[unit].phys_cylinder != -1)
205204         m_drv[unit].phys_cylinder += cylinder-m_drv[unit].log_cylinder[head];
r29179r29180
241240   }
242241
243242   /* limit iterations to 76 to prevent an endless loop if the disc is locked */
244   while (!(seek_complete = !floppy_tk00_r(&m_drv[unit].img->device())) && (seek_count < 76))
243   while (!(seek_complete = !m_drv[unit].img->floppy_tk00_r()) && (seek_count < 76))
245244   {
246      floppy_drive_seek(&m_drv[unit].img->device(), -1);
245      m_drv[unit].img->floppy_drive_seek(-1);
247246      seek_count++;
248247   }
249248   if (! seek_complete)
r29179r29180
279278      return;
280279   }
281280
282   floppy_drive_read_sector_data(&m_drv[m_unit].img->device(), m_head, data_id, m_buf, 128);
281   m_drv[m_unit].img->floppy_drive_read_sector_data(m_head, data_id, m_buf, 128);
283282   m_buf_pos = 0;
284283   m_buf_mode = bm_read;
285284   m_recv_buf = (m_buf[m_buf_pos<<1] << 8) | m_buf[(m_buf_pos<<1)+1];
r29179r29180
305304      return;
306305   }
307306
308   floppy_drive_write_sector_data(&m_drv[m_unit].img->device(), m_head, data_id, m_buf, 128, m_ddam);
307   m_drv[m_unit].img->floppy_drive_write_sector_data(m_head, data_id, m_buf, 128, m_ddam);
309308   m_buf_pos = 0;
310309   m_buf_mode = bm_write;
311310
r29179r29180
587586      }
588587      else if ((m_drv[unit].phys_cylinder != -1) || (!do_restore(unit)))
589588      {
590         floppy_drive_seek(&m_drv[unit].img->device(), cylinder-m_drv[unit].phys_cylinder);
589         m_drv[unit].img->floppy_drive_seek(cylinder-m_drv[unit].phys_cylinder);
591590         m_stat_reg |= status_OP_complete;
592591      }
593592
r29179r29180
871870
872871   for (int i=0; i<MAX_FLOPPIES; i++)
873872   {
874      m_drv[i].img = dynamic_cast<device_image_interface *>(floppy_get_device(machine(), i));
873      m_drv[i].img = floppy_get_device(machine(), i);
875874      m_drv[i].phys_cylinder = -1;
876875      m_drv[i].log_cylinder[0] = m_drv[i].log_cylinder[1] = -1;
877876      m_drv[i].seclen = 64;
trunk/src/mess/machine/ti99/990_dk.h
r29179r29180
55#ifndef __990_DK__
66#define __990_DK__
77
8#include "imagedev/flopdrv.h"
9
810extern const device_type FD800;
911
1012#define MAX_FLOPPIES 4
r29179r29180
5759
5860   struct
5961   {
60      device_image_interface *img;
62      legacy_floppy_image_device *img;
6163      int phys_cylinder;
6264      int log_cylinder[2];
6365      int seclen;
trunk/src/mess/machine/osborne1.c
r29179r29180
429429   memset( m_ram->pointer() + 0x10000, 0xFF, 0x1000 );
430430
431431   for(drive=0;drive<2;drive++)
432      floppy_install_load_proc(floppy_get_device(machine(), drive), osborne1_load_proc);
432      floppy_get_device(machine(), drive)->floppy_install_load_proc(osborne1_load_proc);
433433
434434   space.set_direct_update_handler(direct_update_delegate(FUNC(osborne1_state::osborne1_opbase), this));
435435}
trunk/src/mess/machine/rmnimbus.c
r29179r29180
22742274   wd2793_device *fdc = machine().device<wd2793_device>(FDC_TAG);
22752275
22762276   int pc=space.device().safe_pc();
2277   device_t *drive = machine().device(nimbus_wd17xx_interface.floppy_drive_tags[FDC_DRIVE()]);
2277   legacy_floppy_image_device *drive = machine().device<legacy_floppy_image_device>(nimbus_wd17xx_interface.floppy_drive_tags[FDC_DRIVE()]);
22782278
22792279   switch(offset*2)
22802280   {
r29179r29180
22942294      case 0x10 :
22952295         m_nimbus_drives.reg410_in &= ~FDC_BITS_410;
22962296         m_nimbus_drives.reg410_in |= (FDC_MOTOR() ? FDC_MOTOR_MASKI : 0x00);
2297         m_nimbus_drives.reg410_in |= (floppy_drive_get_flag_state(drive, FLOPPY_DRIVE_INDEX) ? 0x00 : FDC_INDEX_MASK);
2298         m_nimbus_drives.reg410_in |= (floppy_drive_get_flag_state(drive, FLOPPY_DRIVE_READY) ? FDC_READY_MASK : 0x00);
2297         m_nimbus_drives.reg410_in |= (drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX) ? 0x00 : FDC_INDEX_MASK);
2298         m_nimbus_drives.reg410_in |= (drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) ? FDC_READY_MASK : 0x00);
22992299
23002300         // Flip inverted bits
23012301         result=m_nimbus_drives.reg410_in ^ INV_BITS_410;
trunk/src/mess/machine/atarifdc.c
r29179r29180
1616#include "atarifdc.h"
1717#include "sound/pokey.h"
1818#include "machine/6821pia.h"
19#include "imagedev/flopdrv.h"
2019#include "formats/atari_dsk.h"
2120
2221#define VERBOSE_SERIAL  0
r29179r29180
746745   MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(atari_floppy_interface)
747746MACHINE_CONFIG_END
748747
749device_t *atari_fdc_device::atari_floppy_get_device_child(int drive)
748legacy_floppy_image_device *atari_fdc_device::atari_floppy_get_device_child(int drive)
750749{
751750   switch(drive) {
752      case 0 : return subdevice(FLOPPY_0);
753      case 1 : return subdevice(FLOPPY_1);
754      case 2 : return subdevice(FLOPPY_2);
755      case 3 : return subdevice(FLOPPY_3);
751      case 0 : return subdevice<legacy_floppy_image_device>(FLOPPY_0);
752      case 1 : return subdevice<legacy_floppy_image_device>(FLOPPY_1);
753      case 2 : return subdevice<legacy_floppy_image_device>(FLOPPY_2);
754      case 3 : return subdevice<legacy_floppy_image_device>(FLOPPY_3);
756755   }
757756   return NULL;
758757}
r29179r29180
786785
787786   for(id=0;id<4;id++)
788787   {
789      floppy_install_load_proc(atari_floppy_get_device_child(id), _atari_load_proc);
788      atari_floppy_get_device_child(id)->floppy_install_load_proc(_atari_load_proc);
790789   }
791790}
792791
trunk/src/mess/machine/atarifdc.h
r29179r29180
66#ifndef _ATARIFDC_H
77#define _ATARIFDC_H
88
9#include "imagedev/flopdrv.h"
10
911class atari_fdc_device : public device_t
1012{
1113public:
r29179r29180
2830   void add_serin(UINT8 data, int with_checksum);
2931   void a800_serial_command();
3032   void a800_serial_write();
31   device_t *atari_floppy_get_device_child(int drive);
33   legacy_floppy_image_device *atari_floppy_get_device_child(int drive);
3234
3335   struct atari_drive
3436   {
trunk/src/mess/machine/nes.c
r29179r29180
962962   m_fds_ram = auto_alloc_array_clear(machine(), UINT8, 0x8000);
963963   save_pointer(NAME(m_fds_ram), 0x8000);
964964
965   floppy_install_load_proc(floppy_get_device(machine(), 0), nes_load_proc);
966   floppy_install_unload_proc(floppy_get_device(machine(), 0), nes_unload_proc);
965   floppy_get_device(machine(), 0)->floppy_install_load_proc(nes_load_proc);
966   floppy_get_device(machine(), 0)->floppy_install_unload_proc(nes_unload_proc);
967967
968968   // setup alt input handlers for additional FC input devices
969969   address_space &space = machine().device<cpu_device>("maincpu")->space(AS_PROGRAM);
trunk/src/mess/machine/trs80.c
r29179r29180
527527   m_fdc->dden_w(!BIT(data, 7));
528528
529529   /* CLEAR_LINE means to turn motors on */
530   floppy_mon_w(floppy_get_device(machine(), 0), (data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
531   floppy_mon_w(floppy_get_device(machine(), 1), (data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
532   floppy_mon_w(floppy_get_device(machine(), 2), (data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
533   floppy_mon_w(floppy_get_device(machine(), 3), (data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
530   floppy_get_device(machine(), 0)->floppy_mon_w((data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
531   floppy_get_device(machine(), 1)->floppy_mon_w((data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
532   floppy_get_device(machine(), 2)->floppy_mon_w((data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
533   floppy_get_device(machine(), 3)->floppy_mon_w((data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
534534}
535535
536536WRITE8_MEMBER( trs80_state::sys80_f8_w )
r29179r29180
781781
782782   if (drive > 3)
783783   {   /* Turn motors off */
784      floppy_mon_w(floppy_get_device(machine(), 0), ASSERT_LINE);
785      floppy_mon_w(floppy_get_device(machine(), 1), ASSERT_LINE);
786      floppy_mon_w(floppy_get_device(machine(), 2), ASSERT_LINE);
787      floppy_mon_w(floppy_get_device(machine(), 3), ASSERT_LINE);
784      floppy_get_device(machine(), 0)->floppy_mon_w(ASSERT_LINE);
785      floppy_get_device(machine(), 1)->floppy_mon_w(ASSERT_LINE);
786      floppy_get_device(machine(), 2)->floppy_mon_w(ASSERT_LINE);
787      floppy_get_device(machine(), 3)->floppy_mon_w(ASSERT_LINE);
788788      return;
789789   }
790790
r29179r29180
792792   m_fdc->set_side(m_head);
793793
794794   /* Turn motors on */
795   floppy_mon_w(floppy_get_device(machine(), 0), CLEAR_LINE);
796   floppy_mon_w(floppy_get_device(machine(), 1), CLEAR_LINE);
797   floppy_mon_w(floppy_get_device(machine(), 2), CLEAR_LINE);
798   floppy_mon_w(floppy_get_device(machine(), 3), CLEAR_LINE);
795   floppy_get_device(machine(), 0)->floppy_mon_w(CLEAR_LINE);
796   floppy_get_device(machine(), 1)->floppy_mon_w(CLEAR_LINE);
797   floppy_get_device(machine(), 2)->floppy_mon_w(CLEAR_LINE);
798   floppy_get_device(machine(), 3)->floppy_mon_w(CLEAR_LINE);
799799}
800800
801801/*************************************
trunk/src/mess/machine/rx01.c
r29179r29180
1212
1313#include "emu.h"
1414#include "machine/rx01.h"
15#include "imagedev/flopdrv.h"
1615#include "formats/basicdsk.h"
1716
1817static LEGACY_FLOPPY_OPTIONS_START( rx01 )
r29179r29180
7473
7574void rx01_device::device_start()
7675{
77   m_image[0] = subdevice(FLOPPY_0);
78   m_image[1] = subdevice(FLOPPY_1);
76   m_image[0] = subdevice<legacy_floppy_image_device>(FLOPPY_0);
77   m_image[1] = subdevice<legacy_floppy_image_device>(FLOPPY_1);
7978}
8079
8180
r29179r29180
8786{
8887   for(int i=0;i<2;i++)
8988   {
90      floppy_mon_w(m_image[i], 0); // turn it on
91      floppy_drive_set_controller(m_image[i], this);
92      floppy_drive_set_rpm(m_image[i], 360.);
89      m_image[i]->floppy_mon_w(0); // turn it on
90      m_image[i]->floppy_drive_set_controller(this);
91      m_image[i]->floppy_drive_set_rpm(360.);
9392   }
9493   m_rxes = 0;
9594   m_rxcs = 0;
r29179r29180
128127   m_unit = BIT(data,4);
129128   m_interrupt = BIT(data,6);
130129
131   floppy_drive_set_ready_state(m_image[m_unit], 1,0);
130   m_image[m_unit]->floppy_drive_set_ready_state(1,0);
132131
133132
134133   if (BIT(data,14)) // Initialize
r29179r29180
164163         case 7: // Read Error Register
165164               m_state = RX01_COMPLETE;
166165               // set ready signal according to current drive status
167               m_rxes |= floppy_drive_get_flag_state(m_image[m_unit], FLOPPY_DRIVE_READY) << 7;
166               m_rxes |= m_image[m_unit]->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) << 7;
168167               break;
169168      }
170169   }
r29179r29180
195194void rx01_device::service_command()
196195{
197196   printf("service_command %d\n",m_state);
198   m_rxes |= floppy_drive_get_flag_state(m_image[m_unit], FLOPPY_DRIVE_READY) << 7;
197   m_rxes |= m_image[m_unit]->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) << 7;
199198   switch(m_state) {
200199      case RX01_FILL :
201200                  m_buffer[m_buf_pos] = m_rxdb & 0xff;
r29179r29180
241240
242241void rx01_device::position_head()
243242{
244   int cur_track = floppy_drive_get_current_track(m_image[m_unit]);
243   int cur_track = m_image[m_unit]->floppy_drive_get_current_track();
245244   int dir = (cur_track < m_rxta) ? +1 : -1;
246245
247246   while (m_rxta != cur_track)
248247   {
249248      cur_track += dir;
250249
251      floppy_drive_seek(m_image[m_unit], dir);
250      m_image[m_unit]->floppy_drive_seek(dir);
252251   }
253252}
254253
255254void rx01_device::read_sector()
256255{
257256   /* read data */
258   floppy_drive_read_sector_data(m_image[m_unit], 0, m_rxsa, (char *)m_buffer, 128);
257   m_image[m_unit]->floppy_drive_read_sector_data(0, m_rxsa, (char *)m_buffer, 128);
259258}
260259
261260void rx01_device::write_sector(int ddam)
262261{
263262   /* write data */
264   floppy_drive_write_sector_data(m_image[m_unit], 0, m_rxsa, (char *)m_buffer, 128, ddam);
263   m_image[m_unit]->floppy_drive_write_sector_data(0, m_rxsa, (char *)m_buffer, 128, ddam);
265264}
trunk/src/mess/machine/rx01.h
r29179r29180
99#ifndef __RX01__
1010#define __RX01__
1111
12#include "imagedev/flopdrv.h"
13
1214//**************************************************************************
1315//  INTERFACE CONFIGURATION MACROS
1416//**************************************************************************
r29179r29180
6163      RX01_INIT
6264   };
6365
64   device_t *m_image[2];
66   legacy_floppy_image_device *m_image[2];
6567   UINT8 m_buffer[128];
6668   int m_buf_pos;
6769
trunk/src/mess/machine/micropolis.c
r29179r29180
2828
2929
3030#include "emu.h"
31#include "imagedev/flopdrv.h"
3231#include "machine/micropolis.h"
3332
3433
r29179r29180
162161   {
163162      if(m_floppy_drive_tags[i])
164163      {
165         device_t *img = NULL;
164         legacy_floppy_image_device *img = NULL;
166165
167         img = siblingdevice(m_floppy_drive_tags[i]);
166         img = siblingdevice<legacy_floppy_image_device>(m_floppy_drive_tags[i]);
168167
169168         if (img)
170169         {
171            floppy_drive_set_controller(img, this);
172            //floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback);
173            floppy_drive_set_rpm( img, 300.);
170            img->floppy_drive_set_controller(this);
171            //img->floppy_drive_set_index_pulse_callback( wd17xx_index_pulse_callback);
172            img->floppy_drive_set_rpm( 300.);
174173         }
175174      }
176175   }
r29179r29180
197196   m_data_count = m_sector_length;
198197
199198   /* read data */
200   floppy_drive_read_sector_data(m_drive, 0, m_sector, (char *)m_buffer, m_sector_length);
199   m_drive->floppy_drive_read_sector_data(0, m_sector, (char *)m_buffer, m_sector_length);
201200}
202201
203202
r29179r29180
213212   m_data_count = m_sector_length;
214213
215214   /* write data */
216   floppy_drive_write_sector_data(m_drive, 0, m_sector, (char *)m_buffer, m_sector_length, m_write_cmd & 0x01);
215   m_drive->floppy_drive_write_sector_data(0, m_sector, (char *)m_buffer, m_sector_length, m_write_cmd & 0x01);
217216#endif
218217}
219218
r29179r29180
231230      logerror("micropolis_set_drive: $%02x\n", drive);
232231
233232   if (m_floppy_drive_tags[drive])
234      m_drive = siblingdevice(m_floppy_drive_tags[drive]);
233      m_drive = siblingdevice<legacy_floppy_image_device>(m_floppy_drive_tags[drive]);
235234}
236235
237236
r29179r29180
287286   {
288287   case 1:
289288      m_drive_num = data & 3;
290      floppy_mon_w(m_drive, 1); // turn off the old drive
289      m_drive->floppy_mon_w(1); // turn off the old drive
291290      set_drive(m_drive_num); // select new drive
292      floppy_mon_w(m_drive, 0); // turn it on
291      m_drive->floppy_mon_w(0); // turn it on
293292      break;
294293   case 2:  // not emulated, not used in sorcerer
295294      break;
r29179r29180
323322   if (BIT(data, 5))
324323      m_status |= STAT_READY;
325324
326   floppy_drive_set_ready_state(m_drive, 1,0);
325   m_drive->floppy_drive_set_ready_state(1,0);
327326
328327
329328   if (!m_track)
330329      m_status |= STAT_TRACK0;
331330
332   floppy_drive_seek(m_drive, direction);
331   m_drive->floppy_drive_seek(direction);
333332}
334333
335334
trunk/src/mess/machine/appldriv.c
r29179r29180
2727
2828static int apple525_enable_mask = 1;
2929
30device_t *apple525_get_subdevice(device_t *device, int drive)
30legacy_floppy_image_device *apple525_get_subdevice(device_t *device, int drive)
3131{
3232   switch(drive) {
33      case 0 : return device->subdevice(PARENT_FLOPPY_0);
34      case 1 : return device->subdevice(PARENT_FLOPPY_1);
35      case 2 : return device->subdevice(PARENT_FLOPPY_2);
36      case 3 : return device->subdevice(PARENT_FLOPPY_3);
33      case 0 : return device->subdevice<legacy_floppy_image_device>(PARENT_FLOPPY_0);
34      case 1 : return device->subdevice<legacy_floppy_image_device>(PARENT_FLOPPY_1);
35      case 2 : return device->subdevice<legacy_floppy_image_device>(PARENT_FLOPPY_2);
36      case 3 : return device->subdevice<legacy_floppy_image_device>(PARENT_FLOPPY_3);
3737   }
3838   return NULL;
3939}
r29179r29180
4343   int i;
4444   int cnt = 0;
4545   for (i=0;i<4;i++) {
46      device_t *disk = apple525_get_subdevice(device, i);
47      if (floppy_get_drive_type(disk)==ftype) {
46      legacy_floppy_image_device *disk = apple525_get_subdevice(device, i);
47      if (disk->floppy_get_drive_type()==ftype) {
4848         if (cnt==drive) {
4949            return disk;
5050         }
r29179r29180
6969   disk = get_device(image);
7070   len = sizeof(disk->track_data);
7171
72   floppy_drive_read_track_data_info_buffer(image, 0, disk->track_data, &len);
72   disk->floppy_drive_read_track_data_info_buffer(0, disk->track_data, &len);
7373   disk->track_loaded = 1;
7474   disk->track_dirty = 0;
7575}
r29179r29180
8484   if (disk->track_dirty)
8585   {
8686      len = sizeof(disk->track_data);
87      floppy_drive_write_track_data_info_buffer(image, 0, disk->track_data, &len);
87      disk->floppy_drive_write_track_data_info_buffer(0, disk->track_data, &len);
8888      disk->track_dirty = 0;
8989   }
9090   if (unload)
9191      disk->track_loaded = 0;
9292}
9393
94static void apple525_seek_disk(device_t *img, signed int step)
94static void apple525_seek_disk(apple525_floppy_image_device *img, signed int step)
9595{
9696   int track;
9797   int pseudo_track;
r29179r29180
101101
102102   apple525_save_current_track(img, FALSE);
103103
104   track = floppy_drive_get_current_track(img);
104   track = img->floppy_drive_get_current_track();
105105   pseudo_track = (track * 2) + disk->tween_tracks;
106106
107107   pseudo_track += step;
r29179r29180
112112
113113   if (pseudo_track/2 != track)
114114   {
115      floppy_drive_seek(img, pseudo_track/2 - floppy_drive_get_current_track(img));
115      img->floppy_drive_seek(pseudo_track/2 - img->floppy_drive_get_current_track());
116116      disk->track_loaded = 0;
117117   }
118118
r29179r29180
144144         case 8: phase = 3; break;
145145      }
146146
147      phase -= floppy_drive_get_current_track(image) * 2;
147      phase -= cur_disk->floppy_drive_get_current_track() * 2;
148148      if (cur_disk->tween_tracks)
149149         phase--;
150150      phase %= 4;
r29179r29180
152152      switch(phase)
153153      {
154154         case 1:
155            apple525_seek_disk(image, +1);
155            apple525_seek_disk(cur_disk, +1);
156156            break;
157157         case 3:
158            apple525_seek_disk(image, -1);
158            apple525_seek_disk(cur_disk, -1);
159159            break;
160160      }
161161   }
r29179r29180
164164int apple525_get_count(device_t *device)
165165{
166166   int cnt = 0;
167   if ((device->subdevice("^"FLOPPY_0)!=NULL) && (floppy_get_drive_type(device->subdevice("^"FLOPPY_0)) == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_0))!=NULL)) cnt++;
168   if ((device->subdevice("^"FLOPPY_1)!=NULL) && (floppy_get_drive_type(device->subdevice("^"FLOPPY_1)) == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_1))!=NULL)) cnt++;
169   if ((device->subdevice("^"FLOPPY_2)!=NULL) && (floppy_get_drive_type(device->subdevice("^"FLOPPY_2)) == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_2))!=NULL)) cnt++;
170   if ((device->subdevice("^"FLOPPY_3)!=NULL) && (floppy_get_drive_type(device->subdevice("^"FLOPPY_3)) == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_3))!=NULL)) cnt++;
167   if ((device->subdevice("^"FLOPPY_0)!=NULL) && (device->subdevice<legacy_floppy_image_device>("^"FLOPPY_0)->floppy_get_drive_type() == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_0))!=NULL)) cnt++;
168   if ((device->subdevice("^"FLOPPY_1)!=NULL) && (device->subdevice<legacy_floppy_image_device>("^"FLOPPY_1)->floppy_get_drive_type() == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_1))!=NULL)) cnt++;
169   if ((device->subdevice("^"FLOPPY_2)!=NULL) && (device->subdevice<legacy_floppy_image_device>("^"FLOPPY_2)->floppy_get_drive_type() == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_2))!=NULL)) cnt++;
170   if ((device->subdevice("^"FLOPPY_3)!=NULL) && (device->subdevice<legacy_floppy_image_device>("^"FLOPPY_3)->floppy_get_drive_type() == FLOPPY_TYPE_APPLE) && (get_device(device->subdevice(PARENT_FLOPPY_3))!=NULL)) cnt++;
171171
172172   return cnt;
173173}
r29179r29180
307307void apple525_floppy_image_device::device_start()
308308{
309309   legacy_floppy_image_device::device_start();
310   floppy_set_type(this,FLOPPY_TYPE_APPLE);
310   floppy_set_type(FLOPPY_TYPE_APPLE);
311311
312312   state = 0;
313313   tween_tracks = 0;
r29179r29180
321321bool apple525_floppy_image_device::call_load()
322322{
323323   int result = legacy_floppy_image_device::call_load();
324   floppy_drive_seek(*this, -999);
325   floppy_drive_seek(*this, +35/2);
324   floppy_drive_seek(-999);
325   floppy_drive_seek(+35/2);
326326   return result;
327327}
328328
trunk/src/mess/machine/micropolis.h
r29179r29180
1111#define __MICROPOLIS_H__
1212
1313#include "devcb.h"
14#include "imagedev/flopdrv.h"
1415
1516
1617/***************************************************************************
r29179r29180
8889   UINT32  m_sector_length;          /* sector length (byte) */
8990
9091   /* this is the drive currently selected */
91   device_t *m_drive;
92   legacy_floppy_image_device *m_drive;
9293
9394   void read_sector();
9495   void write_sector();
trunk/src/mess/machine/partner.c
r29179r29180
100100         default   : m_fdc->data_w(space, 0,data);break;
101101      }
102102   } else {
103      floppy_mon_w(floppy_get_device(machine(), 0), 1);
104      floppy_mon_w(floppy_get_device(machine(), 1), 1);
103      floppy_get_device(machine(), 0)->floppy_mon_w(1);
104      floppy_get_device(machine(), 1)->floppy_mon_w(1);
105105      if (((data >> 6) & 1)==1) {
106106         m_fdc->set_drive(0);
107         floppy_mon_w(floppy_get_device(machine(), 0), 0);
108         floppy_drive_set_ready_state(floppy_get_device(machine(), 0), 1, 1);
107         floppy_get_device(machine(), 0)->floppy_mon_w(0);
108         floppy_get_device(machine(), 0)->floppy_drive_set_ready_state(1, 1);
109109      }
110110      if (((data >> 3) & 1)==1) {
111111         m_fdc->set_drive(1);
112         floppy_mon_w(floppy_get_device(machine(), 1), 0);
113         floppy_drive_set_ready_state(floppy_get_device(machine(), 1), 1, 1);
112         floppy_get_device(machine(), 1)->floppy_mon_w(0);
113         floppy_get_device(machine(), 1)->floppy_drive_set_ready_state(1, 1);
114114      }
115115      m_fdc->set_side(data >> 7);
116116   }
trunk/src/mess/machine/hec2hrp.c
r29179r29180
107107   fdc->dden_w(1);// density select => always 1 (0 ?a plante !)
108108
109109   /* FDC Motor Control - Bit 0/1 defines the state of the FDD 0/1 motor */
110   floppy_mon_w(floppy_get_device(machine(), 0), 0); // Moteur floppy A:
111   //floppy_mon_w(floppy_get_device(space.machine(), 1), BIT(data, 7));   // Moteur floppy B:, not implanted on the real machine
110   floppy_get_device(machine(), 0)->floppy_mon_w( 0); // Moteur floppy A:
111   //floppy_get_device(machine(), 1)->floppy_mon_w(BIT(data, 7));   // Moteur floppy B:, not implanted on the real machine
112112
113113   //Set the drive ready !
114   floppy_drive_set_ready_state(floppy_get_device(machine(), 0), FLOPPY_DRIVE_READY, 0);// Disc 0 ready !
114   floppy_get_device(machine(), 0)->floppy_drive_set_ready_state(FLOPPY_DRIVE_READY, 0);// Disc 0 ready !
115115
116116}
117117
trunk/src/mess/machine/svi318.c
r29179r29180
564564
565565   for(drive=0;drive<2;drive++)
566566   {
567      floppy_install_load_proc(floppy_get_device(machine(), drive), svi318_load_proc);
567      floppy_get_device(machine(), drive)->floppy_install_load_proc(svi318_load_proc);
568568   }
569569}
570570
trunk/src/mess/includes/thomson.h
r29179r29180
304304   WRITE_LINE_MEMBER( fdc_index_1_w );
305305   WRITE_LINE_MEMBER( fdc_index_2_w );
306306   WRITE_LINE_MEMBER( fdc_index_3_w );
307   void thomson_index_callback(device_t *device, int state);
307   void thomson_index_callback(legacy_floppy_image_device *device, int state);
308308   DECLARE_PALETTE_INIT(thom);
309309   
310310   optional_device<mc6854_device> m_mc6854;
r29179r29180
519519   unsigned to7_lightpen_gpl( int decx, int decy );
520520
521521   int thom_floppy_make_addr( chrn_id id, UINT8* dst, int sector_size );
522   int thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size );
523   int thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side );
522   int thom_floppy_make_sector( legacy_floppy_image_device* img, chrn_id id, UINT8* dst, int sector_size );
523   int thom_floppy_make_track( legacy_floppy_image_device* img, UINT8* dst, int sector_size, int side );
524524   int thom_qdd_make_addr( int sector, UINT8* dst );
525   int thom_qdd_make_sector( device_t* img, int sector, UINT8* dst );
526   int thom_qdd_make_disk ( device_t* img, UINT8* dst );
525   int thom_qdd_make_sector( legacy_floppy_image_device* img, int sector, UINT8* dst );
526   int thom_qdd_make_disk ( legacy_floppy_image_device* img, UINT8* dst );
527527   void to7_5p14_reset();
528528   void to7_5p14_init();
529   void to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state );
529   void to7_5p14_index_pulse_callback( device_t *controller,legacy_floppy_image_device *image, int state );
530530   void to7_5p14sd_reset();
531531   void to7_5p14sd_init();
532   void to7_qdd_index_pulse_cb( device_t *controller,device_t *image, int state );
533   device_t * to7_qdd_image();
532   void to7_qdd_index_pulse_cb( device_t *controller,legacy_floppy_image_device *image, int state );
533   legacy_floppy_image_device * to7_qdd_image();
534534   void to7_qdd_stat_update();
535535   UINT8 to7_qdd_read_byte();
536536   void to7_qdd_write_byte( UINT8 data );
537537   void to7_qdd_reset();
538538   void to7_qdd_init();
539   device_t * thmfc_floppy_image();
540   int thmfc_floppy_is_qdd( device_image_interface *image );
541   void thmfc_floppy_index_pulse_cb( device_t *controller,device_t *image, int state );
539   legacy_floppy_image_device * thmfc_floppy_image();
540   int thmfc_floppy_is_qdd( legacy_floppy_image_device *image );
541   void thmfc_floppy_index_pulse_cb( device_t *controller,legacy_floppy_image_device *image, int state );
542542   int thmfc_floppy_find_sector( chrn_id* dst );
543543   void thmfc_floppy_cmd_complete();
544544   UINT8 thmfc_floppy_read_byte();
trunk/src/emu/bus/ieee488/c8050.c
r29179r29180
618618   UINT8 data = 0;
619619
620620   // write protect sense
621   data |= floppy_wpt_r(m_unit[m_drive].m_image) << 3;
621   data |= m_unit[m_drive].m_image->floppy_wpt_r() << 3;
622622
623623   // drive type
624624   data |= 0x10;
r29179r29180
10171017   m_bit_count = 0;
10181018
10191019   // read track data
1020   floppy_drive_read_track_data_info_buffer(m_unit[unit].m_image, m_side, m_unit[unit].m_track_buffer, &m_unit[unit].m_track_len);
1020   m_unit[unit].m_image->floppy_drive_read_track_data_info_buffer(m_side, m_unit[unit].m_track_buffer, &m_unit[unit].m_track_len);
10211021
10221022   // extract track length
1023   m_unit[unit].m_track_len = floppy_drive_get_current_track_size(m_unit[unit].m_image, m_side);
1023   m_unit[unit].m_track_len = m_unit[unit].m_image->floppy_drive_get_current_track_size(m_side);
10241024}
10251025
10261026
r29179r29180
10381038         read_current_track(unit);
10391039      }
10401040
1041      floppy_mon_w(m_unit[unit].m_image, mtr);
1041      m_unit[unit].m_image->floppy_mon_w(mtr);
10421042
10431043      m_unit[unit].m_mtr = mtr;
10441044   }
r29179r29180
10661066      if (tracks != 0)
10671067      {
10681068         // step read/write head
1069         floppy_drive_seek(m_unit[unit].m_image, tracks);
1069         m_unit[unit].m_image->floppy_drive_seek(tracks);
10701070
10711071         // read new track data
10721072         read_current_track(unit);
r29179r29180
11991199   // install image callbacks
12001200   m_unit[0].m_image = m_image0;
12011201
1202   floppy_install_load_proc(m_image0, c8050_device::on_disk0_change);
1202   m_image0->floppy_install_load_proc(c8050_device::on_disk0_change);
12031203
12041204   if (m_image1)
12051205   {
12061206      m_unit[1].m_image = m_image1;
12071207
1208      floppy_install_load_proc(m_image1, c8050_device::on_disk1_change);
1208      m_image1->floppy_install_load_proc(c8050_device::on_disk1_change);
12091209   }
12101210
12111211   // register for state saving
trunk/src/emu/bus/ieee488/c8050.h
r29179r29180
125125      int m_bit_pos;                          // bit position within track buffer byte
126126
127127      // devices
128      device_t *m_image;
128      legacy_floppy_image_device *m_image;
129129   } m_unit[2];
130130
131131   int m_drive;                        // selected drive
trunk/src/emu/bus/coco/coco_fdc.c
r29179r29180
299299   else if (data & 0x40)
300300      drive = 3;
301301
302   device_t *floppy[4];
302   legacy_floppy_image_device *floppy[4];
303303
304   floppy[0] = subdevice(FLOPPY_0);
305   floppy[1] = subdevice(FLOPPY_1);
306   floppy[2] = subdevice(FLOPPY_2);
307   floppy[3] = subdevice(FLOPPY_3);
304   floppy[0] = subdevice<legacy_floppy_image_device>(FLOPPY_0);
305   floppy[1] = subdevice<legacy_floppy_image_device>(FLOPPY_1);
306   floppy[2] = subdevice<legacy_floppy_image_device>(FLOPPY_2);
307   floppy[3] = subdevice<legacy_floppy_image_device>(FLOPPY_3);
308308
309309   for (int i = 0; i < 4; i++)
310310   {
311      floppy_mon_w(floppy[i], i == drive ? CLEAR_LINE : ASSERT_LINE);
311      floppy[i]->floppy_mon_w(i == drive ? CLEAR_LINE : ASSERT_LINE);
312312   }
313313
314314   head = ((data & 0x40) && (drive != 3)) ? 1 : 0;
trunk/src/emu/bus/bml3/bml3mp1802.c
r29179r29180
110110      floppy_name = FLOPPY_3;
111111      break;
112112   }
113   device_t *floppy = subdevice(floppy_name);
113   legacy_floppy_image_device *floppy = subdevice<legacy_floppy_image_device>(floppy_name);
114114   m_wd17xx->set_drive(drive);
115   floppy_mon_w(floppy, !motor);
116   floppy_drive_set_ready_state(floppy, ASSERT_LINE, 0);
115   floppy->floppy_mon_w(!motor);
116   floppy->floppy_drive_set_ready_state(ASSERT_LINE, 0);
117117   m_wd17xx->set_side(side);
118118}
119119
trunk/src/emu/bus/bml3/bml3mp1805.c
r29179r29180
128128      floppy_name = FLOPPY_3;
129129      break;
130130   }
131   device_t *floppy = subdevice(floppy_name);
131   legacy_floppy_image_device *floppy = subdevice<legacy_floppy_image_device>(floppy_name);
132132   m_mc6843->set_drive(drive);
133   floppy_mon_w(floppy, motor);
134   floppy_drive_set_ready_state(floppy, ASSERT_LINE, 0);
133   floppy->floppy_mon_w(motor);
134   floppy->floppy_drive_set_ready_state(ASSERT_LINE, 0);
135135   m_mc6843->set_side(side);
136136}
137137
trunk/src/emu/bus/ti99_peb/ti_fdc.h
r29179r29180
146146private:
147147   void set_ready_line();
148148   void set_all_geometries(floppy_type_t type);
149   void set_geometry(device_t *drive, floppy_type_t type);
149   void set_geometry(legacy_floppy_image_device *drive, floppy_type_t type);
150150
151151   // Recent address
152152   int             m_address;
trunk/src/emu/bus/ti99_peb/hfdc.c
r29179r29180
304304      if (index==-1) return 0;
305305
306306      /* Get floppy status. */
307      if (floppy_drive_get_flag_state(m_floppy_unit[index], FLOPPY_DRIVE_INDEX) == FLOPPY_DRIVE_INDEX)
307      if (m_floppy_unit[index]->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX) == FLOPPY_DRIVE_INDEX)
308308         reply |= DS_INDEX;
309      if (floppy_tk00_r(m_floppy_unit[index]) == CLEAR_LINE)
309      if (m_floppy_unit[index]->floppy_tk00_r() == CLEAR_LINE)
310310         reply |= DS_TRK00;
311      if (floppy_wpt_r(m_floppy_unit[index]) == CLEAR_LINE)
311      if (m_floppy_unit[index]->floppy_wpt_r() == CLEAR_LINE)
312312         reply |= DS_WRPROT;
313313
314314      /* if (image_exists(disk_img)) */
r29179r29180
321321   {
322322      UINT8 state;
323323      index = slog2((m_output1_latch>>4) & 0x0f)-1;
324      mfm_harddisk_device *hd = static_cast<mfm_harddisk_device *>(m_harddisk_unit[index]);
324      mfm_harddisk_device *hd = m_harddisk_unit[index];
325325      state = hd->get_status();
326326
327327      if (state & MFMHD_TRACK00)      reply |= DS_TRK00;
r29179r29180
338338WRITE8_MEMBER( myarc_hfdc_device::auxbus_out )
339339{
340340   int index;
341   device_t* selected_drive = NULL;
342
343341   switch (offset)
344342   {
345343   case INPUT_STATUS:
r29179r29180
363361      {
364362         // Floppy selected
365363         index = slog2(data & 0x0f);
366         if (index>=0) selected_drive = m_floppy_unit[index];
364         if (index>=0) m_hdc9234->connect_floppy_drive(m_floppy_unit[index]);
367365      }
368366      else
369367      {
370368         // HD selected
371369         index = slog2((data>>4) & 0x0f);
372         if (index>=0) selected_drive = m_harddisk_unit[index-1];
370         if (index>=0) m_hdc9234->connect_hard_drive(m_harddisk_unit[index-1]);
373371      }
374372
375      m_hdc9234->connect_drive(selected_drive);
376373      m_output1_latch = data;
377374      break;
378375
r29179r29180
536533   m_selected = false;
537534
538535   // Find the floppies and hard disks
539   m_floppy_unit[0] = m_slot->get_drive(FLOPPY_0);
540   m_floppy_unit[1] = m_slot->get_drive(FLOPPY_1);
541   m_floppy_unit[2] = m_slot->get_drive(FLOPPY_2);
542   m_floppy_unit[3] = m_slot->get_drive(FLOPPY_3);
536   m_floppy_unit[0] = static_cast<legacy_floppy_image_device *>(m_slot->get_drive(FLOPPY_0));
537   m_floppy_unit[1] = static_cast<legacy_floppy_image_device *>(m_slot->get_drive(FLOPPY_1));
538   m_floppy_unit[2] = static_cast<legacy_floppy_image_device *>(m_slot->get_drive(FLOPPY_2));
539   m_floppy_unit[3] = static_cast<legacy_floppy_image_device *>(m_slot->get_drive(FLOPPY_3));
543540
544   m_harddisk_unit[0] = m_slot->get_drive(MFMHD_0);
545   m_harddisk_unit[1] = m_slot->get_drive(MFMHD_1);
546   m_harddisk_unit[2] = m_slot->get_drive(MFMHD_2);
541   m_harddisk_unit[0] = static_cast<mfm_harddisk_device *>(m_slot->get_drive(MFMHD_0));
542   m_harddisk_unit[1] = static_cast<mfm_harddisk_device *>(m_slot->get_drive(MFMHD_1));
543   m_harddisk_unit[2] = static_cast<mfm_harddisk_device *>(m_slot->get_drive(MFMHD_2));
547544
548545   if (ioport("HFDCDIP")->read()&0x55)
549546      ti99_set_80_track_drives(TRUE);
r29179r29180
560557      {
561558         //  floppy_drive_set_controller(card->floppy_unit[i], device);
562559         //  floppy_drive_set_index_pulse_callback(floppy_unit[i], smc92x4_index_pulse_callback);
563         floppy_drive_set_geometry(m_floppy_unit[i], floptype);
560         m_floppy_unit[i]->floppy_drive_set_geometry(floptype);
564561      }
565562   }
566563
trunk/src/emu/bus/ti99_peb/hfdc.h
r29179r29180
9393   UINT8           m_output2_latch;
9494
9595   /* Connected floppy drives. */
96   device_t*       m_floppy_unit[HFDC_MAX_FLOPPY];
96   legacy_floppy_image_device*       m_floppy_unit[HFDC_MAX_FLOPPY];
9797
9898   /* Connected harddisk drives. */
99   device_t*       m_harddisk_unit[HFDC_MAX_HARD];
99   mfm_harddisk_device*       m_harddisk_unit[HFDC_MAX_HARD];
100100
101101   /* DMA address latch */
102102   UINT32          m_dma_address;
trunk/src/emu/bus/ti99_peb/peribox.c
r29179r29180
394394{
395395   if (TRACE_EMU) logerror("Peribox started\n");
396396
397   floppy_drive_set_rpm(subdevice(FLOPPY_0), 300.);
398   floppy_drive_set_rpm(subdevice(FLOPPY_1), 300.);
399   floppy_drive_set_rpm(subdevice(FLOPPY_2), 300.);
400   floppy_drive_set_rpm(subdevice(FLOPPY_3), 300.);
397   subdevice<legacy_floppy_image_device>(FLOPPY_0)->floppy_drive_set_rpm(300.);
398   subdevice<legacy_floppy_image_device>(FLOPPY_1)->floppy_drive_set_rpm(300.);
399   subdevice<legacy_floppy_image_device>(FLOPPY_2)->floppy_drive_set_rpm(300.);
400   subdevice<legacy_floppy_image_device>(FLOPPY_3)->floppy_drive_set_rpm(300.);
401401
402402   // Resolve the callback lines to the console
403403   m_console_inta.resolve();
trunk/src/emu/bus/ti99_peb/bwg.c
r29179r29180
839839    the default implementation sets the drive geometry to the geometry
840840    of the medium.
841841*/
842void snug_bwg_legacy_device::set_geometry(device_t *drive, floppy_type_t type)
842void snug_bwg_legacy_device::set_geometry(legacy_floppy_image_device *drive, floppy_type_t type)
843843{
844844   // This assertion may fail when the names of the floppy devices change.
845845   // Unfortunately, the wd17xx device assumes the floppy drives at root
846846   // level, so we use an explicitly qualified tag. See peribox.h.
847847   assert(drive != NULL);
848   floppy_drive_set_geometry(drive, type);
848   drive->floppy_drive_set_geometry(type);
849849}
850850
851851void snug_bwg_legacy_device::set_all_geometries(floppy_type_t type)
852852{
853   set_geometry(machine().device(PFLOPPY_0), type);
854   set_geometry(machine().device(PFLOPPY_1), type);
855   set_geometry(machine().device(PFLOPPY_2), type);
853   set_geometry(machine().device<legacy_floppy_image_device>(PFLOPPY_0), type);
854   set_geometry(machine().device<legacy_floppy_image_device>(PFLOPPY_1), type);
855   set_geometry(machine().device<legacy_floppy_image_device>(PFLOPPY_2), type);
856856}
857857
858858/*
trunk/src/emu/bus/ti99_peb/bwg.h
r29179r29180
173173private:
174174   void set_ready_line();
175175   void set_all_geometries(floppy_type_t type);
176   void set_geometry(device_t *drive, floppy_type_t type);
176   void set_geometry(legacy_floppy_image_device *drive, floppy_type_t type);
177177   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
178178
179179   // Holds the status of the DRQ and IRQ lines.
trunk/src/emu/bus/ti99_peb/ti_fdc.c
r29179r29180
648648    the default implementation sets the drive geometry to the geometry
649649    of the medium.
650650*/
651void ti_fdc_legacy_device::set_geometry(device_t *drive, floppy_type_t type)
651void ti_fdc_legacy_device::set_geometry(legacy_floppy_image_device *drive, floppy_type_t type)
652652{
653653   // This assertion may fail when the names of the floppy devices change.
654654   // Unfortunately, the wd17xx device assumes the floppy drives at root
655655   // level, so we use an explicitly qualified tag. See peribox.h.
656656   assert (drive!=NULL);
657   floppy_drive_set_geometry(drive, type);
657   drive->floppy_drive_set_geometry(type);
658658}
659659
660660void ti_fdc_legacy_device::set_all_geometries(floppy_type_t type)
661661{
662   set_geometry(machine().device(PFLOPPY_0), type);
663   set_geometry(machine().device(PFLOPPY_1), type);
664   set_geometry(machine().device(PFLOPPY_2), type);
662   set_geometry(machine().device<legacy_floppy_image_device>(PFLOPPY_0), type);
663   set_geometry(machine().device<legacy_floppy_image_device>(PFLOPPY_1), type);
664   set_geometry(machine().device<legacy_floppy_image_device>(PFLOPPY_2), type);
665665}
666666
667667/*
trunk/src/emu/machine/wd17xx.c
r29179r29180
154154#include "emu.h"
155155#include "formats/imageutl.h"
156156#include "machine/wd17xx.h"
157#include "imagedev/flopdrv.h"
158157
159158/***************************************************************************
160159    CONSTANTS
r29179r29180
494493   if (1) // image_slotexists(m_drive) : FIXME
495494   {
496495      /* keep stepping until track 0 is received or 255 steps have been done */
497      while (floppy_tk00_r(m_drive) && (step_counter != 0))
496      while (m_drive->floppy_tk00_r() && (step_counter != 0))
498497      {
499498         /* update time to simulate seek time busy signal */
500499         m_busy_count++;
501         floppy_drive_seek(m_drive, m_direction);
500         m_drive->floppy_drive_seek(m_direction);
502501         step_counter--;
503502      }
504503   }
r29179r29180
539538         //int len     = m_buffer[i+4];
540539         int filler  = 0xe5; /* IBM and Thomson */
541540         int density = m_density;
542         floppy_drive_format_sector(m_drive,side,sector,track,
541         m_drive->floppy_drive_format_sector(side,sector,track,
543542                  m_hd,sector,density?1:0,filler);
544543         i += 128; /* at least... */
545544      }
r29179r29180
556555   selected format.
557556   */
558557   m_data_count = 0;
559   floppy = flopimg_get_image(m_drive);
558   floppy = m_drive->flopimg_get_image();
560559   if (floppy != NULL)
561560      m_data_count = floppy_get_track_size(floppy, m_hd, m_track);
562561
r29179r29180
568567            m_data_count = wd17xx_dden() ? TRKSIZE_SD : TRKSIZE_DD;
569568      }
570569
571   floppy_drive_write_track_data_info_buffer( m_drive, m_hd, (char *)m_buffer, &(m_data_count) );
570   m_drive->floppy_drive_write_track_data_info_buffer( m_hd, (char *)m_buffer, &(m_data_count) );
572571
573572   m_data_offset = 0;
574573
r29179r29180
707706   /* Determine the track size. We cannot allow different sizes in this
708707   design (see above, write_track). */
709708   m_data_count = 0;
710   floppy = flopimg_get_image(m_drive);
709   floppy = m_drive->flopimg_get_image();
711710   if (floppy != NULL)
712711      m_data_count = floppy_get_track_size(floppy, m_hd, m_track);
713712
r29179r29180
719718            m_data_count = wd17xx_dden() ? TRKSIZE_SD : TRKSIZE_DD;
720719      }
721720
722   floppy_drive_read_track_data_info_buffer( m_drive, m_hd, (char *)m_buffer, &(m_data_count) );
721   m_drive->floppy_drive_read_track_data_info_buffer( m_hd, (char *)m_buffer, &(m_data_count) );
723722
724723   m_data_offset = 0;
725724
r29179r29180
736735   m_status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND);
737736
738737   /* get next id from disc */
739   if (floppy_drive_get_next_id(m_drive, m_hd, &id))
738   if (m_drive->floppy_drive_get_next_id(m_hd, &id))
740739   {
741740      UINT16 crc = 0xffff;
742741
r29179r29180
809808
810809   while (revolution_count!=4)
811810   {
812      if (floppy_drive_get_next_id(m_drive, m_hd, &id))
811      if (m_drive->floppy_drive_get_next_id(m_hd, &id))
813812      {
814813         /* compare track */
815814         if (id.C == m_track)
r29179r29180
834833      }
835834
836835         /* index set? */
837      if (floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_INDEX))
836      if (m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX))
838837      {
839838         /* update revolution count */
840839         revolution_count++;
r29179r29180
886885      m_data_count = m_sector_length;
887886
888887      /* read data */
889      floppy_drive_read_sector_data(m_drive, m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length);
888      m_drive->floppy_drive_read_sector_data(m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length);
890889
891890      wd17xx_timed_data_request();
892891
r29179r29180
936935      m_data_count = m_sector_length;
937936
938937      /* write data */
939      floppy_drive_write_sector_data(m_drive, m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length, m_write_cmd & 0x01);
938      m_drive->floppy_drive_write_sector_data(m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length, m_write_cmd & 0x01);
940939   }
941940}
942941
r29179r29180
957956   /* must be found within 5 revolutions otherwise error */
958957   while (revolution_count!=5)
959958   {
960      if (floppy_drive_get_next_id(m_drive, m_hd, &id))
959      if (m_drive->floppy_drive_get_next_id( m_hd, &id))
961960      {
962961         /* compare track */
963962         if (id.C == m_track)
r29179r29180
969968      }
970969
971970         /* index set? */
972      if (floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_INDEX))
971      if (m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX))
973972      {
974973         /* update revolution count */
975974         revolution_count++;
r29179r29180
992991   if (VERBOSE)
993992      logerror("wd179x: Read Sector callback.\n");
994993
995   if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY))
994   if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
996995      wd17xx_complete_command(DELAY_NOTREADY);
997996   else
998997      wd17xx_read_sector();
r29179r29180
10081007   if (VERBOSE)
10091008      logerror("wd179x: Write Sector callback.\n");
10101009
1011   if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY))
1010   if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
10121011      wd17xx_complete_command(DELAY_NOTREADY);
10131012   else
10141013   {
10151014      /* drive write protected? */
1016      if (floppy_wpt_r(m_drive) == CLEAR_LINE)
1015      if (m_drive->floppy_wpt_r() == CLEAR_LINE)
10171016      {
10181017         m_status |= STA_2_WRITE_PRO;
10191018
r29179r29180
10801079
10811080   if (m_intf->floppy_drive_tags[drive] != NULL)
10821081   {
1083      m_drive = siblingdevice(m_intf->floppy_drive_tags[drive]);
1082      m_drive = siblingdevice<legacy_floppy_image_device>(m_intf->floppy_drive_tags[drive]);
10841083   }
10851084}
10861085
r29179r29180
12011200   else
12021201   {
12031202      m_status &= ~STA_1_NOT_READY;
1204      if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY))
1203      if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
12051204         m_status |= STA_1_NOT_READY;
12061205   }
12071206
r29179r29180
12161215      result |= m_idx << 1;
12171216
12181217      /* bit 2, track 0 state, inverted */
1219      result |= !floppy_tk00_r(m_drive) << 2;
1218      result |= !m_drive->floppy_tk00_r() << 2;
12201219
12211220      if (m_command_type==TYPE_I)
12221221      {
r29179r29180
12271226      }
12281227
12291228      /* bit 6, write protect, inverted */
1230      result |= !floppy_wpt_r(m_drive) << 6;
1229      result |= !m_drive->floppy_wpt_r() << 6;
12311230   }
12321231
12331232   /* eventually set data request bit */
r29179r29180
12831282   if (type() == WD1770 || type() == WD1772)
12841283   {
12851284      m_mo = ASSERT_LINE;
1286      floppy_mon_w(m_drive, CLEAR_LINE);
1285      m_drive->floppy_mon_w(CLEAR_LINE);
12871286   }
12881287
1289   floppy_drive_set_ready_state(m_drive, 1,0);
1288   m_drive->floppy_drive_set_ready_state(1,0);
12901289
12911290   if (!BIT(m_interrupt, 3))
12921291   {
r29179r29180
14091408         m_status &= ~STA_2_LOST_DAT;
14101409         wd17xx_clear_drq();
14111410
1412         if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY))
1411         if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
14131412         {
14141413            wd17xx_complete_command(DELAY_NOTREADY);
14151414         }
14161415         else
14171416         {
14181417            /* drive write protected? */
1419            if (floppy_wpt_r(m_drive) == CLEAR_LINE)
1418            if (m_drive->floppy_wpt_r() == CLEAR_LINE)
14201419            {
14211420            /* yes */
14221421               m_status |= STA_2_WRITE_PRO;
r29179r29180
14521451
14531452         wd17xx_clear_drq();
14541453
1455         if (floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY))
1454         if (m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
14561455            wd17xx_read_id();
14571456         else
14581457            wd17xx_complete_command(DELAY_NOTREADY);
r29179r29180
15191518         /* update track reg */
15201519         m_track += m_direction;
15211520
1522         floppy_drive_seek(m_drive, m_direction);
1521         m_drive->floppy_drive_seek(m_direction);
15231522      }
15241523
15251524      /* simulate seek time busy signal */
r29179r29180
15411540      /* simulate seek time busy signal */
15421541      m_busy_count = 0;  //((data & FDC_STEP_RATE) + 1);
15431542
1544      floppy_drive_seek(m_drive, m_direction);
1543      m_drive->floppy_drive_seek(m_direction);
15451544
15461545      if (data & FDC_STEP_UPDATE)
15471546         m_track += m_direction;
r29179r29180
15641563      /* simulate seek time busy signal */
15651564      m_busy_count = 0;  //((data & FDC_STEP_RATE) + 1);
15661565
1567      floppy_drive_seek(m_drive, m_direction);
1566      m_drive->floppy_drive_seek(m_direction);
15681567
15691568      if (data & FDC_STEP_UPDATE)
15701569         m_track += m_direction;
r29179r29180
15861585      m_busy_count = 0;  //((data & FDC_STEP_RATE) + 1);
15871586
15881587      /* for now only allows a single drive to be selected */
1589      floppy_drive_seek(m_drive, m_direction);
1588      m_drive->floppy_drive_seek(m_direction);
15901589
15911590      if (data & FDC_STEP_UPDATE)
15921591         m_track += m_direction;
r29179r29180
20452044   for (i = 0; i < 4; i++)
20462045   {
20472046      if(m_intf->floppy_drive_tags[i]!=NULL) {
2048         device_t *img = NULL;
2047         legacy_floppy_image_device *img = NULL;
20492048
2050         img = siblingdevice(m_intf->floppy_drive_tags[i]);
2049         img = siblingdevice<legacy_floppy_image_device>(m_intf->floppy_drive_tags[i]);
20512050
20522051         if (img!=NULL) {
2053            floppy_drive_set_controller(img,this);
2054            floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback);
2055            floppy_drive_set_rpm( img, 300.);
2052            img->floppy_drive_set_controller(this);
2053            img->floppy_drive_set_index_pulse_callback(wd17xx_index_pulse_callback);
2054            img->floppy_drive_set_rpm( 300.);
20562055         }
20572056      }
20582057   }
trunk/src/emu/machine/wd17xx.h
r29179r29180
1010#ifndef __WD17XX_H__
1111#define __WD17XX_H__
1212
13#include "imagedev/flopdrv.h"
1314
15
1416/***************************************************************************
1517    TYPE DEFINITIONS
1618***************************************************************************/
r29179r29180
165167   emu_timer *m_timer_cmd, *m_timer_data, *m_timer_rs, *m_timer_ws;
166168
167169   /* this is the drive currently selected */
168   device_t *m_drive;
170   legacy_floppy_image_device *m_drive;
169171
170172   /* this is the head currently selected */
171173   UINT8 m_hd;
trunk/src/emu/machine/smc92x4.c
r29179r29180
200200
201201int smc92x4_device::image_is_single_density()
202202{
203   floppy_image_legacy *image = flopimg_get_image(m_drive);
203   floppy_image_legacy *image = m_drive->flopimg_get_image();
204204   return (floppy_get_track_size(image, 0, 0)<4000);
205205}
206206
r29179r29180
436436   int redcur;
437437   int precomp;
438438   int write_long;
439   mfm_harddisk_device *harddisk;
440439
441440   switch (id)
442441   {
r29179r29180
481480         else
482481         {
483482            if (VERBOSE>5) LOG("smc92x4 step %s direction %d\n", m_drive->tag(), m_step_direction);
484            floppy_drive_seek(m_drive, m_step_direction);
483            m_drive->floppy_drive_seek(m_step_direction);
485484         }
486485      }
487486      else
488487      {
489488         if (VERBOSE>6) LOG("smc92x4 step harddisk direction %d\n", m_step_direction);
490         harddisk = static_cast<mfm_harddisk_device *>(m_drive);
491         harddisk->seek(m_step_direction);
489         m_harddisk->seek(m_step_direction);
492490      }
493491      sync_status_in();
494492      break;
r29179r29180
566564{
567565   int des_cylinder, cur_cylinder;
568566   bool found = false;
569   mfm_harddisk_device *harddisk;
570567
571568   sync_latches_out();
572569   sync_status_in();
r29179r29180
579576   if (m_selected_drive_type & TYPE_FLOPPY)
580577   {
581578      chrn_id idflop;
582      if (flopimg_get_image(m_drive) == NULL)
579      if (m_drive->flopimg_get_image() == NULL)
583580      {
584581         if (VERBOSE>2) LOG("smc92x4 warn: No disk in drive\n");
585582         m_register_r[CHIP_STATUS] |= CS_SYNCERR;
r29179r29180
590587      if ((image_is_single_density() && in_single_density_mode())
591588         || (!image_is_single_density() && !in_single_density_mode()))
592589      {
593         found = floppy_drive_get_next_id(m_drive, m_register_w[DESIRED_HEAD]&0x0f, &idflop);
590         found = m_drive->floppy_drive_get_next_id(m_register_w[DESIRED_HEAD]&0x0f, &idflop);
594591         copyid(idflop, id); /* Need to use bigger values for HD, but we don't use separate variables here */
595592      }
596593      else
r29179r29180
608605   }
609606   else
610607   {
611      harddisk = static_cast<mfm_harddisk_device *>(m_drive);
612
613      harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id);
608      m_harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id);
614609      sync_status_in();
615610      if (!(m_register_r[DRIVE_STATUS]& DS_READY))
616611      {
r29179r29180
670665   int found = false;
671666   int foundsect = false;
672667   int des_cylinder = 0;
673   mfm_harddisk_device *harddisk;
674668
675669   // Set command termination code. The error code is set first, and
676670   // on success, it is cleared.
r29179r29180
683677      if (m_selected_drive_type & TYPE_FLOPPY)
684678      {
685679         chrn_id idflop;
686         found = floppy_drive_get_next_id(m_drive, m_register_w[DESIRED_HEAD]&0x0f, &idflop);
680         found = m_drive->floppy_drive_get_next_id(m_register_w[DESIRED_HEAD]&0x0f, &idflop);
687681         copyid(idflop, id);
688682         if (/* pass==1 && */!found)
689683         {
r29179r29180
694688      }
695689      else
696690      {
697         harddisk = static_cast<mfm_harddisk_device *>(m_drive);
698         harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id);
691         m_harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id);
699692         sync_status_in();
700693         if (!(m_register_r[DRIVE_STATUS]& DS_READY))
701694         {
r29179r29180
742735void smc92x4_device::data_transfer_read(chrn_id_hd id, int transfer_enable)
743736{
744737   int i, retry, sector_len;
745   mfm_harddisk_device *harddisk;
746738
747739   int sector_data_id;
748740   dynamic_buffer buf;
r29179r29180
780772
781773   if (m_selected_drive_type & TYPE_FLOPPY)
782774   {
783      floppy_drive_read_sector_data(m_drive, id.H, sector_data_id, buf, sector_len);
775      m_drive->floppy_drive_read_sector_data(id.H, sector_data_id, buf, sector_len);
784776   }
785777   else
786778   {
787779      // TODO: Should we get the sector length from the harddisk?
788      harddisk = static_cast<mfm_harddisk_device *>(m_drive);
789      harddisk->read_sector(id.C, id.H, id.R, buf);
780      m_harddisk->read_sector(id.C, id.H, id.R, buf);
790781   }
791782   sync_status_in();
792783
r29179r29180
837828   int retry, i, sector_len;
838829   dynamic_buffer buf;
839830   int sector_data_id;
840   mfm_harddisk_device *harddisk;
841831   sync_latches_out();
842832   sync_status_in();
843833
r29179r29180
876866   if (m_selected_drive_type & TYPE_FLOPPY)
877867   {
878868      if (VERBOSE>4) LOG("smc92x4 info: write sector CHS=(%d,%d,%d)\n", id.C, id.H, id.R);
879      floppy_drive_write_sector_data(m_drive, id.H, sector_data_id, buf, sector_len, false);
869      m_drive->floppy_drive_write_sector_data(id.H, sector_data_id, buf, sector_len, false);
880870   }
881871   else
882872   {
883      harddisk = static_cast<mfm_harddisk_device *>(m_drive);
884      harddisk->write_sector(id.C, id.H, id.R, buf);
873      m_harddisk->write_sector(id.C, id.H, id.R, buf);
885874   }
886875   sync_status_in();
887876
r29179r29180
13441333
13451334   sync_status_in();
13461335
1347   floppy = flopimg_get_image(m_drive);
1336   floppy = m_drive->flopimg_get_image();
13481337
13491338   if (floppy != NULL)
13501339      data_count = floppy_get_track_size(floppy, 0, 0);
r29179r29180
14861475   memset(&buffer[index], gap_byte, gap4);
14871476   index += gap4;
14881477
1489   floppy_drive_write_track_data_info_buffer(m_drive, m_register_w[DESIRED_HEAD]&0x0f, buffer, &data_count);
1478   m_drive->floppy_drive_write_track_data_info_buffer(m_register_w[DESIRED_HEAD]&0x0f, buffer, &data_count);
14901479   sync_status_in();
14911480}
14921481
r29179r29180
15061495   int normal_data_mark = flags & 0x10;
15071496   int data_count=0;
15081497
1509   mfm_harddisk_device *harddisk = static_cast<mfm_harddisk_device *>(m_drive);
1510
15111498   dynamic_buffer buffer;
15121499
15131500   sync_status_in();
r29179r29180
15851572   for (i=0; i < gap4; i++) buffer[index++] = gap_byte;
15861573
15871574   // Now write the whole track
1588   harddisk->write_track(m_register_w[DESIRED_HEAD]&0x0f, buffer, data_count);
1575   m_harddisk->write_track(m_register_w[DESIRED_HEAD]&0x0f, buffer, data_count);
15891576
15901577   sync_status_in();
15911578}
r29179r29180
16181605
16191606   sync_latches_out();
16201607
1621   floppy = flopimg_get_image(m_drive);
1608   floppy = m_drive->flopimg_get_image();
16221609
16231610   /* Determine the track size. We cannot allow different sizes in this design. */
16241611   if (floppy != NULL)
r29179r29180
16341621
16351622   buffer = global_alloc_array(UINT8, data_count);
16361623
1637   floppy_drive_read_track_data_info_buffer(m_drive, m_register_w[DESIRED_HEAD]&0x0f, (char *)buffer, &data_count);
1624   m_drive->floppy_drive_read_track_data_info_buffer(m_register_w[DESIRED_HEAD]&0x0f, (char *)buffer, &data_count);
16381625   sync_status_in();
16391626
16401627   // Transfer the buffer to the external memory. We assume the memory
r29179r29180
16621649   int i;
16631650   UINT8 *buffer;
16641651   int data_count=0;
1665   mfm_harddisk_device *harddisk = static_cast<mfm_harddisk_device *>(m_drive);
1666
16671652   sync_latches_out();
16681653
1669   data_count = harddisk->get_track_length();
1654   data_count = m_harddisk->get_track_length();
16701655   buffer = global_alloc_array(UINT8, data_count);
16711656
16721657   /* buffer and data_count are allocated and set by the function. */
1673   harddisk->read_track(m_register_w[DESIRED_HEAD]&0x0f, buffer);
1658   m_harddisk->read_track(m_register_w[DESIRED_HEAD]&0x0f, buffer);
16741659   sync_status_in();
16751660
16761661   if (!(m_register_r[DRIVE_STATUS] & DS_READY))
r29179r29180
20041989   if (VERBOSE>0) LOG("smc92x4: use realistic timing: %02x\n", realistic);
20051990}
20061991
2007void smc92x4_device::connect_drive(device_t *drive)
1992void smc92x4_device::connect_floppy_drive(legacy_floppy_image_device *drive)
20081993{
20091994   m_drive = drive;
20101995   if (VERBOSE>3)
r29179r29180
20131998      else LOG("smc92x4: Connect drive %s\n", drive->tag());
20141999   }
20152000}
2001void smc92x4_device::connect_hard_drive(mfm_harddisk_device *drive)
2002{
2003   m_harddisk = drive;
2004   if (VERBOSE>3)
2005   {
2006      if (drive==NULL) LOG("smc92x4: Unselect all drives\n");
2007      else LOG("smc92x4: Connect drive %s\n", drive->tag());
2008   }
2009}
20162010
20172011void smc92x4_device::reset()
20182012{
trunk/src/emu/machine/smc92x4.h
r29179r29180
9898
9999   // Used to reconfigure the drive connections. Drive selection is done
100100   // using the select lines and maybe also the user-programmable outputs.
101   void connect_drive(device_t *drive);
101   void connect_floppy_drive(legacy_floppy_image_device *drive);
102   void connect_hard_drive(mfm_harddisk_device *drive);
102103
103104   void reset();
104105
r29179r29180
221222   // Hard disks must be instances of mfmhd_device; floppy disks are the common drives.
222223   // We expect the embedding board to replace the drive according to the
223224   // select lines.
224   device_t    *m_drive;
225   legacy_floppy_image_device    *m_drive;
226   mfm_harddisk_device           *m_harddisk;
225227};
226228
227229#define MCFG_SMC92X4_ADD(_tag, _intrf) \
trunk/src/emu/machine/mc6843.c
r29179r29180
139139   /* setup/reset floppy drive */
140140   for ( i = 0; i < 4; i++ )
141141   {
142      device_t * img = floppy_image( i );
143      floppy_mon_w(img, CLEAR_LINE);
144      floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
145      floppy_drive_set_rpm( img, 300. );
142      legacy_floppy_image_device * img = floppy_image( i );
143      img->floppy_mon_w(CLEAR_LINE);
144      img->floppy_drive_set_ready_state(FLOPPY_DRIVE_READY, 0 );
145      img->floppy_drive_set_rpm( 300. );
146146   }
147147   
148148   /* reset registers */
r29179r29180
162162
163163
164164
165device_t* mc6843_device::floppy_image( UINT8 drive )
165legacy_floppy_image_device* mc6843_device::floppy_image( UINT8 drive )
166166{
167   device_t *img = floppy_get_device( machine(), drive );
167   legacy_floppy_image_device *img = floppy_get_device( machine(), drive );
168168   if (!img && owner()) {
169169      // For slot devices, drives are typically attached to the slot rather than the machine
170170      const char *floppy_name = NULL;
r29179r29180
182182         floppy_name = FLOPPY_3;
183183         break;
184184      }
185      img = owner()->subdevice(floppy_name);
185      img = owner()->subdevice<legacy_floppy_image_device>(floppy_name);
186186   }
187187   return img;
188188}
189189
190190
191device_t* mc6843_device::floppy_image( )
191legacy_floppy_image_device* mc6843_device::floppy_image( )
192192{
193193   return floppy_image( m_drive );
194194}
r29179r29180
262262/* Seek Track Zero bottom half */
263263void mc6843_device::finish_STZ( )
264264{
265   device_t* img = floppy_image( );
265   legacy_floppy_image_device* img = floppy_image( );
266266   int i;
267267
268268   /* seek to track zero */
269269   for ( i=0; i<83; i++ )
270270   {
271      if (floppy_tk00_r(img) == CLEAR_LINE)
271      if (img->floppy_tk00_r() == CLEAR_LINE)
272272         break;
273      floppy_drive_seek( img, -1 );
273      img->floppy_drive_seek( -1 );
274274   }
275275
276   LOG(( "%f mc6843_finish_STZ: actual=%i\n", machine().time().as_double(), floppy_drive_get_current_track( img ) ));
276   LOG(( "%f mc6843_finish_STZ: actual=%i\n", machine().time().as_double(), img->floppy_drive_get_current_track() ));
277277
278278   /* update state */
279279   m_CTAR = 0;
280280   m_GCR = 0;
281281   m_SAR = 0;
282   m_STRB |= floppy_tk00_r(img) << 4;
282   m_STRB |= img->floppy_tk00_r() << 4;
283283
284284   cmd_end( );
285285}
r29179r29180
289289/* Seek bottom half */
290290void mc6843_device::finish_SEK( )
291291{
292   device_t* img = floppy_image( );
292   legacy_floppy_image_device* img = floppy_image( );
293293
294294   /* seek to track */
295295   // TODO: not sure how CTAR bit 7 is handled here, but this is the safest approach for now
296   floppy_drive_seek( img, m_GCR - (m_CTAR & 0x7F) );
296   img->floppy_drive_seek( m_GCR - (m_CTAR & 0x7F) );
297297
298   LOG(( "%f mc6843_finish_SEK: from %i to %i (actual=%i)\n", machine().time().as_double(), (m_CTAR & 0x7F), m_GCR, floppy_drive_get_current_track( img ) ));
298   LOG(( "%f mc6843_finish_SEK: from %i to %i (actual=%i)\n", machine().time().as_double(), (m_CTAR & 0x7F), m_GCR, img->floppy_drive_get_current_track() ));
299299
300300   /* update state */
301301   m_CTAR = m_GCR;
r29179r29180
308308/* preamble to all sector read / write commands, returns 1 if found */
309309int mc6843_device::address_search( chrn_id* id )
310310{
311   device_t* img = floppy_image( );
311   legacy_floppy_image_device* img = floppy_image( );
312312   int r = 0;
313313
314314   while ( 1 )
315315   {
316      if ( ( ! floppy_drive_get_next_id( img, m_side, id ) ) || ( id->flags & ID_FLAG_CRC_ERROR_IN_ID_FIELD ) || ( id->N != 0 ) )
316      if ( ( ! img->floppy_drive_get_next_id( m_side, id ) ) || ( id->flags & ID_FLAG_CRC_ERROR_IN_ID_FIELD ) || ( id->N != 0 ) )
317317      {
318318         /* read address error */
319319         LOG(( "%f mc6843_address_search: get_next_id failed\n", machine().time().as_double() ));
r29179r29180
343343         return 1;
344344      }
345345
346      if ( floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) )
346      if ( img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) )
347347      {
348348         r++;
349349         if ( r >= 4 )
r29179r29180
403403void mc6843_device::cont_SR( )
404404{
405405   chrn_id id;
406   device_t* img = floppy_image( );
406   legacy_floppy_image_device* img = floppy_image( );
407407
408408   /* sector seek */
409409   if ( ! address_search_read( &id ) )
410410      return;
411411
412412   /* sector read */
413   floppy_drive_read_sector_data( img, m_side, id.data_id, m_data, 128 );
413   img->floppy_drive_read_sector_data( m_side, id.data_id, m_data, 128 );
414414   m_data_idx = 0;
415415   m_data_size = 128;
416416   m_STRA |= 0x01;     /* set Data Transfer Request */
r29179r29180
551551      data = m_CTAR;
552552      LOG(( "%f %s mc6843_r: read CTAR %i (actual=%i)\n",
553553            machine().time().as_double(), machine().describe_context(), data,
554            floppy_drive_get_current_track( floppy_image( ) ) ));
554            floppy_image()->floppy_drive_get_current_track()));
555555      break;
556556
557557   case 2: /* Interrupt Status Register (ISR) */
r29179r29180
569569   case 3: /* Status Register A (STRA) */
570570   {
571571      /* update */
572      device_t* img = floppy_image( );
573      int flag = floppy_drive_get_flag_state( img, FLOPPY_DRIVE_READY);
572      legacy_floppy_image_device* img = floppy_image( );
573      int flag = img->floppy_drive_get_flag_state( FLOPPY_DRIVE_READY);
574574      m_STRA &= 0xa3;
575575      if ( flag & FLOPPY_DRIVE_READY )
576576         m_STRA |= 0x04;
577577
578      m_STRA |= !floppy_tk00_r(img) << 3;
579      m_STRA |= !floppy_wpt_r(img) << 4;
578      m_STRA |= !img->floppy_tk00_r() << 3;
579      m_STRA |= !img->floppy_wpt_r() << 4;
580580
581581      if ( m_index_pulse )
582582         m_STRA |= 0x40;
r29179r29180
605605      data = m_LTAR;
606606      LOG(( "%f %s mc6843_r: read LTAR %i (actual=%i)\n",
607607            machine().time().as_double(), machine().describe_context(), data,
608            floppy_drive_get_current_track( floppy_image( ) ) ));
608            floppy_image()->floppy_drive_get_current_track()));
609609      break;
610610
611611   default:
r29179r29180
639639         if ( m_data_idx >= m_data_size )
640640         {
641641            /* end of sector write */
642            device_t* img = floppy_image( );
642            legacy_floppy_image_device* img = floppy_image( );
643643
644644            LOG(( "%f %s mc6843_w: write sector %i\n", machine().time().as_double(), machine().describe_context(), m_data_id ));
645645
646            floppy_drive_write_sector_data(
647               img, m_side, m_data_id,
646            img->floppy_drive_write_sector_data(
647               m_side, m_data_id,
648648               m_data, m_data_size,
649649               (cmd == CMD_SWD) ? ID_FLAG_DELETED_DATA : 0 );
650650
r29179r29180
701701            if ( (m_data[2] == 0) && (m_data[4] == 0) )
702702            {
703703               /* valid address id field */
704               device_t* img = floppy_image( );
704               legacy_floppy_image_device* img = floppy_image( );
705705               UINT8 track  = m_data[1];
706706               UINT8 sector = m_data[3];
707707               UINT8 filler = 0xe5; /* standard Thomson filler */
708708               LOG(( "%f %s mc6843_w: address id detected track=%i sector=%i\n", machine().time().as_double(), machine().describe_context(), track, sector));
709               floppy_drive_format_sector( img, m_side, sector, track, 0, sector, 0, filler );
709               img->floppy_drive_format_sector( m_side, sector, track, 0, sector, 0, filler );
710710            }
711711            else
712712            {
r29179r29180
736736      m_CTAR = data;
737737      LOG(( "%f %s mc6843_w: set CTAR to %i %02X (actual=%i) \n",
738738            machine().time().as_double(), machine().describe_context(), m_CTAR, data,
739            floppy_drive_get_current_track( floppy_image( ) ) ));
739            floppy_image()->floppy_drive_get_current_track()));
740740      break;
741741
742742   case 2: /* Command Register (CMR) */
r29179r29180
816816      m_LTAR = data & 0x7f;
817817      LOG(( "%f %s mc6843_w: set LTAR to %i %02X (actual=%i)\n",
818818            machine().time().as_double(), machine().describe_context(), m_LTAR, data,
819            floppy_drive_get_current_track( floppy_image( ) ) ));
819            floppy_image()->floppy_drive_get_current_track()));
820820      break;
821821
822822   default:
trunk/src/emu/machine/mc6843.h
r29179r29180
6767   /* trigger delayed actions (bottom halves) */
6868   emu_timer* m_timer_cont;
6969   
70   device_t* floppy_image(UINT8 drive);
71   device_t* floppy_image();
70   legacy_floppy_image_device* floppy_image(UINT8 drive);
71   legacy_floppy_image_device* floppy_image();
7272   void status_update();
7373   void cmd_end();
7474   void finish_STZ();
trunk/src/emu/machine/i8271.c
r29179r29180
1414
1515#include "emu.h"
1616#include "i8271.h"
17#include "imagedev/flopdrv.h"
1817
1918/* data request */
2019#define I8271_FLAGS_DATA_REQUEST 0x01
r29179r29180
238237   set_dma_drq();
239238}
240239
241device_t *i8271_device::current_image()
240legacy_floppy_image_device *i8271_device::current_image()
242241{
243242   if (m_floppy_drive_tags[m_drive]!=NULL) {
244      return machine().device(m_floppy_drive_tags[m_drive]);
243      return machine().device<legacy_floppy_image_device>(m_floppy_drive_tags[m_drive]);
245244   } else {
246245      return NULL;
247246   }
r29179r29180
250249
251250void i8271_device::seek_to_track(int track)
252251{
253   device_t *img = current_image();
252   legacy_floppy_image_device *img = current_image();
254253   if (track==0)
255254   {
256255      /* seek to track 0 */
r29179r29180
259258      /*logerror("step\n"); */
260259
261260      /* track 0 not set, not seeked more than 255 tracks */
262      while (floppy_tk00_r(img) && (StepCount != 0))
261      while (img->floppy_tk00_r() && (StepCount != 0))
263262      {
264263/*            logerror("step\n"); */
265264         StepCount--;
266         floppy_drive_seek(img, -1);
265         img->floppy_drive_seek(-1);
267266      }
268267
269268      m_CurrentTrack[m_drive] = 0;
r29179r29180
297296
298297
299298      /* seek to track 0 */
300      floppy_drive_seek(img, SignedTracks);
299      img->floppy_drive_seek(SignedTracks);
301300
302301      m_CurrentTrack[m_drive] = track;
303302   }
r29179r29180
610609      case I8271_COMMAND_WRITE_DATA_SINGLE_RECORD:
611610      {
612611         /* put the buffer to the sector */
613         floppy_drive_write_sector_data(current_image(), m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7),0);
612         current_image()->floppy_drive_write_sector_data(m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7),0);
614613
615614         /* completed all sectors? */
616615         m_Counter--;
r29179r29180
653652   if (find_sector())
654653   {
655654      /* get the sector into the buffer */
656      floppy_drive_read_sector_data(current_image(), m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7));
655      current_image()->floppy_drive_read_sector_data(m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7));
657656
658657      /* initialise for reading */
659658      initialise_execution_phase_read(1<<(m_ID_N+7));
r29179r29180
672671   chrn_id id;
673672   
674673   /* get next id from disc */
675   floppy_drive_get_next_id(current_image(), m_side,&id);
674   current_image()->floppy_drive_get_next_id(m_side,&id);
676675
677676   m_pExecutionPhaseData[0] = id.C;
678677   m_pExecutionPhaseData[1] = id.H;
r29179r29180
704703
705704int i8271_device::find_sector()
706705{
707   device_t *img = current_image();
706   legacy_floppy_image_device *img = current_image();
708707//  int track_count_attempt;
709708
710709//  track_count_attempt
r29179r29180
719718      chrn_id id;
720719
721720      /* get next id from disc */
722      if (floppy_drive_get_next_id(img, m_side,&id))
721      if (img->floppy_drive_get_next_id(m_side,&id))
723722      {
724723         /* tested on Amstrad CPC - All bytes must match, otherwise
725724         a NO DATA error is reported */
r29179r29180
742741      }
743742
744743         /* index set? */
745      if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_INDEX))
744      if (img->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX))
746745      {
747746         index_count++;
748747      }
r29179r29180
759758
760759void i8271_device::command_execute()
761760{
762   device_t *img = current_image();
761   legacy_floppy_image_device *img = current_image();
763762
764763   /* clear it = good completion status */
765764   /* this will be changed if anything bad happens! */
r29179r29180
885884               m_drive_control_input = (1<<6) | (1<<2);
886885
887886               /* bit 3 = 0 if write protected */
888               m_drive_control_input |= floppy_wpt_r(img) << 3;
887               m_drive_control_input |= img->floppy_wpt_r() << 3;
889888
890889               /* bit 1 = 0 if head at track 0 */
891               m_drive_control_input |= floppy_tk00_r(img) << 1;
890               m_drive_control_input |= img->floppy_tk00_r() << 1;
892891
893892               /* need to setup this register based on drive selected */
894893               data = m_drive_control_input;
r29179r29180
10211020
10221021               /* load head - on mini-sized drives this turns on the disc motor,
10231022               on standard-sized drives this loads the head and turns the motor on */
1024               floppy_mon_w(img, !BIT(m_CommandParameters[1], 3));
1025               floppy_drive_set_ready_state(img, 1, 1);
1023               img->floppy_mon_w(!BIT(m_CommandParameters[1], 3));
1024               img->floppy_drive_set_ready_state(1, 1);
10261025
10271026               /* step pin changed? if so perform a step in the direction indicated */
10281027               if (((m_drive_control_output^m_CommandParameters[1]) & (1<<1))!=0)
r29179r29180
10421041                        signed_tracks = -1;
10431042                     }
10441043
1045                     floppy_drive_seek(img, signed_tracks);
1044                     img->floppy_drive_seek(signed_tracks);
10461045                  }
10471046               }
10481047
r29179r29180
10811080         /* these two do not appear to be set at all! ?? */
10821081
10831082         if (m_floppy_drive_tags[0]!=NULL) {
1084            if (floppy_drive_get_flag_state(machine().device(m_floppy_drive_tags[0]), FLOPPY_DRIVE_READY))
1083            if (machine().device<legacy_floppy_image_device>(m_floppy_drive_tags[0])->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
10851084            {
10861085               status |= (1<<2);
10871086            }
10881087         }
10891088
10901089         if (m_floppy_drive_tags[1]!=NULL) {
1091            if (floppy_drive_get_flag_state(machine().device(m_floppy_drive_tags[1]), FLOPPY_DRIVE_READY))
1090            if (machine().device<legacy_floppy_image_device>(m_floppy_drive_tags[1])->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
10921091            {
10931092               status |= (1<<6);
10941093            }
10951094         }
10961095
10971096         /* bit 3 = 1 if write protected */
1098         status |= !floppy_wpt_r(img) << 3;
1097         status |= !img->floppy_wpt_r() << 3;
10991098
11001099         /* bit 1 = 1 if head at track 0 */
1101         status |= !floppy_tk00_r(img) << 1;
1100         status |= !img->floppy_tk00_r() << 1;
11021101
11031102         m_ResultRegister = status;
11041103         command_complete(1,0);
r29179r29180
11401139
11411140         get_drive();
11421141
1143         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
1142         if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
11441143         {
11451144            /* Completion type: operation intervention probably required for recovery */
11461145            /* Completion code: Drive not ready */
r29179r29180
11731172
11741173         get_drive();
11751174
1176         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
1175         if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
11771176         {
11781177            /* Completion type: operation intervention probably required for recovery */
11791178            /* Completion code: Drive not ready */
r29179r29180
12121211
12131212         m_drive_control_output &=~1;
12141213
1215         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
1214         if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
12161215         {
12171216            /* Completion type: operation intervention probably required for recovery */
12181217            /* Completion code: Drive not ready */
r29179r29180
12211220         }
12221221         else
12231222         {
1224            if (floppy_wpt_r(img) == CLEAR_LINE)
1223            if (img->floppy_wpt_r() == CLEAR_LINE)
12251224            {
12261225               /* Completion type: operation intervention probably required for recovery */
12271226               /* Completion code: Drive write protected */
r29179r29180
12571256
12581257         m_drive_control_output &=~1;
12591258
1260         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
1259         if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
12611260         {
12621261            /* Completion type: operation intervention probably required for recovery */
12631262            /* Completion code: Drive not ready */
r29179r29180
12661265         }
12671266         else
12681267         {
1269            if (floppy_wpt_r(img) == CLEAR_LINE)
1268            if (img->floppy_wpt_r() == CLEAR_LINE)
12701269            {
12711270               /* Completion type: operation intervention probably required for recovery */
12721271               /* Completion code: Drive write protected */
r29179r29180
12961295
12971296         get_drive();
12981297
1299         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
1298         if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY))
13001299         {
13011300            /* Completion type: operation intervention probably required for recovery */
13021301            /* Completion code: Drive not ready */
trunk/src/emu/machine/i8271.h
r29179r29180
77#ifndef I8271_H_
88#define I8271_H_
99
10#include "imagedev/flopdrv.h"
11
1012#define MCFG_I8271_IRQ_CALLBACK(_write) \
1113   devcb = &i8271_device::set_irq_wr_callback(*device, DEVCB2_##_write);
1214
r29179r29180
126128   emu_timer *m_data_timer;
127129   emu_timer *m_command_complete_timer;
128130   
129   device_t *current_image();
131   legacy_floppy_image_device *current_image();
130132   void seek_to_track(int track);
131133   void load_bad_tracks(int surface);
132134   void write_bad_track(int surface, int track, int data);
trunk/src/emu/imagedev/flopdrv.c
r29179r29180
2929    TYPE DEFINITIONS
3030***************************************************************************/
3131
32struct floppy_drive
33{
34   /* callbacks */
35   devcb_resolved_write_line out_idx_func;
36   devcb_resolved_read_line in_mon_func;
37   devcb_resolved_write_line out_tk00_func;
38   devcb_resolved_write_line out_wpt_func;
39   devcb_resolved_write_line out_rdy_func;
40   devcb_resolved_write_line out_dskchg_func;
41
42   /* state of input lines */
43   int drtn; /* direction */
44   int stp;  /* step */
45   int wtg;  /* write gate */
46   int mon;  /* motor on */
47
48   /* state of output lines */
49   int idx;  /* index pulse */
50   int tk00; /* track 00 */
51   int wpt;  /* write protect */
52   int rdy;  /* ready */
53   int dskchg;     /* disk changed */
54
55   /* drive select logic */
56   int drive_id;
57   int active;
58
59   const floppy_interface  *config;
60
61   /* flags */
62   int flags;
63   /* maximum track allowed */
64   int max_track;
65   /* num sides */
66   int num_sides;
67   /* current track - this may or may not relate to the present cylinder number
68   stored by the fdc */
69   int current_track;
70
71   /* index pulse timer */
72   emu_timer   *index_timer;
73   /* index pulse callback */
74   void    (*index_pulse_callback)(device_t *controller,device_t *image, int state);
75   /* rotation per minute => gives index pulse frequency */
76   float rpm;
77
78   void    (*ready_state_change_callback)(device_t *controller,device_t *img, int state);
79
80   int id_index;
81
82   device_t *controller;
83
84   floppy_image_legacy *floppy;
85   int track;
86   void (*load_proc)(device_image_interface &image);
87   void (*unload_proc)(device_image_interface &image);
88   int floppy_drive_type;
89};
90
91
9232struct floppy_error_map
9333{
9434   floperr_t ferr;
r29179r29180
11555    IMPLEMENTATION
11656***************************************************************************/
11757
118INLINE floppy_drive *get_safe_token(device_t *device)
119{
120   assert( device != NULL );
121   return (floppy_drive *) downcast<legacy_floppy_image_device *>(device)->token();
122}
12358
124floppy_image_legacy *flopimg_get_image(device_t *image)
59floppy_image_legacy *legacy_floppy_image_device::flopimg_get_image()
12560{
126   return get_safe_token(image)->floppy;
61   return m_floppy;
12762}
12863
129static int flopimg_get_sectors_per_track(device_t *image, int side)
64int legacy_floppy_image_device::flopimg_get_sectors_per_track(int side)
13065{
13166   floperr_t err;
13267   int sector_count;
133   floppy_drive *flopimg = get_safe_token( image );
13468
135   if (!flopimg || !flopimg->floppy)
69   if (!m_floppy)
13670      return 0;
13771
138   err = floppy_get_sector_count(flopimg->floppy, side, flopimg->track, &sector_count);
72   err = floppy_get_sector_count(m_floppy, side, m_track, &sector_count);
13973   if (err)
14074      return 0;
14175   return sector_count;
14276}
14377
144static void flopimg_get_id_callback(device_t *image, chrn_id *id, int id_index, int side)
78void legacy_floppy_image_device::flopimg_get_id_callback(chrn_id *id, int id_index, int side)
14579{
146   floppy_drive *flopimg;
14780   int cylinder, sector, N;
14881   unsigned long flags;
14982   UINT32 sector_length;
15083
151   flopimg = get_safe_token( image );
152   if (!flopimg || !flopimg->floppy)
84   if (!m_floppy)
15385      return;
15486
155   floppy_get_indexed_sector_info(flopimg->floppy, side, flopimg->track, id_index, &cylinder, &side, &sector, &sector_length, &flags);
87   floppy_get_indexed_sector_info(m_floppy, side, m_track, id_index, &cylinder, &side, &sector, &sector_length, &flags);
15688
15789   N = compute_log2(sector_length);
15890
r29179r29180
16496   id->N = ((N >= 7) && (N <= 10)) ? N - 7 : 0;
16597}
16698
167static void log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length)
99void legacy_floppy_image_device::log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length)
168100{
169101   char membuf[1024];
170102   int i;
r29179r29180
173105   logerror("%s:  head=%i track=%i sector=%i buffer='%s'\n", name, head, track, sector, membuf);
174106}
175107
176static void floppy_drive_set_geometry_absolute(device_t *img, int tracks, int sides)
108void legacy_floppy_image_device::floppy_drive_set_geometry_absolute(int tracks, int sides)
177109{
178   floppy_drive *pDrive = get_safe_token( img );
179   pDrive->max_track = tracks;
180   pDrive->num_sides = sides;
110   m_max_track = tracks;
111   m_num_sides = sides;
181112}
182113
183void floppy_drive_set_geometry(device_t *img, floppy_type_t type)
114void legacy_floppy_image_device::floppy_drive_set_geometry(floppy_type_t type)
184115{
185   floppy_drive_set_geometry_absolute(img, type.max_track_number, type.head_number);
116   floppy_drive_set_geometry_absolute(type.max_track_number, type.head_number);
186117}
187118
188static TIMER_CALLBACK(floppy_drive_index_callback);
189
190119/* this is called on device init */
191static void floppy_drive_init(device_t *img)
120void legacy_floppy_image_device::floppy_drive_init()
192121{
193   floppy_drive *pDrive = get_safe_token( img );
194
195122   /* initialise flags */
196   pDrive->flags = 0;
197   pDrive->index_pulse_callback = NULL;
198   pDrive->ready_state_change_callback = NULL;
199   pDrive->index_timer = img->machine().scheduler().timer_alloc(FUNC(floppy_drive_index_callback), (void *) img);
200   pDrive->idx = 0;
123   m_flags = 0;
124   m_index_pulse_callback = NULL;
125   m_ready_state_change_callback = NULL;
126   m_index_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(legacy_floppy_image_device::floppy_drive_index_callback),this));
127   m_idx = 0;
201128
202   floppy_drive_set_geometry(img, ((floppy_interface*)img->static_config())->floppy_type);
129   floppy_drive_set_geometry(((floppy_interface*)static_config())->floppy_type);
203130
204131   /* initialise id index - not so important */
205   pDrive->id_index = 0;
132   m_id_index = 0;
206133   /* initialise track */
207   pDrive->current_track = 0;
134   m_current_track = 0;
208135
209136   /* default RPM */
210   pDrive->rpm = 300;
137   m_rpm = 300;
211138
212   pDrive->controller = NULL;
139   m_controller = NULL;
213140
214   pDrive->floppy_drive_type = FLOPPY_TYPE_REGULAR;
141   m_floppy_drive_type = FLOPPY_TYPE_REGULAR;
215142}
216143
217144/* index pulses at rpm/60 Hz, and stays high 1/20th of time */
218static void floppy_drive_index_func(device_t *img)
145void legacy_floppy_image_device::floppy_drive_index_func()
219146{
220   floppy_drive *drive = get_safe_token( img );
147   double ms = 1000.0 / (m_rpm / 60.0);
221148
222   double ms = 1000.0 / (drive->rpm / 60.0);
223
224   if (drive->idx)
149   if (m_idx)
225150   {
226      drive->idx = 0;
227      drive->index_timer->adjust(attotime::from_double(ms*19/20/1000.0));
151      m_idx = 0;
152      m_index_timer->adjust(attotime::from_double(ms*19/20/1000.0));
228153   }
229154   else
230155   {
231      drive->idx = 1;
232      drive->index_timer->adjust(attotime::from_double(ms/20/1000.0));
156      m_idx = 1;
157      m_index_timer->adjust(attotime::from_double(ms/20/1000.0));
233158   }
234159
235   drive->out_idx_func(drive->idx);
160   m_out_idx_func(m_idx);
236161
237   if (drive->index_pulse_callback)
238      drive->index_pulse_callback(drive->controller, img, drive->idx);
162   if (m_index_pulse_callback)
163      m_index_pulse_callback(m_controller, this, m_idx);
239164}
240165
241static TIMER_CALLBACK(floppy_drive_index_callback)
166TIMER_CALLBACK_MEMBER(legacy_floppy_image_device::floppy_drive_index_callback)
242167{
243   device_t *image = (device_t *) ptr;
244   floppy_drive_index_func(image);
168   floppy_drive_index_func();
245169}
246170
247171/*************************************************************************/
248172/* IO_FLOPPY device functions */
249173
250174/* set flag state */
251void floppy_drive_set_flag_state(device_t *img, int flag, int state)
175void legacy_floppy_image_device::floppy_drive_set_flag_state(int flag, int state)
252176{
253   floppy_drive *drv = get_safe_token( img );
254177   int prev_state;
255178   int new_state;
256179
257180   /* get old state */
258   prev_state = drv->flags & flag;
181   prev_state = m_flags & flag;
259182
260183   /* set new state */
261   drv->flags &= ~flag;
184   m_flags &= ~flag;
262185   if (state)
263      drv->flags |= flag;
186      m_flags |= flag;
264187
265188   /* get new state */
266   new_state = drv->flags & flag;
189   new_state = m_flags & flag;
267190
268191   /* changed state? */
269192   if (prev_state ^ new_state)
r29179r29180
271194      if (flag & FLOPPY_DRIVE_READY)
272195      {
273196         /* trigger state change callback */
274         drv->out_rdy_func(new_state ? ASSERT_LINE : CLEAR_LINE);
197         m_out_rdy_func(new_state ? ASSERT_LINE : CLEAR_LINE);
275198
276         if (drv->ready_state_change_callback)
277            drv->ready_state_change_callback(drv->controller, img, new_state);
199         if (m_ready_state_change_callback)
200            m_ready_state_change_callback(m_controller, this, new_state);
278201      }
279202   }
280203}
r29179r29180
282205/* for pc, drive is always ready, for amstrad,pcw,spectrum it is only ready under
283206a fixed set of circumstances */
284207/* use this to set ready state of drive */
285void floppy_drive_set_ready_state(device_t *img, int state, int flag)
286{
287   floppy_drive *drive = get_safe_token(img);
288   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
208void legacy_floppy_image_device::floppy_drive_set_ready_state(int state, int flag)
209{   
289210   if (flag)
290211   {
291212      /* set ready only if drive is present, disk is in the drive,
r29179r29180
293214
294215      /* drive present? */
295216      /* disk inserted? */
296      if (image->exists())
217      if (exists())
297218      {
298         if (drive->mon == CLEAR_LINE)
219         if (m_mon == CLEAR_LINE)
299220         {
300221            /* set state */
301            floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, state);
222            floppy_drive_set_flag_state(FLOPPY_DRIVE_READY, state);
302223            return;
303224         }
304225      }
305      floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, 0);
226      floppy_drive_set_flag_state(FLOPPY_DRIVE_READY, 0);
306227   }
307228   else
308229   {
309230      /* force ready state - for PC driver */
310      floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, state);
231      floppy_drive_set_flag_state(FLOPPY_DRIVE_READY, state);
311232   }
312233}
313234
314235/* get flag state */
315int floppy_drive_get_flag_state(device_t *img, int flag)
236int legacy_floppy_image_device::floppy_drive_get_flag_state(int flag)
316237{
317   floppy_drive *drv = get_safe_token( img );
318238   int drive_flags;
319239   int flags;
320240
321241   flags = 0;
322242
323   drive_flags = drv->flags;
243   drive_flags = m_flags;
324244
325245   /* these flags are independent of a real drive/disk image */
326246   flags |= drive_flags & (FLOPPY_DRIVE_READY | FLOPPY_DRIVE_INDEX);
r29179r29180
331251}
332252
333253
334void floppy_drive_seek(device_t *img, signed int signed_tracks)
335{
336   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
337   floppy_drive *pDrive;
254void legacy_floppy_image_device::floppy_drive_seek(signed int signed_tracks)
255{   
256   LOG(("seek from: %d delta: %d\n",m_current_track, signed_tracks));
338257
339   pDrive = get_safe_token( img );
340
341   LOG(("seek from: %d delta: %d\n",pDrive->current_track, signed_tracks));
342
343258   /* update position */
344   pDrive->current_track+=signed_tracks;
259   m_current_track+=signed_tracks;
345260
346   if (pDrive->current_track<0)
261   if (m_current_track<0)
347262   {
348      pDrive->current_track = 0;
263      m_current_track = 0;
349264   }
350265   else
351   if (pDrive->current_track>=pDrive->max_track)
266   if (m_current_track>=m_max_track)
352267   {
353      pDrive->current_track = pDrive->max_track-1;
268      m_current_track = m_max_track-1;
354269   }
355270
356271   /* set track 0 flag */
357   pDrive->tk00 = (pDrive->current_track == 0) ? CLEAR_LINE : ASSERT_LINE;
358   pDrive->out_tk00_func(pDrive->tk00);
272   m_tk00 = (m_current_track == 0) ? CLEAR_LINE : ASSERT_LINE;
273   m_out_tk00_func(m_tk00);
359274
360275   /* clear disk changed flag */
361   pDrive->dskchg = ASSERT_LINE;
362   //flopimg->out_dskchg_func(flopimg->dskchg);
276   m_dskchg = ASSERT_LINE;
277   //m_out_dskchg_func(m_dskchg);
363278
364279   /* inform disk image of step operation so it can cache information */
365   if (image->exists())
366      pDrive->track = pDrive->current_track;
280   if (exists())
281      m_track = m_current_track;
367282
368   pDrive->id_index = 0;
283   m_id_index = 0;
369284}
370285
371286
372287/* this is not accurate. But it will do for now */
373int floppy_drive_get_next_id(device_t *img, int side, chrn_id *id)
288int legacy_floppy_image_device::floppy_drive_get_next_id(int side, chrn_id *id)
374289{
375   floppy_drive *pDrive;
376290   int spt;
377291
378   pDrive = get_safe_token( img );
379
380292   /* get sectors per track */
381   spt = flopimg_get_sectors_per_track(img, side);
293   spt = flopimg_get_sectors_per_track(side);
382294
383295   /* set index */
384   if ((pDrive->id_index==(spt-1)) || (spt==0))
296   if ((m_id_index==(spt-1)) || (spt==0))
385297   {
386      floppy_drive_set_flag_state(img, FLOPPY_DRIVE_INDEX, 1);
298      floppy_drive_set_flag_state(FLOPPY_DRIVE_INDEX, 1);
387299   }
388300   else
389301   {
390      floppy_drive_set_flag_state(img, FLOPPY_DRIVE_INDEX, 0);
302      floppy_drive_set_flag_state(FLOPPY_DRIVE_INDEX, 0);
391303   }
392304
393305   /* get id */
394306   if (spt!=0)
395307   {
396      flopimg_get_id_callback(img, id, pDrive->id_index, side);
308      flopimg_get_id_callback(id, m_id_index, side);
397309   }
398310
399   pDrive->id_index++;
311   m_id_index++;
400312   if (spt!=0)
401      pDrive->id_index %= spt;
313      m_id_index %= spt;
402314   else
403      pDrive->id_index = 0;
315      m_id_index = 0;
404316
405317   return (spt == 0) ? 0 : 1;
406318}
407319
408void floppy_drive_read_track_data_info_buffer(device_t *img, int side, void *ptr, int *length )
320void legacy_floppy_image_device::floppy_drive_read_track_data_info_buffer(int side, void *ptr, int *length )
409321{
410   floppy_drive *flopimg;
411   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
412
413   if (image->exists())
322   if (exists())
414323   {
415      flopimg = get_safe_token( img );
416      if (!flopimg || !flopimg->floppy)
324      if (!m_floppy)
417325         return;
418326
419      floppy_read_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
327      floppy_read_track_data(m_floppy, side, m_track, ptr, *length);
420328   }
421329}
422330
423void floppy_drive_write_track_data_info_buffer(device_t *img, int side, const void *ptr, int *length )
331void legacy_floppy_image_device::floppy_drive_write_track_data_info_buffer(int side, const void *ptr, int *length )
424332{
425   floppy_drive *flopimg;
426   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
427
428   if (image->exists())
333   if (exists())
429334   {
430      flopimg = get_safe_token( img );
431      if (!flopimg || !flopimg->floppy)
335      if (!m_floppy)
432336         return;
433337
434      floppy_write_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
338      floppy_write_track_data(m_floppy, side, m_track, ptr, *length);
435339   }
436340}
437341
438void floppy_drive_format_sector(device_t *img, int side, int sector_index,int c,int h, int r, int n, int filler)
342void legacy_floppy_image_device::floppy_drive_format_sector(int side, int sector_index,int c,int h, int r, int n, int filler)
439343{
440   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
441
442   if (image->exists())
344   if (exists())
443345   {
444/*      if (drv->interface_.format_sector)
445            drv->interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/
346/*      if (m_interface_.format_sector)
347            m_interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/
446348   }
447349}
448350
449void floppy_drive_read_sector_data(device_t *img, int side, int index1, void *ptr, int length)
351void legacy_floppy_image_device::floppy_drive_read_sector_data(int side, int index1, void *ptr, int length)
450352{
451   floppy_drive *flopimg;
452   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
453
454   if (image->exists())
353   if (exists())
455354   {
456      flopimg = get_safe_token( img );
457      if (!flopimg || !flopimg->floppy)
355      if (!m_floppy)
458356         return;
459357
460      floppy_read_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length);
358      floppy_read_indexed_sector(m_floppy, side, m_track, index1, 0, ptr, length);
461359
462360      if (LOG_FLOPPY)
463         log_readwrite("sector_read", side, flopimg->track, index1, (const char *)ptr, length);
361         log_readwrite("sector_read", side, m_track, index1, (const char *)ptr, length);
464362
465363   }
466364}
467365
468void floppy_drive_write_sector_data(device_t *img, int side, int index1, const void *ptr,int length, int ddam)
366void legacy_floppy_image_device::floppy_drive_write_sector_data(int side, int index1, const void *ptr,int length, int ddam)
469367{
470   floppy_drive *flopimg;
471   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
472
473   if (image->exists())
368   if (exists())
474369   {
475      flopimg = get_safe_token( img );
476      if (!flopimg || !flopimg->floppy)
370      if (!m_floppy)
477371         return;
478372
479373      if (LOG_FLOPPY)
480         log_readwrite("sector_write", side, flopimg->track, index1, (const char *)ptr, length);
374         log_readwrite("sector_write", side, m_track, index1, (const char *)ptr, length);
481375
482      floppy_write_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length, ddam);
376      floppy_write_indexed_sector(m_floppy, side, m_track, index1, 0, ptr, length, ddam);
483377   }
484378}
485379
486void floppy_install_load_proc(device_t *image, void (*proc)(device_image_interface &image))
380void legacy_floppy_image_device::floppy_install_load_proc(void (*proc)(device_image_interface &image))
487381{
488   floppy_drive *flopimg = get_safe_token( image );
489   flopimg->load_proc = proc;
382   m_load_proc = proc;
490383}
491384
492void floppy_install_unload_proc(device_t *image, void (*proc)(device_image_interface &image))
385void legacy_floppy_image_device::floppy_install_unload_proc(void (*proc)(device_image_interface &image))
493386{
494   floppy_drive *flopimg = get_safe_token( image );
495   flopimg->unload_proc = proc;
387   m_unload_proc = proc;
496388}
497389
498390/* set the callback for the index pulse */
499void floppy_drive_set_index_pulse_callback(device_t *img, void (*callback)(device_t *controller,device_t *image, int state))
391void legacy_floppy_image_device::floppy_drive_set_index_pulse_callback(void (*callback)(device_t *controller, device_t *img, int state))
500392{
501   floppy_drive *pDrive = get_safe_token( img );
502   pDrive->index_pulse_callback = callback;
393   m_index_pulse_callback = callback;
503394}
504395
505
506void floppy_drive_set_ready_state_change_callback(device_t *img, void (*callback)(device_t *controller,device_t *img, int state))
396void legacy_floppy_image_device::floppy_drive_set_ready_state_change_callback(void (*callback)(device_t *controller,device_t *img, int state))
507397{
508   floppy_drive *pDrive = get_safe_token( img );
509   pDrive->ready_state_change_callback = callback;
398   m_ready_state_change_callback = callback;
510399}
511400
512int floppy_drive_get_current_track(device_t *img)
401int legacy_floppy_image_device::floppy_drive_get_current_track()
513402{
514   floppy_drive *drv = get_safe_token( img );
515   return drv->current_track;
403   return m_current_track;
516404}
517405
518UINT64 floppy_drive_get_current_track_size(device_t *img, int head)
406UINT64 legacy_floppy_image_device::floppy_drive_get_current_track_size(int head)
519407{
520   floppy_drive *drv = get_safe_token( img );
521408   int size = 0;
522   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
523
524   if (image->exists())
409   if (exists())
525410   {
526      size = floppy_get_track_size(drv->floppy, head, drv->current_track);
411      size = floppy_get_track_size(m_floppy, head, m_current_track);
527412   }
528413
529414   return size;
530415}
531416
532void floppy_drive_set_rpm(device_t *img, float rpm)
417void legacy_floppy_image_device::floppy_drive_set_rpm(float rpm)
533418{
534   floppy_drive *drv = get_safe_token( img );
535   drv->rpm = rpm;
419   m_rpm = rpm;
536420}
537421
538void floppy_drive_set_controller(device_t *img, device_t *controller)
422void legacy_floppy_image_device::floppy_drive_set_controller(device_t *controller)
539423{
540   floppy_drive *drv = get_safe_token( img );
541   drv->controller = controller;
424   m_controller = controller;
542425}
543426
544static int internal_floppy_device_load(device_image_interface *image, int create_format, option_resolution *create_args)
427int legacy_floppy_image_device::internal_floppy_device_load(int create_format, option_resolution *create_args)
545428{
546429   floperr_t err;
547   floppy_drive *flopimg;
548430   const struct FloppyFormat *floppy_options;
549431   int floppy_flags, i;
550432   const char *extension;
551433
552   /* look up instance data */
553   flopimg = get_safe_token( &image->device() );
434   device_image_interface *image = NULL;
435   interface(image);   /* figure out the floppy options */
436   floppy_options = ((floppy_interface*)static_config())->formats;
554437
555   /* figure out the floppy options */
556   floppy_options = ((floppy_interface*)image->device().static_config())->formats;
557
558   if (image->has_been_created())
438   if (has_been_created())
559439   {
560440      /* creating an image */
561441      assert(create_format >= 0);
562      err = floppy_create((void *) image, &image_ioprocs, &floppy_options[create_format], create_args, &flopimg->floppy);
442      err = floppy_create((void *) image, &image_ioprocs, &floppy_options[create_format], create_args, &m_floppy);
563443      if (err)
564444         goto error;
565445   }
566446   else
567447   {
568448      /* opening an image */
569      floppy_flags = !image->is_readonly() ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY;
570      extension = image->filetype();
571      err = floppy_open_choices((void *) image, &image_ioprocs, extension, floppy_options, floppy_flags, &flopimg->floppy);
449      floppy_flags = !is_readonly() ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY;
450      extension = filetype();
451      err = floppy_open_choices((void *) image, &image_ioprocs, extension, floppy_options, floppy_flags, &m_floppy);
572452      if (err)
573453         goto error;
574454   }
575   if (floppy_callbacks(flopimg->floppy)->get_heads_per_disk && floppy_callbacks(flopimg->floppy)->get_tracks_per_disk)
455   if (floppy_callbacks(m_floppy)->get_heads_per_disk && floppy_callbacks(m_floppy)->get_tracks_per_disk)
576456   {
577      floppy_drive_set_geometry_absolute(&image->device(),
578         floppy_get_tracks_per_disk(flopimg->floppy),
579         floppy_get_heads_per_disk(flopimg->floppy));
457      floppy_drive_set_geometry_absolute(floppy_get_tracks_per_disk(m_floppy),floppy_get_heads_per_disk(m_floppy));
580458   }
581459   /* disk changed */
582   flopimg->dskchg = CLEAR_LINE;
460   m_dskchg = CLEAR_LINE;
583461
584462   return IMAGE_INIT_PASS;
585463
r29179r29180
587465   for (i = 0; i < ARRAY_LENGTH(errmap); i++)
588466   {
589467      if (err == errmap[i].ferr)
590         image->seterror(errmap[i].ierr, errmap[i].message);
468         seterror(errmap[i].ierr, errmap[i].message);
591469   }
592470   return IMAGE_INIT_FAIL;
593471}
594472
595static TIMER_CALLBACK( set_wpt )
473TIMER_CALLBACK_MEMBER( legacy_floppy_image_device::set_wpt )
596474{
597   floppy_drive *flopimg = (floppy_drive *)ptr;
598
599   flopimg->wpt = param;
600   flopimg->out_wpt_func(param);
475   m_wpt = param;
476   m_out_wpt_func(param);
601477}
602478
603device_t *floppy_get_device(running_machine &machine,int drive)
479legacy_floppy_image_device *floppy_get_device(running_machine &machine,int drive)
604480{
605481   switch(drive) {
606      case 0 : return machine.device(FLOPPY_0);
607      case 1 : return machine.device(FLOPPY_1);
608      case 2 : return machine.device(FLOPPY_2);
609      case 3 : return machine.device(FLOPPY_3);
482      case 0 : return machine.device<legacy_floppy_image_device>(FLOPPY_0);
483      case 1 : return machine.device<legacy_floppy_image_device>(FLOPPY_1);
484      case 2 : return machine.device<legacy_floppy_image_device>(FLOPPY_2);
485      case 3 : return machine.device<legacy_floppy_image_device>(FLOPPY_3);
610486   }
611487   return NULL;
612488}
613489
614int floppy_get_drive_type(device_t *image)
490int legacy_floppy_image_device::floppy_get_drive_type()
615491{
616   floppy_drive *flopimg = get_safe_token( image );
617   return flopimg->floppy_drive_type;
492   return m_floppy_drive_type;
618493}
619494
620void floppy_set_type(device_t *image,int ftype)
495void legacy_floppy_image_device::floppy_set_type(int ftype)
621496{
622   floppy_drive *flopimg = get_safe_token( image );
623   flopimg->floppy_drive_type = ftype;
497   m_floppy_drive_type = ftype;
624498}
625499
626device_t *floppy_get_device_by_type(running_machine &machine,int ftype,int drive)
500legacy_floppy_image_device *floppy_get_device_by_type(running_machine &machine,int ftype,int drive)
627501{
628502   int i;
629503   int cnt = 0;
630504   for (i=0;i<4;i++) {
631      device_t *disk = floppy_get_device(machine,i);
632      if (floppy_get_drive_type(disk)==ftype) {
505      legacy_floppy_image_device *disk = floppy_get_device(machine,i);
506      if (disk->floppy_get_drive_type()==ftype) {
633507         if (cnt==drive) {
634508            return disk;
635509         }
r29179r29180
649523   return drive;
650524}
651525
652int floppy_get_drive_by_type(device_t *image,int ftype)
526int floppy_get_drive_by_type(legacy_floppy_image_device *image,int ftype)
653527{
654528   int i,drive =0;
655529   for (i=0;i<4;i++) {
656      device_t *disk = floppy_get_device(image->machine(),i);
657      if (floppy_get_drive_type(disk)==ftype) {
530      legacy_floppy_image_device *disk = floppy_get_device(image->machine(),i);
531      if (disk->floppy_get_drive_type()==ftype) {
658532         if (image==disk) {
659533            return drive;
660534         }
r29179r29180
667541int floppy_get_count(running_machine &machine)
668542{
669543   int cnt = 0;
670   if (machine.device(FLOPPY_0)) cnt++;
671   if (machine.device(FLOPPY_1)) cnt++;
672   if (machine.device(FLOPPY_2)) cnt++;
673   if (machine.device(FLOPPY_3)) cnt++;
544   if (machine.device<legacy_floppy_image_device>(FLOPPY_0)) cnt++;
545   if (machine.device<legacy_floppy_image_device>(FLOPPY_1)) cnt++;
546   if (machine.device<legacy_floppy_image_device>(FLOPPY_2)) cnt++;
547   if (machine.device<legacy_floppy_image_device>(FLOPPY_3)) cnt++;
674548   return cnt;
675549}
676550
677551
678552/* drive select 0 */
679WRITE_LINE_DEVICE_HANDLER( floppy_ds0_w )
553WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds0_w )
680554{
681   floppy_drive *drive = get_safe_token(device);
682
683555   if (state == CLEAR_LINE)
684      drive->active = (drive->drive_id == 0);
556      m_active = (m_drive_id == 0);
685557}
686558
687559/* drive select 1 */
688WRITE_LINE_DEVICE_HANDLER( floppy_ds1_w )
560WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds1_w )
689561{
690   floppy_drive *drive = get_safe_token(device);
691
692562   if (state == CLEAR_LINE)
693      drive->active = (drive->drive_id == 1);
563      m_active = (m_drive_id == 1);
694564}
695565
696566/* drive select 2 */
697WRITE_LINE_DEVICE_HANDLER( floppy_ds2_w )
567WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds2_w )
698568{
699   floppy_drive *drive = get_safe_token(device);
700
701569   if (state == CLEAR_LINE)
702      drive->active = (drive->drive_id == 2);
570      m_active = (m_drive_id == 2);
703571}
704572
705573/* drive select 3 */
706WRITE_LINE_DEVICE_HANDLER( floppy_ds3_w )
574WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds3_w )
707575{
708   floppy_drive *drive = get_safe_token(device);
709
710576   if (state == CLEAR_LINE)
711      drive->active = (drive->drive_id == 3);
577      m_active = (m_drive_id == 3);
712578}
713579
714580/* shortcut to write all four ds lines */
715WRITE8_DEVICE_HANDLER( floppy_ds_w )
581WRITE8_MEMBER( legacy_floppy_image_device::floppy_ds_w )
716582{
717   floppy_ds0_w(device, BIT(data, 0));
718   floppy_ds1_w(device, BIT(data, 1));
719   floppy_ds2_w(device, BIT(data, 2));
720   floppy_ds3_w(device, BIT(data, 3));
583   floppy_ds0_w(BIT(data, 0));
584   floppy_ds1_w(BIT(data, 1));
585   floppy_ds2_w(BIT(data, 2));
586   floppy_ds3_w(BIT(data, 3));
721587}
722588
723589/* motor on, active low */
724WRITE_LINE_DEVICE_HANDLER( floppy_mon_w )
590WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_mon_w )
725591{
726   floppy_drive *drive = get_safe_token(device);
727   device_image_interface *image = dynamic_cast<device_image_interface *>(device);
728592   /* force off if there is no attached image */
729   if (!image->exists())
593   if (!exists())
730594      state = ASSERT_LINE;
731595
732596   /* off -> on */
733   if (drive->mon && state == CLEAR_LINE)
597   if (m_mon && state == CLEAR_LINE)
734598   {
735      drive->idx = 0;
736      floppy_drive_index_func(device);
599      m_idx = 0;
600      floppy_drive_index_func();
737601   }
738602
739603   /* on -> off */
740   else if (drive->mon == CLEAR_LINE && state)
741      drive->index_timer->adjust(attotime::zero);
604   else if (m_mon == CLEAR_LINE && state)
605      m_index_timer->adjust(attotime::zero);
742606
743   drive->mon = state;
607   m_mon = state;
744608}
745609
746610/* direction */
747WRITE_LINE_DEVICE_HANDLER( floppy_drtn_w )
611WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_drtn_w )
748612{
749   floppy_drive *drive = get_safe_token(device);
750   drive->drtn = state;
613   m_drtn = state;
751614}
752615
753616/* write data */
754WRITE_LINE_DEVICE_HANDLER( floppy_wtd_w )
617WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_wtd_w )
755618{
756619}
757620
758621/* step */
759WRITE_LINE_DEVICE_HANDLER( floppy_stp_w )
622WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_stp_w )
760623{
761   floppy_drive *drive = get_safe_token(device);
762624
763625   /* move head one track when going from high to low and write gate is high */
764   if (drive->active && drive->stp && state == CLEAR_LINE && drive->wtg)
626   if (m_active && m_stp && state == CLEAR_LINE && m_wtg)
765627   {
766628      /* move head according to the direction line */
767      if (drive->drtn)
629      if (m_drtn)
768630      {
769631         /* move head outward */
770         if (drive->current_track > 0)
771            drive->current_track--;
632         if (m_current_track > 0)
633            m_current_track--;
772634
773635         /* are we at track 0 now? */
774         drive->tk00 = (drive->current_track == 0) ? CLEAR_LINE : ASSERT_LINE;
636         m_tk00 = (m_current_track == 0) ? CLEAR_LINE : ASSERT_LINE;
775637      }
776638      else
777639      {
778640         /* move head inward */
779         if (drive->current_track < drive->max_track)
780            drive->current_track++;
641         if (m_current_track < m_max_track)
642            m_current_track++;
781643
782644         /* we can't be at track 0 here, so reset the line */
783         drive->tk00 = ASSERT_LINE;
645         m_tk00 = ASSERT_LINE;
784646      }
785647
786648      /* update track 0 line with new status */
787      drive->out_tk00_func(drive->tk00);
649      m_out_tk00_func(m_tk00);
788650   }
789651
790   drive->stp = state;
652   m_stp = state;
791653}
792654
793655/* write gate */
794WRITE_LINE_DEVICE_HANDLER( floppy_wtg_w )
656WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_wtg_w )
795657{
796   floppy_drive *drive = get_safe_token(device);
797   drive->wtg = state;
658   m_wtg = state;
798659}
799660
800661/* write protect signal, active low */
801READ_LINE_DEVICE_HANDLER( floppy_wpt_r )
662READ_LINE_MEMBER( legacy_floppy_image_device::floppy_wpt_r )
802663{
803   floppy_drive *drive = get_safe_token(device);
804   return drive->wpt;
664   return m_wpt;
805665}
806666
807667/* track 0 detect */
808READ_LINE_DEVICE_HANDLER( floppy_tk00_r )
668READ_LINE_MEMBER( legacy_floppy_image_device::floppy_tk00_r )
809669{
810   floppy_drive *drive = get_safe_token(device);
811   return drive->tk00;
670   return m_tk00;
812671}
813672
814673/* disk changed */
815READ_LINE_DEVICE_HANDLER( floppy_dskchg_r )
674READ_LINE_MEMBER( legacy_floppy_image_device::floppy_dskchg_r )
816675{
817   floppy_drive *drive = get_safe_token(device);
818   return drive->dskchg;
676   return m_dskchg;
819677}
820678
821679/* 2-sided disk */
822READ_LINE_DEVICE_HANDLER( floppy_twosid_r )
680READ_LINE_MEMBER( legacy_floppy_image_device::floppy_twosid_r )
823681{
824   floppy_drive *drive = get_safe_token(device);
825
826   if (drive->floppy == NULL)
682   if (m_floppy == NULL)
827683      return ASSERT_LINE;
828684   else
829      return !floppy_get_heads_per_disk(drive->floppy);
685      return !floppy_get_heads_per_disk(m_floppy);
830686}
831687
832READ_LINE_DEVICE_HANDLER( floppy_index_r )
688READ_LINE_MEMBER( legacy_floppy_image_device::floppy_index_r )
833689{
834   floppy_drive *drive = get_safe_token(device);
835   return drive->idx;
690   return m_idx;
836691}
837692
838READ_LINE_DEVICE_HANDLER( floppy_ready_r )
693READ_LINE_MEMBER( legacy_floppy_image_device::floppy_ready_r )
839694{
840   return !(floppy_drive_get_flag_state(device, FLOPPY_DRIVE_READY) == FLOPPY_DRIVE_READY);
695   return !(floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) == FLOPPY_DRIVE_READY);
841696}
842697
843698// device type definition
r29179r29180
849704
850705legacy_floppy_image_device::legacy_floppy_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
851706   : device_t(mconfig, LEGACY_FLOPPY, "Floppy Disk", tag, owner, clock, "legacy_floppy_image", __FILE__),
852      device_image_interface(mconfig, *this),
853      m_token(NULL)
707      device_image_interface(mconfig, *this)
854708{
855   m_token = global_alloc_clear(floppy_drive);
856709}
857710
858711legacy_floppy_image_device::legacy_floppy_image_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source)
859712   : device_t(mconfig, type, name, tag, owner, clock, shortname, source),
860      device_image_interface(mconfig, *this),
861      m_token(NULL)
713      device_image_interface(mconfig, *this)
862714{
863   m_token = global_alloc_clear(floppy_drive);
864715}
865716
866717//-------------------------------------------------
r29179r29180
869720
870721legacy_floppy_image_device::~legacy_floppy_image_device()
871722{
872   global_free(m_token);
873723}
874724
875725//-------------------------------------------------
r29179r29180
878728
879729void legacy_floppy_image_device::device_start()
880730{
881   floppy_drive *floppy = get_safe_token( this );
882   floppy->config = (const floppy_interface*)static_config();
883   floppy_drive_init(this);
731   m_config = (const floppy_interface*)static_config();
732   floppy_drive_init();
884733
885   floppy->drive_id = floppy_get_drive(this);
886   floppy->active = FALSE;
734   m_drive_id = floppy_get_drive(this);
735   m_active = FALSE;
887736
888737   /* resolve callbacks */
889   floppy->out_idx_func.resolve(floppy->config->out_idx_func, *this);
890   floppy->in_mon_func.resolve(floppy->config->in_mon_func, *this);
891   floppy->out_tk00_func.resolve(floppy->config->out_tk00_func, *this);
892   floppy->out_wpt_func.resolve(floppy->config->out_wpt_func, *this);
893   floppy->out_rdy_func.resolve(floppy->config->out_rdy_func, *this);
894//  floppy->out_dskchg_func.resolve(floppy->config->out_dskchg_func, *this);
738   m_out_idx_func.resolve(m_config->out_idx_func, *this);
739   m_in_mon_func.resolve(m_config->in_mon_func, *this);
740   m_out_tk00_func.resolve(m_config->out_tk00_func, *this);
741   m_out_wpt_func.resolve(m_config->out_wpt_func, *this);
742   m_out_rdy_func.resolve(m_config->out_rdy_func, *this);
743//  m_out_dskchg_func.resolve(m_config->out_dskchg_func, *this);
895744
896745   /* by default we are not write-protected */
897   floppy->wpt = ASSERT_LINE;
898   floppy->out_wpt_func(floppy->wpt);
746   m_wpt = ASSERT_LINE;
747   m_out_wpt_func(m_wpt);
899748
900749   /* not at track 0 */
901   floppy->tk00 = ASSERT_LINE;
902   floppy->out_tk00_func(floppy->tk00);
750   m_tk00 = ASSERT_LINE;
751   m_out_tk00_func(m_tk00);
903752
904753   /* motor off */
905   floppy->mon = ASSERT_LINE;
754   m_mon = ASSERT_LINE;
906755
907756   /* disk changed */
908   floppy->dskchg = CLEAR_LINE;
909//  floppy->out_dskchg_func(floppy->dskchg);
757   m_dskchg = CLEAR_LINE;
758//  m_out_dskchg_func(m_dskchg);
910759}
911760
912761
r29179r29180
936785
937786bool legacy_floppy_image_device::call_create(int format_type, option_resolution *format_options)
938787{
939   return internal_floppy_device_load(this, format_type, format_options);
788   return internal_floppy_device_load(format_type, format_options);
940789}
941790
942791bool legacy_floppy_image_device::call_load()
943792{
944   floppy_drive *flopimg;
945   int retVal = internal_floppy_device_load(this, -1, NULL);
946   flopimg = get_safe_token( this);
793   int retVal = internal_floppy_device_load(-1, NULL);
947794   if (retVal==IMAGE_INIT_PASS) {
948795      /* if we have one of our hacky unload procs, call it */
949      if (flopimg->load_proc)
950         flopimg->load_proc(*this);
796      if (m_load_proc)
797         m_load_proc(*this);
951798   }
952799
953800   /* push disk halfway into drive */
954   flopimg->wpt = CLEAR_LINE;
955   flopimg->out_wpt_func(flopimg->wpt);
801   m_wpt = CLEAR_LINE;
802   m_out_wpt_func(m_wpt);
956803
957804   /* set timer for disk load */
958805   int next_wpt;
r29179r29180
962809   else
963810      next_wpt = CLEAR_LINE;
964811
965   machine().scheduler().timer_set(attotime::from_msec(250), FUNC(set_wpt), next_wpt, flopimg);
812   machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), next_wpt);
966813
967814   return retVal;
968815}
969816
970817void legacy_floppy_image_device::call_unload()
971818{
972   floppy_drive *flopimg = get_safe_token( this);
973   if (flopimg->unload_proc)
974      flopimg->unload_proc(*this);
819   if (m_unload_proc)
820      m_unload_proc(*this);
975821
976   floppy_close(flopimg->floppy);
977   flopimg->floppy = NULL;
822   floppy_close(m_floppy);
823   m_floppy = NULL;
978824
979825   /* disk changed */
980   flopimg->dskchg = CLEAR_LINE;
981   //flopimg->out_dskchg_func(flopimg->dskchg);
826   m_dskchg = CLEAR_LINE;
827   //m_out_dskchg_func(m_dskchg);
982828
983829   /* pull disk halfway out of drive */
984   flopimg->wpt = CLEAR_LINE;
985   flopimg->out_wpt_func(flopimg->wpt);
830   m_wpt = CLEAR_LINE;
831   m_out_wpt_func(m_wpt);
986832
987833   /* set timer for disk eject */
988   machine().scheduler().timer_set(attotime::from_msec(250), FUNC(set_wpt), ASSERT_LINE, flopimg);
834   machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), ASSERT_LINE);
989835}
990836
991837void legacy_floppy_image_device::call_display_info()
trunk/src/emu/imagedev/flopdrv.h
r29179r29180
9090/* set if index has just occurred */
9191#define FLOPPY_DRIVE_INDEX                      0x0020
9292
93/* a callback which will be executed if the ready state of the drive changes e.g. not ready->ready, ready->not ready */
94void floppy_drive_set_ready_state_change_callback(device_t *img, void (*callback)(device_t *controller,device_t *img, int state));
9593
96void floppy_drive_set_index_pulse_callback(device_t *img, void (*callback)(device_t *controller,device_t *image, int state));
97
98/* set flag state */
99int floppy_drive_get_flag_state(device_t *img, int flag);
100/* get flag state */
101void floppy_drive_set_flag_state(device_t *img, int flag, int state);
102/* get current physical track drive is on */
103int floppy_drive_get_current_track(device_t *img);
104/* get current physical track size */
105UINT64 floppy_drive_get_current_track_size(device_t *img, int head);
106
107/* get next id from track, 1 if got a id, 0 if no id was got */
108int floppy_drive_get_next_id(device_t *img, int side, chrn_id *);
109/* set ready state of drive. If flag == 1, set ready state only if drive present,
110disk is in drive, and motor is on. Otherwise set ready state to the state passed */
111void floppy_drive_set_ready_state(device_t *img, int state, int flag);
112
113/* seek up or down */
114void floppy_drive_seek(device_t *img, signed int signed_tracks);
115
116void floppy_drive_read_track_data_info_buffer(device_t *img, int side, void *ptr, int *length );
117void floppy_drive_write_track_data_info_buffer(device_t *img, int side, const void *ptr, int *length );
118void floppy_drive_format_sector(device_t *img, int side, int sector_index, int c, int h, int r, int n, int filler);
119void floppy_drive_read_sector_data(device_t *img, int side, int index1, void *pBuffer, int length);
120void floppy_drive_write_sector_data(device_t *img, int side, int index1, const void *pBuffer, int length, int ddam);
121
122/* set motor speed to get correct index pulses
123   standard RPM are 300 RPM (common) and 360 RPM
124   Note: this actually only works for soft sectored disks: one index pulse per
125   track.
126*/
127void floppy_drive_set_rpm(device_t *image, float rpm);
128
129void floppy_drive_set_controller(device_t *img, device_t *controller);
130
131floppy_image_legacy *flopimg_get_image(device_t *image);
132
133/* hack for apple II; replace this when we think of something better */
134void floppy_install_unload_proc(device_t *image, void (*proc)(device_image_interface &image));
135
136void floppy_install_load_proc(device_t *image, void (*proc)(device_image_interface &image));
137
138device_t *floppy_get_device(running_machine &machine,int drive);
139device_t *floppy_get_device_by_type(running_machine &machine,int ftype,int drive);
140int floppy_get_drive_type(device_t *image);
141void floppy_set_type(device_t *image,int ftype);
142int floppy_get_count(running_machine &machine);
143
144int floppy_get_drive(device_t *image);
145int floppy_get_drive_by_type(device_t *image,int ftype);
146
147void floppy_drive_set_geometry(device_t *img, floppy_type_t type);
148
149/* drive select lines */
150WRITE_LINE_DEVICE_HANDLER( floppy_ds0_w );
151WRITE_LINE_DEVICE_HANDLER( floppy_ds1_w );
152WRITE_LINE_DEVICE_HANDLER( floppy_ds2_w );
153WRITE_LINE_DEVICE_HANDLER( floppy_ds3_w );
154DECLARE_WRITE8_DEVICE_HANDLER( floppy_ds_w );
155
156WRITE_LINE_DEVICE_HANDLER( floppy_mon_w );
157WRITE_LINE_DEVICE_HANDLER( floppy_drtn_w );
158WRITE_LINE_DEVICE_HANDLER( floppy_stp_w );
159WRITE_LINE_DEVICE_HANDLER( floppy_wtd_w );
160WRITE_LINE_DEVICE_HANDLER( floppy_wtg_w );
161
162/* write-protect */
163READ_LINE_DEVICE_HANDLER( floppy_wpt_r );
164
165/* track 0 detect */
166READ_LINE_DEVICE_HANDLER( floppy_tk00_r );
167
168/* disk changed */
169READ_LINE_DEVICE_HANDLER( floppy_dskchg_r );
170
171/* 2-sided disk */
172READ_LINE_DEVICE_HANDLER( floppy_twosid_r );
173
174// index pulse
175READ_LINE_DEVICE_HANDLER( floppy_index_r );
176
177// drive ready
178READ_LINE_DEVICE_HANDLER( floppy_ready_r );
179
18094class legacy_floppy_image_device :  public device_t,
18195                           public device_image_interface
18296{
r29179r29180
203117   virtual const char *file_extensions() const { return m_extension_list; }
204118   virtual const option_guide *create_option_guide() const { return floppy_option_guide; }
205119
206   // access to legacy token
207   struct floppy_drive *token() const { assert(m_token != NULL); return m_token; }
120   floppy_image_legacy *flopimg_get_image();
121   void floppy_drive_set_geometry(floppy_type_t type);
122   void floppy_drive_set_flag_state(int flag, int state);
123   void floppy_drive_set_ready_state(int state, int flag);
124   int floppy_drive_get_flag_state(int flag);
125   void floppy_drive_seek(signed int signed_tracks);
126   int floppy_drive_get_next_id(int side, chrn_id *id);
127   void floppy_drive_read_track_data_info_buffer(int side, void *ptr, int *length );
128   void floppy_drive_write_track_data_info_buffer(int side, const void *ptr, int *length );
129   void floppy_drive_format_sector(int side, int sector_index,int c,int h, int r, int n, int filler);
130   void floppy_drive_read_sector_data(int side, int index1, void *ptr, int length);
131   void floppy_drive_write_sector_data(int side, int index1, const void *ptr,int length, int ddam);
132   void floppy_install_load_proc(void (*proc)(device_image_interface &image));
133   void floppy_install_unload_proc(void (*proc)(device_image_interface &image));
134   void floppy_drive_set_index_pulse_callback(void (*callback)(device_t *controller,device_t *image, int state));
135   void floppy_drive_set_ready_state_change_callback(void (*callback)(device_t *controller,device_t *img, int state));
136   int floppy_drive_get_current_track();
137   UINT64 floppy_drive_get_current_track_size(int head);
138   void floppy_drive_set_rpm(float rpm);
139   void floppy_drive_set_controller(device_t *controller);
140   int floppy_get_drive_type();
141   void floppy_set_type(int ftype);
142   WRITE_LINE_MEMBER( floppy_ds0_w );
143   WRITE_LINE_MEMBER( floppy_ds1_w );
144   WRITE_LINE_MEMBER( floppy_ds2_w );
145   WRITE_LINE_MEMBER( floppy_ds3_w );
146   WRITE8_MEMBER( floppy_ds_w );
147   WRITE_LINE_MEMBER( floppy_mon_w );
148   WRITE_LINE_MEMBER( floppy_drtn_w );
149   WRITE_LINE_MEMBER( floppy_wtd_w );
150   WRITE_LINE_MEMBER( floppy_stp_w );
151   WRITE_LINE_MEMBER( floppy_wtg_w );
152   READ_LINE_MEMBER( floppy_wpt_r );
153   READ_LINE_MEMBER( floppy_tk00_r );
154   READ_LINE_MEMBER( floppy_dskchg_r );
155   READ_LINE_MEMBER( floppy_twosid_r );
156   READ_LINE_MEMBER( floppy_index_r );
157   READ_LINE_MEMBER( floppy_ready_r );
158
159
160private:
161   int flopimg_get_sectors_per_track(int side);
162   void flopimg_get_id_callback(chrn_id *id, int id_index, int side);
163   void log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length);
164   void floppy_drive_set_geometry_absolute(int tracks, int sides);
165   TIMER_CALLBACK_MEMBER(floppy_drive_index_callback);
166   void floppy_drive_init();
167   void floppy_drive_index_func();
168   TIMER_CALLBACK(floppy_drive_index_callback);
169   int internal_floppy_device_load(int create_format, option_resolution *create_args);
170   TIMER_CALLBACK_MEMBER( set_wpt );
171
208172protected:
209173   // device overrides
210174   virtual void device_config_complete();
211175   virtual void device_start();
212176
213   struct floppy_drive *m_token;
177   /* callbacks */
178   devcb_resolved_write_line m_out_idx_func;
179   devcb_resolved_read_line m_in_mon_func;
180   devcb_resolved_write_line m_out_tk00_func;
181   devcb_resolved_write_line m_out_wpt_func;
182   devcb_resolved_write_line m_out_rdy_func;
183   devcb_resolved_write_line m_out_dskchg_func;
184
185   /* state of input lines */
186   int m_drtn; /* direction */
187   int m_stp;  /* step */
188   int m_wtg;  /* write gate */
189   int m_mon;  /* motor on */
190
191   /* state of output lines */
192   int m_idx;  /* index pulse */
193   int m_tk00; /* track 00 */
194   int m_wpt;  /* write protect */
195   int m_rdy;  /* ready */
196   int m_dskchg;     /* disk changed */
197
198   /* drive select logic */
199   int m_drive_id;
200   int m_active;
201
202   const floppy_interface  *m_config;
203
204   /* flags */
205   int m_flags;
206   /* maximum track allowed */
207   int m_max_track;
208   /* num sides */
209   int m_num_sides;
210   /* current track - this may or may not relate to the present cylinder number
211   stored by the fdc */
212   int m_current_track;
213
214   /* index pulse timer */
215   emu_timer   *m_index_timer;
216   /* index pulse callback */
217   void    (*m_index_pulse_callback)(device_t *controller,device_t *image, int state);
218   /* rotation per minute => gives index pulse frequency */
219   float m_rpm;
220
221   void    (*m_ready_state_change_callback)(device_t *controller,device_t *img, int state);
222
223   int m_id_index;
224
225   device_t *m_controller;
226
227   floppy_image_legacy *m_floppy;
228   int m_track;
229   void (*m_load_proc)(device_image_interface &image);
230   void (*m_unload_proc)(device_image_interface &image);
231   int m_floppy_drive_type;
232
214233   char            m_extension_list[256];
215234};
216235
217236// device type definition
218237extern const device_type LEGACY_FLOPPY;
219238
239
240
241legacy_floppy_image_device *floppy_get_device(running_machine &machine,int drive);
242legacy_floppy_image_device *floppy_get_device_by_type(running_machine &machine,int ftype,int drive);
243int floppy_get_drive(device_t *image);
244int floppy_get_drive_by_type(legacy_floppy_image_device *image,int ftype);
245int floppy_get_count(running_machine &machine);
246
247
220248/***************************************************************************
221249    DEVICE CONFIGURATION MACROS
222250***************************************************************************/

Previous 199869 Revisions Next


© 1997-2024 The MAME Team