Previous 15994 Revisions Next

r5707 Saturday 12th September, 2009 at 12:15:17 UTC by Miodrag Milanović
Some flopdrv cleanup
[src/mess/devices]flopdrv.c flopdrv.h

src/mess/devices/flopdrv.c
r5706r5707
44
55   The functions are emulated and a disk image is used.
66
7  Disk image operation:
8  - set disk image functions using floppy_drive_set_disk_image_interface
9
107  Real disk operation:
118  - set unit id
129
r5706r5707
1815#include "driver.h"
1916#include "flopdrv.h"
2017
21
2218#define VERBOSE      0
2319#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
20   
21/***************************************************************************
22    CONSTANTS
23***************************************************************************/
24
2425#define FLOPDRVTAG   "flopdrv"
26#define LOG_FLOPPY      0
2527
26static struct floppy_drive *get_drive(const device_config *img)
28/***************************************************************************
29    TYPE DEFINITIONS
30***************************************************************************/
31
32typedef struct _floppy_drive floppy_drive;
33struct _floppy_drive
2734{
35   /* flags */
36   int flags;
37   /* maximum track allowed */
38   int max_track;
39   /* num sides */
40   int num_sides;
41   /* current track - this may or may not relate to the present cylinder number
42   stored by the fdc */
43   int current_track;
44
45   /* index pulse timer */
46   void   *index_timer;
47   /* index pulse callback */
48   void   (*index_pulse_callback)(const device_config *controller,const device_config *image, int state);
49   /* rotation per minute => gives index pulse frequency */
50   float rpm;
51   /* current index pulse value */
52   int index;
53
54   void   (*ready_state_change_callback)(const device_config *controller,const device_config *img, int state);
55
56   int id_index;
57
58   const device_config *controller;
59
60   floppy_image *floppy;
61   int track;
62   void (*load_proc)(const device_config *image);
63   void (*unload_proc)(const device_config *image);
64   int (*tracktranslate_proc)(const device_config *image, floppy_image *floppy, int physical_track);
65};
66
67
68typedef struct _floppy_error_map floppy_error_map;
69struct _floppy_error_map
70{
71   floperr_t ferr;
72   image_error_t ierr;
73   const char *message;
74};
75
76
77
78/***************************************************************************
79    GLOBAL VARIABLES
80***************************************************************************/
81
82static const floppy_error_map errmap[] =
83{
84   { FLOPPY_ERROR_SUCCESS,         IMAGE_ERROR_SUCCESS },
85   { FLOPPY_ERROR_INTERNAL,      IMAGE_ERROR_INTERNAL },
86   { FLOPPY_ERROR_UNSUPPORTED,      IMAGE_ERROR_UNSUPPORTED },
87   { FLOPPY_ERROR_OUTOFMEMORY,      IMAGE_ERROR_OUTOFMEMORY },
88   { FLOPPY_ERROR_INVALIDIMAGE,   IMAGE_ERROR_INVALIDIMAGE }
89};
90
91/***************************************************************************
92    IMPLEMENTATION
93***************************************************************************/
94
95static floppy_drive *get_drive(const device_config *img)
96{
2897   return image_lookuptag(img, FLOPDRVTAG);
2998}
3099
100floppy_image *flopimg_get_image(const device_config *image)
101{
102   return get_drive(image)->floppy;
103}
104
105
106
107static void flopimg_seek_callback(const device_config *image, int physical_track)
108{
109   floppy_drive *flopimg;
110
111   flopimg = get_drive(image);
112   if (!flopimg || !flopimg->floppy)
113      return;
114
115   /* translate the track number if necessary */
116   if (flopimg->tracktranslate_proc)
117      physical_track = flopimg->tracktranslate_proc(image, flopimg->floppy, physical_track);
118
119   flopimg->track = physical_track;
120}
121
122
123
124static int flopimg_get_sectors_per_track(const device_config *image, int side)
125{
126   floppy_drive *flopimg;
127   floperr_t err;
128   int sector_count;
129
130   flopimg = get_drive(image);
131   if (!flopimg || !flopimg->floppy)
132      return 0;
133
134   err = floppy_get_sector_count(flopimg->floppy, side, flopimg->track, &sector_count);
135   if (err)
136      return 0;
137   return sector_count;
138}
139
140
141
142static void flopimg_get_id_callback(const device_config *image, chrn_id *id, int id_index, int side)
143{
144   floppy_drive *flopimg;
145   int cylinder, sector, N;
146   unsigned long flags;
147   UINT32 sector_length;
148
149   flopimg = get_drive(image);
150   if (!flopimg || !flopimg->floppy)
151      return;
152
153   floppy_get_indexed_sector_info(flopimg->floppy, side, flopimg->track, id_index, &cylinder, &side, &sector, &sector_length, &flags);
154
155   N = compute_log2(sector_length);
156
157   id->C = cylinder;
158   id->H = side;
159   id->R = sector;
160   id->data_id = id_index;
161   id->flags = flags;
162   id->N = ((N >= 7) && (N <= 10)) ? N - 7 : 0;
163}
164
165
166
167static void log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length)
168{
169   char membuf[1024];
170   int i;
171   for (i = 0; i < length; i++)
172      sprintf(membuf + i*2, "%02x", (int) (UINT8) buf[i]);
173   logerror("%s:  head=%i track=%i sector=%i buffer='%s'\n", name, head, track, sector, membuf);
174}
175
176/* ----------------------------------------------------------------------- */
177
178static int image_fseek_thunk(void *file, INT64 offset, int whence)
179{
180   return image_fseek((const device_config *) file, offset, whence);
181}
182
183static size_t image_fread_thunk(void *file, void *buffer, size_t length)
184{
185   return image_fread((const device_config *) file, buffer, length);
186}
187
188static size_t image_fwrite_thunk(void *file, const void *buffer, size_t length)
189{
190   return image_fwrite((const device_config *) file, buffer, length);
191}
192
193static UINT64 image_fsize_thunk(void *file)
194{
195   return image_length((const device_config *) file);
196}
197
198/* ----------------------------------------------------------------------- */
199
200const struct io_procs mess_ioprocs =
201{
202   NULL,
203   image_fseek_thunk,
204   image_fread_thunk,
205   image_fwrite_thunk,
206   image_fsize_thunk
207};
208
209/*************************************
210 *
211 *   Hacks for specific systems
212 *
213 *************************************/
214
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
31235static TIMER_CALLBACK(floppy_drive_index_callback);
32236
33237/* this is called on device init */
34void floppy_drive_init(const device_config *img, const floppy_interface *iface)
238void floppy_drive_init(const device_config *img)
35239{
36   struct floppy_drive *pDrive;
240   floppy_drive *pDrive;
37241
38242   assert(image_slotexists(img));
39243
40   pDrive = image_alloctag(img, FLOPDRVTAG, sizeof(struct floppy_drive));
244   pDrive = image_alloctag(img, FLOPDRVTAG, sizeof(floppy_drive));
41245
42246   /* initialise flags */
43247   pDrive->flags = 0;
r5706r5707
58262   pDrive->rpm = 300;
59263
60264   pDrive->controller = NULL;
61   
62   floppy_drive_set_disk_image_interface(img, iface);
63265}
64266
65267
r5706r5707
67269/* index pulses at rpm/60 Hz, and stays high 1/20th of time */
68270static void floppy_drive_index_func(const device_config *img)
69271{
70   struct floppy_drive *pDrive = get_drive(img);
272   floppy_drive *pDrive = get_drive(img);
71273
72274   double ms = 1000. / (pDrive->rpm / 60.);
73275
r5706r5707
99301/* set the callback for the index pulse */
100302void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *image, int state))
101303{
102   struct floppy_drive *pDrive = get_drive(img);
304   floppy_drive *pDrive = get_drive(img);
103305   pDrive->index_pulse_callback = callback;
104306}
105307
106308
107309void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *img, int state))
108310{
109   struct floppy_drive *pDrive = get_drive(img);
311   floppy_drive *pDrive = get_drive(img);
110312   pDrive->ready_state_change_callback = callback;
111313}
112314
r5706r5707
136338   return floppy_drive_get_flag_state(img,0x0ff);
137339}
138340
139/* set interface for image interface */
140void floppy_drive_set_disk_image_interface(const device_config *img, const floppy_interface *iface)
141{
142   struct floppy_drive *pDrive = get_drive(img);
143   if (iface)
144      memcpy(&pDrive->interface_, iface, sizeof(floppy_interface));
145   else
146      memset(&pDrive->interface_, 0, sizeof(floppy_interface));
147}
148341
149342/* set flag state */
150343void floppy_drive_set_flag_state(const device_config *img, int flag, int state)
151344{
152   struct floppy_drive *drv = get_drive(img);
345   floppy_drive *drv = get_drive(img);
153346   int prev_state;
154347   int new_state;
155348
r5706r5707
208401      /* if timer already setup remove it */
209402      if (image_slotexists(img))
210403      {
211         struct floppy_drive *pDrive = get_drive(img);
404         floppy_drive *pDrive = get_drive(img);
212405
213406         pDrive->index = 0;
214407         if (new_motor_state)
r5706r5707
271464/* get flag state */
272465int   floppy_drive_get_flag_state(const device_config *img, int flag)
273466{
274   struct floppy_drive *drv = get_drive(img);
467   floppy_drive *drv = get_drive(img);
275468   int drive_flags;
276469   int flags;
277470
r5706r5707
333526
334527void floppy_drive_set_geometry_absolute(const device_config *img, int tracks, int sides)
335528{
336   struct floppy_drive *pDrive = get_drive(img);
529   floppy_drive *pDrive = get_drive(img);
337530   pDrive->max_track = tracks;
338531   pDrive->num_sides = sides;
339532}
340533
341534void floppy_drive_seek(const device_config *img, signed int signed_tracks)
342535{
343   struct floppy_drive *pDrive;
536   floppy_drive *pDrive;
344537
345538   pDrive = get_drive(img);
346539
r5706r5707
368561   }
369562
370563   /* inform disk image of step operation so it can cache information */
371   if (image_exists(img) && pDrive->interface_.seek_callback)
372      pDrive->interface_.seek_callback(img, pDrive->current_track);
564   if (image_exists(img))
565      flopimg_seek_callback(img, pDrive->current_track);
373566
374567        pDrive->id_index = 0;
375568}
r5706r5707
378571/* this is not accurate. But it will do for now */
379572int   floppy_drive_get_next_id(const device_config *img, int side, chrn_id *id)
380573{
381   struct floppy_drive *pDrive;
574   floppy_drive *pDrive;
382575   int spt;
383576
384577   pDrive = get_drive(img);
385578
386579   /* get sectors per track */
387   spt = 0;
388   if (pDrive->interface_.get_sectors_per_track)
389      spt = pDrive->interface_.get_sectors_per_track(img, side);
580   spt = flopimg_get_sectors_per_track(img, side);
390581
391582   /* set index */
392583   if ((pDrive->id_index==(spt-1)) || (spt==0))
r5706r5707
401592   /* get id */
402593   if (spt!=0)
403594   {
404      if (pDrive->interface_.get_id_callback)
405         pDrive->interface_.get_id_callback(img, id, pDrive->id_index, side);
595      flopimg_get_id_callback(img, id, pDrive->id_index, side);
406596   }
407597
408598   pDrive->id_index++;
r5706r5707
416606
417607int   floppy_drive_get_current_track(const device_config *img)
418608{
419   struct floppy_drive *drv = get_drive(img);
609   floppy_drive *drv = get_drive(img);
420610   return drv->current_track;
421611}
422612
423613void floppy_drive_read_track_data_info_buffer(const device_config *img, int side, void *ptr, int *length )
424614{
615   floppy_drive *flopimg;
425616   if (image_exists(img))
426   {
427      struct floppy_drive *drv = get_drive(img);
428      if (drv->interface_.read_track_data_info_buffer)
429         drv->interface_.read_track_data_info_buffer(img, side, ptr, length);
617   {   
618      flopimg = get_drive(img);
619      if (!flopimg || !flopimg->floppy)
620         return;
621   
622      floppy_read_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
430623   }
431624}
432625
433626void floppy_drive_write_track_data_info_buffer(const device_config *img, int side, const void *ptr, int *length )
434627{
628   floppy_drive *flopimg;
435629   if (image_exists(img))
436630   {
437      struct floppy_drive *drv = get_drive(img);
438      if (drv->interface_.write_track_data_info_buffer)
439         drv->interface_.write_track_data_info_buffer(img, side, ptr, length);
631      flopimg = get_drive(img);
632      if (!flopimg || !flopimg->floppy)
633         return;
634   
635      floppy_write_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
440636   }
441637}
442638
r5706r5707
444640{
445641   if (image_exists(img))
446642   {
447      struct floppy_drive *drv = get_drive(img);
448      if (drv->interface_.format_sector)
449         drv->interface_.format_sector(img, side, sector_index,c, h, r, n, filler);
643/*      if (drv->interface_.format_sector)
644         drv->interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/
450645   }
451646}
452647
453void floppy_drive_read_sector_data(const device_config *img, int side, int index1, void *pBuffer, int length)
648void floppy_drive_read_sector_data(const device_config *img, int side, int index1, void *ptr, int length)
454649{
650   floppy_drive *flopimg;
455651   if (image_exists(img))
456652   {
457      struct floppy_drive *drv = get_drive(img);
458      if (drv->interface_.read_sector_data_into_buffer)
459         drv->interface_.read_sector_data_into_buffer(img, side, index1, pBuffer,length);
653      flopimg = get_drive(img);
654      if (!flopimg || !flopimg->floppy)
655         return;
656     
657      floppy_read_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length);
658     
659      if (LOG_FLOPPY)
660         log_readwrite("sector_read", side, flopimg->track, index1, ptr, length);
661     
460662   }
461663}
462664
463void floppy_drive_write_sector_data(const device_config *img, int side, int index1, const void *pBuffer,int length, int ddam)
665void floppy_drive_write_sector_data(const device_config *img, int side, int index1, const void *ptr,int length, int ddam)
464666{
667   floppy_drive *flopimg;
465668   if (image_exists(img))
466   {
467      struct floppy_drive *drv = get_drive(img);
468      if (drv->interface_.write_sector_data_from_buffer)
469         drv->interface_.write_sector_data_from_buffer(img, side, index1, pBuffer,length,ddam);
669   {   
670      flopimg = get_drive(img);
671      if (!flopimg || !flopimg->floppy)
672         return;
673   
674      if (LOG_FLOPPY)
675         log_readwrite("sector_write", side, flopimg->track, index1, ptr, length);
676   
677      floppy_write_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length, ddam);
470678   }
471679}
472680
r5706r5707
509717
510718void floppy_drive_set_rpm(const device_config *img, float rpm)
511719{
512   struct floppy_drive *drv = get_drive(img);
720   floppy_drive *drv = get_drive(img);
513721   drv->rpm = rpm;
514722}
515723
516724void floppy_drive_set_controller(const device_config *img, const device_config *controller)
517725{
518   struct floppy_drive *drv = get_drive(img);
726   floppy_drive *drv = get_drive(img);
519727   drv->controller = controller;
520728}
521729
522
523
524/***************************************************************************
525    CONSTANTS
526***************************************************************************/
527
528#define FLOPPY_TAG      "floptag"
529#define LOG_FLOPPY      0
530
531
532
533/***************************************************************************
534    TYPE DEFINITIONS
535***************************************************************************/
536
537typedef struct _mess_flopimg mess_flopimg;
538struct _mess_flopimg
539{
540   floppy_image *floppy;
541   int track;
542   void (*load_proc)(const device_config *image);
543   void (*unload_proc)(const device_config *image);
544   int (*tracktranslate_proc)(const device_config *image, floppy_image *floppy, int physical_track);
545};
546
547
548
549typedef struct _floppy_error_map floppy_error_map;
550struct _floppy_error_map
551{
552   floperr_t ferr;
553   image_error_t ierr;
554   const char *message;
555};
556
557
558
559/***************************************************************************
560    GLOBAL VARIABLES
561***************************************************************************/
562
563static const floppy_error_map errmap[] =
564{
565   { FLOPPY_ERROR_SUCCESS,         IMAGE_ERROR_SUCCESS },
566   { FLOPPY_ERROR_INTERNAL,      IMAGE_ERROR_INTERNAL },
567   { FLOPPY_ERROR_UNSUPPORTED,      IMAGE_ERROR_UNSUPPORTED },
568   { FLOPPY_ERROR_OUTOFMEMORY,      IMAGE_ERROR_OUTOFMEMORY },
569   { FLOPPY_ERROR_INVALIDIMAGE,   IMAGE_ERROR_INVALIDIMAGE }
570};
571
572/***************************************************************************
573    IMPLEMENTATION
574***************************************************************************/
575
576static mess_flopimg *get_flopimg(const device_config *image)
577{
578   return (mess_flopimg *) image_lookuptag(image, FLOPPY_TAG);
579}
580
581
582
583floppy_image *flopimg_get_image(const device_config *image)
584{
585   return get_flopimg(image)->floppy;
586}
587
588
589
590static void flopimg_seek_callback(const device_config *image, int physical_track)
591{
592   mess_flopimg *flopimg;
593
594   flopimg = get_flopimg(image);
595   if (!flopimg || !flopimg->floppy)
596      return;
597
598   /* translate the track number if necessary */
599   if (flopimg->tracktranslate_proc)
600      physical_track = flopimg->tracktranslate_proc(image, flopimg->floppy, physical_track);
601
602   flopimg->track = physical_track;
603}
604
605
606
607static int flopimg_get_sectors_per_track(const device_config *image, int side)
608{
609   mess_flopimg *flopimg;
610   floperr_t err;
611   int sector_count;
612
613   flopimg = get_flopimg(image);
614   if (!flopimg || !flopimg->floppy)
615      return 0;
616
617   err = floppy_get_sector_count(flopimg->floppy, side, flopimg->track, &sector_count);
618   if (err)
619      return 0;
620   return sector_count;
621}
622
623
624
625static void flopimg_get_id_callback(const device_config *image, chrn_id *id, int id_index, int side)
626{
627   mess_flopimg *flopimg;
628   int cylinder, sector, N;
629   unsigned long flags;
630   UINT32 sector_length;
631
632   flopimg = get_flopimg(image);
633   if (!flopimg || !flopimg->floppy)
634      return;
635
636   floppy_get_indexed_sector_info(flopimg->floppy, side, flopimg->track, id_index, &cylinder, &side, &sector, &sector_length, &flags);
637
638   N = compute_log2(sector_length);
639
640   id->C = cylinder;
641   id->H = side;
642   id->R = sector;
643   id->data_id = id_index;
644   id->flags = flags;
645   id->N = ((N >= 7) && (N <= 10)) ? N - 7 : 0;
646}
647
648
649
650static void log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length)
651{
652   char membuf[1024];
653   int i;
654   for (i = 0; i < length; i++)
655      sprintf(membuf + i*2, "%02x", (int) (UINT8) buf[i]);
656   logerror("%s:  head=%i track=%i sector=%i buffer='%s'\n", name, head, track, sector, membuf);
657}
658
659
660
661static void flopimg_read_sector_data_into_buffer(const device_config *image, int side, int index1, char *ptr, int length)
662{
663   mess_flopimg *flopimg;
664
665   flopimg = get_flopimg(image);
666   if (!flopimg || !flopimg->floppy)
667      return;
668
669   floppy_read_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length);
670
671   if (LOG_FLOPPY)
672      log_readwrite("sector_read", side, flopimg->track, index1, ptr, length);
673}
674
675
676
677static void flopimg_write_sector_data_from_buffer(const device_config *image, int side, int index1, const char *ptr, int length, int ddam)
678{
679   mess_flopimg *flopimg;
680
681   flopimg = get_flopimg(image);
682   if (!flopimg || !flopimg->floppy)
683      return;
684
685   if (LOG_FLOPPY)
686      log_readwrite("sector_write", side, flopimg->track, index1, ptr, length);
687
688   floppy_write_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length, ddam);
689}
690
691
692
693static void flopimg_read_track_data_info_buffer(const device_config *image, int side, void *ptr, int *length)
694{
695   mess_flopimg *flopimg;
696
697   flopimg = get_flopimg(image);
698   if (!flopimg || !flopimg->floppy)
699      return;
700
701   floppy_read_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
702}
703
704
705
706static void flopimg_write_track_data_info_buffer(const device_config *image, int side, const void *ptr, int *length)
707{
708   mess_flopimg *flopimg;
709
710   flopimg = get_flopimg(image);
711   if (!flopimg || !flopimg->floppy)
712      return;
713
714   floppy_write_track_data(flopimg->floppy, side, flopimg->track, ptr, *length);
715}
716
717
718
719static const floppy_interface mess_floppy_interface =
720{
721   flopimg_seek_callback,
722   flopimg_get_sectors_per_track,
723   flopimg_get_id_callback,
724   flopimg_read_sector_data_into_buffer,
725   flopimg_write_sector_data_from_buffer,
726   flopimg_read_track_data_info_buffer,
727   flopimg_write_track_data_info_buffer,
728   NULL
729};
730
731730/* ----------------------------------------------------------------------- */
732731
733static int image_fseek_thunk(void *file, INT64 offset, int whence)
734{
735   return image_fseek((const device_config *) file, offset, whence);
736}
737732
738static size_t image_fread_thunk(void *file, void *buffer, size_t length)
739{
740   return image_fread((const device_config *) file, buffer, length);
741}
742
743static size_t image_fwrite_thunk(void *file, const void *buffer, size_t length)
744{
745   return image_fwrite((const device_config *) file, buffer, length);
746}
747
748static UINT64 image_fsize_thunk(void *file)
749{
750   return image_length((const device_config *) file);
751}
752
753/* ----------------------------------------------------------------------- */
754
755const struct io_procs mess_ioprocs =
756{
757   NULL,
758   image_fseek_thunk,
759   image_fread_thunk,
760   image_fwrite_thunk,
761   image_fsize_thunk
762};
763
764
765
766
767/* ----------------------------------------------------------------------- */
768
769
770733static DEVICE_START( floppy )
771734{
772    image_alloctag(device, FLOPPY_TAG, sizeof(mess_flopimg));
773   floppy_drive_init(device, &mess_floppy_interface);
735   floppy_drive_init(device);
774736}
775737
776738
r5706r5707
778740static int internal_floppy_device_load(const device_config *image, int create_format, option_resolution *create_args)
779741{
780742   floperr_t err;
781   mess_flopimg *flopimg;
743   floppy_drive *flopimg;
782744   const mess_device_class *devclass;
783745   const struct FloppyFormat *floppy_options;
784746   int floppy_flags, i;
r5706r5707
786748   int keep_geometry = 0;
787749
788750   /* look up instance data */
789   flopimg = get_flopimg(image);
751   flopimg = get_drive(image);
790752
791753   /* figure out the floppy options */
792754   devclass = mess_devclass_from_core_device(image);
r5706r5707
843805
844806static DEVICE_IMAGE_LOAD( floppy )
845807{
846   mess_flopimg *flopimg;
808   floppy_drive *flopimg;
847809   int retVal = internal_floppy_device_load(image, -1, NULL);
848   flopimg = image_lookuptag(image, FLOPPY_TAG);
810   flopimg = get_drive(image);
849811   if (retVal==INIT_PASS) {
850812      /* if we have one of our hacky unload procs, call it */
851813      if (flopimg->load_proc)
r5706r5707
865827
866828static DEVICE_IMAGE_UNLOAD( floppy )
867829{
868   mess_flopimg *flopimg;
869   flopimg = image_lookuptag(image, FLOPPY_TAG);
870
871   /* if we have one of our hacky unload procs, call it */
830   floppy_drive *flopimg = get_drive(image);
872831   if (flopimg->unload_proc)
873832      flopimg->unload_proc(image);
874833
r5706r5707
880839
881840/*************************************
882841 *
883 *   Hacks for specific systems
884 *
885 *************************************/
886
887void floppy_install_load_proc(const device_config *image, void (*proc)(const device_config *image))
888{
889   mess_flopimg *flopimg;
890   flopimg = image_lookuptag(image, FLOPPY_TAG);
891   flopimg->load_proc = proc;
892}
893
894void floppy_install_unload_proc(const device_config *image, void (*proc)(const device_config *image))
895{
896   mess_flopimg *flopimg;
897   flopimg = image_lookuptag(image, FLOPPY_TAG);
898   flopimg->unload_proc = proc;
899}
900
901
902
903void floppy_install_tracktranslate_proc(const device_config *image, int (*proc)(const device_config *image, floppy_image *floppy, int physical_track))
904{
905   mess_flopimg *flopimg;
906   flopimg = image_lookuptag(image, FLOPPY_TAG);
907   flopimg->tracktranslate_proc = proc;
908}
909
910/*************************************
911 *
912842 *   Device specification function
913843 *
914844 *************************************/
src/mess/devices/flopdrv.h
r5706r5707
4747/* motor state */
4848#define FLOPPY_DRIVE_MOTOR_ON               0x0040
4949
50
51typedef struct floppy_interface
52{
53   /* seek to physical track */
54   void (*seek_callback)(const device_config *img, int physical_track);
55
56   /* the following are not strictly floppy drive operations, but are used by the
57   nec765 to get data from the track - really the whole track should be constructed
58   into the raw format the nec765 would normally see and this would be totally accurate */
59   /* the disc image would then have to re-interpret this back and update the image
60   with the data */
61
62   /* get number of sectors per track on side specified */
63   int (*get_sectors_per_track)(const device_config *image, int physical_side);
64
65   /* get id from current track and specified side */
66   void (*get_id_callback)(const device_config *image, chrn_id *, int id_index, int physical_side);
67
68   /* read sector data into buffer, length = number of bytes to read */
69   void (*read_sector_data_into_buffer)(const device_config *image, int side,int data_id,char *, int length);
70
71   /* write sector data from buffer, length = number of bytes to read  */
72   void (*write_sector_data_from_buffer)(const device_config *image, int side,int data_id, const char *, int length, int ddam);
73
74   /* Read track in buffer, length = number of bytes to read */
75   void (*read_track_data_info_buffer)(const device_config *image, int side, void *ptr, int *length );
76
77   /* Write track in buffer, length = number of bytes to read */
78   void (*write_track_data_info_buffer)(const device_config *image, int side, const void *ptr, int *length );
79
80   /* format */
81   void (*format_sector)(const device_config *img, int side, int sector_index,int c, int h, int r, int n, int filler);
82} floppy_interface;
83
84struct floppy_drive
85{
86   /* flags */
87   int flags;
88   /* maximum track allowed */
89   int max_track;
90   /* num sides */
91   int num_sides;
92   /* current track - this may or may not relate to the present cylinder number
93   stored by the fdc */
94   int current_track;
95
96   /* index pulse timer */
97   void   *index_timer;
98   /* index pulse callback */
99   void   (*index_pulse_callback)(const device_config *controller,const device_config *image, int state);
100   /* rotation per minute => gives index pulse frequency */
101   float rpm;
102   /* current index pulse value */
103   int index;
104
105   void   (*ready_state_change_callback)(const device_config *controller,const device_config *img, int state);
106
107   unsigned char id_buffer[4];
108
109   int id_index;
110    chrn_id ids[32];
111
112   const device_config *controller;
113   
114   floppy_interface interface_;
115};
116
11750/* a callback which will be executed if the ready state of the drive changes e.g. not ready->ready, ready->not ready */
11851void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *img, int state));
11952
r5706r5707
13770void floppy_drive_set_geometry_absolute(const device_config *img, int tracks, int sides);
13871
13972/* called in device init/exit functions */
140void floppy_drive_init(const device_config *img, const floppy_interface *iface);
73void floppy_drive_init(const device_config *img);
14174
14275/* get next id from track, 1 if got a id, 0 if no id was got */
14376int floppy_drive_get_next_id(const device_config *img, int side, chrn_id *);
r5706r5707
14780
14881void floppy_drive_set_motor_state(const device_config *img, int state);
14982
150/* deprecated; set interface for disk image functions */
151void floppy_drive_set_disk_image_interface(const device_config *img, const floppy_interface *iface);
152
15383/* seek up or down */
15484void floppy_drive_seek(const device_config *img, signed int signed_tracks);
15585

Previous 15994 Revisions Next


© 1998-2018 The MESS Team