vgabios: Move video_param_table definition to vgabios.c.
[seabios.git] / vgasrc / vgatables.c
index 314222e3b2546fdfcd40f35cb1b327a179eab0b8..4a5350dcffba42154bc907882a43b9b9ee8f0613 100644 (file)
@@ -8,94 +8,11 @@
 #include "vgabios.h" // struct VideoParamTableEntry_s
 #include "biosvar.h" // GET_GLOBAL
 #include "util.h" // memcpy_far
-#include "stdvga.h" // struct vgamode_s
+#include "stdvga.h" // stdvga_find_mode
 
 
 /****************************************************************
- * Video parameter table
- ****************************************************************/
-
-// Standard Video Save Pointer Table
-struct VideoSavePointer_s {
-    struct segoff_s videoparam;
-    struct segoff_s paramdynamicsave;
-    struct segoff_s textcharset;
-    struct segoff_s graphcharset;
-    struct segoff_s secsavepointer;
-    u8 reserved[8];
-} PACKED;
-
-struct VideoSavePointer_s video_save_pointer_table VAR16;
-
-// standard BIOS Video Parameter Table
-struct VideoParam_s {
-    u8 twidth;
-    u8 theightm1;
-    u8 cheight;
-    u16 slength;
-    u8 sequ_regs[4];
-    u8 miscreg;
-    u8 crtc_regs[25];
-    u8 actl_regs[20];
-    u8 grdc_regs[9];
-} PACKED;
-
-struct VideoParam_s video_param_table[29] VAR16;
-
-void
-build_video_param(void)
-{
-    static u8 parammodes[ARRAY_SIZE(video_param_table)] VAR16 = {
-        0, 0, 0, 0, 0x04, 0x05, 0x06, 0x07,
-        0, 0, 0, 0, 0, 0x0d, 0x0e, 0,
-        0, 0x0f, 0x10, 0, 0, 0, 0, 0x01,
-        0x03, 0x07, 0x11, 0x12, 0x13
-    };
-
-    int i;
-    for (i=0; i<ARRAY_SIZE(parammodes); i++) {
-        int mode = GET_GLOBAL(parammodes[i]);
-        if (! mode)
-            continue;
-        struct VideoParam_s *vparam_g = &video_param_table[i];
-        struct vgamode_s *vmode_g = find_vga_entry(mode);
-        if (!vmode_g)
-            continue;
-        int width = GET_GLOBAL(vmode_g->width);
-        int height = GET_GLOBAL(vmode_g->height);
-        int cheight = GET_GLOBAL(vmode_g->cheight);
-        if (GET_GLOBAL(vmode_g->memmodel) == MM_TEXT) {
-            SET_VGA(vparam_g->twidth, width);
-            SET_VGA(vparam_g->theightm1, height-1);
-        } else {
-            int cwidth = GET_GLOBAL(vmode_g->cwidth);
-            SET_VGA(vparam_g->twidth, width / cwidth);
-            SET_VGA(vparam_g->theightm1, (height / cheight) - 1);
-        }
-        SET_VGA(vparam_g->cheight, cheight);
-        SET_VGA(vparam_g->slength, GET_GLOBAL(vmode_g->slength));
-        memcpy_far(get_global_seg(), vparam_g->sequ_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->sequ_regs)
-                   , ARRAY_SIZE(vparam_g->sequ_regs));
-        SET_VGA(vparam_g->miscreg, GET_GLOBAL(vmode_g->miscreg));
-        memcpy_far(get_global_seg(), vparam_g->crtc_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->crtc_regs)
-                   , ARRAY_SIZE(vparam_g->crtc_regs));
-        memcpy_far(get_global_seg(), vparam_g->actl_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->actl_regs)
-                   , ARRAY_SIZE(vparam_g->actl_regs));
-        memcpy_far(get_global_seg(), vparam_g->grdc_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->grdc_regs)
-                   , ARRAY_SIZE(vparam_g->grdc_regs));
-    }
-
-    SET_VGA(video_save_pointer_table.videoparam
-            , SEGOFF(get_global_seg(), (u32)video_param_table));
-}
-
-
-/****************************************************************
- * Register definitions
+ * Video mode register definitions
  ****************************************************************/
 
 /* Mono */
@@ -337,80 +254,109 @@ static u8 crtc_6A[] VAR16 = {
     0x59, 0x8d, 0x57, 0x32, 0x00, 0x57, 0x73, 0xe3,
     0xff };
 
-
-/****************************************************************
- * Video mode list
- ****************************************************************/
-
 #define PAL(x) x, sizeof(x)
-#define VPARAM(x) &video_param_table[x]
 
