Skip to content

Commit d4d19e8

Browse files
joevtdingusdev
authored andcommitted
Update Inquiry methods.
ScsiCdrom has an inquiry method that overloads a method in CdromDrive. Make it so that it's a valid override (not overloaded). For CdromDrive, allow inquiry method to work with lengths <> 36 like the SCSI versions. For ScsiHarDisk, the inquiry method is not on override or an overload, but make it like the ScsiCdrom version anyway.
1 parent 1166fda commit d4d19e8

File tree

5 files changed

+72
-57
lines changed

5 files changed

+72
-57
lines changed

devices/common/scsi/scsicdrom.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ void ScsiCdrom::process_command()
6565
this->read(lba, cmd[4], 6);
6666
break;
6767
case ScsiCommand::INQUIRY:
68-
this->inquiry();
68+
this->bytes_out = this->inquiry(cmd, this->data_buf);
69+
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
70+
this->switch_phase(ScsiPhase::DATA_IN);
6971
break;
7072
case ScsiCommand::MODE_SELECT_6:
7173
this->mode_select_6(cmd[4]);
@@ -151,55 +153,53 @@ int ScsiCdrom::test_unit_ready()
151153
return ScsiError::NO_ERROR;
152154
}
153155

154-
void ScsiCdrom::inquiry() {
155-
int page_num = cmd_buf[2];
156-
int alloc_len = cmd_buf[4];
156+
uint32_t ScsiCdrom::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
157+
int page_num = cmd_ptr[2];
158+
int alloc_len = cmd_ptr[4];
157159

158160
if (page_num) {
159161
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
160162
}
161163

162164
if (alloc_len > 36) {
163-
LOG_F(ERROR, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
165+
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
164166
}
165167

166168
int lun;
167169
if (this->last_selection_has_atention) {
168-
LOG_F(9, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
169-
alloc_len, this->last_selection_message);
170+
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
171+
alloc_len, this->last_selection_message);
170172
lun = this->last_selection_message & 7;
171173
}
172174
else {
173-
LOG_F(9, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
174-
alloc_len, cmd_buf[1]);
175-
lun = cmd_buf[1] >> 5;
175+
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
176+
alloc_len, cmd_ptr[1]);
177+
lun = cmd_ptr[1] >> 5;
176178
}
177179

178-
this->data_buf[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
179-
this->data_buf[1] = 0x80; // removable media
180-
this->data_buf[2] = 2; // ANSI version: SCSI-2
181-
this->data_buf[3] = 1; // response data format
182-
this->data_buf[4] = 0x1F; // additional length
183-
this->data_buf[5] = 0;
184-
this->data_buf[6] = 0;
185-
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
186-
std::memcpy(&this->data_buf[8], vendor_info, 8);
187-
std::memcpy(&this->data_buf[16], prod_info, 16);
188-
std::memcpy(&this->data_buf[32], rev_info, 4);
189-
//std::memcpy(&this->data_buf[36], serial_number, 8);
180+
data_ptr[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
181+
data_ptr[1] = 0x80; // removable media
182+
data_ptr[2] = 2; // ANSI version: SCSI-2
183+
data_ptr[3] = 1; // response data format
184+
data_ptr[4] = 0x1F; // additional length
185+
data_ptr[5] = 0;
186+
data_ptr[6] = 0;
187+
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
188+
std::memcpy(&data_ptr[8], vendor_info, 8);
189+
std::memcpy(&data_ptr[16], prod_info, 16);
190+
std::memcpy(&data_ptr[32], rev_info, 4);
191+
//std::memcpy(&data_ptr[36], serial_number, 8);
190192
//etc.
191193

192194
if (alloc_len < 36) {
193-
LOG_F(ERROR, "Inappropriate Allocation Length: %d", alloc_len);
195+
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
196+
alloc_len);
194197
}
195198
else {
196-
memset(&this->data_buf[36], 0, alloc_len - 36);
199+
memset(&data_ptr[36], 0, alloc_len - 36);
197200
}
198201

199-
this->bytes_out = alloc_len;
200-
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
201-
202-
this->switch_phase(ScsiPhase::DATA_IN);
202+
return alloc_len;
203203
}
204204

205205
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";

devices/common/scsi/scsicdrom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ScsiCdrom : public CdromDrive, public ScsiDevice {
4444
protected:
4545
int test_unit_ready();
4646
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
47-
void inquiry();
47+
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) override;
4848
void mode_select_6(uint8_t param_len);
4949

5050
void mode_sense_6();

devices/common/scsi/scsihd.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ void ScsiHardDisk::process_command() {
8484
this->write(lba, cmd[4], 6);
8585
break;
8686
case ScsiCommand::INQUIRY:
87-
this->inquiry();
87+
this->bytes_out = this->inquiry(cmd, this->data_buf);
88+
this->switch_phase(ScsiPhase::DATA_IN);
8889
break;
8990
case ScsiCommand::MODE_SELECT_6:
9091
mode_select_6(cmd[4]);
@@ -212,16 +213,16 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
212213
return ScsiError::NO_ERROR;
213214
}
214215

