static void omap_update_display(void *opaque)

{

    struct omap_lcd_panel_s *omap_lcd = (struct omap_lcd_panel_s *) opaque;

    DisplaySurface *surface = qemu_console_surface(omap_lcd->con);

    draw_line_func draw_line;

    int size, height, first, last;

    int width, linesize, step, bpp, frame_offset;

    hwaddr frame_base;



    if (!omap_lcd || omap_lcd->plm == 1 || !omap_lcd->enable ||

        !surface_bits_per_pixel(surface)) {

        return;

    }



    frame_offset = 0;

    if (omap_lcd->plm != 2) {

        cpu_physical_memory_read(omap_lcd->dma->phys_framebuffer[

                                  omap_lcd->dma->current_frame],

                                 (void *)omap_lcd->palette, 0x200);

        switch (omap_lcd->palette[0] >> 12 & 7) {

        case 3 ... 7:

            frame_offset += 0x200;

            break;

        default:

            frame_offset += 0x20;

        }

    }



    /* Colour depth */

    switch ((omap_lcd->palette[0] >> 12) & 7) {

    case 1:

        draw_line = draw_line_table2[surface_bits_per_pixel(surface)];

        bpp = 2;

        break;



    case 2:

        draw_line = draw_line_table4[surface_bits_per_pixel(surface)];

        bpp = 4;

        break;



    case 3:

        draw_line = draw_line_table8[surface_bits_per_pixel(surface)];

        bpp = 8;

        break;



    case 4 ... 7:

        if (!omap_lcd->tft)

            draw_line = draw_line_table12[surface_bits_per_pixel(surface)];

        else

            draw_line = draw_line_table16[surface_bits_per_pixel(surface)];

        bpp = 16;

        break;



    default:

        /* Unsupported at the moment.  */

        return;

    }



    /* Resolution */

    width = omap_lcd->width;

    if (width != surface_width(surface) ||

        omap_lcd->height != surface_height(surface)) {

        qemu_console_resize(omap_lcd->con,

                            omap_lcd->width, omap_lcd->height);

        surface = qemu_console_surface(omap_lcd->con);

        omap_lcd->invalidate = 1;

    }



    if (omap_lcd->dma->current_frame == 0)

        size = omap_lcd->dma->src_f1_bottom - omap_lcd->dma->src_f1_top;

    else

        size = omap_lcd->dma->src_f2_bottom - omap_lcd->dma->src_f2_top;



    if (frame_offset + ((width * omap_lcd->height * bpp) >> 3) > size + 2) {

        omap_lcd->sync_error = 1;

        omap_lcd_interrupts(omap_lcd);

        omap_lcd->enable = 0;

        return;

    }



    /* Content */

    frame_base = omap_lcd->dma->phys_framebuffer[

            omap_lcd->dma->current_frame] + frame_offset;

    omap_lcd->dma->condition |= 1 << omap_lcd->dma->current_frame;

    if (omap_lcd->dma->interrupts & 1)

        qemu_irq_raise(omap_lcd->dma->irq);

    if (omap_lcd->dma->dual)

        omap_lcd->dma->current_frame ^= 1;



    if (!surface_bits_per_pixel(surface)) {

        return;

    }



    first = 0;

    height = omap_lcd->height;

    if (omap_lcd->subpanel & (1 << 31)) {

        if (omap_lcd->subpanel & (1 << 29))

            first = (omap_lcd->subpanel >> 16) & 0x3ff;

        else

            height = (omap_lcd->subpanel >> 16) & 0x3ff;

        /* TODO: fill the rest of the panel with DPD */

    }



    step = width * bpp >> 3;

    linesize = surface_stride(surface);

    framebuffer_update_display(surface, omap_lcd->sysmem,

                               frame_base, width, height,

                               step, linesize, 0,

                               omap_lcd->invalidate,

                               draw_line, omap_lcd->palette,

                               &first, &last);

    if (first >= 0) {

        dpy_gfx_update(omap_lcd->con, 0, first, width, last - first + 1);

    }

    omap_lcd->invalidate = 0;

}

