src/mess/machine/wd17xx.c
| r8584 | r8585 | |
| 377 | 377 | static void wd17xx_complete_command(running_device *device, int delay); |
| 378 | 378 | static void wd17xx_timed_data_request(running_device *device); |
| 379 | 379 | static void wd17xx_index_pulse_callback(running_device *controller, running_device *img, int state); |
| 380 | static int wd17xx_locate_sector(running_device *device); |
| 381 | static void wd17xx_timed_read_sector_request(running_device *device); |
| 380 | 382 | |
| 381 | 383 | |
| 382 | 384 | /***************************************************************************** |
| r8584 | r8585 | |
| 472 | 474 | } |
| 473 | 475 | } |
| 474 | 476 | |
| 475 | | /* set drq after delay */ |
| 477 | /* write next byte to data register and set drq */ |
| 476 | 478 | static TIMER_CALLBACK( wd17xx_data_callback ) |
| 477 | 479 | { |
| 478 | 480 | running_device *device = (running_device *)ptr; |
| 479 | | wd17xx_set_drq(device); |
| 481 | wd1770_state *w = get_safe_token(device); |
| 482 | |
| 483 | /* any bytes remaining? */ |
| 484 | if (w->data_count >= 1) |
| 485 | { |
| 486 | /* yes */ |
| 487 | w->data = w->buffer[w->data_offset++]; |
| 488 | |
| 489 | if (VERBOSE_DATA) |
| 490 | logerror("wd17xx_data_callback: $%02X (data_count %d)\n", w->data, w->data_count); |
| 491 | |
| 492 | wd17xx_set_drq(device); |
| 493 | |
| 494 | /* any bytes remaining? */ |
| 495 | if (--w->data_count < 1) |
| 496 | { |
| 497 | /* no */ |
| 498 | w->data_offset = 0; |
| 499 | |
| 500 | /* clear ddam type */ |
| 501 | w->status &=~STA_2_REC_TYPE; |
| 502 | |
| 503 | /* read a sector with ddam set? */ |
| 504 | if (w->command_type == TYPE_II && w->ddam != 0) |
| 505 | { |
| 506 | /* set it */ |
| 507 | w->status |= STA_2_REC_TYPE; |
| 508 | } |
| 509 | |
| 510 | /* check if we should handle the next sector for a multi record read */ |
| 511 | if (w->command_type == TYPE_II && w->command == FDC_READ_SEC && (w->read_cmd & 0x10)) |
| 512 | { |
| 513 | if (VERBOSE) |
| 514 | logerror("wd17xx_data_callback: multi sector read\n") |
| 515 | |
| 516 | if (w->sector == 0xff) |
| 517 | w->sector = 0x01; |
| 518 | else |
| 519 | w->sector++; |
| 520 | |
| 521 | wd17xx_timed_read_sector_request(device); |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | /* Delay the INTRQ 3 byte times because we need to read two CRC bytes and |
| 526 | compare them with a calculated CRC */ |
| 527 | wd17xx_complete_command(device, DELAY_DATADONE); |
| 528 | |
| 529 | if (VERBOSE) |
| 530 | logerror("wd17xx_data_callback: data read completed\n"); |
| 531 | } |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | /* requeue us for more data */ |
| 536 | timer_adjust_oneshot(w->timer_data, ATTOTIME_IN_USEC(wd17xx_dden(device) ? 128 : 32), 0); |
| 537 | } |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | logerror("wd17xx_data_callback: (no new data) $%02X (data_count %d)\n", w->data, w->data_count); |
| 542 | } |
| 480 | 543 | } |
| 481 | 544 | |
| 482 | 545 | |
| r8584 | r8585 | |
| 793 | 856 | wd17xx_set_busy(device, ATTOTIME_IN_USEC(400)); |
| 794 | 857 | w->busy_count = 0; |
| 795 | 858 | |
| 796 | | wd17xx_set_drq(device); |
| 797 | | |
| 798 | 859 | if (VERBOSE) |
| 799 | 860 | logerror("read id succeeded.\n"); |
| 861 | |
| 862 | wd17xx_timed_data_request(device); |
| 800 | 863 | } |
| 801 | 864 | else |
| 802 | 865 | { |
| r8584 | r8585 | |
| 1050 | 1113 | |
| 1051 | 1114 | |
| 1052 | 1115 | /* callback to initiate write sector */ |
| 1053 | | static TIMER_CALLBACK(wd17xx_write_sector_callback) |
| 1116 | static TIMER_CALLBACK( wd17xx_write_sector_callback ) |
| 1054 | 1117 | { |
| 1055 | 1118 | running_device *device = (running_device *)ptr; |
| 1056 | 1119 | wd1770_state *w = get_safe_token(device); |
| r8584 | r8585 | |
| 1360 | 1423 | { |
| 1361 | 1424 | wd1770_state *w = get_safe_token(device); |
| 1362 | 1425 | |
| 1363 | | if (w->data_count >= 1) |
| 1364 | | { |
| 1365 | | /* clear data request */ |
| 1366 | | wd17xx_clear_drq(device); |
| 1426 | if (VERBOSE_DATA) |
| 1427 | logerror("wd17xx_data_r: %02x\n", w->data); |
| 1367 | 1428 | |
| 1368 | | /* yes */ |
| 1369 | | w->data = w->buffer[w->data_offset++]; |
| 1429 | /* clear data request */ |
| 1430 | wd17xx_clear_drq(device); |
| 1370 | 1431 | |
| 1371 | | if (VERBOSE_DATA) |
| 1372 | | logerror("wd17xx_data_r: $%02X (data_count %d)\n", w->data, w->data_count); |
| 1373 | | |
| 1374 | | /* any bytes remaining? */ |
| 1375 | | if (--w->data_count < 1) |
| 1376 | | { |
| 1377 | | /* no */ |
| 1378 | | w->data_offset = 0; |
| 1379 | | |
| 1380 | | /* clear ddam type */ |
| 1381 | | w->status &=~STA_2_REC_TYPE; |
| 1382 | | /* read a sector with ddam set? */ |
| 1383 | | if (w->command_type == TYPE_II && w->ddam != 0) |
| 1384 | | { |
| 1385 | | /* set it */ |
| 1386 | | w->status |= STA_2_REC_TYPE; |
| 1387 | | } |
| 1388 | | |
| 1389 | | /* Check we should handle the next sector for a multi record read */ |
| 1390 | | if ( w->command_type == TYPE_II && w->command == FDC_READ_SEC && ( w->read_cmd & 0x10 ) ) { |
| 1391 | | w->sector++; |
| 1392 | | if (wd17xx_locate_sector(device)) |
| 1393 | | { |
| 1394 | | w->data_count = w->sector_length; |
| 1395 | | |
| 1396 | | /* read data */ |
| 1397 | | floppy_drive_read_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length); |
| 1398 | | |
| 1399 | | wd17xx_timed_data_request(device); |
| 1400 | | |
| 1401 | | w->status |= STA_2_BUSY; |
| 1402 | | w->busy_count = 0; |
| 1403 | | } |
| 1404 | | else |
| 1405 | | { |
| 1406 | | wd17xx_complete_command(device, DELAY_DATADONE); |
| 1407 | | |
| 1408 | | if (VERBOSE) |
| 1409 | | logerror("wd17xx_data_r(): multi data read completed\n"); |
| 1410 | | } |
| 1411 | | } |
| 1412 | | else |
| 1413 | | { |
| 1414 | | /* Delay the INTRQ 3 byte times because we need to read two CRC bytes and |
| 1415 | | compare them with a calculated CRC */ |
| 1416 | | wd17xx_complete_command(device, DELAY_DATADONE); |
| 1417 | | |
| 1418 | | if (VERBOSE) |
| 1419 | | logerror("wd17xx_data_r(): data read completed\n"); |
| 1420 | | } |
| 1421 | | } |
| 1422 | | else |
| 1423 | | { |
| 1424 | | /* issue a timed data request */ |
| 1425 | | wd17xx_timed_data_request(device); |
| 1426 | | } |
| 1427 | | } |
| 1428 | | else |
| 1429 | | { |
| 1430 | | logerror("wd17xx_data_r: (no new data) $%02X (data_count %d)\n", w->data, w->data_count); |
| 1431 | | } |
| 1432 | | |
| 1433 | 1432 | return w->data; |
| 1434 | 1433 | } |
| 1435 | 1434 | |
| r8584 | r8585 | |
| 1975 | 1974 | w->intf = (const wd17xx_interface*)device->baseconfig().static_config(); |
| 1976 | 1975 | |
| 1977 | 1976 | w->status = STA_1_TRACK0; |
| 1978 | | w->pause_time = 40; |
| 1977 | w->pause_time = 1000; |
| 1979 | 1978 | w->complete_command_delay = 12; |
| 1980 | 1979 | |
| 1981 | 1980 | /* allocate timers */ |