mirror of
https://github.com/holub/mame
synced 2025-05-06 06:14:45 +03:00
(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.
This commit is contained in:
parent
2bdfe24399
commit
b026ca42e2
@ -255,7 +255,7 @@ bool corvus_hdc_t::parse_hdc_command(UINT8 data) {
|
|||||||
// Write a variably-sized chunk of data to the CHD file
|
// Write a variably-sized chunk of data to the CHD file
|
||||||
//
|
//
|
||||||
// Pass:
|
// Pass:
|
||||||
// drv: Drive number to write to
|
// drv: Corvus drive id (1..15)
|
||||||
// sector: Physical sector number to write to
|
// sector: Physical sector number to write to
|
||||||
// buffer: Buffer to write
|
// buffer: Buffer to write
|
||||||
// len: Length of the buffer (amount of data to write)
|
// len: Length of the buffer (amount of data to write)
|
||||||
@ -323,7 +323,7 @@ UINT8 corvus_hdc_t::corvus_write_sector(UINT8 drv, UINT32 sector, UINT8 *buffer,
|
|||||||
//
|
//
|
||||||
UINT8 corvus_hdc_t::corvus_write_logical_sector(dadr_t *dadr, UINT8 *buffer, int len) {
|
UINT8 corvus_hdc_t::corvus_write_logical_sector(dadr_t *dadr, UINT8 *buffer, int len) {
|
||||||
UINT8 status; // Status returned from Physical Sector read
|
UINT8 status; // Status returned from Physical Sector read
|
||||||
UINT8 drv; // Drive number (1 - 15)
|
UINT8 drv; // Corvus drive id (1..15)
|
||||||
UINT32 sector; // Sector number on drive
|
UINT32 sector; // Sector number on drive
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -334,13 +334,13 @@ UINT8 corvus_hdc_t::corvus_write_logical_sector(dadr_t *dadr, UINT8 *buffer, int
|
|||||||
//
|
//
|
||||||
// For example: 0x23 would decode to Drive ID #3, high-order nibble: 0x02.
|
// For example: 0x23 would decode to Drive ID #3, high-order nibble: 0x02.
|
||||||
//
|
//
|
||||||
drv = (dadr->address_msn_and_drive & 0x0f) - 1;
|
drv = (dadr->address_msn_and_drive & 0x0f);
|
||||||
sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb;
|
sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb;
|
||||||
|
|
||||||
LOG(("corvus_write_logical_sector: Writing based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n",
|
LOG(("corvus_write_logical_sector: Writing based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n",
|
||||||
dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv));
|
dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv));
|
||||||
|
|
||||||
// Set up the global corvus_hdc so m_tracks_per_cylinder and m_sectors_per_track are valid
|
// Set m_tracks_per_cylinder and m_sectors_per_track
|
||||||
corvus_hdc_file(drv);
|
corvus_hdc_file(drv);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -363,7 +363,7 @@ UINT8 corvus_hdc_t::corvus_write_logical_sector(dadr_t *dadr, UINT8 *buffer, int
|
|||||||
// Read a variably-sized chunk of data from the CHD file
|
// Read a variably-sized chunk of data from the CHD file
|
||||||
//
|
//
|
||||||
// Pass:
|
// Pass:
|
||||||
// drv: Drive number to read from
|
// drv: Corvus drive id (1..15)
|
||||||
// sector: Physical sector number to read from
|
// sector: Physical sector number to read from
|
||||||
// buffer: Buffer to hold the data read from the disk
|
// buffer: Buffer to hold the data read from the disk
|
||||||
// len: Length of the buffer
|
// len: Length of the buffer
|
||||||
@ -420,7 +420,7 @@ UINT8 corvus_hdc_t::corvus_read_sector(UINT8 drv, UINT32 sector, UINT8 *buffer,
|
|||||||
//
|
//
|
||||||
UINT8 corvus_hdc_t::corvus_read_logical_sector(dadr_t *dadr, UINT8 *buffer, int len) {
|
UINT8 corvus_hdc_t::corvus_read_logical_sector(dadr_t *dadr, UINT8 *buffer, int len) {
|
||||||
UINT8 status; // Status returned from Physical Sector read
|
UINT8 status; // Status returned from Physical Sector read
|
||||||
UINT8 drv; // Drive number (1 - 15)
|
UINT8 drv; // Corvus drive id (1..15)
|
||||||
UINT32 sector; // Sector number on drive
|
UINT32 sector; // Sector number on drive
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -431,13 +431,13 @@ UINT8 corvus_hdc_t::corvus_read_logical_sector(dadr_t *dadr, UINT8 *buffer, int
|
|||||||
//
|
//
|
||||||
// For example: 0x23 would decode to Drive ID #3, high-order nibble: 0x02.
|
// For example: 0x23 would decode to Drive ID #3, high-order nibble: 0x02.
|
||||||
//
|
//
|
||||||
drv = (dadr->address_msn_and_drive & 0x0f) - 1;
|
drv = (dadr->address_msn_and_drive & 0x0f);
|
||||||
sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb;
|
sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb;
|
||||||
|
|
||||||
LOG(("corvus_read_logical_sector: Reading based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n",
|
LOG(("corvus_read_logical_sector: Reading based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n",
|
||||||
dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv));
|
dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv));
|
||||||
|
|
||||||
// Set up the global corvus_hdc so m_tracks_per_cylinder and m_sectors_per_track are valid
|
// Set up m_tracks_per_cylinder and m_sectors_per_track
|
||||||
corvus_hdc_file(drv);
|
corvus_hdc_file(drv);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -480,7 +480,7 @@ UINT8 corvus_hdc_t::corvus_lock_semaphore(UINT8 *name) {
|
|||||||
//
|
//
|
||||||
// Read the semaphore table from the drive
|
// Read the semaphore table from the drive
|
||||||
//
|
//
|
||||||
status = corvus_read_sector(0, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
status = corvus_read_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
||||||
if(status != STAT_SUCCESS) {
|
if(status != STAT_SUCCESS) {
|
||||||
logerror("corvus_lock_semaphore: Error reading semaphore table, status: 0x%2.2x\n", status);
|
logerror("corvus_lock_semaphore: Error reading semaphore table, status: 0x%2.2x\n", status);
|
||||||
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
||||||
@ -514,7 +514,7 @@ UINT8 corvus_hdc_t::corvus_lock_semaphore(UINT8 *name) {
|
|||||||
} else {
|
} else {
|
||||||
m_buffer.semaphore_locking_response.result = SEM_PRIOR_STATE_NOT_SET; // It wasn't there already
|
m_buffer.semaphore_locking_response.result = SEM_PRIOR_STATE_NOT_SET; // It wasn't there already
|
||||||
memcpy(&semaphore_table.semaphore_block.semaphore_entry[blank_offset], name, 8);// Stick it into the table
|
memcpy(&semaphore_table.semaphore_block.semaphore_entry[blank_offset], name, 8);// Stick it into the table
|
||||||
status = corvus_write_sector(0, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
status = corvus_write_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
||||||
if(status != STAT_SUCCESS) {
|
if(status != STAT_SUCCESS) {
|
||||||
logerror("corvus_lock_semaphore: Error updating semaphore table, status: 0x%2.2x\n", status);
|
logerror("corvus_lock_semaphore: Error updating semaphore table, status: 0x%2.2x\n", status);
|
||||||
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
||||||
@ -554,7 +554,7 @@ UINT8 corvus_hdc_t::corvus_unlock_semaphore(UINT8 *name) {
|
|||||||
//
|
//
|
||||||
// Read the semaphore table from the drive
|
// Read the semaphore table from the drive
|
||||||
//
|
//
|
||||||
status = corvus_read_sector(0, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
status = corvus_read_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
||||||
if(status != STAT_SUCCESS) {
|
if(status != STAT_SUCCESS) {
|
||||||
logerror("corvus_unlock_semaphore: Error reading semaphore table, status: 0x%2.2x\n", status);
|
logerror("corvus_unlock_semaphore: Error reading semaphore table, status: 0x%2.2x\n", status);
|
||||||
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
||||||
@ -584,7 +584,7 @@ UINT8 corvus_hdc_t::corvus_unlock_semaphore(UINT8 *name) {
|
|||||||
} else {
|
} else {
|
||||||
m_buffer.semaphore_locking_response.result = SEM_PRIOR_STATE_SET; // It was there
|
m_buffer.semaphore_locking_response.result = SEM_PRIOR_STATE_SET; // It was there
|
||||||
memcpy(&semaphore_table.semaphore_block.semaphore_entry[offset], " ", 8); // Clear it
|
memcpy(&semaphore_table.semaphore_block.semaphore_entry[offset], " ", 8); // Clear it
|
||||||
status = corvus_write_sector(0, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
status = corvus_write_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
||||||
if(status != STAT_SUCCESS) {
|
if(status != STAT_SUCCESS) {
|
||||||
logerror("corvus_unlock_semaphore: Error updating semaphore table, status: 0x%2.2x\n", status);
|
logerror("corvus_unlock_semaphore: Error updating semaphore table, status: 0x%2.2x\n", status);
|
||||||
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
m_buffer.semaphore_locking_response.result = SEM_DISK_ERROR;
|
||||||
@ -616,7 +616,7 @@ UINT8 corvus_hdc_t::corvus_init_semaphore_table() {
|
|||||||
|
|
||||||
memset(semaphore_table.semaphore_block.semaphore_table, 0x20, 256);
|
memset(semaphore_table.semaphore_block.semaphore_table, 0x20, 256);
|
||||||
|
|
||||||
status = corvus_write_sector(0, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
status = corvus_write_sector(1, 7, semaphore_table.semaphore_block.semaphore_table, 256);
|
||||||
if(status != STAT_SUCCESS) {
|
if(status != STAT_SUCCESS) {
|
||||||
logerror("corvus_init_semaphore_table: Error updating semaphore table, status: 0x%2.2x\n", status);
|
logerror("corvus_init_semaphore_table: Error updating semaphore table, status: 0x%2.2x\n", status);
|
||||||
return status;
|
return status;
|
||||||
@ -633,7 +633,7 @@ UINT8 corvus_hdc_t::corvus_init_semaphore_table() {
|
|||||||
// Fills in the Drive Parameter packet based on the opened CHD file
|
// Fills in the Drive Parameter packet based on the opened CHD file
|
||||||
//
|
//
|
||||||
// Pass:
|
// Pass:
|
||||||
// drv: Drive number to get parameters from
|
// drv: Corvus drive id (1..15)
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// Status of command
|
// Status of command
|
||||||
@ -658,8 +658,6 @@ UINT8 corvus_hdc_t::corvus_get_drive_parameters(UINT8 drv) {
|
|||||||
//
|
//
|
||||||
// Make sure a valid drive is being accessed
|
// Make sure a valid drive is being accessed
|
||||||
//
|
//
|
||||||
drv -= 1; // Internally, drives start at 0
|
|
||||||
|
|
||||||
if ( ! corvus_hdc_file( drv ) )
|
if ( ! corvus_hdc_file( drv ) )
|
||||||
{
|
{
|
||||||
logerror("corvus_get_drive_parameters: Attempt to retrieve parameters from non-existant drive: %d\n", drv);
|
logerror("corvus_get_drive_parameters: Attempt to retrieve parameters from non-existant drive: %d\n", drv);
|
||||||
@ -730,7 +728,7 @@ UINT8 corvus_hdc_t::corvus_get_drive_parameters(UINT8 drv) {
|
|||||||
memcpy(m_buffer.drive_param_response.table_info.lsi11_vdo_table, raw_disk_parameter_block.dpb.lsi11_vdo_table, 8);
|
memcpy(m_buffer.drive_param_response.table_info.lsi11_vdo_table, raw_disk_parameter_block.dpb.lsi11_vdo_table, 8);
|
||||||
memcpy(m_buffer.drive_param_response.table_info.lsi11_spare_table, raw_disk_parameter_block.dpb.lsi11_spare_table, 8);
|
memcpy(m_buffer.drive_param_response.table_info.lsi11_spare_table, raw_disk_parameter_block.dpb.lsi11_spare_table, 8);
|
||||||
|
|
||||||
m_buffer.drive_param_response.drive_number = drv + 1;
|
m_buffer.drive_param_response.drive_number = drv;
|
||||||
m_buffer.drive_param_response.physical_capacity.msb = (raw_capacity & 0xff0000) >> 16;
|
m_buffer.drive_param_response.physical_capacity.msb = (raw_capacity & 0xff0000) >> 16;
|
||||||
m_buffer.drive_param_response.physical_capacity.midb = (raw_capacity & 0x00ff00) >> 8;
|
m_buffer.drive_param_response.physical_capacity.midb = (raw_capacity & 0x00ff00) >> 8;
|
||||||
m_buffer.drive_param_response.physical_capacity.lsb = (raw_capacity & 0x0000ff);
|
m_buffer.drive_param_response.physical_capacity.lsb = (raw_capacity & 0x0000ff);
|
||||||
@ -757,8 +755,7 @@ UINT8 corvus_hdc_t::corvus_get_drive_parameters(UINT8 drv) {
|
|||||||
UINT8 corvus_hdc_t::corvus_read_boot_block(UINT8 block) {
|
UINT8 corvus_hdc_t::corvus_read_boot_block(UINT8 block) {
|
||||||
LOG(("corvus_read_boot_block: Reading boot block: %d\n", block));
|
LOG(("corvus_read_boot_block: Reading boot block: %d\n", block));
|
||||||
|
|
||||||
return corvus_read_sector(0, 25 + block, m_buffer.read_512_response.data, 512);
|
return corvus_read_sector(1, 25 + block, m_buffer.read_512_response.data, 512);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -784,7 +781,7 @@ UINT8 corvus_hdc_t::corvus_read_firmware_block(UINT8 head, UINT8 sector) {
|
|||||||
LOG(("corvus_read_firmware_block: Reading firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n",
|
LOG(("corvus_read_firmware_block: Reading firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n",
|
||||||
head, sector, relative_sector));
|
head, sector, relative_sector));
|
||||||
|
|
||||||
status = corvus_read_sector(0, relative_sector, m_buffer.read_512_response.data, 512); // TODO: Which drive should Prep Mode talk to ???
|
status = corvus_read_sector(1, relative_sector, m_buffer.read_512_response.data, 512); // TODO: Which drive should Prep Mode talk to ???
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +809,7 @@ UINT8 corvus_hdc_t::corvus_write_firmware_block(UINT8 head, UINT8 sector, UINT8
|
|||||||
LOG(("corvus_write_firmware_block: Writing firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n",
|
LOG(("corvus_write_firmware_block: Writing firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n",
|
||||||
head, sector, relative_sector));
|
head, sector, relative_sector));
|
||||||
|
|
||||||
status = corvus_write_sector(0, relative_sector, buffer, 512); // TODO: Which drive should Prep Mode talk to ???
|
status = corvus_write_sector(1, relative_sector, buffer, 512); // TODO: Which drive should Prep Mode talk to ???
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -835,8 +832,8 @@ UINT8 corvus_hdc_t::corvus_format_drive(UINT8 *pattern, UINT16 len) {
|
|||||||
UINT8 status = 0;
|
UINT8 status = 0;
|
||||||
UINT8 tbuffer[512];
|
UINT8 tbuffer[512];
|
||||||
|
|
||||||
// Set up the global corvus_hdc so m_tracks_per_cylinder and m_sectors_per_track are valid
|
// Set up m_tracks_per_cylinder and m_sectors_per_track
|
||||||
corvus_hdc_file(0);
|
corvus_hdc_file(1);
|
||||||
|
|
||||||
max_sector = m_sectors_per_track * m_tracks_per_cylinder * m_cylinders_per_drive;
|
max_sector = m_sectors_per_track * m_tracks_per_cylinder * m_cylinders_per_drive;
|
||||||
|
|
||||||
@ -848,11 +845,11 @@ UINT8 corvus_hdc_t::corvus_format_drive(UINT8 *pattern, UINT16 len) {
|
|||||||
pattern = tbuffer;
|
pattern = tbuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(("corvus_format_drive: Formatting drive with 0x%5.5x sectors, pattern buffer (passed length: %d)follows\n", max_sector, 512));
|
LOG(("corvus_format_drive: Formatting drive with 0x%5.5x sectors, pattern buffer (passed length: %d) follows\n", max_sector, 512));
|
||||||
LOG_BUFFER(pattern, 512);
|
LOG_BUFFER(pattern, 512);
|
||||||
|
|
||||||
for(sector = 0; sector <= max_sector; sector++) {
|
for(sector = 0; sector <= max_sector; sector++) {
|
||||||
status = corvus_write_sector(0, sector, pattern, 512);
|
status = corvus_write_sector(1, sector, pattern, 512);
|
||||||
if(status != STAT_SUCCESS) {
|
if(status != STAT_SUCCESS) {
|
||||||
logerror("corvus_format_drive: Error while formatting drive in corvus_write_sector--sector: 0x%5.5x, status: 0x%x2.2x\n",
|
logerror("corvus_format_drive: Error while formatting drive in corvus_write_sector--sector: 0x%5.5x, status: 0x%x2.2x\n",
|
||||||
sector, status);
|
sector, status);
|
||||||
@ -871,23 +868,24 @@ UINT8 corvus_hdc_t::corvus_format_drive(UINT8 *pattern, UINT16 len) {
|
|||||||
// Returns a hard_disk_file object for a given virtual hard drive device in the concept
|
// Returns a hard_disk_file object for a given virtual hard drive device in the concept
|
||||||
//
|
//
|
||||||
// Pass:
|
// Pass:
|
||||||
// id: Drive number (1 - 15)
|
// drv: Corvus drive id (1..15)
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// hard_disk_file object
|
// hard_disk_file object
|
||||||
//
|
//
|
||||||
hard_disk_file *corvus_hdc_t::corvus_hdc_file(int id) {
|
hard_disk_file *corvus_hdc_t::corvus_hdc_file(int drv) {
|
||||||
static const char *const tags[] = {
|
static const char *const tags[] = {
|
||||||
"harddisk1", "harddisk2", "harddisk3", "harddisk4"
|
"harddisk1", "harddisk2", "harddisk3", "harddisk4"
|
||||||
};
|
};
|
||||||
|
|
||||||
// we only support 4 drives, as per the tags[] table, so prevent a crash
|
// we only support 4 drives, as per the tags[] table, so prevent a crash
|
||||||
if (id > 3)
|
// Corvus drive id numbers are 1-based so we check 1..4 instead of 0..3
|
||||||
|
if (drv < 1 || drv > 4)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
harddisk_image_device *img = siblingdevice<harddisk_image_device>(tags[id]);
|
harddisk_image_device *img = siblingdevice<harddisk_image_device>(tags[drv - 1]);
|
||||||
|
|
||||||
if ( !img )
|
if ( !img )
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -902,7 +900,7 @@ hard_disk_file *corvus_hdc_t::corvus_hdc_file(int id) {
|
|||||||
m_tracks_per_cylinder = info->heads;
|
m_tracks_per_cylinder = info->heads;
|
||||||
m_cylinders_per_drive = info->cylinders;
|
m_cylinders_per_drive = info->cylinders;
|
||||||
|
|
||||||
LOG(("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", id, info->heads, info->cylinders, info->sectors));
|
LOG(("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", drv, info->heads, info->cylinders, info->sectors));
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -979,7 +977,7 @@ void corvus_hdc_t::corvus_process_command_packet(bool invalid_command_flag) {
|
|||||||
break;
|
break;
|
||||||
case SEMAPHORE_STATUS_MOD:
|
case SEMAPHORE_STATUS_MOD:
|
||||||
m_buffer.semaphore_status_response.status =
|
m_buffer.semaphore_status_response.status =
|
||||||
corvus_read_sector(0, 7, m_buffer.semaphore_status_response.table, 256);
|
corvus_read_sector(1, 7, m_buffer.semaphore_status_response.table, 256);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
invalid_command_flag = true;
|
invalid_command_flag = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user