vgabios: Use vesa style memory model flags in stdvga code.

Replace the custom flags with the flags defined in the VBE spec.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c
index c7331e4..e90d48f 100644
--- a/vgasrc/stdvga.c
+++ b/vgasrc/stdvga.c
@@ -527,11 +527,10 @@
 clear_screen(struct vgamode_s *vmode_g)
 {
     switch (GET_GLOBAL(vmode_g->memmodel)) {
-    case CTEXT:
-    case MTEXT:
+    case MM_TEXT:
         memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0720, 32*1024);
         break;
-    case CGA:
+    case MM_CGA:
         memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 32*1024);
         break;
     default:
@@ -627,7 +626,7 @@
 
     // Write the fonts in memory
     u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
-    if (memmodel & TEXT)
+    if (memmodel == MM_TEXT)
         stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, 0, 16);
 
     // Setup BDA variables
diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h
index 0685584..0a99d37 100644
--- a/vgasrc/stdvga.h
+++ b/vgasrc/stdvga.h
@@ -44,24 +44,6 @@
 #define SEG_CTEXT 0xB800
 #define SEG_MTEXT 0xB000
 
-/*
- * Tables of default values for each mode
- */
-#define TEXT       0x80
-
-#define CTEXT      (0x00 | TEXT)
-#define MTEXT      (0x01 | TEXT)
-#define CGA        0x02
-#define PLANAR1    0x03
-#define PLANAR4    0x04
-#define LINEAR8    0x05
-
-// for SVGA
-#define LINEAR15   0x10
-#define LINEAR16   0x11
-#define LINEAR24   0x12
-#define LINEAR32   0x13
-
 struct vgamode_s {
     u8 svgamode;
     u8 memmodel;    /* CTEXT,MTEXT,CGA,PL1,PL2,PL4,P8,P15,P16,P24,P32 */
diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c
index 063a2fd..7bed069 100644
--- a/vgasrc/vgabios.c
+++ b/vgasrc/vgabios.c
@@ -135,7 +135,7 @@
     struct cursorpos cp = get_cursor_pos(page);
 
     u16 address;
-    if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
+    if (GET_GLOBAL(vmode_g->memmodel) == MM_TEXT) {
         // Get the dimensions
         u16 nbcols = GET_BDA(video_cols);
         u16 nbrows = GET_BDA(video_rows) + 1;
@@ -339,7 +339,8 @@
     SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
     SET_BDA(video_switches, 0xF9);
     SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
-    SET_BDA(cursor_type, GET_GLOBAL(vmode_g->memmodel) & TEXT ? 0x0607 : 0x0000);
+    SET_BDA(cursor_type
+            , GET_GLOBAL(vmode_g->memmodel) == MM_TEXT ? 0x0607 : 0x0000);
     int i;
     for (i=0; i<8; i++)
         SET_BDA(cursor_pos[i], 0x0000);
diff --git a/vgasrc/vgabios.h b/vgasrc/vgabios.h
index 176f71c..7c5e8d3 100644
--- a/vgasrc/vgabios.h
+++ b/vgasrc/vgabios.h
@@ -33,6 +33,16 @@
 #define MF_LINEARFB   0x4000
 #define MF_NOCLEARMEM 0x8000
 
+// Memory model types
+#define MM_TEXT            0x00
+#define MM_CGA             0x01
+#define MM_HERCULES        0x02
+#define MM_PLANAR          0x03
+#define MM_PACKED          0x04
+#define MM_NON_CHAIN_4_256 0x05
+#define MM_DIRECT          0x06
+#define MM_YUV             0x07
+
 // vgatables.c
 struct vgamode_s;
 struct vgamode_s *find_vga_entry(u8 mode);
diff --git a/vgasrc/vgafb.c b/vgasrc/vgafb.c
index 85e4ab3..0f33720 100644
--- a/vgasrc/vgafb.c
+++ b/vgasrc/vgafb.c
@@ -176,18 +176,17 @@
 
     // FIXME gfx mode not complete
     switch (GET_GLOBAL(vmode_g->memmodel)) {
-    case CTEXT:
-    case MTEXT:
+    case MM_TEXT:
         scroll_text(vmode_g, nblines, attr, ul, lr);
         break;
-    case PLANAR4:
-    case PLANAR1:
+    case MM_PLANAR:
         scroll_pl4(vmode_g, nblines, attr, ul, lr);
         break;
-    case CGA:
+    case MM_CGA:
         scroll_cga(vmode_g, nblines, attr, ul, lr);
         break;
-    case LINEAR8:
+    case MM_DIRECT:
+    case MM_PACKED:
         scroll_lin(vmode_g, nblines, attr, ul, lr);
         break;
     }
@@ -357,18 +356,17 @@
 
     // FIXME gfx mode not complete
     switch (GET_GLOBAL(vmode_g->memmodel)) {
-    case CTEXT:
-    case MTEXT:
+    case MM_TEXT:
         write_text_char(vmode_g, cp, ca);
         break;
-    case PLANAR4:
-    case PLANAR1:
+    case MM_PLANAR:
         write_gfx_char_pl4(vmode_g, cp, ca);
         break;
-    case CGA:
+    case MM_CGA:
         write_gfx_char_cga(vmode_g, cp, ca);
         break;
-    case LINEAR8:
+    case MM_DIRECT:
+    case MM_PACKED:
         write_gfx_char_lin(vmode_g, cp, ca);
         break;
     }
@@ -382,7 +380,7 @@
     if (!vmode_g)
         goto fail;
 
-    if (!(GET_GLOBAL(vmode_g->memmodel) & TEXT)) {
+    if (GET_GLOBAL(vmode_g->memmodel) != MM_TEXT) {
         // FIXME gfx mode
         dprintf(1, "Read char in graphics mode\n");
         goto fail;
@@ -416,13 +414,10 @@
     struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
     if (!vmode_g)
         return;
-    if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
-        return;
 
     u8 *addr_far, mask, attr, data;
     switch (GET_GLOBAL(vmode_g->memmodel)) {
-    case PLANAR4:
-    case PLANAR1:
+    case MM_PLANAR:
         addr_far = (void*)(x / 8 + y * GET_BDA(video_cols));
         mask = 0x80 >> (x & 0x07);
         stdvga_grdc_write(0x08, mask);
@@ -435,7 +430,7 @@
         stdvga_grdc_write(0x05, 0x00);
         stdvga_grdc_write(0x03, 0x00);
         break;
-    case CGA:
+    case MM_CGA:
         if (GET_GLOBAL(vmode_g->pixbits) == 2)
             addr_far = (void*)((x >> 2) + (y >> 1) * 80);
         else
@@ -458,10 +453,13 @@
         }
         SET_FARVAR(SEG_CTEXT, *addr_far, data);
         break;
-    case LINEAR8:
+    case MM_DIRECT:
+    case MM_PACKED:
         addr_far = (void*)(x + y * (GET_BDA(video_cols) * 8));
         SET_FARVAR(SEG_GRAPH, *addr_far, color);
         break;
+    case MM_TEXT:
+        return;
     }
 }
 
@@ -472,13 +470,10 @@
     struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
     if (!vmode_g)
         return 0;
-    if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
-        return 0;
 
     u8 *addr_far, mask, attr=0, data, i;
     switch (GET_GLOBAL(vmode_g->memmodel)) {
-    case PLANAR4:
-    case PLANAR1:
+    case MM_PLANAR:
         addr_far = (void*)(x / 8 + y * GET_BDA(video_cols));
         mask = 0x80 >> (x & 0x07);
         attr = 0x00;
@@ -489,7 +484,7 @@
                 attr |= (0x01 << i);
         }
         break;
-    case CGA:
+    case MM_CGA:
         addr_far = (void*)((x >> 2) + (y >> 1) * 80);
         if (y & 1)
             addr_far += 0x2000;
@@ -499,10 +494,13 @@
         else
             attr = (data >> (7 - (x & 0x07))) & 0x01;
         break;
-    case LINEAR8:
+    case MM_DIRECT:
+    case MM_PACKED:
         addr_far = (void*)(x + y * (GET_BDA(video_cols) * 8));
         attr = GET_FARVAR(SEG_GRAPH, *addr_far);
         break;
+    case MM_TEXT:
+        return 0;
     }
     return attr;
 }
