| Previous | 199869 Revisions | Next |
| r31206 Sunday 6th July, 2014 at 19:44:19 UTC by Mike Naberezny |
|---|
| (MESS) corvushd: Use Corvus drive id numbers throughout. (nw) Using the Corvus id number consistently throughout makes it easier to reason about this code. Previously, some functions used a 0-based drive index (0..14) and others used the 1-based Corvus id number (1..15). The only place we actually need it to be 0-based is in corvus_hdc_file(), so now we just convert it there instead of in several places. |
| [src/emu/machine] | corvushd.c |
| r31205 | r31206 | |
|---|---|---|
| 255 | 255 | // Write a variably-sized chunk of data to the CHD file |
| 256 | 256 | // |
| 257 | 257 | // Pass: |
| 258 | // drv: | |
| 258 | // drv: Corvus drive id (1..15) | |
| 259 | 259 | // sector: Physical sector number to write to |
| 260 | 260 | // buffer: Buffer to write |
| 261 | 261 | // len: Length of the buffer (amount of data to write) |
| r31205 | r31206 | |
| 323 | 323 | // |
| 324 | 324 | UINT8 corvus_hdc_t::corvus_write_logical_sector(dadr_t *dadr, UINT8 *buffer, int len) { |
| 325 | 325 | UINT8 status; // Status returned from Physical Sector read |
| 326 | UINT8 drv; // | |
| 326 | UINT8 drv; // Corvus drive id (1..15) | |
| 327 | 327 | UINT32 sector; // Sector number on drive |
| 328 | 328 | |
| 329 | 329 | // |
| r31205 | r31206 | |
| 334 | 334 | // |
| 335 | 335 | // For example: 0x23 would decode to Drive ID #3, high-order nibble: 0x02. |
| 336 | 336 | // |
| 337 | drv = (dadr->address_msn_and_drive & 0x0f) | |
| 337 | drv = (dadr->address_msn_and_drive & 0x0f); | |
| 338 | 338 | sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb; |
| 339 | 339 | |
| 340 | 340 | LOG(("corvus_write_logical_sector: Writing based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n", |
| 341 | 341 | dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv)); |
| 342 | 342 | |
| 343 | // Set | |
| 343 | // Set m_tracks_per_cylinder and m_sectors_per_track | |
| 344 | 344 | corvus_hdc_file(drv); |
| 345 | 345 | |
| 346 | 346 | // |
| r31205 | r31206 | |
| 363 | 363 | // Read a variably-sized chunk of data from the CHD file |
| 364 | 364 | // |
| 365 | 365 | // Pass: |
| 366 | // drv: | |
| 366 | // drv: Corvus drive id (1..15) | |
| 367 | 367 | // sector: Physical sector number to read from |
| 368 | 368 | // buffer: Buffer to hold the data read from the disk |
| 369 | 369 | // len: Length of the buffer |
| r31205 | r31206 | |
| 420 | 420 | // |
| 421 | 421 | UINT8 corvus_hdc_t::corvus_read_logical_sector(dadr_t *dadr, UINT8 *buffer, int len) { |
| 422 | 422 | UINT8 status; // Status returned from Physical Sector read |
| 423 | UINT8 drv; // | |
| 423 | UINT8 drv; // Corvus drive id (1..15) | |
| 424 | 424 | UINT32 sector; // Sector number on drive |
| 425 | 425 | |
| 426 | 426 | // |
| r31205 | r31206 | |
| 431 | 431 | // |
| 432 | 432 | // For example: 0x23 would decode to Drive ID #3, high-order nibble: 0x02. |
| 433 | 433 | // |
| 434 | drv = (dadr->address_msn_and_drive & 0x0f) | |
| 434 | drv = (dadr->address_msn_and_drive & 0x0f); | |
| 435 | 435 | sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb; |
| 436 | 436 | |
| 437 | 437 | LOG(("corvus_read_logical_sector: Reading based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n", |
| 438 | 438 | dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv)); |
| 439 | 439 | |
| 440 | // Set up | |
| 440 | // Set up m_tracks_per_cylinder and m_sectors_per_track | |
| 441 | 441 | corvus_hdc_file(drv); |
| 442 | 442 | |
| 443 | 443 | // |
| r31205 | r31206 | |
| 480 | 480 | // |
| 481 | 481 | // Read the semaphore table from the drive |
| 482 | 482 | // |
| 483 | status = corvus_read_sector( | |
| 483 | status = corvus_read_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256); | |
| 484 | 484 | if(status != STAT_SUCCESS) { |
| 485 | 485 | logerror("corvus_lock_semaphore: Error reading semaphore table, status: 0x%2.2x\n", status); |
| 486 | 486 | m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR; |
| r31205 | r31206 | |
| 514 | 514 | } else { |
| 515 | 515 | m_buffer.semaphore_locking_response.result = SEM_PRIOR_STATE_NOT_SET; // It wasn't there already |
| 516 | 516 | memcpy(&semaphore_table.semaphore_block.semaphore_entry[blank_offset], name, 8);// Stick it into the table |
| 517 | status = corvus_write_sector( | |
| 517 | status = corvus_write_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256); | |
| 518 | 518 | if(status != STAT_SUCCESS) { |
| 519 | 519 | logerror("corvus_lock_semaphore: Error updating semaphore table, status: 0x%2.2x\n", status); |
| 520 | 520 | m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR; |
| r31205 | r31206 | |
| 554 | 554 | // |
| 555 | 555 | // Read the semaphore table from the drive |
| 556 | 556 | // |
| 557 | status = corvus_read_sector( | |
| 557 | status = corvus_read_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256); | |
| 558 | 558 | if(status != STAT_SUCCESS) { |
| 559 | 559 | logerror("corvus_unlock_semaphore: Error reading semaphore table, status: 0x%2.2x\n", status); |
| 560 | 560 | m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR; |
| r31205 | r31206 | |
| 584 | 584 | } else { |
| 585 | 585 | m_buffer.semaphore_locking_response.result = SEM_PRIOR_STATE_SET; // It was there |
| 586 | 586 | memcpy(&semaphore_table.semaphore_block.semaphore_entry[offset], " ", 8); // Clear it |
| 587 | status = corvus_write_sector( | |
| 587 | status = corvus_write_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256); | |
| 588 | 588 | if(status != STAT_SUCCESS) { |
| 589 | 589 | logerror("corvus_unlock_semaphore: Error updating semaphore table, status: 0x%2.2x\n", status); |
| 590 | 590 | m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR; |
| r31205 | r31206 | |
| 616 | 616 | |
| 617 | 617 | memset(semaphore_table.semaphore_block.semaphore_table, 0x20, 256); |
| 618 | 618 | |
| 619 | status = corvus_write_sector( | |
| 619 | status = corvus_write_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256); | |
| 620 | 620 | if(status != STAT_SUCCESS) { |
| 621 | 621 | logerror("corvus_init_semaphore_table: Error updating semaphore table, status: 0x%2.2x\n", status); |
| 622 | 622 | return status; |
| r31205 | r31206 | |
| 633 | 633 | // Fills in the Drive Parameter packet based on the opened CHD file |
| 634 | 634 | // |
| 635 | 635 | // Pass: |
| 636 | // drv: | |
| 636 | // drv: Corvus drive id (1..15) | |
| 637 | 637 | // |
| 638 | 638 | // Returns: |
| 639 | 639 | // Status of command |
| r31205 | r31206 | |
| 658 | 658 | // |
| 659 | 659 | // Make sure a valid drive is being accessed |
| 660 | 660 | // |
| 661 | drv -= 1; // Internally, drives start at 0 | |
| 662 | ||
| 663 | 661 | if ( ! corvus_hdc_file( drv ) ) |
| 664 | 662 | { |
| 665 | 663 | logerror("corvus_get_drive_parameters: Attempt to retrieve parameters from non-existant drive: %d\n", drv); |
| r31205 | r31206 | |
| 730 | 728 | memcpy(m_buffer.drive_param_response.table_info.lsi11_vdo_table, raw_disk_parameter_block.dpb.lsi11_vdo_table, 8); |
| 731 | 729 | memcpy(m_buffer.drive_param_response.table_info.lsi11_spare_table, raw_disk_parameter_block.dpb.lsi11_spare_table, 8); |
| 732 | 730 | |
| 733 | m_buffer.drive_param_response.drive_number = drv | |
| 731 | m_buffer.drive_param_response.drive_number = drv; | |
| 734 | 732 | m_buffer.drive_param_response.physical_capacity.msb = (raw_capacity & 0xff0000) >> 16; |
| 735 | 733 | m_buffer.drive_param_response.physical_capacity.midb = (raw_capacity & 0x00ff00) >> 8; |
| 736 | 734 | m_buffer.drive_param_response.physical_capacity.lsb = (raw_capacity & 0x0000ff); |
| r31205 | r31206 | |
| 757 | 755 | UINT8 corvus_hdc_t::corvus_read_boot_block(UINT8 block) { |
| 758 | 756 | LOG(("corvus_read_boot_block: Reading boot block: %d\n", block)); |
| 759 | 757 | |
| 760 | return corvus_read_sector(0, 25 + block, m_buffer.read_512_response.data, 512); | |
| 761 | ||
| 758 | return corvus_read_sector(1, 25 + block, m_buffer.read_512_response.data, 512); | |
| 762 | 759 | } |
| 763 | 760 | |
| 764 | 761 | |
| r31205 | r31206 | |
| 784 | 781 | LOG(("corvus_read_firmware_block: Reading firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n", |
| 785 | 782 | head, sector, relative_sector)); |
| 786 | 783 | |
| 787 | status = corvus_read_sector( | |
| 784 | status = corvus_read_sector(1, relative_sector, m_buffer.read_512_response.data, 512); // TODO: Which drive should Prep Mode talk to ??? | |
| 788 | 785 | return status; |
| 789 | 786 | } |
| 790 | 787 | |
| r31205 | r31206 | |
| 812 | 809 | LOG(("corvus_write_firmware_block: Writing firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n", |
| 813 | 810 | head, sector, relative_sector)); |
| 814 | 811 | |
| 815 | status = corvus_write_sector( | |
| 812 | status = corvus_write_sector(1, relative_sector, buffer, 512); // TODO: Which drive should Prep Mode talk to ??? | |
| 816 | 813 | return status; |
| 817 | 814 | } |
| 818 | 815 | |
| r31205 | r31206 | |
| 835 | 832 | UINT8 status = 0; |
| 836 | 833 | UINT8 tbuffer[512]; |
| 837 | 834 | |
| 838 | // Set up the global corvus_hdc so m_tracks_per_cylinder and m_sectors_per_track are valid | |
| 839 | corvus_hdc_file(0); | |
| 835 | // Set up m_tracks_per_cylinder and m_sectors_per_track | |
| 836 | corvus_hdc_file(1); | |
| 840 | 837 | |
| 841 | 838 | max_sector = m_sectors_per_track * m_tracks_per_cylinder * m_cylinders_per_drive; |
| 842 | 839 | |
| r31205 | r31206 | |
| 848 | 845 | pattern = tbuffer; |
| 849 | 846 | } |
| 850 | 847 | |
| 851 | LOG(("corvus_format_drive: Formatting drive with 0x%5.5x sectors, pattern buffer (passed length: %d)follows\n", max_sector, 512)); | |
| 848 | LOG(("corvus_format_drive: Formatting drive with 0x%5.5x sectors, pattern buffer (passed length: %d) follows\n", max_sector, 512)); | |
| 852 | 849 | LOG_BUFFER(pattern, 512); |
| 853 | 850 | |
| 854 | 851 | for(sector = 0; sector <= max_sector; sector++) { |
| 855 | status = corvus_write_sector( | |
| 852 | status = corvus_write_sector(1, sector, pattern, 512); | |
| 856 | 853 | if(status != STAT_SUCCESS) { |
| 857 | 854 | logerror("corvus_format_drive: Error while formatting drive in corvus_write_sector--sector: 0x%5.5x, status: 0x%x2.2x\n", |
| 858 | 855 | sector, status); |
| r31205 | r31206 | |
| 871 | 868 | // Returns a hard_disk_file object for a given virtual hard drive device in the concept |
| 872 | 869 | // |
| 873 | 870 | // Pass: |
| 874 | // | |
| 871 | // drv: Corvus drive id (1..15) | |
| 875 | 872 | // |
| 876 | 873 | // Returns: |
| 877 | 874 | // hard_disk_file object |
| 878 | 875 | // |
| 879 | hard_disk_file *corvus_hdc_t::corvus_hdc_file(int | |
| 876 | hard_disk_file *corvus_hdc_t::corvus_hdc_file(int drv) { | |
| 880 | 877 | static const char *const tags[] = { |
| 881 | 878 | "harddisk1", "harddisk2", "harddisk3", "harddisk4" |
| 882 | 879 | }; |
| 883 | 880 | |
| 884 | 881 | // we only support 4 drives, as per the tags[] table, so prevent a crash |
| 885 | if (id > 3) | |
| 882 | // Corvus drive id numbers are 1-based so we check 1..4 instead of 0..3 | |
| 883 | if (drv < 1 || drv > 4) | |
| 886 | 884 | { |
| 887 | 885 | return NULL; |
| 888 | 886 | } |
| 889 | 887 | |
| 890 | harddisk_image_device *img = siblingdevice<harddisk_image_device>(tags[ | |
| 888 | harddisk_image_device *img = siblingdevice<harddisk_image_device>(tags[drv - 1]); | |
| 891 | 889 | |
| 892 | 890 | if ( !img ) |
| 893 | 891 | return NULL; |
| r31205 | r31206 | |
| 902 | 900 | m_tracks_per_cylinder = info->heads; |
| 903 | 901 | m_cylinders_per_drive = info->cylinders; |
| 904 | 902 | |
| 905 | LOG(("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", | |
| 903 | LOG(("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", drv, info->heads, info->cylinders, info->sectors)); | |
| 906 | 904 | |
| 907 | 905 | return file; |
| 908 | 906 | } |
| r31205 | r31206 | |
| 979 | 977 | break; |
| 980 | 978 | case SEMAPHORE_STATUS_MOD: |
| 981 | 979 | m_buffer.semaphore_status_response.status = |
| 982 | corvus_read_sector( | |
| 980 | corvus_read_sector(1, 7, m_buffer.semaphore_status_response.table, 256); | |
| 983 | 981 | break; |
| 984 | 982 | default: |
| 985 | 983 | invalid_command_flag = true; |
| Previous | 199869 Revisions | Next |