Previous 15994 Revisions Next

r11728 Monday 30th May, 2011 at 16:32:02 UTC by Miodrag Milanović
pc_fdc - Data rate detection added [Carl]
[src/mess/machine]pc_fdc.c upd765.c upd765.h

src/mess/machine/upd765.c
r11727r11728
8181
8282#define UPD765_RESET 0x080
8383
84#define UPD765_BAD_MEDIA 0x100
85
8486typedef struct _upd765_t upd765_t;
8587struct _upd765_t
8688{
r11727r11728
862864   /* number of times we have seen index hole */
863865   int index_count = 0;
864866
867   if (fdc->upd765_flags & UPD765_BAD_MEDIA) {
868      fdc->upd765_status[1] |= 1;
869      return FALSE;
870   }
871   
865872   /* get sector id's */
866873   do
867874    {
r11727r11728
15031510            /* sector id == EOT */
15041511            UINT8 ddam;
15051512
1513            /* nothing to write */
1514            if ((fdc->upd765_transfer_bytes_remaining==0) && (fdc->upd765_flags & UPD765_DMA_MODE))
1515            {
1516               if (fdc->upd765_flags & UPD765_TC)
1517                  upd765_write_complete(device);
1518               // if TC or not set or PIO, what?
1519               break;
1520            }
1521
15061522            ddam = 0;
15071523            if (fdc->command == 0x09)
15081524            {
r11727r11728
19301946         {
19311947            /* is disk inserted? */
19321948            device_image_interface *image = dynamic_cast<device_image_interface *>( img);
1933            if (image->exists())
1949            if (image!=NULL && image->exists())
19341950            {
19351951               int index_count = 0;
19361952
r11727r11728
19491965                  /* get next id from disc */
19501966                  if (floppy_drive_get_next_id(img, fdc->side, &id))
19511967                  {
1952                     /* got an id - quit */
1953                     break;
1968                     /* got an id */
1969                     /* if bad media keep going until failure */
1970                     if (!(fdc->upd765_flags & UPD765_BAD_MEDIA)) break;
19541971                  }
19551972
19561973                  if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_INDEX))
r11727r11728
19611978               }
19621979               while (index_count!=2);
19631980
1981               if (fdc->upd765_flags & UPD765_BAD_MEDIA)
1982               {
1983                     fdc->upd765_status[0] |= 0x40;
1984                     fdc->upd765_status[1] |= 1;
1985               }
1986
19641987               /* at this point, we have seen a id or two index pulses have occured! */
19651988               fdc->upd765_result_bytes[0] = fdc->upd765_status[0];
19661989               fdc->upd765_result_bytes[1] = fdc->upd765_status[1];
r11727r11728
22082231   upd765_set_int(device, 1);
22092232}
22102233
2234void upd765_set_bad(device_t *device, int state)
2235{
2236   upd765_t *fdc = get_safe_token(device);
2237   if (state) fdc->upd765_flags |= UPD765_BAD_MEDIA;
2238   else fdc->upd765_flags &= ~UPD765_BAD_MEDIA;
2239}
2240
22112241void upd765_reset(device_t *device, int offset)
22122242{
22132243   upd765_t *fdc = get_safe_token(device);
src/mess/machine/upd765.h
r11727r11728
8787WRITE_LINE_DEVICE_HANDLER(upd765_ready_w);
8888
8989void upd765_idle(device_t *device);
90void upd765_set_bad(device_t *device, int state);
9091
9192/*********************/
9293/* STATUS REGISTER 1 */
src/mess/machine/pc_fdc.c
r11727r11728
327327   }
328328}
329329
330
331330/*  PCJr FDC Digitial Output Register (DOR)
332331
333332    On a PC Jr the DOR is wired up a bit differently:
r11727r11728
427426   fdc->digital_output_register = data;
428427}
429428
429#define RATE_250  2
430#define RATE_300  1
431#define RATE_500  0
432#define RATE_1000 3
430433
434static void pc_fdc_check_data_rate(running_machine &machine)
435{
436   device_t *device = floppy_get_device(machine, fdc->digital_output_register & 0x03);
437   floppy_image *image;
438   int tracks, sectors, rate;
439
440   upd765_set_bad(pc_get_device(machine), 0); // unset in case format is unknown
441   if (!device) return;
442   image = flopimg_get_image(device);
443   if (!image) return;
444   tracks = floppy_get_tracks_per_disk(image);
445   tracks -= (tracks % 10); // ignore extra tracks
446   floppy_get_sector_count(image, 0, 0, &sectors);
447
448   if (tracks == 40) {
449      if ((fdc->data_rate_register != RATE_250) && (fdc->data_rate_register != RATE_300))
450         upd765_set_bad(pc_get_device(machine), 1);
451      return;
452   } else if (tracks == 80) {
453      if (sectors <= 14)      rate = RATE_250;    // 720KB 5 1/4 and 3 1/2
454      else if (sectors <= 24) rate = RATE_500;    // 1.2MB 5 1/4 and 1.44MB 3 1/2
455      else                    rate = RATE_1000;   // 2.88MB 3 1/2
456   } else return;
457
458   if (rate != (fdc->data_rate_register & 3))
459      upd765_set_bad(pc_get_device(machine), 1);
460}
461
431462READ8_HANDLER ( pc_fdc_r )
432463{
433464   UINT8 data = 0xff;
r11727r11728
469500   if (LOG_FDC)
470501      logerror("pc_fdc_w(): pc=0x%08x offset=%d data=0x%02X\n", (unsigned) cpu_get_reg(space->machine().firstcpu,STATE_GENPC), offset, data);
471502
503   pc_fdc_check_data_rate(space->machine());  // check every time a command may start
472504   switch(offset)
473505   {
474506      case 0:   /* n/a */
r11727r11728
499531             *      1 0      250 kbps
500532             *      1 1     1000 kbps
501533             */
534         pc_fdc_data_rate_w(space->machine(), data & 3);
502535         break;
503536   }
504537}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team