void framebuffer_update_display(

    DisplayState *ds,

    MemoryRegion *address_space,

    target_phys_addr_t base,

    int cols, /* Width in pixels.  */

    int rows, /* Height in pixels.  */

    int src_width, /* Length of source line, in bytes.  */

    int dest_row_pitch, /* Bytes between adjacent horizontal output pixels.  */

    int dest_col_pitch, /* Bytes between adjacent vertical output pixels.  */

    int invalidate, /* nonzero to redraw the whole image.  */

    drawfn fn,

    void *opaque,

    int *first_row, /* Input and output.  */

    int *last_row /* Output only */)

{

    target_phys_addr_t src_len;

    uint8_t *dest;

    uint8_t *src;

    uint8_t *src_base;

    int first, last = 0;

    int dirty;

    int i;

    ram_addr_t addr;

    MemoryRegionSection mem_section;

    MemoryRegion *mem;



    i = *first_row;

    *first_row = -1;

    src_len = src_width * rows;



    mem_section = memory_region_find(address_space, base, src_len);

    if (mem_section.size != src_len || !memory_region_is_ram(mem_section.mr)) {

        return;

    }

    mem = mem_section.mr;

    assert(mem);

    assert(mem_section.offset_within_address_space == base);



    memory_region_sync_dirty_bitmap(mem);

    src_base = cpu_physical_memory_map(base, &src_len, 0);

    /* If we can't map the framebuffer then bail.  We could try harder,

       but it's not really worth it as dirty flag tracking will probably

       already have failed above.  */

    if (!src_base)

        return;

    if (src_len != src_width * rows) {

        cpu_physical_memory_unmap(src_base, src_len, 0, 0);

        return;

    }

    src = src_base;

    dest = ds_get_data(ds);

    if (dest_col_pitch < 0)

        dest -= dest_col_pitch * (cols - 1);

    if (dest_row_pitch < 0) {

        dest -= dest_row_pitch * (rows - 1);

    }

    first = -1;

    addr = mem_section.offset_within_region;



    addr += i * src_width;

    src += i * src_width;

    dest += i * dest_row_pitch;



    for (; i < rows; i++) {

        dirty = memory_region_get_dirty(mem, addr, src_width,

                                             DIRTY_MEMORY_VGA);

        if (dirty || invalidate) {

            fn(opaque, dest, src, cols, dest_col_pitch);

            if (first == -1)

                first = i;

            last = i;

        }

        addr += src_width;

        src += src_width;

        dest += dest_row_pitch;

    }

    cpu_physical_memory_unmap(src_base, src_len, 0, 0);

    if (first < 0) {

        return;

    }

    memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,

                              DIRTY_MEMORY_VGA);

    *first_row = first;

    *last_row = last;

}

void framebuffer_update_display(

    DisplayState *ds,

    MemoryRegion *address_space,

    target_phys_addr_t base,

    int cols, 

    int rows, 

    int src_width, 

    int dest_row_pitch, 

    int dest_col_pitch, 

    int invalidate, 

    drawfn fn,

    void *opaque,

    int *first_row, 

    int *last_row )

{

    target_phys_addr_t src_len;

    uint8_t *dest;

    uint8_t *src;

    uint8_t *src_base;

    int first, last = 0;

    int dirty;

    int i;

    ram_addr_t addr;

    MemoryRegionSection mem_section;

    MemoryRegion *mem;



    i = *first_row;

    *first_row = -1;

    src_len = src_width * rows;



    mem_section = memory_region_find(address_space, base, src_len);

    if (mem_section.size != src_len || !memory_region_is_ram(mem_section.mr)) {

        return;

    }

    mem = mem_section.mr;

    assert(mem);

    assert(mem_section.offset_within_address_space == base);



    memory_region_sync_dirty_bitmap(mem);

    src_base = cpu_physical_memory_map(base, &src_len, 0);

    





    if (!src_base)

        return;

    if (src_len != src_width * rows) {

        cpu_physical_memory_unmap(src_base, src_len, 0, 0);

        return;

    }

    src = src_base;

    dest = ds_get_data(ds);

    if (dest_col_pitch < 0)

        dest -= dest_col_pitch * (cols - 1);

    if (dest_row_pitch < 0) {

        dest -= dest_row_pitch * (rows - 1);

    }

    first = -1;

    addr = mem_section.offset_within_region;



    addr += i * src_width;

    src += i * src_width;

    dest += i * dest_row_pitch;



    for (; i < rows; i++) {

        dirty = memory_region_get_dirty(mem, addr, src_width,

                                             DIRTY_MEMORY_VGA);

        if (dirty || invalidate) {

            fn(opaque, dest, src, cols, dest_col_pitch);

            if (first == -1)

                first = i;

            last = i;

        }

        addr += src_width;

        src += src_width;

        dest += dest_row_pitch;

    }

    cpu_physical_memory_unmap(src_base, src_len, 0, 0);

    if (first < 0) {

        return;

    }

    memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,

                              DIRTY_MEMORY_VGA);

    *first_row = first;

    *last_row = last;

}