215-
void ScsiHardDisk::inquiry() {
216-
int page_num = cmd_buf[2];
217-
int alloc_len = cmd_buf[4];
216+
uint32_t ScsiHardDisk::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
217+
int page_num = cmd_ptr[2];
218+
int alloc_len = cmd_ptr[4];
218219

219220
if (page_num) {
220221
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
221222
}
222223

223224
if (alloc_len > 36) {
224-
LOG_F(INFO, "%s: %d bytes requested in INQUIRY", this->name.c_str(), alloc_len);
225+
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
225226
}
226227

227228
int lun;
@@ -231,35 +232,34 @@ void ScsiHardDisk::inquiry() {
231232
lun = this->last_selection_message & 7;
232233
}
233234
else {
234-
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(), alloc_len, cmd_buf[1]);
235-
lun = cmd_buf[1] >> 5;
235+
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
236+
alloc_len, cmd_ptr[1]);
237+
lun = cmd_ptr[1] >> 5;
236238
}
237239

238-
this->data_buf[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
239-
this->data_buf[1] = 0; // non-removable media; 0x80 = removable media
240-
this->data_buf[2] = 2; // ANSI version: SCSI-2
241-
this->data_buf[3] = 1; // response data format
242-
this->data_buf[4] = 0x1F; // additional length
243-
this->data_buf[5] = 0;
244-
this->data_buf[6] = 0;
245-
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
246-
std::memcpy(&this->data_buf[8], vendor_info, 8);
247-
std::memcpy(&this->data_buf[16], prod_info, 16);
248-
std::memcpy(&this->data_buf[32], rev_info, 4);
249-
//std::memcpy(&this->data_buf[36], serial_number, 8);
240+
data_ptr[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
241+
data_ptr[1] = 0; // non-removable media; 0x80 = removable media
242+
data_ptr[2] = 2; // ANSI version: SCSI-2
243+
data_ptr[3] = 1; // response data format
244+
data_ptr[4] = 0x1F; // additional length
245+
data_ptr[5] = 0;
246+
data_ptr[6] = 0;
247+
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
248+
std::memcpy(&data_ptr[8], vendor_info, 8);
249+
std::memcpy(&data_ptr[16], prod_info, 16);
250+
std::memcpy(&data_ptr[32], rev_info, 4);
251+
//std::memcpy(&data_ptr[36], serial_number, 8);
250252
//etc.
251253

252254
if (alloc_len < 36) {
253255
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
254256
alloc_len);
255257
}
256258
else {
257-
memset(&this->data_buf[36], 0, alloc_len - 36);
259+
memset(&data_ptr[36], 0, alloc_len - 36);
258260
}
259261

260-
this->bytes_out = alloc_len;
261-
262-
this->switch_phase(ScsiPhase::DATA_IN);
262+
return alloc_len;
263263
}
264264

265265
int ScsiHardDisk::send_diagnostic() {

devices/common/scsi/scsihd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ScsiHardDisk : public ScsiDevice {
4949

5050
void mode_sense_6();
5151
void format();
52-
void inquiry();
52+
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
5353
void read_capacity_10();
5454
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
5555
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);

devices/storage/cdromdrive.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
DingusPPC - The Experimental PowerPC Macintosh emulator
3-
Copyright (C) 2018-24 divingkatae and maximum
3+
Copyright (C) 2018-25 divingkatae and maximum
44
(theweirdo) spatium
55
66
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -77,10 +77,15 @@ static char cdrom_product_id[] = "DINGUS CD-ROM ";
7777
static char cdrom_revision_id[] = "1.0 ";
7878

7979
uint32_t CdromDrive::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
80-
uint8_t alloc_len = cmd_ptr[4];
80+
int page_num = cmd_ptr[2];
81+
int alloc_len = cmd_ptr[4];
82+
83+
if (page_num) {
84+
ABORT_F("%s: invalid page number in INQUIRY", "CdromDrive");
85+
}
8186

8287
if (alloc_len > 36) {
83-
LOG_F(WARNING, "CD-ROM: more than 36 bytes requested in INQUIRY");
88+
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", "CdromDrive");
8489
}
8590

8691
data_ptr[0] = 5; // device type: CD-ROM
@@ -94,8 +99,18 @@ uint32_t CdromDrive::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
9499
std::memcpy(&data_ptr[8], cdrom_vendor_dingus_id, 8);
95100
std::memcpy(&data_ptr[16], cdrom_product_id, 16);
96101
std::memcpy(&data_ptr[32], cdrom_revision_id, 4);
102+
//std::memcpy(&data_ptr[36], serial_number, 8);
103+
//etc.
104+
105+
if (alloc_len < 36) {
106+
LOG_F(ERROR, "%s: allocation length too small: %d", "CdromDrive",
107+
alloc_len);
108+
}
109+
else {
110+
memset(&data_ptr[36], 0, alloc_len - 36);
111+
}
97112

98-
return 36;
113+
return alloc_len;
99114
}
100115

101116
uint32_t CdromDrive::mode_sense_ex(bool is_sense_6, uint8_t* cmd_ptr, uint8_t* data_ptr) {

0 commit comments

Comments
 (0)