-static struct vgamode_s vga_modes[] VAR16 = {
-    //mode model       tx   ty bpp cw ch  sstart     slength
+static struct stdvga_mode_s vga_modes[] VAR16 = {
+    //mode { model       tx   ty bpp cw ch  sstart    }
     // pelm  dac            sequ     misc  crtc     actl     grdc
-    {0x00, MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT, 0x0800
+    {0x00, { MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
-    {0x01, MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT, 0x0800
+    {0x01, { MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
-    {0x02, MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT, 0x1000
+    {0x02, { MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
-    {0x03, MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT, 0x1000
+    {0x03, { MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
-    {0x04, MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT, 0x0800
+    {0x04, { MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT }
      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
-    {0x05, MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT, 0x0800
+    {0x05, { MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT }
      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
-    {0x06, MM_CGA,    640, 200, 1, 8,  8, SEG_CTEXT, 0x1000
+    {0x06, { MM_CGA,    640, 200, 1, 8,  8, SEG_CTEXT }
      , 0xFF, PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06},
-    {0x07, MM_TEXT,    80,  25, 4, 9, 16, SEG_MTEXT, 0x1000
+    {0x07, { MM_TEXT,    80,  25, 4, 9, 16, SEG_MTEXT }
      , 0xFF, PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07},
-    {0x0D, MM_PLANAR, 320, 200, 4, 8,  8, SEG_GRAPH, 0x2000
+    {0x0D, { MM_PLANAR, 320, 200, 4, 8,  8, SEG_GRAPH }
      , 0xFF, PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d},
-    {0x0E, MM_PLANAR, 640, 200, 4, 8,  8, SEG_GRAPH, 0x4000
+    {0x0E, { MM_PLANAR, 640, 200, 4, 8,  8, SEG_GRAPH }
      , 0xFF, PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d},
-    {0x0F, MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH, 0x8000
+    {0x0F, { MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH }
      , 0xFF, PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d},
-    {0x10, MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH, 0x8000
+    {0x10, { MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d},
-    {0x11, MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH, 0x0000
+    {0x11, { MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d},
-    {0x12, MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH, 0x0000
+    {0x12, { MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d},
-    {0x13, MM_PACKED, 320, 200, 8, 8,  8, SEG_GRAPH, 0x0000
+    {0x13, { MM_PACKED, 320, 200, 8, 8,  8, SEG_GRAPH }
      , 0xFF, PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13},
-    {0x6A, MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH, 0x0000
+    {0x6A, { MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d},
 };
 
+
+/****************************************************************
+ * Mode functions
+ ****************************************************************/
+
 struct vgamode_s *
-find_vga_entry(u8 mode)
+stdvga_find_mode(int mode)
 {
     int i;
     for (i = 0; i < ARRAY_SIZE(vga_modes); i++) {
-        struct vgamode_s *vmode_g = &vga_modes[i];
-        if (GET_GLOBAL(vmode_g->mode) == mode)
-            return vmode_g;
+        struct stdvga_mode_s *stdmode_g = &vga_modes[i];
+        if (GET_GLOBAL(stdmode_g->mode) == mode)
+            return &stdmode_g->info;
     }
     return NULL;
 }
 
+void
+stdvga_build_video_param(void)
+{
+    static u8 parammodes[] VAR16 = {
+        0, 0, 0, 0, 0x04, 0x05, 0x06, 0x07,
+        0, 0, 0, 0, 0, 0x0d, 0x0e, 0,
+        0, 0x0f, 0x10, 0, 0, 0, 0, 0x01,
+        0x03, 0x07, 0x11, 0x12, 0x13
+    };
 
-/****************************************************************
- * Static functionality table
- ****************************************************************/
-
-u8 static_functionality[0x10] VAR16 = {
- /* 0 */ 0xff,  // All modes supported #1
- /* 1 */ 0xe0,  // All modes supported #2
- /* 2 */ 0x0f,  // All modes supported #3
- /* 3 */ 0x00, 0x00, 0x00, 0x00,  // reserved
- /* 7 */ 0x07,  // 200, 350, 400 scan lines
- /* 8 */ 0x02,  // mamimum number of visible charsets in text mode
- /* 9 */ 0x08,  // total number of charset blocks in text mode
- /* a */ 0xe7,  // Change to add new functions
- /* b */ 0x0c,  // Change to add new functions
- /* c */ 0x00,  // reserved
- /* d */ 0x00,  // reserved
- /* e */ 0x00,  // Change to add new functions
- /* f */ 0x00   // reserved
-};
+    int i;
+    for (i=0; i<ARRAY_SIZE(parammodes); i++) {
+        int mode = GET_GLOBAL(parammodes[i]);
+        if (! mode)
+            continue;
+        struct VideoParam_s *vparam_g = &video_param_table[i];
+        struct vgamode_s *vmode_g = stdvga_find_mode(mode);
+        if (!vmode_g)
+            continue;
+        int width = GET_GLOBAL(vmode_g->width);
+        int height = GET_GLOBAL(vmode_g->height);
+        u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
+        int cheight = GET_GLOBAL(vmode_g->cheight);
+        if (memmodel == MM_TEXT) {
+            SET_VGA(vparam_g->twidth, width);
+            SET_VGA(vparam_g->theightm1, height-1);
+        } else {
+            int cwidth = GET_GLOBAL(vmode_g->cwidth);
+            SET_VGA(vparam_g->twidth, width / cwidth);
+            SET_VGA(vparam_g->theightm1, (height / cheight) - 1);
+        }
+        SET_VGA(vparam_g->cheight, cheight);
+        SET_VGA(vparam_g->slength, calc_page_size(memmodel, width, height));
+        struct stdvga_mode_s *stdmode_g = container_of(
+            vmode_g, struct stdvga_mode_s, info);
+        memcpy_far(get_global_seg(), vparam_g->sequ_regs
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->sequ_regs)
+                   , ARRAY_SIZE(vparam_g->sequ_regs));
+        SET_VGA(vparam_g->miscreg, GET_GLOBAL(stdmode_g->miscreg));
+        memcpy_far(get_global_seg(), vparam_g->crtc_regs
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->crtc_regs)
+                   , ARRAY_SIZE(vparam_g->crtc_regs));
+        memcpy_far(get_global_seg(), vparam_g->actl_regs
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->actl_regs)
+                   , ARRAY_SIZE(vparam_g->actl_regs));
+        memcpy_far(get_global_seg(), vparam_g->grdc_regs
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->grdc_regs)
+                   , ARRAY_SIZE(vparam_g->grdc_regs));
+    }
+}