void FUNC_0(

    DisplayState *VAR_0,

    MemoryRegion *VAR_1,

    target_phys_addr_t VAR_2,

    int VAR_3, 

    int VAR_4, 

    int VAR_5, 

    int VAR_6, 

    int VAR_7, 

    int VAR_8, 

    drawfn VAR_9,

    void *VAR_10,

    int *VAR_11, 

    int *VAR_12 )

{

    target_phys_addr_t src_len;

    uint8_t *dest;

    uint8_t *src;

    uint8_t *src_base;

    int VAR_13, VAR_14 = 0;

    int VAR_15;

    int VAR_16;

    ram_addr_t addr;

    MemoryRegionSection mem_section;

    MemoryRegion *mem;



    VAR_16 = *VAR_11;

    *VAR_11 = -1;

    src_len = VAR_5 * VAR_4;



    mem_section = memory_region_find(VAR_1, VAR_2, src_len);

    if (mem_section.size != src_len || !memory_region_is_ram(mem_section.mr)) {

        return;

    }

    mem = mem_section.mr;

    assert(mem);

    assert(mem_section.offset_within_address_space == VAR_2);



    memory_region_sync_dirty_bitmap(mem);

    src_base = cpu_physical_memory_map(VAR_2, &src_len, 0);

    





    if (!src_base)

        return;

    if (src_len != VAR_5 * VAR_4) {

        cpu_physical_memory_unmap(src_base, src_len, 0, 0);

        return;

    }

    src = src_base;

    dest = ds_get_data(VAR_0);

    if (VAR_7 < 0)

        dest -= VAR_7 * (VAR_3 - 1);

    if (VAR_6 < 0) {

        dest -= VAR_6 * (VAR_4 - 1);

    }

    VAR_13 = -1;

    addr = mem_section.offset_within_region;



    addr += VAR_16 * VAR_5;

    src += VAR_16 * VAR_5;

    dest += VAR_16 * VAR_6;



    for (; VAR_16 < VAR_4; VAR_16++) {

        VAR_15 = memory_region_get_dirty(mem, addr, VAR_5,

                                             DIRTY_MEMORY_VGA);

        if (VAR_15 || VAR_8) {

            VAR_9(VAR_10, dest, src, VAR_3, VAR_7);

            if (VAR_13 == -1)

                VAR_13 = VAR_16;

            VAR_14 = VAR_16;

        }

        addr += VAR_5;

        src += VAR_5;

        dest += VAR_6;

    }

    cpu_physical_memory_unmap(src_base, src_len, 0, 0);

    if (VAR_13 < 0) {

        return;

    }

    memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,

                              DIRTY_MEMORY_VGA);

    *VAR_11 = VAR_13;

    *VAR_12 = VAR_14;

}

void FUNC_0(
DisplayState *VAR_0,
MemoryRegion *VAR_1,
target_phys_addr_t VAR_2,
int VAR_3,
int VAR_4,
int VAR_5,
int VAR_6,
int VAR_7,
int VAR_8,
drawfn VAR_9,
void *VAR_10,
int *VAR_11,
int *VAR_12 )
{ target_phys_addr_t src_len; uint8_t *dest; uint8_t *src; uint8_t *src_base; int VAR_13, VAR_14 = 0; int VAR_15; int VAR_16; ram_addr_t addr; MemoryRegionSection mem_section; MemoryRegion *mem; VAR_16 = *VAR_11; *VAR_11 = -1; src_len = VAR_5 * VAR_4; mem_section = memory_region_find(VAR_1, VAR_2, src_len); if (mem_section.size != src_len || !memory_region_is_ram(mem_section.mr)) { return; } mem = mem_section.mr; assert(mem); assert(mem_section.offset_within_address_space == VAR_2); memory_region_sync_dirty_bitmap(mem); src_base = cpu_physical_memory_map(VAR_2, &src_len, 0); if (!src_base)
return; if (src_len != VAR_5 * VAR_4) { cpu_physical_memory_unmap(src_base, src_len, 0, 0); return; } src = src_base; dest = ds_get_data(VAR_0); if (VAR_7 < 0)
dest -= VAR_7 * (VAR_3 - 1); if (VAR_6 < 0) { dest -= VAR_6 * (VAR_4 - 1); } VAR_13 = -1; addr = mem_section.offset_within_region; addr += VAR_16 * VAR_5; src += VAR_16 * VAR_5; dest += VAR_16 * VAR_6; for (; VAR_16 < VAR_4; VAR_16++) { VAR_15 = memory_region_get_dirty(mem, addr, VAR_5,
DIRTY_MEMORY_VGA); if (VAR_15 || VAR_8) { VAR_9(VAR_10, dest, src, VAR_3, VAR_7); if (VAR_13 == -1)
VAR_13 = VAR_16; VAR_14 = VAR_16; } addr += VAR_5; src += VAR_5; dest += VAR_6; } cpu_physical_memory_unmap(src_base, src_len, 0, 0); if (VAR_13 < 0) { return; } memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,
DIRTY_MEMORY_VGA); *VAR_11 = VAR_13; *VAR_12 = VAR_14; }