src/mess/machine/pc_hdc.c
| r2654 | r2655 | |
| 14 | 14 | The format of the so called 'POD' (power on drive paramters?) area |
| 15 | 15 | read from the MBR (master boot record) at offset 1AD to 1BD is wrong. |
| 16 | 16 | |
| 17 | |
| 18 | |
| 19 | There were a lot of different Fixed Disk Adapter for the IBM pcs. |
| 20 | Xebec produced a couple of the Fixed Disk Adapter for IBM. |
| 21 | |
| 22 | One Xebec Adapter has these roms on it: |
| 23 | One MK6xxxx ROM: 62X0822__(M)_AMI_8621MAB__S68B364-P__(C)IBM_CORP_1982,1985__PHILIPPINES.12D.2364.bin |
| 24 | One 2732 ROM for the Z80: 104839RE__COPYRIGHT__XEBEC_1986.12A.2732.bin |
| 25 | |
| 26 | |
| 27 | tandon Fixed Disk Adapter found in an IBM 5150: |
| 28 | 600963-001__TYPE_5.U12.2764.bin |
| 29 | |
| 17 | 30 | ***************************************************************************/ |
| 18 | 31 | |
| 19 | | #include <stdio.h> |
| 20 | | |
| 21 | 32 | #include "driver.h" |
| 22 | | #include "deprecat.h" |
| 23 | 33 | #include "machine/pc_hdc.h" |
| 24 | | #include "machine/pic8259.h" |
| 25 | 34 | #include "machine/8237dma.h" |
| 26 | 35 | #include "devices/harddriv.h" |
| 27 | 36 | #include "memconv.h" |
| r2654 | r2655 | |
| 73 | 82 | |
| 74 | 83 | /* XT hard disk controller control bits */ |
| 75 | 84 | #define CTL_PIO 0x00 |
| 76 | | #define CTL_DMA 0x03 |
| 85 | #define CTL_DMA 0x01 |
| 77 | 86 | |
| 78 | 87 | static int idx = 0; /* contoller * 2 + drive */ |
| 79 | 88 | static int drv = 0; /* 0 master, 1 slave drive */ |
| r2654 | r2655 | |
| 99 | 108 | |
| 100 | 109 | static int data_cnt = 0; /* data count */ |
| 101 | 110 | static UINT8 *buffer; /* data buffer */ |
| 102 | | static UINT8 *ptr = 0; /* data pointer */ |
| 111 | static UINT8 *buffer_ptr = 0; /* data pointer */ |
| 103 | 112 | static UINT8 hdc_control; |
| 104 | 113 | static void (*hdc_set_irq)(int,int); |
| 114 | static const device_config *pc_hdc_dma8237; |
| 105 | 115 | |
| 116 | |
| 106 | 117 | static const char *const hdc_command_names[] = |
| 107 | 118 | { |
| 108 | 119 | "CMD_TESTREADY", /* 0x00 */ |
| r2654 | r2655 | |
| 182 | 193 | status[i] = 0; |
| 183 | 194 | error[i] = 0; |
| 184 | 195 | dip[i] = 0xff; |
| 196 | pc_hdc_dma8237 = NULL; |
| 185 | 197 | timer[i] = timer_alloc(pc_hdc_command, NULL); |
| 186 | 198 | if (!timer[i]) |
| 187 | 199 | return -1; |
| r2654 | r2655 | |
| 189 | 201 | return 0; |
| 190 | 202 | } |
| 191 | 203 | |
| 204 | |
| 205 | void pc_hdc_set_dma8237_device( const device_config *dma8237 ) |
| 206 | { |
| 207 | pc_hdc_dma8237 = dma8237; |
| 208 | } |
| 209 | |
| 210 | |
| 192 | 211 | static hard_disk_file *pc_hdc_file(int id) |
| 193 | 212 | { |
| 194 | 213 | const device_config *img; |
| r2654 | r2655 | |
| 200 | 219 | return mess_hd_get_hard_disk_file(img); |
| 201 | 220 | } |
| 202 | 221 | |
| 203 | | static void pc_hdc_result(int n) |
| 222 | static void pc_hdc_result(int n, int set_error_info) |
| 204 | 223 | { |
| 205 | 224 | int irq; |
| 206 | 225 | |
| 207 | 226 | /* dip switch selected INT 5 or 2 */ |
| 208 | 227 | irq = (dip[n] & 0x40) ? 5 : 2; |
| 209 | 228 | |
| 210 | | if ( hdc_set_irq ) { |
| 229 | if ( ( hdc_control & 0x02 ) && hdc_set_irq ) { |
| 211 | 230 | hdc_set_irq( irq, 1 ); |
| 212 | | hdc_set_irq( irq, 0 ); |
| 213 | 231 | } |
| 214 | 232 | |
| 215 | 233 | if (LOG_HDC_STATUS) |
| r2654 | r2655 | |
| 217 | 235 | |
| 218 | 236 | buffer[data_cnt++] = csb[n]; |
| 219 | 237 | |
| 220 | | if (csb[n] & CSB_ERROR) |
| 238 | if (set_error_info && ( csb[n] & CSB_ERROR ) ) |
| 221 | 239 | { |
| 222 | 240 | buffer[data_cnt++] = error[n]; |
| 223 | 241 | if (error[n] & 0x80) |
| r2654 | r2655 | |
| 385 | 403 | } |
| 386 | 404 | else |
| 387 | 405 | { |
| 388 | | dma8237_run_transfer(0, HDC_DMA); |
| 406 | dma8237_run_transfer(pc_hdc_dma8237, HDC_DMA); |
| 389 | 407 | } |
| 390 | 408 | } |
| 391 | 409 | |
| r2654 | r2655 | |
| 417 | 435 | } |
| 418 | 436 | else |
| 419 | 437 | { |
| 420 | | dma8237_run_transfer(0, HDC_DMA); |
| 438 | dma8237_run_transfer(pc_hdc_dma8237, HDC_DMA); |
| 421 | 439 | } |
| 422 | 440 | } |
| 423 | 441 | |
| r2654 | r2655 | |
| 458 | 476 | static TIMER_CALLBACK(pc_hdc_command) |
| 459 | 477 | { |
| 460 | 478 | int n = param; |
| 479 | int set_error_info = 1; |
| 480 | int old_error = error[n]; /* Previous error data is needed for CMD_SENSE */ |
| 481 | int old_csb = csb[n]; |
| 461 | 482 | UINT8 cmd; |
| 462 | 483 | const char *command_name; |
| 463 | 484 | |
| 464 | 485 | csb[n] = 0x00; |
| 465 | 486 | error[n] = 0; |
| 466 | 487 | |
| 467 | | ptr = buffer; |
| 488 | buffer_ptr = buffer; |
| 468 | 489 | cmd = buffer[0]; |
| 469 | 490 | |
| 491 | get_drive(n); |
| 492 | |
| 470 | 493 | if (LOG_HDC_STATUS) |
| 471 | 494 | { |
| 472 | 495 | command_name = hdc_command_names[cmd] ? hdc_command_names[cmd] : "Unknown"; |
| r2654 | r2655 | |
| 477 | 500 | switch (cmd) |
| 478 | 501 | { |
| 479 | 502 | case CMD_TESTREADY: |
| 480 | | case CMD_SENSE: |
| 481 | | get_drive(n); |
| 503 | set_error_info = 0; |
| 482 | 504 | test_ready(n); |
| 483 | 505 | break; |
| 506 | case CMD_SENSE: |
| 507 | error[n] = old_error; |
| 508 | csb[n] = old_csb; |
| 509 | /* Perform error code translation. This may need to be expanded in the future. */ |
| 510 | buffer[data_cnt++] = ( error[n] & 0xC0 ) | ( ( error[n] & 0x04 ) ? 0x04 : 0x00 ) ; |
| 511 | buffer[data_cnt++] = (drv << 5) | head[idx]; |
| 512 | buffer[data_cnt++] = ((cylinder[idx] >> 2) & 0xc0) | sector[idx]; |
| 513 | buffer[data_cnt++] = cylinder[idx] & 0xff; |
| 514 | set_error_info = 0; |
| 515 | break; |
| 484 | 516 | case CMD_RECALIBRATE: |
| 485 | | get_drive(n); |
| 486 | 517 | get_chsn(n); |
| 487 | | /* test_ready(n); */ |
| 518 | test_ready(n); |
| 519 | set_error_info = 0; |
| 488 | 520 | break; |
| 489 | 521 | |
| 490 | 522 | case CMD_FORMATDRV: |
| r2654 | r2655 | |
| 493 | 525 | case CMD_FORMATBAD: |
| 494 | 526 | case CMD_SEEK: |
| 495 | 527 | case CMD_DRIVEDIAG: |
| 496 | | get_drive(n); |
| 497 | 528 | get_chsn(n); |
| 498 | 529 | test_ready(n); |
| 499 | 530 | break; |
| 500 | 531 | |
| 501 | 532 | case CMD_READ: |
| 502 | 533 | case CMD_READLONG: |
| 503 | | get_drive(n); |
| 504 | 534 | get_chsn(n); |
| 505 | 535 | |
| 506 | 536 | if (LOG_HDC_STATUS) |
| r2654 | r2655 | |
| 511 | 541 | |
| 512 | 542 | if (test_ready(n)) |
| 513 | 543 | execute_read(); |
| 544 | set_error_info = 0; |
| 514 | 545 | break; |
| 515 | 546 | |
| 516 | 547 | case CMD_WRITE: |
| 517 | 548 | case CMD_WRITELONG: |
| 518 | | get_drive(n); |
| 519 | 549 | get_chsn(n); |
| 520 | 550 | |
| 521 | 551 | if (LOG_HDC_STATUS) |
| r2654 | r2655 | |
| 529 | 559 | break; |
| 530 | 560 | |
| 531 | 561 | case CMD_SETPARAM: |
| 532 | | get_drive(n); |
| 533 | 562 | get_chsn(n); |
| 534 | 563 | cylinders[idx] = ((buffer[6]&3)<<8) | buffer[7]; |
| 535 | 564 | heads[idx] = buffer[8] & 0x1f; |
| r2654 | r2655 | |
| 549 | 578 | break; |
| 550 | 579 | |
| 551 | 580 | } |
| 552 | | pc_hdc_result(n); |
| 581 | pc_hdc_result(n, set_error_info); |
| 553 | 582 | } |
| 554 | 583 | |
| 555 | 584 | |
| r2654 | r2655 | |
| 580 | 609 | if (LOG_HDC_DATA) |
| 581 | 610 | logerror("hdc_data_w BOARD #%d $%02x: ", n, data); |
| 582 | 611 | |
| 583 | | ptr = buffer; |
| 612 | buffer_ptr = buffer; |
| 584 | 613 | data_cnt = 6; /* expect 6 bytes including this one */ |
| 585 | 614 | status[n] &= ~STA_READY; |
| 586 | 615 | status[n] &= ~STA_INPUT; |
| r2654 | r2655 | |
| 614 | 643 | data_cnt = 0; |
| 615 | 644 | status[n] |= STA_INPUT; |
| 616 | 645 | csb[n] |= CSB_ERROR | 0x20; /* unknown command */ |
| 617 | | pc_hdc_result(n); |
| 646 | pc_hdc_result(n, 1); |
| 618 | 647 | break; |
| 619 | 648 | } |
| 620 | 649 | if( data_cnt ) |
| r2654 | r2655 | |
| 626 | 655 | if (LOG_HDC_DATA) |
| 627 | 656 | logerror("hdc_data_w BOARD #%d $%02x\n", n, data); |
| 628 | 657 | |
| 629 | | *ptr++ = data; |
| 658 | *buffer_ptr++ = data; |
| 630 | 659 | status[n] |= STA_READY; |
| 631 | 660 | if (--data_cnt == 0) |
| 632 | 661 | { |
| r2654 | r2655 | |
| 654 | 683 | csb[n] = 0; |
| 655 | 684 | status[n] = STA_COMMAND | STA_READY; |
| 656 | 685 | memset(buffer, 0, sizeof(buffer)); |
| 657 | | ptr = buffer; |
| 686 | buffer_ptr = buffer; |
| 658 | 687 | data_cnt = 0; |
| 659 | 688 | } |
| 660 | 689 | |
| r2654 | r2655 | |
| 670 | 699 | |
| 671 | 700 | static void pc_hdc_control_w(int n, int data) |
| 672 | 701 | { |
| 702 | int irq = irq = (dip[n] & 0x40) ? 5 : 2; |
| 703 | |
| 673 | 704 | if (LOG_HDC_STATUS) |
| 674 | 705 | logerror("pc_hdc_control_w(): Control write pc=0x%08x data=%d\n", (unsigned) cpunum_get_reg(0, REG_PC), data); |
| 675 | 706 | |
| 676 | 707 | hdc_control = data; |
| 708 | |
| 709 | if ( ! ( hdc_control & 0x02 ) && hdc_set_irq ) { |
| 710 | hdc_set_irq( irq, 0 ); |
| 711 | } |
| 677 | 712 | } |
| 678 | 713 | |
| 679 | 714 | |
| r2654 | r2655 | |
| 683 | 718 | UINT8 data = 0xff; |
| 684 | 719 | if( data_cnt ) |
| 685 | 720 | { |
| 686 | | data = *ptr++; |
| 721 | data = *buffer_ptr++; |
| 687 | 722 | status[n] &= ~STA_INTERRUPT; |
| 688 | 723 | if( --data_cnt == 0 ) |
| 689 | 724 | { |
| r2654 | r2655 | |
| 706 | 741 | |
| 707 | 742 | |
| 708 | 743 | |
| 744 | /* |
| 745 | Dipswitch configuration |
| 746 | |
| 747 | |
| 748 | Tandon/Western Digital Fixed Disk Controller |
| 749 | bit0-1 : Determine disk size(?) |
| 750 | Causes geometry data to be read from c8043, c8053, c8063, c8073 (?) |
| 751 | 00 - 40 Mbytes |
| 752 | 01 - 30 Mbytes |
| 753 | 10 - 10 Mbytes |
| 754 | 11 - 20 Mbytes |
| 755 | bit2-7 : unknown |
| 756 | |
| 757 | */ |
| 758 | |
| 709 | 759 | static UINT8 pc_hdc_dipswitch_r(int n) |
| 710 | 760 | { |
| 711 | 761 | int data = dip[n]; |
| r2654 | r2655 | |
| 724 | 774 | static UINT8 pc_HDC_r(int chip, offs_t offs) |
| 725 | 775 | { |
| 726 | 776 | UINT8 data = 0xff; |
| 727 | | if( !(input_port_read_indexed(Machine, 3) & (0x08>>chip)) || !pc_hdc_file(chip<<1) ) |
| 728 | | return data; |
| 777 | |
| 729 | 778 | switch( offs ) |
| 730 | 779 | { |
| 731 | 780 | case 0: data = pc_hdc_data_r(chip); break; |
| r2654 | r2655 | |
| 735 | 784 | } |
| 736 | 785 | |
| 737 | 786 | if (LOG_HDC_CALL) |
| 738 | | logerror("pc_HDC_r(): chip=%d offs=%d result=0x%02x\n", chip, offs, data); |
| 787 | logerror("pc_HDC_r(): pc=%06X chip=%d offs=%d result=0x%02x\n", activecpu_get_pc(), chip, offs, data); |
| 739 | 788 | |
| 740 | 789 | return data; |
| 741 | 790 | } |
| r2654 | r2655 | |
| 745 | 794 | static void pc_HDC_w(int chip, offs_t offs, UINT8 data) |
| 746 | 795 | { |
| 747 | 796 | if (LOG_HDC_CALL) |
| 748 | | logerror("pc_HDC_w(): chip=%d offs=%d data=0x%02x\n", chip, offs, data); |
| 797 | logerror("pc_HDC_w(): pc=%06X chip=%d offs=%d data=0x%02x\n", activecpu_get_pc(), chip, offs, data); |
| 749 | 798 | |
| 750 | | if( !(input_port_read_indexed(Machine, 3) & (0x08>>chip)) || !pc_hdc_file(chip<<1) ) |
| 751 | | return; |
| 752 | | |
| 753 | 799 | switch( offs ) |
| 754 | 800 | { |
| 755 | 801 | case 0: pc_hdc_data_w(chip,data); break; |
src/mess/machine/pc.c
| r2654 | r2655 | |
| 57 | 57 | static struct { |
| 58 | 58 | const device_config *pic8259_master; |
| 59 | 59 | const device_config *pic8259_slave; |
| 60 | | const device_config *dma8237_1; |
| 61 | | const device_config *dma8237_2; |
| 60 | const device_config *dma8237; |
| 62 | 61 | } pc_devices; |
| 63 | 62 | |
| 64 | 63 | /************************************************************************* |
| r2654 | r2655 | |
| 783 | 782 | |
| 784 | 783 | static void pc_fdc_dma_drq(int state, int read_) |
| 785 | 784 | { |
| 786 | | dma8237_drq_write( (device_config*)device_list_find_by_tag( Machine->config->devicelist, DMA8237, "dma8237" ), FDC_DMA, state); |
| 785 | dma8237_drq_write( pc_devices.dma8237, FDC_DMA, state); |
| 787 | 786 | } |
| 788 | 787 | |
| 789 | 788 | |
| r2654 | r2655 | |
| 1014 | 1013 | |
| 1015 | 1014 | pc_devices.pic8259_master = device_list_find_by_tag( machine->config->devicelist, PIC8259, "pic8259_master" ); |
| 1016 | 1015 | pc_devices.pic8259_slave = device_list_find_by_tag( machine->config->devicelist, PIC8259, "pic8259_slave" ); |
| 1017 | | pc_devices.dma8237_1 = device_list_find_by_tag( machine->config->devicelist, DMA8237, "dma8237_1" ); |
| 1018 | | pc_devices.dma8237_2 = device_list_find_by_tag( machine->config->devicelist, DMA8237, "dma8237_2" ); |
| 1016 | pc_devices.dma8237 = device_list_find_by_tag( machine->config->devicelist, DMA8237, "dma8237" ); |
| 1019 | 1017 | pc_mouse_set_serial_port( device_list_find_by_tag( machine->config->devicelist, INS8250, "ins8250_0" ) ); |
| 1018 | pc_hdc_set_dma8237_device( pc_devices.dma8237 ); |
| 1020 | 1019 | } |
| 1021 | 1020 | |
| 1022 | 1021 | |
| r2654 | r2655 | |
| 1082 | 1081 | INTERRUPT_GEN( pc_frame_interrupt ) |
| 1083 | 1082 | { |
| 1084 | 1083 | pc_keyboard(); |
| 1084 | |
| 1085 | /* Extermely crappy hack to have let the ibm5150 support 640kb. For testing purposes only. */ |
| 1086 | // if ( mess_ram[0x413] == 0x00 && mess_ram[0x414] == 0x01 ) |
| 1087 | // { |
| 1088 | // mess_ram[0x413] = 640 & 0xff; |
| 1089 | // mess_ram[0x414] = 640 >> 8; |
| 1090 | // } |
| 1091 | |
| 1085 | 1092 | } |
| 1086 | 1093 | |
| 1087 | 1094 | INTERRUPT_GEN( pc_vga_frame_interrupt ) |