trunk/src/emu/machine/idectrl.c
| r18713 | r18714 | |
| 42 | 42 | #define IDE_STATUS_DRIVE_READY 0x40 |
| 43 | 43 | #define IDE_STATUS_BUSY 0x80 |
| 44 | 44 | |
| 45 | | #define IDE_CONFIG_REGISTERS 0x10 |
| 46 | | |
| 47 | 45 | #define BANK(b, v) (((v) << 4) | (b)) |
| 48 | 46 | |
| 49 | 47 | #define IDE_BANK0_DATA BANK(0, 0) |
| r18713 | r18714 | |
| 99 | 97 | #define IDE_BUSMASTER_STATUS_IRQ 0x04 |
| 100 | 98 | |
| 101 | 99 | |
| 102 | | |
| 103 | | /*************************************************************************** |
| 104 | | TYPE DEFINITIONS |
| 105 | | ***************************************************************************/ |
| 106 | | struct ide_device |
| 100 | void ide_controller_device::signal_interrupt() |
| 107 | 101 | { |
| 108 | | UINT16 cur_cylinder; |
| 109 | | UINT8 cur_sector; |
| 110 | | UINT8 cur_head; |
| 111 | | UINT8 cur_head_reg; |
| 112 | | UINT32 cur_lba; |
| 113 | | ide_slot_device *slot; |
| 114 | | }; |
| 115 | | |
| 116 | | |
| 117 | | struct ide_state |
| 118 | | { |
| 119 | | device_t *device; |
| 120 | | |
| 121 | | UINT8 adapter_control; |
| 122 | | UINT8 status; |
| 123 | | UINT8 error; |
| 124 | | UINT8 command; |
| 125 | | UINT8 interrupt_pending; |
| 126 | | UINT8 precomp_offset; |
| 127 | | |
| 128 | | UINT8 buffer[IDE_DISK_SECTOR_SIZE]; |
| 129 | | UINT16 buffer_offset; |
| 130 | | UINT16 sector_count; |
| 131 | | |
| 132 | | UINT16 block_count; |
| 133 | | UINT16 sectors_until_int; |
| 134 | | UINT8 verify_only; |
| 135 | | |
| 136 | | UINT8 dma_active; |
| 137 | | address_space *dma_space; |
| 138 | | UINT8 dma_address_xor; |
| 139 | | UINT8 dma_last_buffer; |
| 140 | | offs_t dma_address; |
| 141 | | offs_t dma_descriptor; |
| 142 | | UINT32 dma_bytes_left; |
| 143 | | |
| 144 | | UINT8 bus_master_command; |
| 145 | | UINT8 bus_master_status; |
| 146 | | UINT32 bus_master_descriptor; |
| 147 | | |
| 148 | | UINT8 config_unknown; |
| 149 | | UINT8 config_register[IDE_CONFIG_REGISTERS]; |
| 150 | | UINT8 config_register_num; |
| 151 | | |
| 152 | | emu_timer * last_status_timer; |
| 153 | | emu_timer * reset_timer; |
| 154 | | |
| 155 | | UINT8 master_password_enable; |
| 156 | | UINT8 user_password_enable; |
| 157 | | const UINT8 * master_password; |
| 158 | | const UINT8 * user_password; |
| 159 | | |
| 160 | | UINT8 gnetreadlock; |
| 161 | | |
| 162 | | UINT8 cur_drive; |
| 163 | | ide_device drive[2]; |
| 164 | | }; |
| 165 | | |
| 166 | | |
| 167 | | |
| 168 | | /*************************************************************************** |
| 169 | | FUNCTION PROTOTYPES |
| 170 | | ***************************************************************************/ |
| 171 | | |
| 172 | | static TIMER_CALLBACK( reset_callback ); |
| 173 | | |
| 174 | | static void continue_read(ide_state *ide); |
| 175 | | static void read_sector_done(ide_state *ide); |
| 176 | | static TIMER_CALLBACK( read_sector_done_callback ); |
| 177 | | static void read_first_sector(ide_state *ide); |
| 178 | | static void read_next_sector(ide_state *ide); |
| 179 | | |
| 180 | | static UINT32 ide_controller_read(device_t *device, int bank, offs_t offset, int size); |
| 181 | | static void ide_controller_write(device_t *device, int bank, offs_t offset, int size, UINT32 data); |
| 182 | | |
| 183 | | |
| 184 | | |
| 185 | | /*************************************************************************** |
| 186 | | INLINE FUNCTIONS |
| 187 | | ***************************************************************************/ |
| 188 | | |
| 189 | | /*------------------------------------------------- |
| 190 | | get_safe_token - makes sure that the passed |
| 191 | | in device is, in fact, an IDE controller |
| 192 | | -------------------------------------------------*/ |
| 193 | | |
| 194 | | INLINE ide_state *get_safe_token(device_t *device) |
| 195 | | { |
| 196 | | assert(device != NULL); |
| 197 | | assert(device->type() == IDE_CONTROLLER); |
| 198 | | |
| 199 | | return (ide_state *)downcast<ide_controller_device *>(device)->token(); |
| 200 | | } |
| 201 | | |
| 202 | | |
| 203 | | INLINE void signal_interrupt(ide_state *ide) |
| 204 | | { |
| 205 | | const ide_config *config = (const ide_config *)ide->device->static_config(); |
| 206 | | |
| 207 | 102 | LOG(("IDE interrupt assert\n")); |
| 208 | 103 | |
| 209 | 104 | /* signal an interrupt */ |
| 210 | | if (config->interrupt != NULL) |
| 211 | | (*config->interrupt)(ide->device, ASSERT_LINE); |
| 212 | | ide->interrupt_pending = 1; |
| 213 | | ide->bus_master_status |= IDE_BUSMASTER_STATUS_IRQ; |
| 105 | m_irq_handler(ASSERT_LINE); |
| 106 | interrupt_pending = 1; |
| 107 | bus_master_status |= IDE_BUSMASTER_STATUS_IRQ; |
| 214 | 108 | } |
| 215 | 109 | |
| 216 | 110 | |
| 217 | | INLINE void clear_interrupt(ide_state *ide) |
| 111 | void ide_controller_device::clear_interrupt() |
| 218 | 112 | { |
| 219 | | const ide_config *config = (const ide_config *)ide->device->static_config(); |
| 220 | | |
| 221 | 113 | LOG(("IDE interrupt clear\n")); |
| 222 | 114 | |
| 223 | 115 | /* clear an interrupt */ |
| 224 | | if (config->interrupt != NULL) |
| 225 | | (*config->interrupt)(ide->device, CLEAR_LINE); |
| 226 | | ide->interrupt_pending = 0; |
| 116 | m_irq_handler(CLEAR_LINE); |
| 117 | interrupt_pending = 0; |
| 227 | 118 | } |
| 228 | 119 | |
| 229 | 120 | |
| r18713 | r18714 | |
| 234 | 125 | |
| 235 | 126 | static TIMER_CALLBACK( delayed_interrupt ) |
| 236 | 127 | { |
| 237 | | ide_state *ide = (ide_state *)ptr; |
| 128 | ide_controller_device *ide = (ide_controller_device *)ptr; |
| 238 | 129 | ide->status &= ~IDE_STATUS_BUSY; |
| 239 | | signal_interrupt(ide); |
| 130 | ide->signal_interrupt(); |
| 240 | 131 | } |
| 241 | 132 | |
| 242 | 133 | |
| 243 | 134 | static TIMER_CALLBACK( delayed_interrupt_buffer_ready ) |
| 244 | 135 | { |
| 245 | | ide_state *ide = (ide_state *)ptr; |
| 136 | ide_controller_device *ide = (ide_controller_device *)ptr; |
| 246 | 137 | ide->status &= ~IDE_STATUS_BUSY; |
| 247 | 138 | ide->status |= IDE_STATUS_BUFFER_READY; |
| 248 | | signal_interrupt(ide); |
| 139 | ide->signal_interrupt(); |
| 249 | 140 | } |
| 250 | 141 | |
| 251 | 142 | |
| 252 | | INLINE void signal_delayed_interrupt(ide_state *ide, attotime time, int buffer_ready) |
| 143 | void ide_controller_device::signal_delayed_interrupt(attotime time, int buffer_ready) |
| 253 | 144 | { |
| 254 | 145 | /* clear buffer ready and set the busy flag */ |
| 255 | | ide->status &= ~IDE_STATUS_BUFFER_READY; |
| 256 | | ide->status |= IDE_STATUS_BUSY; |
| 146 | status &= ~IDE_STATUS_BUFFER_READY; |
| 147 | status |= IDE_STATUS_BUSY; |
| 257 | 148 | |
| 258 | 149 | /* set a timer */ |
| 259 | 150 | if (buffer_ready) |
| 260 | | ide->device->machine().scheduler().timer_set(time, FUNC(delayed_interrupt_buffer_ready), 0, ide); |
| 151 | machine().scheduler().timer_set(time, FUNC(delayed_interrupt_buffer_ready), 0, this); |
| 261 | 152 | else |
| 262 | | ide->device->machine().scheduler().timer_set(time, FUNC(delayed_interrupt), 0, ide); |
| 153 | machine().scheduler().timer_set(time, FUNC(delayed_interrupt), 0, this); |
| 263 | 154 | } |
| 264 | 155 | |
| 265 | 156 | |
| r18713 | r18714 | |
| 268 | 159 | INITIALIZATION AND RESET |
| 269 | 160 | ***************************************************************************/ |
| 270 | 161 | |
| 271 | | UINT8 *ide_get_features(device_t *device, int drive) |
| 162 | UINT8 *ide_controller_device::ide_get_features(int _drive) |
| 272 | 163 | { |
| 273 | | ide_state *ide = get_safe_token(device); |
| 274 | | return ide->drive[drive].slot->get_features(); |
| 164 | return drive[_drive].slot->get_features(); |
| 275 | 165 | } |
| 276 | 166 | |
| 277 | | void ide_set_gnet_readlock(device_t *device, const UINT8 onoff) |
| 167 | void ide_controller_device::ide_set_gnet_readlock(const UINT8 onoff) |
| 278 | 168 | { |
| 279 | | ide_state *ide = get_safe_token(device); |
| 280 | | ide->gnetreadlock = onoff; |
| 169 | gnetreadlock = onoff; |
| 281 | 170 | } |
| 282 | 171 | |
| 283 | | void ide_set_master_password(device_t *device, const UINT8 *password) |
| 172 | void ide_controller_device::ide_set_master_password(const UINT8 *password) |
| 284 | 173 | { |
| 285 | | ide_state *ide = get_safe_token(device); |
| 286 | | |
| 287 | | ide->master_password = password; |
| 288 | | ide->master_password_enable = (ide->master_password != NULL); |
| 174 | master_password = password; |
| 175 | master_password_enable = (master_password != NULL); |
| 289 | 176 | } |
| 290 | 177 | |
| 291 | 178 | |
| 292 | | void ide_set_user_password(device_t *device, const UINT8 *password) |
| 179 | void ide_controller_device::ide_set_user_password(const UINT8 *password) |
| 293 | 180 | { |
| 294 | | ide_state *ide = get_safe_token(device); |
| 295 | | |
| 296 | | ide->user_password = password; |
| 297 | | ide->user_password_enable = (ide->user_password != NULL); |
| 181 | user_password = password; |
| 182 | user_password_enable = (user_password != NULL); |
| 298 | 183 | } |
| 299 | 184 | |
| 300 | 185 | |
| r18713 | r18714 | |
| 363 | 248 | * |
| 364 | 249 | *************************************/ |
| 365 | 250 | |
| 366 | | INLINE UINT32 lba_address(ide_state *ide) |
| 251 | UINT32 ide_controller_device::lba_address() |
| 367 | 252 | { |
| 368 | 253 | /* LBA direct? */ |
| 369 | | if (ide->drive[ide->cur_drive].cur_head_reg & 0x40) |
| 370 | | return ide->drive[ide->cur_drive].cur_sector + ide->drive[ide->cur_drive].cur_cylinder * 256 + ide->drive[ide->cur_drive].cur_head * 16777216; |
| 254 | if (drive[cur_drive].cur_head_reg & 0x40) |
| 255 | return drive[cur_drive].cur_sector + drive[cur_drive].cur_cylinder * 256 + drive[cur_drive].cur_head * 16777216; |
| 371 | 256 | |
| 372 | 257 | /* standard CHS */ |
| 373 | 258 | else |
| 374 | | return (ide->drive[ide->cur_drive].cur_cylinder * ide->drive[ide->cur_drive].slot->get_heads() + ide->drive[ide->cur_drive].cur_head) * ide->drive[ide->cur_drive].slot->get_sectors() + ide->drive[ide->cur_drive].cur_sector - 1; |
| 259 | return (drive[cur_drive].cur_cylinder * drive[cur_drive].slot->get_heads() + drive[cur_drive].cur_head) * drive[cur_drive].slot->get_sectors() + drive[cur_drive].cur_sector - 1; |
| 375 | 260 | } |
| 376 | 261 | |
| 377 | 262 | |
| r18713 | r18714 | |
| 382 | 267 | * |
| 383 | 268 | *************************************/ |
| 384 | 269 | |
| 385 | | INLINE void next_sector(ide_state *ide) |
| 270 | void ide_controller_device::next_sector() |
| 386 | 271 | { |
| 387 | 272 | /* LBA direct? */ |
| 388 | | if (ide->drive[ide->cur_drive].cur_head_reg & 0x40) |
| 273 | if (drive[cur_drive].cur_head_reg & 0x40) |
| 389 | 274 | { |
| 390 | | ide->drive[ide->cur_drive].cur_sector++; |
| 391 | | if (ide->drive[ide->cur_drive].cur_sector == 0) |
| 275 | drive[cur_drive].cur_sector++; |
| 276 | if (drive[cur_drive].cur_sector == 0) |
| 392 | 277 | { |
| 393 | | ide->drive[ide->cur_drive].cur_cylinder++; |
| 394 | | if (ide->drive[ide->cur_drive].cur_cylinder == 0) |
| 395 | | ide->drive[ide->cur_drive].cur_head++; |
| 278 | drive[cur_drive].cur_cylinder++; |
| 279 | if (drive[cur_drive].cur_cylinder == 0) |
| 280 | drive[cur_drive].cur_head++; |
| 396 | 281 | } |
| 397 | 282 | } |
| 398 | 283 | |
| r18713 | r18714 | |
| 400 | 285 | else |
| 401 | 286 | { |
| 402 | 287 | /* sectors are 1-based */ |
| 403 | | ide->drive[ide->cur_drive].cur_sector++; |
| 404 | | if (ide->drive[ide->cur_drive].cur_sector > ide->drive[ide->cur_drive].slot->get_sectors()) |
| 288 | drive[cur_drive].cur_sector++; |
| 289 | if (drive[cur_drive].cur_sector > drive[cur_drive].slot->get_sectors()) |
| 405 | 290 | { |
| 406 | 291 | /* heads are 0 based */ |
| 407 | | ide->drive[ide->cur_drive].cur_sector = 1; |
| 408 | | ide->drive[ide->cur_drive].cur_head++; |
| 409 | | if (ide->drive[ide->cur_drive].cur_head >= ide->drive[ide->cur_drive].slot->get_heads()) |
| 292 | drive[cur_drive].cur_sector = 1; |
| 293 | drive[cur_drive].cur_head++; |
| 294 | if (drive[cur_drive].cur_head >= drive[cur_drive].slot->get_heads()) |
| 410 | 295 | { |
| 411 | | ide->drive[ide->cur_drive].cur_head = 0; |
| 412 | | ide->drive[ide->cur_drive].cur_cylinder++; |
| 296 | drive[cur_drive].cur_head = 0; |
| 297 | drive[cur_drive].cur_cylinder++; |
| 413 | 298 | } |
| 414 | 299 | } |
| 415 | 300 | } |
| 416 | 301 | |
| 417 | | ide->drive[ide->cur_drive].cur_lba = lba_address(ide); |
| 302 | drive[cur_drive].cur_lba = lba_address(); |
| 418 | 303 | } |
| 419 | 304 | |
| 420 | 305 | |
| r18713 | r18714 | |
| 452 | 337 | m_features[ 2*2+0] = 0; /* 2: reserved */ |
| 453 | 338 | m_features[ 2*2+1] = 0; |
| 454 | 339 | m_features[ 3*2+0] = m_num_heads & 0xff; /* 3: logical heads */ |
| 455 | | m_features[ 3*2+1] = 0;/*ide->num_heads >> 8;*/ |
| 340 | m_features[ 3*2+1] = 0;/*num_heads >> 8;*/ |
| 456 | 341 | m_features[ 4*2+0] = 0; /* 4: vendor specific (obsolete) */ |
| 457 | 342 | m_features[ 4*2+1] = 0; |
| 458 | 343 | m_features[ 5*2+0] = 0; /* 5: vendor specific (obsolete) */ |
| 459 | 344 | m_features[ 5*2+1] = 0; |
| 460 | 345 | m_features[ 6*2+0] = m_num_sectors & 0xff; /* 6: logical sectors per logical track */ |
| 461 | | m_features[ 6*2+1] = 0;/*ide->num_sectors >> 8;*/ |
| 346 | m_features[ 6*2+1] = 0;/*num_sectors >> 8;*/ |
| 462 | 347 | m_features[ 7*2+0] = 0; /* 7: vendor-specific */ |
| 463 | 348 | m_features[ 7*2+1] = 0; |
| 464 | 349 | m_features[ 8*2+0] = 0; /* 8: vendor-specific */ |
| r18713 | r18714 | |
| 494 | 379 | m_features[54*2+0] = m_num_cylinders & 0xff; /* 54: number of current logical cylinders */ |
| 495 | 380 | m_features[54*2+1] = m_num_cylinders >> 8; |
| 496 | 381 | m_features[55*2+0] = m_num_heads & 0xff; /* 55: number of current logical heads */ |
| 497 | | m_features[55*2+1] = 0;/*ide->num_heads >> 8;*/ |
| 382 | m_features[55*2+1] = 0;/*num_heads >> 8;*/ |
| 498 | 383 | m_features[56*2+0] = m_num_sectors & 0xff; /* 56: number of current logical sectors per track */ |
| 499 | | m_features[56*2+1] = 0;/*ide->num_sectors >> 8;*/ |
| 384 | m_features[56*2+1] = 0;/*num_sectors >> 8;*/ |
| 500 | 385 | m_features[57*2+0] = sectors_per_track & 0xff; /* 57-58: number of current logical sectors per track */ |
| 501 | 386 | m_features[57*2+1] = sectors_per_track >> 8; |
| 502 | 387 | m_features[58*2+0] = sectors_per_track >> 16; |
| r18713 | r18714 | |
| 603 | 488 | |
| 604 | 489 | static TIMER_CALLBACK( security_error_done ) |
| 605 | 490 | { |
| 606 | | ide_state *ide = (ide_state *)ptr; |
| 491 | ide_controller_device *ide = (ide_controller_device *)ptr; |
| 607 | 492 | |
| 608 | 493 | /* clear error state */ |
| 609 | 494 | ide->status &= ~IDE_STATUS_ERROR; |
| 610 | 495 | ide->status |= IDE_STATUS_DRIVE_READY; |
| 611 | 496 | } |
| 612 | 497 | |
| 613 | | static void security_error(ide_state *ide) |
| 498 | void ide_controller_device::security_error() |
| 614 | 499 | { |
| 615 | 500 | /* set error state */ |
| 616 | | ide->status |= IDE_STATUS_ERROR; |
| 617 | | ide->status &= ~IDE_STATUS_DRIVE_READY; |
| 501 | status |= IDE_STATUS_ERROR; |
| 502 | status &= ~IDE_STATUS_DRIVE_READY; |
| 618 | 503 | |
| 619 | 504 | /* just set a timer and mark ourselves error */ |
| 620 | | ide->device->machine().scheduler().timer_set(TIME_SECURITY_ERROR, FUNC(security_error_done), 0, ide); |
| 505 | machine().scheduler().timer_set(TIME_SECURITY_ERROR, FUNC(security_error_done), 0, this); |
| 621 | 506 | } |
| 622 | 507 | |
| 623 | 508 | |
| r18713 | r18714 | |
| 628 | 513 | * |
| 629 | 514 | *************************************/ |
| 630 | 515 | |
| 631 | | static void continue_read(ide_state *ide) |
| 516 | void ide_controller_device::continue_read() |
| 632 | 517 | { |
| 633 | 518 | /* reset the totals */ |
| 634 | | ide->buffer_offset = 0; |
| 519 | buffer_offset = 0; |
| 635 | 520 | |
| 636 | 521 | /* clear the buffer ready and busy flag */ |
| 637 | | ide->status &= ~IDE_STATUS_BUFFER_READY; |
| 638 | | ide->status &= ~IDE_STATUS_BUSY; |
| 522 | status &= ~IDE_STATUS_BUFFER_READY; |
| 523 | status &= ~IDE_STATUS_BUSY; |
| 639 | 524 | |
| 640 | | if (ide->master_password_enable || ide->user_password_enable) |
| 525 | if (master_password_enable || user_password_enable) |
| 641 | 526 | { |
| 642 | | security_error(ide); |
| 527 | security_error(); |
| 643 | 528 | |
| 644 | | ide->sector_count = 0; |
| 645 | | ide->bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 646 | | ide->dma_active = 0; |
| 529 | sector_count = 0; |
| 530 | bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 531 | dma_active = 0; |
| 647 | 532 | |
| 648 | 533 | return; |
| 649 | 534 | } |
| 650 | 535 | |
| 651 | 536 | /* if there is more data to read, keep going */ |
| 652 | | if (ide->sector_count > 0) |
| 653 | | ide->sector_count--; |
| 654 | | if (ide->sector_count > 0) |
| 655 | | read_next_sector(ide); |
| 537 | if (sector_count > 0) |
| 538 | sector_count--; |
| 539 | if (sector_count > 0) |
| 540 | read_next_sector(); |
| 656 | 541 | else |
| 657 | 542 | { |
| 658 | | ide->bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 659 | | ide->dma_active = 0; |
| 543 | bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 544 | dma_active = 0; |
| 660 | 545 | } |
| 661 | 546 | } |
| 662 | 547 | |
| 663 | 548 | |
| 664 | | static void write_buffer_to_dma(ide_state *ide) |
| 549 | void ide_controller_device::write_buffer_to_dma() |
| 665 | 550 | { |
| 666 | 551 | int bytesleft = IDE_DISK_SECTOR_SIZE; |
| 667 | | UINT8 *data = ide->buffer; |
| 552 | UINT8 *data = buffer; |
| 668 | 553 | |
| 669 | | // LOG(("Writing sector to %08X\n", ide->dma_address)); |
| 554 | // LOG(("Writing sector to %08X\n", dma_address)); |
| 670 | 555 | |
| 671 | 556 | /* loop until we've consumed all bytes */ |
| 672 | 557 | while (bytesleft--) |
| 673 | 558 | { |
| 674 | 559 | /* if we're out of space, grab the next descriptor */ |
| 675 | | if (ide->dma_bytes_left == 0) |
| 560 | if (dma_bytes_left == 0) |
| 676 | 561 | { |
| 677 | 562 | /* if we're out of buffer space, that's bad */ |
| 678 | | if (ide->dma_last_buffer) |
| 563 | if (dma_last_buffer) |
| 679 | 564 | { |
| 680 | 565 | LOG(("DMA Out of buffer space!\n")); |
| 681 | 566 | return; |
| 682 | 567 | } |
| 683 | 568 | |
| 684 | 569 | /* fetch the address */ |
| 685 | | ide->dma_address = ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor); |
| 686 | | ide->dma_address |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 8; |
| 687 | | ide->dma_address |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 16; |
| 688 | | ide->dma_address |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 24; |
| 689 | | ide->dma_address &= 0xfffffffe; |
| 570 | dma_address = dma_space->read_byte(dma_descriptor++ ^ dma_address_xor); |
| 571 | dma_address |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 8; |
| 572 | dma_address |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 16; |
| 573 | dma_address |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 24; |
| 574 | dma_address &= 0xfffffffe; |
| 690 | 575 | |
| 691 | 576 | /* fetch the length */ |
| 692 | | ide->dma_bytes_left = ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor); |
| 693 | | ide->dma_bytes_left |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 8; |
| 694 | | ide->dma_bytes_left |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 16; |
| 695 | | ide->dma_bytes_left |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 24; |
| 696 | | ide->dma_last_buffer = (ide->dma_bytes_left >> 31) & 1; |
| 697 | | ide->dma_bytes_left &= 0xfffe; |
| 698 | | if (ide->dma_bytes_left == 0) |
| 699 | | ide->dma_bytes_left = 0x10000; |
| 577 | dma_bytes_left = dma_space->read_byte(dma_descriptor++ ^ dma_address_xor); |
| 578 | dma_bytes_left |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 8; |
| 579 | dma_bytes_left |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 16; |
| 580 | dma_bytes_left |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 24; |
| 581 | dma_last_buffer = (dma_bytes_left >> 31) & 1; |
| 582 | dma_bytes_left &= 0xfffe; |
| 583 | if (dma_bytes_left == 0) |
| 584 | dma_bytes_left = 0x10000; |
| 700 | 585 | |
| 701 | | // LOG(("New DMA descriptor: address = %08X bytes = %04X last = %d\n", ide->dma_address, ide->dma_bytes_left, ide->dma_last_buffer)); |
| 586 | // LOG(("New DMA descriptor: address = %08X bytes = %04X last = %d\n", dma_address, dma_bytes_left, dma_last_buffer)); |
| 702 | 587 | } |
| 703 | 588 | |
| 704 | 589 | /* write the next byte */ |
| 705 | | ide->dma_space->write_byte(ide->dma_address++, *data++); |
| 706 | | ide->dma_bytes_left--; |
| 590 | dma_space->write_byte(dma_address++, *data++); |
| 591 | dma_bytes_left--; |
| 707 | 592 | } |
| 708 | 593 | } |
| 709 | 594 | |
| 710 | 595 | |
| 711 | | static void read_sector_done(ide_state *ide) |
| 596 | void ide_controller_device::read_sector_done() |
| 712 | 597 | { |
| 713 | | int lba = lba_address(ide), count = 0; |
| 598 | int lba = lba_address(), count = 0; |
| 714 | 599 | |
| 715 | 600 | /* GNET readlock check */ |
| 716 | | if (ide->gnetreadlock) { |
| 717 | | ide->status &= ~IDE_STATUS_ERROR; |
| 718 | | ide->status &= ~IDE_STATUS_BUSY; |
| 601 | if (gnetreadlock) { |
| 602 | status &= ~IDE_STATUS_ERROR; |
| 603 | status &= ~IDE_STATUS_BUSY; |
| 719 | 604 | return; |
| 720 | 605 | } |
| 721 | 606 | /* now do the read */ |
| 722 | | if (ide->drive[ide->cur_drive].slot) { |
| 723 | | count = ide->drive[ide->cur_drive].slot->read_sector(lba, ide->buffer); |
| 607 | if (drive[cur_drive].slot) { |
| 608 | count = drive[cur_drive].slot->read_sector(lba, buffer); |
| 724 | 609 | } |
| 725 | 610 | |
| 726 | 611 | /* by default, mark the buffer ready and the seek complete */ |
| 727 | | if (!ide->verify_only) |
| 728 | | ide->status |= IDE_STATUS_BUFFER_READY; |
| 729 | | ide->status |= IDE_STATUS_SEEK_COMPLETE; |
| 612 | if (!verify_only) |
| 613 | status |= IDE_STATUS_BUFFER_READY; |
| 614 | status |= IDE_STATUS_SEEK_COMPLETE; |
| 730 | 615 | |
| 731 | 616 | /* and clear the busy and error flags */ |
| 732 | | ide->status &= ~IDE_STATUS_ERROR; |
| 733 | | ide->status &= ~IDE_STATUS_BUSY; |
| 617 | status &= ~IDE_STATUS_ERROR; |
| 618 | status &= ~IDE_STATUS_BUSY; |
| 734 | 619 | |
| 735 | 620 | /* if we succeeded, advance to the next sector and set the nice bits */ |
| 736 | 621 | if (count == 1) |
| 737 | 622 | { |
| 738 | 623 | /* advance the pointers, unless this is the last sector */ |
| 739 | 624 | /* Gauntlet: Dark Legacy checks to make sure we stop on the last sector */ |
| 740 | | if (ide->sector_count != 1) |
| 741 | | next_sector(ide); |
| 625 | if (sector_count != 1) |
| 626 | next_sector(); |
| 742 | 627 | |
| 743 | 628 | /* clear the error value */ |
| 744 | | ide->error = IDE_ERROR_NONE; |
| 629 | error = IDE_ERROR_NONE; |
| 745 | 630 | |
| 746 | 631 | /* signal an interrupt */ |
| 747 | | if (!ide->verify_only) |
| 748 | | ide->sectors_until_int--; |
| 749 | | if (ide->sectors_until_int == 0 || ide->sector_count == 1) |
| 632 | if (!verify_only) |
| 633 | sectors_until_int--; |
| 634 | if (sectors_until_int == 0 || sector_count == 1) |
| 750 | 635 | { |
| 751 | | ide->sectors_until_int = ((ide->command == IDE_COMMAND_READ_MULTIPLE_BLOCK) ? ide->block_count : 1); |
| 752 | | signal_interrupt(ide); |
| 636 | sectors_until_int = ((command == IDE_COMMAND_READ_MULTIPLE_BLOCK) ? block_count : 1); |
| 637 | signal_interrupt(); |
| 753 | 638 | } |
| 754 | 639 | |
| 755 | 640 | /* handle DMA */ |
| 756 | | if (ide->dma_active) |
| 757 | | write_buffer_to_dma(ide); |
| 641 | if (dma_active) |
| 642 | write_buffer_to_dma(); |
| 758 | 643 | |
| 759 | 644 | /* if we're just verifying or if we DMA'ed the data, we can read the next sector */ |
| 760 | | if (ide->verify_only || ide->dma_active) |
| 761 | | continue_read(ide); |
| 645 | if (verify_only || dma_active) |
| 646 | continue_read(); |
| 762 | 647 | } |
| 763 | 648 | |
| 764 | 649 | /* if we got an error, we need to report it */ |
| 765 | 650 | else |
| 766 | 651 | { |
| 767 | 652 | /* set the error flag and the error */ |
| 768 | | ide->status |= IDE_STATUS_ERROR; |
| 769 | | ide->error = IDE_ERROR_BAD_SECTOR; |
| 770 | | ide->bus_master_status |= IDE_BUSMASTER_STATUS_ERROR; |
| 771 | | ide->bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 653 | status |= IDE_STATUS_ERROR; |
| 654 | error = IDE_ERROR_BAD_SECTOR; |
| 655 | bus_master_status |= IDE_BUSMASTER_STATUS_ERROR; |
| 656 | bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 772 | 657 | |
| 773 | 658 | /* signal an interrupt */ |
| 774 | | signal_interrupt(ide); |
| 659 | signal_interrupt(); |
| 775 | 660 | } |
| 776 | 661 | } |
| 777 | 662 | |
| 778 | 663 | |
| 779 | 664 | static TIMER_CALLBACK( read_sector_done_callback ) |
| 780 | 665 | { |
| 781 | | read_sector_done((ide_state *)ptr); |
| 666 | ide_controller_device *ide = (ide_controller_device *)ptr; |
| 667 | |
| 668 | ide->read_sector_done(); |
| 782 | 669 | } |
| 783 | 670 | |
| 784 | 671 | |
| 785 | | static void read_first_sector(ide_state *ide) |
| 672 | void ide_controller_device::read_first_sector() |
| 786 | 673 | { |
| 787 | 674 | /* mark ourselves busy */ |
| 788 | | ide->status |= IDE_STATUS_BUSY; |
| 675 | status |= IDE_STATUS_BUSY; |
| 789 | 676 | |
| 790 | 677 | /* just set a timer */ |
| 791 | | if (ide->command == IDE_COMMAND_READ_MULTIPLE_BLOCK) |
| 678 | if (command == IDE_COMMAND_READ_MULTIPLE_BLOCK) |
| 792 | 679 | { |
| 793 | | int new_lba = lba_address(ide); |
| 680 | int new_lba = lba_address(); |
| 794 | 681 | attotime seek_time; |
| 795 | 682 | |
| 796 | | if (new_lba == ide->drive[ide->cur_drive].cur_lba || new_lba == ide->drive[ide->cur_drive].cur_lba + 1) |
| 683 | if (new_lba == drive[cur_drive].cur_lba || new_lba == drive[cur_drive].cur_lba + 1) |
| 797 | 684 | seek_time = TIME_NO_SEEK_MULTISECTOR; |
| 798 | 685 | else |
| 799 | 686 | seek_time = TIME_SEEK_MULTISECTOR; |
| 800 | 687 | |
| 801 | | ide->drive[ide->cur_drive].cur_lba = new_lba; |
| 802 | | ide->device->machine().scheduler().timer_set(seek_time, FUNC(read_sector_done_callback), 0, ide); |
| 688 | drive[cur_drive].cur_lba = new_lba; |
| 689 | machine().scheduler().timer_set(seek_time, FUNC(read_sector_done_callback), 0, this); |
| 803 | 690 | } |
| 804 | 691 | else |
| 805 | | ide->device->machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(read_sector_done_callback), 0, ide); |
| 692 | machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(read_sector_done_callback), 0, this); |
| 806 | 693 | } |
| 807 | 694 | |
| 808 | 695 | |
| 809 | | static void read_next_sector(ide_state *ide) |
| 696 | void ide_controller_device::read_next_sector() |
| 810 | 697 | { |
| 811 | 698 | /* mark ourselves busy */ |
| 812 | | ide->status |= IDE_STATUS_BUSY; |
| 699 | status |= IDE_STATUS_BUSY; |
| 813 | 700 | |
| 814 | | if (ide->command == IDE_COMMAND_READ_MULTIPLE_BLOCK) |
| 701 | if (command == IDE_COMMAND_READ_MULTIPLE_BLOCK) |
| 815 | 702 | { |
| 816 | | if (ide->sectors_until_int != 1) |
| 703 | if (sectors_until_int != 1) |
| 817 | 704 | /* make ready now */ |
| 818 | | read_sector_done(ide); |
| 705 | read_sector_done(); |
| 819 | 706 | else |
| 820 | 707 | /* just set a timer */ |
| 821 | | ide->device->machine().scheduler().timer_set(attotime::from_usec(1), FUNC(read_sector_done_callback), 0, ide); |
| 708 | machine().scheduler().timer_set(attotime::from_usec(1), FUNC(read_sector_done_callback), 0, this); |
| 822 | 709 | } |
| 823 | 710 | else |
| 824 | 711 | /* just set a timer */ |
| 825 | | ide->device->machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(read_sector_done_callback), 0, ide); |
| 712 | machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(read_sector_done_callback), 0, this); |
| 826 | 713 | } |
| 827 | 714 | |
| 828 | 715 | |
| r18713 | r18714 | |
| 833 | 720 | * |
| 834 | 721 | *************************************/ |
| 835 | 722 | |
| 836 | | static void write_sector_done(ide_state *ide); |
| 837 | 723 | static TIMER_CALLBACK( write_sector_done_callback ); |
| 838 | 724 | |
| 839 | | static void continue_write(ide_state *ide) |
| 725 | void ide_controller_device::continue_write() |
| 840 | 726 | { |
| 841 | 727 | /* reset the totals */ |
| 842 | | ide->buffer_offset = 0; |
| 728 | buffer_offset = 0; |
| 843 | 729 | |
| 844 | 730 | /* clear the buffer ready flag */ |
| 845 | | ide->status &= ~IDE_STATUS_BUFFER_READY; |
| 846 | | ide->status |= IDE_STATUS_BUSY; |
| 731 | status &= ~IDE_STATUS_BUFFER_READY; |
| 732 | status |= IDE_STATUS_BUSY; |
| 847 | 733 | |
| 848 | | if (ide->command == IDE_COMMAND_WRITE_MULTIPLE_BLOCK) |
| 734 | if (command == IDE_COMMAND_WRITE_MULTIPLE_BLOCK) |
| 849 | 735 | { |
| 850 | | if (ide->sectors_until_int != 1) |
| 736 | if (sectors_until_int != 1) |
| 851 | 737 | { |
| 852 | 738 | /* ready to write now */ |
| 853 | | write_sector_done(ide); |
| 739 | write_sector_done(); |
| 854 | 740 | } |
| 855 | 741 | else |
| 856 | 742 | { |
| 857 | 743 | /* set a timer to do the write */ |
| 858 | | ide->device->machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(write_sector_done_callback), 0, ide); |
| 744 | machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(write_sector_done_callback), 0, this); |
| 859 | 745 | } |
| 860 | 746 | } |
| 861 | 747 | else |
| 862 | 748 | { |
| 863 | 749 | /* set a timer to do the write */ |
| 864 | | ide->device->machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(write_sector_done_callback), 0, ide); |
| 750 | machine().scheduler().timer_set(TIME_PER_SECTOR, FUNC(write_sector_done_callback), 0, this); |
| 865 | 751 | } |
| 866 | 752 | } |
| 867 | 753 | |
| 868 | 754 | |
| 869 | | static void read_buffer_from_dma(ide_state *ide) |
| 755 | void ide_controller_device::read_buffer_from_dma() |
| 870 | 756 | { |
| 871 | 757 | int bytesleft = IDE_DISK_SECTOR_SIZE; |
| 872 | | UINT8 *data = ide->buffer; |
| 758 | UINT8 *data = buffer; |
| 873 | 759 | |
| 874 | | // LOG(("Reading sector from %08X\n", ide->dma_address)); |
| 760 | // LOG(("Reading sector from %08X\n", dma_address)); |
| 875 | 761 | |
| 876 | 762 | /* loop until we've consumed all bytes */ |
| 877 | 763 | while (bytesleft--) |
| 878 | 764 | { |
| 879 | 765 | /* if we're out of space, grab the next descriptor */ |
| 880 | | if (ide->dma_bytes_left == 0) |
| 766 | if (dma_bytes_left == 0) |
| 881 | 767 | { |
| 882 | 768 | /* if we're out of buffer space, that's bad */ |
| 883 | | if (ide->dma_last_buffer) |
| 769 | if (dma_last_buffer) |
| 884 | 770 | { |
| 885 | 771 | LOG(("DMA Out of buffer space!\n")); |
| 886 | 772 | return; |
| 887 | 773 | } |
| 888 | 774 | |
| 889 | 775 | /* fetch the address */ |
| 890 | | ide->dma_address = ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor); |
| 891 | | ide->dma_address |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 8; |
| 892 | | ide->dma_address |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 16; |
| 893 | | ide->dma_address |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 24; |
| 894 | | ide->dma_address &= 0xfffffffe; |
| 776 | dma_address = dma_space->read_byte(dma_descriptor++ ^ dma_address_xor); |
| 777 | dma_address |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 8; |
| 778 | dma_address |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 16; |
| 779 | dma_address |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 24; |
| 780 | dma_address &= 0xfffffffe; |
| 895 | 781 | |
| 896 | 782 | /* fetch the length */ |
| 897 | | ide->dma_bytes_left = ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor); |
| 898 | | ide->dma_bytes_left |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 8; |
| 899 | | ide->dma_bytes_left |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 16; |
| 900 | | ide->dma_bytes_left |= ide->dma_space->read_byte(ide->dma_descriptor++ ^ ide->dma_address_xor) << 24; |
| 901 | | ide->dma_last_buffer = (ide->dma_bytes_left >> 31) & 1; |
| 902 | | ide->dma_bytes_left &= 0xfffe; |
| 903 | | if (ide->dma_bytes_left == 0) |
| 904 | | ide->dma_bytes_left = 0x10000; |
| 783 | dma_bytes_left = dma_space->read_byte(dma_descriptor++ ^ dma_address_xor); |
| 784 | dma_bytes_left |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 8; |
| 785 | dma_bytes_left |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 16; |
| 786 | dma_bytes_left |= dma_space->read_byte(dma_descriptor++ ^ dma_address_xor) << 24; |
| 787 | dma_last_buffer = (dma_bytes_left >> 31) & 1; |
| 788 | dma_bytes_left &= 0xfffe; |
| 789 | if (dma_bytes_left == 0) |
| 790 | dma_bytes_left = 0x10000; |
| 905 | 791 | |
| 906 | | // LOG(("New DMA descriptor: address = %08X bytes = %04X last = %d\n", ide->dma_address, ide->dma_bytes_left, ide->dma_last_buffer)); |
| 792 | // LOG(("New DMA descriptor: address = %08X bytes = %04X last = %d\n", dma_address, dma_bytes_left, dma_last_buffer)); |
| 907 | 793 | } |
| 908 | 794 | |
| 909 | 795 | /* read the next byte */ |
| 910 | | *data++ = ide->dma_space->read_byte(ide->dma_address++); |
| 911 | | ide->dma_bytes_left--; |
| 796 | *data++ = dma_space->read_byte(dma_address++); |
| 797 | dma_bytes_left--; |
| 912 | 798 | } |
| 913 | 799 | } |
| 914 | 800 | |
| 915 | 801 | |
| 916 | | static void write_sector_done(ide_state *ide) |
| 802 | void ide_controller_device::write_sector_done() |
| 917 | 803 | { |
| 918 | | int lba = lba_address(ide), count = 0; |
| 804 | int lba = lba_address(), count = 0; |
| 919 | 805 | |
| 920 | 806 | /* now do the write */ |
| 921 | | if (ide->drive[ide->cur_drive].slot) { |
| 922 | | count = ide->drive[ide->cur_drive].slot->write_sector(lba, ide->buffer); |
| 807 | if (drive[cur_drive].slot) { |
| 808 | count = drive[cur_drive].slot->write_sector(lba, buffer); |
| 923 | 809 | } |
| 924 | 810 | |
| 925 | 811 | /* by default, mark the buffer ready and the seek complete */ |
| 926 | | ide->status |= IDE_STATUS_BUFFER_READY; |
| 927 | | ide->status |= IDE_STATUS_SEEK_COMPLETE; |
| 812 | status |= IDE_STATUS_BUFFER_READY; |
| 813 | status |= IDE_STATUS_SEEK_COMPLETE; |
| 928 | 814 | |
| 929 | 815 | /* and clear the busy adn error flags */ |
| 930 | | ide->status &= ~IDE_STATUS_ERROR; |
| 931 | | ide->status &= ~IDE_STATUS_BUSY; |
| 816 | status &= ~IDE_STATUS_ERROR; |
| 817 | status &= ~IDE_STATUS_BUSY; |
| 932 | 818 | |
| 933 | 819 | /* if we succeeded, advance to the next sector and set the nice bits */ |
| 934 | 820 | if (count == 1) |
| 935 | 821 | { |
| 936 | 822 | /* advance the pointers, unless this is the last sector */ |
| 937 | 823 | /* Gauntlet: Dark Legacy checks to make sure we stop on the last sector */ |
| 938 | | if (ide->sector_count != 1) |
| 939 | | next_sector(ide); |
| 824 | if (sector_count != 1) |
| 825 | next_sector(); |
| 940 | 826 | |
| 941 | 827 | /* clear the error value */ |
| 942 | | ide->error = IDE_ERROR_NONE; |
| 828 | error = IDE_ERROR_NONE; |
| 943 | 829 | |
| 944 | 830 | /* signal an interrupt */ |
| 945 | | if (--ide->sectors_until_int == 0 || ide->sector_count == 1) |
| 831 | if (--sectors_until_int == 0 || sector_count == 1) |
| 946 | 832 | { |
| 947 | | ide->sectors_until_int = ((ide->command == IDE_COMMAND_WRITE_MULTIPLE_BLOCK) ? ide->block_count : 1); |
| 948 | | signal_interrupt(ide); |
| 833 | sectors_until_int = ((command == IDE_COMMAND_WRITE_MULTIPLE_BLOCK) ? block_count : 1); |
| 834 | signal_interrupt(); |
| 949 | 835 | } |
| 950 | 836 | |
| 951 | 837 | /* signal an interrupt if there's more data needed */ |
| 952 | | if (ide->sector_count > 0) |
| 953 | | ide->sector_count--; |
| 954 | | if (ide->sector_count == 0) |
| 955 | | ide->status &= ~IDE_STATUS_BUFFER_READY; |
| 838 | if (sector_count > 0) |
| 839 | sector_count--; |
| 840 | if (sector_count == 0) |
| 841 | status &= ~IDE_STATUS_BUFFER_READY; |
| 956 | 842 | |
| 957 | 843 | /* keep going for DMA */ |
| 958 | | if (ide->dma_active && ide->sector_count != 0) |
| 844 | if (dma_active && sector_count != 0) |
| 959 | 845 | { |
| 960 | | read_buffer_from_dma(ide); |
| 961 | | continue_write(ide); |
| 846 | read_buffer_from_dma(); |
| 847 | continue_write(); |
| 962 | 848 | } |
| 963 | 849 | else |
| 964 | | ide->dma_active = 0; |
| 850 | dma_active = 0; |
| 965 | 851 | } |
| 966 | 852 | |
| 967 | 853 | /* if we got an error, we need to report it */ |
| 968 | 854 | else |
| 969 | 855 | { |
| 970 | 856 | /* set the error flag and the error */ |
| 971 | | ide->status |= IDE_STATUS_ERROR; |
| 972 | | ide->error = IDE_ERROR_BAD_SECTOR; |
| 973 | | ide->bus_master_status |= IDE_BUSMASTER_STATUS_ERROR; |
| 974 | | ide->bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 857 | status |= IDE_STATUS_ERROR; |
| 858 | error = IDE_ERROR_BAD_SECTOR; |
| 859 | bus_master_status |= IDE_BUSMASTER_STATUS_ERROR; |
| 860 | bus_master_status &= ~IDE_BUSMASTER_STATUS_ACTIVE; |
| 975 | 861 | |
| 976 | 862 | /* signal an interrupt */ |
| 977 | | signal_interrupt(ide); |
| 863 | signal_interrupt(); |
| 978 | 864 | } |
| 979 | 865 | } |
| 980 | 866 | |
| 981 | 867 | |
| 982 | 868 | static TIMER_CALLBACK( write_sector_done_callback ) |
| 983 | 869 | { |
| 984 | | write_sector_done((ide_state *)ptr); |
| 870 | ide_controller_device *ide = (ide_controller_device *)ptr; |
| 871 | ide->write_sector_done(); |
| 985 | 872 | } |
| 986 | 873 | |
| 987 | 874 | |
| r18713 | r18714 | |
| 992 | 879 | * |
| 993 | 880 | *************************************/ |
| 994 | 881 | |
| 995 | | static void handle_command(ide_state *ide, UINT8 command) |
| 882 | void ide_controller_device::handle_command(UINT8 _command) |
| 996 | 883 | { |
| 997 | 884 | UINT8 key[5]; |
| 998 | 885 | |
| 999 | 886 | /* implicitly clear interrupts here */ |
| 1000 | | clear_interrupt(ide); |
| 1001 | | ide->command = command; |
| 887 | clear_interrupt(); |
| 888 | command = _command; |
| 1002 | 889 | switch (command) |
| 1003 | 890 | { |
| 1004 | 891 | case IDE_COMMAND_READ_MULTIPLE: |
| 1005 | 892 | case IDE_COMMAND_READ_MULTIPLE_NORETRY: |
| 1006 | 893 | LOGPRINT(("IDE Read multiple: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1007 | | 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)); |
| 894 | drive[cur_drive].cur_cylinder, drive[cur_drive].cur_head, drive[cur_drive].cur_sector, lba_address(), sector_count)); |
| 1008 | 895 | |
| 1009 | 896 | /* reset the buffer */ |
| 1010 | | ide->buffer_offset = 0; |
| 1011 | | ide->sectors_until_int = 1; |
| 1012 | | ide->dma_active = 0; |
| 1013 | | ide->verify_only = 0; |
| 897 | buffer_offset = 0; |
| 898 | sectors_until_int = 1; |
| 899 | dma_active = 0; |
| 900 | verify_only = 0; |
| 1014 | 901 | |
| 1015 | 902 | /* start the read going */ |
| 1016 | | read_first_sector(ide); |
| 903 | read_first_sector(); |
| 1017 | 904 | break; |
| 1018 | 905 | |
| 1019 | 906 | case IDE_COMMAND_READ_MULTIPLE_BLOCK: |
| 1020 | 907 | LOGPRINT(("IDE Read multiple block: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1021 | | 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)); |
| 908 | drive[cur_drive].cur_cylinder, drive[cur_drive].cur_head, drive[cur_drive].cur_sector, lba_address(), sector_count)); |
| 1022 | 909 | |
| 1023 | 910 | /* reset the buffer */ |
| 1024 | | ide->buffer_offset = 0; |
| 1025 | | ide->sectors_until_int = 1; |
| 1026 | | ide->dma_active = 0; |
| 1027 | | ide->verify_only = 0; |
| 911 | buffer_offset = 0; |
| 912 | sectors_until_int = 1; |
| 913 | dma_active = 0; |
| 914 | verify_only = 0; |
| 1028 | 915 | |
| 1029 | 916 | /* start the read going */ |
| 1030 | | read_first_sector(ide); |
| 917 | read_first_sector(); |
| 1031 | 918 | break; |
| 1032 | 919 | |
| 1033 | 920 | case IDE_COMMAND_VERIFY_MULTIPLE: |
| 1034 | 921 | case IDE_COMMAND_VERIFY_NORETRY: |
| 1035 | 922 | LOGPRINT(("IDE Read verify multiple with/without retries: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1036 | | 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)); |
| 923 | drive[cur_drive].cur_cylinder, drive[cur_drive].cur_head, drive[cur_drive].cur_sector, lba_address(), sector_count)); |
| 1037 | 924 | |
| 1038 | 925 | /* reset the buffer */ |
| 1039 | | ide->buffer_offset = 0; |
| 1040 | | ide->sectors_until_int = 1; |
| 1041 | | ide->dma_active = 0; |
| 1042 | | ide->verify_only = 1; |
| 926 | buffer_offset = 0; |
| 927 | sectors_until_int = 1; |
| 928 | dma_active = 0; |
| 929 | verify_only = 1; |
| 1043 | 930 | |
| 1044 | 931 | /* start the read going */ |
| 1045 | | read_first_sector(ide); |
| 932 | read_first_sector(); |
| 1046 | 933 | break; |
| 1047 | 934 | |
| 1048 | 935 | case IDE_COMMAND_READ_DMA: |
| 1049 | 936 | LOGPRINT(("IDE Read multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1050 | | 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)); |
| 937 | drive[cur_drive].cur_cylinder, drive[cur_drive].cur_head, drive[cur_drive].cur_sector, lba_address(), sector_count)); |
| 1051 | 938 | |
| 1052 | 939 | /* reset the buffer */ |
| 1053 | | ide->buffer_offset = 0; |
| 1054 | | ide->sectors_until_int = ide->sector_count; |
| 1055 | | ide->dma_active = 1; |
| 1056 | | ide->verify_only = 0; |
| 940 | buffer_offset = 0; |
| 941 | sectors_until_int = sector_count; |
| 942 | dma_active = 1; |
| 943 | verify_only = 0; |
| 1057 | 944 | |
| 1058 | 945 | /* start the read going */ |
| 1059 | | if (ide->bus_master_command & 1) |
| 1060 | | read_first_sector(ide); |
| 946 | if (bus_master_command & 1) |
| 947 | read_first_sector(); |
| 1061 | 948 | break; |
| 1062 | 949 | |
| 1063 | 950 | case IDE_COMMAND_WRITE_MULTIPLE: |
| 1064 | 951 | case IDE_COMMAND_WRITE_MULTIPLE_NORETRY: |
| 1065 | 952 | LOGPRINT(("IDE Write multiple: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1066 | | 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)); |
| 953 | drive[cur_drive].cur_cylinder, drive[cur_drive].cur_head, drive[cur_drive].cur_sector, lba_address(), sector_count)); |
| 1067 | 954 | |
| 1068 | 955 | /* reset the buffer */ |
| 1069 | | ide->buffer_offset = 0; |
| 1070 | | ide->sectors_until_int = 1; |
| 1071 | | ide->dma_active = 0; |
| 956 | buffer_offset = 0; |
| 957 | sectors_until_int = 1; |
| 958 | dma_active = 0; |
| 1072 | 959 | |
| 1073 | 960 | /* mark the buffer ready */ |
| 1074 | | ide->status |= IDE_STATUS_BUFFER_READY; |
| 961 | status |= IDE_STATUS_BUFFER_READY; |
| 1075 | 962 | break; |
| 1076 | 963 | |
| 1077 | 964 | case IDE_COMMAND_WRITE_MULTIPLE_BLOCK: |
| 1078 | 965 | LOGPRINT(("IDE Write multiple block: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1079 | | 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)); |
| 966 | drive[cur_drive].cur_cylinder, drive[cur_drive].cur_head, drive[cur_drive].cur_sector, lba_address(), sector_count)); |
| 1080 | 967 | |
| 1081 | 968 | /* reset the buffer */ |
| 1082 | | ide->buffer_offset = 0; |
| 1083 | | ide->sectors_until_int = 1; |
| 1084 | | ide->dma_active = 0; |
| 969 | buffer_offset = 0; |
| 970 | sectors_until_int = 1; |
| 971 | dma_active = 0; |
| 1085 | 972 | |
| 1086 | 973 | /* mark the buffer ready */ |
| 1087 | | ide->status |= IDE_STATUS_BUFFER_READY; |
| 974 | status |= IDE_STATUS_BUFFER_READY; |
| 1088 | 975 | break; |
| 1089 | 976 | |
| 1090 | 977 | case IDE_COMMAND_WRITE_DMA: |
| 1091 | 978 | LOGPRINT(("IDE Write multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n", |
| 1092 | | 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)); |
| 979 | drive[cur_drive].cur_cylinder, drive[cur_drive].cur_head, drive[cur_drive].cur_sector, lba_address(), sector_count)); |
| 1093 | 980 | |
| 1094 | 981 | /* reset the buffer */ |
| 1095 | | ide->buffer_offset = 0; |
| 1096 | | ide->sectors_until_int = ide->sector_count; |
| 1097 | | ide->dma_active = 1; |
| 982 | buffer_offset = 0; |
| 983 | sectors_until_int = sector_count; |
| 984 | dma_active = 1; |
| 1098 | 985 | |
| 1099 | 986 | /* start the read going */ |
| 1100 | | if (ide->bus_master_command & 1) |
| 987 | if (bus_master_command & 1) |
| 1101 | 988 | { |
| 1102 | | read_buffer_from_dma(ide); |
| 1103 | | continue_write(ide); |
| 989 | read_buffer_from_dma(); |
| 990 | continue_write(); |
| 1104 | 991 | } |
| 1105 | 992 | break; |
| 1106 | 993 | |
| r18713 | r18714 | |
| 1108 | 995 | LOGPRINT(("IDE Security Unlock\n")); |
| 1109 | 996 | |
| 1110 | 997 | /* reset the buffer */ |
| 1111 | | ide->buffer_offset = 0; |
| 1112 | | ide->sectors_until_int = 0; |
| 1113 | | ide->dma_active = 0; |
| 998 | buffer_offset = 0; |
| 999 | sectors_until_int = 0; |
| 1000 | dma_active = 0; |
| 1114 | 1001 | |
| 1115 | 1002 | /* mark the buffer ready */ |
| 1116 | | ide->status |= IDE_STATUS_BUFFER_READY; |
| 1117 | | signal_interrupt(ide); |
| 1003 | status |= IDE_STATUS_BUFFER_READY; |
| 1004 | signal_interrupt(); |
| 1118 | 1005 | break; |
| 1119 | 1006 | |
| 1120 | 1007 | case IDE_COMMAND_GET_INFO: |
| 1121 | 1008 | LOGPRINT(("IDE Read features\n")); |
| 1122 | 1009 | |
| 1123 | 1010 | /* reset the buffer */ |
| 1124 | | ide->buffer_offset = 0; |
| 1125 | | ide->sector_count = 1; |
| 1011 | buffer_offset = 0; |
| 1012 | sector_count = 1; |
| 1126 | 1013 | |
| 1127 | 1014 | /* build the features page */ |
| 1128 | | if (ide->drive[ide->cur_drive].slot->get_features()) { |
| 1129 | | memcpy(ide->buffer, ide->drive[ide->cur_drive].slot->get_features(), sizeof(ide->buffer)); |
| 1015 | if (drive[cur_drive].slot->get_features()) { |
| 1016 | memcpy(buffer, drive[cur_drive].slot->get_features(), sizeof(buffer)); |
| 1130 | 1017 | } |
| 1131 | 1018 | |
| 1132 | 1019 | /* indicate everything is ready */ |
| 1133 | | ide->status |= IDE_STATUS_BUFFER_READY; |
| 1134 | | ide->status |= IDE_STATUS_SEEK_COMPLETE; |
| 1135 | | ide->status |= IDE_STATUS_DRIVE_READY; |
| 1020 | status |= IDE_STATUS_BUFFER_READY; |
| 1021 | status |= IDE_STATUS_SEEK_COMPLETE; |
| 1022 | status |= IDE_STATUS_DRIVE_READY; |
| 1136 | 1023 | |
| 1137 | 1024 | /* and clear the busy adn error flags */ |
| 1138 | | ide->status &= ~IDE_STATUS_ERROR; |
| 1139 | | ide->status &= ~IDE_STATUS_BUSY; |
| 1025 | status &= ~IDE_STATUS_ERROR; |
| 1026 | status &= ~IDE_STATUS_BUSY; |
| 1140 | 1027 | |
| 1141 | 1028 | /* clear the error too */ |
| 1142 | | ide->error = IDE_ERROR_NONE; |
| 1029 | error = IDE_ERROR_NONE; |
| 1143 | 1030 | |
| 1144 | 1031 | /* signal an interrupt */ |
| 1145 | | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 1); |
| 1032 | signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 1); |
| 1146 | 1033 | break; |
| 1147 | 1034 | |
| 1148 | 1035 | case IDE_COMMAND_DIAGNOSTIC: |
| 1149 | | ide->error = IDE_ERROR_DEFAULT; |
| 1036 | error = IDE_ERROR_DEFAULT; |
| 1150 | 1037 | |
| 1151 | 1038 | /* signal an interrupt */ |
| 1152 | | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0); |
| 1039 | signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0); |
| 1153 | 1040 | break; |
| 1154 | 1041 | |
| 1155 | 1042 | case IDE_COMMAND_RECALIBRATE: |
| 1156 | 1043 | /* clear the error too */ |
| 1157 | | ide->error = IDE_ERROR_NONE; |
| 1044 | error = IDE_ERROR_NONE; |
| 1158 | 1045 | /* signal an interrupt */ |
| 1159 | | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0); |
| 1046 | signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0); |
| 1160 | 1047 | break; |
| 1161 | 1048 | |
| 1162 | 1049 | case IDE_COMMAND_IDLE: |
| 1163 | 1050 | /* clear the error too */ |
| 1164 | | ide->error = IDE_ERROR_NONE; |
| 1051 | error = IDE_ERROR_NONE; |
| 1165 | 1052 | |
| 1166 | 1053 | /* for timeout disabled value is 0 */ |
| 1167 | | ide->sector_count = 0; |
| 1054 | sector_count = 0; |
| 1168 | 1055 | /* signal an interrupt */ |
| 1169 | | signal_interrupt(ide); |
| 1056 | signal_interrupt(); |
| 1170 | 1057 | break; |
| 1171 | 1058 | |
| 1172 | 1059 | case IDE_COMMAND_SET_CONFIG: |
| 1173 | | LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", ide->drive[ide->cur_drive].cur_head + 1, ide->sector_count)); |
| 1174 | | ide->status &= ~IDE_STATUS_ERROR; |
| 1175 | | ide->error = IDE_ERROR_NONE; |
| 1176 | | ide->drive[ide->cur_drive].slot->set_geometry(ide->sector_count,ide->drive[ide->cur_drive].cur_head + 1); |
| 1060 | LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", drive[cur_drive].cur_head + 1, sector_count)); |
| 1061 | status &= ~IDE_STATUS_ERROR; |
| 1062 | error = IDE_ERROR_NONE; |
| 1063 | drive[cur_drive].slot->set_geometry(sector_count,drive[cur_drive].cur_head + 1); |
| 1177 | 1064 | |
| 1178 | 1065 | /* signal an interrupt */ |
| 1179 | | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0); |
| 1066 | signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0); |
| 1180 | 1067 | break; |
| 1181 | 1068 | |
| 1182 | 1069 | case IDE_COMMAND_UNKNOWN_F9: |
| r18713 | r18714 | |
| 1184 | 1071 | LOGPRINT(("IDE unknown command (F9)\n")); |
| 1185 | 1072 | |
| 1186 | 1073 | /* signal an interrupt */ |
| 1187 | | signal_interrupt(ide); |
| 1074 | signal_interrupt(); |
| 1188 | 1075 | break; |
| 1189 | 1076 | |
| 1190 | 1077 | case IDE_COMMAND_SET_FEATURES: |
| 1191 | | 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)); |
| 1078 | LOGPRINT(("IDE Set features (%02X %02X %02X %02X %02X)\n", precomp_offset, sector_count & 0xff, drive[cur_drive].cur_sector, drive[cur_drive].cur_cylinder & 0xff, drive[cur_drive].cur_cylinder >> 8)); |
| 1192 | 1079 | |
| 1193 | 1080 | /* signal an interrupt */ |
| 1194 | | signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0); |
| 1081 | signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0); |
| 1195 | 1082 | break; |
| 1196 | 1083 | |
| 1197 | 1084 | case IDE_COMMAND_SET_BLOCK_COUNT: |
| 1198 | | LOGPRINT(("IDE Set block count (%02X)\n", ide->sector_count)); |
| 1085 | LOGPRINT(("IDE Set block count (%02X)\n", sector_count)); |
| 1199 | 1086 | |
| 1200 | | ide->block_count = ide->sector_count; |
| 1087 | block_count = sector_count; |
| 1201 | 1088 | // judge dredd wants 'drive ready' on this command |
| 1202 | | ide->status |= IDE_STATUS_DRIVE_READY; |
| 1089 | status |= IDE_STATUS_DRIVE_READY; |
| 1203 | 1090 | |
| 1204 | 1091 | /* signal an interrupt */ |
| 1205 | | signal_interrupt(ide); |
| 1092 | signal_interrupt(); |
| 1206 | 1093 | break; |
| 1207 | 1094 | |
| 1208 | 1095 | case IDE_COMMAND_TAITO_GNET_UNLOCK_1: |
| 1209 | 1096 | LOGPRINT(("IDE GNET Unlock 1\n")); |
| 1210 | 1097 | |
| 1211 | | ide->sector_count = 1; |
| 1212 | | ide->status |= IDE_STATUS_DRIVE_READY; |
| 1213 | | ide->status &= ~IDE_STATUS_ERROR; |
| 1214 | | signal_interrupt(ide); |
| 1098 | sector_count = 1; |
| 1099 | status |= IDE_STATUS_DRIVE_READY; |
| 1100 | status &= ~IDE_STATUS_ERROR; |
| 1101 | signal_interrupt(); |
| 1215 | 1102 | break; |
| 1216 | 1103 | |
| 1217 | 1104 | case IDE_COMMAND_TAITO_GNET_UNLOCK_2: |
| 1218 | 1105 | LOGPRINT(("IDE GNET Unlock 2\n")); |
| 1219 | 1106 | |
| 1220 | 1107 | /* reset the buffer */ |
| 1221 | | ide->buffer_offset = 0; |
| 1222 | | ide->sectors_until_int = 0; |
| 1223 | | ide->dma_active = 0; |
| 1108 | buffer_offset = 0; |
| 1109 | sectors_until_int = 0; |
| 1110 | dma_active = 0; |
| 1224 | 1111 | |
| 1225 | 1112 | /* mark the buffer ready */ |
| 1226 | | ide->status |= IDE_STATUS_BUFFER_READY; |
| 1227 | | signal_interrupt(ide); |
| 1113 | status |= IDE_STATUS_BUFFER_READY; |
| 1114 | signal_interrupt(); |
| 1228 | 1115 | break; |
| 1229 | 1116 | |
| 1230 | 1117 | case IDE_COMMAND_TAITO_GNET_UNLOCK_3: |
| 1231 | 1118 | LOGPRINT(("IDE GNET Unlock 3\n")); |
| 1232 | 1119 | |
| 1233 | 1120 | /* key check */ |
| 1234 | | ide->drive[ide->cur_drive].slot->read_key(key); |
| 1235 | | 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]))) |
| 1121 | drive[cur_drive].slot->read_key(key); |
| 1122 | if ((precomp_offset == key[0]) && (sector_count == key[1]) && (drive[cur_drive].cur_sector == key[2]) && (drive[cur_drive].cur_cylinder == (((UINT16)key[4]<<8)|key[3]))) |
| 1236 | 1123 | { |
| 1237 | | ide->gnetreadlock= 0; |
| 1124 | gnetreadlock= 0; |
| 1238 | 1125 | } |
| 1239 | 1126 | |
| 1240 | 1127 | /* update flags */ |
| 1241 | | ide->status |= IDE_STATUS_DRIVE_READY; |
| 1242 | | ide->status &= ~IDE_STATUS_ERROR; |
| 1243 | | signal_interrupt(ide); |
| 1128 | status |= IDE_STATUS_DRIVE_READY; |
| 1129 | status &= ~IDE_STATUS_ERROR; |
| 1130 | signal_interrupt(); |
| 1244 | 1131 | break; |
| 1245 | 1132 | |
| 1246 | 1133 | case IDE_COMMAND_SEEK: |
| r18713 | r18714 | |
| 1250 | 1137 | so that implements actual seek |
| 1251 | 1138 | */ |
| 1252 | 1139 | /* clear the error too */ |
| 1253 | | ide->error = IDE_ERROR_NONE; |
| 1140 | error = IDE_ERROR_NONE; |
| 1254 | 1141 | |
| 1255 | 1142 | /* for timeout disabled value is 0 */ |
| 1256 | | ide->sector_count = 0; |
| 1143 | sector_count = 0; |
| 1257 | 1144 | /* signal an interrupt */ |
| 1258 | | signal_interrupt(ide); |
| 1145 | signal_interrupt(); |
| 1259 | 1146 | break; |
| 1260 | 1147 | |
| 1261 | 1148 | |
| 1262 | 1149 | default: |
| 1263 | 1150 | LOGPRINT(("IDE unknown command (%02X)\n", command)); |
| 1264 | | ide->status |= IDE_STATUS_ERROR; |
| 1265 | | ide->error = IDE_ERROR_UNKNOWN_COMMAND; |
| 1266 | | signal_interrupt(ide); |
| 1267 | | //debugger_break(ide->device->machine()); |
| 1151 | status |= IDE_STATUS_ERROR; |
| 1152 | error = IDE_ERROR_UNKNOWN_COMMAND; |
| 1153 | signal_interrupt(); |
| 1154 | //debugger_break(device->machine()); |
| 1268 | 1155 | break; |
| 1269 | 1156 | } |
| 1270 | 1157 | } |
| r18713 | r18714 | |
| 1277 | 1164 | * |
| 1278 | 1165 | *************************************/ |
| 1279 | 1166 | |
| 1280 | | static UINT32 ide_controller_read(device_t *device, int bank, offs_t offset, int size) |
| 1167 | UINT32 ide_controller_device::ide_controller_read(int bank, offs_t offset, int size) |
| 1281 | 1168 | { |
| 1282 | | ide_state *ide = get_safe_token(device); |
| 1283 | 1169 | UINT32 result = 0; |
| 1284 | 1170 | |
| 1285 | 1171 | /* logit */ |
| 1286 | 1172 | // if (BANK(bank, offset) != IDE_BANK0_DATA && BANK(bank, offset) != IDE_BANK0_STATUS_COMMAND && BANK(bank, offset) != IDE_BANK1_STATUS_CONTROL) |
| 1287 | | LOG(("%s:IDE read at %d:%X, size=%d\n", device->machine().describe_context(), bank, offset, size)); |
| 1173 | LOG(("%s:IDE read at %d:%X, size=%d\n", machine().describe_context(), bank, offset, size)); |
| 1288 | 1174 | |
| 1289 | | if (ide->drive[ide->cur_drive].slot->is_connected()) |
| 1175 | if (drive[cur_drive].slot->is_connected()) |
| 1290 | 1176 | { |
| 1291 | | if (ide->drive[ide->cur_drive].slot->is_ready()) { |
| 1292 | | ide->status |= IDE_STATUS_DRIVE_READY; |
| 1177 | if (drive[cur_drive].slot->is_ready()) { |
| 1178 | status |= IDE_STATUS_DRIVE_READY; |
| 1293 | 1179 | } else { |
| 1294 | | ide->status &= ~IDE_STATUS_DRIVE_READY; |
| 1180 | status &= ~IDE_STATUS_DRIVE_READY; |
| 1295 | 1181 | } |
| 1296 | 1182 | } |
| 1297 | 1183 | |
| r18713 | r18714 | |
| 1299 | 1185 | { |
| 1300 | 1186 | /* unknown config register */ |
| 1301 | 1187 | case IDE_BANK2_CONFIG_UNK: |
| 1302 | | return ide->config_unknown; |
| 1188 | return config_unknown; |
| 1303 | 1189 | |
| 1304 | 1190 | /* active config register */ |
| 1305 | 1191 | case IDE_BANK2_CONFIG_REGISTER: |
| 1306 | | return ide->config_register_num; |
| 1192 | return config_register_num; |
| 1307 | 1193 | |
| 1308 | 1194 | /* data from active config register */ |
| 1309 | 1195 | case IDE_BANK2_CONFIG_DATA: |
| 1310 | | if (ide->config_register_num < IDE_CONFIG_REGISTERS) |
| 1311 | | return ide->config_register[ide->config_register_num]; |
| 1196 | if (config_register_num < IDE_CONFIG_REGISTERS) |
| 1197 | return config_register[config_register_num]; |
| 1312 | 1198 | return 0; |
| 1313 | 1199 | |
| 1314 | 1200 | /* read data if there's data to be read */ |
| 1315 | 1201 | case IDE_BANK0_DATA: |
| 1316 | | if (ide->status & IDE_STATUS_BUFFER_READY) |
| 1202 | if (status & IDE_STATUS_BUFFER_READY) |
| 1317 | 1203 | { |
| 1318 | 1204 | /* fetch the correct amount of data */ |
| 1319 | | result = ide->buffer[ide->buffer_offset++]; |
| 1205 | result = buffer[buffer_offset++]; |
| 1320 | 1206 | if (size > 1) |
| 1321 | | result |= ide->buffer[ide->buffer_offset++] << 8; |
| 1207 | result |= buffer[buffer_offset++] << 8; |
| 1322 | 1208 | if (size > 2) |
| 1323 | 1209 | { |
| 1324 | | result |= ide->buffer[ide->buffer_offset++] << 16; |
| 1325 | | result |= ide->buffer[ide->buffer_offset++] << 24; |
| 1210 | result |= buffer[buffer_offset++] << 16; |
| 1211 | result |= buffer[buffer_offset++] << 24; |
| 1326 | 1212 | } |
| 1327 | 1213 | |
| 1328 | 1214 | /* if we're at the end of the buffer, handle it */ |
| 1329 | | if (ide->buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 1215 | if (buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 1330 | 1216 | { |
| 1331 | | LOG(("%s:IDE completed PIO read\n", device->machine().describe_context())); |
| 1332 | | continue_read(ide); |
| 1333 | | ide->error = IDE_ERROR_DEFAULT; |
| 1217 | LOG(("%s:IDE completed PIO read\n", machine().describe_context())); |
| 1218 | continue_read(); |
| 1219 | error = IDE_ERROR_DEFAULT; |
| 1334 | 1220 | } |
| 1335 | 1221 | } |
| 1336 | 1222 | break; |
| 1337 | 1223 | |
| 1338 | 1224 | /* return the current error */ |
| 1339 | 1225 | case IDE_BANK0_ERROR: |
| 1340 | | return ide->error; |
| 1226 | return error; |
| 1341 | 1227 | |
| 1342 | 1228 | /* return the current sector count */ |
| 1343 | 1229 | case IDE_BANK0_SECTOR_COUNT: |
| 1344 | | return ide->sector_count; |
| 1230 | return sector_count; |
| 1345 | 1231 | |
| 1346 | 1232 | /* return the current sector */ |
| 1347 | 1233 | case IDE_BANK0_SECTOR_NUMBER: |
| 1348 | | return ide->drive[ide->cur_drive].cur_sector; |
| 1234 | return drive[cur_drive].cur_sector; |
| 1349 | 1235 | |
| 1350 | 1236 | /* return the current cylinder LSB */ |
| 1351 | 1237 | case IDE_BANK0_CYLINDER_LSB: |
| 1352 | | return ide->drive[ide->cur_drive].cur_cylinder & 0xff; |
| 1238 | return drive[cur_drive].cur_cylinder & 0xff; |
| 1353 | 1239 | |
| 1354 | 1240 | /* return the current cylinder MSB */ |
| 1355 | 1241 | case IDE_BANK0_CYLINDER_MSB: |
| 1356 | | return ide->drive[ide->cur_drive].cur_cylinder >> 8; |
| 1242 | return drive[cur_drive].cur_cylinder >> 8; |
| 1357 | 1243 | |
| 1358 | 1244 | /* return the current head */ |
| 1359 | 1245 | case IDE_BANK0_HEAD_NUMBER: |
| 1360 | | return ide->drive[ide->cur_drive].cur_head_reg; |
| 1246 | return drive[cur_drive].cur_head_reg; |
| 1361 | 1247 | |
| 1362 | 1248 | /* return the current status and clear any pending interrupts */ |
| 1363 | 1249 | case IDE_BANK0_STATUS_COMMAND: |
| 1364 | 1250 | /* return the current status but don't clear interrupts */ |
| 1365 | 1251 | case IDE_BANK1_STATUS_CONTROL: |
| 1366 | | result = ide->status; |
| 1367 | | if (ide->last_status_timer->elapsed() > TIME_PER_ROTATION) |
| 1252 | result = status; |
| 1253 | if (last_status_timer->elapsed() > TIME_PER_ROTATION) |
| 1368 | 1254 | { |
| 1369 | 1255 | result |= IDE_STATUS_HIT_INDEX; |
| 1370 | | ide->last_status_timer->adjust(attotime::never); |
| 1256 | last_status_timer->adjust(attotime::never); |
| 1371 | 1257 | } |
| 1372 | 1258 | |
| 1373 | 1259 | /* clear interrutps only when reading the real status */ |
| 1374 | 1260 | if (BANK(bank, offset) == IDE_BANK0_STATUS_COMMAND) |
| 1375 | 1261 | { |
| 1376 | | if (ide->interrupt_pending) |
| 1377 | | clear_interrupt(ide); |
| 1262 | if (interrupt_pending) |
| 1263 | clear_interrupt(); |
| 1378 | 1264 | } |
| 1379 | 1265 | break; |
| 1380 | 1266 | |
| 1381 | 1267 | /* log anything else */ |
| 1382 | 1268 | default: |
| 1383 | | logerror("%s:unknown IDE read at %03X, size=%d\n", device->machine().describe_context(), offset, size); |
| 1269 | logerror("%s:unknown IDE read at %03X, size=%d\n", machine().describe_context(), offset, size); |
| 1384 | 1270 | break; |
| 1385 | 1271 | } |
| 1386 | 1272 | |
| r18713 | r18714 | |
| 1396 | 1282 | * |
| 1397 | 1283 | *************************************/ |
| 1398 | 1284 | |
| 1399 | | static void ide_controller_write(device_t *device, int bank, offs_t offset, int size, UINT32 data) |
| 1285 | void ide_controller_device::ide_controller_write(int bank, offs_t offset, int size, UINT32 data) |
| 1400 | 1286 | { |
| 1401 | | ide_state *ide = get_safe_token(device); |
| 1402 | | |
| 1403 | 1287 | /* logit */ |
| 1404 | 1288 | if (BANK(bank, offset) != IDE_BANK0_DATA) |
| 1405 | | LOG(("%s:IDE write to %d:%X = %08X, size=%d\n", device->machine().describe_context(), bank, offset, data, size)); |
| 1289 | LOG(("%s:IDE write to %d:%X = %08X, size=%d\n", machine().describe_context(), bank, offset, data, size)); |
| 1406 | 1290 | // fprintf(stderr, "ide write %03x %02x size=%d\n", offset, data, size); |
| 1407 | 1291 | switch (BANK(bank, offset)) |
| 1408 | 1292 | { |
| 1409 | 1293 | /* unknown config register */ |
| 1410 | 1294 | case IDE_BANK2_CONFIG_UNK: |
| 1411 | | ide->config_unknown = data; |
| 1295 | config_unknown = data; |
| 1412 | 1296 | break; |
| 1413 | 1297 | |
| 1414 | 1298 | /* active config register */ |
| 1415 | 1299 | case IDE_BANK2_CONFIG_REGISTER: |
| 1416 | | ide->config_register_num = data; |
| 1300 | config_register_num = data; |
| 1417 | 1301 | break; |
| 1418 | 1302 | |
| 1419 | 1303 | /* data from active config register */ |
| 1420 | 1304 | case IDE_BANK2_CONFIG_DATA: |
| 1421 | | if (ide->config_register_num < IDE_CONFIG_REGISTERS) |
| 1422 | | ide->config_register[ide->config_register_num] = data; |
| 1305 | if (config_register_num < IDE_CONFIG_REGISTERS) |
| 1306 | config_register[config_register_num] = data; |
| 1423 | 1307 | break; |
| 1424 | 1308 | |
| 1425 | 1309 | /* write data */ |
| 1426 | 1310 | case IDE_BANK0_DATA: |
| 1427 | | if (ide->status & IDE_STATUS_BUFFER_READY) |
| 1311 | if (status & IDE_STATUS_BUFFER_READY) |
| 1428 | 1312 | { |
| 1429 | 1313 | /* store the correct amount of data */ |
| 1430 | | ide->buffer[ide->buffer_offset++] = data; |
| 1314 | buffer[buffer_offset++] = data; |
| 1431 | 1315 | if (size > 1) |
| 1432 | | ide->buffer[ide->buffer_offset++] = data >> 8; |
| 1316 | buffer[buffer_offset++] = data >> 8; |
| 1433 | 1317 | if (size > 2) |
| 1434 | 1318 | { |
| 1435 | | ide->buffer[ide->buffer_offset++] = data >> 16; |
| 1436 | | ide->buffer[ide->buffer_offset++] = data >> 24; |
| 1319 | buffer[buffer_offset++] = data >> 16; |
| 1320 | buffer[buffer_offset++] = data >> 24; |
| 1437 | 1321 | } |
| 1438 | 1322 | |
| 1439 | 1323 | /* if we're at the end of the buffer, handle it */ |
| 1440 | | if (ide->buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 1324 | if (buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 1441 | 1325 | { |
| 1442 | | LOG(("%s:IDE completed PIO write\n", device->machine().describe_context())); |
| 1443 | | if (ide->command == IDE_COMMAND_SECURITY_UNLOCK) |
| 1326 | LOG(("%s:IDE completed PIO write\n", machine().describe_context())); |
| 1327 | if (command == IDE_COMMAND_SECURITY_UNLOCK) |
| 1444 | 1328 | { |
| 1445 | | if (ide->user_password_enable && memcmp(ide->buffer, ide->user_password, 2 + 32) == 0) |
| 1329 | if (user_password_enable && memcmp(buffer, user_password, 2 + 32) == 0) |
| 1446 | 1330 | { |
| 1447 | 1331 | LOGPRINT(("IDE Unlocked user password\n")); |
| 1448 | | ide->user_password_enable = 0; |
| 1332 | user_password_enable = 0; |
| 1449 | 1333 | } |
| 1450 | | if (ide->master_password_enable && memcmp(ide->buffer, ide->master_password, 2 + 32) == 0) |
| 1334 | if (master_password_enable && memcmp(buffer, master_password, 2 + 32) == 0) |
| 1451 | 1335 | { |
| 1452 | 1336 | LOGPRINT(("IDE Unlocked master password\n")); |
| 1453 | | ide->master_password_enable = 0; |
| 1337 | master_password_enable = 0; |
| 1454 | 1338 | } |
| 1455 | 1339 | if (PRINTF_IDE_PASSWORD) |
| 1456 | 1340 | { |
| r18713 | r18714 | |
| 1461 | 1345 | if (i % 8 == 2) |
| 1462 | 1346 | mame_printf_debug("\n"); |
| 1463 | 1347 | |
| 1464 | | mame_printf_debug("0x%02x, 0x%02x, ", ide->buffer[i], ide->buffer[i + 1]); |
| 1465 | | //mame_printf_debug("0x%02x%02x, ", ide->buffer[i], ide->buffer[i + 1]); |
| 1348 | mame_printf_debug("0x%02x, 0x%02x, ", buffer[i], buffer[i + 1]); |
| 1349 | //mame_printf_debug("0x%02x%02x, ", buffer[i], buffer[i + 1]); |
| 1466 | 1350 | } |
| 1467 | 1351 | mame_printf_debug("\n"); |
| 1468 | 1352 | } |
| 1469 | 1353 | |
| 1470 | 1354 | /* clear the busy and error flags */ |
| 1471 | | ide->status &= ~IDE_STATUS_ERROR; |
| 1472 | | ide->status &= ~IDE_STATUS_BUSY; |
| 1473 | | ide->status &= ~IDE_STATUS_BUFFER_READY; |
| 1355 | status &= ~IDE_STATUS_ERROR; |
| 1356 | status &= ~IDE_STATUS_BUSY; |
| 1357 | status &= ~IDE_STATUS_BUFFER_READY; |
| 1474 | 1358 | |
| 1475 | | if (ide->master_password_enable || ide->user_password_enable) |
| 1476 | | security_error(ide); |
| 1359 | if (master_password_enable || user_password_enable) |
| 1360 | security_error(); |
| 1477 | 1361 | else |
| 1478 | | ide->status |= IDE_STATUS_DRIVE_READY; |
| 1362 | status |= IDE_STATUS_DRIVE_READY; |
| 1479 | 1363 | } |
| 1480 | | else if (ide->command == IDE_COMMAND_TAITO_GNET_UNLOCK_2) |
| 1364 | else if (command == IDE_COMMAND_TAITO_GNET_UNLOCK_2) |
| 1481 | 1365 | { |
| 1482 | 1366 | UINT8 key[5] = { 0 }; |
| 1483 | 1367 | int i, bad = 0; |
| 1484 | | ide->drive[ide->cur_drive].slot->read_key(key); |
| 1368 | drive[cur_drive].slot->read_key(key); |
| 1485 | 1369 | |
| 1486 | 1370 | for (i=0; !bad && i<512; i++) |
| 1487 | | bad = ((i < 2 || i >= 7) && ide->buffer[i]) || ((i >= 2 && i < 7) && ide->buffer[i] != key[i-2]); |
| 1371 | bad = ((i < 2 || i >= 7) && buffer[i]) || ((i >= 2 && i < 7) && buffer[i] != key[i-2]); |
| 1488 | 1372 | |
| 1489 | | ide->status &= ~IDE_STATUS_BUSY; |
| 1490 | | ide->status &= ~IDE_STATUS_BUFFER_READY; |
| 1373 | status &= ~IDE_STATUS_BUSY; |
| 1374 | status &= ~IDE_STATUS_BUFFER_READY; |
| 1491 | 1375 | if (bad) |
| 1492 | | ide->status |= IDE_STATUS_ERROR; |
| 1376 | status |= IDE_STATUS_ERROR; |
| 1493 | 1377 | else { |
| 1494 | | ide->status &= ~IDE_STATUS_ERROR; |
| 1495 | | ide->gnetreadlock= 0; |
| 1378 | status &= ~IDE_STATUS_ERROR; |
| 1379 | gnetreadlock= 0; |
| 1496 | 1380 | } |
| 1497 | 1381 | } |
| 1498 | 1382 | else |
| 1499 | | continue_write(ide); |
| 1383 | continue_write(); |
| 1500 | 1384 | |
| 1501 | 1385 | } |
| 1502 | 1386 | } |
| r18713 | r18714 | |
| 1504 | 1388 | |
| 1505 | 1389 | /* precompensation offset?? */ |
| 1506 | 1390 | case IDE_BANK0_ERROR: |
| 1507 | | ide->precomp_offset = data; |
| 1391 | precomp_offset = data; |
| 1508 | 1392 | break; |
| 1509 | 1393 | |
| 1510 | 1394 | /* sector count */ |
| 1511 | 1395 | case IDE_BANK0_SECTOR_COUNT: |
| 1512 | | ide->sector_count = data ? data : 256; |
| 1396 | sector_count = data ? data : 256; |
| 1513 | 1397 | break; |
| 1514 | 1398 | |
| 1515 | 1399 | /* current sector */ |
| 1516 | 1400 | case IDE_BANK0_SECTOR_NUMBER: |
| 1517 | | ide->drive[ide->cur_drive].cur_sector = data; |
| 1401 | drive[cur_drive].cur_sector = data; |
| 1518 | 1402 | break; |
| 1519 | 1403 | |
| 1520 | 1404 | /* current cylinder LSB */ |
| 1521 | 1405 | case IDE_BANK0_CYLINDER_LSB: |
| 1522 | | ide->drive[ide->cur_drive].cur_cylinder = (ide->drive[ide->cur_drive].cur_cylinder & 0xff00) | (data & 0xff); |
| 1406 | drive[cur_drive].cur_cylinder = (drive[cur_drive].cur_cylinder & 0xff00) | (data & 0xff); |
| 1523 | 1407 | break; |
| 1524 | 1408 | |
| 1525 | 1409 | /* current cylinder MSB */ |
| 1526 | 1410 | case IDE_BANK0_CYLINDER_MSB: |
| 1527 | | ide->drive[ide->cur_drive].cur_cylinder = (ide->drive[ide->cur_drive].cur_cylinder & 0x00ff) | ((data & 0xff) << 8); |
| 1411 | drive[cur_drive].cur_cylinder = (drive[cur_drive].cur_cylinder & 0x00ff) | ((data & 0xff) << 8); |
| 1528 | 1412 | break; |
| 1529 | 1413 | |
| 1530 | 1414 | /* current head */ |
| 1531 | 1415 | case IDE_BANK0_HEAD_NUMBER: |
| 1532 | | ide->cur_drive = (data & 0x10) >> 4; |
| 1533 | | ide->drive[ide->cur_drive].cur_head = data & 0x0f; |
| 1534 | | ide->drive[ide->cur_drive].cur_head_reg = data; |
| 1416 | cur_drive = (data & 0x10) >> 4; |
| 1417 | drive[cur_drive].cur_head = data & 0x0f; |
| 1418 | drive[cur_drive].cur_head_reg = data; |
| 1535 | 1419 | // LBA mode = data & 0x40 |
| 1536 | 1420 | break; |
| 1537 | 1421 | |
| 1538 | 1422 | /* command */ |
| 1539 | 1423 | case IDE_BANK0_STATUS_COMMAND: |
| 1540 | | handle_command(ide, data); |
| 1424 | handle_command(data); |
| 1541 | 1425 | break; |
| 1542 | 1426 | |
| 1543 | 1427 | /* adapter control */ |
| 1544 | 1428 | case IDE_BANK1_STATUS_CONTROL: |
| 1545 | | ide->adapter_control = data; |
| 1429 | adapter_control = data; |
| 1546 | 1430 | |
| 1547 | 1431 | /* handle controller reset */ |
| 1548 | 1432 | //if (data == 0x04) |
| 1549 | 1433 | if (data & 0x04) |
| 1550 | 1434 | { |
| 1551 | | ide->status |= IDE_STATUS_BUSY; |
| 1552 | | ide->status &= ~IDE_STATUS_DRIVE_READY; |
| 1553 | | ide->reset_timer->adjust(attotime::from_msec(5)); |
| 1435 | status |= IDE_STATUS_BUSY; |
| 1436 | status &= ~IDE_STATUS_DRIVE_READY; |
| 1437 | reset_timer->adjust(attotime::from_msec(5)); |
| 1554 | 1438 | } |
| 1555 | 1439 | break; |
| 1556 | 1440 | } |
| r18713 | r18714 | |
| 1564 | 1448 | * |
| 1565 | 1449 | *************************************/ |
| 1566 | 1450 | |
| 1567 | | static UINT32 ide_bus_master_read(device_t *device, offs_t offset, int size) |
| 1451 | UINT32 ide_controller_device::ide_bus_master_read(offs_t offset, int size) |
| 1568 | 1452 | { |
| 1569 | | ide_state *ide = get_safe_token(device); |
| 1453 | LOG(("%s:ide_bus_master_read(%d, %d)\n", machine().describe_context(), offset, size)); |
| 1570 | 1454 | |
| 1571 | | LOG(("%s:ide_bus_master_read(%d, %d)\n", device->machine().describe_context(), offset, size)); |
| 1572 | | |
| 1573 | 1455 | /* command register */ |
| 1574 | 1456 | if (offset == 0) |
| 1575 | | return ide->bus_master_command | (ide->bus_master_status << 16); |
| 1457 | return bus_master_command | (bus_master_status << 16); |
| 1576 | 1458 | |
| 1577 | 1459 | /* status register */ |
| 1578 | 1460 | if (offset == 2) |
| 1579 | | return ide->bus_master_status; |
| 1461 | return bus_master_status; |
| 1580 | 1462 | |
| 1581 | 1463 | /* descriptor table register */ |
| 1582 | 1464 | if (offset == 4) |
| 1583 | | return ide->bus_master_descriptor; |
| 1465 | return bus_master_descriptor; |
| 1584 | 1466 | |
| 1585 | 1467 | return 0xffffffff; |
| 1586 | 1468 | } |
| r18713 | r18714 | |
| 1593 | 1475 | * |
| 1594 | 1476 | *************************************/ |
| 1595 | 1477 | |
| 1596 | | static void ide_bus_master_write(device_t *device, offs_t offset, int size, UINT32 data) |
| 1478 | void ide_controller_device::ide_bus_master_write(offs_t offset, int size, UINT32 data) |
| 1597 | 1479 | { |
| 1598 | | ide_state *ide = get_safe_token(device); |
| 1480 | LOG(("%s:ide_bus_master_write(%d, %d, %08X)\n", machine().describe_context(), offset, size, data)); |
| 1599 | 1481 | |
| 1600 | | LOG(("%s:ide_bus_master_write(%d, %d, %08X)\n", device->machine().describe_context(), offset, size, data)); |
| 1601 | | |
| 1602 | 1482 | /* command register */ |
| 1603 | 1483 | if (offset == 0) |
| 1604 | 1484 | { |
| 1605 | | UINT8 old = ide->bus_master_command; |
| 1485 | UINT8 old = bus_master_command; |
| 1606 | 1486 | UINT8 val = data & 0xff; |
| 1607 | 1487 | |
| 1608 | 1488 | /* save the read/write bit and the start/stop bit */ |
| 1609 | | ide->bus_master_command = (old & 0xf6) | (val & 0x09); |
| 1610 | | ide->bus_master_status = (ide->bus_master_status & ~IDE_BUSMASTER_STATUS_ACTIVE) | (val & 0x01); |
| 1489 | bus_master_command = (old & 0xf6) | (val & 0x09); |
| 1490 | bus_master_status = (bus_master_status & ~IDE_BUSMASTER_STATUS_ACTIVE) | (val & 0x01); |
| 1611 | 1491 | |
| 1612 | 1492 | /* handle starting a transfer */ |
| 1613 | 1493 | if (!(old & 1) && (val & 1)) |
| 1614 | 1494 | { |
| 1615 | 1495 | /* reset all the DMA data */ |
| 1616 | | ide->dma_bytes_left = 0; |
| 1617 | | ide->dma_last_buffer = 0; |
| 1618 | | ide->dma_descriptor = ide->bus_master_descriptor; |
| 1496 | dma_bytes_left = 0; |
| 1497 | dma_last_buffer = 0; |
| 1498 | dma_descriptor = bus_master_descriptor; |
| 1619 | 1499 | |
| 1620 | 1500 | /* if we're going live, start the pending read/write */ |
| 1621 | | if (ide->dma_active) |
| 1501 | if (dma_active) |
| 1622 | 1502 | { |
| 1623 | | if (ide->bus_master_command & 8) |
| 1624 | | read_next_sector(ide); |
| 1503 | if (bus_master_command & 8) |
| 1504 | read_next_sector(); |
| 1625 | 1505 | else |
| 1626 | 1506 | { |
| 1627 | | read_buffer_from_dma(ide); |
| 1628 | | continue_write(ide); |
| 1507 | read_buffer_from_dma(); |
| 1508 | continue_write(); |
| 1629 | 1509 | } |
| 1630 | 1510 | } |
| 1631 | 1511 | } |
| r18713 | r18714 | |
| 1634 | 1514 | /* status register */ |
| 1635 | 1515 | if (offset <= 2 && offset + size > 2) |
| 1636 | 1516 | { |
| 1637 | | UINT8 old = ide->bus_master_status; |
| 1517 | UINT8 old = bus_master_status; |
| 1638 | 1518 | UINT8 val = data >> (8 * (2 - offset)); |
| 1639 | 1519 | |
| 1640 | 1520 | /* save the DMA capable bits */ |
| 1641 | | ide->bus_master_status = (old & 0x9f) | (val & 0x60); |
| 1521 | bus_master_status = (old & 0x9f) | (val & 0x60); |
| 1642 | 1522 | |
| 1643 | 1523 | /* clear interrupt and error bits */ |
| 1644 | 1524 | if (val & IDE_BUSMASTER_STATUS_IRQ) |
| 1645 | | ide->bus_master_status &= ~IDE_BUSMASTER_STATUS_IRQ; |
| 1525 | bus_master_status &= ~IDE_BUSMASTER_STATUS_IRQ; |
| 1646 | 1526 | if (val & IDE_BUSMASTER_STATUS_ERROR) |
| 1647 | | ide->bus_master_status &= ~IDE_BUSMASTER_STATUS_ERROR; |
| 1527 | bus_master_status &= ~IDE_BUSMASTER_STATUS_ERROR; |
| 1648 | 1528 | } |
| 1649 | 1529 | |
| 1650 | 1530 | /* descriptor table register */ |
| 1651 | 1531 | if (offset == 4) |
| 1652 | | ide->bus_master_descriptor = data & 0xfffffffc; |
| 1532 | bus_master_descriptor = data & 0xfffffffc; |
| 1653 | 1533 | } |
| 1654 | 1534 | |
| 1655 | 1535 | |
| r18713 | r18714 | |
| 1670 | 1550 | */ |
| 1671 | 1551 | int ide_bus_r(device_t *device, int select, int offset) |
| 1672 | 1552 | { |
| 1673 | | return ide_controller_read(device, select ? 1 : 0, offset, select == 0 && offset == 0 ? 2 : 1); |
| 1553 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1554 | return ide->ide_controller_read(select ? 1 : 0, offset, select == 0 && offset == 0 ? 2 : 1); |
| 1674 | 1555 | } |
| 1675 | 1556 | |
| 1676 | 1557 | /* |
| r18713 | r18714 | |
| 1684 | 1565 | */ |
| 1685 | 1566 | void ide_bus_w(device_t *device, int select, int offset, int data) |
| 1686 | 1567 | { |
| 1568 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1687 | 1569 | if (select == 0 && offset == 0) |
| 1688 | | ide_controller_write(device, 0, 0, 2, data); |
| 1570 | ide->ide_controller_write(0, 0, 2, data); |
| 1689 | 1571 | else |
| 1690 | | ide_controller_write(device, select ? 1 : 0, offset, 1, data & 0xff); |
| 1572 | ide->ide_controller_write(select ? 1 : 0, offset, 1, data & 0xff); |
| 1691 | 1573 | } |
| 1692 | 1574 | |
| 1693 | 1575 | UINT32 ide_controller_r(device_t *device, int reg, int size) |
| 1694 | 1576 | { |
| 1577 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1695 | 1578 | if (reg >= 0x1f0 && reg < 0x1f8) |
| 1696 | | return ide_controller_read(device, 0, reg & 7, size); |
| 1579 | return ide->ide_controller_read(0, reg & 7, size); |
| 1697 | 1580 | if (reg >= 0x3f0 && reg < 0x3f8) |
| 1698 | | return ide_controller_read(device, 1, reg & 7, size); |
| 1581 | return ide->ide_controller_read(1, reg & 7, size); |
| 1699 | 1582 | if (reg >= 0x030 && reg < 0x040) |
| 1700 | | return ide_controller_read(device, 2, reg & 0xf, size); |
| 1583 | return ide->ide_controller_read(2, reg & 0xf, size); |
| 1701 | 1584 | return 0xffffffff; |
| 1702 | 1585 | } |
| 1703 | 1586 | |
| 1704 | 1587 | void ide_controller_w(device_t *device, int reg, int size, UINT32 data) |
| 1705 | 1588 | { |
| 1589 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1706 | 1590 | if (reg >= 0x1f0 && reg < 0x1f8) |
| 1707 | | ide_controller_write(device, 0, reg & 7, size, data); |
| 1591 | ide->ide_controller_write(0, reg & 7, size, data); |
| 1708 | 1592 | if (reg >= 0x3f0 && reg < 0x3f8) |
| 1709 | | ide_controller_write(device, 1, reg & 7, size, data); |
| 1593 | ide->ide_controller_write(1, reg & 7, size, data); |
| 1710 | 1594 | if (reg >= 0x030 && reg < 0x040) |
| 1711 | | ide_controller_write(device, 2, reg & 0xf, size, data); |
| 1595 | ide->ide_controller_write(2, reg & 0xf, size, data); |
| 1712 | 1596 | } |
| 1713 | 1597 | |
| 1714 | 1598 | |
| r18713 | r18714 | |
| 1743 | 1627 | |
| 1744 | 1628 | READ32_DEVICE_HANDLER( ide_controller32_pcmcia_r ) |
| 1745 | 1629 | { |
| 1630 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1631 | |
| 1746 | 1632 | int size; |
| 1747 | 1633 | UINT32 res = 0xffffffff; |
| 1748 | 1634 | |
| r18713 | r18714 | |
| 1750 | 1636 | size = convert_to_offset_and_size32(&offset, mem_mask); |
| 1751 | 1637 | |
| 1752 | 1638 | if (offset < 0x008) |
| 1753 | | res = ide_controller_read(device, 0, offset & 7, size); |
| 1639 | res = ide->ide_controller_read(0, offset & 7, size); |
| 1754 | 1640 | if (offset >= 0x008 && offset < 0x010) |
| 1755 | | res = ide_controller_read(device, 1, offset & 7, size); |
| 1641 | res = ide->ide_controller_read(1, offset & 7, size); |
| 1756 | 1642 | |
| 1757 | 1643 | return res << ((offset & 3) * 8); |
| 1758 | 1644 | } |
| r18713 | r18714 | |
| 1762 | 1648 | { |
| 1763 | 1649 | int size; |
| 1764 | 1650 | |
| 1651 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1652 | |
| 1765 | 1653 | offset *= 4; |
| 1766 | 1654 | size = convert_to_offset_and_size32(&offset, mem_mask); |
| 1767 | 1655 | data = data >> ((offset & 3) * 8); |
| 1768 | 1656 | |
| 1769 | 1657 | if (offset < 0x008) |
| 1770 | | ide_controller_write(device, 0, offset & 7, size, data); |
| 1658 | ide->ide_controller_write(0, offset & 7, size, data); |
| 1771 | 1659 | if (offset >= 0x008 && offset < 0x010) |
| 1772 | | ide_controller_write(device, 1, offset & 7, size, data); |
| 1660 | ide->ide_controller_write(1, offset & 7, size, data); |
| 1773 | 1661 | } |
| 1774 | 1662 | |
| 1775 | 1663 | READ32_DEVICE_HANDLER( ide_bus_master32_r ) |
| 1776 | 1664 | { |
| 1777 | 1665 | int size; |
| 1778 | 1666 | |
| 1667 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1668 | |
| 1779 | 1669 | offset *= 4; |
| 1780 | 1670 | size = convert_to_offset_and_size32(&offset, mem_mask); |
| 1781 | 1671 | |
| 1782 | | return ide_bus_master_read(device, offset, size) << ((offset & 3) * 8); |
| 1672 | return ide->ide_bus_master_read(offset, size) << ((offset & 3) * 8); |
| 1783 | 1673 | } |
| 1784 | 1674 | |
| 1785 | 1675 | |
| r18713 | r18714 | |
| 1787 | 1677 | { |
| 1788 | 1678 | int size; |
| 1789 | 1679 | |
| 1680 | ide_controller_device *ide = (ide_controller_device *) device; |
| 1681 | |
| 1790 | 1682 | offset *= 4; |
| 1791 | 1683 | size = convert_to_offset_and_size32(&offset, mem_mask); |
| 1792 | 1684 | |
| 1793 | | ide_bus_master_write(device, offset, size, data >> ((offset & 3) * 8)); |
| 1685 | ide->ide_bus_master_write(offset, size, data >> ((offset & 3) * 8)); |
| 1794 | 1686 | } |
| 1795 | 1687 | |
| 1796 | 1688 | |
| r18713 | r18714 | |
| 1822 | 1714 | ide_controller_w(device, offset, size, data >> ((offset & 1) * 8)); |
| 1823 | 1715 | } |
| 1824 | 1716 | |
| 1717 | SLOT_INTERFACE_START(ide_image_devices) |
| 1718 | SLOT_INTERFACE("hdd", IDE_HARDDISK_IMAGE) |
| 1719 | SLOT_INTERFACE_END |
| 1825 | 1720 | |
| 1721 | SLOT_INTERFACE_START(ide_devices) |
| 1722 | SLOT_INTERFACE("hdd", IDE_HARDDISK) |
| 1723 | SLOT_INTERFACE_END |
| 1826 | 1724 | |
| 1827 | | /*************************************************************************** |
| 1828 | | DEVICE INTERFACE |
| 1829 | | ***************************************************************************/ |
| 1725 | const device_type IDE_CONTROLLER = &device_creator<ide_controller_device>; |
| 1830 | 1726 | |
| 1831 | | /*------------------------------------------------- |
| 1832 | | device start callback |
| 1833 | | -------------------------------------------------*/ |
| 1834 | | |
| 1835 | | static DEVICE_START( ide_controller ) |
| 1727 | ide_controller_device::ide_controller_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 1728 | device_t(mconfig, IDE_CONTROLLER, "IDE Controller", tag, owner, clock), |
| 1729 | master_password(NULL), |
| 1730 | user_password(NULL), |
| 1731 | m_irq_handler(*this), |
| 1732 | bmcpu(NULL), |
| 1733 | bmspace(0) |
| 1836 | 1734 | { |
| 1837 | | ide_state *ide = get_safe_token(device); |
| 1838 | | const ide_config *config; |
| 1735 | } |
| 1839 | 1736 | |
| 1840 | | /* validate some basic stuff */ |
| 1841 | | assert(device != NULL); |
| 1842 | | assert(device->static_config() != NULL); |
| 1737 | //------------------------------------------------- |
| 1738 | // device_start - device-specific startup |
| 1739 | //------------------------------------------------- |
| 1843 | 1740 | |
| 1844 | | /* store a pointer back to the device */ |
| 1845 | | ide->device = device; |
| 1741 | void ide_controller_device::device_start() |
| 1742 | { |
| 1743 | m_irq_handler.resolve_safe(); |
| 1846 | 1744 | |
| 1847 | 1745 | /* set MAME harddisk handle */ |
| 1848 | | config = (const ide_config *)device->static_config(); |
| 1746 | drive[0].slot = owner()->subdevice<ide_slot_device>("drive_0"); |
| 1747 | drive[1].slot = owner()->subdevice<ide_slot_device>("drive_1"); |
| 1849 | 1748 | |
| 1850 | | ide->drive[0].slot = device->owner()->subdevice<ide_slot_device>("drive_0"); |
| 1851 | | ide->drive[1].slot = device->owner()->subdevice<ide_slot_device>("drive_1"); |
| 1852 | | |
| 1853 | 1749 | /* find the bus master space */ |
| 1854 | | if (config->bmcpu != NULL) |
| 1750 | if (bmcpu != NULL) |
| 1855 | 1751 | { |
| 1856 | | device_t *bmtarget = device->machine().device(config->bmcpu); |
| 1752 | device_t *bmtarget = machine().device(bmcpu); |
| 1857 | 1753 | if (bmtarget == NULL) |
| 1858 | | throw emu_fatalerror("IDE controller '%s' bus master target '%s' doesn't exist!", device->tag(), config->bmcpu); |
| 1754 | throw emu_fatalerror("IDE controller '%s' bus master target '%s' doesn't exist!", tag(), bmcpu); |
| 1859 | 1755 | device_memory_interface *memory; |
| 1860 | 1756 | if (!bmtarget->interface(memory)) |
| 1861 | | throw emu_fatalerror("IDE controller '%s' bus master target '%s' has no memory!", device->tag(), config->bmcpu); |
| 1862 | | ide->dma_space = &memory->space(config->bmspace); |
| 1863 | | ide->dma_address_xor = (ide->dma_space->endianness() == ENDIANNESS_LITTLE) ? 0 : 3; |
| 1757 | throw emu_fatalerror("IDE controller '%s' bus master target '%s' has no memory!", tag(), bmcpu); |
| 1758 | dma_space = &memory->space(bmspace); |
| 1759 | dma_address_xor = (dma_space->endianness() == ENDIANNESS_LITTLE) ? 0 : 3; |
| 1864 | 1760 | } |
| 1865 | 1761 | |
| 1866 | 1762 | /* create a timer for timing status */ |
| 1867 | | ide->last_status_timer = device->machine().scheduler().timer_alloc(FUNC_NULL); |
| 1868 | | ide->reset_timer = device->machine().scheduler().timer_alloc(FUNC(reset_callback), (void *)device); |
| 1763 | last_status_timer = machine().scheduler().timer_alloc(FUNC_NULL); |
| 1764 | reset_timer = machine().scheduler().timer_alloc(FUNC(reset_callback), this); |
| 1869 | 1765 | |
| 1870 | 1766 | /* register ide states */ |
| 1871 | | device->save_item(NAME(ide->adapter_control)); |
| 1872 | | device->save_item(NAME(ide->status)); |
| 1873 | | device->save_item(NAME(ide->error)); |
| 1874 | | device->save_item(NAME(ide->command)); |
| 1875 | | device->save_item(NAME(ide->interrupt_pending)); |
| 1876 | | device->save_item(NAME(ide->precomp_offset)); |
| 1767 | save_item(NAME(adapter_control)); |
| 1768 | save_item(NAME(status)); |
| 1769 | save_item(NAME(error)); |
| 1770 | save_item(NAME(command)); |
| 1771 | save_item(NAME(interrupt_pending)); |
| 1772 | save_item(NAME(precomp_offset)); |
| 1877 | 1773 | |
| 1878 | | device->save_item(NAME(ide->buffer)); |
| 1879 | | //device->save_item(NAME(ide->features)); |
| 1880 | | device->save_item(NAME(ide->buffer_offset)); |
| 1881 | | device->save_item(NAME(ide->sector_count)); |
| 1774 | save_item(NAME(buffer)); |
| 1775 | //save_item(NAME(features)); |
| 1776 | save_item(NAME(buffer_offset)); |
| 1777 | save_item(NAME(sector_count)); |
| 1882 | 1778 | |
| 1883 | | device->save_item(NAME(ide->block_count)); |
| 1884 | | device->save_item(NAME(ide->sectors_until_int)); |
| 1779 | save_item(NAME(block_count)); |
| 1780 | save_item(NAME(sectors_until_int)); |
| 1885 | 1781 | |
| 1886 | | device->save_item(NAME(ide->dma_active)); |
| 1887 | | device->save_item(NAME(ide->dma_last_buffer)); |
| 1888 | | device->save_item(NAME(ide->dma_address)); |
| 1889 | | device->save_item(NAME(ide->dma_descriptor)); |
| 1890 | | device->save_item(NAME(ide->dma_bytes_left)); |
| 1782 | save_item(NAME(dma_active)); |
| 1783 | save_item(NAME(dma_last_buffer)); |
| 1784 | save_item(NAME(dma_address)); |
| 1785 | save_item(NAME(dma_descriptor)); |
| 1786 | save_item(NAME(dma_bytes_left)); |
| 1891 | 1787 | |
| 1892 | | device->save_item(NAME(ide->bus_master_command)); |
| 1893 | | device->save_item(NAME(ide->bus_master_status)); |
| 1894 | | device->save_item(NAME(ide->bus_master_descriptor)); |
| 1788 | save_item(NAME(bus_master_command)); |
| 1789 | save_item(NAME(bus_master_status)); |
| 1790 | save_item(NAME(bus_master_descriptor)); |
| 1895 | 1791 | |
| 1896 | | //device->save_item(NAME(ide->cur_cylinder)); |
| 1897 | | //device->save_item(NAME(ide->cur_sector)); |
| 1898 | | //device->save_item(NAME(ide->cur_head)); |
| 1899 | | //device->save_item(NAME(ide->cur_head_reg)); |
| 1792 | //save_item(NAME(cur_cylinder)); |
| 1793 | //save_item(NAME(cur_sector)); |
| 1794 | //save_item(NAME(cur_head)); |
| 1795 | //save_item(NAME(cur_head_reg)); |
| 1900 | 1796 | |
| 1901 | | //device->save_item(NAME(ide->cur_lba)); |
| 1797 | //save_item(NAME(cur_lba)); |
| 1902 | 1798 | |
| 1903 | | //device->save_item(NAME(ide->num_cylinders)); |
| 1904 | | //device->save_item(NAME(ide->num_sectors)); |
| 1905 | | //device->save_item(NAME(ide->num_heads)); |
| 1799 | //save_item(NAME(num_cylinders)); |
| 1800 | //save_item(NAME(num_sectors)); |
| 1801 | //save_item(NAME(num_heads)); |
| 1906 | 1802 | |
| 1907 | | device->save_item(NAME(ide->config_unknown)); |
| 1908 | | device->save_item(NAME(ide->config_register)); |
| 1909 | | device->save_item(NAME(ide->config_register_num)); |
| 1803 | save_item(NAME(config_unknown)); |
| 1804 | save_item(NAME(config_register)); |
| 1805 | save_item(NAME(config_register_num)); |
| 1910 | 1806 | |
| 1911 | | device->save_item(NAME(ide->master_password_enable)); |
| 1912 | | device->save_item(NAME(ide->user_password_enable)); |
| 1807 | save_item(NAME(master_password_enable)); |
| 1808 | save_item(NAME(user_password_enable)); |
| 1913 | 1809 | |
| 1914 | | device->save_item(NAME(ide->gnetreadlock)); |
| 1810 | save_item(NAME(gnetreadlock)); |
| 1915 | 1811 | } |
| 1916 | 1812 | |
| 1917 | | /*------------------------------------------------- |
| 1918 | | device reset callback |
| 1919 | | -------------------------------------------------*/ |
| 1920 | | |
| 1921 | | static DEVICE_RESET( ide_controller ) |
| 1922 | | { |
| 1923 | | ide_state *ide = get_safe_token(device); |
| 1924 | | LOG(("IDE controller reset performed\n")); |
| 1925 | | /* reset the drive state */ |
| 1926 | | ide->cur_drive = 0; |
| 1927 | | ide->status = IDE_STATUS_DRIVE_READY | IDE_STATUS_SEEK_COMPLETE; |
| 1928 | | ide->error = IDE_ERROR_DEFAULT; |
| 1929 | | ide->buffer_offset = 0; |
| 1930 | | ide->gnetreadlock = 0; |
| 1931 | | ide->master_password_enable = (ide->master_password != NULL); |
| 1932 | | ide->user_password_enable = (ide->user_password != NULL); |
| 1933 | | clear_interrupt(ide); |
| 1934 | | } |
| 1935 | | |
| 1936 | | SLOT_INTERFACE_START(ide_image_devices) |
| 1937 | | SLOT_INTERFACE("hdd", IDE_HARDDISK_IMAGE) |
| 1938 | | SLOT_INTERFACE_END |
| 1939 | | |
| 1940 | | SLOT_INTERFACE_START(ide_devices) |
| 1941 | | SLOT_INTERFACE("hdd", IDE_HARDDISK) |
| 1942 | | SLOT_INTERFACE_END |
| 1943 | | |
| 1944 | | const device_type IDE_CONTROLLER = &device_creator<ide_controller_device>; |
| 1945 | | |
| 1946 | | ide_controller_device::ide_controller_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 1947 | | : device_t(mconfig, IDE_CONTROLLER, "IDE Controller", tag, owner, clock) |
| 1948 | | { |
| 1949 | | m_token = global_alloc_clear(ide_state); |
| 1950 | | } |
| 1951 | | |
| 1952 | 1813 | //------------------------------------------------- |
| 1953 | | // device_config_complete - perform any |
| 1954 | | // operations now that the configuration is |
| 1955 | | // complete |
| 1956 | | //------------------------------------------------- |
| 1957 | | |
| 1958 | | void ide_controller_device::device_config_complete() |
| 1959 | | { |
| 1960 | | } |
| 1961 | | |
| 1962 | | //------------------------------------------------- |
| 1963 | | // device_start - device-specific startup |
| 1964 | | //------------------------------------------------- |
| 1965 | | |
| 1966 | | void ide_controller_device::device_start() |
| 1967 | | { |
| 1968 | | DEVICE_START_NAME( ide_controller )(this); |
| 1969 | | } |
| 1970 | | |
| 1971 | | //------------------------------------------------- |
| 1972 | 1814 | // device_reset - device-specific reset |
| 1973 | 1815 | //------------------------------------------------- |
| 1974 | 1816 | |
| 1975 | 1817 | void ide_controller_device::device_reset() |
| 1976 | 1818 | { |
| 1977 | | DEVICE_RESET_NAME( ide_controller )(this); |
| 1819 | LOG(("IDE controller reset performed\n")); |
| 1820 | /* reset the drive state */ |
| 1821 | cur_drive = 0; |
| 1822 | status = IDE_STATUS_DRIVE_READY | IDE_STATUS_SEEK_COMPLETE; |
| 1823 | error = IDE_ERROR_DEFAULT; |
| 1824 | buffer_offset = 0; |
| 1825 | gnetreadlock = 0; |
| 1826 | master_password_enable = (master_password != NULL); |
| 1827 | user_password_enable = (user_password != NULL); |
| 1828 | clear_interrupt(); |
| 1978 | 1829 | } |
| 1979 | 1830 | |
| 1980 | 1831 | |