Commit 799e709b43a8a2ca19db3153d45f0eba934025c2

Authored by aliguori
1 parent 3e00b3f5

Revert r6989

There is a much more elegant fix that will follow up after this commit.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7025 c046a42c-6fe2-441c-8c8c-71466251a162
hw/cirrus_vga.c
@@ -1392,8 +1392,6 @@ cirrus_hook_write_sr(CirrusVGAState * s, unsigned reg_index, int reg_value) @@ -1392,8 +1392,6 @@ cirrus_hook_write_sr(CirrusVGAState * s, unsigned reg_index, int reg_value)
1392 break; 1392 break;
1393 } 1393 }
1394 1394
1395 - vga_update_resolution((VGAState *)s);  
1396 -  
1397 return CIRRUS_HOOK_HANDLED; 1395 return CIRRUS_HOOK_HANDLED;
1398 } 1396 }
1399 1397
@@ -1421,7 +1419,6 @@ static void cirrus_write_hidden_dac(CirrusVGAState * s, int reg_value) @@ -1421,7 +1419,6 @@ static void cirrus_write_hidden_dac(CirrusVGAState * s, int reg_value)
1421 #endif 1419 #endif
1422 } 1420 }
1423 s->cirrus_hidden_dac_lockindex = 0; 1421 s->cirrus_hidden_dac_lockindex = 0;
1424 - vga_update_resolution((VGAState *)s);  
1425 } 1422 }
1426 1423
1427 /*************************************** 1424 /***************************************
@@ -1708,8 +1705,6 @@ cirrus_hook_write_cr(CirrusVGAState * s, unsigned reg_index, int reg_value) @@ -1708,8 +1705,6 @@ cirrus_hook_write_cr(CirrusVGAState * s, unsigned reg_index, int reg_value)
1708 break; 1705 break;
1709 } 1706 }
1710 1707
1711 - vga_update_resolution((VGAState *)s);  
1712 -  
1713 return CIRRUS_HOOK_HANDLED; 1708 return CIRRUS_HOOK_HANDLED;
1714 } 1709 }
1715 1710
@@ -2835,7 +2830,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -2835,7 +2830,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
2835 if (s->ar_flip_flop == 0) { 2830 if (s->ar_flip_flop == 0) {
2836 val &= 0x3f; 2831 val &= 0x3f;
2837 s->ar_index = val; 2832 s->ar_index = val;
2838 - vga_update_resolution((VGAState *)s);  
2839 } else { 2833 } else {
2840 index = s->ar_index & 0x1f; 2834 index = s->ar_index & 0x1f;
2841 switch (index) { 2835 switch (index) {
@@ -2929,7 +2923,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -2929,7 +2923,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
2929 /* can always write bit 4 of CR7 */ 2923 /* can always write bit 4 of CR7 */
2930 if (s->cr_index == 7) 2924 if (s->cr_index == 7)
2931 s->cr[7] = (s->cr[7] & ~0x10) | (val & 0x10); 2925 s->cr[7] = (s->cr[7] & ~0x10) | (val & 0x10);
2932 - vga_update_resolution((VGAState *)s);  
2933 return; 2926 return;
2934 } 2927 }
2935 switch (s->cr_index) { 2928 switch (s->cr_index) {
@@ -2958,7 +2951,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -2958,7 +2951,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
2958 s->update_retrace_info((VGAState *) s); 2951 s->update_retrace_info((VGAState *) s);
2959 break; 2952 break;
2960 } 2953 }
2961 - vga_update_resolution((VGAState *)s);  
2962 break; 2954 break;
2963 case 0x3ba: 2955 case 0x3ba:
2964 case 0x3da: 2956 case 0x3da:
@@ -3165,8 +3157,7 @@ static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id) @@ -3165,8 +3157,7 @@ static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
3165 3157
3166 cirrus_update_memory_access(s); 3158 cirrus_update_memory_access(s);
3167 /* force refresh */ 3159 /* force refresh */
3168 - vga_update_resolution((VGAState *)s);  
3169 - s->want_full_update = 1; 3160 + s->graphic_mode = -1;
3170 cirrus_update_bank_ptr(s, 0); 3161 cirrus_update_bank_ptr(s, 0);
3171 cirrus_update_bank_ptr(s, 1); 3162 cirrus_update_bank_ptr(s, 1);
3172 return 0; 3163 return 0;
hw/vga.c
@@ -36,10 +36,6 @@ @@ -36,10 +36,6 @@
36 36
37 //#define DEBUG_BOCHS_VBE 37 //#define DEBUG_BOCHS_VBE
38 38
39 -#define GMODE_TEXT 0  
40 -#define GMODE_GRAPH 1  
41 -#define GMODE_BLANK 2  
42 -  
43 /* force some bits to zero */ 39 /* force some bits to zero */
44 const uint8_t sr_mask[8] = { 40 const uint8_t sr_mask[8] = {
45 0x03, 41 0x03,
@@ -397,7 +393,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -397,7 +393,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
397 if (s->ar_flip_flop == 0) { 393 if (s->ar_flip_flop == 0) {
398 val &= 0x3f; 394 val &= 0x3f;
399 s->ar_index = val; 395 s->ar_index = val;
400 - vga_update_resolution(s);  
401 } else { 396 } else {
402 index = s->ar_index & 0x1f; 397 index = s->ar_index & 0x1f;
403 switch(index) { 398 switch(index) {
@@ -438,7 +433,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -438,7 +433,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
438 #endif 433 #endif
439 s->sr[s->sr_index] = val & sr_mask[s->sr_index]; 434 s->sr[s->sr_index] = val & sr_mask[s->sr_index];
440 if (s->sr_index == 1) s->update_retrace_info(s); 435 if (s->sr_index == 1) s->update_retrace_info(s);
441 - vga_update_resolution(s);  
442 break; 436 break;
443 case 0x3c7: 437 case 0x3c7:
444 s->dac_read_index = val; 438 s->dac_read_index = val;
@@ -466,7 +460,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -466,7 +460,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
466 printf("vga: write GR%x = 0x%02x\n", s->gr_index, val); 460 printf("vga: write GR%x = 0x%02x\n", s->gr_index, val);
467 #endif 461 #endif
468 s->gr[s->gr_index] = val & gr_mask[s->gr_index]; 462 s->gr[s->gr_index] = val & gr_mask[s->gr_index];
469 - vga_update_resolution(s);  
470 break; 463 break;
471 case 0x3b4: 464 case 0x3b4:
472 case 0x3d4: 465 case 0x3d4:
@@ -482,7 +475,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -482,7 +475,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
482 /* can always write bit 4 of CR7 */ 475 /* can always write bit 4 of CR7 */
483 if (s->cr_index == 7) 476 if (s->cr_index == 7)
484 s->cr[7] = (s->cr[7] & ~0x10) | (val & 0x10); 477 s->cr[7] = (s->cr[7] & ~0x10) | (val & 0x10);
485 - vga_update_resolution(s);  
486 return; 478 return;
487 } 479 }
488 switch(s->cr_index) { 480 switch(s->cr_index) {
@@ -510,7 +502,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val) @@ -510,7 +502,6 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
510 s->update_retrace_info(s); 502 s->update_retrace_info(s);
511 break; 503 break;
512 } 504 }
513 - vga_update_resolution(s);  
514 break; 505 break;
515 case 0x3ba: 506 case 0x3ba:
516 case 0x3da: 507 case 0x3da:
@@ -590,13 +581,11 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) @@ -590,13 +581,11 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
590 if ((val <= VBE_DISPI_MAX_XRES) && ((val & 7) == 0)) { 581 if ((val <= VBE_DISPI_MAX_XRES) && ((val & 7) == 0)) {
591 s->vbe_regs[s->vbe_index] = val; 582 s->vbe_regs[s->vbe_index] = val;
592 } 583 }
593 - vga_update_resolution(s);  
594 break; 584 break;
595 case VBE_DISPI_INDEX_YRES: 585 case VBE_DISPI_INDEX_YRES:
596 if (val <= VBE_DISPI_MAX_YRES) { 586 if (val <= VBE_DISPI_MAX_YRES) {
597 s->vbe_regs[s->vbe_index] = val; 587 s->vbe_regs[s->vbe_index] = val;
598 } 588 }
599 - vga_update_resolution(s);  
600 break; 589 break;
601 case VBE_DISPI_INDEX_BPP: 590 case VBE_DISPI_INDEX_BPP:
602 if (val == 0) 591 if (val == 0)
@@ -605,7 +594,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) @@ -605,7 +594,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
605 val == 16 || val == 24 || val == 32) { 594 val == 16 || val == 24 || val == 32) {
606 s->vbe_regs[s->vbe_index] = val; 595 s->vbe_regs[s->vbe_index] = val;
607 } 596 }
608 - vga_update_resolution(s);  
609 break; 597 break;
610 case VBE_DISPI_INDEX_BANK: 598 case VBE_DISPI_INDEX_BANK:
611 if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) { 599 if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) {
@@ -674,7 +662,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) @@ -674,7 +662,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
674 } 662 }
675 s->dac_8bit = (val & VBE_DISPI_8BIT_DAC) > 0; 663 s->dac_8bit = (val & VBE_DISPI_8BIT_DAC) > 0;
676 s->vbe_regs[s->vbe_index] = val; 664 s->vbe_regs[s->vbe_index] = val;
677 - vga_update_resolution(s);  
678 break; 665 break;
679 case VBE_DISPI_INDEX_VIRT_WIDTH: 666 case VBE_DISPI_INDEX_VIRT_WIDTH:
680 { 667 {
@@ -695,7 +682,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) @@ -695,7 +682,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
695 s->vbe_regs[VBE_DISPI_INDEX_VIRT_HEIGHT] = h; 682 s->vbe_regs[VBE_DISPI_INDEX_VIRT_HEIGHT] = h;
696 s->vbe_line_offset = line_offset; 683 s->vbe_line_offset = line_offset;
697 } 684 }
698 - vga_update_resolution(s);  
699 break; 685 break;
700 case VBE_DISPI_INDEX_X_OFFSET: 686 case VBE_DISPI_INDEX_X_OFFSET:
701 case VBE_DISPI_INDEX_Y_OFFSET: 687 case VBE_DISPI_INDEX_Y_OFFSET:
@@ -710,7 +696,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) @@ -710,7 +696,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
710 s->vbe_start_addr += x * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3); 696 s->vbe_start_addr += x * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
711 s->vbe_start_addr >>= 2; 697 s->vbe_start_addr >>= 2;
712 } 698 }
713 - vga_update_resolution(s);  
714 break; 699 break;
715 default: 700 default:
716 break; 701 break;
@@ -1317,6 +1302,7 @@ static void vga_draw_text(VGAState *s, int full_update) @@ -1317,6 +1302,7 @@ static void vga_draw_text(VGAState *s, int full_update)
1317 s->plane_updated = 0; 1302 s->plane_updated = 0;
1318 full_update = 1; 1303 full_update = 1;
1319 } 1304 }
  1305 + full_update |= update_basic_params(s);
