src/mess/machine/wd1772.c
| r13298 | r13299 | |
| 2 | 2 | |
| 3 | 3 | #include "debugger.h" |
| 4 | 4 | |
| 5 | const device_type WD1770x = &device_creator<wd1770_t>; |
| 5 | 6 | const device_type WD1772x = &device_creator<wd1772_t>; |
| 7 | const device_type WD1773x = &device_creator<wd1773_t>; |
| 6 | 8 | |
| 7 | | const int wd1772_t::step_times[4] = { 48000, 96000, 16000, 24000 }; |
| 8 | | |
| 9 | | wd1772_t::wd1772_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, WD1772x, "WD1772", tag, owner, clock) |
| 9 | wd177x_t::wd177x_t(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) : |
| 10 | device_t(mconfig, type, name, tag, owner, clock) |
| 10 | 11 | { |
| 11 | 12 | } |
| 12 | 13 | |
| 13 | | void wd1772_t::device_start() |
| 14 | void wd177x_t::device_start() |
| 14 | 15 | { |
| 15 | 16 | t_gen = timer_alloc(TM_GEN); |
| 16 | 17 | t_cmd = timer_alloc(TM_CMD); |
| r13298 | r13299 | |
| 33 | 34 | save_item(NAME(last_dir)); |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | | void wd1772_t::device_reset() |
| 37 | void wd177x_t::device_reset() |
| 37 | 38 | { |
| 38 | 39 | command = 0x00; |
| 39 | 40 | main_state = IDLE; |
| r13298 | r13299 | |
| 52 | 53 | drq = false; |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | | void wd1772_t::set_floppy(floppy_image_device *_floppy) |
| 56 | void wd177x_t::set_floppy(floppy_image_device *_floppy) |
| 56 | 57 | { |
| 57 | 58 | if(floppy == _floppy) |
| 58 | 59 | return; |
| r13298 | r13299 | |
| 65 | 66 | floppy = _floppy; |
| 66 | 67 | |
| 67 | 68 | if(floppy) { |
| 68 | | floppy->mon_w(status & S_MON ? 0 : 1); |
| 69 | | floppy->setup_index_pulse_cb(floppy_image_device::index_pulse_cb(FUNC(wd1772_t::index_callback), this)); |
| 69 | if(has_motor()) |
| 70 | floppy->mon_w(status & S_MON ? 0 : 1); |
| 71 | floppy->setup_index_pulse_cb(floppy_image_device::index_pulse_cb(FUNC(wd177x_t::index_callback), this)); |
| 70 | 72 | } |
| 71 | 73 | } |
| 72 | 74 | |
| 73 | | void wd1772_t::setup_intrq_cb(line_cb cb) |
| 75 | void wd177x_t::setup_intrq_cb(line_cb cb) |
| 74 | 76 | { |
| 75 | 77 | intrq_cb = cb; |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | | void wd1772_t::setup_drq_cb(line_cb cb) |
| 80 | void wd177x_t::setup_drq_cb(line_cb cb) |
| 79 | 81 | { |
| 80 | 82 | drq_cb = cb; |
| 81 | 83 | } |
| 82 | 84 | |
| 83 | | void wd1772_t::dden_w(bool _dden) |
| 85 | void wd177x_t::dden_w(bool _dden) |
| 84 | 86 | { |
| 85 | 87 | dden = _dden; |
| 86 | 88 | } |
| 87 | 89 | |
| 88 | | astring wd1772_t::tts(attotime t) |
| 90 | astring wd177x_t::tts(attotime t) |
| 89 | 91 | { |
| 90 | 92 | char buf[256]; |
| 91 | 93 | int nsec = t.attoseconds / ATTOSECONDS_PER_NANOSECOND; |
| r13298 | r13299 | |
| 93 | 95 | return buf; |
| 94 | 96 | } |
| 95 | 97 | |
| 96 | | astring wd1772_t::ttsn() |
| 98 | astring wd177x_t::ttsn() |
| 97 | 99 | { |
| 98 | 100 | return tts(machine().time()); |
| 99 | 101 | } |
| 100 | 102 | |
| 101 | | void wd1772_t::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 103 | void wd177x_t::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 102 | 104 | { |
| 103 | 105 | live_sync(); |
| 104 | 106 | |
| r13298 | r13299 | |
| 112 | 114 | general_continue(); |
| 113 | 115 | } |
| 114 | 116 | |
| 115 | | void wd1772_t::command_end() |
| 117 | void wd177x_t::command_end() |
| 116 | 118 | { |
| 117 | 119 | main_state = sub_state = IDLE; |
| 118 | 120 | status &= ~S_BUSY; |
| r13298 | r13299 | |
| 122 | 124 | intrq_cb(intrq); |
| 123 | 125 | } |
| 124 | 126 | |
| 125 | | void wd1772_t::seek_start(int state) |
| 127 | void wd177x_t::seek_start(int state) |
| 126 | 128 | { |
| 127 | 129 | main_state = state; |
| 128 | 130 | status = (status & ~(S_CRC|S_RNF|S_SPIN)) | S_BUSY; |
| 129 | | sub_state = SPINUP; |
| 131 | sub_state = has_motor() ? SPINUP : SPINUP_DONE; |
| 130 | 132 | status_type_1 = true; |
| 131 | 133 | seek_continue(); |
| 132 | 134 | } |
| 133 | 135 | |
| 134 | | void wd1772_t::seek_continue() |
| 136 | void wd177x_t::seek_continue() |
| 135 | 137 | { |
| 136 | 138 | for(;;) { |
| 137 | 139 | switch(sub_state) { |
| r13298 | r13299 | |
| 174 | 176 | } |
| 175 | 177 | counter++; |
| 176 | 178 | sub_state = SEEK_WAIT_STEP_TIME; |
| 177 | | delay_cycles(t_gen, step_times[command & 3]); |
| 179 | delay_cycles(t_gen, step_time(command & 3)); |
| 178 | 180 | return; |
| 179 | 181 | |
| 180 | 182 | case SEEK_WAIT_STEP_TIME: |
| r13298 | r13299 | |
| 254 | 256 | } |
| 255 | 257 | } |
| 256 | 258 | |
| 257 | | void wd1772_t::read_sector_start() |
| 259 | bool wd177x_t::sector_matches() const |
| 258 | 260 | { |
| 261 | if(cur_live.idbuf[0] != track || cur_live.idbuf[2] != sector) |
| 262 | return false; |
| 263 | if(!has_side_check()) |
| 264 | return true; |
| 265 | if(command & 8) |
| 266 | return cur_live.idbuf[1] & 1; |
| 267 | else |
| 268 | return !(cur_live.idbuf[1] & 1); |
| 269 | } |
| 270 | |
| 271 | void wd177x_t::read_sector_start() |
| 272 | { |
| 259 | 273 | main_state = READ_SECTOR; |
| 260 | 274 | status = (status & ~(S_CRC|S_LOST|S_RNF|S_WP|S_DDM)) | S_BUSY; |
| 261 | 275 | drop_drq(); |
| 262 | | sub_state = SPINUP; |
| 276 | sub_state = has_motor() ? SPINUP : SPINUP_DONE; |
| 263 | 277 | status_type_1 = false; |
| 264 | 278 | read_sector_continue(); |
| 265 | 279 | } |
| 266 | 280 | |
| 267 | | void wd1772_t::read_sector_continue() |
| 281 | void wd177x_t::read_sector_continue() |
| 268 | 282 | { |
| 269 | 283 | static int size_codes[4] = { 128, 256, 512, 1024 }; |
| 270 | 284 | |
| r13298 | r13299 | |
| 284 | 298 | case SPINUP_DONE: |
| 285 | 299 | if(command & 4) { |
| 286 | 300 | sub_state = SETTLE_WAIT; |
| 287 | | delay_cycles(t_gen, 120000); |
| 301 | delay_cycles(t_gen, settle_time()); |
| 288 | 302 | return; |
| 289 | 303 | } else { |
| 290 | 304 | sub_state = SETTLE_DONE; |
| r13298 | r13299 | |
| 301 | 315 | return; |
| 302 | 316 | |
| 303 | 317 | case SCAN_ID: |
| 304 | | if(cur_live.idbuf[0] != track || cur_live.idbuf[2] != sector) { |
| 318 | if(!sector_matches()) { |
| 305 | 319 | live_start(SEARCH_ADDRESS_MARK); |
| 306 | 320 | return; |
| 307 | 321 | } |
| r13298 | r13299 | |
| 340 | 354 | } |
| 341 | 355 | } |
| 342 | 356 | |
| 343 | | void wd1772_t::read_track_start() |
| 357 | void wd177x_t::read_track_start() |
| 344 | 358 | { |
| 345 | 359 | main_state = READ_TRACK; |
| 346 | 360 | status = (status & ~(S_LOST|S_RNF)) | S_BUSY; |
| 347 | 361 | drop_drq(); |
| 348 | | sub_state = SPINUP; |
| 362 | sub_state = has_motor() ? SPINUP : SPINUP_DONE; |
| 349 | 363 | status_type_1 = false; |
| 350 | 364 | read_track_continue(); |
| 351 | 365 | } |
| 352 | 366 | |
| 353 | | void wd1772_t::read_track_continue() |
| 367 | void wd177x_t::read_track_continue() |
| 354 | 368 | { |
| 355 | 369 | for(;;) { |
| 356 | 370 | switch(sub_state) { |
| r13298 | r13299 | |
| 368 | 382 | case SPINUP_DONE: |
| 369 | 383 | if(command & 4) { |
| 370 | 384 | sub_state = SETTLE_WAIT; |
| 371 | | delay_cycles(t_gen, 120000); |
| 385 | delay_cycles(t_gen, settle_time()); |
| 372 | 386 | return; |
| 373 | 387 | |
| 374 | 388 | } else { |
| r13298 | r13299 | |
| 403 | 417 | } |
| 404 | 418 | } |
| 405 | 419 | |
| 406 | | void wd1772_t::read_id_start() |
| 420 | void wd177x_t::read_id_start() |
| 407 | 421 | { |
| 408 | 422 | main_state = READ_ID; |
| 409 | 423 | status = (status & ~(S_WP|S_DDM|S_LOST|S_RNF)) | S_BUSY; |
| 410 | 424 | drop_drq(); |
| 411 | | sub_state = SPINUP; |
| 425 | sub_state = has_motor() ? SPINUP : SPINUP_DONE; |
| 412 | 426 | status_type_1 = false; |
| 413 | 427 | read_id_continue(); |
| 414 | 428 | } |
| 415 | 429 | |
| 416 | | void wd1772_t::read_id_continue() |
| 430 | void wd177x_t::read_id_continue() |
| 417 | 431 | { |
| 418 | 432 | for(;;) { |
| 419 | 433 | switch(sub_state) { |
| r13298 | r13299 | |
| 431 | 445 | case SPINUP_DONE: |
| 432 | 446 | if(command & 4) { |
| 433 | 447 | sub_state = SETTLE_WAIT; |
| 434 | | delay_cycles(t_gen, 120000); |
| 448 | delay_cycles(t_gen, settle_time()); |
| 435 | 449 | return; |
| 436 | 450 | } else { |
| 437 | 451 | sub_state = SETTLE_DONE; |
| r13298 | r13299 | |
| 463 | 477 | } |
| 464 | 478 | } |
| 465 | 479 | |
| 466 | | void wd1772_t::write_track_start() |
| 480 | void wd177x_t::write_track_start() |
| 467 | 481 | { |
| 468 | 482 | main_state = WRITE_TRACK; |
| 469 | 483 | status = (status & ~(S_WP|S_DDM|S_LOST|S_RNF)) | S_BUSY; |
| 470 | 484 | drop_drq(); |
| 471 | | sub_state = SPINUP; |
| 485 | sub_state = has_motor() ? SPINUP : SPINUP_DONE; |
| 472 | 486 | status_type_1 = false; |
| 473 | 487 | write_track_continue(); |
| 474 | 488 | } |
| 475 | 489 | |
| 476 | | void wd1772_t::write_track_continue() |
| 490 | void wd177x_t::write_track_continue() |
| 477 | 491 | { |
| 478 | 492 | for(;;) { |
| 479 | 493 | switch(sub_state) { |
| r13298 | r13299 | |
| 491 | 505 | case SPINUP_DONE: |
| 492 | 506 | if(command & 4) { |
| 493 | 507 | sub_state = SETTLE_WAIT; |
| 494 | | delay_cycles(t_gen, 120000); |
| 508 | delay_cycles(t_gen, settle_time()); |
| 495 | 509 | return; |
| 496 | 510 | } else { |
| 497 | 511 | sub_state = SETTLE_DONE; |
| r13298 | r13299 | |
| 539 | 553 | } |
| 540 | 554 | |
| 541 | 555 | |
| 542 | | void wd1772_t::write_sector_start() |
| 556 | void wd177x_t::write_sector_start() |
| 543 | 557 | { |
| 544 | 558 | main_state = WRITE_SECTOR; |
| 545 | 559 | status = (status & ~(S_CRC|S_LOST|S_RNF|S_WP|S_DDM)) | S_BUSY; |
| 546 | 560 | drop_drq(); |
| 547 | | sub_state = SPINUP; |
| 561 | sub_state = has_motor() ? SPINUP : SPINUP_DONE; |
| 548 | 562 | status_type_1 = false; |
| 549 | 563 | write_sector_continue(); |
| 550 | 564 | } |
| 551 | 565 | |
| 552 | | void wd1772_t::write_sector_continue() |
| 566 | void wd177x_t::write_sector_continue() |
| 553 | 567 | { |
| 554 | 568 | static int size_codes[4] = { 128, 256, 512, 1024 }; |
| 555 | 569 | |
| r13298 | r13299 | |
| 569 | 583 | case SPINUP_DONE: |
| 570 | 584 | if(command & 4) { |
| 571 | 585 | sub_state = SETTLE_WAIT; |
| 572 | | delay_cycles(t_gen, 120000); |
| 586 | delay_cycles(t_gen, settle_time()); |
| 573 | 587 | return; |
| 574 | 588 | } else { |
| 575 | 589 | sub_state = SETTLE_DONE; |
| r13298 | r13299 | |
| 586 | 600 | return; |
| 587 | 601 | |
| 588 | 602 | case SCAN_ID: |
| 589 | | if(cur_live.idbuf[0] != track || cur_live.idbuf[2] != sector) { |
| 603 | if(!sector_matches()) { |
| 590 | 604 | live_start(SEARCH_ADDRESS_MARK); |
| 591 | 605 | return; |
| 592 | 606 | } |
| r13298 | r13299 | |
| 622 | 636 | } |
| 623 | 637 | } |
| 624 | 638 | |
| 625 | | void wd1772_t::interrupt_start() |
| 639 | void wd177x_t::interrupt_start() |
| 626 | 640 | { |
| 627 | 641 | if(status & S_BUSY) { |
| 628 | 642 | main_state = sub_state = cur_live.state = IDLE; |
| r13298 | r13299 | |
| 636 | 650 | } |
| 637 | 651 | } |
| 638 | 652 | |
| 639 | | void wd1772_t::general_continue() |
| 653 | void wd177x_t::general_continue() |
| 640 | 654 | { |
| 641 | 655 | if(cur_live.state != IDLE) { |
| 642 | 656 | live_run(); |
| r13298 | r13299 | |
| 671 | 685 | } |
| 672 | 686 | } |
| 673 | 687 | |
| 674 | | void wd1772_t::do_generic() |
| 688 | void wd177x_t::do_generic() |
| 675 | 689 | { |
| 676 | 690 | switch(sub_state) { |
| 677 | 691 | case IDLE: |
| r13298 | r13299 | |
| 702 | 716 | } |
| 703 | 717 | } |
| 704 | 718 | |
| 705 | | void wd1772_t::do_cmd_w() |
| 719 | void wd177x_t::do_cmd_w() |
| 706 | 720 | { |
| 707 | 721 | // fprintf(stderr, "%s: command %02x\n", ttsn().cstr(), cmd_buffer); |
| 708 | 722 | |
| r13298 | r13299 | |
| 729 | 743 | } |
| 730 | 744 | } |
| 731 | 745 | |
| 732 | | void wd1772_t::cmd_w(UINT8 val) |
| 746 | void wd177x_t::cmd_w(UINT8 val) |
| 733 | 747 | { |
| 734 | 748 | if(intrq && ((command & 0xf8) != 0xd8)) { |
| 735 | 749 | intrq = false; |
| r13298 | r13299 | |
| 746 | 760 | delay_cycles(t_cmd, dden ? 384 : 184); |
| 747 | 761 | } |
| 748 | 762 | |
| 749 | | UINT8 wd1772_t::status_r() |
| 763 | UINT8 wd177x_t::status_r() |
| 750 | 764 | { |
| 751 | 765 | if(intrq && ((command & 0xf8) != 0xd8)) { |
| 752 | 766 | intrq = false; |
| r13298 | r13299 | |
| 779 | 793 | return status; |
| 780 | 794 | } |
| 781 | 795 | |
| 782 | | void wd1772_t::do_track_w() |
| 796 | void wd177x_t::do_track_w() |
| 783 | 797 | { |
| 784 | 798 | track = track_buffer; |
| 785 | 799 | track_buffer = -1; |
| 786 | 800 | } |
| 787 | 801 | |
| 788 | | void wd1772_t::track_w(UINT8 val) |
| 802 | void wd177x_t::track_w(UINT8 val) |
| 789 | 803 | { |
| 790 | 804 | // No more than one write in flight |
| 791 | 805 | if(track_buffer != -1) |
| r13298 | r13299 | |
| 795 | 809 | delay_cycles(t_track, dden ? 256 : 128); |
| 796 | 810 | } |
| 797 | 811 | |
| 798 | | UINT8 wd1772_t::track_r() |
| 812 | UINT8 wd177x_t::track_r() |
| 799 | 813 | { |
| 800 | 814 | return track; |
| 801 | 815 | } |
| 802 | 816 | |
| 803 | | void wd1772_t::do_sector_w() |
| 817 | void wd177x_t::do_sector_w() |
| 804 | 818 | { |
| 805 | 819 | sector = sector_buffer; |
| 806 | 820 | sector_buffer = -1; |
| 807 | 821 | } |
| 808 | 822 | |
| 809 | | void wd1772_t::sector_w(UINT8 val) |
| 823 | void wd177x_t::sector_w(UINT8 val) |
| 810 | 824 | { |
| 811 | 825 | // No more than one write in flight |
| 812 | 826 | if(sector_buffer != -1) |
| r13298 | r13299 | |
| 816 | 830 | delay_cycles(t_sector, dden ? 256 : 128); |
| 817 | 831 | } |
| 818 | 832 | |
| 819 | | UINT8 wd1772_t::sector_r() |
| 833 | UINT8 wd177x_t::sector_r() |
| 820 | 834 | { |
| 821 | 835 | return sector; |
| 822 | 836 | } |
| 823 | 837 | |
| 824 | | void wd1772_t::data_w(UINT8 val) |
| 838 | void wd177x_t::data_w(UINT8 val) |
| 825 | 839 | { |
| 826 | 840 | data = val; |
| 827 | 841 | drop_drq(); |
| 828 | 842 | } |
| 829 | 843 | |
| 830 | | UINT8 wd1772_t::data_r() |
| 844 | UINT8 wd177x_t::data_r() |
| 831 | 845 | { |
| 832 | 846 | drop_drq(); |
| 833 | 847 | return data; |
| 834 | 848 | } |
| 835 | 849 | |
| 836 | | void wd1772_t::gen_w(int reg, UINT8 val) |
| 850 | void wd177x_t::gen_w(int reg, UINT8 val) |
| 837 | 851 | { |
| 838 | 852 | switch(reg) { |
| 839 | 853 | case 0: cmd_w(val); break; |
| r13298 | r13299 | |
| 843 | 857 | } |
| 844 | 858 | } |
| 845 | 859 | |
| 846 | | UINT8 wd1772_t::gen_r(int reg) |
| 860 | UINT8 wd177x_t::gen_r(int reg) |
| 847 | 861 | { |
| 848 | 862 | switch(reg) { |
| 849 | 863 | case 0: return status_r(); break; |
| r13298 | r13299 | |
| 854 | 868 | return 0xff; |
| 855 | 869 | } |
| 856 | 870 | |
| 857 | | void wd1772_t::delay_cycles(emu_timer *tm, int cycles) |
| 871 | void wd177x_t::delay_cycles(emu_timer *tm, int cycles) |
| 858 | 872 | { |
| 859 | 873 | tm->adjust(clocks_to_attotime(cycles)); |
| 860 | 874 | } |
| 861 | 875 | |
| 862 | | void wd1772_t::spinup() |
| 876 | void wd177x_t::spinup() |
| 863 | 877 | { |
| 864 | 878 | if(command & 0x08) |
| 865 | 879 | sub_state = SPINUP_DONE; |
| r13298 | r13299 | |
| 874 | 888 | |
| 875 | 889 | } |
| 876 | 890 | |
| 877 | | void wd1772_t::index_callback(floppy_image_device *floppy, int state) |
| 891 | void wd177x_t::index_callback(floppy_image_device *floppy, int state) |
| 878 | 892 | { |
| 879 | 893 | live_sync(); |
| 880 | 894 | |
| r13298 | r13299 | |
| 885 | 899 | |
| 886 | 900 | switch(sub_state) { |
| 887 | 901 | case IDLE: |
| 888 | | motor_timeout ++; |
| 889 | | if(motor_timeout >= 5) { |
| 890 | | status &= ~S_MON; |
| 891 | | if(floppy) |
| 892 | | floppy->mon_w(1); |
| 902 | if(has_motor()) { |
| 903 | motor_timeout ++; |
| 904 | if(motor_timeout >= 5) { |
| 905 | status &= ~S_MON; |
| 906 | if(floppy) |
| 907 | floppy->mon_w(1); |
| 908 | } |
| 893 | 909 | } |
| 894 | 910 | break; |
| 895 | 911 | |
| r13298 | r13299 | |
| 944 | 960 | general_continue(); |
| 945 | 961 | } |
| 946 | 962 | |
| 947 | | bool wd1772_t::intrq_r() |
| 963 | bool wd177x_t::intrq_r() |
| 948 | 964 | { |
| 949 | 965 | return intrq; |
| 950 | 966 | } |
| 951 | 967 | |
| 952 | | bool wd1772_t::drq_r() |
| 968 | bool wd177x_t::drq_r() |
| 953 | 969 | { |
| 954 | 970 | return drq; |
| 955 | 971 | } |
| 956 | 972 | |
| 957 | | void wd1772_t::live_start(int state) |
| 973 | void wd177x_t::live_start(int state) |
| 958 | 974 | { |
| 959 | 975 | cur_live.tm = machine().time(); |
| 960 | 976 | cur_live.state = state; |
| r13298 | r13299 | |
| 974 | 990 | live_run(); |
| 975 | 991 | } |
| 976 | 992 | |
| 977 | | void wd1772_t::checkpoint() |
| 993 | void wd177x_t::checkpoint() |
| 978 | 994 | { |
| 979 | 995 | cur_live.pll.commit(floppy, cur_live.tm); |
| 980 | 996 | checkpoint_live = cur_live; |
| 981 | 997 | } |
| 982 | 998 | |
| 983 | | void wd1772_t::rollback() |
| 999 | void wd177x_t::rollback() |
| 984 | 1000 | { |
| 985 | 1001 | cur_live = checkpoint_live; |
| 986 | 1002 | } |
| 987 | 1003 | |
| 988 | | void wd1772_t::live_delay(int state) |
| 1004 | void wd177x_t::live_delay(int state) |
| 989 | 1005 | { |
| 990 | 1006 | cur_live.next_state = state; |
| 991 | 1007 | t_gen->adjust(cur_live.tm - machine().time()); |
| 992 | 1008 | } |
| 993 | 1009 | |
| 994 | | void wd1772_t::live_sync() |
| 1010 | void wd177x_t::live_sync() |
| 995 | 1011 | { |
| 996 | 1012 | if(!cur_live.tm.is_never()) { |
| 997 | 1013 | if(cur_live.tm > machine().time()) { |
| r13298 | r13299 | |
| 1014 | 1030 | } |
| 1015 | 1031 | } |
| 1016 | 1032 | |
| 1017 | | void wd1772_t::live_abort() |
| 1033 | void wd177x_t::live_abort() |
| 1018 | 1034 | { |
| 1019 | 1035 | if(cur_live.tm > machine().time()) { |
| 1020 | 1036 | rollback(); |
| r13298 | r13299 | |
| 1027 | 1043 | cur_live.next_state = -1; |
| 1028 | 1044 | } |
| 1029 | 1045 | |
| 1030 | | bool wd1772_t::read_one_bit(attotime limit) |
| 1046 | bool wd177x_t::read_one_bit(attotime limit) |
| 1031 | 1047 | { |
| 1032 | 1048 | int bit = cur_live.pll.get_next_bit(cur_live.tm, floppy, limit); |
| 1033 | 1049 | if(bit < 0) |
| r13298 | r13299 | |
| 1045 | 1061 | return false; |
| 1046 | 1062 | } |
| 1047 | 1063 | |
| 1048 | | bool wd1772_t::write_one_bit(attotime limit) |
| 1064 | bool wd177x_t::write_one_bit(attotime limit) |
| 1049 | 1065 | { |
| 1050 | 1066 | bool bit = cur_live.shift_reg & 0x8000; |
| 1051 | 1067 | if(cur_live.pll.write_next_bit(bit, cur_live.tm, floppy, limit)) |
| r13298 | r13299 | |
| 1061 | 1077 | return false; |
| 1062 | 1078 | } |
| 1063 | 1079 | |
| 1064 | | void wd1772_t::live_write_raw(UINT16 raw) |
| 1080 | void wd177x_t::live_write_raw(UINT16 raw) |
| 1065 | 1081 | { |
| 1066 | 1082 | // logerror("write %04x %04x\n", raw, cur_live.crc); |
| 1067 | 1083 | cur_live.shift_reg = raw; |
| 1068 | 1084 | cur_live.data_bit_context = raw & 1; |
| 1069 | 1085 | } |
| 1070 | 1086 | |
| 1071 | | void wd1772_t::live_write_mfm(UINT8 mfm) |
| 1087 | void wd177x_t::live_write_mfm(UINT8 mfm) |
| 1072 | 1088 | { |
| 1073 | 1089 | bool context = cur_live.data_bit_context; |
| 1074 | 1090 | UINT16 raw = 0; |
| r13298 | r13299 | |
| 1085 | 1101 | // logerror("write %02x %04x %04x\n", mfm, cur_live.crc, raw); |
| 1086 | 1102 | } |
| 1087 | 1103 | |
| 1088 | | void wd1772_t::live_run(attotime limit) |
| 1104 | void wd177x_t::live_run(attotime limit) |
| 1089 | 1105 | { |
| 1090 | 1106 | if(cur_live.state == IDLE || cur_live.next_state != -1) |
| 1091 | 1107 | return; |
| r13298 | r13299 | |
| 1436 | 1452 | } |
| 1437 | 1453 | } |
| 1438 | 1454 | |
| 1439 | | void wd1772_t::set_drq() |
| 1455 | void wd177x_t::set_drq() |
| 1440 | 1456 | { |
| 1441 | 1457 | if(drq) |
| 1442 | 1458 | status |= S_LOST; |
| r13298 | r13299 | |
| 1447 | 1463 | } |
| 1448 | 1464 | } |
| 1449 | 1465 | |
| 1450 | | void wd1772_t::drop_drq() |
| 1466 | void wd177x_t::drop_drq() |
| 1451 | 1467 | { |
| 1452 | 1468 | if(drq) { |
| 1453 | 1469 | drq = false; |
| r13298 | r13299 | |
| 1456 | 1472 | } |
| 1457 | 1473 | } |
| 1458 | 1474 | |
| 1459 | | void wd1772_t::pll_t::set_clock(attotime period) |
| 1475 | void wd177x_t::pll_t::set_clock(attotime period) |
| 1460 | 1476 | { |
| 1461 | 1477 | for(int i=0; i<42; i++) |
| 1462 | 1478 | delays[i] = period*(i+1); |
| 1463 | 1479 | } |
| 1464 | 1480 | |
| 1465 | | void wd1772_t::pll_t::reset(attotime when) |
| 1481 | void wd177x_t::pll_t::reset(attotime when) |
| 1466 | 1482 | { |
| 1467 | 1483 | counter = 0; |
| 1468 | 1484 | increment = 128; |
| r13298 | r13299 | |
| 1478 | 1494 | write_start_time = attotime::never; |
| 1479 | 1495 | } |
| 1480 | 1496 | |
| 1481 | | int wd1772_t::pll_t::get_next_bit(attotime &tm, floppy_image_device *floppy, attotime limit) |
| 1497 | int wd177x_t::pll_t::get_next_bit(attotime &tm, floppy_image_device *floppy, attotime limit) |
| 1482 | 1498 | { |
| 1483 | 1499 | attotime when = floppy ? floppy->get_next_transition(ctime) : attotime::never; |
| 1484 | 1500 | #if 0 |
| r13298 | r13299 | |
| 1558 | 1574 | return bit; |
| 1559 | 1575 | } |
| 1560 | 1576 | |
| 1561 | | void wd1772_t::pll_t::start_writing(attotime tm) |
| 1577 | void wd177x_t::pll_t::start_writing(attotime tm) |
| 1562 | 1578 | { |
| 1563 | 1579 | write_start_time = tm; |
| 1564 | 1580 | write_position = 0; |
| 1565 | 1581 | } |
| 1566 | 1582 | |
| 1567 | | void wd1772_t::pll_t::stop_writing(floppy_image_device *floppy, attotime tm) |
| 1583 | void wd177x_t::pll_t::stop_writing(floppy_image_device *floppy, attotime tm) |
| 1568 | 1584 | { |
| 1569 | 1585 | commit(floppy, tm); |
| 1570 | 1586 | write_start_time = attotime::never; |
| 1571 | 1587 | } |
| 1572 | 1588 | |
| 1573 | | bool wd1772_t::pll_t::write_next_bit(bool bit, attotime &tm, floppy_image_device *floppy, attotime limit) |
| 1589 | bool wd177x_t::pll_t::write_next_bit(bool bit, attotime &tm, floppy_image_device *floppy, attotime limit) |
| 1574 | 1590 | { |
| 1575 | 1591 | if(write_start_time == attotime::never) { |
| 1576 | 1592 | write_start_time = ctime; |
| r13298 | r13299 | |
| 1600 | 1616 | return false; |
| 1601 | 1617 | } |
| 1602 | 1618 | |
| 1603 | | void wd1772_t::pll_t::commit(floppy_image_device *floppy, attotime tm) |
| 1619 | void wd177x_t::pll_t::commit(floppy_image_device *floppy, attotime tm) |
| 1604 | 1620 | { |
| 1605 | 1621 | if(write_start_time == attotime::never || tm == write_start_time) |
| 1606 | 1622 | return; |
| r13298 | r13299 | |
| 1610 | 1626 | write_start_time = tm; |
| 1611 | 1627 | write_position = 0; |
| 1612 | 1628 | } |
| 1629 | |
| 1630 | int wd177x_t::step_time(int mode) const |
| 1631 | { |
| 1632 | const static int step_times[4] = { 48000, 96000, 160000, 240000 }; |
| 1633 | return step_times[mode]; |
| 1634 | } |
| 1635 | |
| 1636 | int wd177x_t::settle_time() const |
| 1637 | { |
| 1638 | return 240000; |
| 1639 | } |
| 1640 | |
| 1641 | bool wd177x_t::has_side_check() const |
| 1642 | { |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
| 1646 | wd1770_t::wd1770_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : wd177x_t(mconfig, WD1770x, "WD1770", tag, owner, clock) |
| 1647 | { |
| 1648 | } |
| 1649 | |
| 1650 | bool wd1770_t::has_motor() const |
| 1651 | { |
| 1652 | return true; |
| 1653 | } |
| 1654 | |
| 1655 | wd1772_t::wd1772_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : wd177x_t(mconfig, WD1772x, "WD1772", tag, owner, clock) |
| 1656 | { |
| 1657 | } |
| 1658 | |
| 1659 | bool wd1772_t::has_motor() const |
| 1660 | { |
| 1661 | return true; |
| 1662 | } |
| 1663 | |
| 1664 | int wd1772_t::step_time(int mode) const |
| 1665 | { |
| 1666 | const static int step_times[4] = { 48000, 96000, 16000, 24000 }; |
| 1667 | return step_times[mode]; |
| 1668 | } |
| 1669 | |
| 1670 | int wd1772_t::settle_time() const |
| 1671 | { |
| 1672 | return 120000; |
| 1673 | } |
| 1674 | |
| 1675 | wd1773_t::wd1773_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : wd177x_t(mconfig, WD1773x, "WD1773", tag, owner, clock) |
| 1676 | { |
| 1677 | } |
| 1678 | |
| 1679 | bool wd1773_t::has_motor() const |
| 1680 | { |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
| 1684 | bool wd1773_t::has_side_check() const |
| 1685 | { |
| 1686 | return false; |
| 1687 | } |
src/mess/machine/wd1772.h
| r13298 | r13299 | |
| 4 | 4 | #include "emu.h" |
| 5 | 5 | #include "imagedev/floppy.h" |
| 6 | 6 | |
| 7 | #define MCFG_WD1770x_ADD(_tag, _clock) \ |
| 8 | MCFG_DEVICE_ADD(_tag, WD1770x, _clock) |
| 9 | |
| 7 | 10 | #define MCFG_WD1772x_ADD(_tag, _clock) \ |
| 8 | 11 | MCFG_DEVICE_ADD(_tag, WD1772x, _clock) |
| 9 | 12 | |
| 10 | | class wd1772_t : public device_t { |
| 13 | #define MCFG_WD1773x_ADD(_tag, _clock) \ |
| 14 | MCFG_DEVICE_ADD(_tag, WD1773x, _clock) |
| 15 | |
| 16 | class wd177x_t : public device_t { |
| 11 | 17 | public: |
| 12 | 18 | typedef delegate<void (bool state)> line_cb; |
| 13 | 19 | |
| 14 | | wd1772_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 20 | wd177x_t(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); |
| 15 | 21 | |
| 16 | 22 | void dden_w(bool dden); |
| 17 | 23 | void set_floppy(floppy_image_device *floppy); |
| r13298 | r13299 | |
| 44 | 50 | virtual void device_reset(); |
| 45 | 51 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 46 | 52 | |
| 53 | virtual bool has_motor() const = 0; |
| 54 | virtual bool has_side_check() const; |
| 55 | virtual int step_time(int mode) const; |
| 56 | virtual int settle_time() const; |
| 57 | |
| 47 | 58 | private: |
| 48 | 59 | enum { TM_GEN, TM_CMD, TM_TRACK, TM_SECTOR }; |
| 49 | 60 | |
| r13298 | r13299 | |
| 200 | 211 | S_MON = 0x80 |
| 201 | 212 | }; |
| 202 | 213 | |
| 203 | | const static int step_times[4]; |
| 204 | | |
| 205 | 214 | floppy_image_device *floppy; |
| 206 | 215 | |
| 207 | 216 | emu_timer *t_gen, *t_cmd, *t_track, *t_sector; |
| r13298 | r13299 | |
| 257 | 266 | |
| 258 | 267 | void spinup(); |
| 259 | 268 | void index_callback(floppy_image_device *floppy, int state); |
| 269 | bool sector_matches() const; |
| 260 | 270 | |
| 261 | 271 | void live_start(int live_state); |
| 262 | 272 | void live_abort(); |
| r13298 | r13299 | |
| 275 | 285 | void set_drq(); |
| 276 | 286 | }; |
| 277 | 287 | |
| 288 | class wd1770_t : public wd177x_t { |
| 289 | public: |
| 290 | wd1770_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 291 | |
| 292 | protected: |
| 293 | virtual bool has_motor() const; |
| 294 | }; |
| 295 | |
| 296 | class wd1772_t : public wd177x_t { |
| 297 | public: |
| 298 | wd1772_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 299 | |
| 300 | protected: |
| 301 | virtual bool has_motor() const; |
| 302 | virtual int step_time(int mode) const; |
| 303 | virtual int settle_time() const; |
| 304 | }; |
| 305 | |
| 306 | class wd1773_t : public wd177x_t { |
| 307 | public: |
| 308 | wd1773_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 309 | |
| 310 | protected: |
| 311 | virtual bool has_motor() const; |
| 312 | virtual bool has_side_check() const; |
| 313 | }; |
| 314 | |
| 315 | extern const device_type WD1770x; |
| 278 | 316 | extern const device_type WD1772x; |
| 317 | extern const device_type WD1773x; |
| 279 | 318 | |
| 280 | 319 | #endif |