src/mess/machine/upd765.c
| r11727 | r11728 | |
| 81 | 81 | |
| 82 | 82 | #define UPD765_RESET 0x080 |
| 83 | 83 | |
| 84 | #define UPD765_BAD_MEDIA 0x100 |
| 85 | |
| 84 | 86 | typedef struct _upd765_t upd765_t; |
| 85 | 87 | struct _upd765_t |
| 86 | 88 | { |
| r11727 | r11728 | |
| 862 | 864 | /* number of times we have seen index hole */ |
| 863 | 865 | int index_count = 0; |
| 864 | 866 | |
| 867 | if (fdc->upd765_flags & UPD765_BAD_MEDIA) { |
| 868 | fdc->upd765_status[1] |= 1; |
| 869 | return FALSE; |
| 870 | } |
| 871 | |
| 865 | 872 | /* get sector id's */ |
| 866 | 873 | do |
| 867 | 874 | { |
| r11727 | r11728 | |
| 1503 | 1510 | /* sector id == EOT */ |
| 1504 | 1511 | UINT8 ddam; |
| 1505 | 1512 | |
| 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 | |
| 1506 | 1522 | ddam = 0; |
| 1507 | 1523 | if (fdc->command == 0x09) |
| 1508 | 1524 | { |
| r11727 | r11728 | |
| 1930 | 1946 | { |
| 1931 | 1947 | /* is disk inserted? */ |
| 1932 | 1948 | device_image_interface *image = dynamic_cast<device_image_interface *>( img); |
| 1933 | | if (image->exists()) |
| 1949 | if (image!=NULL && image->exists()) |
| 1934 | 1950 | { |
| 1935 | 1951 | int index_count = 0; |
| 1936 | 1952 | |
| r11727 | r11728 | |
| 1949 | 1965 | /* get next id from disc */ |
| 1950 | 1966 | if (floppy_drive_get_next_id(img, fdc->side, &id)) |
| 1951 | 1967 | { |
| 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; |
| 1954 | 1971 | } |
| 1955 | 1972 | |
| 1956 | 1973 | if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_INDEX)) |
| r11727 | r11728 | |
| 1961 | 1978 | } |
| 1962 | 1979 | while (index_count!=2); |
| 1963 | 1980 | |
| 1981 | if (fdc->upd765_flags & UPD765_BAD_MEDIA) |
| 1982 | { |
| 1983 | fdc->upd765_status[0] |= 0x40; |
| 1984 | fdc->upd765_status[1] |= 1; |
| 1985 | } |
| 1986 | |
| 1964 | 1987 | /* at this point, we have seen a id or two index pulses have occured! */ |
| 1965 | 1988 | fdc->upd765_result_bytes[0] = fdc->upd765_status[0]; |
| 1966 | 1989 | fdc->upd765_result_bytes[1] = fdc->upd765_status[1]; |
| r11727 | r11728 | |
| 2208 | 2231 | upd765_set_int(device, 1); |
| 2209 | 2232 | } |
| 2210 | 2233 | |
| 2234 | void 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 | |
| 2211 | 2241 | void upd765_reset(device_t *device, int offset) |
| 2212 | 2242 | { |
| 2213 | 2243 | upd765_t *fdc = get_safe_token(device); |
src/mess/machine/pc_fdc.c
| r11727 | r11728 | |
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | | |
| 331 | 330 | /* PCJr FDC Digitial Output Register (DOR) |
| 332 | 331 | |
| 333 | 332 | On a PC Jr the DOR is wired up a bit differently: |
| r11727 | r11728 | |
| 427 | 426 | fdc->digital_output_register = data; |
| 428 | 427 | } |
| 429 | 428 | |
| 429 | #define RATE_250 2 |
| 430 | #define RATE_300 1 |
| 431 | #define RATE_500 0 |
| 432 | #define RATE_1000 3 |
| 430 | 433 | |
| 434 | static 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, §ors); |
| 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 | |
| 431 | 462 | READ8_HANDLER ( pc_fdc_r ) |
| 432 | 463 | { |
| 433 | 464 | UINT8 data = 0xff; |
| r11727 | r11728 | |
| 469 | 500 | if (LOG_FDC) |
| 470 | 501 | logerror("pc_fdc_w(): pc=0x%08x offset=%d data=0x%02X\n", (unsigned) cpu_get_reg(space->machine().firstcpu,STATE_GENPC), offset, data); |
| 471 | 502 | |
| 503 | pc_fdc_check_data_rate(space->machine()); // check every time a command may start |
| 472 | 504 | switch(offset) |
| 473 | 505 | { |
| 474 | 506 | case 0: /* n/a */ |
| r11727 | r11728 | |
| 499 | 531 | * 1 0 250 kbps |
| 500 | 532 | * 1 1 1000 kbps |
| 501 | 533 | */ |
| 534 | pc_fdc_data_rate_w(space->machine(), data & 3); |
| 502 | 535 | break; |
| 503 | 536 | } |
| 504 | 537 | } |