static void sdhci_write_block_to_card(SDHCIState *s)

{

    int index = 0;



    if (s->prnsts & SDHC_SPACE_AVAILABLE) {

        if (s->norintstsen & SDHC_NISEN_WBUFRDY) {

            s->norintsts |= SDHC_NIS_WBUFRDY;

        }

        sdhci_update_irq(s);

        return;

    }



    if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {

        if (s->blkcnt == 0) {

            return;

        } else {

            s->blkcnt--;

        }

    }



    for (index = 0; index < (s->blksize & 0x0fff); index++) {

        sd_write_data(s->card, s->fifo_buffer[index]);

    }



    /* Next data can be written through BUFFER DATORT register */

    s->prnsts |= SDHC_SPACE_AVAILABLE;



    /* Finish transfer if that was the last block of data */

    if ((s->trnmod & SDHC_TRNS_MULTI) == 0 ||

            ((s->trnmod & SDHC_TRNS_MULTI) &&

            (s->trnmod & SDHC_TRNS_BLK_CNT_EN) && (s->blkcnt == 0))) {

        SDHCI_GET_CLASS(s)->end_data_transfer(s);

    } else if (s->norintstsen & SDHC_NISEN_WBUFRDY) {

        s->norintsts |= SDHC_NIS_WBUFRDY;

    }



    /* Generate Block Gap Event if requested and if not the last block */

    if (s->stopped_state == sdhc_gap_write && (s->trnmod & SDHC_TRNS_MULTI) &&

            s->blkcnt > 0) {

        s->prnsts &= ~SDHC_DOING_WRITE;

        if (s->norintstsen & SDHC_EISEN_BLKGAP) {

            s->norintsts |= SDHC_EIS_BLKGAP;

        }

        SDHCI_GET_CLASS(s)->end_data_transfer(s);

    }



    sdhci_update_irq(s);

}

static void sdhci_write_block_to_card(SDHCIState *s)

{

    int index = 0;



    if (s->prnsts & SDHC_SPACE_AVAILABLE) {

        if (s->norintstsen & SDHC_NISEN_WBUFRDY) {

            s->norintsts |= SDHC_NIS_WBUFRDY;

        }

        sdhci_update_irq(s);

        return;

    }



    if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {

        if (s->blkcnt == 0) {

            return;

        } else {

            s->blkcnt--;

        }

    }



    for (index = 0; index < (s->blksize & 0x0fff); index++) {

        sd_write_data(s->card, s->fifo_buffer[index]);

    }



    

    s->prnsts |= SDHC_SPACE_AVAILABLE;



    

    if ((s->trnmod & SDHC_TRNS_MULTI) == 0 ||

            ((s->trnmod & SDHC_TRNS_MULTI) &&

            (s->trnmod & SDHC_TRNS_BLK_CNT_EN) && (s->blkcnt == 0))) {

        SDHCI_GET_CLASS(s)->end_data_transfer(s);

    } else if (s->norintstsen & SDHC_NISEN_WBUFRDY) {

        s->norintsts |= SDHC_NIS_WBUFRDY;

    }



    

    if (s->stopped_state == sdhc_gap_write && (s->trnmod & SDHC_TRNS_MULTI) &&

            s->blkcnt > 0) {

        s->prnsts &= ~SDHC_DOING_WRITE;

        if (s->norintstsen & SDHC_EISEN_BLKGAP) {

            s->norintsts |= SDHC_EIS_BLKGAP;

        }

        SDHCI_GET_CLASS(s)->end_data_transfer(s);

    }



    sdhci_update_irq(s);

}

static void FUNC_0(SDHCIState *VAR_0)

{

    int VAR_1 = 0;



    if (VAR_0->prnsts & SDHC_SPACE_AVAILABLE) {

        if (VAR_0->norintstsen & SDHC_NISEN_WBUFRDY) {

            VAR_0->norintsts |= SDHC_NIS_WBUFRDY;

        }

        sdhci_update_irq(VAR_0);

        return;

    }



    if (VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) {

        if (VAR_0->blkcnt == 0) {

            return;

        } else {

            VAR_0->blkcnt--;

        }

    }



    for (VAR_1 = 0; VAR_1 < (VAR_0->blksize & 0x0fff); VAR_1++) {

        sd_write_data(VAR_0->card, VAR_0->fifo_buffer[VAR_1]);

    }



    

    VAR_0->prnsts |= SDHC_SPACE_AVAILABLE;



    

    if ((VAR_0->trnmod & SDHC_TRNS_MULTI) == 0 ||

            ((VAR_0->trnmod & SDHC_TRNS_MULTI) &&

            (VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) && (VAR_0->blkcnt == 0))) {

        SDHCI_GET_CLASS(VAR_0)->end_data_transfer(VAR_0);

    } else if (VAR_0->norintstsen & SDHC_NISEN_WBUFRDY) {

        VAR_0->norintsts |= SDHC_NIS_WBUFRDY;

    }



    

    if (VAR_0->stopped_state == sdhc_gap_write && (VAR_0->trnmod & SDHC_TRNS_MULTI) &&

            VAR_0->blkcnt > 0) {

        VAR_0->prnsts &= ~SDHC_DOING_WRITE;

        if (VAR_0->norintstsen & SDHC_EISEN_BLKGAP) {

            VAR_0->norintsts |= SDHC_EIS_BLKGAP;

        }

        SDHCI_GET_CLASS(VAR_0)->end_data_transfer(VAR_0);

    }



    sdhci_update_irq(VAR_0);

}

static void FUNC_0(SDHCIState *VAR_0)
{ int VAR_1 = 0; if (VAR_0->prnsts & SDHC_SPACE_AVAILABLE) { if (VAR_0->norintstsen & SDHC_NISEN_WBUFRDY) { VAR_0->norintsts |= SDHC_NIS_WBUFRDY; } sdhci_update_irq(VAR_0); return; } if (VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) { if (VAR_0->blkcnt == 0) { return; } else { VAR_0->blkcnt--; } } for (VAR_1 = 0; VAR_1 < (VAR_0->blksize & 0x0fff); VAR_1++) { sd_write_data(VAR_0->card, VAR_0->fifo_buffer[VAR_1]); } VAR_0->prnsts |= SDHC_SPACE_AVAILABLE; if ((VAR_0->trnmod & SDHC_TRNS_MULTI) == 0 ||
((VAR_0->trnmod & SDHC_TRNS_MULTI) &&
(VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) && (VAR_0->blkcnt == 0))) { SDHCI_GET_CLASS(VAR_0)->end_data_transfer(VAR_0); } else if (VAR_0->norintstsen & SDHC_NISEN_WBUFRDY) { VAR_0->norintsts |= SDHC_NIS_WBUFRDY; } if (VAR_0->stopped_state == sdhc_gap_write && (VAR_0->trnmod & SDHC_TRNS_MULTI) &&
VAR_0->blkcnt > 0) { VAR_0->prnsts &= ~SDHC_DOING_WRITE; if (VAR_0->norintstsen & SDHC_EISEN_BLKGAP) { VAR_0->norintsts |= SDHC_EIS_BLKGAP; } SDHCI_GET_CLASS(VAR_0)->end_data_transfer(VAR_0); } sdhci_update_irq(VAR_0); }