1320 1306
1321 line_offset = s->line_offset; 1307 line_offset = s->line_offset;
1322 s1 = s->vram_ptr + (s->start_addr * 4); 1308 s1 = s->vram_ptr + (s->start_addr * 4);
@@ -1328,6 +1314,18 @@ static void vga_draw_text(VGAState *s, int full_update) @@ -1328,6 +1314,18 @@ static void vga_draw_text(VGAState *s, int full_update)
1328 return; 1314 return;
1329 } 1315 }
1330 1316
  1317 + if (width != s->last_width || height != s->last_height ||
  1318 + cw != s->last_cw || cheight != s->last_ch || s->last_depth) {
  1319 + s->last_scr_width = width * cw;
  1320 + s->last_scr_height = height * cheight;
  1321 + qemu_console_resize(s->ds, s->last_scr_width, s->last_scr_height);
  1322 + s->last_depth = 0;
  1323 + s->last_width = width;
  1324 + s->last_height = height;
  1325 + s->last_ch = cheight;
  1326 + s->last_cw = cw;
  1327 + full_update = 1;
  1328 + }
1331 s->rgb_to_pixel = 1329 s->rgb_to_pixel =
1332 rgb_to_pixel_dup_table[get_depth_index(s->ds)]; 1330 rgb_to_pixel_dup_table[get_depth_index(s->ds)];
1333 full_update |= update_palette16(s); 1331 full_update |= update_palette16(s);
@@ -1584,21 +1582,39 @@ static void vga_sync_dirty_bitmap(VGAState *s) @@ -1584,21 +1582,39 @@ static void vga_sync_dirty_bitmap(VGAState *s)
1584 vga_dirty_log_start(s); 1582 vga_dirty_log_start(s);
1585 } 1583 }
1586 1584
1587 -static void vga_update_resolution_graphics(VGAState *s) 1585 +/*
  1586 + * graphic modes
  1587 + */
  1588 +static void vga_draw_graphic(VGAState *s, int full_update)
