From 0dc379404c7b41d5bb171001804c492943980e66 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 4 Jan 2017 06:33:18 +0100 Subject: [PATCH] CD-ROM is no longer reloaded if not in ejected/empty state; ATAPI commands that accept a buffer length allocation now send no data if the allocated length is 0. --- src/ide.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/win.c | 2 +- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/ide.c b/src/ide.c index 1355bfb53..6a5b419f4 100644 --- a/src/ide.c +++ b/src/ide.c @@ -1954,6 +1954,12 @@ static void atapicommand(int ide_board) /* Clear the sense stuff as per the spec. */ atapi_sense_clear(temp_command, 0); + + if (idebufferb[4] == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } break; case GPCMD_SET_SPEED: @@ -2013,6 +2019,12 @@ static void atapicommand(int ide_board) idecallback[ide_board]=60*IDE_TIME; ide->packlen=len; // pclog("READ_TOC_PMA_ATIP format %02X, length %i (%i)\n", toc_format, ide->cylinder, idebufferb[1]); + + if (len == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } return; case GPCMD_READ_CD: @@ -2200,12 +2212,20 @@ static void atapicommand(int ide_board) if (temp_command == GPCMD_MODE_SENSE_6) { len = SCSICDROMModeSense(idebufferb,4,temp); + if (len > alloc_length) + { + len = alloc_length; + } idebufferb[0] = len - 1; idebufferb[1]=3; /*120mm data CD-ROM*/ } else { len = SCSICDROMModeSense(idebufferb,8,temp); + if (len > alloc_length) + { + len = alloc_length; + } idebufferb[0]=(len - 2)>>8; idebufferb[1]=(len - 2)&255; idebufferb[2]=3; /*120mm data CD-ROM*/ @@ -2214,6 +2234,12 @@ static void atapicommand(int ide_board) atapi_command_send_init(ide, temp_command, len, alloc_length); atapi_command_ready(ide_board, len); + + if (len == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } return; case GPCMD_MODE_SELECT_6: @@ -2250,6 +2276,12 @@ static void atapicommand(int ide_board) ide->pos=0; idecallback[ide_board]=60*IDE_TIME; ide->packlen=len; + + if (len == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } } return; @@ -2307,6 +2339,12 @@ static void atapicommand(int ide_board) atapi_command_send_init(ide, temp_command, len, alloc_length); atapi_command_ready(ide_board, len); + + if (len == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } break; case GPCMD_GET_EVENT_STATUS_NOTIFICATION: @@ -2383,12 +2421,22 @@ static void atapicommand(int ide_board) } len=34; + if (len > alloc_length) + { + len = alloc_length + } ide->packetstatus = ATAPI_STATUS_DATA; ide->cylinder=len; ide->secount=2; ide->pos=0; idecallback[ide_board]=60*IDE_TIME; ide->packlen=len; + + if (len == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } break; case GPCMD_READ_TRACK_INFORMATION: @@ -2452,7 +2500,13 @@ static void atapicommand(int ide_board) ide->pos=0; idecallback[ide_board]=60*IDE_TIME; ide->packlen=len; - break; + + if (len == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } + break; case GPCMD_PLAY_AUDIO_10: case GPCMD_PLAY_AUDIO_12: @@ -2689,6 +2743,12 @@ atapi_out: atapi_command_send_init(ide, temp_command, len, alloc_length); atapi_command_ready(ide_board, len); + + if (len == 0) + { + ide->packetstatus = ATAPI_STATUS_COMPLETE; + idecallback[ide_board]=50*IDE_TIME; + } break; case GPCMD_PREVENT_REMOVAL: diff --git a/src/win.c b/src/win.c index ad03db92b..c8ea78941 100644 --- a/src/win.c +++ b/src/win.c @@ -1342,7 +1342,7 @@ void win_cdrom_reload() HMENU hmenu; hmenu=GetMenu(ghwnd); int new_cdrom_drive; - if ((cdrom_drive == old_cdrom_drive) || (old_cdrom_drive == 0)) + if ((cdrom_drive == old_cdrom_drive) || (old_cdrom_drive == 0) || (cdrom_drive != 0)) { /* Switch from empty to empty. Do nothing. */ return;