tonioni / WinUAE

WinUAE Amiga emulator
http://www.winuae.net/
543 stars 87 forks source link

ATAPI Write / Mode Select fix #300

Closed LIV2 closed 4 months ago

LIV2 commented 4 months ago

I noticed that setting the volume via mode select on ATAPI devices was not working and tracked it down to this.

Before scsi_emulate_cmd() is called for commands writing to the device the memcpy was using ide->data_size. Then ide->data_size is copied to scsi->data_len.

The problem here is that by the time we get here, ide->data_size is 0 because it is decremented on every data write before the packet is processed here: https://github.com/tonioni/WinUAE/blob/b2877eeb48e2a922f2a9ca50481e7d3ca16d0f5c/ide.cpp#L1365-L1373

ide->data_offset is zeroed by atapi_set_size() well before the call to scsi_emulate_cmd() https://github.com/tonioni/WinUAE/blob/b2877eeb48e2a922f2a9ca50481e7d3ca16d0f5c/ide.cpp#L857-L861

So I thought ide->packet_data_size might be the only valid option here.

I then needed to add MODE SELECT into scsi_emulate_analyze() to set the correct data_len before this would work.

I noticed that near the bottom of this function, the data_len will be set from the usual location in the CDB but only if data_len was already -1. I wonder if it might make sense to set scsi->data_len to -1 before the call to scsi_emualate_analyze() but wasn't sure.

tonioni commented 4 months ago

Looks good (I don't think ATAPI CD support was not used for anything else than basic CD filesystem reads) but scsi_emulate_analyze change is outside of switch block?

Not sure about -1, it is was written long time ago..

LIV2 commented 4 months ago

Oops right you are, not sure how that slipped in sorry.

Have fixed that now