1588 { 1589 {
1589 - int depth = s->get_bpp(s);  
1590 - int width, height, shift_control, double_scan; 1590 + int y1, y, update, page_min, page_max, linesize, y_start, double_scan, mask, depth;
  1591 + int width, height, shift_control, line_offset, page0, page1, bwidth, bits;
1591 int disp_width, multi_scan, multi_run; 1592 int disp_width, multi_scan, multi_run;
  1593 + uint8_t *d;
  1594 + uint32_t v, addr1, addr;
  1595 + vga_draw_line_func *vga_draw_line;
  1596 +
  1597 + full_update |= update_basic_params(s);
  1598 +
  1599 + if (!full_update)
  1600 + vga_sync_dirty_bitmap(s);
1592 1601
1593 s->get_resolution(s, &width, &height); 1602 s->get_resolution(s, &width, &height);
1594 disp_width = width; 1603 disp_width = width;
1595 1604
1596 shift_control = (s->gr[0x05] >> 5) & 3; 1605 shift_control = (s->gr[0x05] >> 5) & 3;
1597 double_scan = (s->cr[0x09] >> 7); 1606 double_scan = (s->cr[0x09] >> 7);
1598 - 1607 + if (shift_control != 1) {
  1608 + multi_scan = (((s->cr[0x09] & 0x1f) + 1) << double_scan) - 1;
  1609 + } else {
  1610 + /* in CGA modes, multi_scan is ignored */
  1611 + /* XXX: is it correct ? */
  1612 + multi_scan = double_scan;
  1613 + }
  1614 + multi_run = multi_scan;
1599 if (shift_control != s->shift_control || 1615 if (shift_control != s->shift_control ||
1600 double_scan != s->double_scan) { 1616 double_scan != s->double_scan) {
1601 - s->want_full_update = 1; 1617 + full_update = 1;
1602 s->shift_control = shift_control; 1618 s->shift_control = shift_control;
1603 s->double_scan = double_scan; 1619 s->double_scan = double_scan;
1604 } 1620 }
@@ -1612,28 +1628,12 @@ static void vga_update_resolution_graphics(VGAState *s) @@ -1612,28 +1628,12 @@ static void vga_update_resolution_graphics(VGAState *s)
1612 disp_width <<= 1; 1628 disp_width <<= 1;
1613 } 1629 }
1614 } 1630 }
1615 - disp_width = width;  
1616 -  
1617 - if (shift_control != 1) {  
1618 - multi_scan = (((s->cr[0x09] & 0x1f) + 1) << double_scan) - 1;  
1619 - } else {  
1620 - /* in CGA modes, multi_scan is ignored */  
1621 - /* XXX: is it correct ? */  
1622 - multi_scan = double_scan;  
1623 - }  
1624 -  
1625 - multi_run = multi_scan;  
1626 1631
  1632 + depth = s->get_bpp(s);
