scsicdrom: Cleanup.

- Use macros for reading 2 byte or 4 byte big endian data. block_size is assumed to be < 64K so WRITE_DWORD_BE_A will write two leading zeros.
- Scalar pass by value parameters don't need to be const.
- Remove some unnecessary locals.
This commit is contained in:
joevt 2024-03-10 01:02:45 -08:00 committed by dingusdev
parent a868f4eee4
commit d3c913e384
1 changed files with 9 additions and 18 deletions

View File

@ -38,7 +38,7 @@ ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(nam
void ScsiCdrom::process_command()
{
uint32_t lba, xfer_len;
uint32_t lba;
this->pre_xfer_action = nullptr;
this->post_xfer_action = nullptr;
@ -112,12 +112,11 @@ void ScsiCdrom::process_command()
this->read_capacity_10();
break;
case ScsiCommand::READ_10:
lba = READ_DWORD_BE_U(&cmd[2]);
xfer_len = READ_WORD_BE_U(&cmd[7]);
lba = READ_DWORD_BE_U(&cmd[2]);
if (cmd[1] & 1) {
ABORT_F("%s: RelAdr bit set in READ_10", this->name.c_str());
}
read(lba, xfer_len, 10);
read(lba, READ_WORD_BE_U(&cmd[7]), 10);
break;
case ScsiCommand::WRITE_10:
this->illegal_command(cmd);
@ -177,7 +176,7 @@ bool ScsiCdrom::get_more_data() {
return this->data_size != 0;
}
void ScsiCdrom::read(const uint32_t lba, uint16_t nblocks, const uint8_t cmd_len)
void ScsiCdrom::read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len)
{
if (cmd_len == 6 && nblocks == 0)
nblocks = 256;
@ -233,17 +232,15 @@ void ScsiCdrom::mode_sense_6()
uint8_t page_code = this->cmd_buf[2] & 0x3F;
//uint8_t alloc_len = this->cmd_buf[4];
int num_blocks = this->size_blocks;
this->data_buf[ 0] = 13; // initial data size
this->data_buf[ 1] = 0; // medium type
this->data_buf[ 2] = 0x80; // medium is write protected
this->data_buf[ 3] = 8; // block description length
this->data_buf[ 4] = 0; // density code
this->data_buf[ 5] = (num_blocks >> 16) & 0xFFU;
this->data_buf[ 6] = (num_blocks >> 8) & 0xFFU;
this->data_buf[ 7] = (num_blocks ) & 0xFFU;
this->data_buf[ 5] = (this->size_blocks >> 16) & 0xFFU;
this->data_buf[ 6] = (this->size_blocks >> 8) & 0xFFU;
this->data_buf[ 7] = (this->size_blocks ) & 0xFFU;
this->data_buf[ 8] = 0;
this->data_buf[ 9] = 0;
this->data_buf[10] = (this->block_size >> 8) & 0xFFU;
@ -386,14 +383,8 @@ void ScsiCdrom::read_capacity_10()
int last_lba = this->size_blocks - 1;
this->data_buf[0] = (last_lba >> 24) & 0xFFU;
this->data_buf[1] = (last_lba >> 16) & 0xFFU;
this->data_buf[2] = (last_lba >> 8) & 0xFFU;
this->data_buf[3] = (last_lba >> 0) & 0xFFU;
this->data_buf[4] = 0;
this->data_buf[5] = 0;
this->data_buf[6] = (this->block_size >> 8) & 0xFFU;
this->data_buf[7] = this->block_size & 0xFFU;
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
WRITE_DWORD_BE_A(&this->data_buf[4], this->block_size);
this->bytes_out = 8;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;