4fd99642433e630a422e1640c1f66783f29a206f
[seabios.git] / vgasrc / vgatables.c
1 // Tables used by VGA bios
2 //
3 // Copyright (C) 2009  Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2001-2008 the LGPL VGABios developers Team
5 //
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
7
8 #include "vgabios.h" // struct VideoParamTableEntry_s
9 #include "biosvar.h" // GET_GLOBAL
10 #include "util.h" // memcpy_far
11 #include "stdvga.h" // struct vgamode_s
12
13
14 /****************************************************************
15  * Video parameter table
16  ****************************************************************/
17
18 // Standard Video Save Pointer Table
19 struct VideoSavePointer_s {
20     struct segoff_s videoparam;
21     struct segoff_s paramdynamicsave;
22     struct segoff_s textcharset;
23     struct segoff_s graphcharset;
24     struct segoff_s secsavepointer;
25     u8 reserved[8];
26 } PACKED;
27
28 struct VideoSavePointer_s video_save_pointer_table VAR16;
29
30 // standard BIOS Video Parameter Table
31 struct VideoParam_s {
32     u8 twidth;
33     u8 theightm1;
34     u8 cheight;
35     u16 slength;
36     u8 sequ_regs[4];
37     u8 miscreg;
38     u8 crtc_regs[25];
39     u8 actl_regs[20];
40     u8 grdc_regs[9];
41 } PACKED;
42
43 struct VideoParam_s video_param_table[29] VAR16;
44
45 void
46 build_video_param(void)
47 {
48     static u8 parammodes[ARRAY_SIZE(video_param_table)] VAR16 = {
49         0, 0, 0, 0, 0x04, 0x05, 0x06, 0x07,
50         0, 0, 0, 0, 0, 0x0d, 0x0e, 0,
51         0, 0x0f, 0x10, 0, 0, 0, 0, 0x01,
52         0x03, 0x07, 0x11, 0x12, 0x13
53     };
54
55     int i;
56     for (i=0; i<ARRAY_SIZE(parammodes); i++) {
57         int mode = GET_GLOBAL(parammodes[i]);
58         if (! mode)
59             continue;
60         struct VideoParam_s *vparam_g = &video_param_table[i];
61         struct vgamode_s *vmode_g = find_vga_entry(mode);
62         if (!vmode_g)
63             continue;
64         int width = GET_GLOBAL(vmode_g->width);
65         int height = GET_GLOBAL(vmode_g->height);
66         u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
67         int cheight = GET_GLOBAL(vmode_g->cheight);
68         if (memmodel == MM_TEXT) {
69             SET_VGA(vparam_g->twidth, width);
70             SET_VGA(vparam_g->theightm1, height-1);
71         } else {
72             int cwidth = GET_GLOBAL(vmode_g->cwidth);
73             SET_VGA(vparam_g->twidth, width / cwidth);
74             SET_VGA(vparam_g->theightm1, (height / cheight) - 1);
75         }
76         SET_VGA(vparam_g->cheight, cheight);
77         SET_VGA(vparam_g->slength, calc_page_size(memmodel, width, height));
78         memcpy_far(get_global_seg(), vparam_g->sequ_regs
79                    , get_global_seg(), GET_GLOBAL(vmode_g->sequ_regs)
80                    , ARRAY_SIZE(vparam_g->sequ_regs));
81         SET_VGA(vparam_g->miscreg, GET_GLOBAL(vmode_g->miscreg));
82         memcpy_far(get_global_seg(), vparam_g->crtc_regs
83                    , get_global_seg(), GET_GLOBAL(vmode_g->crtc_regs)
84                    , ARRAY_SIZE(vparam_g->crtc_regs));
85         memcpy_far(get_global_seg(), vparam_g->actl_regs
86                    , get_global_seg(), GET_GLOBAL(vmode_g->actl_regs)
87                    , ARRAY_SIZE(vparam_g->actl_regs));
88         memcpy_far(get_global_seg(), vparam_g->grdc_regs
89                    , get_global_seg(), GET_GLOBAL(vmode_g->grdc_regs)
90                    , ARRAY_SIZE(vparam_g->grdc_regs));
91     }
92
93     SET_VGA(video_save_pointer_table.videoparam
94             , SEGOFF(get_global_seg(), (u32)video_param_table));
95 }
96
97
98 /****************************************************************
99  * Register definitions
100  ****************************************************************/
101
102 /* Mono */
103 static u8 palette0[] VAR16 = {
104   0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
105   0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
106   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
107   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
108   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
109   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
110   0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f,
111   0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f,
112   0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
113   0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
114   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
115   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
116   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
117   0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
118   0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f,
119   0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f
120 };
121
122 static u8 palette1[] VAR16 = {
123   0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
124   0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
125   0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
126   0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
127   0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
128   0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
129   0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
130   0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
131   0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
132   0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
133   0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
134   0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
135   0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
136   0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
137   0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
138   0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f
139 };
140
141 static u8 palette2[] VAR16 = {
142   0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
143   0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x2a,0x00, 0x2a,0x2a,0x2a,
144   0x00,0x00,0x15, 0x00,0x00,0x3f, 0x00,0x2a,0x15, 0x00,0x2a,0x3f,
145   0x2a,0x00,0x15, 0x2a,0x00,0x3f, 0x2a,0x2a,0x15, 0x2a,0x2a,0x3f,
146   0x00,0x15,0x00, 0x00,0x15,0x2a, 0x00,0x3f,0x00, 0x00,0x3f,0x2a,
147   0x2a,0x15,0x00, 0x2a,0x15,0x2a, 0x2a,0x3f,0x00, 0x2a,0x3f,0x2a,
148   0x00,0x15,0x15, 0x00,0x15,0x3f, 0x00,0x3f,0x15, 0x00,0x3f,0x3f,
149   0x2a,0x15,0x15, 0x2a,0x15,0x3f, 0x2a,0x3f,0x15, 0x2a,0x3f,0x3f,
150   0x15,0x00,0x00, 0x15,0x00,0x2a, 0x15,0x2a,0x00, 0x15,0x2a,0x2a,
151   0x3f,0x00,0x00, 0x3f,0x00,0x2a, 0x3f,0x2a,0x00, 0x3f,0x2a,0x2a,
152   0x15,0x00,0x15, 0x15,0x00,0x3f, 0x15,0x2a,0x15, 0x15,0x2a,0x3f,
153   0x3f,0x00,0x15, 0x3f,0x00,0x3f, 0x3f,0x2a,0x15, 0x3f,0x2a,0x3f,
154   0x15,0x15,0x00, 0x15,0x15,0x2a, 0x15,0x3f,0x00, 0x15,0x3f,0x2a,
155   0x3f,0x15,0x00, 0x3f,0x15,0x2a, 0x3f,0x3f,0x00, 0x3f,0x3f,0x2a,
156   0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
157   0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f
158 };
159
160 static u8 palette3[] VAR16 = {
161   0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
162   0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
163   0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
164   0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
165   0x00,0x00,0x00, 0x05,0x05,0x05, 0x08,0x08,0x08, 0x0b,0x0b,0x0b,
166   0x0e,0x0e,0x0e, 0x11,0x11,0x11, 0x14,0x14,0x14, 0x18,0x18,0x18,
167   0x1c,0x1c,0x1c, 0x20,0x20,0x20, 0x24,0x24,0x24, 0x28,0x28,0x28,
168   0x2d,0x2d,0x2d, 0x32,0x32,0x32, 0x38,0x38,0x38, 0x3f,0x3f,0x3f,
169   0x00,0x00,0x3f, 0x10,0x00,0x3f, 0x1f,0x00,0x3f, 0x2f,0x00,0x3f,
170   0x3f,0x00,0x3f, 0x3f,0x00,0x2f, 0x3f,0x00,0x1f, 0x3f,0x00,0x10,
171   0x3f,0x00,0x00, 0x3f,0x10,0x00, 0x3f,0x1f,0x00, 0x3f,0x2f,0x00,
172   0x3f,0x3f,0x00, 0x2f,0x3f,0x00, 0x1f,0x3f,0x00, 0x10,0x3f,0x00,
173   0x00,0x3f,0x00, 0x00,0x3f,0x10, 0x00,0x3f,0x1f, 0x00,0x3f,0x2f,
174   0x00,0x3f,0x3f, 0x00,0x2f,0x3f, 0x00,0x1f,0x3f, 0x00,0x10,0x3f,
175   0x1f,0x1f,0x3f, 0x27,0x1f,0x3f, 0x2f,0x1f,0x3f, 0x37,0x1f,0x3f,
176   0x3f,0x1f,0x3f, 0x3f,0x1f,0x37, 0x3f,0x1f,0x2f, 0x3f,0x1f,0x27,
177
178   0x3f,0x1f,0x1f, 0x3f,0x27,0x1f, 0x3f,0x2f,0x1f, 0x3f,0x37,0x1f,
179   0x3f,0x3f,0x1f, 0x37,0x3f,0x1f, 0x2f,0x3f,0x1f, 0x27,0x3f,0x1f,
180   0x1f,0x3f,0x1f, 0x1f,0x3f,0x27, 0x1f,0x3f,0x2f, 0x1f,0x3f,0x37,
181   0x1f,0x3f,0x3f, 0x1f,0x37,0x3f, 0x1f,0x2f,0x3f, 0x1f,0x27,0x3f,
182   0x2d,0x2d,0x3f, 0x31,0x2d,0x3f, 0x36,0x2d,0x3f, 0x3a,0x2d,0x3f,
183   0x3f,0x2d,0x3f, 0x3f,0x2d,0x3a, 0x3f,0x2d,0x36, 0x3f,0x2d,0x31,
184   0x3f,0x2d,0x2d, 0x3f,0x31,0x2d, 0x3f,0x36,0x2d, 0x3f,0x3a,0x2d,
185   0x3f,0x3f,0x2d, 0x3a,0x3f,0x2d, 0x36,0x3f,0x2d, 0x31,0x3f,0x2d,
186   0x2d,0x3f,0x2d, 0x2d,0x3f,0x31, 0x2d,0x3f,0x36, 0x2d,0x3f,0x3a,
187   0x2d,0x3f,0x3f, 0x2d,0x3a,0x3f, 0x2d,0x36,0x3f, 0x2d,0x31,0x3f,
188   0x00,0x00,0x1c, 0x07,0x00,0x1c, 0x0e,0x00,0x1c, 0x15,0x00,0x1c,
189   0x1c,0x00,0x1c, 0x1c,0x00,0x15, 0x1c,0x00,0x0e, 0x1c,0x00,0x07,
190   0x1c,0x00,0x00, 0x1c,0x07,0x00, 0x1c,0x0e,0x00, 0x1c,0x15,0x00,
191   0x1c,0x1c,0x00, 0x15,0x1c,0x00, 0x0e,0x1c,0x00, 0x07,0x1c,0x00,
192   0x00,0x1c,0x00, 0x00,0x1c,0x07, 0x00,0x1c,0x0e, 0x00,0x1c,0x15,
193   0x00,0x1c,0x1c, 0x00,0x15,0x1c, 0x00,0x0e,0x1c, 0x00,0x07,0x1c,
194
195   0x0e,0x0e,0x1c, 0x11,0x0e,0x1c, 0x15,0x0e,0x1c, 0x18,0x0e,0x1c,
196   0x1c,0x0e,0x1c, 0x1c,0x0e,0x18, 0x1c,0x0e,0x15, 0x1c,0x0e,0x11,
197   0x1c,0x0e,0x0e, 0x1c,0x11,0x0e, 0x1c,0x15,0x0e, 0x1c,0x18,0x0e,
198   0x1c,0x1c,0x0e, 0x18,0x1c,0x0e, 0x15,0x1c,0x0e, 0x11,0x1c,0x0e,
199   0x0e,0x1c,0x0e, 0x0e,0x1c,0x11, 0x0e,0x1c,0x15, 0x0e,0x1c,0x18,
200   0x0e,0x1c,0x1c, 0x0e,0x18,0x1c, 0x0e,0x15,0x1c, 0x0e,0x11,0x1c,
201   0x14,0x14,0x1c, 0x16,0x14,0x1c, 0x18,0x14,0x1c, 0x1a,0x14,0x1c,
202   0x1c,0x14,0x1c, 0x1c,0x14,0x1a, 0x1c,0x14,0x18, 0x1c,0x14,0x16,
203   0x1c,0x14,0x14, 0x1c,0x16,0x14, 0x1c,0x18,0x14, 0x1c,0x1a,0x14,
204   0x1c,0x1c,0x14, 0x1a,0x1c,0x14, 0x18,0x1c,0x14, 0x16,0x1c,0x14,
205   0x14,0x1c,0x14, 0x14,0x1c,0x16, 0x14,0x1c,0x18, 0x14,0x1c,0x1a,
206   0x14,0x1c,0x1c, 0x14,0x1a,0x1c, 0x14,0x18,0x1c, 0x14,0x16,0x1c,
207   0x00,0x00,0x10, 0x04,0x00,0x10, 0x08,0x00,0x10, 0x0c,0x00,0x10,
208   0x10,0x00,0x10, 0x10,0x00,0x0c, 0x10,0x00,0x08, 0x10,0x00,0x04,
209   0x10,0x00,0x00, 0x10,0x04,0x00, 0x10,0x08,0x00, 0x10,0x0c,0x00,
210   0x10,0x10,0x00, 0x0c,0x10,0x00, 0x08,0x10,0x00, 0x04,0x10,0x00,
211
212   0x00,0x10,0x00, 0x00,0x10,0x04, 0x00,0x10,0x08, 0x00,0x10,0x0c,
213   0x00,0x10,0x10, 0x00,0x0c,0x10, 0x00,0x08,0x10, 0x00,0x04,0x10,
214   0x08,0x08,0x10, 0x0a,0x08,0x10, 0x0c,0x08,0x10, 0x0e,0x08,0x10,
215   0x10,0x08,0x10, 0x10,0x08,0x0e, 0x10,0x08,0x0c, 0x10,0x08,0x0a,
216   0x10,0x08,0x08, 0x10,0x0a,0x08, 0x10,0x0c,0x08, 0x10,0x0e,0x08,
217   0x10,0x10,0x08, 0x0e,0x10,0x08, 0x0c,0x10,0x08, 0x0a,0x10,0x08,
218   0x08,0x10,0x08, 0x08,0x10,0x0a, 0x08,0x10,0x0c, 0x08,0x10,0x0e,
219   0x08,0x10,0x10, 0x08,0x0e,0x10, 0x08,0x0c,0x10, 0x08,0x0a,0x10,
220   0x0b,0x0b,0x10, 0x0c,0x0b,0x10, 0x0d,0x0b,0x10, 0x0f,0x0b,0x10,
221   0x10,0x0b,0x10, 0x10,0x0b,0x0f, 0x10,0x0b,0x0d, 0x10,0x0b,0x0c,
222   0x10,0x0b,0x0b, 0x10,0x0c,0x0b, 0x10,0x0d,0x0b, 0x10,0x0f,0x0b,
223   0x10,0x10,0x0b, 0x0f,0x10,0x0b, 0x0d,0x10,0x0b, 0x0c,0x10,0x0b,
224   0x0b,0x10,0x0b, 0x0b,0x10,0x0c, 0x0b,0x10,0x0d, 0x0b,0x10,0x0f,
225   0x0b,0x10,0x10, 0x0b,0x0f,0x10, 0x0b,0x0d,0x10, 0x0b,0x0c,0x10,
226   0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
227   0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00
228 };
229
230 static u8 sequ_01[] VAR16 = { 0x08, 0x03, 0x00, 0x02 };
231 static u8 crtc_01[] VAR16 = {
232     0x2d, 0x27, 0x28, 0x90, 0x2b, 0xa0, 0xbf, 0x1f,
233     0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
234     0x9c, 0x8e, 0x8f, 0x14, 0x1f, 0x96, 0xb9, 0xa3,
235     0xff };
236 static u8 actl_01[] VAR16 = {
237     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
238     0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
239     0x0c, 0x00, 0x0f, 0x08 };
240 static u8 grdc_01[] VAR16 = {
241     0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x0f, 0xff };
242 static u8 sequ_03[] VAR16 = { 0x00, 0x03, 0x00, 0x02 };
243 static u8 crtc_03[] VAR16 = {
244     0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
245     0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
246     0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
247     0xff };
248 static u8 sequ_04[] VAR16 = { 0x09, 0x03, 0x00, 0x02 };
249 static u8 crtc_04[] VAR16 = {
250     0x2d, 0x27, 0x28, 0x90, 0x2b, 0x80, 0xbf, 0x1f,
251     0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252     0x9c, 0x8e, 0x8f, 0x14, 0x00, 0x96, 0xb9, 0xa2,
253     0xff };
254 static u8 actl_04[] VAR16 = {
255     0x00, 0x13, 0x15, 0x17, 0x02, 0x04, 0x06, 0x07,
256     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
257     0x01, 0x00, 0x03, 0x00 };
258 static u8 grdc_04[] VAR16 = {
259     0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0f, 0x0f, 0xff };
260 static u8 sequ_06[] VAR16 = { 0x01, 0x01, 0x00, 0x06 };
261 static u8 crtc_06[] VAR16 = {
262     0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
263     0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264     0x9c, 0x8e, 0x8f, 0x28, 0x00, 0x96, 0xb9, 0xc2,
265     0xff };
266 static u8 actl_06[] VAR16 = {
267     0x00, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
268     0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
269     0x01, 0x00, 0x01, 0x00 };
270 static u8 grdc_06[] VAR16 = {
271     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0f, 0xff };
272 static u8 crtc_07[] VAR16 = {
273     0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
274     0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
275     0x9c, 0x8e, 0x8f, 0x28, 0x0f, 0x96, 0xb9, 0xa3,
276     0xff };
277 static u8 actl_07[] VAR16 = {
278     0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
279     0x10, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
280     0x0e, 0x00, 0x0f, 0x08 };
281 static u8 grdc_07[] VAR16 = {
282     0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x0f, 0xff };
283 static u8 sequ_0d[] VAR16 = { 0x09, 0x0f, 0x00, 0x06 };
284 static u8 crtc_0d[] VAR16 = {
285     0x2d, 0x27, 0x28, 0x90, 0x2b, 0x80, 0xbf, 0x1f,
286     0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287     0x9c, 0x8e, 0x8f, 0x14, 0x00, 0x96, 0xb9, 0xe3,
288     0xff };
289 static u8 actl_0d[] VAR16 = {
290     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
291     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
292     0x01, 0x00, 0x0f, 0x00 };
293 static u8 grdc_0d[] VAR16 = {
294     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff };
295 static u8 sequ_0e[] VAR16 = { 0x01, 0x0f, 0x00, 0x06 };
296 static u8 crtc_0e[] VAR16 = {
297     0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
298     0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299     0x9c, 0x8e, 0x8f, 0x28, 0x00, 0x96, 0xb9, 0xe3,
300     0xff };
301 static u8 crtc_0f[] VAR16 = {
302     0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
303     0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304     0x83, 0x85, 0x5d, 0x28, 0x0f, 0x63, 0xba, 0xe3,
305     0xff };
306 static u8 actl_0f[] VAR16 = {
307     0x00, 0x08, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
308     0x00, 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
309     0x01, 0x00, 0x01, 0x00 };
310 static u8 actl_10[] VAR16 = {
311     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
312     0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
313     0x01, 0x00, 0x0f, 0x00 };
314 static u8 crtc_11[] VAR16 = {
315     0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e,
316     0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317     0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
318     0xff };
319 static u8 actl_11[] VAR16 = {
320     0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f,
321     0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f,
322     0x01, 0x00, 0x0f, 0x00 };
323 static u8 sequ_13[] VAR16 = { 0x01, 0x0f, 0x00, 0x0e };
324 static u8 crtc_13[] VAR16 = {
325     0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
326     0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327     0x9c, 0x8e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3,
328     0xff };
329 static u8 actl_13[] VAR16 = {
330     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
331     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
332     0x41, 0x00, 0x0f, 0x00 };
333 static u8 grdc_13[] VAR16 = {
334     0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f, 0xff };
335 static u8 crtc_6A[] VAR16 = {
336     0x7f, 0x63, 0x63, 0x83, 0x6b, 0x1b, 0x72, 0xf0,
337     0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
338     0x59, 0x8d, 0x57, 0x32, 0x00, 0x57, 0x73, 0xe3,
339     0xff };
340
341
342 /****************************************************************
343  * Video mode list
344  ****************************************************************/
345
346 #define PAL(x) x, sizeof(x)
347 #define VPARAM(x) &video_param_table[x]
348
349 static struct vgamode_s vga_modes[] VAR16 = {
350     //mode model       tx   ty bpp cw ch  sstart
351     // pelm  dac            sequ     misc  crtc     actl     grdc
352     {0x00, MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT
353      , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
354     {0x01, MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT
355      , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
356     {0x02, MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT
357      , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
358     {0x03, MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT
359      , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
360     {0x04, MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT
361      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
362     {0x05, MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT
363      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
364     {0x06, MM_CGA,    640, 200, 1, 8,  8, SEG_CTEXT
365      , 0xFF, PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06},
366     {0x07, MM_TEXT,    80,  25, 4, 9, 16, SEG_MTEXT
367      , 0xFF, PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07},
368     {0x0D, MM_PLANAR, 320, 200, 4, 8,  8, SEG_GRAPH
369      , 0xFF, PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d},
370     {0x0E, MM_PLANAR, 640, 200, 4, 8,  8, SEG_GRAPH
371      , 0xFF, PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d},
372     {0x0F, MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH
373      , 0xFF, PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d},
374     {0x10, MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH
375      , 0xFF, PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d},
376     {0x11, MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH
377      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d},
378     {0x12, MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH
379      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d},
380     {0x13, MM_PACKED, 320, 200, 8, 8,  8, SEG_GRAPH
381      , 0xFF, PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13},
382     {0x6A, MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH
383      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d},
384 };
385
386 struct vgamode_s *
387 find_vga_entry(u8 mode)
388 {
389     int i;
390     for (i = 0; i < ARRAY_SIZE(vga_modes); i++) {
391         struct vgamode_s *vmode_g = &vga_modes[i];
392         if (GET_GLOBAL(vmode_g->mode) == mode)
393             return vmode_g;
394     }
395     return NULL;
396 }
397
398
399 /****************************************************************
400  * Static functionality table
401  ****************************************************************/
402
403 u8 static_functionality[0x10] VAR16 = {
404  /* 0 */ 0xff,  // All modes supported #1
405  /* 1 */ 0xe0,  // All modes supported #2
406  /* 2 */ 0x0f,  // All modes supported #3
407  /* 3 */ 0x00, 0x00, 0x00, 0x00,  // reserved
408  /* 7 */ 0x07,  // 200, 350, 400 scan lines
409  /* 8 */ 0x02,  // mamimum number of visible charsets in text mode
410  /* 9 */ 0x08,  // total number of charset blocks in text mode
411  /* a */ 0xe7,  // Change to add new functions
412  /* b */ 0x0c,  // Change to add new functions
413  /* c */ 0x00,  // reserved
414  /* d */ 0x00,  // reserved
415  /* e */ 0x00,  // Change to add new functions
416  /* f */ 0x00   // reserved
417 };