vga and cirrus_vga: create vga_ioport_invalid() and use it everywhere
authorJuan Quintela <quintela@redhat.com>
Mon, 31 Aug 2009 14:07:19 +0000 (16:07 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 9 Sep 2009 19:55:13 +0000 (14:55 -0500)
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/cirrus_vga.c
hw/vga.c
hw/vga_int.h

index 5f57107..7e63399 100644 (file)
@@ -2661,10 +2661,7 @@ static uint32_t cirrus_vga_ioport_read(void *opaque, uint32_t addr)
     CirrusVGAState *s = opaque;
     int val, index;
 
-    /* check port range access depending on color/monochrome mode */
-    if ((addr >= 0x3b0 && addr <= 0x3bf && (s->vga.msr & MSR_COLOR_EMULATION))
-       || (addr >= 0x3d0 && addr <= 0x3df
-           && !(s->vga.msr & MSR_COLOR_EMULATION))) {
+    if (vga_ioport_invalid(&s->vga, addr)) {
        val = 0xff;
     } else {
        switch (addr) {
@@ -2768,11 +2765,9 @@ static void cirrus_vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     int index;
 
     /* check port range access depending on color/monochrome mode */
-    if ((addr >= 0x3b0 && addr <= 0x3bf && (s->vga.msr & MSR_COLOR_EMULATION))
-       || (addr >= 0x3d0 && addr <= 0x3df
-           && !(s->vga.msr & MSR_COLOR_EMULATION)))
+    if (vga_ioport_invalid(&s->vga, addr)) {
        return;
-
+    }
 #ifdef DEBUG_VGA
     printf("VGA: write addr=0x%04x data=0x%02x\n", addr, val);
 #endif
index 8cd1117..b4c31ce 100644 (file)
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -284,14 +284,23 @@ static uint8_t vga_dumb_retrace(VGAState *s)
     return s->st01 ^ (ST01_V_RETRACE | ST01_DISP_ENABLE);
 }
 
+int vga_ioport_invalid(VGACommonState *s, uint32_t addr)
+{
+    if (s->msr & MSR_COLOR_EMULATION) {
+        /* Color */
+        return (addr >= 0x3b0 && addr <= 0x3bf);
+    } else {
+        /* Monochrome */
+        return (addr >= 0x3d0 && addr <= 0x3df);
+    }
+}
+
 uint32_t vga_ioport_read(void *opaque, uint32_t addr)
 {
     VGACommonState *s = opaque;
     int val, index;
 
-    /* check port range access depending on color/monochrome mode */
-    if ((addr >= 0x3b0 && addr <= 0x3bf && (s->msr & MSR_COLOR_EMULATION)) ||
-        (addr >= 0x3d0 && addr <= 0x3df && !(s->msr & MSR_COLOR_EMULATION))) {
+    if (vga_ioport_invalid(s, addr)) {
         val = 0xff;
     } else {
         switch(addr) {
@@ -383,10 +392,9 @@ void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     int index;
 
     /* check port range access depending on color/monochrome mode */
-    if ((addr >= 0x3b0 && addr <= 0x3bf && (s->msr & MSR_COLOR_EMULATION)) ||
-        (addr >= 0x3d0 && addr <= 0x3df && !(s->msr & MSR_COLOR_EMULATION)))
+    if (vga_ioport_invalid(s, addr)) {
         return;
-
+    }
 #ifdef DEBUG_VGA
     printf("VGA: write addr=0x%04x data=0x%02x\n", addr, val);
 #endif
index 9ff205d..c162c07 100644 (file)
@@ -214,6 +214,8 @@ void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
                              unsigned int color0, unsigned int color1,
                              unsigned int color_xor);
 
+int vga_ioport_invalid(VGACommonState *s, uint32_t addr);
+
 extern const uint8_t sr_mask[8];
 extern const uint8_t gr_mask[16];