diff --git a/vgasrc/vgatables.c b/vgasrc/vgatables.c
index 0eda104..048e6c5 100644
--- a/vgasrc/vgatables.c
+++ b/vgasrc/vgatables.c
@@ -339,37 +339,37 @@
 static struct vgamode_s vga_modes[] VAR16 = {
     //mode model     tx  ty  ch bits sstart    slength
     // pelm  dac            sequ     misc  crtc     actl     grdc
-    {0x00, CTEXT,    40, 25, 16, 4, SEG_CTEXT, 0x0800
-     , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01 },
-    {0x01, CTEXT,    40, 25, 16, 4, SEG_CTEXT, 0x0800
-     , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01 },
-    {0x02, CTEXT,    80, 25, 16, 4, SEG_CTEXT, 0x1000
-     , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01 },
-    {0x03, CTEXT,    80, 25, 16, 4, SEG_CTEXT, 0x1000
-     , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01 },
-    {0x04, CGA,      40, 25,  8, 2, SEG_CTEXT, 0x0800
+    {0x00, MM_TEXT,    40, 25, 16, 4, SEG_CTEXT, 0x0800
+     , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
+    {0x01, MM_TEXT,    40, 25, 16, 4, SEG_CTEXT, 0x0800
+     , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
+    {0x02, MM_TEXT,    80, 25, 16, 4, SEG_CTEXT, 0x1000
+     , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
+    {0x03, MM_TEXT,    80, 25, 16, 4, SEG_CTEXT, 0x1000
+     , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
+    {0x04, MM_CGA,     40, 25,  8, 2, SEG_CTEXT, 0x0800
      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
-    {0x05, CGA,      40, 25,  8, 2, SEG_CTEXT, 0x0800
+    {0x05, MM_CGA,     40, 25,  8, 2, SEG_CTEXT, 0x0800
      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
-    {0x06, CGA,      80, 25,  8, 1, SEG_CTEXT, 0x1000
+    {0x06, MM_CGA,     80, 25,  8, 1, SEG_CTEXT, 0x1000
      , 0xFF, PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06},
-    {0x07, MTEXT,    80, 25, 16, 4, SEG_MTEXT, 0x1000
+    {0x07, MM_TEXT,    80, 25, 16, 4, SEG_MTEXT, 0x1000
      , 0xFF, PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07},
-    {0x0D, PLANAR4,  40, 25,  8, 4, SEG_GRAPH, 0x2000
+    {0x0D, MM_PLANAR,  40, 25,  8, 4, SEG_GRAPH, 0x2000
      , 0xFF, PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d},
-    {0x0E, PLANAR4,  80, 25,  8, 4, SEG_GRAPH, 0x4000
+    {0x0E, MM_PLANAR,  80, 25,  8, 4, SEG_GRAPH, 0x4000
      , 0xFF, PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d},
-    {0x0F, PLANAR1,  80, 25, 14, 1, SEG_GRAPH, 0x8000
+    {0x0F, MM_PLANAR,  80, 25, 14, 1, SEG_GRAPH, 0x8000
      , 0xFF, PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d},
-    {0x10, PLANAR4,  80, 25, 14, 4, SEG_GRAPH, 0x8000
+    {0x10, MM_PLANAR,  80, 25, 14, 4, SEG_GRAPH, 0x8000
      , 0xFF, PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d},
-    {0x11, PLANAR1,  80, 30, 16, 1, SEG_GRAPH, 0x0000
+    {0x11, MM_PLANAR,  80, 30, 16, 1, SEG_GRAPH, 0x0000
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d},
-    {0x12, PLANAR4,  80, 30, 16, 4, SEG_GRAPH, 0x0000
+    {0x12, MM_PLANAR,  80, 30, 16, 4, SEG_GRAPH, 0x0000
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d},
-    {0x13, LINEAR8,  40, 25,  8, 8, SEG_GRAPH, 0x0000
+    {0x13, MM_PACKED,  40, 25,  8, 8, SEG_GRAPH, 0x0000
      , 0xFF, PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13},
-    {0x6A, PLANAR4, 100, 37, 16, 4, SEG_GRAPH, 0x0000
+    {0x6A, MM_PLANAR, 100, 37, 16, 4, SEG_GRAPH, 0x0000
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d},
 };