Previous 15994 Revisions Next

r9488 Sunday 31st October, 2010 at 16:32:49 UTC by Michael Zapf
Indenting
[src/mess/devices]ti99_hd.c

src/mess/devices/ti99_hd.c
r9487r9488
3131#if 0
3232static void dump_contents(UINT8 *buffer, int length)
3333{
34        for (int i=0; i < length; i+=16)
35        {
36                for (int j=0; j < 16; j+=2)
37                {
38                        printf("%02x%02x ", buffer[i+j], buffer[i+j+1]);
39                }
40                printf("\n");
41        }
34   for (int i=0; i < length; i+=16)
35   {
36      for (int j=0; j < 16; j+=2)
37      {
38         printf("%02x%02x ", buffer[i+j], buffer[i+j+1]);
39      }
40      printf("\n");
41   }
4242}
4343#endif
4444
r9487r9488
5454      info = hard_disk_get_info(hdfile);
5555
5656      if (   (cylinder >= info->cylinders) ||
57         (head >= info->heads) ||
58              (sector >= info->sectors))
59                   return FALSE;
57            (head >= info->heads) ||
58            (sector >= info->sectors))
59      return FALSE;
6060
6161      *lba = (cylinder * info->heads + head)
62              * info->sectors
63         + sector;
62            * info->sectors
63            + sector;
6464      return TRUE;
6565   }
6666   return FALSE;
r9487r9488
6969/* Accessor functions */
7070void ti99_mfm_harddisk_read_sector(running_device *harddisk, int cylinder, int head, int sector, UINT8 **buf, int *sector_length)
7171{
72        UINT32 lba;
72   UINT32 lba;
7373   mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token();
7474   running_device *drive = harddisk->subdevice("drive");
75        hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
75   hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
7676
77        *sector_length = 256;
78        *buf = (UINT8 *)malloc(*sector_length);
77   *sector_length = 256;
78   *buf = (UINT8 *)malloc(*sector_length);
7979
8080   if (cylinder != hd->current_cylinder)
8181   {
8282      return;
8383   }
8484
85        if (file==NULL)
86        {
87                hd->status &= ~MFMHD_READY;
88                return;
89        }
85   if (file==NULL)
86   {
87      hd->status &= ~MFMHD_READY;
88      return;
89   }
9090
91        if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba))
92        {
93                hd->status &= ~MFMHD_READY;
94                return;
95        }
91   if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba))
92   {
93      hd->status &= ~MFMHD_READY;
94      return;
95   }
9696
97        if (!hard_disk_read(file, lba, *buf))
98        {
99           hd->status &= ~MFMHD_READY;
100                return;
101        }
102/* printf("ti99_hd read sector  c=%04d h=%02d s=%02d\n", cylinder, head, sector); */
103        hd->status |= MFMHD_READY;
97   if (!hard_disk_read(file, lba, *buf))
98   {
99      hd->status &= ~MFMHD_READY;
100      return;
101   }
102   /* printf("ti99_hd read sector  c=%04d h=%02d s=%02d\n", cylinder, head, sector); */
103   hd->status |= MFMHD_READY;
104104}
105105
106106void ti99_mfm_harddisk_write_sector(running_device *harddisk, int cylinder, int head, int sector, UINT8 *buf, int sector_length)
107107{
108        UINT32 lba;
108   UINT32 lba;
109109   mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token();
110110   running_device *drive = harddisk->subdevice("drive");
111        hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
111   hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
112112
113        if (file==NULL)
114        {
115                hd->status &= ~MFMHD_READY;
116                return;
117        }
113   if (file==NULL)
114   {
115      hd->status &= ~MFMHD_READY;
116      return;
117   }
118118
119        if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba))
120        {
121                hd->status &= ~MFMHD_READY;
122                hd->status |= MFMHD_WRFAULT;
123                return;
124        }
119   if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba))
120   {
121      hd->status &= ~MFMHD_READY;
122      hd->status |= MFMHD_WRFAULT;
123      return;
124   }
125125
126        if (!hard_disk_write(file, lba, buf))
126   if (!hard_disk_write(file, lba, buf))
127127   {
128                hd->status &= ~MFMHD_READY;
129                hd->status |= MFMHD_WRFAULT;
128      hd->status &= ~MFMHD_READY;
129      hd->status |= MFMHD_WRFAULT;
130130      return;
131131   }
132132
133        hd->status |= MFMHD_READY;
133   hd->status |= MFMHD_READY;
134134}
135135
136136#define TI99HD_BLOCKNOTFOUND -1
r9487r9488
176176
177177   /* We assume an interleave of 3 for 32 sectors. */
178178   int step = 3;
179        UINT32 lba;
180        int i;
179   UINT32 lba;
180   int i;
181181
182        int gap1 = 16;
183        int gap2 = 8;
184        int gap3 = 15;
185        int gap4 = 340;
186        int sync = 13;
187        int count;
188        int size;
189        int position = 0;
190        int sector;
191        int crc;
182   int gap1 = 16;
183   int gap2 = 8;
184   int gap3 = 15;
185   int gap4 = 340;
186   int sync = 13;
187   int count;
188   int size;
189   int position = 0;
190   int sector;
191   int crc;
192192
193193   const hard_disk_info *info;
194        hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
194   hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
195195
196196   if (file==NULL)
197197   {
r9487r9488
201201
202202   info = hard_disk_get_info(file);
203203
204        count = info->sectors;
205        size = info->sectorbytes/128;
204   count = info->sectors;
205   size = info->sectorbytes/128;
206206
207207   *data_count = gap1 + count*(sync+12+gap2+sync+size*128+gap3)+gap4;
208208
r9487r9488
284284
285285   *pbuffer = trackdata;
286286
287   /* Remember to free the buffer! Except when an error has occured,
288    the function returns a newly allocated buffer.
289    Errors are indicated by READY=FALSE. */
287   // Remember to free the buffer! Except when an error has occured,
288   // the function returns a newly allocated buffer.
289   // Errors are indicated by READY=FALSE.
290290}
291291
292292/*
r9487r9488
320320
321321   current_pos = find_block(track_image, 0, 100, 0x4e, gap1);
322322
323   /* In case of defect formats, we continue as far as possible. This
324    may lead to sectors not being written. */
323   // In case of defect formats, we continue as far as possible. This
324   // may lead to sectors not being written. */
325325   if (current_pos==TI99HD_BLOCKNOTFOUND)
326326   {
327327      logerror("ti99_hd error: write track: Cannot find gap1 for cylinder %d, head %d.\n", hd->current_cylinder, head);
r9487r9488
411411   running_device *drive;
412412   mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token();
413413   drive = harddisk->subdevice("drive");
414        hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
414   hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
415415
416416   if (file!=NULL)
417417      status |= MFMHD_READY;
r9487r9488
434434   running_device *drive = harddisk->subdevice("drive");
435435   mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token();
436436   const hard_disk_info *info;
437        hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
437   hard_disk_file *file = mess_hd_get_hard_disk_file(drive);
438438
439439   if (file==NULL)   return;
440440
r9487r9488
461461   running_device *drive = harddisk->subdevice("drive");
462462   mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token();
463463   const hard_disk_info *info;
464        hard_disk_file *file;
464   hard_disk_file *file;
465465   int interleave = 3;
466466
467467   file = mess_hd_get_hard_disk_file(drive);
468468   if (file==NULL)
469469   {
470                hd->status &= ~MFMHD_READY;
470      hd->status &= ~MFMHD_READY;
471471      return;
472472   }
473473
r9487r9488
497497
498498
499499MACHINE_CONFIG_FRAGMENT( mfmhd )
500        MDRV_DEVICE_ADD( "drive", HARDDISK, 0 )
500   MDRV_DEVICE_ADD( "drive", HARDDISK, 0 )
501501MACHINE_CONFIG_END
502502
503503MACHINE_CONFIG_FRAGMENT( idehd )
504        MDRV_DEVICE_ADD( "drive", IDE_HARDDISK, 0 )
504   MDRV_DEVICE_ADD( "drive", IDE_HARDDISK, 0 )
505505MACHINE_CONFIG_END
506506
507507static const char DEVTEMPLATE_SOURCE[] = __FILE__;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team