void ide_atapi_cmd_reply_end(IDEState *s)

{

    int byte_count_limit, size, ret;

#ifdef DEBUG_IDE_ATAPI

    printf("reply: tx_size=%d elem_tx_size=%d index=%d\n",

           s->packet_transfer_size,

           s->elementary_transfer_size,

           s->io_buffer_index);

#endif

    if (s->packet_transfer_size <= 0) {

        /* end of transfer */

        ide_atapi_cmd_ok(s);

        ide_set_irq(s->bus);

#ifdef DEBUG_IDE_ATAPI

        printf("status=0x%x\n", s->status);

#endif

    } else {

        /* see if a new sector must be read */

        if (s->lba != -1 && s->io_buffer_index >= s->cd_sector_size) {

            ret = cd_read_sector(s, s->lba, s->io_buffer, s->cd_sector_size);

            if (ret < 0) {

                ide_atapi_io_error(s, ret);

                return;

            }

            s->lba++;

            s->io_buffer_index = 0;

        }

        if (s->elementary_transfer_size > 0) {

            /* there are some data left to transmit in this elementary

               transfer */

            size = s->cd_sector_size - s->io_buffer_index;

            if (size > s->elementary_transfer_size)

                size = s->elementary_transfer_size;

            s->packet_transfer_size -= size;

            s->elementary_transfer_size -= size;

            s->io_buffer_index += size;

            ide_transfer_start(s, s->io_buffer + s->io_buffer_index - size,

                               size, ide_atapi_cmd_reply_end);

        } else {

            /* a new transfer is needed */

            s->nsector = (s->nsector & ~7) | ATAPI_INT_REASON_IO;

            byte_count_limit = atapi_byte_count_limit(s);

#ifdef DEBUG_IDE_ATAPI

            printf("byte_count_limit=%d\n", byte_count_limit);

#endif

            size = s->packet_transfer_size;

            if (size > byte_count_limit) {

                /* byte count limit must be even if this case */

                if (byte_count_limit & 1)

                    byte_count_limit--;

                size = byte_count_limit;

            }

            s->lcyl = size;

            s->hcyl = size >> 8;

            s->elementary_transfer_size = size;

            /* we cannot transmit more than one sector at a time */

            if (s->lba != -1) {

                if (size > (s->cd_sector_size - s->io_buffer_index))

                    size = (s->cd_sector_size - s->io_buffer_index);

            }

            s->packet_transfer_size -= size;

            s->elementary_transfer_size -= size;

            s->io_buffer_index += size;

            ide_transfer_start(s, s->io_buffer + s->io_buffer_index - size,

                               size, ide_atapi_cmd_reply_end);

            ide_set_irq(s->bus);

#ifdef DEBUG_IDE_ATAPI

            printf("status=0x%x\n", s->status);

#endif

        }

    }

}

void ide_atapi_cmd_reply_end(IDEState *s)

