src/emu/machine/idectrl.c
| r13992 | r13993 | |
| 91 | 91 | |
| 92 | 92 | #define IDE_ERROR_NONE 0x00 |
| 93 | 93 | #define IDE_ERROR_DEFAULT 0x01 |
| 94 | #define IDE_ERROR_TRACK0_NOT_FOUND 0x02 |
| 94 | 95 | #define IDE_ERROR_UNKNOWN_COMMAND 0x04 |
| 95 | 96 | #define IDE_ERROR_BAD_LOCATION 0x10 |
| 96 | 97 | #define IDE_ERROR_BAD_SECTOR 0x80 |
| r13992 | r13993 | |
| 104 | 105 | /*************************************************************************** |
| 105 | 106 | TYPE DEFINITIONS |
| 106 | 107 | ***************************************************************************/ |
| 108 | typedef struct _ide_device ide_device; |
| 109 | struct _ide_device |
| 110 | { |
| 111 | UINT8 features[IDE_DISK_SECTOR_SIZE]; |
| 107 | 112 | |
| 113 | UINT16 cur_cylinder; |
| 114 | UINT8 cur_sector; |
| 115 | UINT8 cur_head; |
| 116 | UINT8 cur_head_reg; |
| 117 | |
| 118 | UINT32 cur_lba; |
| 119 | |
| 120 | UINT16 num_cylinders; |
| 121 | UINT8 num_sectors; |
| 122 | UINT8 num_heads; |
| 123 | |
| 124 | chd_file *handle; |
| 125 | hard_disk_file *disk; |
| 126 | bool is_image_device; |
| 127 | }; |
| 128 | |
| 129 | |
| 108 | 130 | typedef struct _ide_state ide_state; |
| 109 | 131 | struct _ide_state |
| 110 | 132 | { |
| r13992 | r13993 | |
| 118 | 140 | UINT8 precomp_offset; |
| 119 | 141 | |
| 120 | 142 | UINT8 buffer[IDE_DISK_SECTOR_SIZE]; |
| 121 | | UINT8 features[IDE_DISK_SECTOR_SIZE]; |
| 122 | 143 | UINT16 buffer_offset; |
| 123 | 144 | UINT16 sector_count; |
| 124 | 145 | |
| r13992 | r13993 | |
| 138 | 159 | UINT8 bus_master_status; |
| 139 | 160 | UINT32 bus_master_descriptor; |
| 140 | 161 | |
| 141 | | UINT16 cur_cylinder; |
| 142 | | UINT8 cur_sector; |
| 143 | | UINT8 cur_head; |
| 144 | | UINT8 cur_head_reg; |
| 145 | | |
| 146 | | UINT32 cur_lba; |
| 147 | | |
| 148 | | UINT16 num_cylinders; |
| 149 | | UINT8 num_sectors; |
| 150 | | UINT8 num_heads; |
| 151 | | |
| 152 | 162 | UINT8 config_unknown; |
| 153 | 163 | UINT8 config_register[IDE_CONFIG_REGISTERS]; |
| 154 | 164 | UINT8 config_register_num; |
| 155 | 165 | |
| 156 | | chd_file *handle; |
| 157 | | hard_disk_file *disk; |
| 158 | | bool is_image_device; |
| 159 | 166 | emu_timer * last_status_timer; |
| 160 | 167 | emu_timer * reset_timer; |
| 161 | 168 | |
| r13992 | r13993 | |
| 166 | 173 | |
| 167 | 174 | UINT8 gnetreadlock; |
| 168 | 175 | ide_hardware * hardware; |
| 176 | |
| 177 | UINT8 cur_drive; |
| 178 | ide_device drive[2]; |
| 169 | 179 | }; |
| 170 | 180 | |
| 171 | 181 | |
| r13992 | r13993 | |
| 176 | 186 | |
| 177 | 187 | static TIMER_CALLBACK( reset_callback ); |
| 178 | 188 | |
| 179 | | static void ide_build_features(ide_state *ide); |
| 189 | static void ide_build_features(ide_state *ide, int drive); |
| 180 | 190 | |
| 181 | 191 | static void continue_read(ide_state *ide); |
| 182 | 192 | static void read_sector_done(ide_state *ide); |
| r13992 | r13993 | |
| 275 | 285 | INITIALIZATION AND RESET |
| 276 | 286 | ***************************************************************************/ |
| 277 | 287 | |
| 278 | | UINT8 *ide_get_features(device_t *device) |
| 288 | UINT8 *ide_get_features(device_t *device, int drive) |
| 279 | 289 | { |
| 280 | 290 | ide_state *ide = get_safe_token(device); |
| 281 | | return ide->features; |
| 291 | return ide->drive[drive].features; |
| 282 | 292 | } |
| 283 | 293 | |
| 284 | 294 | void ide_set_gnet_readlock(device_t *device, const UINT8 onoff) |
| r13992 | r13993 | |
| 373 | 383 | INLINE UINT32 lba_address(ide_state *ide) |
| 374 | 384 | { |
| 375 | 385 | /* LBA direct? */ |
| 376 | | if (ide->cur_head_reg & 0x40) |
| 377 | | return ide->cur_sector + ide->cur_cylinder * 256 + ide->cur_head * 16777216; |
| 386 | if (ide->drive[ide->cur_drive].cur_head_reg & 0x40) |
| 387 | return ide->drive[ide->cur_drive].cur_sector + ide->drive[ide->cur_drive].cur_cylinder * 256 + ide->drive[ide->cur_drive].cur_head * 16777216; |
| 378 | 388 | |
| 379 | 389 | /* standard CHS */ |
| 380 | 390 | else |
| 381 | | return (ide->cur_cylinder * ide->num_heads + ide->cur_head) * ide->num_sectors + ide->cur_sector - 1; |
| 391 | return (ide->drive[ide->cur_drive].cur_cylinder * ide->drive[ide->cur_drive].num_heads + ide->drive[ide->cur_drive].cur_head) * ide->drive[ide->cur_drive].num_sectors + ide->drive[ide->cur_drive].cur_sector - 1; |
| 382 | 392 | } |
| 383 | 393 | |
| 384 | 394 | |
| r13992 | r13993 | |
| 392 | 402 | INLINE void next_sector(ide_state *ide) |
| 393 | 403 | { |
| 394 | 404 | /* LBA direct? */ |
| 395 | | if (ide->cur_head_reg & 0x40) |
| 405 | if (ide->drive[ide->cur_drive].cur_head_reg & 0x40) |
| 396 | 406 | { |
| 397 | | ide->cur_sector++; |
| 398 | | if (ide->cur_sector == 0) |
| 407 | ide->drive[ide->cur_drive].cur_sector++; |
| 408 | if (ide->drive[ide->cur_drive].cur_sector == 0) |
| 399 | 409 | { |
| 400 | | ide->cur_cylinder++; |
| 401 | | if (ide->cur_cylinder == 0) |
| 402 | | ide->cur_head++; |
| 410 | ide->drive[ide->cur_drive].cur_cylinder++; |
| 411 | if (ide->drive[ide->cur_drive].cur_cylinder == 0) |
| 412 | ide->drive[ide->cur_drive].cur_head++; |
| 403 | 413 | } |
| 404 | 414 | } |
| 405 | 415 | |
| r13992 | r13993 | |
| 407 | 417 | else |
| 408 | 418 | { |
| 409 | 419 | /* sectors are 1-based */ |
| 410 | | ide->cur_sector++; |
| 411 | | if (ide->cur_sector > ide->num_sectors) |
| 420 | ide->drive[ide->cur_drive].cur_sector++; |
| 421 | if (ide->drive[ide->cur_drive].cur_sector > ide->drive[ide->cur_drive].num_sectors) |
| 412 | 422 | { |
| 413 | 423 | /* heads are 0 based */ |
| 414 | | ide->cur_sector = 1; |
| 415 | | ide->cur_head++; |
| 416 | | if (ide->cur_head >= ide->num_heads) |
| 424 | ide->drive[ide->cur_drive].cur_sector = 1; |
| 425 | ide->drive[ide->cur_drive].cur_head++; |
| 426 | if (ide->drive[ide->cur_drive].cur_head >= ide->drive[ide->cur_drive].num_heads) |
| 417 | 427 | { |
| 418 | | ide->cur_head = 0; |
| 419 | | ide->cur_cylinder++; |
| 428 | ide->drive[ide->cur_drive].cur_head = 0; |
| 429 | ide->drive[ide->cur_drive].cur_cylinder++; |
| 420 | 430 | } |
| 421 | 431 | } |
| 422 | 432 | } |
| 423 | 433 | |
| 424 | | ide->cur_lba = lba_address(ide); |
| 434 | ide->drive[ide->cur_drive].cur_lba = lba_address(ide); |
| 425 | 435 | } |
| 426 | 436 | |
| 427 | 437 | |
| r13992 | r13993 | |
| 445 | 455 | } |
| 446 | 456 | |
| 447 | 457 | |
| 448 | | static void ide_generate_features(ide_state *ide) |
| 458 | static void ide_generate_features(ide_state *ide,int drive) |
| 449 | 459 | { |
| 450 | | int total_sectors = ide->num_cylinders * ide->num_heads * ide->num_sectors; |
| 451 | | int sectors_per_track = ide->num_heads * ide->num_sectors; |
| 460 | int total_sectors = ide->drive[drive].num_cylinders * ide->drive[drive].num_heads * ide->drive[drive].num_sectors; |
| 461 | int sectors_per_track = ide->drive[drive].num_heads * ide->drive[drive].num_sectors; |
| 452 | 462 | |
| 453 | 463 | /* basic geometry */ |
| 454 | | ide->features[ 0*2+0] = 0x5a; /* 0: configuration bits */ |
| 455 | | ide->features[ 0*2+1] = 0x04; |
| 456 | | ide->features[ 1*2+0] = ide->num_cylinders & 0xff; /* 1: logical cylinders */ |
| 457 | | ide->features[ 1*2+1] = ide->num_cylinders >> 8; |
| 458 | | ide->features[ 2*2+0] = 0; /* 2: reserved */ |
| 459 | | ide->features[ 2*2+1] = 0; |
| 460 | | ide->features[ 3*2+0] = ide->num_heads & 0xff; /* 3: logical heads */ |
| 461 | | ide->features[ 3*2+1] = 0;/*ide->num_heads >> 8;*/ |
| 462 | | ide->features[ 4*2+0] = 0; /* 4: vendor specific (obsolete) */ |
| 463 | | ide->features[ 4*2+1] = 0; |
| 464 | | ide->features[ 5*2+0] = 0; /* 5: vendor specific (obsolete) */ |
| 465 | | ide->features[ 5*2+1] = 0; |
| 466 | | ide->features[ 6*2+0] = ide->num_sectors & 0xff; /* 6: logical sectors per logical track */ |
| 467 | | ide->features[ 6*2+1] = 0;/*ide->num_sectors >> 8;*/ |
| 468 | | ide->features[ 7*2+0] = 0; /* 7: vendor-specific */ |
| 469 | | ide->features[ 7*2+1] = 0; |
| 470 | | ide->features[ 8*2+0] = 0; /* 8: vendor-specific */ |
| 471 | | ide->features[ 8*2+1] = 0; |
| 472 | | ide->features[ 9*2+0] = 0; /* 9: vendor-specific */ |
| 473 | | ide->features[ 9*2+1] = 0; |
| 474 | | swap_strncpy(&ide->features[10*2+0], /* 10-19: serial number */ |
| 464 | ide->drive[drive].features[ 0*2+0] = 0x5a; /* 0: configuration bits */ |
| 465 | ide->drive[drive].features[ 0*2+1] = 0x04; |
| 466 | ide->drive[drive].features[ 1*2+0] = ide->drive[drive].num_cylinders & 0xff; /* 1: logical cylinders */ |
| 467 | ide->drive[drive].features[ 1*2+1] = ide->drive[drive].num_cylinders >> 8; |
| 468 | ide->drive[drive].features[ 2*2+0] = 0; /* 2: reserved */ |
| 469 | ide->drive[drive].features[ 2*2+1] = 0; |
| 470 | ide->drive[drive].features[ 3*2+0] = ide->drive[drive].num_heads & 0xff; /* 3: logical heads */ |
| 471 | ide->drive[drive].features[ 3*2+1] = 0;/*ide->num_heads >> 8;*/ |
| 472 | ide->drive[drive].features[ 4*2+0] = 0; /* 4: vendor specific (obsolete) */ |
| 473 | ide->drive[drive].features[ 4*2+1] = 0; |
| 474 | ide->drive[drive].features[ 5*2+0] = 0; /* 5: vendor specific (obsolete) */ |
| 475 | ide->drive[drive].features[ 5*2+1] = 0; |
| 476 | ide->drive[drive].features[ 6*2+0] = ide->drive[drive].num_sectors & 0xff; /* 6: logical sectors per logical track */ |
| 477 | ide->drive[drive].features[ 6*2+1] = 0;/*ide->num_sectors >> 8;*/ |
| 478 | ide->drive[drive].features[ 7*2+0] = 0; /* 7: vendor-specific */ |
| 479 | ide->drive[drive].features[ 7*2+1] = 0; |
| 480 | ide->drive[drive].features[ 8*2+0] = 0; /* 8: vendor-specific */ |
| 481 | ide->drive[drive].features[ 8*2+1] = 0; |
| 482 | ide->drive[drive].features[ 9*2+0] = 0; /* 9: vendor-specific */ |
| 483 | ide->drive[drive].features[ 9*2+1] = 0; |
| 484 | swap_strncpy(&ide->drive[drive].features[10*2+0], /* 10-19: serial number */ |
| 475 | 485 | "00000000000000000000", 10); |
| 476 | | ide->features[20*2+0] = 0; /* 20: vendor-specific */ |
| 477 | | ide->features[20*2+1] = 0; |
| 478 | | ide->features[21*2+0] = 0; /* 21: vendor-specific */ |
| 479 | | ide->features[21*2+1] = 0; |
| 480 | | ide->features[22*2+0] = 4; /* 22: # of vendor-specific bytes on read/write long commands */ |
| 481 | | ide->features[22*2+1] = 0; |
| 482 | | swap_strncpy(&ide->features[23*2+0], /* 23-26: firmware revision */ |
| 486 | ide->drive[drive].features[20*2+0] = 0; /* 20: vendor-specific */ |
| 487 | ide->drive[drive].features[20*2+1] = 0; |
| 488 | ide->drive[drive].features[21*2+0] = 0; /* 21: vendor-specific */ |
| 489 | ide->drive[drive].features[21*2+1] = 0; |
| 490 | ide->drive[drive].features[22*2+0] = 4; /* 22: # of vendor-specific bytes on read/write long commands */ |
| 491 | ide->drive[drive].features[22*2+1] = 0; |
| 492 | swap_strncpy(&ide->drive[drive].features[23*2+0], /* 23-26: firmware revision */ |
| 483 | 493 | "1.0", 4); |
| 484 | | swap_strncpy(&ide->features[27*2+0], /* 27-46: model number */ |
| 494 | swap_strncpy(&ide->drive[drive].features[27*2+0], /* 27-46: model number */ |
| 485 | 495 | "MAME Compressed Hard Disk", 20); |
| 486 | | ide->features[47*2+0] = 0x01; /* 47: read/write multiple support */ |
| 487 | | ide->features[47*2+1] = 0x80; |
| 488 | | ide->features[48*2+0] = 0; /* 48: reserved */ |
| 489 | | ide->features[48*2+1] = 0; |
| 490 | | ide->features[49*2+0] = 0x03; /* 49: capabilities */ |
| 491 | | ide->features[49*2+1] = 0x0f; |
| 492 | | ide->features[50*2+0] = 0; /* 50: reserved */ |
| 493 | | ide->features[50*2+1] = 0; |
| 494 | | ide->features[51*2+0] = 2; /* 51: PIO data transfer cycle timing mode */ |
| 495 | | ide->features[51*2+1] = 0; |
| 496 | | ide->features[52*2+0] = 2; /* 52: single word DMA transfer cycle timing mode */ |
| 497 | | ide->features[52*2+1] = 0; |
| 498 | | ide->features[53*2+0] = 3; /* 53: field validity */ |
| 499 | | ide->features[53*2+1] = 0; |
| 500 | | ide->features[54*2+0] = ide->num_cylinders & 0xff; /* 54: number of current logical cylinders */ |
| 501 | | ide->features[54*2+1] = ide->num_cylinders >> 8; |
| 502 | | ide->features[55*2+0] = ide->num_heads & 0xff; /* 55: number of current logical heads */ |
| 503 | | ide->features[55*2+1] = 0;/*ide->num_heads >> 8;*/ |
| 504 | | ide->features[56*2+0] = ide->num_sectors & 0xff; /* 56: number of current logical sectors per track */ |
| 505 | | ide->features[56*2+1] = 0;/*ide->num_sectors >> 8;*/ |
| 506 | | ide->features[57*2+0] = sectors_per_track & 0xff; /* 57-58: number of current logical sectors per track */ |
| 507 | | ide->features[57*2+1] = sectors_per_track >> 8; |
| 508 | | ide->features[58*2+0] = sectors_per_track >> 16; |
| 509 | | ide->features[58*2+1] = sectors_per_track >> 24; |
| 510 | | ide->features[59*2+0] = 0; /* 59: multiple sector timing */ |
| 511 | | ide->features[59*2+1] = 0; |
| 512 | | ide->features[60*2+0] = total_sectors & 0xff; /* 60-61: total user addressable sectors */ |
| 513 | | ide->features[60*2+1] = total_sectors >> 8; |
| 514 | | ide->features[61*2+0] = total_sectors >> 16; |
| 515 | | ide->features[61*2+1] = total_sectors >> 24; |
| 516 | | ide->features[62*2+0] = 0x07; /* 62: single word dma transfer */ |
| 517 | | ide->features[62*2+1] = 0x00; |
| 518 | | ide->features[63*2+0] = 0x07; /* 63: multiword DMA transfer */ |
| 519 | | ide->features[63*2+1] = 0x04; |
| 520 | | ide->features[64*2+0] = 0x03; /* 64: flow control PIO transfer modes supported */ |
| 521 | | ide->features[64*2+1] = 0x00; |
| 522 | | ide->features[65*2+0] = 0x78; /* 65: minimum multiword DMA transfer cycle time per word */ |
| 523 | | ide->features[65*2+1] = 0x00; |
| 524 | | ide->features[66*2+0] = 0x78; /* 66: mfr's recommended multiword DMA transfer cycle time */ |
| 525 | | ide->features[66*2+1] = 0x00; |
| 526 | | ide->features[67*2+0] = 0x4d; /* 67: minimum PIO transfer cycle time without flow control */ |
| 527 | | ide->features[67*2+1] = 0x01; |
| 528 | | ide->features[68*2+0] = 0x78; /* 68: minimum PIO transfer cycle time with IORDY */ |
| 529 | | ide->features[68*2+1] = 0x00; |
| 530 | | ide->features[69*2+0] = 0x00; /* 69-70: reserved */ |
| 531 | | ide->features[69*2+1] = 0x00; |
| 532 | | ide->features[71*2+0] = 0x00; /* 71: reserved for IDENTIFY PACKET command */ |
| 533 | | ide->features[71*2+1] = 0x00; |
| 534 | | ide->features[72*2+0] = 0x00; /* 72: reserved for IDENTIFY PACKET command */ |
| 535 | | ide->features[72*2+1] = 0x00; |
| 536 | | ide->features[73*2+0] = 0x00; /* 73: reserved for IDENTIFY PACKET command */ |
| 537 | | ide->features[73*2+1] = 0x00; |
| 538 | | ide->features[74*2+0] = 0x00; /* 74: reserved for IDENTIFY PACKET command */ |
| 539 | | ide->features[74*2+1] = 0x00; |
| 540 | | ide->features[75*2+0] = 0x00; /* 75: queue depth */ |
| 541 | | ide->features[75*2+1] = 0x00; |
| 542 | | ide->features[76*2+0] = 0x00; /* 76-79: reserved */ |
| 543 | | ide->features[76*2+1] = 0x00; |
| 544 | | ide->features[80*2+0] = 0x00; /* 80: major version number */ |
| 545 | | ide->features[80*2+1] = 0x00; |
| 546 | | ide->features[81*2+0] = 0x00; /* 81: minor version number */ |
| 547 | | ide->features[81*2+1] = 0x00; |
| 548 | | ide->features[82*2+0] = 0x00; /* 82: command set supported */ |
| 549 | | ide->features[82*2+1] = 0x00; |
| 550 | | ide->features[83*2+0] = 0x00; /* 83: command sets supported */ |
| 551 | | ide->features[83*2+1] = 0x00; |
| 552 | | ide->features[84*2+0] = 0x00; /* 84: command set/feature supported extension */ |
| 553 | | ide->features[84*2+1] = 0x00; |
| 554 | | ide->features[85*2+0] = 0x00; /* 85: command set/feature enabled */ |
| 555 | | ide->features[85*2+1] = 0x00; |
| 556 | | ide->features[86*2+0] = 0x00; /* 86: command set/feature enabled */ |
| 557 | | ide->features[86*2+1] = 0x00; |
| 558 | | ide->features[87*2+0] = 0x00; /* 87: command set/feature default */ |
| 559 | | ide->features[87*2+1] = 0x00; |
| 560 | | ide->features[88*2+0] = 0x00; /* 88: additional DMA modes */ |
| 561 | | ide->features[88*2+1] = 0x00; |
| 562 | | ide->features[89*2+0] = 0x00; /* 89: time required for security erase unit completion */ |
| 563 | | ide->features[89*2+1] = 0x00; |
| 564 | | ide->features[90*2+0] = 0x00; /* 90: time required for enhanced security erase unit completion */ |
| 565 | | ide->features[90*2+1] = 0x00; |
| 566 | | ide->features[91*2+0] = 0x00; /* 91: current advanced power management value */ |
| 567 | | ide->features[91*2+1] = 0x00; |
| 568 | | ide->features[92*2+0] = 0x00; /* 92: master password revision code */ |
| 569 | | ide->features[92*2+1] = 0x00; |
| 570 | | ide->features[93*2+0] = 0x00; /* 93: hardware reset result */ |
| 571 | | ide->features[93*2+1] = 0x00; |
| 572 | | ide->features[94*2+0] = 0x00; /* 94: acoustic management values */ |
| 573 | | ide->features[94*2+1] = 0x00; |
| 574 | | ide->features[95*2+0] = 0x00; /* 95-99: reserved */ |
| 575 | | ide->features[95*2+1] = 0x00; |
| 576 | | ide->features[100*2+0] = total_sectors & 0xff; /* 100-103: maximum 48-bit LBA */ |
| 577 | | ide->features[100*2+1] = total_sectors >> 8; |
| 578 | | ide->features[101*2+0] = total_sectors >> 16; |
| 579 | | ide->features[101*2+1] = total_sectors >> 24; |
| 580 | | ide->features[102*2+0] = 0x00; |
| 581 | | ide->features[102*2+1] = 0x00; |
| 582 | | ide->features[103*2+0] = 0x00; |
| 583 | | ide->features[103*2+1] = 0x00; |
| 584 | | ide->features[104*2+0] = 0x00; /* 104-126: reserved */ |
| 585 | | ide->features[104*2+1] = 0x00; |
| 586 | | ide->features[127*2+0] = 0x00; /* 127: removable media status notification */ |
| 587 | | ide->features[127*2+1] = 0x00; |
| 588 | | ide->features[128*2+0] = 0x00; /* 128: security status */ |
| 589 | | ide->features[128*2+1] = 0x00; |
| 590 | | ide->features[129*2+0] = 0x00; /* 129-159: vendor specific */ |
| 591 | | ide->features[129*2+1] = 0x00; |
| 592 | | ide->features[160*2+0] = 0x00; /* 160: CFA power mode 1 */ |
| 593 | | ide->features[160*2+1] = 0x00; |
| 594 | | ide->features[161*2+0] = 0x00; /* 161-175: reserved for CompactFlash */ |
| 595 | | ide->features[161*2+1] = 0x00; |
| 596 | | ide->features[176*2+0] = 0x00; /* 176-205: current media serial number */ |
| 597 | | ide->features[176*2+1] = 0x00; |
| 598 | | ide->features[206*2+0] = 0x00; /* 206-254: reserved */ |
| 599 | | ide->features[206*2+1] = 0x00; |
| 600 | | ide->features[255*2+0] = 0x00; /* 255: integrity word */ |
| 601 | | ide->features[255*2+1] = 0x00; |
| 496 | ide->drive[drive].features[47*2+0] = 0x01; /* 47: read/write multiple support */ |
| 497 | ide->drive[drive].features[47*2+1] = 0x80; |
| 498 | ide->drive[drive].features[48*2+0] = 0; /* 48: reserved */ |
| 499 | ide->drive[drive].features[48*2+1] = 0; |
| 500 | ide->drive[drive].features[49*2+0] = 0x03; /* 49: capabilities */ |
| 501 | ide->drive[drive].features[49*2+1] = 0x0f; |
| 502 | ide->drive[drive].features[50*2+0] = 0; /* 50: reserved */ |
| 503 | ide->drive[drive].features[50*2+1] = 0; |
| 504 | ide->drive[drive].features[51*2+0] = 2; /* 51: PIO data transfer cycle timing mode */ |
| 505 | ide->drive[drive].features[51*2+1] = 0; |
| 506 | ide->drive[drive].features[52*2+0] = 2; /* 52: single word DMA transfer cycle timing mode */ |
| 507 | ide->drive[drive].features[52*2+1] = 0; |
| 508 | ide->drive[drive].features[53*2+0] = 3; /* 53: field validity */ |
| 509 | ide->drive[drive].features[53*2+1] = 0; |
| 510 | ide->drive[drive].features[54*2+0] = ide->drive[drive].num_cylinders & 0xff; /* 54: number of current logical cylinders */ |
| 511 | ide->drive[drive].features[54*2+1] = ide->drive[drive].num_cylinders >> 8; |
| 512 | ide->drive[drive].features[55*2+0] = ide->drive[drive].num_heads & 0xff; /* 55: number of current logical heads */ |
| 513 | ide->drive[drive].features[55*2+1] = 0;/*ide->num_heads >> 8;*/ |
| 514 | ide->drive[drive].features[56*2+0] = ide->drive[drive].num_sectors & 0xff; /* 56: number of current logical sectors per track */ |
| 515 | ide->drive[drive].features[56*2+1] = 0;/*ide->num_sectors >> 8;*/ |
| 516 | ide->drive[drive].features[57*2+0] = sectors_per_track & 0xff; /* 57-58: number of current logical sectors per track */ |
| 517 | ide->drive[drive].features[57*2+1] = sectors_per_track >> 8; |
| 518 | ide->drive[drive].features[58*2+0] = sectors_per_track >> 16; |
| 519 | ide->drive[drive].features[58*2+1] = sectors_per_track >> 24; |
| 520 | ide->drive[drive].features[59*2+0] = 0; /* 59: multiple sector timing */ |
| 521 | ide->drive[drive].features[59*2+1] = 0; |
| 522 | ide->drive[drive].features[60*2+0] = total_sectors & 0xff; /* 60-61: total user addressable sectors */ |
| 523 | ide->drive[drive].features[60*2+1] = total_sectors >> 8; |
| 524 | ide->drive[drive].features[61*2+0] = total_sectors >> 16; |
| 525 | ide->drive[drive].features[61*2+1] = total_sectors >> 24; |
| 526 | ide->drive[drive].features[62*2+0] = 0x07; /* 62: single word dma transfer */ |
| 527 | ide->drive[drive].features[62*2+1] = 0x00; |
| 528 | ide->drive[drive].features[63*2+0] = 0x07; /* 63: multiword DMA transfer */ |
| 529 | ide->drive[drive].features[63*2+1] = 0x04; |
| 530 | ide->drive[drive].features[64*2+0] = 0x03; /* 64: flow control PIO transfer modes supported */ |
| 531 | ide->drive[drive].features[64*2+1] = 0x00; |
| 532 | ide->drive[drive].features[65*2+0] = 0x78; /* 65: minimum multiword DMA transfer cycle time per word */ |
| 533 | ide->drive[drive].features[65*2+1] = 0x00; |
| 534 | ide->drive[drive].features[66*2+0] = 0x78; /* 66: mfr's recommended multiword DMA transfer cycle time */ |
| 535 | ide->drive[drive].features[66*2+1] = 0x00; |
| 536 | ide->drive[drive].features[67*2+0] = 0x4d; /* 67: minimum PIO transfer cycle time without flow control */ |
| 537 | ide->drive[drive].features[67*2+1] = 0x01; |
| 538 | ide->drive[drive].features[68*2+0] = 0x78; /* 68: minimum PIO transfer cycle time with IORDY */ |
| 539 | ide->drive[drive].features[68*2+1] = 0x00; |
| 540 | ide->drive[drive].features[69*2+0] = 0x00; /* 69-70: reserved */ |
| 541 | ide->drive[drive].features[69*2+1] = 0x00; |
| 542 | ide->drive[drive].features[71*2+0] = 0x00; /* 71: reserved for IDENTIFY PACKET command */ |
| 543 | ide->drive[drive].features[71*2+1] = 0x00; |
| 544 | ide->drive[drive].features[72*2+0] = 0x00; /* 72: reserved for IDENTIFY PACKET command */ |
| 545 | ide->drive[drive].features[72*2+1] = 0x00; |
| 546 | ide->drive[drive].features[73*2+0] = 0x00; /* 73: reserved for IDENTIFY PACKET command */ |
| 547 | ide->drive[drive].features[73*2+1] = 0x00; |
| 548 | ide->drive[drive].features[74*2+0] = 0x00; /* 74: reserved for IDENTIFY PACKET command */ |
| 549 | ide->drive[drive].features[74*2+1] = 0x00; |
| 550 | ide->drive[drive].features[75*2+0] = 0x00; /* 75: queue depth */ |
| 551 | ide->drive[drive].features[75*2+1] = 0x00; |
| 552 | ide->drive[drive].features[76*2+0] = 0x00; /* 76-79: reserved */ |
| 553 | ide->drive[drive].features[76*2+1] = 0x00; |
| 554 | ide->drive[drive].features[80*2+0] = 0x00; /* 80: major version number */ |
| 555 | ide->drive[drive].features[80*2+1] = 0x00; |
| 556 | ide->drive[drive].features[81*2+0] = 0x00; /* 81: minor version number */ |
| 557 | ide->drive[drive].features[81*2+1] = 0x00; |
| 558 | ide->drive[drive].features[82*2+0] = 0x00; /* 82: command set supported */ |
| 559 | ide->drive[drive].features[82*2+1] = 0x00; |
| 560 | ide->drive[drive].features[83*2+0] = 0x00; /* 83: command sets supported */ |
| 561 | ide->drive[drive].features[83*2+1] = 0x00; |
| 562 | ide->drive[drive].features[84*2+0] = 0x00; /* 84: command set/feature supported extension */ |
| 563 | ide->drive[drive].features[84*2+1] = 0x00; |
| 564 | ide->drive[drive].features[85*2+0] = 0x00; /* 85: command set/feature enabled */ |
| 565 | ide->drive[drive].features[85*2+1] = 0x00; |
| 566 | ide->drive[drive].features[86*2+0] = 0x00; /* 86: command set/feature enabled */ |
| 567 | ide->drive[drive].features[86*2+1] = 0x00; |
| 568 | ide->drive[drive].features[87*2+0] = 0x00; /* 87: command set/feature default */ |
| 569 | ide->drive[drive].features[87*2+1] = 0x00; |
| 570 | ide->drive[drive].features[88*2+0] = 0x00; /* 88: additional DMA modes */ |
| 571 | ide->drive[drive].features[88*2+1] = 0x00; |
| 572 | ide->drive[drive].features[89*2+0] = 0x00; /* 89: time required for security erase unit completion */ |
| 573 | ide->drive[drive].features[89*2+1] = 0x00; |
| 574 | ide->drive[drive].features[90*2+0] = 0x00; /* 90: time required for enhanced security erase unit completion */ |
| 575 | ide->drive[drive].features[90*2+1] = 0x00; |
| 576 | ide->drive[drive].features[91*2+0] = 0x00; /* 91: current advanced power management value */ |
| 577 | ide->drive[drive].features[91*2+1] = 0x00; |
| 578 | ide->drive[drive].features[92*2+0] = 0x00; /* 92: master password revision code */ |
| 579 | ide->drive[drive].features[92*2+1] = 0x00; |
| 580 | ide->drive[drive].features[93*2+0] = 0x00; /* 93: hardware reset result */ |
| 581 | ide->drive[drive].features[93*2+1] = 0x00; |
| 582 | ide->drive[drive].features[94*2+0] = 0x00; /* 94: acoustic management values */ |
| 583 | ide->drive[drive].features[94*2+1] = 0x00; |
| 584 | ide->drive[drive].features[95*2+0] = 0x00; /* 95-99: reserved */ |
| 585 | ide->drive[drive].features[95*2+1] = 0x00; |
| 586 | ide->drive[drive].features[100*2+0] = total_sectors & 0xff; /* 100-103: maximum 48-bit LBA */ |
| 587 | ide->drive[drive].features[100*2+1] = total_sectors >> 8; |
| 588 | ide->drive[drive].features[101*2+0] = total_sectors >> 16; |
| 589 | ide->drive[drive].features[101*2+1] = total_sectors >> 24; |
| 590 | ide->drive[drive].features[102*2+0] = 0x00; |
| 591 | ide->drive[drive].features[102*2+1] = 0x00; |
| 592 | ide->drive[drive].features[103*2+0] = 0x00; |
| 593 | ide->drive[drive].features[103*2+1] = 0x00; |
| 594 | ide->drive[drive].features[104*2+0] = 0x00; /* 104-126: reserved */ |
| 595 | ide->drive[drive].features[104*2+1] = 0x00; |
| 596 | ide->drive[drive].features[127*2+0] = 0x00; /* 127: removable media status notification */ |
| 597 | ide->drive[drive].features[127*2+1] = 0x00; |
| 598 | ide->drive[drive].features[128*2+0] = 0x00; /* 128: security status */ |
| 599 | ide->drive[drive].features[128*2+1] = 0x00; |
| 600 | ide->drive[drive].features[129*2+0] = 0x00; /* 129-159: vendor specific */ |
| 601 | ide->drive[drive].features[129*2+1] = 0x00; |
| 602 | ide->drive[drive].features[160*2+0] = 0x00; /* 160: CFA power mode 1 */ |
| 603 | ide->drive[drive].features[160*2+1] = 0x00; |
| 604 | ide->drive[drive].features[161*2+0] = 0x00; /* 161-175: reserved for CompactFlash */ |
| 605 | ide->drive[drive].features[161*2+1] = 0x00; |
| 606 | ide->drive[drive].features[176*2+0] = 0x00; /* 176-205: current media serial number */ |
| 607 | ide->drive[drive].features[176*2+1] = 0x00; |
| 608 | ide->drive[drive].features[206*2+0] = 0x00; /* 206-254: reserved */ |
| 609 | ide->drive[drive].features[206*2+1] = 0x00; |
| 610 | ide->drive[drive].features[255*2+0] = 0x00; /* 255: integrity word */ |
| 611 | ide->drive[drive].features[255*2+1] = 0x00; |
| 602 | 612 | } |
| 603 | 613 | |
| 604 | 614 | |
| 605 | | static void ide_build_features(ide_state *ide) |
| 615 | static void ide_build_features(ide_state *ide, int drive) |
| 606 | 616 | { |
| 607 | | memset(ide->features, 0, IDE_DISK_SECTOR_SIZE); |
| 608 | | if (chd_get_metadata (ide->handle, HARD_DISK_IDENT_METADATA_TAG, 0, ide->features, IDE_DISK_SECTOR_SIZE, 0, 0, 0) != CHDERR_NONE) |
| 609 | | ide_generate_features (ide); |
| 617 | memset(ide->drive[drive].features, 0, IDE_DISK_SECTOR_SIZE); |
| 618 | if (chd_get_metadata (ide->drive[drive].handle, HARD_DISK_IDENT_METADATA_TAG, 0, ide->drive[drive].features, IDE_DISK_SECTOR_SIZE, 0, 0, 0) != CHDERR_NONE) |
| 619 | ide_generate_features (ide,drive); |
| 610 | 620 | } |
| 611 | 621 | |
| 612 | 622 | /************************************* |
| r13992 | r13993 | |
| 733 | 743 | return; |
| 734 | 744 | } |
| 735 | 745 | /* now do the read */ |
| 736 | | if (ide->disk) |
| 737 | | count = hard_disk_read(ide->disk, lba, ide->buffer); |
| 746 | if (ide->drive[ide->cur_drive].disk) |
| 747 | count = hard_disk_read(ide->drive[ide->cur_drive].disk, lba, ide->buffer); |
| 738 | 748 | else if (ide->hardware != NULL) { |
| 739 | 749 | count = ide->hardware->read_sector(ide->device, lba, ide->buffer); |
| 740 | 750 | } |
| r13992 | r13993 | |
| 809 | 819 | int new_lba = lba_address(ide); |
| 810 | 820 | attotime seek_time; |
| 811 | 821 | |
| 812 | | if (new_lba == ide->cur_lba || new_lba == ide->cur_lba + 1) |
| 822 | if (new_lba == ide->drive[ide->cur_drive].cur_lba || new_lba == ide->drive[ide->cur_drive].cur_lba + 1) |
| 813 | 823 | seek_time = TIME_NO_SEEK_MULTISECTOR; |
| 814 | 824 | else |
| 815 | 825 | seek_time = TIME_SEEK_MULTISECTOR; |
| 816 | 826 | |
| 817 | | ide->cur_lba = new_lba; |
| 827 | ide->drive[ide->cur_drive].cur_lba = new_lba; |
| 818 | 828 | ide->device->machine().scheduler().timer_set(seek_time, FUNC(read_sector_done_callback), 0, ide); |
| 819 | 829 | } |
| 820 | 830 | else |
| r13992 | r13993 | |
| 934 | 944 | int lba = lba_address(ide), count = 0; |
| 935 | 945 | |
| 936 | 946 | /* now do the write */ |
| 937 | | if (ide->disk) |
| 938 | | count = hard_disk_write(ide->disk, lba, ide->buffer); |
| 947 | if (ide->drive[ide->cur_drive].disk) |
| 948 | count = hard_disk_write(ide->drive[ide->cur_drive].disk, lba, ide->buffer); |
| 939 | 949 | else if (ide->hardware != NULL) { |
| 940 | 950 | count = ide->hardware->write_sector(ide->device, lba, ide->buffer); |
| 941 | 951 | } |
| r13992 | r13993 | |
| 1016 | 1026 | |
| 1017 | 1027 | /* implicitly clear interrupts here */ |
| 1018 | 1028 | clear_interrupt(ide); |
| 1019 | | |
| 1020 | 1029 | ide->command = command; |
| 1021 | 1030 | switch (command) |
| 1022 | 1031 | { |
| 1023 | 1032 | case IDE_COMMAND_READ_MULTIPLE: |
| 1024 | 1033 | case IDE_COMMAND_READ_MULTIPLE_ONCE: |
| 1025 | 1034 | LOGPRINT(("IDE Read multiple: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1026 | | ide->cur_cylinder, ide->cur_head, ide->cur_sector, lba_address(ide), ide->sector_count)); |
| 1035 | ide->drive[ide->cur_drive].cur_cylinder, ide->drive[ide->cur_drive].cur_head, ide->drive[ide->cur_drive].cur_sector, lba_address(ide), ide->sector_count)); |
| 1027 | 1036 | |
| 1028 | 1037 | /* reset the buffer */ |
| 1029 | 1038 | ide->buffer_offset = 0; |
| r13992 | r13993 | |
| 1037 | 1046 | |
| 1038 | 1047 | case IDE_COMMAND_READ_MULTIPLE_BLOCK: |
| 1039 | 1048 | LOGPRINT(("IDE Read multiple block: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1040 | | ide->cur_cylinder, ide->cur_head, ide->cur_sector, lba_address(ide), ide->sector_count)); |
| 1049 | ide->drive[ide->cur_drive].cur_cylinder, ide->drive[ide->cur_drive].cur_head, ide->drive[ide->cur_drive].cur_sector, lba_address(ide), ide->sector_count)); |
| 1041 | 1050 | |
| 1042 | 1051 | /* reset the buffer */ |
| 1043 | 1052 | ide->buffer_offset = 0; |
| r13992 | r13993 | |
| 1052 | 1061 | case IDE_COMMAND_VERIFY_MULTIPLE: |
| 1053 | 1062 | case IDE_COMMAND_VERIFY_NORETRY: |
| 1054 | 1063 | LOGPRINT(("IDE Read verify multiple with/without retries: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1055 | | ide->cur_cylinder, ide->cur_head, ide->cur_sector, lba_address(ide), ide->sector_count)); |
| 1064 | ide->drive[ide->cur_drive].cur_cylinder, ide->drive[ide->cur_drive].cur_head, ide->drive[ide->cur_drive].cur_sector, lba_address(ide), ide->sector_count)); |
| 1056 | 1065 | |
| 1057 | 1066 | /* reset the buffer */ |
| 1058 | 1067 | ide->buffer_offset = 0; |
| r13992 | r13993 | |
| 1066 | 1075 | |
| 1067 | 1076 | case IDE_COMMAND_READ_DMA: |
| 1068 | 1077 | LOGPRINT(("IDE Read multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1069 | | ide->cur_cylinder, ide->cur_head, ide->cur_sector, lba_address(ide), ide->sector_count)); |
| 1078 | ide->drive[ide->cur_drive].cur_cylinder, ide->drive[ide->cur_drive].cur_head, ide->drive[ide->cur_drive].cur_sector, lba_address(ide), ide->sector_count)); |
| 1070 | 1079 | |
| 1071 | 1080 | /* reset the buffer */ |
| 1072 | 1081 | ide->buffer_offset = 0; |
| r13992 | r13993 | |
| 1081 | 1090 | |
| 1082 | 1091 | case IDE_COMMAND_WRITE_MULTIPLE: |
| 1083 | 1092 | LOGPRINT(("IDE Write multiple: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1084 | | ide->cur_cylinder, ide->cur_head, ide->cur_sector, lba_address(ide), ide->sector_count)); |
| 1093 | ide->drive[ide->cur_drive].cur_cylinder, ide->drive[ide->cur_drive].cur_head, ide->drive[ide->cur_drive].cur_sector, lba_address(ide), ide->sector_count)); |
| 1085 | 1094 | |
| 1086 | 1095 | /* reset the buffer */ |
| 1087 | 1096 | ide->buffer_offset = 0; |
| r13992 | r13993 | |
| 1094 | 1103 | |
| 1095 | 1104 | case IDE_COMMAND_WRITE_MULTIPLE_BLOCK: |
| 1096 | 1105 | LOGPRINT(("IDE Write multiple block: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1097 | | ide->cur_cylinder, ide->cur_head, ide->cur_sector, lba_address(ide), ide->sector_count)); |
| 1106 | ide->drive[ide->cur_drive].cur_cylinder, ide->drive[ide->cur_drive].cur_head, ide->drive[ide->cur_drive].cur_sector, lba_address(ide), ide->sector_count)); |
| 1098 | 1107 | |
| 1099 | 1108 | /* reset the buffer */ |
| 1100 | 1109 | ide->buffer_offset = 0; |
| r13992 | r13993 | |
| 1107 | 1116 | |
| 1108 | 1117 | case IDE_COMMAND_WRITE_DMA: |
| 1109 | 1118 | LOGPRINT(("IDE Write multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1110 | | ide->cur_cylinder, ide->cur_head, ide->cur_sector, lba_address(ide), ide->sector_count)); |
| 1119 | ide->drive[ide->cur_drive].cur_cylinder, ide->drive[ide->cur_drive].cur_head, ide->drive[ide->cur_drive].cur_sector, lba_address(ide), ide->sector_count)); |
| 1111 | 1120 | |
| 1112 | 1121 | /* reset the buffer */ |
| 1113 | 1122 | ide->buffer_offset = 0; |
| r13992 | r13993 | |
| 1143 | 1152 | ide->sector_count = 1; |
| 1144 | 1153 | |
| 1145 | 1154 | /* build the features page */ |
| 1146 | | memcpy(ide->buffer, ide->features, sizeof(ide->buffer)); |
| 1155 | memcpy(ide->buffer, ide->drive[ide->cur_drive].features, sizeof(ide->buffer)); |
| 1147 | 1156 | |
| 1148 | 1157 | /* indicate everything is ready */ |
| 1149 | 1158 | ide->status |= IDE_STATUS_BUFFER_READY; |
| r13992 | r13993 | |
| 1171 | 1180 | case IDE_COMMAND_RECALIBRATE: |
| 1172 | 1181 | /* clear the error too */ |
| 1173 | 1182 | ide->error = IDE_ERROR_NONE; |
| 1174 | | |
| 1175 | 1183 | /* signal an interrupt */ |
| 1176 | 1184 | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0); |
| 1177 | 1185 | break; |
| r13992 | r13993 | |
| 1187 | 1195 | break; |
| 1188 | 1196 | |
| 1189 | 1197 | case IDE_COMMAND_SET_CONFIG: |
| 1190 | | LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", ide->cur_head + 1, ide->sector_count)); |
| 1198 | LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", ide->drive[ide->cur_drive].cur_head + 1, ide->sector_count)); |
| 1191 | 1199 | ide->status &= ~IDE_STATUS_ERROR; |
| 1192 | 1200 | ide->error = IDE_ERROR_NONE; |
| 1193 | 1201 | |
| 1194 | | ide->num_sectors = ide->sector_count; |
| 1195 | | ide->num_heads = ide->cur_head + 1; |
| 1202 | ide->drive[ide->cur_drive].num_sectors = ide->sector_count; |
| 1203 | ide->drive[ide->cur_drive].num_heads = ide->drive[ide->cur_drive].cur_head + 1; |
| 1196 | 1204 | |
| 1197 | 1205 | /* signal an interrupt */ |
| 1198 | 1206 | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0); |
| r13992 | r13993 | |
| 1207 | 1215 | break; |
| 1208 | 1216 | |
| 1209 | 1217 | case IDE_COMMAND_SET_FEATURES: |
| 1210 | | LOGPRINT(("IDE Set features (%02X %02X %02X %02X %02X)\n", ide->precomp_offset, ide->sector_count & 0xff, ide->cur_sector, ide->cur_cylinder & 0xff, ide->cur_cylinder >> 8)); |
| 1218 | LOGPRINT(("IDE Set features (%02X %02X %02X %02X %02X)\n", ide->precomp_offset, ide->sector_count & 0xff, ide->drive[ide->cur_drive].cur_sector, ide->drive[ide->cur_drive].cur_cylinder & 0xff, ide->drive[ide->cur_drive].cur_cylinder >> 8)); |
| 1211 | 1219 | |
| 1212 | 1220 | /* signal an interrupt */ |
| 1213 | 1221 | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0); |
| r13992 | r13993 | |
| 1250 | 1258 | LOGPRINT(("IDE GNET Unlock 3\n")); |
| 1251 | 1259 | |
| 1252 | 1260 | /* key check */ |
| 1253 | | chd_get_metadata (ide->handle, HARD_DISK_KEY_METADATA_TAG, 0, key, 5, 0, 0, 0); |
| 1254 | | if ((ide->precomp_offset == key[0]) && (ide->sector_count == key[1]) && (ide->cur_sector == key[2]) && (ide->cur_cylinder == (((UINT16)key[4]<<8)|key[3]))) |
| 1261 | chd_get_metadata (ide->drive[ide->cur_drive].handle, HARD_DISK_KEY_METADATA_TAG, 0, key, 5, 0, 0, 0); |
| 1262 | if ((ide->precomp_offset == key[0]) && (ide->sector_count == key[1]) && (ide->drive[ide->cur_drive].cur_sector == key[2]) && (ide->drive[ide->cur_drive].cur_cylinder == (((UINT16)key[4]<<8)|key[3]))) |
| 1255 | 1263 | { |
| 1256 | 1264 | ide->gnetreadlock= 0; |
| 1257 | 1265 | } |
| r13992 | r13993 | |
| 1305 | 1313 | // if (BANK(bank, offset) != IDE_BANK0_DATA && BANK(bank, offset) != IDE_BANK0_STATUS_COMMAND && BANK(bank, offset) != IDE_BANK1_STATUS_CONTROL) |
| 1306 | 1314 | LOG(("%s:IDE read at %d:%X, size=%d\n", device->machine().describe_context(), bank, offset, size)); |
| 1307 | 1315 | |
| 1316 | if (ide->drive[ide->cur_drive].disk) { |
| 1317 | ide->status |= IDE_STATUS_DRIVE_READY; |
| 1318 | } else { |
| 1319 | ide->status &= ~IDE_STATUS_DRIVE_READY; |
| 1320 | } |
| 1321 | |
| 1308 | 1322 | switch (BANK(bank, offset)) |
| 1309 | 1323 | { |
| 1310 | 1324 | /* unknown config register */ |
| r13992 | r13993 | |
| 1355 | 1369 | |
| 1356 | 1370 | /* return the current sector */ |
| 1357 | 1371 | case IDE_BANK0_SECTOR_NUMBER: |
| 1358 | | return ide->cur_sector; |
| 1372 | return ide->drive[ide->cur_drive].cur_sector; |
| 1359 | 1373 | |
| 1360 | 1374 | /* return the current cylinder LSB */ |
| 1361 | 1375 | case IDE_BANK0_CYLINDER_LSB: |
| 1362 | | return ide->cur_cylinder & 0xff; |
| 1376 | return ide->drive[ide->cur_drive].cur_cylinder & 0xff; |
| 1363 | 1377 | |
| 1364 | 1378 | /* return the current cylinder MSB */ |
| 1365 | 1379 | case IDE_BANK0_CYLINDER_MSB: |
| 1366 | | return ide->cur_cylinder >> 8; |
| 1380 | return ide->drive[ide->cur_drive].cur_cylinder >> 8; |
| 1367 | 1381 | |
| 1368 | 1382 | /* return the current head */ |
| 1369 | 1383 | case IDE_BANK0_HEAD_NUMBER: |
| 1370 | | return ide->cur_head_reg; |
| 1384 | return ide->drive[ide->cur_drive].cur_head_reg; |
| 1371 | 1385 | |
| 1372 | 1386 | /* return the current status and clear any pending interrupts */ |
| 1373 | 1387 | case IDE_BANK0_STATUS_COMMAND: |
| r13992 | r13993 | |
| 1491 | 1505 | { |
| 1492 | 1506 | UINT8 key[5] = { 0, 0, 0, 0, 0 }; |
| 1493 | 1507 | int i, bad = 0; |
| 1494 | | chd_get_metadata (ide->handle, HARD_DISK_KEY_METADATA_TAG, 0, key, 5, 0, 0, 0); |
| 1508 | chd_get_metadata (ide->drive[ide->cur_drive].handle, HARD_DISK_KEY_METADATA_TAG, 0, key, 5, 0, 0, 0); |
| 1495 | 1509 | |
| 1496 | 1510 | for (i=0; !bad && i<512; i++) |
| 1497 | 1511 | bad = ((i < 2 || i >= 7) && ide->buffer[i]) || ((i >= 2 && i < 7) && ide->buffer[i] != key[i-2]); |
| r13992 | r13993 | |
| 1524 | 1538 | |
| 1525 | 1539 | /* current sector */ |
| 1526 | 1540 | case IDE_BANK0_SECTOR_NUMBER: |
| 1527 | | ide->cur_sector = data; |
| 1541 | ide->drive[ide->cur_drive].cur_sector = data; |
| 1528 | 1542 | break; |
| 1529 | 1543 | |
| 1530 | 1544 | /* current cylinder LSB */ |
| 1531 | 1545 | case IDE_BANK0_CYLINDER_LSB: |
| 1532 | | ide->cur_cylinder = (ide->cur_cylinder & 0xff00) | (data & 0xff); |
| 1546 | ide->drive[ide->cur_drive].cur_cylinder = (ide->drive[ide->cur_drive].cur_cylinder & 0xff00) | (data & 0xff); |
| 1533 | 1547 | break; |
| 1534 | 1548 | |
| 1535 | 1549 | /* current cylinder MSB */ |
| 1536 | 1550 | case IDE_BANK0_CYLINDER_MSB: |
| 1537 | | ide->cur_cylinder = (ide->cur_cylinder & 0x00ff) | ((data & 0xff) << 8); |
| 1551 | ide->drive[ide->cur_drive].cur_cylinder = (ide->drive[ide->cur_drive].cur_cylinder & 0x00ff) | ((data & 0xff) << 8); |
| 1538 | 1552 | break; |
| 1539 | 1553 | |
| 1540 | 1554 | /* current head */ |
| 1541 | 1555 | case IDE_BANK0_HEAD_NUMBER: |
| 1542 | | ide->cur_head = data & 0x0f; |
| 1543 | | ide->cur_head_reg = data; |
| 1544 | | // drive index = data & 0x10 |
| 1556 | ide->cur_drive = (data & 0x10) >> 4; |
| 1557 | ide->drive[ide->cur_drive].cur_head = data & 0x0f; |
| 1558 | ide->drive[ide->cur_drive].cur_head_reg = data; |
| 1545 | 1559 | // LBA mode = data & 0x40 |
| 1546 | 1560 | break; |
| 1547 | 1561 | |
| r13992 | r13993 | |
| 1858 | 1872 | |
| 1859 | 1873 | /* set MAME harddisk handle */ |
| 1860 | 1874 | config = (const ide_config *)downcast<const legacy_device_base *>(device)->inline_config(); |
| 1861 | | ide->handle = get_disk_handle(device->machine(), (config->master != NULL) ? config->master : device->tag()); |
| 1862 | | ide->disk = hard_disk_open(ide->handle); |
| 1863 | | ide->is_image_device = false; |
| 1875 | |
| 1876 | ide->drive[0].handle = get_disk_handle(device->machine(), (config->master != NULL) ? config->master : device->tag()); |
| 1877 | ide->drive[0].disk = hard_disk_open(ide->drive[0].handle); |
| 1878 | ide->drive[0].is_image_device = false; |
| 1879 | |
| 1880 | if (config->slave) { |
| 1881 | ide->drive[1].handle = get_disk_handle(device->machine(), config->slave); |
| 1882 | ide->drive[1].disk = hard_disk_open(ide->drive[1].handle); |
| 1883 | ide->drive[1].is_image_device = false; |
| 1884 | } |
| 1885 | |
| 1864 | 1886 | //assert_always(config->slave == NULL, "IDE controller does not yet support slave drives\n"); |
| 1865 | 1887 | |
| 1866 | 1888 | /* find the bus master space */ |
| r13992 | r13993 | |
| 1879 | 1901 | } |
| 1880 | 1902 | |
| 1881 | 1903 | /* get and copy the geometry */ |
| 1882 | | if (ide->disk != NULL) |
| 1904 | if (ide->drive[0].disk != NULL) |
| 1883 | 1905 | { |
| 1884 | | hdinfo = hard_disk_get_info(ide->disk); |
| 1906 | hdinfo = hard_disk_get_info(ide->drive[0].disk); |
| 1885 | 1907 | if (hdinfo->sectorbytes == IDE_DISK_SECTOR_SIZE) |
| 1886 | 1908 | { |
| 1887 | | ide->num_cylinders = hdinfo->cylinders; |
| 1888 | | ide->num_sectors = hdinfo->sectors; |
| 1889 | | ide->num_heads = hdinfo->heads; |
| 1890 | | if (PRINTF_IDE_COMMANDS) mame_printf_debug("CHS: %d %d %d\n", ide->num_cylinders, ide->num_heads, ide->num_sectors); |
| 1909 | ide->drive[0].num_cylinders = hdinfo->cylinders; |
| 1910 | ide->drive[0].num_sectors = hdinfo->sectors; |
| 1911 | ide->drive[0].num_heads = hdinfo->heads; |
| 1912 | if (PRINTF_IDE_COMMANDS) mame_printf_debug("CHS: %d %d %d\n", ide->drive[0].num_cylinders, ide->drive[0].num_heads, ide->drive[0].num_sectors); |
| 1891 | 1913 | } |
| 1892 | 1914 | |
| 1893 | 1915 | /* build the features page */ |
| 1894 | | ide_build_features(ide); |
| 1895 | | } else if (config->hardware != NULL) { |
| 1916 | ide_build_features(ide,0); |
| 1917 | } |
| 1918 | if (ide->drive[1].disk != NULL) |
| 1919 | { |
| 1920 | hdinfo = hard_disk_get_info(ide->drive[1].disk); |
| 1921 | if (hdinfo->sectorbytes == IDE_DISK_SECTOR_SIZE) |
| 1922 | { |
| 1923 | ide->drive[1].num_cylinders = hdinfo->cylinders; |
| 1924 | ide->drive[1].num_sectors = hdinfo->sectors; |
| 1925 | ide->drive[1].num_heads = hdinfo->heads; |
| 1926 | if (PRINTF_IDE_COMMANDS) mame_printf_debug("CHS: %d %d %d\n", ide->drive[1].num_cylinders, ide->drive[1].num_heads, ide->drive[1].num_sectors); |
| 1927 | } |
| 1928 | |
| 1929 | /* build the features page */ |
| 1930 | ide_build_features(ide,1); |
| 1931 | } |
| 1932 | if (config->hardware != NULL) { |
| 1896 | 1933 | ide->hardware = (ide_hardware *)config->hardware; |
| 1897 | | ide->hardware->get_info(ide->device, ide->features, ide->num_cylinders, ide->num_sectors, ide->num_heads); |
| 1898 | | ide_generate_features (ide); |
| 1934 | ide->hardware->get_info(ide->device, ide->drive[0].features, ide->drive[0].num_cylinders, ide->drive[0].num_sectors, ide->drive[0].num_heads); |
| 1935 | ide_generate_features (ide,0); |
| 1899 | 1936 | } |
| 1900 | 1937 | |
| 1901 | 1938 | /* create a timer for timing status */ |
| r13992 | r13993 | |
| 1911 | 1948 | device->save_item(NAME(ide->precomp_offset)); |
| 1912 | 1949 | |
| 1913 | 1950 | device->save_item(NAME(ide->buffer)); |
| 1914 | | device->save_item(NAME(ide->features)); |
| 1951 | //device->save_item(NAME(ide->features)); |
| 1915 | 1952 | device->save_item(NAME(ide->buffer_offset)); |
| 1916 | 1953 | device->save_item(NAME(ide->sector_count)); |
| 1917 | 1954 | |
| r13992 | r13993 | |
| 1928 | 1965 | device->save_item(NAME(ide->bus_master_status)); |
| 1929 | 1966 | device->save_item(NAME(ide->bus_master_descriptor)); |
| 1930 | 1967 | |
| 1931 | | device->save_item(NAME(ide->cur_cylinder)); |
| 1932 | | device->save_item(NAME(ide->cur_sector)); |
| 1933 | | device->save_item(NAME(ide->cur_head)); |
| 1934 | | device->save_item(NAME(ide->cur_head_reg)); |
| 1968 | //device->save_item(NAME(ide->cur_cylinder)); |
| 1969 | //device->save_item(NAME(ide->cur_sector)); |
| 1970 | //device->save_item(NAME(ide->cur_head)); |
| 1971 | //device->save_item(NAME(ide->cur_head_reg)); |
| 1935 | 1972 | |
| 1936 | | device->save_item(NAME(ide->cur_lba)); |
| 1973 | //device->save_item(NAME(ide->cur_lba)); |
| 1937 | 1974 | |
| 1938 | | device->save_item(NAME(ide->num_cylinders)); |
| 1939 | | device->save_item(NAME(ide->num_sectors)); |
| 1940 | | device->save_item(NAME(ide->num_heads)); |
| 1975 | //device->save_item(NAME(ide->num_cylinders)); |
| 1976 | //device->save_item(NAME(ide->num_sectors)); |
| 1977 | //device->save_item(NAME(ide->num_heads)); |
| 1941 | 1978 | |
| 1942 | 1979 | device->save_item(NAME(ide->config_unknown)); |
| 1943 | 1980 | device->save_item(NAME(ide->config_register)); |
| r13992 | r13993 | |
| 1957 | 1994 | static DEVICE_STOP( ide_controller ) |
| 1958 | 1995 | { |
| 1959 | 1996 | ide_state *ide = get_safe_token(device); |
| 1960 | | if (!ide->is_image_device) { |
| 1997 | if (!ide->drive[0].is_image_device) { |
| 1961 | 1998 | /* close the hard disk */ |
| 1962 | | if (ide->disk != NULL) |
| 1963 | | hard_disk_close(ide->disk); |
| 1999 | if (ide->drive[0].disk != NULL) |
| 2000 | hard_disk_close(ide->drive[0].disk); |
| 1964 | 2001 | } |
| 2002 | if (!ide->drive[1].is_image_device) { |
| 2003 | /* close the hard disk */ |
| 2004 | if (ide->drive[1].disk != NULL) |
| 2005 | hard_disk_close(ide->drive[1].disk); |
| 2006 | } |
| 1965 | 2007 | } |
| 1966 | 2008 | |
| 1967 | 2009 | |
| r13992 | r13993 | |
| 1974 | 2016 | ide_state *ide = get_safe_token(device); |
| 1975 | 2017 | const ide_config *config = (const ide_config *)downcast<const legacy_device_base *>(device)->inline_config(); |
| 1976 | 2018 | |
| 2019 | ide->cur_drive = 0; |
| 1977 | 2020 | LOG(("IDE controller reset performed\n")); |
| 1978 | | astring hardtag; |
| 2021 | astring hardtag_master; |
| 2022 | astring hardtag_slave; |
| 1979 | 2023 | if (config->master) { |
| 1980 | | device->siblingtag(hardtag, config->master); |
| 2024 | device->siblingtag(hardtag_master, config->master); |
| 1981 | 2025 | } |
| 2026 | if (config->slave) { |
| 2027 | device->siblingtag(hardtag_slave, config->slave); |
| 2028 | } |
| 1982 | 2029 | |
| 1983 | | if (device->machine().device( hardtag.cstr() )) { |
| 1984 | | if (!ide->disk) |
| 2030 | if (device->machine().device( hardtag_master.cstr() )) { |
| 2031 | if (!ide->drive[0].disk) |
| 1985 | 2032 | { |
| 1986 | | ide->handle = device->machine().device<harddisk_image_device>(hardtag.cstr())->get_chd_file(); // should be config->master |
| 2033 | ide->drive[0].handle = device->machine().device<harddisk_image_device>(hardtag_master.cstr())->get_chd_file(); // should be config->master |
| 1987 | 2034 | |
| 1988 | | if (ide->handle) |
| 2035 | if (ide->drive[0].handle) |
| 1989 | 2036 | { |
| 1990 | | ide->disk = device->machine().device<harddisk_image_device>(hardtag.cstr())->get_hard_disk_file(); // should be config->master |
| 1991 | | ide->is_image_device = true; |
| 2037 | ide->drive[0].disk = device->machine().device<harddisk_image_device>(hardtag_master.cstr())->get_hard_disk_file(); // should be config->master |
| 2038 | ide->drive[0].is_image_device = true; |
| 1992 | 2039 | |
| 1993 | | if (ide->disk != NULL) |
| 2040 | if (ide->drive[0].disk != NULL) |
| 1994 | 2041 | { |
| 1995 | 2042 | const hard_disk_info *hdinfo; |
| 1996 | 2043 | |
| 1997 | | hdinfo = hard_disk_get_info(ide->disk); |
| 2044 | hdinfo = hard_disk_get_info(ide->drive[0].disk); |
| 1998 | 2045 | if (hdinfo->sectorbytes == IDE_DISK_SECTOR_SIZE) |
| 1999 | 2046 | { |
| 2000 | | ide->num_cylinders = hdinfo->cylinders; |
| 2001 | | ide->num_sectors = hdinfo->sectors; |
| 2002 | | ide->num_heads = hdinfo->heads; |
| 2003 | | if (PRINTF_IDE_COMMANDS) printf("CHS: %d %d %d\n", ide->num_cylinders, ide->num_heads, ide->num_sectors); |
| 2047 | ide->drive[0].num_cylinders = hdinfo->cylinders; |
| 2048 | ide->drive[0].num_sectors = hdinfo->sectors; |
| 2049 | ide->drive[0].num_heads = hdinfo->heads; |
| 2050 | if (PRINTF_IDE_COMMANDS) printf("CHS: %d %d %d\n", ide->drive[0].num_cylinders, ide->drive[0].num_heads, ide->drive[0].num_sectors); |
| 2004 | 2051 | } |
| 2005 | 2052 | |
| 2006 | 2053 | /* build the features page */ |
| 2007 | | ide_build_features(ide); |
| 2054 | ide_build_features(ide,0); |
| 2008 | 2055 | } |
| 2009 | 2056 | } |
| 2010 | 2057 | } |
| 2011 | | } else if (ide->hardware != NULL) { |
| 2012 | | ide->hardware->get_info(ide->device, ide->features, ide->num_cylinders, ide->num_sectors, ide->num_heads); |
| 2013 | | ide_generate_features (ide); |
| 2058 | } |
| 2059 | if (device->machine().device( hardtag_slave.cstr() )) { |
| 2060 | if (!ide->drive[1].disk) |
| 2061 | { |
| 2062 | ide->drive[1].handle = device->machine().device<harddisk_image_device>(hardtag_slave.cstr())->get_chd_file(); // should be config->master |
| 2063 | |
| 2064 | if (ide->drive[1].handle) |
| 2065 | { |
| 2066 | ide->drive[1].disk = device->machine().device<harddisk_image_device>(hardtag_slave.cstr())->get_hard_disk_file(); // should be config->master |
| 2067 | ide->drive[1].is_image_device = true; |
| 2068 | |
| 2069 | if (ide->drive[1].disk != NULL) |
| 2070 | { |
| 2071 | const hard_disk_info *hdinfo; |
| 2072 | |
| 2073 | hdinfo = hard_disk_get_info(ide->drive[1].disk); |
| 2074 | if (hdinfo->sectorbytes == IDE_DISK_SECTOR_SIZE) |
| 2075 | { |
| 2076 | ide->drive[1].num_cylinders = hdinfo->cylinders; |
| 2077 | ide->drive[1].num_sectors = hdinfo->sectors; |
| 2078 | ide->drive[1].num_heads = hdinfo->heads; |
| 2079 | if (PRINTF_IDE_COMMANDS) printf("CHS: %d %d %d\n", ide->drive[1].num_cylinders, ide->drive[1].num_heads, ide->drive[1].num_sectors); |
| 2080 | } |
| 2081 | |
| 2082 | /* build the features page */ |
| 2083 | ide_build_features(ide,1); |
| 2084 | } |
| 2085 | } |
| 2086 | } |
| 2087 | } |
| 2088 | if (ide->hardware != NULL) { |
| 2089 | ide->hardware->get_info(ide->device, ide->drive[0].features, ide->drive[0].num_cylinders, ide->drive[0].num_sectors, ide->drive[0].num_heads); |
| 2090 | ide_generate_features (ide,0); |
| 2014 | 2091 | } |
| 2015 | 2092 | |
| 2016 | 2093 | /* reset the drive state */ |