Previous 15994 Revisions Next

r5709 Saturday 12th September, 2009 at 15:04:30 UTC by Miodrag Milanović
flopdrv reorganisation
[src/mess/devices]flopdrv.c

src/mess/devices/flopdrv.c
r5708r5709
11/*
2   This code handles the floppy drives.
3   All FDD actions should be performed using these functions.
2    This code handles the floppy drives.
3    All FDD actions should be performed using these functions.
44
5   The functions are emulated and a disk image is used.
5    The functions are emulated and a disk image is used.
66
77  Real disk operation:
88  - set unit id
99
1010  TODO:
11   - Disk change handling.
12   - Override write protect if disk image has been opened in read mode
11    - Disk change handling.
12    - Override write protect if disk image has been opened in read mode
1313*/
1414
1515#include "driver.h"
r5708r5709
1717
1818#define VERBOSE      0
1919#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
20   
20
2121/***************************************************************************
2222    CONSTANTS
2323***************************************************************************/
r5708r5709
3939   /* num sides */
4040   int num_sides;
4141   /* current track - this may or may not relate to the present cylinder number
42   stored by the fdc */
42    stored by the fdc */
4343   int current_track;
4444
4545   /* index pulse timer */
r5708r5709
9191/***************************************************************************
9292    IMPLEMENTATION
9393***************************************************************************/
94
9594static floppy_drive *get_drive(const device_config *img)
9695{
9796   return image_lookuptag(img, FLOPDRVTAG);
r5708r5709
102101   return get_drive(image)->floppy;
103102}
104103
105
106
107104static void flopimg_seek_callback(const device_config *image, int physical_track)
108105{
109   floppy_drive *flopimg;
110
111   flopimg = get_drive(image);
106   floppy_drive *flopimg = get_drive(image);
112107   if (!flopimg || !flopimg->floppy)
113108      return;
114109
r5708r5709
119114   flopimg->track = physical_track;
120115}
121116
122
123
124117static int flopimg_get_sectors_per_track(const device_config *image, int side)
125118{
126   floppy_drive *flopimg;
127119   floperr_t err;
128120   int sector_count;
121   floppy_drive *flopimg = get_drive(image);
129122
130   flopimg = get_drive(image);
131123   if (!flopimg || !flopimg->floppy)
132124      return 0;
133125
r5708r5709
137129   return sector_count;
138130}
139131
140
141
142132static void flopimg_get_id_callback(const device_config *image, chrn_id *id, int id_index, int side)
143133{
144134   floppy_drive *flopimg;
r5708r5709
162152   id->N = ((N >= 7) && (N <= 10)) ? N - 7 : 0;
163153}
164154
165
166
167155static void log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length)
168156{
169157   char membuf[1024];
r5708r5709
206194   image_fsize_thunk
207195};
208196
209/*************************************
210 *
211 *   Hacks for specific systems
212 *
213 *************************************/
214197
215void floppy_install_load_proc(const device_config *image, void (*proc)(const device_config *image))
216{
217   floppy_drive *flopimg = get_drive(image);
218   flopimg->load_proc = proc;
219}
220
221void floppy_install_unload_proc(const device_config *image, void (*proc)(const device_config *image))
222{
223   floppy_drive *flopimg = get_drive(image);
224   flopimg->unload_proc = proc;
225}
226
227
228
229void floppy_install_tracktranslate_proc(const device_config *image, int (*proc)(const device_config *image, floppy_image *floppy, int physical_track))
230{
231   floppy_drive *flopimg = get_drive(image);
232   flopimg->tracktranslate_proc = proc;
233}
234
235198static TIMER_CALLBACK(floppy_drive_index_callback);
236199
237200/* this is called on device init */
r5708r5709
264227   pDrive->controller = NULL;
265228}
266229
267
268
269230/* index pulses at rpm/60 Hz, and stays high 1/20th of time */
270231static void floppy_drive_index_func(const device_config *img)
271232{
r5708r5709
288249      pDrive->index_pulse_callback(pDrive->controller, img, pDrive->index);
289250}
290251
291
292
293252static TIMER_CALLBACK(floppy_drive_index_callback)
294253{
295254   const device_config *image = (const device_config *) ptr;
296255   floppy_drive_index_func(image);
297256}
298257
299
300
301/* set the callback for the index pulse */
302void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *image, int state))
303{
304   floppy_drive *pDrive = get_drive(img);
305   pDrive->index_pulse_callback = callback;
306}
307
308
309void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *img, int state))
310{
311   floppy_drive *pDrive = get_drive(img);
312   pDrive->ready_state_change_callback = callback;
313}
314
315258/*************************************************************************/
316259/* IO_FLOPPY device functions */
317260
r5708r5709
327270   if (new_status!=-1)
328271   {
329272      /* we don't set the flags directly.
330      The flags are "cooked" when we do a floppy_drive_get_flag_state depending on
331      if drive is connected etc. So if we wrote the flags back it would
332      corrupt this information. Therefore we update the flags depending on new_status */
273        The flags are "cooked" when we do a floppy_drive_get_flag_state depending on
274        if drive is connected etc. So if we wrote the flags back it would
275        corrupt this information. Therefore we update the flags depending on new_status */
333276
334277      floppy_drive_set_flag_state(img, FLOPPY_DRIVE_DISK_WRITE_PROTECTED, (new_status & FLOPPY_DRIVE_DISK_WRITE_PROTECTED));
335278   }
r5708r5709
338281   return floppy_drive_get_flag_state(img,0x0ff);
339282}
340283
341
342284/* set flag state */
343285void floppy_drive_set_flag_state(const device_config *img, int flag, int state)
344286{
r5708r5709
432374   if (flag)
433375   {
434376      /* set ready only if drive is present, disk is in the drive,
435      and disk motor is on - for Amstrad, Spectrum and PCW*/
377        and disk motor is on - for Amstrad, Spectrum and PCW*/
436378
437379      /* drive present? */
438380      if (image_slotexists(img))
r5708r5709
442384         {
443385            if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_MOTOR_ON))
444386            {
445
446387               /* set state */
447388               floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, state);
448389                    return;
449390            }
450391         }
451392      }
452
453393      floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, 0);
454394   }
455395   else
r5708r5709
457397      /* force ready state - for PC driver */
458398      floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, state);
459399   }
460
461400}
462401
463
464402/* get flag state */
465403int   floppy_drive_get_flag_state(const device_config *img, int flag)
466404{
r5708r5709
524462   floppy_drive_set_geometry_absolute(img, max_track, num_sides);
525463}
526464
527void floppy_drive_set_geometry_absolute(const device_config *img, int tracks, int sides)
528{
529   floppy_drive *pDrive = get_drive(img);
530   pDrive->max_track = tracks;
531   pDrive->num_sides = sides;
532}
533
534465void floppy_drive_seek(const device_config *img, signed int signed_tracks)
535466{
536467   floppy_drive *pDrive;
r5708r5709
604535   return (spt == 0) ? 0 : 1;
605536}
606537
607int   floppy_drive_get_current_track(const device_config *img)
608{
609   floppy_drive *drv = get_drive(img);
610   return drv->current_track;
611}
612
613538void floppy_drive_read_track_data_info_buffer(const device_config *img, int side, void *ptr, int *length )
614539{
615540   floppy_drive *flopimg;
616541   if (image_exists(img))
617   {   
542   {
618543      flopimg = get_drive(img);
619544      if (!flopimg || !flopimg->floppy)
620545         return;
621   
546
622547      floppy_read_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
623548   }
624549}
r5708r5709
631556      flopimg = get_drive(img);
632557      if (!flopimg || !flopimg->floppy)
633558         return;
634   
559
635560      floppy_write_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
636561   }
637562}
r5708r5709
640565{
641566   if (image_exists(img))
642567   {
643/*      if (drv->interface_.format_sector)
644         drv->interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/
568/*      if (drv->interface_.format_sector)
569            drv->interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/
645570   }
646571}
647572
r5708r5709
653578      flopimg = get_drive(img);
654579      if (!flopimg || !flopimg->floppy)
655580         return;
656     
581
657582      floppy_read_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length);
658     
583
659584      if (LOG_FLOPPY)
660585         log_readwrite("sector_read", side, flopimg->track, index1, ptr, length);
661     
586
662587   }
663588}
664589
r5708r5709
666591{
667592   floppy_drive *flopimg;
668593   if (image_exists(img))
669   {   
594   {
670595      flopimg = get_drive(img);
671596      if (!flopimg || !flopimg->floppy)
672597         return;
673   
598
674599      if (LOG_FLOPPY)
675600         log_readwrite("sector_write", side, flopimg->track, index1, ptr, length);
676   
601
677602      floppy_write_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length, ddam);
678603   }
679604}
r5708r5709
713638   return usecs;
714639}
715640
641void floppy_install_load_proc(const device_config *image, void (*proc)(const device_config *image))
642{
643   floppy_drive *flopimg = get_drive(image);
644   flopimg->load_proc = proc;
645}
716646
647void floppy_install_unload_proc(const device_config *image, void (*proc)(const device_config *image))
648{
649   floppy_drive *flopimg = get_drive(image);
650   flopimg->unload_proc = proc;
651}
717652
653void floppy_install_tracktranslate_proc(const device_config *image, int (*proc)(const device_config *image, floppy_image *floppy, int physical_track))
654{
655   floppy_drive *flopimg = get_drive(image);
656   flopimg->tracktranslate_proc = proc;
657}
658
659/* set the callback for the index pulse */
660void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *image, int state))
661{
662   floppy_drive *pDrive = get_drive(img);
663   pDrive->index_pulse_callback = callback;
664}
665
666
667void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *img, int state))
668{
669   floppy_drive *pDrive = get_drive(img);
670   pDrive->ready_state_change_callback = callback;
671}
672
673void floppy_drive_set_geometry_absolute(const device_config *img, int tracks, int sides)
674{
675   floppy_drive *pDrive = get_drive(img);
676   pDrive->max_track = tracks;
677   pDrive->num_sides = sides;
678}
679
680int   floppy_drive_get_current_track(const device_config *img)
681{
682   floppy_drive *drv = get_drive(img);
683   return drv->current_track;
684}
685
718686void floppy_drive_set_rpm(const device_config *img, float rpm)
719687{
720688   floppy_drive *drv = get_drive(img);
r5708r5709
728696}
729697
730698/* ----------------------------------------------------------------------- */
731
732
733699static DEVICE_START( floppy )
734700{
735701   floppy_drive_init(device);
736702}
737703
738
739
740704static int internal_floppy_device_load(const device_config *image, int create_format, option_resolution *create_args)
741705{
742706   floperr_t err;
r5708r5709
771735      if (err)
772736         goto error;
773737   }
774       
738
775739   /* if we can get head and track counts, then set the geometry accordingly
776      However, at least the ti99 system family requires that medium track
777      count and drive track count be handled separately.
778      It is possible to insert a 40 track medium in an 80 track drive; the
779      TI controllers read the track count from sector 0 and automatically
780      apply double steps. Setting the track count of the drive to the
781      medium track count will then lead to unreachable tracks.
782   */
740       However, at least the ti99 system family requires that medium track
741       count and drive track count be handled separately.
742       It is possible to insert a 40 track medium in an 80 track drive; the
743       TI controllers read the track count from sector 0 and automatically
744       apply double steps. Setting the track count of the drive to the
745       medium track count will then lead to unreachable tracks.
746    */
783747   keep_geometry = (int)mess_device_get_info_int(mess_devclass_from_core_device(image), MESS_DEVINFO_INT_KEEP_DRIVE_GEOMETRY);
784748
785   if (!keep_geometry
749   if (!keep_geometry
786750            && floppy_callbacks(flopimg->floppy)->get_heads_per_disk
787751      && floppy_callbacks(flopimg->floppy)->get_tracks_per_disk)
788752   {
r5708r5709
816780   return retVal;
817781}
818782
819
820
821783static DEVICE_IMAGE_CREATE( floppy )
822784{
823   return internal_floppy_device_load(image, create_format, create_args);   
785   return internal_floppy_device_load(image, create_format, create_args);
824786}
825787
826
827
828788static DEVICE_IMAGE_UNLOAD( floppy )
829789{
830790   floppy_drive *flopimg = get_drive(image);
r5708r5709
835795   flopimg->floppy = NULL;
836796}
837797
838
839
840798/*************************************
841799 *
842 *   Device specification function
800 *  Device specification function
843801 *
844802 *************************************/
845803

Previous 15994 Revisions Next


© 1998-2018 The MESS Team