src/mess/machine/nec765.c
| r3836 | r3837 | |
| 125 | 125 | static int nec765_sector_count_complete(running_machine *machine); |
| 126 | 126 | static void nec765_increment_sector(running_machine *machine); |
| 127 | 127 | static void nec765_update_state(running_machine *machine); |
| 128 | | static void nec765_set_dma_drq(int state); |
| 129 | | static void nec765_set_int(int state); |
| 128 | static void nec765_set_dma_drq(running_machine *machine,int state); |
| 129 | static void nec765_set_int(running_machine *machine,int state); |
| 130 | 130 | |
| 131 | 131 | static NEC765 fdc; |
| 132 | 132 | static char nec765_data_buffer[32*1024]; |
| r3836 | r3837 | |
| 154 | 154 | } |
| 155 | 155 | else |
| 156 | 156 | { |
| 157 | | image = nec765_iface.get_image(fdc.drive); |
| 157 | image = nec765_iface.get_image(machine, fdc.drive); |
| 158 | 158 | } |
| 159 | 159 | return image; |
| 160 | 160 | } |
| r3836 | r3837 | |
| 305 | 305 | /* set drive and side */ |
| 306 | 306 | fdc.nec765_status[0] |= fdc.drive | (fdc.side<<2); |
| 307 | 307 | |
| 308 | | nec765_set_int(0); |
| 309 | | nec765_set_int(1); |
| 308 | nec765_set_int(machine,0); |
| 309 | nec765_set_int(machine,1); |
| 310 | 310 | |
| 311 | 311 | fdc.nec765_flags &= ~NEC765_SEEK_ACTIVE; |
| 312 | 312 | } |
| r3836 | r3837 | |
| 319 | 319 | timer_reset(fdc.seek_timer, attotime_never); |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | | static void nec765_timer_func(int timer_type) |
| 322 | static void nec765_timer_func(running_machine *machine, int timer_type) |
| 323 | 323 | { |
| 324 | 324 | /* type 0 = data transfer mode in execution phase */ |
| 325 | 325 | if (fdc.timer_type == 0) |
| r3836 | r3837 | |
| 336 | 336 | } |
| 337 | 337 | else |
| 338 | 338 | { |
| 339 | | nec765_timer_func(fdc.timer_type); |
| 339 | nec765_timer_func(machine, fdc.timer_type); |
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | else if (fdc.timer_type==2) |
| r3836 | r3837 | |
| 355 | 355 | case 17: /* scan equal */ |
| 356 | 356 | case 19: /* scan low or equal */ |
| 357 | 357 | case 29: /* scan high or equal */ |
| 358 | | nec765_set_int(1); |
| 358 | nec765_set_int(machine,1); |
| 359 | 359 | break; |
| 360 | 360 | |
| 361 | 361 | default: |
| r3836 | r3837 | |
| 372 | 372 | a int is generated per byte */ |
| 373 | 373 | if (fdc.nec765_flags & NEC765_DMA_MODE) |
| 374 | 374 | { |
| 375 | | nec765_set_dma_drq(1); |
| 375 | nec765_set_dma_drq(machine,1); |
| 376 | 376 | } |
| 377 | 377 | else |
| 378 | 378 | { |
| 379 | 379 | if (fdc.FDC_main & (1<<7)) |
| 380 | 380 | { |
| 381 | 381 | /* set int to indicate data is ready */ |
| 382 | | nec765_set_int(1); |
| 382 | nec765_set_int(machine,1); |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
| r3836 | r3837 | |
| 389 | 389 | |
| 390 | 390 | static TIMER_CALLBACK(nec765_timer_callback) |
| 391 | 391 | { |
| 392 | | nec765_timer_func(param); |
| 392 | nec765_timer_func(machine,param); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /* after (32-27) the DRQ is set, then 27 us later, the int is set. |
| r3836 | r3837 | |
| 398 | 398 | effectively disabled by reading the data before the NMI int can be set. |
| 399 | 399 | */ |
| 400 | 400 | |
| 401 | | static void nec765_setup_timed_generic(int timer_type, attotime duration) |
| 401 | static void nec765_setup_timed_generic(running_machine *machine, int timer_type, attotime duration) |
| 402 | 402 | { |
| 403 | 403 | fdc.timer_type = timer_type; |
| 404 | 404 | |
| r3836 | r3837 | |
| 408 | 408 | } |
| 409 | 409 | else |
| 410 | 410 | { |
| 411 | | nec765_timer_func(fdc.timer_type); |
| 411 | nec765_timer_func(machine,fdc.timer_type); |
| 412 | 412 | timer_reset(fdc.timer, attotime_never); |
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /* setup data request */ |
| 417 | | static void nec765_setup_timed_data_request(int bytes) |
| 417 | static void nec765_setup_timed_data_request(running_machine *machine, int bytes) |
| 418 | 418 | { |
| 419 | 419 | /* setup timer to trigger in NEC765_DATA_RATE us */ |
| 420 | | nec765_setup_timed_generic(0, ATTOTIME_IN_USEC(32-27) /*NEC765_DATA_RATE)*bytes*/); |
| 420 | nec765_setup_timed_generic(machine, 0, ATTOTIME_IN_USEC(32-27) /*NEC765_DATA_RATE)*bytes*/); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /* setup result data request */ |
| 424 | | static void nec765_setup_timed_result_data_request(void) |
| 424 | static void nec765_setup_timed_result_data_request(running_machine *machine) |
| 425 | 425 | { |
| 426 | | nec765_setup_timed_generic(2, ATTOTIME_IN_USEC(NEC765_DATA_RATE*2)); |
| 426 | nec765_setup_timed_generic(machine, 2, ATTOTIME_IN_USEC(NEC765_DATA_RATE*2)); |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | |
| r3836 | r3837 | |
| 535 | 535 | |
| 536 | 536 | |
| 537 | 537 | |
| 538 | | static void nec765_setup_execution_phase_read(char *ptr, int size) |
| 538 | static void nec765_setup_execution_phase_read(running_machine *machine, char *ptr, int size) |
| 539 | 539 | { |
| 540 | 540 | fdc.FDC_main |= 0x040; /* FDC->CPU */ |
| 541 | 541 | |
| r3836 | r3837 | |
| 544 | 544 | fdc.execution_phase_data = ptr; |
| 545 | 545 | fdc.nec765_phase = NEC765_EXECUTION_PHASE_READ; |
| 546 | 546 | |
| 547 | | nec765_setup_timed_data_request(1); |
| 547 | nec765_setup_timed_data_request(machine, 1); |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | | static void nec765_setup_execution_phase_write(char *ptr, int size) |
| 550 | static void nec765_setup_execution_phase_write(running_machine *machine, char *ptr, int size) |
| 551 | 551 | { |
| 552 | 552 | fdc.FDC_main &= ~0x040; /* FDC->CPU */ |
| 553 | 553 | |
| r3836 | r3837 | |
| 557 | 557 | fdc.nec765_phase = NEC765_EXECUTION_PHASE_WRITE; |
| 558 | 558 | |
| 559 | 559 | /* setup a data request with first byte */ |
| 560 | | nec765_setup_timed_data_request(1); |
| 560 | nec765_setup_timed_data_request(machine,1); |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | |
| 564 | | static void nec765_setup_result_phase(int byte_count) |
| 564 | static void nec765_setup_result_phase(running_machine *machine, int byte_count) |
| 565 | 565 | { |
| 566 | 566 | fdc.FDC_main |= 0x040; /* FDC->CPU */ |
| 567 | 567 | fdc.FDC_main &= ~0x020; /* not execution phase */ |
| r3836 | r3837 | |
| 570 | 570 | fdc.nec765_transfer_bytes_remaining = byte_count; |
| 571 | 571 | fdc.nec765_phase = NEC765_RESULT_PHASE; |
| 572 | 572 | |
| 573 | | nec765_setup_timed_result_data_request(); |
| 573 | nec765_setup_timed_result_data_request(machine); |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | void nec765_idle(void) |
| r3836 | r3837 | |
| 586 | 586 | |
| 587 | 587 | |
| 588 | 588 | /* change flags */ |
| 589 | | static void nec765_change_flags(unsigned int flags, unsigned int mask) |
| 589 | static void nec765_change_flags(running_machine *machine,unsigned int flags, unsigned int mask) |
| 590 | 590 | { |
| 591 | 591 | unsigned int new_flags; |
| 592 | 592 | unsigned int changed_flags; |
| r3836 | r3837 | |
| 601 | 601 | |
| 602 | 602 | /* if interrupt changed, call the handler */ |
| 603 | 603 | if ((changed_flags & NEC765_INT) && nec765_iface.interrupt) |
| 604 | | nec765_iface.interrupt((fdc.nec765_flags & NEC765_INT) ? 1 : 0); |
| 604 | nec765_iface.interrupt(machine,(fdc.nec765_flags & NEC765_INT) ? 1 : 0); |
| 605 | 605 | |
| 606 | 606 | /* if DRQ changed, call the handler */ |
| 607 | 607 | if ((changed_flags & NEC765_DMA_DRQ) && nec765_iface.dma_drq) |
| 608 | | nec765_iface.dma_drq((fdc.nec765_flags & NEC765_DMA_DRQ) ? 1 : 0, fdc.FDC_main & (1<<6)); |
| 608 | nec765_iface.dma_drq(machine,(fdc.nec765_flags & NEC765_DMA_DRQ) ? 1 : 0, fdc.FDC_main & (1<<6)); |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | |
| 612 | 612 | |
| 613 | 613 | /* set int output */ |
| 614 | | static void nec765_set_int(int state) |
| 614 | static void nec765_set_int(running_machine *machine, int state) |
| 615 | 615 | { |
| 616 | 616 | if (LOG_INTERRUPT) |
| 617 | 617 | logerror("nec765_set_int(): state=%d\n", state); |
| 618 | | nec765_change_flags(state ? NEC765_INT : 0, NEC765_INT); |
| 618 | nec765_change_flags(machine, state ? NEC765_INT : 0, NEC765_INT); |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | |
| 622 | 622 | |
| 623 | 623 | /* set dma request output */ |
| 624 | | static void nec765_set_dma_drq(int state) |
| 624 | static void nec765_set_dma_drq(running_machine *machine, int state) |
| 625 | 625 | { |
| 626 | | nec765_change_flags(state ? NEC765_DMA_DRQ : 0, NEC765_DMA_DRQ); |
| 626 | nec765_change_flags(machine, state ? NEC765_DMA_DRQ : 0, NEC765_DMA_DRQ); |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | |
| r3836 | r3837 | |
| 670 | 670 | fdc.nec765_status[0] |= 8; |
| 671 | 671 | |
| 672 | 672 | /* trigger an int */ |
| 673 | | nec765_set_int(1); |
| 673 | nec765_set_int(img->machine, 1); |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | |
| r3836 | r3837 | |
| 709 | 709 | old_state = fdc.nec765_flags; |
| 710 | 710 | |
| 711 | 711 | /* clear drq */ |
| 712 | | nec765_set_dma_drq(0); |
| 712 | nec765_set_dma_drq(machine, 0); |
| 713 | 713 | |
| 714 | 714 | fdc.nec765_flags &= ~NEC765_TC; |
| 715 | 715 | if (state) |
| r3836 | r3837 | |
| 892 | 892 | return 0; |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | | static void nec765_read_complete(void) |
| 895 | static void nec765_read_complete(running_machine *machine) |
| 896 | 896 | { |
| 897 | 897 | |
| 898 | 898 | /* causes problems!!! - need to fix */ |
| r3836 | r3837 | |
| 926 | 926 | fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */ |
| 927 | 927 | fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */ |
| 928 | 928 | |
| 929 | | nec765_setup_result_phase(7); |
| 929 | nec765_setup_result_phase(machine,7); |
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | static void nec765_read_data(running_machine *machine) |
| r3836 | r3837 | |
| 946 | 946 | fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */ |
| 947 | 947 | fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */ |
| 948 | 948 | fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */ |
| 949 | | nec765_setup_result_phase(7); |
| 949 | nec765_setup_result_phase(machine,7); |
| 950 | 950 | return; |
| 951 | 951 | } |
| 952 | 952 | |
| r3836 | r3837 | |
| 974 | 974 | if (nec765_sector_count_complete(machine)) |
| 975 | 975 | { |
| 976 | 976 | /* read complete */ |
| 977 | | nec765_read_complete(); |
| 977 | nec765_read_complete(machine); |
| 978 | 978 | return; |
| 979 | 979 | } |
| 980 | 980 | |
| r3836 | r3837 | |
| 992 | 992 | else |
| 993 | 993 | { |
| 994 | 994 | /* error in finding sector */ |
| 995 | | nec765_read_complete(); |
| 995 | nec765_read_complete(machine); |
| 996 | 996 | return; |
| 997 | 997 | } |
| 998 | 998 | } |
| r3836 | r3837 | |
| 1006 | 1006 | |
| 1007 | 1007 | floppy_drive_read_sector_data(img, fdc.side, fdc.sector_id,nec765_data_buffer,data_size); |
| 1008 | 1008 | |
| 1009 | | nec765_setup_execution_phase_read(nec765_data_buffer, data_size); |
| 1009 | nec765_setup_execution_phase_read(machine,nec765_data_buffer, data_size); |
| 1010 | 1010 | } |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| r3836 | r3837 | |
| 1029 | 1029 | fdc.nec765_result_bytes[4] = fdc.format_data[1]; |
| 1030 | 1030 | fdc.nec765_result_bytes[5] = fdc.format_data[2]; |
| 1031 | 1031 | fdc.nec765_result_bytes[6] = fdc.format_data[3]; |
| 1032 | | nec765_setup_result_phase(7); |
| 1032 | nec765_setup_result_phase(machine,7); |
| 1033 | 1033 | |
| 1034 | 1034 | return; |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | | nec765_setup_execution_phase_write(&fdc.format_data[0], 4); |
| 1037 | nec765_setup_execution_phase_write(machine, &fdc.format_data[0], 4); |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | static void nec765_read_a_track(running_machine *machine) |
| r3836 | r3837 | |
| 1071 | 1071 | |
| 1072 | 1072 | floppy_drive_read_sector_data(current_image(machine), fdc.side, fdc.sector_id,nec765_data_buffer,data_size); |
| 1073 | 1073 | |
| 1074 | | nec765_setup_execution_phase_read(nec765_data_buffer, data_size); |
| 1074 | nec765_setup_execution_phase_read(machine,nec765_data_buffer, data_size); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | static int nec765_just_read_last_sector_on_track(running_machine *machine) |
| r3836 | r3837 | |
| 1081 | 1081 | return 0; |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | | static void nec765_write_complete(void) |
| 1084 | static void nec765_write_complete(running_machine *machine) |
| 1085 | 1085 | { |
| 1086 | 1086 | |
| 1087 | 1087 | /* causes problems!!! - need to fix */ |
| r3836 | r3837 | |
| 1115 | 1115 | fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */ |
| 1116 | 1116 | fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */ |
| 1117 | 1117 | |
| 1118 | | nec765_setup_result_phase(7); |
| 1118 | nec765_setup_result_phase(machine,7); |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | |
| r3836 | r3837 | |
| 1134 | 1134 | fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */ |
| 1135 | 1135 | fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */ |
| 1136 | 1136 | fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */ |
| 1137 | | nec765_setup_result_phase(7); |
| 1137 | nec765_setup_result_phase(machine,7); |
| 1138 | 1138 | return; |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| r3836 | r3837 | |
| 1143 | 1143 | { |
| 1144 | 1144 | fdc.nec765_status[1] |= NEC765_ST1_NOT_WRITEABLE; |
| 1145 | 1145 | |
| 1146 | | nec765_write_complete(); |
| 1146 | nec765_write_complete(machine); |
| 1147 | 1147 | return; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| r3836 | r3837 | |
| 1153 | 1153 | |
| 1154 | 1154 | data_size = nec765_n_to_bytes(fdc.nec765_command_bytes[5]); |
| 1155 | 1155 | |
| 1156 | | nec765_setup_execution_phase_write(nec765_data_buffer, data_size); |
| 1156 | nec765_setup_execution_phase_write(machine,nec765_data_buffer, data_size); |
| 1157 | 1157 | } |
| 1158 | 1158 | else |
| 1159 | 1159 | { |
| 1160 | | nec765_setup_result_phase(7); |
| 1160 | nec765_setup_result_phase(machine,7); |
| 1161 | 1161 | } |
| 1162 | 1162 | } |
| 1163 | 1163 | |
| r3836 | r3837 | |
| 1404 | 1404 | fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */ |
| 1405 | 1405 | fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */ |
| 1406 | 1406 | |
| 1407 | | nec765_setup_result_phase(7); |
| 1407 | nec765_setup_result_phase(machine,7); |
| 1408 | 1408 | } |
| 1409 | 1409 | else |
| 1410 | 1410 | { |
| r3836 | r3837 | |
| 1434 | 1434 | fdc.nec765_result_bytes[4] = fdc.format_data[1]; |
| 1435 | 1435 | fdc.nec765_result_bytes[5] = fdc.format_data[2]; |
| 1436 | 1436 | fdc.nec765_result_bytes[6] = fdc.format_data[3]; |
| 1437 | | nec765_setup_result_phase(7); |
| 1437 | nec765_setup_result_phase(machine,7); |
| 1438 | 1438 | } |
| 1439 | 1439 | else |
| 1440 | 1440 | { |
| r3836 | r3837 | |
| 1462 | 1462 | if (nec765_sector_count_complete(machine)) |
| 1463 | 1463 | { |
| 1464 | 1464 | nec765_increment_sector(machine); |
| 1465 | | nec765_write_complete(); |
| 1465 | nec765_write_complete(machine); |
| 1466 | 1466 | } |
| 1467 | 1467 | else |
| 1468 | 1468 | { |
| r3836 | r3837 | |
| 1482 | 1482 | /* sector id == EOT */ |
| 1483 | 1483 | if (nec765_sector_count_complete(machine) || nec765_read_data_stop()) |
| 1484 | 1484 | { |
| 1485 | | nec765_read_complete(); |
| 1485 | nec765_read_complete(machine); |
| 1486 | 1486 | } |
| 1487 | 1487 | else |
| 1488 | 1488 | { |
| r3836 | r3837 | |
| 1573 | 1573 | case 17: /* scan equal */ |
| 1574 | 1574 | case 19: /* scan low or equal */ |
| 1575 | 1575 | case 29: /* scan high or equal */ |
| 1576 | | nec765_set_int(0); |
| 1576 | nec765_set_int(machine, 0); |
| 1577 | 1577 | break; |
| 1578 | 1578 | |
| 1579 | 1579 | default: |
| r3836 | r3837 | |
| 1613 | 1613 | else |
| 1614 | 1614 | { |
| 1615 | 1615 | /* trigger int */ |
| 1616 | | nec765_setup_timed_data_request(1); |
| 1616 | nec765_setup_timed_data_request(machine,1); |
| 1617 | 1617 | } |
| 1618 | 1618 | break; |
| 1619 | 1619 | |
| r3836 | r3837 | |
| 1680 | 1680 | } |
| 1681 | 1681 | else |
| 1682 | 1682 | { |
| 1683 | | nec765_setup_timed_data_request(1); |
| 1683 | nec765_setup_timed_data_request(machine,1); |
| 1684 | 1684 | } |
| 1685 | 1685 | break; |
| 1686 | 1686 | } |
| r3836 | r3837 | |
| 1697 | 1697 | { |
| 1698 | 1698 | |
| 1699 | 1699 | /* reading the data byte clears the interrupt */ |
| 1700 | | nec765_set_int(CLEAR_LINE); |
| 1700 | nec765_set_int(space->machine,CLEAR_LINE); |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | /* reset data request */ |
| r3836 | r3837 | |
| 1729 | 1729 | { |
| 1730 | 1730 | |
| 1731 | 1731 | /* reading the data byte clears the interrupt */ |
| 1732 | | nec765_set_int(CLEAR_LINE); |
| 1732 | nec765_set_int(space->machine, CLEAR_LINE); |
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | 1735 | /* reset data request */ |
| r3836 | r3837 | |
| 1740 | 1740 | } |
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | | static void nec765_setup_invalid(void) |
| 1743 | static void nec765_setup_invalid(running_machine *machine) |
| 1744 | 1744 | { |
| 1745 | 1745 | fdc.command = 0; |
| 1746 | 1746 | fdc.nec765_result_bytes[0] = 0x080; |
| 1747 | | nec765_setup_result_phase(1); |
| 1747 | nec765_setup_result_phase(machine,1); |
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | static void nec765_setup_command(running_machine *machine) |
| r3836 | r3837 | |
| 1832 | 1832 | |
| 1833 | 1833 | /* two side and fault not set but should be? */ |
| 1834 | 1834 | fdc.nec765_result_bytes[0] = fdc.nec765_status[3]; |
| 1835 | | nec765_setup_result_phase(1); |
| 1835 | nec765_setup_result_phase(machine,1); |
| 1836 | 1836 | break; |
| 1837 | 1837 | |
| 1838 | 1838 | case 0x07: /* recalibrate */ |
| r3836 | r3837 | |
| 1894 | 1894 | fdc.nec765_result_bytes[5] = id.R; /* R */ |
| 1895 | 1895 | fdc.nec765_result_bytes[6] = id.N; /* N */ |
| 1896 | 1896 | |
| 1897 | | nec765_setup_result_phase(7); |
| 1897 | nec765_setup_result_phase(machine,7); |
| 1898 | 1898 | } |
| 1899 | 1899 | else |
| 1900 | 1900 | { |
| r3836 | r3837 | |
| 1926 | 1926 | if (fdc.nec765_flags & NEC765_INT) |
| 1927 | 1927 | { |
| 1928 | 1928 | /* yes. Clear int */ |
| 1929 | | nec765_set_int(CLEAR_LINE); |
| 1929 | nec765_set_int(machine, CLEAR_LINE); |
| 1930 | 1930 | |
| 1931 | 1931 | /* clear drive seek bits */ |
| 1932 | 1932 | fdc.FDC_main &= ~(1 | 2 | 4 | 8); |
| r3836 | r3837 | |
| 1937 | 1937 | fdc.nec765_result_bytes[1] = fdc.pcn[fdc.drive]; |
| 1938 | 1938 | |
| 1939 | 1939 | /* return result */ |
| 1940 | | nec765_setup_result_phase(2); |
| 1940 | nec765_setup_result_phase(machine,2); |
| 1941 | 1941 | } |
| 1942 | 1942 | else |
| 1943 | 1943 | { |
| 1944 | 1944 | if(fdc.version == NEC72065 && (fdc.FDC_main & 0x0f) == 0x00) |
| 1945 | 1945 | { // based on XM6 |
| 1946 | | nec765_setup_invalid(); |
| 1946 | nec765_setup_invalid(machine); |
| 1947 | 1947 | } |
| 1948 | 1948 | else |
| 1949 | 1949 | { |
| r3836 | r3837 | |
| 1953 | 1953 | fdc.nec765_result_bytes[1] = fdc.pcn[fdc.drive]; |
| 1954 | 1954 | |
| 1955 | 1955 | /* return result */ |
| 1956 | | nec765_setup_result_phase(2); |
| 1956 | nec765_setup_result_phase(machine,2); |
| 1957 | 1957 | } |
| 1958 | 1958 | } |
| 1959 | 1959 | break; |
| r3836 | r3837 | |
| 2042 | 2042 | { |
| 2043 | 2043 | case NEC765A: |
| 2044 | 2044 | case NEC72065: |
| 2045 | | nec765_setup_invalid(); |
| 2045 | nec765_setup_invalid(machine); |
| 2046 | 2046 | break; |
| 2047 | 2047 | |
| 2048 | 2048 | case NEC765B: |
| r3836 | r3837 | |
| 2052 | 2052 | /* version */ |
| 2053 | 2053 | fdc.nec765_status[0] = 0x090; |
| 2054 | 2054 | fdc.nec765_result_bytes[0] = fdc.nec765_status[0]; |
| 2055 | | nec765_setup_result_phase(1); |
| 2055 | nec765_setup_result_phase(machine,1); |
| 2056 | 2056 | } |
| 2057 | 2057 | break; |
| 2058 | 2058 | |
| r3836 | r3837 | |
| 2063 | 2063 | case 0x10: /* version */ |
| 2064 | 2064 | fdc.nec765_status[0] = 0x90; |
| 2065 | 2065 | fdc.nec765_result_bytes[0] = fdc.nec765_status[0]; |
| 2066 | | nec765_setup_result_phase(1); |
| 2066 | nec765_setup_result_phase(machine,1); |
| 2067 | 2067 | break; |
| 2068 | 2068 | |
| 2069 | 2069 | case 0x13: /* configure */ |
| r3836 | r3837 | |
| 2076 | 2076 | fdc.nec765_result_bytes[2] = fdc.pcn[2]; |
| 2077 | 2077 | fdc.nec765_result_bytes[3] = fdc.pcn[3]; |
| 2078 | 2078 | |
| 2079 | | nec765_setup_result_phase(10); |
| 2079 | nec765_setup_result_phase(machine,10); |
| 2080 | 2080 | break; |
| 2081 | 2081 | |
| 2082 | 2082 | case 0x12: /* perpendicular mode */ |
| r3836 | r3837 | |
| 2084 | 2084 | break; |
| 2085 | 2085 | |
| 2086 | 2086 | case 0x14: /* lock */ |
| 2087 | | nec765_setup_result_phase(1); |
| 2087 | nec765_setup_result_phase(machine,1); |
| 2088 | 2088 | break; |
| 2089 | 2089 | } |
| 2090 | 2090 | break; |
| r3836 | r3837 | |
| 2097 | 2097 | WRITE8_HANDLER(nec765_dack_w) |
| 2098 | 2098 | { |
| 2099 | 2099 | /* clear request */ |
| 2100 | | nec765_set_dma_drq(CLEAR_LINE); |
| 2100 | nec765_set_dma_drq(space->machine, CLEAR_LINE); |
| 2101 | 2101 | |
| 2102 | 2102 | /* write data */ |
| 2103 | 2103 | nec765_data_w(space, offset, data); |
| r3836 | r3837 | |
| 2106 | 2106 | READ8_HANDLER(nec765_dack_r) |
| 2107 | 2107 | { |
| 2108 | 2108 | /* clear data request */ |
| 2109 | | nec765_set_dma_drq(CLEAR_LINE); |
| 2109 | nec765_set_dma_drq(space->machine,CLEAR_LINE); |
| 2110 | 2110 | |
| 2111 | 2111 | /* read data */ |
| 2112 | 2112 | return nec765_data_r(space, offset); |
| r3836 | r3837 | |
| 2119 | 2119 | nec765_idle(); |
| 2120 | 2120 | |
| 2121 | 2121 | /* set int low */ |
| 2122 | | nec765_set_int(0); |
| 2122 | nec765_set_int(machine, 0); |
| 2123 | 2123 | /* set dma drq output */ |
| 2124 | | nec765_set_dma_drq(0); |
| 2124 | nec765_set_dma_drq(machine,0); |
| 2125 | 2125 | |
| 2126 | 2126 | /* tandy 100hx assumes that after NEC is reset, it is in DMA mode */ |
| 2127 | 2127 | fdc.nec765_flags |= NEC765_DMA_MODE; |
| r3836 | r3837 | |
| 2154 | 2154 | fdc.nec765_status[0] |= 0x08; |
| 2155 | 2155 | } |
| 2156 | 2156 | |
| 2157 | | nec765_set_int(1); |
| 2157 | nec765_set_int(machine, 1); |
| 2158 | 2158 | } |
| 2159 | 2159 | } |
| 2160 | 2160 | |
| r3836 | r3837 | |
| 2174 | 2174 | { |
| 2175 | 2175 | fdc.nec765_flags |= NEC765_RESET; |
| 2176 | 2176 | |
| 2177 | | nec765_set_int(0); |
| 2177 | nec765_set_int(machine, 0); |
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | 2180 | /* reset changed state? */ |
src/mess/machine/i8271.c
| r3836 | r3837 | |
| 4 | 4 | |
| 5 | 5 | /* TODO: |
| 6 | 6 | |
| 7 | | - Scan commands |
| 8 | | - Check the commands work properly using a BBC disc copier program |
| 7 | - Scan commands |
| 8 | - Check the commands work properly using a BBC disc copier program |
| 9 | 9 | - check if 0 is specified as number of sectors, how many sectors |
| 10 | 10 | is actually transfered |
| 11 | | - deleted data functions (error if data finds deleted data?) |
| 11 | - deleted data functions (error if data finds deleted data?) |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | #include "driver.h" |
| 16 | | #include "deprecat.h" |
| 17 | 16 | #include "i8271.h" |
| 18 | 17 | #include "devices/flopdrv.h" |
| 19 | 18 | |
| 19 | /* data request */ |
| 20 | #define I8271_FLAGS_DATA_REQUEST 0x01 |
| 21 | /* data direction. If 0x02, then it is from fdc to cpu, else |
| 22 | it is from cpu to fdc */ |
| 23 | #define I8271_FLAGS_DATA_DIRECTION 0x02 |
| 20 | 24 | |
| 21 | | I8271_STATE_t I8271_STATE; |
| 25 | typedef struct _i8271_t i8271_t; |
| 26 | struct _i8271_t |
| 27 | { |
| 28 | int flags; |
| 29 | int state; |
| 30 | unsigned char Command; |
| 31 | unsigned char StatusRegister; |
| 32 | unsigned char CommandRegister; |
| 33 | unsigned char ResultRegister; |
| 34 | unsigned char ParameterRegister; |
| 35 | unsigned char ResetRegister; |
| 36 | unsigned char data; |
| 22 | 37 | |
| 23 | | static void i8271_command_execute(void); |
| 24 | | static void i8271_command_continue(void); |
| 25 | | static void i8271_command_complete(int result, int int_rq); |
| 26 | | static void i8271_data_request(void); |
| 27 | | static void i8271_timed_data_request(void); |
| 38 | /* number of parameters required after command is specified */ |
| 39 | unsigned long ParameterCount; |
| 40 | /* number of parameters written so far */ |
| 41 | unsigned long ParameterCountWritten; |
| 42 | |
| 43 | unsigned char CommandParameters[8]; |
| 44 | |
| 45 | /* current track for each drive */ |
| 46 | unsigned long CurrentTrack[2]; |
| 47 | |
| 48 | /* 2 bad tracks for drive 0, followed by 2 bad tracks for drive 1 */ |
| 49 | unsigned long BadTracks[4]; |
| 50 | |
| 51 | /* mode special register */ |
| 52 | unsigned long Mode; |
| 53 | |
| 54 | |
| 55 | /* drive outputs */ |
| 56 | int drive; |
| 57 | int side; |
| 58 | |
| 59 | /* drive control output special register */ |
| 60 | int drive_control_output; |
| 61 | /* drive control input special register */ |
| 62 | int drive_control_input; |
| 63 | |
| 64 | unsigned long StepRate; |
| 65 | unsigned long HeadSettlingTime; |
| 66 | unsigned long IndexCountBeforeHeadUnload; |
| 67 | unsigned long HeadLoadTime; |
| 68 | |
| 69 | /* id on disc to find */ |
| 70 | int ID_C; |
| 71 | int ID_H; |
| 72 | int ID_R; |
| 73 | int ID_N; |
| 74 | |
| 75 | /* id of data for read/write */ |
| 76 | int data_id; |
| 77 | |
| 78 | int ExecutionPhaseTransferCount; |
| 79 | char *pExecutionPhaseData; |
| 80 | int ExecutionPhaseCount; |
| 81 | |
| 82 | /* sector counter and id counter */ |
| 83 | int Counter; |
| 84 | |
| 85 | /* ==0, to cpu, !=0 =from cpu */ |
| 86 | int data_direction; |
| 87 | const i8271_interface *intf; |
| 88 | |
| 89 | void *data_timer; |
| 90 | void *command_complete_timer; |
| 91 | }; |
| 92 | |
| 93 | typedef enum |
| 94 | { |
| 95 | I8271_STATE_EXECUTION_READ = 0, |
| 96 | I8271_STATE_EXECUTION_WRITE |
| 97 | } I8271_STATE_t; |
| 98 | |
| 99 | /* commands accepted */ |
| 100 | #define I8271_COMMAND_SPECIFY 0x035 |
| 101 | #define I8271_COMMAND_SEEK 0x029 |
| 102 | #define I8271_COMMAND_READ_DRIVE_STATUS 0x02c |
| 103 | #define I8271_COMMAND_READ_SPECIAL_REGISTER 0x03d |
| 104 | #define I8271_COMMAND_WRITE_SPECIAL_REGISTER 0x03a |
| 105 | #define I8271_COMMAND_FORMAT 0x023 |
| 106 | #define I8271_COMMAND_READ_ID 0x01b |
| 107 | #define I8271_COMMAND_READ_DATA_SINGLE_RECORD 0x012 |
| 108 | #define I8271_COMMAND_READ_DATA_AND_DELETED_DATA_SINGLE_RECORD 0x016 |
| 109 | #define I8271_COMMAND_WRITE_DATA_SINGLE_RECORD 0x00a |
| 110 | #define I8271_COMMAND_WRITE_DELETED_DATA_SINGLE_RECORD 0x00e |
| 111 | #define I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_SINGLE_RECORD 0x01e |
| 112 | #define I8271_COMMAND_READ_DATA_MULTI_RECORD 0x013 |
| 113 | #define I8271_COMMAND_READ_DATA_AND_DELETED_DATA_MULTI_RECORD 0x017 |
| 114 | #define I8271_COMMAND_WRITE_DATA_MULTI_RECORD 0x00b |
| 115 | #define I8271_COMMAND_WRITE_DELETED_DATA_MULTI_RECORD 0x00f |
| 116 | #define I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_MULTI_RECORD 0x01f |
| 117 | #define I8271_COMMAND_SCAN_DATA 0x000 |
| 118 | #define I8271_COMMAND_SCAN_DATA_AND_DELETED_DATA 0x004 |
| 119 | |
| 120 | /* |
| 121 | #define I8271_COMMAND_READ_OPERATION (1<<4) |
| 122 | #define I8271_COMMAND_DELETED_DATA (1<<2) |
| 123 | #define I8271_COMMAND_MULTI_RECORD (1<<0) |
| 124 | */ |
| 125 | |
| 126 | |
| 127 | |
| 128 | /* first parameter for specify command */ |
| 129 | #define I8271_SPECIFY_INITIALIZATION 0x0d |
| 130 | #define I8271_SPECIFY_LOAD_BAD_TRACKS_SURFACE_0 0x010 |
| 131 | #define I8271_SPECIFY_LOAD_BAD_TRACKS_SURFACE_1 0x018 |
| 132 | |
| 133 | /* first parameter for read/write special register */ |
| 134 | #define I8271_SPECIAL_REGISTER_SCAN_SECTOR_NUMBER 0x06 |
| 135 | #define I8271_SPECIAL_REGISTER_SCAN_MSB_OF_COUNT 0x014 |
| 136 | #define I8271_SPECIAL_REGISTER_SCAN_LSB_OF_COUNT 0x013 |
| 137 | #define I8271_SPECIAL_REGISTER_SURFACE_0_CURRENT_TRACK 0x012 |
| 138 | #define I8271_SPECIAL_REGISTER_SURFACE_1_CURRENT_TRACK 0x01a |
| 139 | #define I8271_SPECIAL_REGISTER_MODE_REGISTER 0x017 |
| 140 | #define I8271_SPECIAL_REGISTER_DRIVE_CONTROL_OUTPUT_PORT 0x023 |
| 141 | #define I8271_SPECIAL_REGISTER_DRIVE_CONTROL_INPUT_PORT 0x022 |
| 142 | #define I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_1 0x010 |
| 143 | #define I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_2 0x011 |
| 144 | #define I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_1 0x018 |
| 145 | #define I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_2 0x019 |
| 146 | |
| 147 | |
| 148 | /* status register bits */ |
| 149 | #define I8271_STATUS_COMMAND_BUSY 0x080 |
| 150 | #define I8271_STATUS_COMMAND_FULL 0x040 |
| 151 | #define I8271_STATUS_PARAMETER_FULL 0x020 |
| 152 | #define I8271_STATUS_RESULT_FULL 0x010 |
| 153 | #define I8271_STATUS_INT_REQUEST 0x008 |
| 154 | #define I8271_STATUS_NON_DMA_REQUEST 0x004 |
| 155 | |
| 156 | static void i8271_command_execute(const device_config *device); |
| 157 | static void i8271_command_continue(const device_config *device); |
| 158 | static void i8271_command_complete(const device_config *device,int result, int int_rq); |
| 159 | static void i8271_data_request(const device_config *device); |
| 160 | static void i8271_timed_data_request(const device_config *device); |
| 28 | 161 | /* locate sector for read/write operation */ |
| 29 | | static int i8271_find_sector(void); |
| 162 | static int i8271_find_sector(const device_config *device); |
| 30 | 163 | /* do a read operation */ |
| 31 | | static void i8271_do_read(void); |
| 32 | | static void i8271_do_write(void); |
| 33 | | static void i8271_do_read_id(void); |
| 34 | | static void i8271_set_irq_state(int); |
| 35 | | static void i8271_set_dma_drq(void); |
| 164 | static void i8271_do_read(const device_config *device); |
| 165 | static void i8271_do_write(const device_config *device); |
| 166 | static void i8271_do_read_id(const device_config *device); |
| 167 | static void i8271_set_irq_state(const device_config *device,int); |
| 168 | static void i8271_set_dma_drq(const device_config *device); |
| 36 | 169 | |
| 37 | 170 | static TIMER_CALLBACK(i8271_data_timer_callback); |
| 38 | 171 | static TIMER_CALLBACK(i8271_timed_command_complete_callback); |
| 39 | 172 | |
| 40 | | static char temp_buffer[16384]; |
| 41 | | |
| 42 | | static I8271 i8271; |
| 43 | | |
| 44 | 173 | #define VERBOSE 0 |
| 45 | 174 | |
| 46 | 175 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 47 | 176 | #define FDC_LOG(x) do { if (VERBOSE) logerror("I8271: %s\n",x); } while (0) |
| 48 | 177 | #define FDC_LOG_COMMAND(x) do { if (VERBOSE) logerror("I8271: COMMAND %s\n",x); } while (0) |
| 49 | 178 | |
| 50 | | static const device_config *current_image(void) |
| 179 | static DEVICE_RESET( i8271 ); |
| 180 | |
| 181 | INLINE i8271_t *get_safe_token(const device_config *device) |
| 51 | 182 | { |
| 52 | | return image_from_devtype_and_index(IO_FLOPPY, i8271.drive); |
| 183 | assert(device != NULL); |
| 184 | assert(device->token != NULL); |
| 185 | |
| 186 | return (i8271_t *)device->token; |
| 53 | 187 | } |
| 54 | 188 | |
| 55 | | void i8271_init(const i8271_interface *iface) |
| 189 | |
| 190 | static const device_config *current_image(const device_config *device) |
| 56 | 191 | { |
| 57 | | memset(&i8271, 0, sizeof(I8271)); |
| 58 | | |
| 59 | | if (iface!=NULL) |
| 60 | | { |
| 61 | | memcpy(&i8271.fdc_interface, iface, sizeof(i8271_interface)); |
| 62 | | } |
| 63 | | i8271.data_timer = timer_alloc(Machine, i8271_data_timer_callback, NULL); |
| 64 | | i8271.command_complete_timer = timer_alloc(Machine, i8271_timed_command_complete_callback, NULL); |
| 65 | | i8271.drive = 0; |
| 66 | | i8271.pExecutionPhaseData = temp_buffer; |
| 67 | | |
| 68 | | i8271_reset(); |
| 192 | i8271_t *i8271 = get_safe_token(device); |
| 193 | return image_from_devtype_and_index(IO_FLOPPY, i8271->drive); |
| 69 | 194 | } |
| 70 | 195 | |
| 71 | 196 | |
| 72 | | static void i8271_seek_to_track(int track) |
| 197 | static void i8271_seek_to_track(const device_config *device,int track) |
| 73 | 198 | { |
| 74 | | const device_config *img = current_image(); |
| 75 | | |
| 199 | const device_config *img = current_image(device); |
| 200 | i8271_t *i8271 = get_safe_token(device); |
| 76 | 201 | if (track==0) |
| 77 | 202 | { |
| 78 | 203 | /* seek to track 0 */ |
| r3836 | r3837 | |
| 92 | 217 | floppy_drive_seek(img, -1); |
| 93 | 218 | } |
| 94 | 219 | |
| 95 | | i8271.CurrentTrack[i8271.drive] = 0; |
| 220 | i8271->CurrentTrack[i8271->drive] = 0; |
| 96 | 221 | |
| 97 | 222 | /* failed to find track 0? */ |
| 98 | 223 | if (StepCount==0) |
| 99 | 224 | { |
| 100 | 225 | /* Completion Type: operator intervation probably required for recovery */ |
| 101 | 226 | /* Completion code: track 0 not found */ |
| 102 | | i8271.ResultRegister |= (2<<3) | 2<<1; |
| 227 | i8271->ResultRegister |= (2<<3) | 2<<1; |
| 103 | 228 | } |
| 104 | 229 | |
| 105 | 230 | /* step out - towards track 0 */ |
| 106 | | i8271.drive_control_output &=~(1<<2); |
| 231 | i8271->drive_control_output &=~(1<<2); |
| 107 | 232 | } |
| 108 | 233 | else |
| 109 | 234 | { |
| r3836 | r3837 | |
| 111 | 236 | signed int SignedTracks; |
| 112 | 237 | |
| 113 | 238 | /* calculate number of tracks to seek */ |
| 114 | | SignedTracks = track - i8271.CurrentTrack[i8271.drive]; |
| 239 | SignedTracks = track - i8271->CurrentTrack[i8271->drive]; |
| 115 | 240 | |
| 116 | 241 | /* step towards 0 */ |
| 117 | | i8271.drive_control_output &= ~(1<<2); |
| 242 | i8271->drive_control_output &= ~(1<<2); |
| 118 | 243 | |
| 119 | 244 | if (SignedTracks>0) |
| 120 | 245 | { |
| 121 | 246 | /* step away from 0 */ |
| 122 | | i8271.drive_control_output |= (1<<2); |
| 247 | i8271->drive_control_output |= (1<<2); |
| 123 | 248 | } |
| 124 | 249 | |
| 125 | 250 | |
| 126 | 251 | /* seek to track 0 */ |
| 127 | 252 | floppy_drive_seek(img, SignedTracks); |
| 128 | 253 | |
| 129 | | i8271.CurrentTrack[i8271.drive] = track; |
| 254 | i8271->CurrentTrack[i8271->drive] = track; |
| 130 | 255 | } |
| 131 | 256 | } |
| 132 | 257 | |
| 133 | 258 | |
| 134 | 259 | static TIMER_CALLBACK(i8271_data_timer_callback) |
| 135 | 260 | { |
| 261 | const device_config *device = ptr; |
| 262 | i8271_t *i8271 = get_safe_token(device); |
| 263 | |
| 136 | 264 | /* ok, trigger data request now */ |
| 137 | | i8271_data_request(); |
| 265 | i8271_data_request(device); |
| 138 | 266 | |
| 139 | 267 | /* stop it */ |
| 140 | | timer_reset(i8271.data_timer, attotime_never); |
| 268 | timer_reset(i8271->data_timer, attotime_never); |
| 141 | 269 | } |
| 142 | 270 | |
| 143 | 271 | /* setup a timed data request - data request will be triggered in a few usecs time */ |
| 144 | | static void i8271_timed_data_request(void) |
| 272 | static void i8271_timed_data_request(const device_config *device) |
| 145 | 273 | { |
| 146 | 274 | int usecs; |
| 147 | | |
| 275 | i8271_t *i8271 = get_safe_token(device); |
| 148 | 276 | /* 64 for single density */ |
| 149 | 277 | usecs = 64; |
| 150 | 278 | |
| 151 | 279 | /* set timers */ |
| 152 | | timer_reset(i8271.command_complete_timer, attotime_never); |
| 153 | | timer_adjust_oneshot(i8271.data_timer, ATTOTIME_IN_USEC(usecs), 0); |
| 280 | timer_reset(i8271->command_complete_timer, attotime_never); |
| 281 | timer_adjust_oneshot(i8271->data_timer, ATTOTIME_IN_USEC(usecs), 0); |
| 154 | 282 | } |
| 155 | 283 | |
| 156 | 284 | |
| 157 | 285 | static TIMER_CALLBACK(i8271_timed_command_complete_callback) |
| 158 | 286 | { |
| 159 | | i8271_command_complete(1,1); |
| 287 | const device_config *device = ptr; |
| 288 | i8271_t *i8271 = get_safe_token(device); |
| 160 | 289 | |
| 290 | i8271_command_complete(device,1,1); |
| 291 | |
| 161 | 292 | /* stop it, but don't allow it to be free'd */ |
| 162 | | timer_reset(i8271.command_complete_timer, attotime_never); |
| 293 | timer_reset(i8271->command_complete_timer, attotime_never); |
| 163 | 294 | } |
| 164 | 295 | |
| 165 | 296 | /* setup a irq to occur 128us later - in reality this would be much later, because the int would |
| 166 | 297 | come after reading the two CRC bytes at least! This function is used when a irq is required at |
| 167 | 298 | command completion. Required for read data and write data, where last byte could be missed! */ |
| 168 | | static void i8271_timed_command_complete(void) |
| 299 | static void i8271_timed_command_complete(const device_config *device) |
| 169 | 300 | { |
| 170 | 301 | int usecs; |
| 302 | i8271_t *i8271 = get_safe_token(device); |
| 171 | 303 | |
| 172 | 304 | /* 64 for single density - 2 crc bytes later*/ |
| 173 | 305 | usecs = 64*2; |
| 174 | 306 | |
| 175 | 307 | /* set timers */ |
| 176 | | timer_reset(i8271.data_timer, attotime_never); |
| 177 | | timer_adjust_oneshot(i8271.command_complete_timer, ATTOTIME_IN_USEC(usecs), 0); |
| 308 | timer_reset(i8271->data_timer, attotime_never); |
| 309 | timer_adjust_oneshot(i8271->command_complete_timer, ATTOTIME_IN_USEC(usecs), 0); |
| 178 | 310 | } |
| 179 | 311 | |
| 180 | | void i8271_reset() |
| 312 | static void i8271_set_irq_state(const device_config *device,int state) |
| 181 | 313 | { |
| 182 | | i8271.StatusRegister = 0; //I8271_STATUS_INT_REQUEST | I8271_STATUS_NON_DMA_REQUEST; |
| 183 | | i8271.Mode = 0x0c0; /* bits 0, 1 are initialized to zero */ |
| 184 | | i8271.ParameterCountWritten = 0; |
| 185 | | i8271.ParameterCount = 0; |
| 186 | | |
| 187 | | /* if timer is active remove */ |
| 188 | | timer_reset(i8271.command_complete_timer, attotime_never); |
| 189 | | timer_reset(i8271.data_timer, attotime_never); |
| 190 | | |
| 191 | | /* clear irq */ |
| 192 | | i8271_set_irq_state(0); |
| 193 | | /* clear dma */ |
| 194 | | i8271_set_dma_drq(); |
| 195 | | } |
| 196 | | |
| 197 | | static void i8271_set_irq_state(int state) |
| 198 | | { |
| 199 | | i8271.StatusRegister &= ~I8271_STATUS_INT_REQUEST; |
| 314 | i8271_t *i8271 = get_safe_token(device); |
| 315 | i8271->StatusRegister &= ~I8271_STATUS_INT_REQUEST; |
| 200 | 316 | if (state) |
| 201 | 317 | { |
| 202 | | i8271.StatusRegister |= I8271_STATUS_INT_REQUEST; |
| 318 | i8271->StatusRegister |= I8271_STATUS_INT_REQUEST; |
| 203 | 319 | } |
| 204 | 320 | |
| 205 | | if (i8271.fdc_interface.interrupt) |
| 321 | if (i8271->intf->interrupt) |
| 206 | 322 | { |
| 207 | | i8271.fdc_interface.interrupt((i8271.StatusRegister & I8271_STATUS_INT_REQUEST)); |
| 323 | i8271->intf->interrupt(device, (i8271->StatusRegister & I8271_STATUS_INT_REQUEST)); |
| 208 | 324 | } |
| 209 | 325 | } |
| 210 | 326 | |
| 211 | | static void i8271_set_dma_drq(void) |
| 327 | static void i8271_set_dma_drq(const device_config *device) |
| 212 | 328 | { |
| 213 | | if (i8271.fdc_interface.dma_request) |
| 329 | i8271_t *i8271 = get_safe_token(device); |
| 330 | if (i8271->intf->dma_request) |
| 214 | 331 | { |
| 215 | | i8271.fdc_interface.dma_request((i8271.flags & I8271_FLAGS_DATA_REQUEST), (i8271.flags & I8271_FLAGS_DATA_DIRECTION)); |
| 332 | i8271->intf->dma_request(device, (i8271->flags & I8271_FLAGS_DATA_REQUEST), (i8271->flags & I8271_FLAGS_DATA_DIRECTION)); |
| 216 | 333 | } |
| 217 | 334 | } |
| 218 | 335 | |
| 219 | | static void i8271_load_bad_tracks(int surface) |
| 336 | static void i8271_load_bad_tracks(const device_config *device, int surface) |
| 220 | 337 | { |
| 221 | | i8271.BadTracks[(surface<<1) + 0] = i8271.CommandParameters[1]; |
| 222 | | i8271.BadTracks[(surface<<1) + 1] = i8271.CommandParameters[2]; |
| 223 | | i8271.CurrentTrack[surface] = i8271.CommandParameters[3]; |
| 338 | i8271_t *i8271 = get_safe_token(device); |
| 339 | i8271->BadTracks[(surface<<1) + 0] = i8271->CommandParameters[1]; |
| 340 | i8271->BadTracks[(surface<<1) + 1] = i8271->CommandParameters[2]; |
| 341 | i8271->CurrentTrack[surface] = i8271->CommandParameters[3]; |
| 224 | 342 | } |
| 225 | 343 | |
| 226 | | static void i8271_write_bad_track(int surface, int track, int data) |
| 344 | static void i8271_write_bad_track(const device_config *device, int surface, int track, int data) |
| 227 | 345 | { |
| 228 | | i8271.BadTracks[(surface<<1) + (track-1)] = data; |
| 346 | i8271_t *i8271 = get_safe_token(device); |
| 347 | i8271->BadTracks[(surface<<1) + (track-1)] = data; |
| 229 | 348 | } |
| 230 | 349 | |
| 231 | | static void i8271_write_current_track(int surface, int track) |
| 350 | static void i8271_write_current_track(const device_config *device,int surface, int track) |
| 232 | 351 | { |
| 233 | | i8271.CurrentTrack[surface] = track; |
| 352 | i8271_t *i8271 = get_safe_token(device); |
| 353 | i8271->CurrentTrack[surface] = track; |
| 234 | 354 | } |
| 235 | 355 | |
| 236 | | static int i8271_read_current_track(int surface) |
| 356 | static int i8271_read_current_track(const device_config *device,int surface) |
| 237 | 357 | { |
| 238 | | return i8271.CurrentTrack[surface]; |
| 358 | i8271_t *i8271 = get_safe_token(device); |
| 359 | return i8271->CurrentTrack[surface]; |
| 239 | 360 | } |
| 240 | 361 | |
| 241 | | static int i8271_read_bad_track(int surface, int track) |
| 362 | static int i8271_read_bad_track(const device_config *device,int surface, int track) |
| 242 | 363 | { |
| 243 | | return i8271.BadTracks[(surface<<1) + (track-1)]; |
| 364 | i8271_t *i8271 = get_safe_token(device); |
| 365 | return i8271->BadTracks[(surface<<1) + (track-1)]; |
| 244 | 366 | } |
| 245 | 367 | |
| 246 | | static void i8271_get_drive(void) |
| 368 | static void i8271_get_drive(const device_config *device) |
| 247 | 369 | { |
| 370 | i8271_t *i8271 = get_safe_token(device); |
| 248 | 371 | /* &40 = drive 0 side 0 */ |
| 249 | 372 | /* &80 = drive 1 side 0 */ |
| 250 | 373 | |
| 251 | 374 | |
| 252 | 375 | |
| 253 | | if (i8271.CommandRegister & (1<<6)) |
| 376 | if (i8271->CommandRegister & (1<<6)) |
| 254 | 377 | { |
| 255 | | i8271.drive = 0; |
| 378 | i8271->drive = 0; |
| 256 | 379 | } |
| 257 | 380 | |
| 258 | | if (i8271.CommandRegister & (1<<7)) |
| 381 | if (i8271->CommandRegister & (1<<7)) |
| 259 | 382 | { |
| 260 | | i8271.drive = 1; |
| 383 | i8271->drive = 1; |
| 261 | 384 | } |
| 262 | 385 | |
| 263 | 386 | } |
| 264 | 387 | |
| 265 | | static void i8271_check_all_parameters_written(void) |
| 388 | static void i8271_check_all_parameters_written(const device_config *device) |
| 266 | 389 | { |
| 267 | | if (i8271.ParameterCount == i8271.ParameterCountWritten) |
| 390 | i8271_t *i8271 = get_safe_token(device); |
| 391 | if (i8271->ParameterCount == i8271->ParameterCountWritten) |
| 268 | 392 | { |
| 269 | | i8271.StatusRegister &= ~I8271_STATUS_COMMAND_FULL; |
| 393 | i8271->StatusRegister &= ~I8271_STATUS_COMMAND_FULL; |
| 270 | 394 | |
| 271 | | i8271_command_execute(); |
| 395 | i8271_command_execute(device); |
| 272 | 396 | } |
| 273 | 397 | } |
| 274 | 398 | |
| 275 | 399 | |
| 276 | | static void i8271_update_state(void) |
| 400 | static void i8271_update_state(const device_config *device) |
| 277 | 401 | { |
| 278 | | switch (i8271.state) |
| 402 | i8271_t *i8271 = get_safe_token(device); |
| 403 | switch (i8271->state) |
| 279 | 404 | { |
| 280 | 405 | /* fdc reading data and passing it to cpu which must read it */ |
| 281 | 406 | case I8271_STATE_EXECUTION_READ: |
| 282 | 407 | { |
| 283 | | // /* if data request has been cleared, i.e. caused by a read of the register */ |
| 284 | | // if ((i8271.flags & I8271_FLAGS_DATA_REQUEST)==0) |
| 408 | // /* if data request has been cleared, i.e. caused by a read of the register */ |
| 409 | // if ((i8271->flags & I8271_FLAGS_DATA_REQUEST)==0) |
| 285 | 410 | { |
| 286 | 411 | /* setup data with byte */ |
| 287 | | i8271.data = i8271.pExecutionPhaseData[i8271.ExecutionPhaseCount]; |
| 412 | i8271->data = i8271->pExecutionPhaseData[i8271->ExecutionPhaseCount]; |
| 288 | 413 | |
| 289 | | /* logerror("read data %02x\n", i8271.data); */ |
| 414 | /* logerror("read data %02x\n", i8271->data); */ |
| 290 | 415 | |
| 291 | 416 | /* update counters */ |
| 292 | | i8271.ExecutionPhaseCount++; |
| 293 | | i8271.ExecutionPhaseTransferCount--; |
| 417 | i8271->ExecutionPhaseCount++; |
| 418 | i8271->ExecutionPhaseTransferCount--; |
| 294 | 419 | |
| 295 | | // logerror("Count: %04x\n", i8271.ExecutionPhaseCount); |
| 296 | | // logerror("Remaining: %04x\n", i8271.ExecutionPhaseTransferCount); |
| 420 | // logerror("Count: %04x\n", i8271->ExecutionPhaseCount); |
| 421 | // logerror("Remaining: %04x\n", i8271->ExecutionPhaseTransferCount); |
| 297 | 422 | |
| 298 | 423 | /* completed? */ |
| 299 | | if (i8271.ExecutionPhaseTransferCount==0) |
| 424 | if (i8271->ExecutionPhaseTransferCount==0) |
| 300 | 425 | { |
| 301 | 426 | /* yes */ |
| 302 | 427 | |
| 303 | | // logerror("sector read complete!\n"); |
| 428 | // logerror("sector read complete!\n"); |
| 304 | 429 | /* continue command */ |
| 305 | | i8271_command_continue(); |
| 430 | i8271_command_continue(device); |
| 306 | 431 | } |
| 307 | 432 | else |
| 308 | 433 | { |
| 309 | 434 | /* no */ |
| 310 | 435 | |
| 311 | 436 | /* issue data request */ |
| 312 | | i8271_timed_data_request(); |
| 437 | i8271_timed_data_request(device); |
| 313 | 438 | } |
| 314 | 439 | } |
| 315 | 440 | } |
| r3836 | r3837 | |
| 319 | 444 | case I8271_STATE_EXECUTION_WRITE: |
| 320 | 445 | { |
| 321 | 446 | /* setup data with byte */ |
| 322 | | i8271.pExecutionPhaseData[i8271.ExecutionPhaseCount] = i8271.data; |
| 447 | i8271->pExecutionPhaseData[i8271->ExecutionPhaseCount] = i8271->data; |
| 323 | 448 | /* update counters */ |
| 324 | | i8271.ExecutionPhaseCount++; |
| 325 | | i8271.ExecutionPhaseTransferCount--; |
| 449 | i8271->ExecutionPhaseCount++; |
| 450 | i8271->ExecutionPhaseTransferCount--; |
| 326 | 451 | |
| 327 | 452 | /* completed? */ |
| 328 | | if (i8271.ExecutionPhaseTransferCount==0) |
| 453 | if (i8271->ExecutionPhaseTransferCount==0) |
| 329 | 454 | { |
| 330 | 455 | /* yes */ |
| 331 | 456 | |
| 332 | 457 | /* continue command */ |
| 333 | | i8271_command_continue(); |
| 458 | i8271_command_continue(device); |
| 334 | 459 | } |
| 335 | 460 | else |
| 336 | 461 | { |
| 337 | 462 | /* no */ |
| 338 | 463 | |
| 339 | 464 | /* issue data request */ |
| 340 | | i8271_timed_data_request(); |
| 465 | i8271_timed_data_request(device); |
| 341 | 466 | } |
| 342 | 467 | } |
| 343 | 468 | break; |
| r3836 | r3837 | |
| 347 | 472 | } |
| 348 | 473 | } |
| 349 | 474 | |
| 350 | | static void i8271_initialise_execution_phase_read(int transfer_size) |
| 475 | static void i8271_initialise_execution_phase_read(const device_config *device,int transfer_size) |
| 351 | 476 | { |
| 477 | i8271_t *i8271 = get_safe_token(device); |
| 352 | 478 | /* read */ |
| 353 | | i8271.flags |= I8271_FLAGS_DATA_DIRECTION; |
| 354 | | i8271.ExecutionPhaseCount = 0; |
| 355 | | i8271.ExecutionPhaseTransferCount = transfer_size; |
| 356 | | i8271.state = I8271_STATE_EXECUTION_READ; |
| 479 | i8271->flags |= I8271_FLAGS_DATA_DIRECTION; |
| 480 | i8271->ExecutionPhaseCount = 0; |
| 481 | i8271->ExecutionPhaseTransferCount = transfer_size; |
| 482 | i8271->state = I8271_STATE_EXECUTION_READ; |
| 357 | 483 | } |
| 358 | 484 | |
| 359 | 485 | |
| 360 | | static void i8271_initialise_execution_phase_write(int transfer_size) |
| 486 | static void i8271_initialise_execution_phase_write(const device_config *device,int transfer_size) |
| 361 | 487 | { |
| 488 | i8271_t *i8271 = get_safe_token(device); |
| 362 | 489 | /* write */ |
| 363 | | i8271.flags &= ~I8271_FLAGS_DATA_DIRECTION; |
| 364 | | i8271.ExecutionPhaseCount = 0; |
| 365 | | i8271.ExecutionPhaseTransferCount = transfer_size; |
| 366 | | i8271.state = I8271_STATE_EXECUTION_WRITE; |
| 490 | i8271->flags &= ~I8271_FLAGS_DATA_DIRECTION; |
| 491 | i8271->ExecutionPhaseCount = 0; |
| 492 | i8271->ExecutionPhaseTransferCount = transfer_size; |
| 493 | i8271->state = I8271_STATE_EXECUTION_WRITE; |
| 367 | 494 | } |
| 368 | 495 | |
| 369 | 496 | /* for data transfers */ |
| 370 | | static void i8271_data_request(void) |
| 497 | static void i8271_data_request(const device_config *device) |
| 371 | 498 | { |
| 372 | | i8271.flags |= I8271_FLAGS_DATA_REQUEST; |
| 499 | i8271_t *i8271 = get_safe_token(device); |
| 500 | i8271->flags |= I8271_FLAGS_DATA_REQUEST; |
| 373 | 501 | |
| 374 | | if ((i8271.Mode & 0x01)!=0) |
| 502 | if ((i8271->Mode & 0x01)!=0) |
| 375 | 503 | { |
| 376 | 504 | /* non-dma */ |
| 377 | | i8271.StatusRegister |= I8271_STATUS_NON_DMA_REQUEST; |
| 505 | i8271->StatusRegister |= I8271_STATUS_NON_DMA_REQUEST; |
| 378 | 506 | /* set int */ |
| 379 | | i8271_set_irq_state(1); |
| 507 | i8271_set_irq_state(device,1); |
| 380 | 508 | } |
| 381 | 509 | else |
| 382 | 510 | { |
| 383 | 511 | /* dma */ |
| 384 | | i8271.StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST; |
| 512 | i8271->StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST; |
| 385 | 513 | |
| 386 | | i8271_set_dma_drq(); |
| 514 | i8271_set_dma_drq(device); |
| 387 | 515 | } |
| 388 | 516 | } |
| 389 | 517 | |
| 390 | | static void i8271_command_complete(int result, int int_rq) |
| 518 | static void i8271_command_complete(const device_config *device,int result, int int_rq) |
| 391 | 519 | { |
| 520 | i8271_t *i8271 = get_safe_token(device); |
| 392 | 521 | /* not busy, and not a execution phase data request in non-dma mode */ |
| 393 | | i8271.StatusRegister &= ~(I8271_STATUS_COMMAND_BUSY | I8271_STATUS_NON_DMA_REQUEST); |
| 522 | i8271->StatusRegister &= ~(I8271_STATUS_COMMAND_BUSY | I8271_STATUS_NON_DMA_REQUEST); |
| 394 | 523 | |
| 395 | 524 | if (result) |
| 396 | 525 | { |
| 397 | | i8271.StatusRegister |= I8271_STATUS_RESULT_FULL; |
| 526 | i8271->StatusRegister |= I8271_STATUS_RESULT_FULL; |
| 398 | 527 | } |
| 399 | 528 | |
| 400 | 529 | if (int_rq) |
| 401 | 530 | { |
| 402 | 531 | /* trigger an int */ |
| 403 | | i8271_set_irq_state(1); |
| 532 | i8271_set_irq_state(device,1); |
| 404 | 533 | } |
| 405 | 534 | |
| 406 | 535 | /* correct?? */ |
| 407 | | i8271.drive_control_output &=~1; |
| 536 | i8271->drive_control_output &=~1; |
| 408 | 537 | } |
| 409 | 538 | |
| 410 | 539 | |
| 411 | 540 | /* for data transfers */ |
| 412 | | static void i8271_clear_data_request(void) |
| 541 | static void i8271_clear_data_request(const device_config *device) |
| 413 | 542 | { |
| 414 | | i8271.flags &= ~I8271_FLAGS_DATA_REQUEST; |
| 543 | i8271_t *i8271 = get_safe_token(device); |
| 544 | i8271->flags &= ~I8271_FLAGS_DATA_REQUEST; |
| 415 | 545 | |
| 416 | | if ((i8271.Mode & 0x01)!=0) |
| 546 | if ((i8271->Mode & 0x01)!=0) |
| 417 | 547 | { |
| 418 | 548 | /* non-dma */ |
| 419 | | i8271.StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST; |
| 549 | i8271->StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST; |
| 420 | 550 | /* set int */ |
| 421 | | i8271_set_irq_state(0); |
| 551 | i8271_set_irq_state(device,0); |
| 422 | 552 | } |
| 423 | 553 | else |
| 424 | 554 | { |
| 425 | 555 | /* dma */ |
| 426 | | i8271_set_dma_drq(); |
| 556 | i8271_set_dma_drq(device); |
| 427 | 557 | } |
| 428 | 558 | } |
| 429 | 559 | |
| 430 | 560 | |
| 431 | | static void i8271_command_continue(void) |
| 561 | static void i8271_command_continue(const device_config *device) |
| 432 | 562 | { |
| 433 | | switch (i8271.Command) |
| 563 | i8271_t *i8271 = get_safe_token(device); |
| 564 | switch (i8271->Command) |
| 434 | 565 | { |
| 435 | 566 | case I8271_COMMAND_READ_DATA_MULTI_RECORD: |
| 436 | 567 | case I8271_COMMAND_READ_DATA_SINGLE_RECORD: |
| 437 | 568 | { |
| 438 | 569 | /* completed all sectors? */ |
| 439 | | i8271.Counter--; |
| 570 | i8271->Counter--; |
| 440 | 571 | /* increment sector id */ |
| 441 | | i8271.ID_R++; |
| 572 | i8271->ID_R++; |
| 442 | 573 | |
| 443 | 574 | /* end command? */ |
| 444 | | if (i8271.Counter==0) |
| 575 | if (i8271->Counter==0) |
| 445 | 576 | { |
| 446 | 577 | |
| 447 | | i8271_timed_command_complete(); |
| 578 | i8271_timed_command_complete(device); |
| 448 | 579 | return; |
| 449 | 580 | } |
| 450 | 581 | |
| 451 | | i8271_do_read(); |
| 582 | i8271_do_read(device); |
| 452 | 583 | } |
| 453 | 584 | break; |
| 454 | 585 | |
| r3836 | r3837 | |
| 456 | 587 | case I8271_COMMAND_WRITE_DATA_SINGLE_RECORD: |
| 457 | 588 | { |
| 458 | 589 | /* put the buffer to the sector */ |
| 459 | | floppy_drive_write_sector_data(current_image(), i8271.side, i8271.data_id, i8271.pExecutionPhaseData, 1<<(i8271.ID_N+7),0); |
| 590 | floppy_drive_write_sector_data(current_image(device), i8271->side, i8271->data_id, i8271->pExecutionPhaseData, 1<<(i8271->ID_N+7),0); |
| 460 | 591 | |
| 461 | 592 | /* completed all sectors? */ |
| 462 | | i8271.Counter--; |
| 593 | i8271->Counter--; |
| 463 | 594 | /* increment sector id */ |
| 464 | | i8271.ID_R++; |
| 595 | i8271->ID_R++; |
| 465 | 596 | |
| 466 | 597 | /* end command? */ |
| 467 | | if (i8271.Counter==0) |
| 598 | if (i8271->Counter==0) |
| 468 | 599 | { |
| 469 | 600 | |
| 470 | | i8271_timed_command_complete(); |
| 601 | i8271_timed_command_complete(device); |
| 471 | 602 | return; |
| 472 | 603 | } |
| 473 | 604 | |
| 474 | | i8271_do_write(); |
| 605 | i8271_do_write(device); |
| 475 | 606 | } |
| 476 | 607 | break; |
| 477 | 608 | |
| 478 | 609 | case I8271_COMMAND_READ_ID: |
| 479 | 610 | { |
| 480 | | i8271.Counter--; |
| 611 | i8271->Counter--; |
| 481 | 612 | |
| 482 | | if (i8271.Counter==0) |
| 613 | if (i8271->Counter==0) |
| 483 | 614 | { |
| 484 | | i8271_timed_command_complete(); |
| 615 | i8271_timed_command_complete(device); |
| 485 | 616 | return; |
| 486 | 617 | } |
| 487 | 618 | |
| 488 | | i8271_do_read_id(); |
| 619 | i8271_do_read_id(device); |
| 489 | 620 | } |
| 490 | 621 | break; |
| 491 | 622 | |
| r3836 | r3837 | |
| 494 | 625 | } |
| 495 | 626 | } |
| 496 | 627 | |
| 497 | | static void i8271_do_read(void) |
| 628 | static void i8271_do_read(const device_config *device) |
| 498 | 629 | { |
| 630 | i8271_t *i8271 = get_safe_token(device); |
| 499 | 631 | /* find the sector */ |
| 500 | | if (i8271_find_sector()) |
| 632 | if (i8271_find_sector(device)) |
| 501 | 633 | { |
| 502 | 634 | /* get the sector into the buffer */ |
| 503 | | floppy_drive_read_sector_data(current_image(), i8271.side, i8271.data_id, i8271.pExecutionPhaseData, 1<<(i8271.ID_N+7)); |
| 635 | floppy_drive_read_sector_data(current_image(device), i8271->side, i8271->data_id, i8271->pExecutionPhaseData, 1<<(i8271->ID_N+7)); |
| 504 | 636 | |
| 505 | 637 | /* initialise for reading */ |
| 506 | | i8271_initialise_execution_phase_read(1<<(i8271.ID_N+7)); |
| 638 | i8271_initialise_execution_phase_read(device, 1<<(i8271->ID_N+7)); |
| 507 | 639 | |
| 508 | 640 | /* update state - gets first byte and triggers a data request */ |
| 509 | | i8271_timed_data_request(); |
| 641 | i8271_timed_data_request(device); |
| 510 | 642 | return; |
| 511 | 643 | } |
| 512 | 644 | LOG(("error getting sector data\n")); |
| 513 | 645 | |
| 514 | | i8271_timed_command_complete(); |
| 646 | i8271_timed_command_complete(device); |
| 515 | 647 | } |
| 516 | 648 | |
| 517 | | static void i8271_do_read_id(void) |
| 649 | static void i8271_do_read_id(const device_config *device) |
| 518 | 650 | { |
| 519 | 651 | chrn_id id; |
| 652 | i8271_t *i8271 = get_safe_token(device); |
| 520 | 653 | |
| 521 | 654 | /* get next id from disc */ |
| 522 | | floppy_drive_get_next_id(current_image(), i8271.side,&id); |
| 655 | floppy_drive_get_next_id(current_image(device), i8271->side,&id); |
| 523 | 656 | |
| 524 | | i8271.pExecutionPhaseData[0] = id.C; |
| 525 | | i8271.pExecutionPhaseData[1] = id.H; |
| 526 | | i8271.pExecutionPhaseData[2] = id.R; |
| 527 | | i8271.pExecutionPhaseData[3] = id.N; |
| 657 | i8271->pExecutionPhaseData[0] = id.C; |
| 658 | i8271->pExecutionPhaseData[1] = id.H; |
| 659 | i8271->pExecutionPhaseData[2] = id.R; |
| 660 | i8271->pExecutionPhaseData[3] = id.N; |
| 528 | 661 | |
| 529 | | i8271_initialise_execution_phase_read(4); |
| 662 | i8271_initialise_execution_phase_read(device, 4); |
| 530 | 663 | } |
| 531 | 664 | |
| 532 | 665 | |
| 533 | | static void i8271_do_write(void) |
| 666 | static void i8271_do_write(const device_config *device) |
| 534 | 667 | { |
| 668 | i8271_t *i8271 = get_safe_token(device); |
| 535 | 669 | /* find the sector */ |
| 536 | | if (i8271_find_sector()) |
| 670 | if (i8271_find_sector(device)) |
| 537 | 671 | { |
| 538 | 672 | /* initialise for reading */ |
| 539 | | i8271_initialise_execution_phase_write(1<<(i8271.ID_N+7)); |
| 673 | i8271_initialise_execution_phase_write(device,1<<(i8271->ID_N+7)); |
| 540 | 674 | |
| 541 | 675 | /* update state - gets first byte and triggers a data request */ |
| 542 | | i8271_timed_data_request(); |
| 676 | i8271_timed_data_request(device); |
| 543 | 677 | return; |
| 544 | 678 | } |
| 545 | 679 | LOG(("error getting sector data\n")); |
| 546 | 680 | |
| 547 | | i8271_timed_command_complete(); |
| 681 | i8271_timed_command_complete(device); |
| 548 | 682 | } |
| 549 | 683 | |
| 550 | 684 | |
| 551 | 685 | |
| 552 | | static int i8271_find_sector(void) |
| 686 | static int i8271_find_sector(const device_config *device) |
| 553 | 687 | { |
| 554 | | const device_config *img = current_image(); |
| 555 | | // int track_count_attempt; |
| 688 | const device_config *img = current_image(device); |
| 689 | i8271_t *i8271 = get_safe_token(device); |
| 690 | // int track_count_attempt; |
| 556 | 691 | |
| 557 | | // track_count_attempt |
| 692 | // track_count_attempt |
| 558 | 693 | /* find sector within one revolution of the disc - 2 index pulses */ |
| 559 | 694 | |
| 560 | 695 | /* number of times we have seen index hole */ |
| r3836 | r3837 | |
| 566 | 701 | chrn_id id; |
| 567 | 702 | |
| 568 | 703 | /* get next id from disc */ |
| 569 | | if (floppy_drive_get_next_id(img, i8271.side,&id)) |
| 704 | if (floppy_drive_get_next_id(img, i8271->side,&id)) |
| 570 | 705 | { |
| 571 | 706 | /* tested on Amstrad CPC - All bytes must match, otherwise |
| 572 | | a NO DATA error is reported */ |
| 573 | | if (id.R == i8271.ID_R) |
| 707 | a NO DATA error is reported */ |
| 708 | if (id.R == i8271->ID_R) |
| 574 | 709 | { |
| 575 | 710 | /* TODO: Is this correct? What about bad tracks? */ |
| 576 | | if (id.C == i8271.CurrentTrack[i8271.drive]) |
| 711 | if (id.C == i8271->CurrentTrack[i8271->drive]) |
| 577 | 712 | { |
| 578 | | i8271.data_id = id.data_id; |
| 713 | i8271->data_id = id.data_id; |
| 579 | 714 | return 1; |
| 580 | 715 | } |
| 581 | 716 | else |
| r3836 | r3837 | |
| 599 | 734 | |
| 600 | 735 | /* completion type: command/drive error */ |
| 601 | 736 | /* completion code: sector not found */ |
| 602 | | i8271.ResultRegister |= (3<<3); |
| 737 | i8271->ResultRegister |= (3<<3); |
| 603 | 738 | |
| 604 | 739 | return 0; |
| 605 | 740 | } |
| 606 | 741 | |
| 607 | | static void i8271_command_execute(void) |
| 742 | static void i8271_command_execute(const device_config *device) |
| 608 | 743 | { |
| 609 | | const device_config *img = current_image(); |
| 744 | i8271_t *i8271 = get_safe_token(device); |
| 745 | const device_config *img = current_image(device); |
| 610 | 746 | |
| 611 | 747 | /* clear it = good completion status */ |
| 612 | 748 | /* this will be changed if anything bad happens! */ |
| 613 | | i8271.ResultRegister = 0; |
| 749 | i8271->ResultRegister = 0; |
| 614 | 750 | |
| 615 | | switch (i8271.Command) |
| 751 | switch (i8271->Command) |
| 616 | 752 | { |
| 617 | 753 | case I8271_COMMAND_SPECIFY: |
| 618 | 754 | { |
| 619 | | switch (i8271.CommandParameters[0]) |
| 755 | switch (i8271->CommandParameters[0]) |
| 620 | 756 | { |
| 621 | 757 | case 0x0d: |
| 622 | 758 | { |
| 623 | 759 | LOG(("Initialization\n")); |
| 624 | | i8271.StepRate = i8271.CommandParameters[1]; |
| 625 | | i8271.HeadSettlingTime = i8271.CommandParameters[2]; |
| 626 | | i8271.IndexCountBeforeHeadUnload = (i8271.CommandParameters[3]>>4) & 0x0f; |
| 627 | | i8271.HeadLoadTime = (i8271.CommandParameters[3] & 0x0f); |
| 760 | i8271->StepRate = i8271->CommandParameters[1]; |
| 761 | i8271->HeadSettlingTime = i8271->CommandParameters[2]; |
| 762 | i8271->IndexCountBeforeHeadUnload = (i8271->CommandParameters[3]>>4) & 0x0f; |
| 763 | i8271->HeadLoadTime = (i8271->CommandParameters[3] & 0x0f); |
| 628 | 764 | } |
| 629 | 765 | break; |
| 630 | 766 | |
| 631 | 767 | case 0x010: |
| 632 | 768 | { |
| 633 | 769 | LOG(("Load bad Tracks Surface 0\n")); |
| 634 | | i8271_load_bad_tracks(0); |
| 770 | i8271_load_bad_tracks(device,0); |
| 635 | 771 | |
| 636 | 772 | } |
| 637 | 773 | break; |
| r3836 | r3837 | |
| 639 | 775 | case 0x018: |
| 640 | 776 | { |
| 641 | 777 | LOG(("Load bad Tracks Surface 1\n")); |
| 642 | | i8271_load_bad_tracks(1); |
| 778 | i8271_load_bad_tracks(device,1); |
| 643 | 779 | |
| 644 | 780 | } |
| 645 | 781 | break; |
| 646 | 782 | } |
| 647 | 783 | |
| 648 | 784 | /* no result */ |
| 649 | | i8271_command_complete(0,0); |
| 785 | i8271_command_complete(device,0,0); |
| 650 | 786 | } |
| 651 | 787 | break; |
| 652 | 788 | |
| r3836 | r3837 | |
| 655 | 791 | /* unknown - what is read when a special register that isn't allowed is specified? */ |
| 656 | 792 | int data = 0x0ff; |
| 657 | 793 | |
| 658 | | switch (i8271.CommandParameters[0]) |
| 794 | switch (i8271->CommandParameters[0]) |
| 659 | 795 | { |
| 660 | 796 | case I8271_SPECIAL_REGISTER_MODE_REGISTER: |
| 661 | 797 | { |
| 662 | | data = i8271.Mode; |
| 798 | data = i8271->Mode; |
| 663 | 799 | } |
| 664 | 800 | break; |
| 665 | 801 | |
| 666 | 802 | case I8271_SPECIAL_REGISTER_SURFACE_0_CURRENT_TRACK: |
| 667 | 803 | { |
| 668 | | data = i8271_read_current_track(0); |
| 804 | data = i8271_read_current_track(device, 0); |
| 669 | 805 | |
| 670 | 806 | } |
| 671 | 807 | break; |
| 672 | 808 | |
| 673 | 809 | case I8271_SPECIAL_REGISTER_SURFACE_1_CURRENT_TRACK: |
| 674 | 810 | { |
| 675 | | data = i8271_read_current_track(1); |
| 811 | data = i8271_read_current_track(device, 1); |
| 676 | 812 | } |
| 677 | 813 | break; |
| 678 | 814 | |
| 679 | 815 | case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_1: |
| 680 | 816 | { |
| 681 | | data = i8271_read_bad_track(0,1); |
| 817 | data = i8271_read_bad_track(device, 0,1); |
| 682 | 818 | } |
| 683 | 819 | break; |
| 684 | 820 | |
| 685 | 821 | case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_2: |
| 686 | 822 | { |
| 687 | | data = i8271_read_bad_track(0,2); |
| 823 | data = i8271_read_bad_track(device, 0,2); |
| 688 | 824 | } |
| 689 | 825 | break; |
| 690 | 826 | |
| 691 | 827 | case I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_1: |
| 692 | 828 | { |
| 693 | | data = i8271_read_bad_track(1,1); |
| 829 | data = i8271_read_bad_track(device, 1,1); |
| 694 | 830 | } |
| 695 | 831 | break; |
| 696 | 832 | |
| 697 | 833 | case I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_2: |
| 698 | 834 | { |
| 699 | | data = i8271_read_bad_track(1,2); |
| 835 | data = i8271_read_bad_track(device, 1,2); |
| 700 | 836 | } |
| 701 | 837 | break; |
| 702 | 838 | |
| r3836 | r3837 | |
| 704 | 840 | { |
| 705 | 841 | FDC_LOG_COMMAND("Read Drive Control Output port\n"); |
| 706 | 842 | |
| 707 | | i8271_get_drive(); |
| 843 | i8271_get_drive(device); |
| 708 | 844 | |
| 709 | 845 | /* assumption: select bits reflect the select bits from the previous |
| 710 | | command. i.e. read drive status */ |
| 711 | | data = (i8271.drive_control_output & ~0x0c0) |
| 712 | | | (i8271.CommandRegister & 0x0c0); |
| 846 | command. i.e. read drive status */ |
| 847 | data = (i8271->drive_control_output & ~0x0c0) |
| 848 | | (i8271->CommandRegister & 0x0c0); |
| 713 | 849 | |
| 714 | 850 | |
| 715 | 851 | } |
| r3836 | r3837 | |
| 729 | 865 | FDC_LOG_COMMAND("Read Drive Control Input port\n"); |
| 730 | 866 | |
| 731 | 867 | |
| 732 | | i8271.drive_control_input = (1<<6) | (1<<2); |
| 868 | i8271->drive_control_input = (1<<6) | (1<<2); |
| 733 | 869 | |
| 734 | 870 | /* bit 3 = 0 if write protected */ |
| 735 | 871 | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_DISK_WRITE_PROTECTED)) |
| 736 | 872 | { |
| 737 | | i8271.drive_control_input |= (1<<3); |
| 873 | i8271->drive_control_input |= (1<<3); |
| 738 | 874 | } |
| 739 | 875 | |
| 740 | 876 | /* bit 1 = 0 if head at track 0 */ |
| 741 | 877 | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_HEAD_AT_TRACK_0)) |
| 742 | 878 | { |
| 743 | | i8271.drive_control_input |= (1<<1); |
| 879 | i8271->drive_control_input |= (1<<1); |
| 744 | 880 | } |
| 745 | 881 | |
| 746 | 882 | |
| 747 | 883 | /* need to setup this register based on drive selected */ |
| 748 | | data = i8271.drive_control_input; |
| 884 | data = i8271->drive_control_input; |
| 749 | 885 | |
| 750 | 886 | |
| 751 | 887 | |
| r3836 | r3837 | |
| 755 | 891 | |
| 756 | 892 | } |
| 757 | 893 | |
| 758 | | i8271.ResultRegister = data; |
| 894 | i8271->ResultRegister = data; |
| 759 | 895 | |
| 760 | | i8271_command_complete(1,0); |
| 896 | i8271_command_complete(device,1,0); |
| 761 | 897 | } |
| 762 | 898 | break; |
| 763 | 899 | |
| 764 | 900 | |
| 765 | 901 | case I8271_COMMAND_WRITE_SPECIAL_REGISTER: |
| 766 | 902 | { |
| 767 | | switch (i8271.CommandParameters[0]) |
| 903 | switch (i8271->CommandParameters[0]) |
| 768 | 904 | { |
| 769 | 905 | case I8271_SPECIAL_REGISTER_MODE_REGISTER: |
| 770 | 906 | { |
| 771 | 907 | /* TODO: Check bits 6-7 and 5-2 are valid */ |
| 772 | | i8271.Mode = i8271.CommandParameters[1]; |
| 908 | i8271->Mode = i8271->CommandParameters[1]; |
| 773 | 909 | |
| 774 | | if (i8271.Mode & 0x01) |
| 910 | if (i8271->Mode & 0x01) |
| 775 | 911 | { |
| 776 | 912 | LOG(("Mode: Non-DMA\n")); |
| 777 | 913 | } |
| r3836 | r3837 | |
| 780 | 916 | LOG(("Mode: DMA\n")); |
| 781 | 917 | } |
| 782 | 918 | |
| 783 | | if (i8271.Mode & 0x02) |
| 919 | if (i8271->Mode & 0x02) |
| 784 | 920 | { |
| 785 | 921 | LOG(("Single actuator\n")); |
| 786 | 922 | } |
| r3836 | r3837 | |
| 794 | 930 | case I8271_SPECIAL_REGISTER_SURFACE_0_CURRENT_TRACK: |
| 795 | 931 | { |
| 796 | 932 | LOG(("Surface 0 Current Track\n")); |
| 797 | | i8271_write_current_track(0, i8271.CommandParameters[1]); |
| 933 | i8271_write_current_track(device, 0, i8271->CommandParameters[1]); |
| 798 | 934 | } |
| 799 | 935 | break; |
| 800 | 936 | |
| 801 | 937 | case I8271_SPECIAL_REGISTER_SURFACE_1_CURRENT_TRACK: |
| 802 | 938 | { |
| 803 | 939 | LOG(("Surface 1 Current Track\n")); |
| 804 | | i8271_write_current_track(1, i8271.CommandParameters[1]); |
| 940 | i8271_write_current_track(device, 1, i8271->CommandParameters[1]); |
| 805 | 941 | } |
| 806 | 942 | break; |
| 807 | 943 | |
| 808 | 944 | case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_1: |
| 809 | 945 | { |
| 810 | 946 | LOG(("Surface 0 Bad Track 1\n")); |
| 811 | | i8271_write_bad_track(0, 1, i8271.CommandParameters[1]); |
| 947 | i8271_write_bad_track(device, 0, 1, i8271->CommandParameters[1]); |
| 812 | 948 | } |
| 813 | 949 | break; |
| 814 | 950 | |
| 815 | 951 | case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_2: |
| 816 | 952 | { |
| 817 | 953 | LOG(("Surface 0 Bad Track 2\n")); |
| 818 | | i8271_write_bad_track(0, 2,i8271.CommandParameters[1]); |
| 954 | i8271_write_bad_track(device, 0, 2,i8271->CommandParameters[1]); |
| 819 | 955 | } |
| 820 | 956 | break; |
| 821 | 957 | |
| r3836 | r3837 | |
| 824 | 960 | LOG(("Surface 1 Bad Track 1\n")); |
| 825 | 961 | |
| 826 | 962 | |
| 827 | | i8271_write_bad_track(1, 1, i8271.CommandParameters[1]); |
| 963 | i8271_write_bad_track(device, 1, 1, i8271->CommandParameters[1]); |
| 828 | 964 | } |
| 829 | 965 | break; |
| 830 | 966 | |
| r3836 | r3837 | |
| 832 | 968 | { |
| 833 | 969 | LOG(("Surface 1 Bad Track 2\n")); |
| 834 | 970 | |
| 835 | | i8271_write_bad_track(1, 2, i8271.CommandParameters[1]); |
| 971 | i8271_write_bad_track(device, 1, 2, i8271->CommandParameters[1]); |
| 836 | 972 | } |
| 837 | 973 | break; |
| 838 | 974 | |
| 839 | 975 | case I8271_SPECIAL_REGISTER_DRIVE_CONTROL_OUTPUT_PORT: |
| 840 | 976 | { |
| 841 | | // /* get drive selected */ |
| 842 | | // i8271.drive = (i8271.CommandParameters[1]>>6) & 0x03; |
| 977 | // /* get drive selected */ |
| 978 | // i8271->drive = (i8271->CommandParameters[1]>>6) & 0x03; |
| 843 | 979 | |
| 844 | 980 | FDC_LOG_COMMAND("Write Drive Control Output port\n"); |
| 845 | 981 | |
| 846 | 982 | |
| 847 | | if (i8271.CommandParameters[1] & 0x01) |
| 983 | if (i8271->CommandParameters[1] & 0x01) |
| 848 | 984 | { |
| 849 | 985 | LOG(("Write Enable\n")); |
| 850 | 986 | } |
| 851 | | if (i8271.CommandParameters[1] & 0x02) |
| 987 | if (i8271->CommandParameters[1] & 0x02) |
| 852 | 988 | { |
| 853 | 989 | LOG(("Seek/Step\n")); |
| 854 | 990 | } |
| 855 | | if (i8271.CommandParameters[1] & 0x04) |
| 991 | if (i8271->CommandParameters[1] & 0x04) |
| 856 | 992 | { |
| 857 | 993 | LOG(("Direction\n")); |
| 858 | 994 | } |
| 859 | | if (i8271.CommandParameters[1] & 0x08) |
| 995 | if (i8271->CommandParameters[1] & 0x08) |
| 860 | 996 | { |
| 861 | 997 | LOG(("Load Head\n")); |
| 862 | 998 | } |
| 863 | | if (i8271.CommandParameters[1] & 0x010) |
| 999 | if (i8271->CommandParameters[1] & 0x010) |
| 864 | 1000 | { |
| 865 | 1001 | LOG(("Low head current\n")); |
| 866 | 1002 | } |
| 867 | | if (i8271.CommandParameters[1] & 0x020) |
| 1003 | if (i8271->CommandParameters[1] & 0x020) |
| 868 | 1004 | { |
| 869 | 1005 | LOG(("Write Fault Reset\n")); |
| 870 | 1006 | } |
| 871 | 1007 | |
| 872 | | LOG(("Select %02x\n", (i8271.CommandParameters[1] & 0x0c0)>>6)); |
| 1008 | LOG(("Select %02x\n", (i8271->CommandParameters[1] & 0x0c0)>>6)); |
| 873 | 1009 | |
| 874 | 1010 | /* get drive */ |
| 875 | | i8271_get_drive(); |
| 1011 | i8271_get_drive(device); |
| 876 | 1012 | |
| 877 | 1013 | /* on bbc dfs 09 this is the side select output */ |
| 878 | | i8271.side = (i8271.CommandParameters[1]>>5) & 0x01; |
| 1014 | i8271->side = (i8271->CommandParameters[1]>>5) & 0x01; |
| 879 | 1015 | |
| 880 | 1016 | /* load head - on mini-sized drives this turns on the disc motor, |
| 881 | | on standard-sized drives this loads the head and turns the motor on */ |
| 882 | | floppy_drive_set_motor_state(img, i8271.CommandParameters[1] & 0x08); |
| 1017 | on standard-sized drives this loads the head and turns the motor on */ |
| 1018 | floppy_drive_set_motor_state(img, i8271->CommandParameters[1] & 0x08); |
| 883 | 1019 | floppy_drive_set_ready_state(img, 1, 1); |
| 884 | 1020 | |
| 885 | 1021 | /* step pin changed? if so perform a step in the direction indicated */ |
| 886 | | if (((i8271.drive_control_output^i8271.CommandParameters[1]) & (1<<1))!=0) |
| 1022 | if (((i8271->drive_control_output^i8271->CommandParameters[1]) & (1<<1))!=0) |
| 887 | 1023 | { |
| 888 | 1024 | /* step pin changed state? */ |
| 889 | 1025 | |
| 890 | | if ((i8271.CommandParameters[1] & (1<<1))!=0) |
| 1026 | if ((i8271->CommandParameters[1] & (1<<1))!=0) |
| 891 | 1027 | { |
| 892 | 1028 | signed int signed_tracks; |
| 893 | 1029 | |
| 894 | | if ((i8271.CommandParameters[1] & (1<<2))!=0) |
| 1030 | if ((i8271->CommandParameters[1] & (1<<2))!=0) |
| 895 | 1031 | { |
| 896 | 1032 | signed_tracks = 1; |
| 897 | 1033 | } |
| r3836 | r3837 | |
| 904 | 1040 | } |
| 905 | 1041 | } |
| 906 | 1042 | |
| 907 | | i8271.drive_control_output = i8271.CommandParameters[1]; |
| 1043 | i8271->drive_control_output = i8271->CommandParameters[1]; |
| 908 | 1044 | |
| 909 | 1045 | |
| 910 | 1046 | } |
| r3836 | r3837 | |
| 915 | 1051 | |
| 916 | 1052 | FDC_LOG_COMMAND("Write Drive Control Input port\n"); |
| 917 | 1053 | |
| 918 | | // i8271.drive_control_input = i8271.CommandParameters[1]; |
| 1054 | // i8271->drive_control_input = i8271->CommandParameters[1]; |
| 919 | 1055 | } |
| 920 | 1056 | break; |
| 921 | 1057 | |
| 922 | 1058 | } |
| 923 | 1059 | |
| 924 | 1060 | /* write doesn't supply a result */ |
| 925 | | i8271_command_complete(0,0); |
| 1061 | i8271_command_complete(device,0,0); |
| 926 | 1062 | } |
| 927 | 1063 | break; |
| 928 | 1064 | |
| r3836 | r3837 | |
| 930 | 1066 | { |
| 931 | 1067 | unsigned char status; |
| 932 | 1068 | |
| 933 | | i8271_get_drive(); |
| 1069 | i8271_get_drive(device); |
| 934 | 1070 | |
| 935 | 1071 | /* no write fault */ |
| 936 | 1072 | status = 0; |
| r3836 | r3837 | |
| 960 | 1096 | status |= (1<<1); |
| 961 | 1097 | } |
| 962 | 1098 | |
| 963 | | i8271.ResultRegister = status; |
| 964 | | i8271_command_complete(1,0); |
| 1099 | i8271->ResultRegister = status; |
| 1100 | i8271_command_complete(device,1,0); |
| 965 | 1101 | |
| 966 | 1102 | } |
| 967 | 1103 | break; |
| 968 | 1104 | |
| 969 | 1105 | case I8271_COMMAND_SEEK: |
| 970 | 1106 | { |
| 971 | | i8271_get_drive(); |
| 1107 | i8271_get_drive(device); |
| 972 | 1108 | |
| 973 | 1109 | |
| 974 | | i8271_seek_to_track(i8271.CommandParameters[0]); |
| 1110 | i8271_seek_to_track(device,i8271->CommandParameters[0]); |
| 975 | 1111 | |
| 976 | 1112 | /* check for bad seek */ |
| 977 | | i8271_timed_command_complete(); |
| 1113 | i8271_timed_command_complete(device); |
| 978 | 1114 | |
| 979 | 1115 | } |
| 980 | 1116 | break; |
| r3836 | r3837 | |
| 982 | 1118 | case I8271_COMMAND_READ_DATA_MULTI_RECORD: |
| 983 | 1119 | { |
| 984 | 1120 | /* N value as stored in ID field */ |
| 985 | | i8271.ID_N = (i8271.CommandParameters[2]>>5) & 0x07; |
| 1121 | i8271->ID_N = (i8271->CommandParameters[2]>>5) & 0x07; |
| 986 | 1122 | |
| 987 | 1123 | /* starting sector id */ |
| 988 | | i8271.ID_R = i8271.CommandParameters[1]; |
| 1124 | i8271->ID_R = i8271->CommandParameters[1]; |
| 989 | 1125 | |
| 990 | 1126 | /* number of sectors to transfer */ |
| 991 | | i8271.Counter = i8271.CommandParameters[2] & 0x01f; |
| 1127 | i8271->Counter = i8271->CommandParameters[2] & 0x01f; |
| 992 | 1128 | |
| 993 | 1129 | |
| 994 | 1130 | FDC_LOG_COMMAND("READ DATA MULTI RECORD"); |
| 995 | 1131 | |
| 996 | | LOG(("Sector Count: %02x\n", i8271.Counter)); |
| 997 | | LOG(("Track: %02x\n",i8271.CommandParameters[0])); |
| 998 | | LOG(("Sector: %02x\n", i8271.CommandParameters[1])); |
| 999 | | LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7))); |
| 1132 | LOG(("Sector Count: %02x\n", i8271->Counter)); |
| 1133 | LOG(("Track: %02x\n",i8271->CommandParameters[0])); |
| 1134 | LOG(("Sector: %02x\n", i8271->CommandParameters[1])); |
| 1135 | LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7))); |
| 1000 | 1136 | |
| 1001 | | i8271_get_drive(); |
| 1137 | i8271_get_drive(device); |
| 1002 | 1138 | |
| 1003 | 1139 | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1004 | 1140 | { |
| 1005 | 1141 | /* Completion type: operation intervention probably required for recovery */ |
| 1006 | 1142 | /* Completion code: Drive not ready */ |
| 1007 | | i8271.ResultRegister = (2<<3); |
| 1008 | | i8271_timed_command_complete(); |
| 1143 | i8271->ResultRegister = (2<<3); |
| 1144 | i8271_timed_command_complete(device); |
| 1009 | 1145 | } |
| 1010 | 1146 | else |
| 1011 | 1147 | { |
| 1012 | | i8271_seek_to_track(i8271.CommandParameters[0]); |
| 1148 | i8271_seek_to_track(device,i8271->CommandParameters[0]); |
| 1013 | 1149 | |
| 1014 | 1150 | |
| 1015 | | i8271_do_read(); |
| 1151 | i8271_do_read(device); |
| 1016 | 1152 | } |
| 1017 | 1153 | |
| 1018 | 1154 | } |
| r3836 | r3837 | |
| 1022 | 1158 | { |
| 1023 | 1159 | FDC_LOG_COMMAND("READ DATA SINGLE RECORD"); |
| 1024 | 1160 | |
| 1025 | | i8271.ID_N = 0; |
| 1026 | | i8271.Counter = 1; |
| 1027 | | i8271.ID_R = i8271.CommandParameters[1]; |
| 1161 | i8271->ID_N = 0; |
| 1162 | i8271->Counter = 1; |
| 1163 | i8271->ID_R = i8271->CommandParameters[1]; |
| 1028 | 1164 | |
| 1029 | | LOG(("Sector Count: %02x\n", i8271.Counter)); |
| 1030 | | LOG(("Track: %02x\n",i8271.CommandParameters[0])); |
| 1031 | | LOG(("Sector: %02x\n", i8271.CommandParameters[1])); |
| 1032 | | LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7))); |
| 1165 | LOG(("Sector Count: %02x\n", i8271->Counter)); |
| 1166 | LOG(("Track: %02x\n",i8271->CommandParameters[0])); |
| 1167 | LOG(("Sector: %02x\n", i8271->CommandParameters[1])); |
| 1168 | LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7))); |
| 1033 | 1169 | |
| 1034 | | i8271_get_drive(); |
| 1170 | i8271_get_drive(device); |
| 1035 | 1171 | |
| 1036 | 1172 | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1037 | 1173 | { |
| 1038 | 1174 | /* Completion type: operation intervention probably required for recovery */ |
| 1039 | 1175 | /* Completion code: Drive not ready */ |
| 1040 | | i8271.ResultRegister = (2<<3); |
| 1041 | | i8271_timed_command_complete(); |
| 1176 | i8271->ResultRegister = (2<<3); |
| 1177 | i8271_timed_command_complete(device); |
| 1042 | 1178 | } |
| 1043 | 1179 | else |
| 1044 | 1180 | { |
| 1045 | | i8271_seek_to_track(i8271.CommandParameters[0]); |
| 1181 | i8271_seek_to_track(device,i8271->CommandParameters[0]); |
| 1046 | 1182 | |
| 1047 | | i8271_do_read(); |
| 1183 | i8271_do_read(device); |
| 1048 | 1184 | } |
| 1049 | 1185 | |
| 1050 | 1186 | } |
| r3836 | r3837 | |
| 1053 | 1189 | case I8271_COMMAND_WRITE_DATA_MULTI_RECORD: |
| 1054 | 1190 | { |
| 1055 | 1191 | /* N value as stored in ID field */ |
| 1056 | | i8271.ID_N = (i8271.CommandParameters[2]>>5) & 0x07; |
| 1192 | i8271->ID_N = (i8271->CommandParameters[2]>>5) & 0x07; |
| 1057 | 1193 | |
| 1058 | 1194 | /* starting sector id */ |
| 1059 | | i8271.ID_R = i8271.CommandParameters[1]; |
| 1195 | i8271->ID_R = i8271->CommandParameters[1]; |
| 1060 | 1196 | |
| 1061 | 1197 | /* number of sectors to transfer */ |
| 1062 | | i8271.Counter = i8271.CommandParameters[2] & 0x01f; |
| 1198 | i8271->Counter = i8271->CommandParameters[2] & 0x01f; |
| 1063 | 1199 | |
| 1064 | 1200 | FDC_LOG_COMMAND("READ DATA MULTI RECORD"); |
| 1065 | 1201 | |
| 1066 | | LOG(("Sector Count: %02x\n", i8271.Counter)); |
| 1067 | | LOG(("Track: %02x\n",i8271.CommandParameters[0])); |
| 1068 | | LOG(("Sector: %02x\n", i8271.CommandParameters[1])); |
| 1069 | | LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7))); |
| 1202 | LOG(("Sector Count: %02x\n", i8271->Counter)); |
| 1203 | LOG(("Track: %02x\n",i8271->CommandParameters[0])); |
| 1204 | LOG(("Sector: %02x\n", i8271->CommandParameters[1])); |
| 1205 | LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7))); |
| 1070 | 1206 | |
| 1071 | | i8271_get_drive(); |
| 1207 | i8271_get_drive(device); |
| 1072 | 1208 | |
| 1073 | | i8271.drive_control_output &=~1; |
| 1209 | i8271->drive_control_output &=~1; |
| 1074 | 1210 | |
| 1075 | 1211 | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1076 | 1212 | { |
| 1077 | 1213 | /* Completion type: operation intervention probably required for recovery */ |
| 1078 | 1214 | /* Completion code: Drive not ready */ |
| 1079 | | i8271.ResultRegister = (2<<3); |
| 1080 | | i8271_timed_command_complete(); |
| 1215 | i8271->ResultRegister = (2<<3); |
| 1216 | i8271_timed_command_complete(device); |
| 1081 | 1217 | } |
| 1082 | 1218 | else |
| 1083 | 1219 | { |
| r3836 | r3837 | |
| 1085 | 1221 | { |
| 1086 | 1222 | /* Completion type: operation intervention probably required for recovery */ |
| 1087 | 1223 | /* Completion code: Drive write protected */ |
| 1088 | | i8271.ResultRegister = (2<<3) | (1<<1); |
| 1089 | | i8271_timed_command_complete(); |
| 1224 | i8271->ResultRegister = (2<<3) | (1<<1); |
| 1225 | i8271_timed_command_complete(device); |
| 1090 | 1226 | } |
| 1091 | 1227 | else |
| 1092 | 1228 | { |
| 1093 | | i8271.drive_control_output |=1; |
| 1229 | i8271->drive_control_output |=1; |
| 1094 | 1230 | |
| 1095 | | i8271_seek_to_track(i8271.CommandParameters[0]); |
| 1231 | i8271_seek_to_track(device,i8271->CommandParameters[0]); |
| 1096 | 1232 | |
| 1097 | | i8271_do_write(); |
| 1233 | i8271_do_write(device); |
| 1098 | 1234 | } |
| 1099 | 1235 | } |
| 1100 | 1236 | } |
| r3836 | r3837 | |
| 1104 | 1240 | { |
| 1105 | 1241 | FDC_LOG_COMMAND("WRITE DATA SINGLE RECORD"); |
| 1106 | 1242 | |
| 1107 | | i8271.ID_N = 0; |
| 1108 | | i8271.Counter = 1; |
| 1109 | | i8271.ID_R = i8271.CommandParameters[1]; |
| 1243 | i8271->ID_N = 0; |
| 1244 | i8271->Counter = 1; |
| 1245 | i8271->ID_R = i8271->CommandParameters[1]; |
| 1110 | 1246 | |
| 1111 | 1247 | |
| 1112 | | LOG(("Sector Count: %02x\n", i8271.Counter)); |
| 1113 | | LOG(("Track: %02x\n",i8271.CommandParameters[0])); |
| 1114 | | LOG(("Sector: %02x\n", i8271.CommandParameters[1])); |
| 1115 | | LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7))); |
| 1116 | | i8271_get_drive(); |
| 1248 | LOG(("Sector Count: %02x\n", i8271->Counter)); |
| 1249 | LOG(("Track: %02x\n",i8271->CommandParameters[0])); |
| 1250 | LOG(("Sector: %02x\n", i8271->CommandParameters[1])); |
| 1251 | LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7))); |
| 1252 | i8271_get_drive(device); |
| 1117 | 1253 | |
| 1118 | | i8271.drive_control_output &=~1; |
| 1254 | i8271->drive_control_output &=~1; |
| 1119 | 1255 | |
| 1120 | 1256 | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1121 | 1257 | { |
| 1122 | 1258 | /* Completion type: operation intervention probably required for recovery */ |
| 1123 | 1259 | /* Completion code: Drive not ready */ |
| 1124 | | i8271.ResultRegister = (2<<3); |
| 1125 | | i8271_timed_command_complete(); |
| 1260 | i8271->ResultRegister = (2<<3); |
| 1261 | i8271_timed_command_complete(device); |
| 1126 | 1262 | } |
| 1127 | 1263 | else |
| 1128 | 1264 | { |
| r3836 | r3837 | |
| 1130 | 1266 | { |
| 1131 | 1267 | /* Completion type: operation intervention probably required for recovery */ |
| 1132 | 1268 | /* Completion code: Drive write protected */ |
| 1133 | | i8271.ResultRegister = (2<<3) | (1<<1); |
| 1134 | | i8271_timed_command_complete(); |
| 1269 | i8271->ResultRegister = (2<<3) | (1<<1); |
| 1270 | i8271_timed_command_complete(device); |
| 1135 | 1271 | } |
| 1136 | 1272 | else |
| 1137 | 1273 | { |
| 1138 | 1274 | |
| 1139 | | i8271.drive_control_output |=1; |
| 1275 | i8271->drive_control_output |=1; |
| 1140 | 1276 | |
| 1141 | | i8271_seek_to_track(i8271.CommandParameters[0]); |
| 1277 | i8271_seek_to_track(device,i8271->CommandParameters[0]); |
| 1142 | 1278 | |
| 1143 | | i8271_do_write(); |
| 1279 | i8271_do_write(device); |
| 1144 | 1280 | } |
| 1145 | 1281 | } |
| 1146 | 1282 | |
| r3836 | r3837 | |
| 1152 | 1288 | { |
| 1153 | 1289 | FDC_LOG_COMMAND("READ ID"); |
| 1154 | 1290 | |
| 1155 | | LOG(("Track: %02x\n",i8271.CommandParameters[0])); |
| 1156 | | LOG(("ID Field Count: %02x\n", i8271.CommandParameters[2])); |
| 1291 | LOG(("Track: %02x\n",i8271->CommandParameters[0])); |
| 1292 | LOG(("ID Field Count: %02x\n", i8271->CommandParameters[2])); |
| 1157 | 1293 | |
| 1158 | | i8271_get_drive(); |
| 1294 | i8271_get_drive(device); |
| 1159 | 1295 | |
| 1160 | 1296 | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1161 | 1297 | { |
| 1162 | 1298 | /* Completion type: operation intervention probably required for recovery */ |
| 1163 | 1299 | /* Completion code: Drive not ready */ |
| 1164 | | i8271.ResultRegister = (2<<3); |
| 1165 | | i8271_timed_command_complete(); |
| 1300 | i8271->ResultRegister = (2<<3); |
| 1301 | i8271_timed_command_complete(device); |
| 1166 | 1302 | } |
| 1167 | 1303 | else |
| 1168 | 1304 | { |
| 1169 | 1305 | |
| 1170 | | i8271.Counter = i8271.CommandParameters[2]; |
| 1306 | i8271->Counter = i8271->CommandParameters[2]; |
| 1171 | 1307 | |
| 1172 | | i8271_seek_to_track(i8271.CommandParameters[0]); |
| 1308 | i8271_seek_to_track(device,i8271->CommandParameters[0]); |
| 1173 | 1309 | |
| 1174 | | i8271_do_read_id(); |
| 1310 | i8271_do_read_id(device); |
| 1175 | 1311 | } |
| 1176 | 1312 | } |
| 1177 | 1313 | break; |
| r3836 | r3837 | |
| 1184 | 1320 | |
| 1185 | 1321 | |
| 1186 | 1322 | |
| 1187 | | WRITE8_HANDLER(i8271_w) |
| 1323 | WRITE8_DEVICE_HANDLER(i8271_w) |
| 1188 | 1324 | { |
| 1325 | i8271_t *i8271 = get_safe_token(device); |
| 1189 | 1326 | switch (offset & 3) |
| 1190 | 1327 | { |
| 1191 | 1328 | case 0: |
| 1192 | 1329 | { |
| 1193 | 1330 | LOG(("I8271 W Command Register: %02x\n", data)); |
| 1194 | 1331 | |
| 1195 | | i8271.CommandRegister = data; |
| 1196 | | i8271.Command = i8271.CommandRegister & 0x03f; |
| 1332 | i8271->CommandRegister = data; |
| 1333 | i8271->Command = i8271->CommandRegister & 0x03f; |
| 1197 | 1334 | |
| 1198 | | i8271.StatusRegister |= I8271_STATUS_COMMAND_BUSY | I8271_STATUS_COMMAND_FULL; |
| 1199 | | i8271.StatusRegister &= ~I8271_STATUS_PARAMETER_FULL | I8271_STATUS_RESULT_FULL; |
| 1200 | | i8271.ParameterCountWritten = 0; |
| 1335 | i8271->StatusRegister |= I8271_STATUS_COMMAND_BUSY | I8271_STATUS_COMMAND_FULL; |
| 1336 | i8271->StatusRegister &= ~I8271_STATUS_PARAMETER_FULL | I8271_STATUS_RESULT_FULL; |
| 1337 | i8271->ParameterCountWritten = 0; |
| 1201 | 1338 | |
| 1202 | | switch (i8271.Command) |
| 1339 | switch (i8271->Command) |
| 1203 | 1340 | { |
| 1204 | 1341 | case I8271_COMMAND_SPECIFY: |
| 1205 | 1342 | { |
| 1206 | 1343 | FDC_LOG_COMMAND("SPECIFY"); |
| 1207 | 1344 | |
| 1208 | | i8271.ParameterCount = 4; |
| 1345 | i8271->ParameterCount = 4; |
| 1209 | 1346 | } |
| 1210 | 1347 | break; |
| 1211 | 1348 | |
| r3836 | r3837 | |
| 1213 | 1350 | { |
| 1214 | 1351 | FDC_LOG_COMMAND("SEEK"); |
| 1215 | 1352 | |
| 1216 | | i8271.ParameterCount = 1; |
| 1353 | i8271->ParameterCount = 1; |
| 1217 | 1354 | } |
| 1218 | 1355 | break; |
| 1219 | 1356 | |
| r3836 | r3837 | |
| 1221 | 1358 | { |
| 1222 | 1359 | FDC_LOG_COMMAND("READ DRIVE STATUS"); |
| 1223 | 1360 | |
| 1224 | | i8271.ParameterCount = 0; |
| 1361 | i8271->ParameterCount = 0; |
| 1225 | 1362 | } |
| 1226 | 1363 | break; |
| 1227 | 1364 | |
| r3836 | r3837 | |
| 1229 | 1366 | { |
| 1230 | 1367 | FDC_LOG_COMMAND("READ SPECIAL REGISTER"); |
| 1231 | 1368 | |
| 1232 | | i8271.ParameterCount = 1; |
| 1369 | i8271->ParameterCount = 1; |
| 1233 | 1370 | } |
| 1234 | 1371 | break; |
| 1235 | 1372 | |
| r3836 | r3837 | |
| 1237 | 1374 | { |
| 1238 | 1375 | FDC_LOG_COMMAND("WRITE SPECIAL REGISTER"); |
| 1239 | 1376 | |
| 1240 | | i8271.ParameterCount = 2; |
| 1377 | i8271->ParameterCount = 2; |
| 1241 | 1378 | } |
| 1242 | 1379 | break; |
| 1243 | 1380 | |
| 1244 | 1381 | case I8271_COMMAND_FORMAT: |
| 1245 | 1382 | { |
| 1246 | | i8271.ParameterCount = 5; |
| 1383 | i8271->ParameterCount = 5; |
| 1247 | 1384 | } |
| 1248 | 1385 | break; |
| 1249 | 1386 | |
| 1250 | 1387 | case I8271_COMMAND_READ_ID: |
| 1251 | 1388 | { |
| 1252 | | i8271.ParameterCount = 3; |
| 1389 | i8271->ParameterCount = 3; |
| 1253 | 1390 | |
| 1254 | 1391 | } |
| 1255 | 1392 | break; |
| r3836 | r3837 | |
| 1261 | 1398 | case I8271_COMMAND_WRITE_DELETED_DATA_SINGLE_RECORD: |
| 1262 | 1399 | case I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_SINGLE_RECORD: |
| 1263 | 1400 | { |
| 1264 | | i8271.ParameterCount = 2; |
| 1401 | i8271->ParameterCount = 2; |
| 1265 | 1402 | } |
| 1266 | 1403 | break; |
| 1267 | 1404 | |
| r3836 | r3837 | |
| 1271 | 1408 | case I8271_COMMAND_WRITE_DELETED_DATA_MULTI_RECORD: |
| 1272 | 1409 | case I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_MULTI_RECORD: |
| 1273 | 1410 | { |
| 1274 | | i8271.ParameterCount = 3; |
| 1411 | i8271->ParameterCount = 3; |
| 1275 | 1412 | } |
| 1276 | 1413 | break; |
| 1277 | 1414 | |
| 1278 | 1415 | case I8271_COMMAND_SCAN_DATA: |
| 1279 | 1416 | case I8271_COMMAND_SCAN_DATA_AND_DELETED_DATA: |
| 1280 | 1417 | { |
| 1281 | | i8271.ParameterCount = 5; |
| 1418 | i8271->ParameterCount = 5; |
| 1282 | 1419 | } |
| 1283 | 1420 | break; |
| 1284 | 1421 | |
| r3836 | r3837 | |
| 1289 | 1426 | |
| 1290 | 1427 | } |
| 1291 | 1428 | |
| 1292 | | i8271_check_all_parameters_written(); |
| 1429 | i8271_check_all_parameters_written(device); |
| 1293 | 1430 | } |
| 1294 | 1431 | break; |
| 1295 | 1432 | |
| 1296 | 1433 | case 1: |
| 1297 | 1434 | { |
| 1298 | 1435 | LOG(("I8271 W Parameter Register: %02x\n",data)); |
| 1299 | | i8271.ParameterRegister = data; |
| 1436 | i8271->ParameterRegister = data; |
| 1300 | 1437 | |
| 1301 | | if (i8271.ParameterCount!=0) |
| 1438 | if (i8271->ParameterCount!=0) |
| 1302 | 1439 | { |
| 1303 | | i8271.CommandParameters[i8271.ParameterCountWritten] = data; |
| 1304 | | i8271.ParameterCountWritten++; |
| 1440 | i8271->CommandParameters[i8271->ParameterCountWritten] = data; |
| 1441 | i8271->ParameterCountWritten++; |
| 1305 | 1442 | } |
| 1306 | 1443 | |
| 1307 | | i8271_check_all_parameters_written(); |
| 1444 | i8271_check_all_parameters_written(device); |
| 1308 | 1445 | } |
| 1309 | 1446 | break; |
| 1310 | 1447 | |
| 1311 | 1448 | case 2: |
| 1312 | 1449 | { |
| 1313 | 1450 | LOG(("I8271 W Reset Register: %02x\n", data)); |
| 1314 | | if (((data ^ i8271.ResetRegister) & 0x01)!=0) |
| 1451 | if (((data ^ i8271->ResetRegister) & 0x01)!=0) |
| 1315 | 1452 | { |
| 1316 | 1453 | if ((data & 0x01)==0) |
| 1317 | 1454 | { |
| 1318 | | i8271_reset(); |
| 1455 | device_reset_i8271(device); |
| 1319 | 1456 | } |
| 1320 | 1457 | } |
| 1321 | 1458 | |
| 1322 | | i8271.ResetRegister = data; |
| 1459 | i8271->ResetRegister = data; |
| 1323 | 1460 | |
| 1324 | 1461 | |
| 1325 | 1462 | } |
| r3836 | r3837 | |
| 1330 | 1467 | } |
| 1331 | 1468 | } |
| 1332 | 1469 | |
| 1333 | | READ8_HANDLER(i8271_r) |
| 1470 | READ8_DEVICE_HANDLER(i8271_r) |
| 1334 | 1471 | { |
| 1472 | i8271_t *i8271 = get_safe_token(device); |
| 1335 | 1473 | switch (offset & 3) |
| 1336 | 1474 | { |
| 1337 | 1475 | case 0: |
| 1338 | 1476 | { |
| 1339 | 1477 | /* bit 1,0 are zero other bits contain status data */ |
| 1340 | | i8271.StatusRegister &= ~0x03; |
| 1341 | | LOG(("I8271 R Status Register: %02x\n",i8271.StatusRegister)); |
| 1342 | | return i8271.StatusRegister; |
| 1478 | i8271->StatusRegister &= ~0x03; |
| 1479 | LOG(("I8271 R Status Register: %02x\n",i8271->StatusRegister)); |
| 1480 | return i8271->StatusRegister; |
| 1343 | 1481 | } |
| 1344 | 1482 | |
| 1345 | 1483 | case 1: |
| 1346 | 1484 | { |
| 1347 | 1485 | |
| 1348 | | if ((i8271.StatusRegister & I8271_STATUS_COMMAND_BUSY)==0) |
| 1486 | if ((i8271->StatusRegister & I8271_STATUS_COMMAND_BUSY)==0) |
| 1349 | 1487 | { |
| 1350 | 1488 | /* clear IRQ */ |
| 1351 | | i8271_set_irq_state(0); |
| 1489 | i8271_set_irq_state(device,0); |
| 1352 | 1490 | |
| 1353 | | i8271.StatusRegister &= ~I8271_STATUS_RESULT_FULL; |
| 1354 | | LOG(("I8271 R Result Register %02x\n",i8271.ResultRegister)); |
| 1355 | | return i8271.ResultRegister; |
| 1491 | i8271->StatusRegister &= ~I8271_STATUS_RESULT_FULL; |
| 1492 | LOG(("I8271 R Result Register %02x\n",i8271->ResultRegister)); |
| 1493 | return i8271->ResultRegister; |
| 1356 | 1494 | } |
| 1357 | 1495 | |
| 1358 | 1496 | /* not useful information when command busy */ |
| r3836 | r3837 | |
| 1369 | 1507 | |
| 1370 | 1508 | |
| 1371 | 1509 | /* to be completed! */ |
| 1372 | | READ8_HANDLER(i8271_dack_r) |
| 1510 | READ8_DEVICE_HANDLER(i8271_dack_r) |
| 1373 | 1511 | { |
| 1374 | | return i8271_data_r(space, offset); |
| 1512 | return i8271_data_r(device, offset); |
| 1375 | 1513 | } |
| 1376 | 1514 | |
| 1377 | 1515 | /* to be completed! */ |
| 1378 | | WRITE8_HANDLER(i8271_dack_w) |
| 1516 | WRITE8_DEVICE_HANDLER(i8271_dack_w) |
| 1379 | 1517 | { |
| 1380 | | i8271_data_w(space, offset, data); |
| 1518 | i8271_data_w(device, offset, data); |
| 1381 | 1519 | } |
| 1382 | 1520 | |
| 1383 | | READ8_HANDLER(i8271_data_r) |
| 1521 | READ8_DEVICE_HANDLER(i8271_data_r) |
| 1384 | 1522 | { |
| 1385 | | i8271_clear_data_request(); |
| 1523 | i8271_t *i8271 = get_safe_token(device); |
| 1386 | 1524 | |
| 1387 | | i8271_update_state(); |
| 1525 | i8271_clear_data_request(device); |
| 1388 | 1526 | |
| 1389 | | // logerror("I8271 R data: %02x\n",i8271.data); |
| 1527 | i8271_update_state(device); |
| 1390 | 1528 | |
| 1529 | // logerror("I8271 R data: %02x\n",i8271->data); |
| 1391 | 1530 | |
| 1392 | | return i8271.data; |
| 1531 | |
| 1532 | return i8271->data; |
| 1393 | 1533 | } |
| 1394 | 1534 | |
| 1395 | | WRITE8_HANDLER(i8271_data_w) |
| 1535 | WRITE8_DEVICE_HANDLER(i8271_data_w) |
| 1396 | 1536 | { |
| 1397 | | i8271.data = data; |
| 1537 | i8271_t *i8271 = get_safe_token(device); |
| 1538 | i8271->data = data; |
| 1398 | 1539 | |
| 1399 | | // logerror("I8271 W data: %02x\n",i8271.data); |
| 1540 | // logerror("I8271 W data: %02x\n",i8271->data); |
| 1400 | 1541 | |
| 1401 | | i8271_clear_data_request(); |
| 1542 | i8271_clear_data_request(device); |
| 1402 | 1543 | |
| 1403 | | i8271_update_state(); |
| 1544 | i8271_update_state(device); |
| 1404 | 1545 | } |
| 1405 | 1546 | |
| 1547 | |
| 1548 | /* Device Interface */ |
| 1549 | |
| 1550 | static DEVICE_START( i8271 ) |
| 1551 | { |
| 1552 | i8271_t *i8271 = get_safe_token(device); |
| 1553 | // validate arguments |
| 1554 | |
| 1555 | assert(device != NULL); |
| 1556 | assert(device->tag != NULL); |
| 1557 | assert(strlen(device->tag) < 20); |
| 1558 | assert(device->static_config != NULL); |
| 1559 | |
| 1560 | i8271->intf = device->static_config; |
| 1561 | |
| 1562 | i8271->data_timer = timer_alloc(device->machine, i8271_data_timer_callback, (void *)device); |
| 1563 | i8271->command_complete_timer = timer_alloc(device->machine, i8271_timed_command_complete_callback, (void *)device); |
| 1564 | i8271->drive = 0; |
| 1565 | i8271->pExecutionPhaseData = auto_malloc(0x4000); |
| 1566 | |
| 1567 | // register for state saving |
| 1568 | //state_save_register_item(device->machine, "i8271", device->tag, 0, i8271->number); |
| 1569 | return DEVICE_START_OK; |
| 1570 | } |
| 1571 | |
| 1572 | static DEVICE_RESET( i8271 ) |
| 1573 | { |
| 1574 | i8271_t *i8271 = get_safe_token(device); |
| 1575 | |
| 1576 | i8271->StatusRegister = 0; //I8271_STATUS_INT_REQUEST | I8271_STATUS_NON_DMA_REQUEST; |
| 1577 | i8271->Mode = 0x0c0; /* bits 0, 1 are initialized to zero */ |
| 1578 | i8271->ParameterCountWritten = 0; |
| 1579 | i8271->ParameterCount = 0; |
| 1580 | |
| 1581 | /* if timer is active remove */ |
| 1582 | timer_reset(i8271->command_complete_timer, attotime_never); |
| 1583 | timer_reset(i8271->data_timer, attotime_never); |
| 1584 | |
| 1585 | /* clear irq */ |
| 1586 | i8271_set_irq_state(device,0); |
| 1587 | /* clear dma */ |
| 1588 | i8271_set_dma_drq(device); |
| 1589 | |
| 1590 | } |
| 1591 | |
| 1592 | static DEVICE_SET_INFO( i8271 ) |
| 1593 | { |
| 1594 | switch (state) |
| 1595 | { |
| 1596 | /* no parameters to set */ |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | DEVICE_GET_INFO( i8271 ) |
| 1601 | { |
| 1602 | switch (state) |
| 1603 | { |
| 1604 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1605 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(i8271_t); break; |
| 1606 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 1607 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 1608 | |
| 1609 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1610 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(i8271); break; |
| 1611 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(i8271); break; |
| 1612 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1613 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(i8271); break; |
| 1614 | |
| 1615 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1616 | case DEVINFO_STR_NAME: info->s = "Intel 8271"; break; |
| 1617 | case DEVINFO_STR_FAMILY: info->s = "Intel 8271"; break; |
| 1618 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 1619 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 1620 | case DEVINFO_STR_CREDITS: info->s = "Copyright MESS Team"; break; |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | |