qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [patch] incorrect VGA initialization, can provide imag


From: Piotr Krysik
Subject: Re: [Qemu-devel] [patch] incorrect VGA initialization, can provide image
Date: Fri, 10 Sep 2004 05:26:12 -0700 (PDT)

Hi,

Thanks for your comment.

I updated the patch to factor common code from 
vga_mem_writeb and remove goto. The source should 
be easer to read now.


Regards,

Piotrek

--- Johannes Schindelin <address@hidden>
wrote:

> Hi,
> 
> why not consolidate those identical lines (checking
> if the address is in
> font memory) into a function?
> 
> Just a thought,
> Dscho


        
                
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 
diff -ru qemu-snapshot-2004-08-04_23/hw/vga.c 
qemu-snapshot-2004-08-04_23-vga-update/hw/vga.c
--- qemu-snapshot-2004-08-04_23/hw/vga.c        2004-06-26 18:12:26.000000000 
+0200
+++ qemu-snapshot-2004-08-04_23-vga-update/hw/vga.c     2004-09-10 
13:50:36.000000000 +0200
@@ -658,12 +658,47 @@
     return v;
 }
 
+/* write byte to video ram */
+static inline void vram_writeb(VGAState *s, target_phys_addr_t addr, uint32_t 
val)
+{
+#ifdef DEBUG_VGA_MEM
+    printf("vga: vram: [0x%x]\n", addr);
+#endif
+    s->vram_ptr[addr] = val;
+    /* force full update for vga_draw_text when writing font memory */
+    if (((s->font_offsets[0] ^ addr) & ~0x7ffc) == 0 ||
+        ((s->font_offsets[1] ^ addr) & ~0x7ffc) == 0)
+        s->font_offsets[0] = -1;
+    cpu_physical_memory_set_dirty(s->vram_offset + addr);
+}
+
+/* write to video ram using mask in sr[2] register */
+static inline void vram_writel_sr2(VGAState *s, target_phys_addr_t addr, 
uint32_t val)
+{
+    uint32_t *ptr;
+    uint32_t write_mask;
+
+    ptr = (uint32_t *)(s->vram_ptr + addr);
+    write_mask = mask16[s->sr[2]];
+#ifdef DEBUG_VGA_MEM
+    printf("vga: vram latch: [0x%x] mask=0x%08x val=0x%08x\n", 
+           addr, write_mask, val);
+#endif
+    *ptr = (*ptr & ~write_mask) | (val & write_mask);
+    /* force full update for vga_draw_text when writing font memory */
+    if ((s->sr[2] & 4) &&
+        (((s->font_offsets[0] ^ (addr + 2)) & ~0x7ffc) == 0 ||
+        ((s->font_offsets[1] ^ (addr + 2)) & ~0x7ffc) == 0))
+        s->font_offsets[0] = -1;
+    cpu_physical_memory_set_dirty(s->vram_offset + addr);
+}
+
 /* called for accesses between 0xa0000 and 0xc0000 */
 void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     VGAState *s = opaque;
     int memory_map_mode, plane, write_mode, b, func_select;
-    uint32_t write_mask, bit_mask, set_mask;
+    uint32_t bit_mask, set_mask;
 
 #ifdef DEBUG_VGA_MEM
     printf("vga: [0x%x] = 0x%02x\n", addr, val);
@@ -696,22 +731,14 @@
         /* chain 4 mode : simplest access */
         plane = addr & 3;
         if (s->sr[2] & (1 << plane)) {
-            s->vram_ptr[addr] = val;
-#ifdef DEBUG_VGA_MEM
-            printf("vga: chain4: [0x%x]\n", addr);
-#endif
-            cpu_physical_memory_set_dirty(s->vram_offset + addr);
+            vram_writeb(s, addr, val);
         }
     } else if (s->gr[5] & 0x10) {
         /* odd/even mode (aka text mode mapping) */
         plane = (s->gr[4] & 2) | (addr & 1);
         if (s->sr[2] & (1 << plane)) {
             addr = ((addr & ~1) << 1) | plane;
-            s->vram_ptr[addr] = val;
-#ifdef DEBUG_VGA_MEM
-            printf("vga: odd/even: [0x%x]\n", addr);
-#endif
-            cpu_physical_memory_set_dirty(s->vram_offset + addr);
+            vram_writeb(s, addr, val);
         }
     } else {
         /* standard VGA latched access */
@@ -732,7 +759,8 @@
             break;
         case 1:
             val = s->latch;
-            goto do_write;
+            vram_writel_sr2(s, addr << 2, val);
+            return;
         case 2:
             val = mask16[val & 0x0f];
             bit_mask = s->gr[8];
@@ -773,17 +801,7 @@
         bit_mask |= bit_mask << 16;
         val = (val & bit_mask) | (s->latch & ~bit_mask);
 
-    do_write:
-        /* mask data according to sr[2] */
-        write_mask = mask16[s->sr[2]];
-        ((uint32_t *)s->vram_ptr)[addr] = 
-            (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | 
-            (val & write_mask);
-#ifdef DEBUG_VGA_MEM
-            printf("vga: latch: [0x%x] mask=0x%08x val=0x%08x\n", 
-                   addr * 4, write_mask, val);
-#endif
-            cpu_physical_memory_set_dirty(s->vram_offset + (addr << 2));
+        vram_writel_sr2(s, addr << 2, val);
     }
 }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]