1627 if (s->line_offset != s->last_line_offset || 1633 if (s->line_offset != s->last_line_offset ||
1628 disp_width != s->last_width || 1634 disp_width != s->last_width ||
1629 height != s->last_height || 1635 height != s->last_height ||
1630 - s->last_depth != depth ||  
1631 - s->multi_run != multi_run ||  
1632 - s->multi_scan != multi_scan ||  
1633 - s->want_full_update) {  
1634 - if (s->ds->surface->pf.depth == 0) {  
1635 - goto dont_touch_display_surface;  
1636 - } 1636 + s->last_depth != depth) {
1637 #if defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN) 1637 #if defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
1638 if (depth == 16 || depth == 32) { 1638 if (depth == 16 || depth == 32) {
1639 #else 1639 #else
@@ -1650,91 +1650,14 @@ static void vga_update_resolution_graphics(VGAState *s) @@ -1650,91 +1650,14 @@ static void vga_update_resolution_graphics(VGAState *s)
1650 } else { 1650 } else {
1651 qemu_console_resize(s->ds, disp_width, height); 1651 qemu_console_resize(s->ds, disp_width, height);
1652 } 1652 }
1653 - dont_touch_display_surface:  
1654 s->last_scr_width = disp_width; 1653 s->last_scr_width = disp_width;
1655 s->last_scr_height = height; 1654 s->last_scr_height = height;
1656 s->last_width = disp_width; 1655 s->last_width = disp_width;
1657 s->last_height = height; 1656 s->last_height = height;
1658 s->last_line_offset = s->line_offset; 1657 s->last_line_offset = s->line_offset;
1659 s->last_depth = depth; 1658 s->last_depth = depth;
1660 - s->multi_run = multi_run;  
1661 - s->multi_scan = multi_scan;  
1662 - s->want_full_update = 1;  
1663 - }  
1664 -}  
1665 -  
1666 -static void vga_update_resolution_text(VGAState *s)  
1667 -{  
1668 - int width, height, cw, cheight;  
1669 -  
1670 - vga_get_text_resolution(s, &width, &height, &cw, &cheight);  
1671 - if (width != s->last_width || height != s->last_height ||  
1672 - cw != s->last_cw || cheight != s->last_ch || s->last_depth) {  
1673 - s->last_scr_width = width * cw;  
1674 - s->last_scr_height = height * cheight;  
1675 - if (s->ds->surface->pf.depth != 0) {  
1676 - qemu_console_resize(s->ds, s->last_scr_width, s->last_scr_height);  
1677 - } else {  
1678 - /*  
1679 - * curses expects width and height to be in character cell  
1680 - * dimensions, not pixels.  
1681 - */  
1682 - s->ds->surface->width = width;  
1683 - s->ds->surface->height = height;  
1684 - dpy_resize(s->ds);  
1685 - }  
1686 - s->last_depth = 0;  
1687 - s->last_width = width;  
1688 - s->last_height = height;  
1689 - s->last_ch = cheight;  
1690 - s->last_cw = cw;  
1691 - s->want_full_update = 1;  
1692 - }  
1693 -}  
1694 -  
1695 -void vga_update_resolution(VGAState *s)  
1696 -{  
1697 - int graphic_mode;  
1698 -  
1699 - if (!(s->ar_index & 0x20)) {  
1700 - graphic_mode = GMODE_BLANK;  
1701 - } else {  
1702 - graphic_mode = s->gr[6] & 1;  
1703 - }  
1704 - if (graphic_mode != s->graphic_mode) {  
1705 - s->graphic_mode = graphic_mode;  
1706 - s->want_full_update = 1;  
1707 - }  
1708 - s->want_full_update |= update_basic_params(s);  
1709 - switch (graphic_mode) {  
1710 - case GMODE_TEXT:  
1711 - vga_update_resolution_text(s);  
1712 - break;  
1713 - case GMODE_GRAPH:  
1714 - vga_update_resolution_graphics(s);  
1715 - break;  
1716 - }  
1717 -}  
1718 -  
1719 -/*  
1720 - * graphic modes  
1721 - */  
1722 -static void vga_draw_graphic(VGAState *s, int full_update)  
1723 -{  
1724 - int y1, y, update, linesize, y_start, mask;  
1725 - int width, height, line_offset, bwidth, bits;  
1726 - int multi_run;  
1727 - uint8_t *d;  
1728 - uint32_t v, addr1, addr;  
1729 - long page0, page1, page_min, page_max;  
1730 - vga_draw_line_func *vga_draw_line;  
1731 -  
1732 - if (!full_update)  
1733 - vga_sync_dirty_bitmap(s);  
1734 -  
1735 - s->get_resolution(s, &width, &height);  
1736 - multi_run = s->multi_run;  
1737 - if (is_buffer_shared(s->ds->surface) && 1659 + full_update = 1;
  1660 + } else if (is_buffer_shared(s->ds->surface) &&
1738 (full_update || s->ds->surface->data != s->vram_ptr + (s->start_addr * 4))) { 1661 (full_update || s->ds->surface->data != s->vram_ptr + (s->start_addr * 4))) {
1739 s->ds->surface->data = s->vram_ptr + (s->start_addr * 4); 1662 s->ds->surface->data = s->vram_ptr + (s->start_addr * 4);
1740 dpy_setdata(s->ds); 1663 dpy_setdata(s->ds);
@@ -1743,7 +1666,7 @@ static void vga_draw_graphic(VGAState *s, int full_update) @@ -1743,7 +1666,7 @@ static void vga_draw_graphic(VGAState *s, int full_update)
1743 s->rgb_to_pixel = 1666 s->rgb_to_pixel =
1744 rgb_to_pixel_dup_table[get_depth_index(s->ds)]; 1667 rgb_to_pixel_dup_table[get_depth_index(s->ds)];
1745 1668
1746 - if (s->shift_control == 0) { 1669 + if (shift_control == 0) {
1747 full_update |= update_palette16(s); 1670 full_update |= update_palette16(s);
1748 if (s->sr[0x01] & 8) { 1671 if (s->sr[0x01] & 8) {
1749 v = VGA_DRAW_LINE4D2; 1672 v = VGA_DRAW_LINE4D2;
@@ -1751,7 +1674,7 @@ static void vga_draw_graphic(VGAState *s, int full_update) @@ -1751,7 +1674,7 @@ static void vga_draw_graphic(VGAState *s, int full_update)
1751 v = VGA_DRAW_LINE4; 1674 v = VGA_DRAW_LINE4;
1752 } 1675 }
1753 bits = 4; 1676 bits = 4;
1754 - } else if (s->shift_control == 1) { 1677 + } else if (shift_control == 1) {
1755 full_update |= update_palette16(s); 1678 full_update |= update_palette16(s);
1756 if (s->sr[0x01] & 8) { 1679 if (s->sr[0x01] & 8) {
1757 v = VGA_DRAW_LINE2D2; 1680 v = VGA_DRAW_LINE2D2;
@@ -1847,7 +1770,7 @@ static void vga_draw_graphic(VGAState *s, int full_update) @@ -1847,7 +1770,7 @@ static void vga_draw_graphic(VGAState *s, int full_update)
1847 if (y_start >= 0) { 1770 if (y_start >= 0) {
1848 /* flush to display */ 1771 /* flush to display */
1849 dpy_update(s->ds, 0, y_start, 1772 dpy_update(s->ds, 0, y_start,
1850 - s->last_width, y - y_start); 1773 + disp_width, y - y_start);
1851 y_start = -1; 1774 y_start = -1;
1852 } 1775 }
1853 } 1776 }
@@ -1856,7 +1779,7 @@ static void vga_draw_graphic(VGAState *s, int full_update) @@ -1856,7 +1779,7 @@ static void vga_draw_graphic(VGAState *s, int full_update)
1856 if ((y1 & mask) == mask) 1779 if ((y1 & mask) == mask)
1857 addr1 += line_offset; 1780 addr1 += line_offset;
1858 y1++; 1781 y1++;
1859 - multi_run = s->multi_scan; 1782 + multi_run = multi_scan;
1860 } else { 1783 } else {
1861 multi_run--; 1784 multi_run--;
1862 } 1785 }
@@ -1868,7 +1791,7 @@ static void vga_draw_graphic(VGAState *s, int full_update) @@ -1868,7 +1791,7 @@ static void vga_draw_graphic(VGAState *s, int full_update)
1868 if (y_start >= 0) { 1791 if (y_start >= 0) {
1869 /* flush to display */ 1792 /* flush to display */
1870 dpy_update(s->ds, 0, y_start, 1793 dpy_update(s->ds, 0, y_start,
1871 - s->last_width, y - y_start); 1794 + disp_width, y - y_start);
1872 } 1795 }
1873 /* reset modified pages */ 1796 /* reset modified pages */
1874 if (page_max != -1) { 1797 if (page_max != -1) {
@@ -1905,17 +1828,29 @@ static void vga_draw_blank(VGAState *s, int full_update) @@ -1905,17 +1828,29 @@ static void vga_draw_blank(VGAState *s, int full_update)
1905 s->last_scr_width, s->last_scr_height); 1828 s->last_scr_width, s->last_scr_height);
1906 } 1829 }
1907 1830
  1831 +#define GMODE_TEXT 0
  1832 +#define GMODE_GRAPH 1
  1833 +#define GMODE_BLANK 2
  1834 +