{

    int byte_count_limit, size, ret;

#ifdef DEBUG_IDE_ATAPI

    printf("reply: tx_size=%d elem_tx_size=%d index=%d\n",

           s->packet_transfer_size,

           s->elementary_transfer_size,

           s->io_buffer_index);

#endif

    if (s->packet_transfer_size <= 0) {

        

        ide_atapi_cmd_ok(s);

        ide_set_irq(s->bus);

#ifdef DEBUG_IDE_ATAPI

        printf("status=0x%x\n", s->status);

#endif

    } else {

        

        if (s->lba != -1 && s->io_buffer_index >= s->cd_sector_size) {

            ret = cd_read_sector(s, s->lba, s->io_buffer, s->cd_sector_size);

            if (ret < 0) {

                ide_atapi_io_error(s, ret);

                return;

            }

            s->lba++;

            s->io_buffer_index = 0;

        }

        if (s->elementary_transfer_size > 0) {

            



            size = s->cd_sector_size - s->io_buffer_index;

            if (size > s->elementary_transfer_size)

                size = s->elementary_transfer_size;

            s->packet_transfer_size -= size;

            s->elementary_transfer_size -= size;

            s->io_buffer_index += size;

            ide_transfer_start(s, s->io_buffer + s->io_buffer_index - size,

                               size, ide_atapi_cmd_reply_end);

        } else {

            

            s->nsector = (s->nsector & ~7) | ATAPI_INT_REASON_IO;

            byte_count_limit = atapi_byte_count_limit(s);

#ifdef DEBUG_IDE_ATAPI

            printf("byte_count_limit=%d\n", byte_count_limit);

#endif

            size = s->packet_transfer_size;

            if (size > byte_count_limit) {

                

                if (byte_count_limit & 1)

                    byte_count_limit--;

                size = byte_count_limit;

            }

            s->lcyl = size;

            s->hcyl = size >> 8;

            s->elementary_transfer_size = size;

            

            if (s->lba != -1) {

                if (size > (s->cd_sector_size - s->io_buffer_index))

                    size = (s->cd_sector_size - s->io_buffer_index);

            }

            s->packet_transfer_size -= size;

            s->elementary_transfer_size -= size;

            s->io_buffer_index += size;

            ide_transfer_start(s, s->io_buffer + s->io_buffer_index - size,

                               size, ide_atapi_cmd_reply_end);

            ide_set_irq(s->bus);

#ifdef DEBUG_IDE_ATAPI

            printf("status=0x%x\n", s->status);

#endif

        }

    }

}

        printf("status=0x%x\n", s->status);             ret = cd_read_sector(s, s->lba, s->io_buffer, s->cd_sector_size);             if (ret < 0) {                 ide_atapi_io_error(s, ret);             s->lba++;             s->io_buffer_index = 0;
void FUNC_0(IDEState *VAR_0)

{

    int VAR_1, VAR_2, VAR_3;

#ifdef DEBUG_IDE_ATAPI

    printf("reply: tx_size=%d elem_tx_size=%d index=%d\n",

           VAR_0->packet_transfer_size,

           VAR_0->elementary_transfer_size,

           VAR_0->io_buffer_index);

#endif

    if (VAR_0->packet_transfer_size <= 0) {

        

        ide_atapi_cmd_ok(VAR_0);

        ide_set_irq(VAR_0->bus);

#ifdef DEBUG_IDE_ATAPI

        printf("status=0x%x\n", VAR_0->status);

#endif

    } else {

        

        if (VAR_0->lba != -1 && VAR_0->io_buffer_index >= VAR_0->cd_sector_size) {

            VAR_3 = cd_read_sector(VAR_0, VAR_0->lba, VAR_0->io_buffer, VAR_0->cd_sector_size);

            if (VAR_3 < 0) {

                ide_atapi_io_error(VAR_0, VAR_3);

                return;

            }

            VAR_0->lba++;

            VAR_0->io_buffer_index = 0;

        }

        if (VAR_0->elementary_transfer_size > 0) {

            



            VAR_2 = VAR_0->cd_sector_size - VAR_0->io_buffer_index;

            if (VAR_2 > VAR_0->elementary_transfer_size)

                VAR_2 = VAR_0->elementary_transfer_size;

            VAR_0->packet_transfer_size -= VAR_2;

            VAR_0->elementary_transfer_size -= VAR_2;

            VAR_0->io_buffer_index += VAR_2;

            ide_transfer_start(VAR_0, VAR_0->io_buffer + VAR_0->io_buffer_index - VAR_2,

                               VAR_2, FUNC_0);

        } else {

            

            VAR_0->nsector = (VAR_0->nsector & ~7) | ATAPI_INT_REASON_IO;

            VAR_1 = atapi_byte_count_limit(VAR_0);

#ifdef DEBUG_IDE_ATAPI

            printf("VAR_1=%d\n", VAR_1);

#endif

            VAR_2 = VAR_0->packet_transfer_size;

            if (VAR_2 > VAR_1) {

                

                if (VAR_1 & 1)

                    VAR_1--;

                VAR_2 = VAR_1;

            }

            VAR_0->lcyl = VAR_2;

            VAR_0->hcyl = VAR_2 >> 8;

            VAR_0->elementary_transfer_size = VAR_2;

            

            if (VAR_0->lba != -1) {

                if (VAR_2 > (VAR_0->cd_sector_size - VAR_0->io_buffer_index))

                    VAR_2 = (VAR_0->cd_sector_size - VAR_0->io_buffer_index);

            }

            VAR_0->packet_transfer_size -= VAR_2;

            VAR_0->elementary_transfer_size -= VAR_2;

            VAR_0->io_buffer_index += VAR_2;

            ide_transfer_start(VAR_0, VAR_0->io_buffer + VAR_0->io_buffer_index - VAR_2,

                               VAR_2, FUNC_0);

            ide_set_irq(VAR_0->bus);

#ifdef DEBUG_IDE_ATAPI

            printf("status=0x%x\n", VAR_0->status);

#endif

        }

    }

}

void FUNC_0(IDEState *VAR_0)
{ int VAR_1, VAR_2, VAR_3; #ifdef DEBUG_IDE_ATAPI
printf("reply: tx_size=%d elem_tx_size=%d index=%d\n",
VAR_0->packet_transfer_size,
VAR_0->elementary_transfer_size,
VAR_0->io_buffer_index); #endif
if (VAR_0->packet_transfer_size <= 0) { ide_atapi_cmd_ok(VAR_0); ide_set_irq(VAR_0->bus); #ifdef DEBUG_IDE_ATAPI
printf("status=0x%x\n", VAR_0->status); #endif
} else { if (VAR_0->lba != -1 && VAR_0->io_buffer_index >= VAR_0->cd_sector_size) { VAR_3 = cd_read_sector(VAR_0, VAR_0->lba, VAR_0->io_buffer, VAR_0->cd_sector_size); if (VAR_3 < 0) { ide_atapi_io_error(VAR_0, VAR_3); return; } VAR_0->lba++; VAR_0->io_buffer_index = 0; } if (VAR_0->elementary_transfer_size > 0) { VAR_2 = VAR_0->cd_sector_size - VAR_0->io_buffer_index; if (VAR_2 > VAR_0->elementary_transfer_size)
VAR_2 = VAR_0->elementary_transfer_size; VAR_0->packet_transfer_size -= VAR_2; VAR_0->elementary_transfer_size -= VAR_2; VAR_0->io_buffer_index += VAR_2; ide_transfer_start(VAR_0, VAR_0->io_buffer + VAR_0->io_buffer_index - VAR_2,
VAR_2, FUNC_0); } else { VAR_0->nsector = (VAR_0->nsector & ~7) | ATAPI_INT_REASON_IO; VAR_1 = atapi_byte_count_limit(VAR_0); #ifdef DEBUG_IDE_ATAPI
printf("VAR_1=%d\n", VAR_1); #endif
VAR_2 = VAR_0->packet_transfer_size; if (VAR_2 > VAR_1) { if (VAR_1 & 1)
VAR_1--; VAR_2 = VAR_1; } VAR_0->lcyl = VAR_2; VAR_0->hcyl = VAR_2 >> 8; VAR_0->elementary_transfer_size = VAR_2; if (VAR_0->lba != -1) { if (VAR_2 > (VAR_0->cd_sector_size - VAR_0->io_buffer_index))
VAR_2 = (VAR_0->cd_sector_size - VAR_0->io_buffer_index); } VAR_0->packet_transfer_size -= VAR_2; VAR_0->elementary_transfer_size -= VAR_2; VAR_0->io_buffer_index += VAR_2; ide_transfer_start(VAR_0, VAR_0->io_buffer + VAR_0->io_buffer_index - VAR_2,
VAR_2, FUNC_0); ide_set_irq(VAR_0->bus); #ifdef DEBUG_IDE_ATAPI
printf("status=0x%x\n", VAR_0->status); #endif
} } }