static void omap_update_display(void *opaque)

{

    struct omap_lcd_panel_s *omap_lcd = (struct omap_lcd_panel_s *) opaque;

    DisplaySurface *surface = qemu_console_surface(omap_lcd->con);

    draw_line_func draw_line;

    int size, height, first, last;

    int width, linesize, step, bpp, frame_offset;

    hwaddr frame_base;



    if (!omap_lcd || omap_lcd->plm == 1 || !omap_lcd->enable ||

        !surface_bits_per_pixel(surface)) {

        return;

    }



    frame_offset = 0;

    if (omap_lcd->plm != 2) {

        cpu_physical_memory_read(omap_lcd->dma->phys_framebuffer[

                                  omap_lcd->dma->current_frame],

                                 (void *)omap_lcd->palette, 0x200);

        switch (omap_lcd->palette[0] >> 12 & 7) {

        case 3 ... 7:

            frame_offset += 0x200;

            break;

        default:

            frame_offset += 0x20;

        }

    }



    

    switch ((omap_lcd->palette[0] >> 12) & 7) {

    case 1:

        draw_line = draw_line_table2[surface_bits_per_pixel(surface)];

        bpp = 2;

        break;



    case 2:

        draw_line = draw_line_table4[surface_bits_per_pixel(surface)];

        bpp = 4;

        break;



    case 3:

        draw_line = draw_line_table8[surface_bits_per_pixel(surface)];

        bpp = 8;

        break;



    case 4 ... 7:

        if (!omap_lcd->tft)

            draw_line = draw_line_table12[surface_bits_per_pixel(surface)];

        else

            draw_line = draw_line_table16[surface_bits_per_pixel(surface)];

        bpp = 16;

        break;



    default:

        

        return;

    }



    

    width = omap_lcd->width;

    if (width != surface_width(surface) ||

        omap_lcd->height != surface_height(surface)) {

        qemu_console_resize(omap_lcd->con,

                            omap_lcd->width, omap_lcd->height);

        surface = qemu_console_surface(omap_lcd->con);

        omap_lcd->invalidate = 1;

    }



    if (omap_lcd->dma->current_frame == 0)

        size = omap_lcd->dma->src_f1_bottom - omap_lcd->dma->src_f1_top;

    else

        size = omap_lcd->dma->src_f2_bottom - omap_lcd->dma->src_f2_top;



    if (frame_offset + ((width * omap_lcd->height * bpp) >> 3) > size + 2) {

        omap_lcd->sync_error = 1;

        omap_lcd_interrupts(omap_lcd);

        omap_lcd->enable = 0;

        return;

    }



    

    frame_base = omap_lcd->dma->phys_framebuffer[

            omap_lcd->dma->current_frame] + frame_offset;

    omap_lcd->dma->condition |= 1 << omap_lcd->dma->current_frame;

    if (omap_lcd->dma->interrupts & 1)

        qemu_irq_raise(omap_lcd->dma->irq);

    if (omap_lcd->dma->dual)

        omap_lcd->dma->current_frame ^= 1;



    if (!surface_bits_per_pixel(surface)) {

        return;

    }



    first = 0;

    height = omap_lcd->height;

    if (omap_lcd->subpanel & (1 << 31)) {

        if (omap_lcd->subpanel & (1 << 29))

            first = (omap_lcd->subpanel >> 16) & 0x3ff;

        else

            height = (omap_lcd->subpanel >> 16) & 0x3ff;

        

    }



    step = width * bpp >> 3;

    linesize = surface_stride(surface);

    framebuffer_update_display(surface, omap_lcd->sysmem,

                               frame_base, width, height,

                               step, linesize, 0,

                               omap_lcd->invalidate,

                               draw_line, omap_lcd->palette,

                               &first, &last);

    if (first >= 0) {

        dpy_gfx_update(omap_lcd->con, 0, first, width, last - first + 1);

    }

    omap_lcd->invalidate = 0;

}