1908 static void vga_update_display(void *opaque) 1835 static void vga_update_display(void *opaque)
1909 { 1836 {
1910 VGAState *s = (VGAState *)opaque; 1837 VGAState *s = (VGAState *)opaque;
1911 - int full_update; 1838 + int full_update, graphic_mode;
1912 1839
1913 if (ds_get_bits_per_pixel(s->ds) == 0) { 1840 if (ds_get_bits_per_pixel(s->ds) == 0) {
1914 /* nothing to do */ 1841 /* nothing to do */
1915 } else { 1842 } else {
1916 - full_update = s->want_full_update;  
1917 - s->want_full_update = 0;  
1918 - switch(s->graphic_mode) { 1843 + full_update = 0;
  1844 + if (!(s->ar_index & 0x20)) {
  1845 + graphic_mode = GMODE_BLANK;
  1846 + } else {
  1847 + graphic_mode = s->gr[6] & 1;
  1848 + }
  1849 + if (graphic_mode != s->graphic_mode) {
  1850 + s->graphic_mode = graphic_mode;
  1851 + full_update = 1;
  1852 + }
  1853 + switch(graphic_mode) {
1919 case GMODE_TEXT: 1854 case GMODE_TEXT:
1920 vga_draw_text(s, full_update); 1855 vga_draw_text(s, full_update);
1921 break; 1856 break;
@@ -1935,8 +1870,8 @@ static void vga_invalidate_display(void *opaque) @@ -1935,8 +1870,8 @@ static void vga_invalidate_display(void *opaque)
1935 { 1870 {
1936 VGAState *s = (VGAState *)opaque; 1871 VGAState *s = (VGAState *)opaque;
1937 1872
1938 - vga_update_resolution(s);  
1939 - s->want_full_update = 1; 1873 + s->last_width = -1;
  1874 + s->last_height = -1;
1940 } 1875 }
1941 1876
1942 void vga_reset(void *opaque) 1877 void vga_reset(void *opaque)
@@ -1980,6 +1915,7 @@ void vga_reset(void *opaque) @@ -1980,6 +1915,7 @@ void vga_reset(void *opaque)
1980 s->vbe_bank_mask = (s->vram_size >> 16) - 1; 1915 s->vbe_bank_mask = (s->vram_size >> 16) - 1;
1981 #endif 1916 #endif
1982 memset(s->font_offsets, '\0', sizeof(s->font_offsets)); 1917 memset(s->font_offsets, '\0', sizeof(s->font_offsets));
  1918 + s->graphic_mode = -1; /* force full update */
1983 s->shift_control = 0; 1919 s->shift_control = 0;
1984 s->double_scan = 0; 1920 s->double_scan = 0;
1985 s->line_offset = 0; 1921 s->line_offset = 0;
@@ -2005,7 +1941,6 @@ void vga_reset(void *opaque) @@ -2005,7 +1941,6 @@ void vga_reset(void *opaque)
2005 memset(&s->retrace_info, 0, sizeof (s->retrace_info)); 1941 memset(&s->retrace_info, 0, sizeof (s->retrace_info));
2006 break; 1942 break;
2007 } 1943 }
2008 - vga_update_resolution(s);  
2009 } 1944 }
2010 1945
2011 #define TEXTMODE_X(x) ((x) % width) 1946 #define TEXTMODE_X(x) ((x) % width)
@@ -2017,28 +1952,50 @@ void vga_reset(void *opaque) @@ -2017,28 +1952,50 @@ void vga_reset(void *opaque)
2017 static void vga_update_text(void *opaque, console_ch_t *chardata) 1952 static void vga_update_text(void *opaque, console_ch_t *chardata)
2018 { 1953 {
2019 VGAState *s = (VGAState *) opaque; 1954 VGAState *s = (VGAState *) opaque;
2020 - int i, cursor_offset, cursor_visible; 1955 + int graphic_mode, i, cursor_offset, cursor_visible;
2021 int cw, cheight, width, height, size, c_min, c_max; 1956 int cw, cheight, width, height, size, c_min, c_max;
2022 uint32_t *src; 1957 uint32_t *src;
2023 console_ch_t *dst, val; 1958 console_ch_t *dst, val;
2024 char msg_buffer[80]; 1959 char msg_buffer[80];
2025 - int full_update = s->want_full_update; 1960 + int full_update = 0;
  1961 +
  1962 + if (!(s->ar_index & 0x20)) {
  1963 + graphic_mode = GMODE_BLANK;
  1964 + } else {
  1965 + graphic_mode = s->gr[6] & 1;
  1966 + }
  1967 + if (graphic_mode != s->graphic_mode) {
  1968 + s->graphic_mode = graphic_mode;
  1969 + full_update = 1;
  1970 + }
  1971 + if (s->last_width == -1) {
  1972 + s->last_width = 0;
  1973 + full_update = 1;
  1974 + }
2026 1975
2027 - s->want_full_update = 0;  
2028 - switch (s->graphic_mode) { 1976 + switch (graphic_mode) {
2029 case GMODE_TEXT: 1977 case GMODE_TEXT:
2030 /* TODO: update palette */ 1978 /* TODO: update palette */
  1979 + full_update |= update_basic_params(s);
2031 1980
2032 - vga_get_text_resolution(s, &width, &height, &cw, &cheight);  
2033 -  
2034 - if (s->ds->surface->width != width  
2035 - || s->ds->surface->height != height) {  
2036 - s->ds->surface->width = width;  
2037 - s->ds->surface->height = height;  
2038 - dpy_resize(s->ds); 1981 + /* total width & height */
  1982 + cheight = (s->cr[9] & 0x1f) + 1;
  1983 + cw = 8;
  1984 + if (!(s->sr[1] & 0x01))
  1985 + cw = 9;
  1986 + if (s->sr[1] & 0x08)
  1987 + cw = 16; /* NOTE: no 18 pixel wide */
  1988 + width = (s->cr[0x01] + 1);
  1989 + if (s->cr[0x06] == 100) {
  1990 + /* ugly hack for CGA 160x100x16 - explain me the logic */
  1991 + height = 100;
  1992 + } else {
  1993 + height = s->cr[0x12] |
  1994 + ((s->cr[0x07] & 0x02) << 7) |
  1995 + ((s->cr[0x07] & 0x40) << 3);
  1996 + height = (height + 1) / cheight;
2039 } 1997 }
2040 1998
2041 - /* total width & height */  
2042 size = (height * width); 1999 size = (height * width);
2043 if (size > CH_ATTR_SIZE) { 2000 if (size > CH_ATTR_SIZE) {
2044 if (!full_update) 2001 if (!full_update)
@@ -2049,6 +2006,20 @@ static void vga_update_text(void *opaque, console_ch_t *chardata) @@ -2049,6 +2006,20 @@ static void vga_update_text(void *opaque, console_ch_t *chardata)
2049 break; 2006 break;
2050 } 2007 }
2051 2008
  2009 + if (width != s->last_width || height != s->last_height ||
  2010 + cw != s->last_cw || cheight != s->last_ch) {
  2011 + s->last_scr_width = width * cw;
  2012 + s->last_scr_height = height * cheight;
  2013 + s->ds->surface->width = width;
  2014 + s->ds->surface->height = height;
  2015 + dpy_resize(s->ds);
  2016 + s->last_width = width;
  2017 + s->last_height = height;
  2018 + s->last_ch = cheight;
  2019 + s->last_cw = cw;
  2020 + full_update = 1;
  2021 + }
  2022 +
2052 /* Update "hardware" cursor */ 2023 /* Update "hardware" cursor */
2053 cursor_offset = ((s->cr[0x0e] << 8) | s->cr[0x0f]) - s->start_addr; 2024 cursor_offset = ((s->cr[0x0e] << 8) | s->cr[0x0f]) - s->start_addr;
2054 if (cursor_offset != s->cursor_offset || 2025 if (cursor_offset != s->cursor_offset ||
@@ -2247,8 +2218,7 @@ static int vga_load(QEMUFile *f, void *opaque, int version_id) @@ -2247,8 +2218,7 @@ static int vga_load(QEMUFile *f, void *opaque, int version_id)
2247 #endif 2218 #endif
2248 2219
2249 /* force refresh */ 2220 /* force refresh */
2250 - vga_update_resolution(s);  
2251 - s->want_full_update = 1; 2221 + s->graphic_mode = -1;
2252 return 0; 2222 return 0;
2253 } 2223 }
2254 2224
@@ -2671,8 +2641,7 @@ static void vga_screen_dump_common(VGAState *s, const char *filename, @@ -2671,8 +2641,7 @@ static void vga_screen_dump_common(VGAState *s, const char *filename,
2671 ds->surface = qemu_create_displaysurface(ds, w, h); 2641 ds->surface = qemu_create_displaysurface(ds, w, h);
2672 2642
2673 s->ds = ds; 2643 s->ds = ds;
2674 - vga_update_resolution(s);  
2675 - s->want_full_update = 1; 2644 + s->graphic_mode = -1;
2676 vga_update_display(s); 2645 vga_update_display(s);
2677 2646
2678 ppm_save(filename, ds->surface); 2647 ppm_save(filename, ds->surface);
@@ -2703,16 +2672,10 @@ static void vga_screen_dump(void *opaque, const char *filename) @@ -2703,16 +2672,10 @@ static void vga_screen_dump(void *opaque, const char *filename)
2703 { 2672 {
2704 VGAState *s = (VGAState *)opaque; 2673 VGAState *s = (VGAState *)opaque;
2705 2674
2706 - switch (s->graphic_mode) {  
2707 - case GMODE_TEXT:  
2708 - vga_screen_dump_text(s, filename);  
2709 - break;  
2710 - case GMODE_GRAPH:  
2711 - vga_screen_dump_graphic(s, filename);  
2712 - break;  
2713 - case GMODE_BLANK:  
2714 - default: 2675 + if (!(s->ar_index & 0x20))
2715 vga_screen_dump_blank(s, filename); 2676 vga_screen_dump_blank(s, filename);
2716 - break;  
2717 - } 2677 + else if (s->gr[6] & 1)
  2678 + vga_screen_dump_graphic(s, filename);
  2679 + else
  2680 + vga_screen_dump_text(s, filename);
2718 } 2681 }
hw/vga_int.h
@@ -147,11 +147,8 @@ typedef void (* vga_update_retrace_info_fn)(struct VGAState *s); @@ -147,11 +147,8 @@ typedef void (* vga_update_retrace_info_fn)(struct VGAState *s);
147 DisplayState *ds; \ 147 DisplayState *ds; \
148 uint32_t font_offsets[2]; \ 148 uint32_t font_offsets[2]; \
149 int graphic_mode; \ 149 int graphic_mode; \
150 - int want_full_update; \  
151 uint8_t shift_control; \ 150 uint8_t shift_control; \
152 uint8_t double_scan; \ 151 uint8_t double_scan; \
153 - uint8_t multi_run; \  
154 - uint8_t multi_scan; \  
155 uint32_t line_offset; \ 152 uint32_t line_offset; \
156 uint32_t line_compare; \ 153 uint32_t line_compare; \
157 uint32_t start_addr; \ 154 uint32_t start_addr; \
@@ -198,7 +195,6 @@ void vga_common_init(VGAState *s, uint8_t *vga_ram_base, @@ -198,7 +195,6 @@ void vga_common_init(VGAState *s, uint8_t *vga_ram_base,
198 ram_addr_t vga_ram_offset, int vga_ram_size); 195 ram_addr_t vga_ram_offset, int vga_ram_size);
199 void vga_init(VGAState *s); 196 void vga_init(VGAState *s);
200 void vga_reset(void *s); 197 void vga_reset(void *s);
201 -void vga_update_resolution(VGAState *s);  
202 198
203 void vga_dirty_log_start(VGAState *s); 199 void vga_dirty_log_start(VGAState *s);
204 void vga_dirty_log_stop(VGAState *s); 200 void vga_dirty_log_stop(VGAState *s);