static void FUNC_0(void *VAR_0)

{

    struct omap_lcd_panel_s *VAR_1 = (struct omap_lcd_panel_s *) VAR_0;

    DisplaySurface *surface = qemu_console_surface(VAR_1->con);

    draw_line_func draw_line;

    int VAR_2, VAR_3, VAR_4, VAR_5;

    int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    hwaddr frame_base;



    if (!VAR_1 || VAR_1->plm == 1 || !VAR_1->enable ||

        !surface_bits_per_pixel(surface)) {

        return;

    }



    VAR_10 = 0;

    if (VAR_1->plm != 2) {

        cpu_physical_memory_read(VAR_1->dma->phys_framebuffer[

                                  VAR_1->dma->current_frame],

                                 (void *)VAR_1->palette, 0x200);

        switch (VAR_1->palette[0] >> 12 & 7) {

        case 3 ... 7:

            VAR_10 += 0x200;

            break;

        default:

            VAR_10 += 0x20;

        }

    }



    

    switch ((VAR_1->palette[0] >> 12) & 7) {

    case 1:

        draw_line = draw_line_table2[surface_bits_per_pixel(surface)];

        VAR_9 = 2;

        break;



    case 2:

        draw_line = draw_line_table4[surface_bits_per_pixel(surface)];

        VAR_9 = 4;

        break;



    case 3:

        draw_line = draw_line_table8[surface_bits_per_pixel(surface)];

        VAR_9 = 8;

        break;



    case 4 ... 7:

        if (!VAR_1->tft)

            draw_line = draw_line_table12[surface_bits_per_pixel(surface)];

        else

            draw_line = draw_line_table16[surface_bits_per_pixel(surface)];

        VAR_9 = 16;

        break;



    default:

        

        return;

    }



    

    VAR_6 = VAR_1->VAR_6;

    if (VAR_6 != surface_width(surface) ||

        VAR_1->VAR_3 != surface_height(surface)) {

        qemu_console_resize(VAR_1->con,

                            VAR_1->VAR_6, VAR_1->VAR_3);

        surface = qemu_console_surface(VAR_1->con);

        VAR_1->invalidate = 1;

    }



    if (VAR_1->dma->current_frame == 0)

        VAR_2 = VAR_1->dma->src_f1_bottom - VAR_1->dma->src_f1_top;

    else

        VAR_2 = VAR_1->dma->src_f2_bottom - VAR_1->dma->src_f2_top;



    if (VAR_10 + ((VAR_6 * VAR_1->VAR_3 * VAR_9) >> 3) > VAR_2 + 2) {

        VAR_1->sync_error = 1;

        omap_lcd_interrupts(VAR_1);

        VAR_1->enable = 0;

        return;

    }



    

    frame_base = VAR_1->dma->phys_framebuffer[

            VAR_1->dma->current_frame] + VAR_10;

    VAR_1->dma->condition |= 1 << VAR_1->dma->current_frame;

    if (VAR_1->dma->interrupts & 1)

        qemu_irq_raise(VAR_1->dma->irq);

    if (VAR_1->dma->dual)

        VAR_1->dma->current_frame ^= 1;



    if (!surface_bits_per_pixel(surface)) {

        return;

    }



    VAR_4 = 0;

    VAR_3 = VAR_1->VAR_3;

    if (VAR_1->subpanel & (1 << 31)) {

        if (VAR_1->subpanel & (1 << 29))

            VAR_4 = (VAR_1->subpanel >> 16) & 0x3ff;

        else

            VAR_3 = (VAR_1->subpanel >> 16) & 0x3ff;

        

    }



    VAR_8 = VAR_6 * VAR_9 >> 3;

    VAR_7 = surface_stride(surface);

    framebuffer_update_display(surface, VAR_1->sysmem,

                               frame_base, VAR_6, VAR_3,

                               VAR_8, VAR_7, 0,

                               VAR_1->invalidate,

                               draw_line, VAR_1->palette,

                               &VAR_4, &VAR_5);

    if (VAR_4 >= 0) {

        dpy_gfx_update(VAR_1->con, 0, VAR_4, VAR_6, VAR_5 - VAR_4 + 1);

    }

    VAR_1->invalidate = 0;

}

static void FUNC_0(void *VAR_0)
{ struct omap_lcd_panel_s *VAR_1 = (struct omap_lcd_panel_s *) VAR_0; DisplaySurface *surface = qemu_console_surface(VAR_1->con); draw_line_func draw_line; int VAR_2, VAR_3, VAR_4, VAR_5; int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; hwaddr frame_base; if (!VAR_1 || VAR_1->plm == 1 || !VAR_1->enable ||
!surface_bits_per_pixel(surface)) { return; } VAR_10 = 0; if (VAR_1->plm != 2) { cpu_physical_memory_read(VAR_1->dma->phys_framebuffer[
VAR_1->dma->current_frame],
(void *)VAR_1->palette, 0x200); switch (VAR_1->palette[0] >> 12 & 7) { case 3 ... 7:
VAR_10 += 0x200; break; default:
VAR_10 += 0x20; } } switch ((VAR_1->palette[0] >> 12) & 7) { case 1:
draw_line = draw_line_table2[surface_bits_per_pixel(surface)]; VAR_9 = 2; break; case 2:
draw_line = draw_line_table4[surface_bits_per_pixel(surface)]; VAR_9 = 4; break; case 3:
draw_line = draw_line_table8[surface_bits_per_pixel(surface)]; VAR_9 = 8; break; case 4 ... 7:
if (!VAR_1->tft)
draw_line = draw_line_table12[surface_bits_per_pixel(surface)]; else
draw_line = draw_line_table16[surface_bits_per_pixel(surface)]; VAR_9 = 16; break; default:
return; } VAR_6 = VAR_1->VAR_6; if (VAR_6 != surface_width(surface) ||
VAR_1->VAR_3 != surface_height(surface)) { qemu_console_resize(VAR_1->con,
VAR_1->VAR_6, VAR_1->VAR_3); surface = qemu_console_surface(VAR_1->con); VAR_1->invalidate = 1; } if (VAR_1->dma->current_frame == 0)
VAR_2 = VAR_1->dma->src_f1_bottom - VAR_1->dma->src_f1_top; else
VAR_2 = VAR_1->dma->src_f2_bottom - VAR_1->dma->src_f2_top; if (VAR_10 + ((VAR_6 * VAR_1->VAR_3 * VAR_9) >> 3) > VAR_2 + 2) { VAR_1->sync_error = 1; omap_lcd_interrupts(VAR_1); VAR_1->enable = 0; return; } frame_base = VAR_1->dma->phys_framebuffer[
VAR_1->dma->current_frame] + VAR_10; VAR_1->dma->condition |= 1 << VAR_1->dma->current_frame; if (VAR_1->dma->interrupts & 1)
qemu_irq_raise(VAR_1->dma->irq); if (VAR_1->dma->dual)
VAR_1->dma->current_frame ^= 1; if (!surface_bits_per_pixel(surface)) { return; } VAR_4 = 0; VAR_3 = VAR_1->VAR_3; if (VAR_1->subpanel & (1 << 31)) { if (VAR_1->subpanel & (1 << 29))
VAR_4 = (VAR_1->subpanel >> 16) & 0x3ff; else
VAR_3 = (VAR_1->subpanel >> 16) & 0x3ff; } VAR_8 = VAR_6 * VAR_9 >> 3; VAR_7 = surface_stride(surface); framebuffer_update_display(surface, VAR_1->sysmem,
frame_base, VAR_6, VAR_3,
VAR_8, VAR_7, 0,
VAR_1->invalidate,
draw_line, VAR_1->palette,
&VAR_4, &VAR_5); if (VAR_4 >= 0) { dpy_gfx_update(VAR_1->con, 0, VAR_4, VAR_6, VAR_5 - VAR_4 + 1); } VAR_1->invalidate = 0; }