1 /* Generate the VGABIOS VBE Tables */
2 #include <stdlib.h>
3 #include <stdio.h>
4 
5 #define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB 16
6 
7 typedef struct {
8     int width;
9     int height;
10     int depth;
11     int mode;
12 } ModeInfo;
13 
14 ModeInfo modes[] = {
15     /* standard VESA modes */
16 { 640, 400, 8                          , 0x100},
17 { 640, 480, 8                          , 0x101},
18 { 800, 600, 4                          , 0x102},
19 { 800, 600, 8                          , 0x103},
20 { 1024, 768, 4                         , 0x104},
21 { 1024, 768, 8                         , 0x105},
22 { 1280, 1024, 4                        , 0x106},
23 { 1280, 1024, 8                        , 0x107},
24 { 320, 200, 15                       , 0x10D},
25 { 320, 200, 16                        , 0x10E},
26 { 320, 200, 24                        , 0x10F},
27 { 640, 480, 15                       , 0x110},
28 { 640, 480, 16                        , 0x111},
29 { 640, 480, 24                        , 0x112},
30 { 800, 600, 15                       , 0x113},
31 { 800, 600, 16                        , 0x114},
32 { 800, 600, 24                        , 0x115},
33 { 1024, 768, 15                      , 0x116},
34 { 1024, 768, 16                       , 0x117},
35 { 1024, 768, 24                       , 0x118},
36 { 1280, 1024, 15                     , 0x119},
37 { 1280, 1024, 16                      , 0x11A},
38 { 1280, 1024, 24                      , 0x11B},
39 { 1600, 1200, 8                        , 0x11C},
40 { 1600, 1200, 15                     , 0x11D},
41 { 1600, 1200, 16                      , 0x11E},
42 { 1600, 1200, 24                      , 0x11F},
43 
44       /* BOCHS/PLE, 86 'own' mode numbers */
45 { 320, 200, 32                        , 0x140},
46 { 640, 400, 32                        , 0x141},
47 { 640, 480, 32                        , 0x142},
48 { 800, 600, 32                        , 0x143},
49 { 1024, 768, 32                       , 0x144},
50 { 1280, 1024, 32                      , 0x145},
51 { 320, 200, 8                           , 0x146},
52 { 1600, 1200, 32                      , 0x147},
53 { 1152, 864, 8                      , 0x148},
54 { 1152, 864, 15                      , 0x149},
55 { 1152, 864, 16                      , 0x14a},
56 { 1152, 864, 24                      , 0x14b},
57 { 1152, 864, 32                      , 0x14c},
58 { 1280, 768, 16                      , 0x175},
59 { 1280, 768, 24                      , 0x176},
60 { 1280, 768, 32                      , 0x177},
61 { 1280, 800, 16                      , 0x178},
62 { 1280, 800, 24                      , 0x179},
63 { 1280, 800, 32                      , 0x17a},
64 { 1280, 960, 16                      , 0x17b},
65 { 1280, 960, 24                      , 0x17c},
66 { 1280, 960, 32                      , 0x17d},
67 { 1440, 900, 16                      , 0x17e},
68 { 1440, 900, 24                      , 0x17f},
69 { 1440, 900, 32                      , 0x180},
70 { 1400, 1050, 16                     , 0x181},
71 { 1400, 1050, 24                     , 0x182},
72 { 1400, 1050, 32                     , 0x183},
73 { 1680, 1050, 16                     , 0x184},
74 { 1680, 1050, 24                     , 0x185},
75 { 1680, 1050, 32                     , 0x186},
76 { 1920, 1200, 16                     , 0x187},
77 { 1920, 1200, 24                     , 0x188},
78 { 1920, 1200, 32                     , 0x189},
79 { 2560, 1600, 16                     , 0x18a},
80 { 2560, 1600, 24                     , 0x18b},
81 { 2560, 1600, 32                     , 0x18c},
82 { 0, },
83 };
84 
main(int argc,char ** argv)85 int main(int argc, char **argv)
86 {
87   const ModeInfo *pm;
88   int pages, pitch;
89   int r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
90   const char *str;
91   long vram_size = VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024 * 1024;
92 
93   printf("/* THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
94   printf("#define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB %d\n\n", VBE_DISPI_TOTAL_VIDEO_MEMORY_MB);
95   printf("static ModeInfoListItem mode_info_list[]=\n");
96   printf("{\n");
97   for (pm = modes; pm->mode != 0; pm++) {
98     if (pm->depth == 4)
99       pitch = (pm->width + 7) / 8;
100     else
101       pitch = pm->width * ((pm->depth + 7) / 8);
102     pages = vram_size / (pm->height * pitch);
103     if (pages > 0) {
104       printf("{ 0x%04x, /* %dx%dx%d */\n",
105              pm->mode, pm->width, pm->height, pm->depth);
106       if (pm->depth == 4)
107         printf("{ /*Bit16u ModeAttributes*/ %s,\n",
108                "VBE_MODE_ATTRIBUTE_SUPPORTED | "
109                "VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE | "
110                "VBE_MODE_ATTRIBUTE_COLOR_MODE | "
111                "VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT | "
112                "VBE_MODE_ATTRIBUTE_GRAPHICS_MODE");
113       else
114         printf("{ /*Bit16u ModeAttributes*/ %s,\n",
115                "VBE_MODE_ATTRIBUTE_SUPPORTED | "
116                "VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE | "
117                "VBE_MODE_ATTRIBUTE_COLOR_MODE | "
118                "VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE | "
119                "VBE_MODE_ATTRIBUTE_GRAPHICS_MODE");
120       printf("/*Bit8u  WinAAttributes*/ %s,\n",
121              "VBE_WINDOW_ATTRIBUTE_RELOCATABLE | "
122              "VBE_WINDOW_ATTRIBUTE_READABLE | "
123              "VBE_WINDOW_ATTRIBUTE_WRITEABLE");
124 
125       printf("/*Bit8u  WinBAttributes*/ %d,\n", 0);
126 
127       printf("/*Bit16u WinGranularity*/ %s,\n", "VBE_DISPI_BANK_SIZE_KB");
128 
129       printf("/*Bit16u WinSize*/ %s,\n", "VBE_DISPI_BANK_SIZE_KB");
130 
131       printf("/*Bit16u WinASegment*/ %s,\n", "VGAMEM_GRAPH");
132 
133       printf("/*Bit16u WinBSegment*/ 0x%04x,\n", 0);
134 
135       printf("/*Bit32u WinFuncPtr*/ %d,\n", 0);
136 
137       printf("/*Bit16u BytesPerScanLine*/ %d,\n", pitch);
138 
139       // Mandatory information for VBE 1.2 and above
140       printf("/*Bit16u XResolution*/ %d,\n", pm->width);
141       printf("/*Bit16u YResolution*/ %d,\n", pm->height);
142       printf("/*Bit8u  XCharSize*/ %d,\n", 8);
143       printf("/*Bit8u  YCharSize*/ %d,\n", 16);
144       if (pm->depth == 4) {
145         printf("/*Bit8u  NumberOfPlanes*/ %d,\n", 4);
146       } else {
147         printf("/*Bit8u  NumberOfPlanes*/ %d,\n", 1);
148       }
149       printf("/*Bit8u  BitsPerPixel*/ %d,\n", pm->depth);
150       printf("/*Bit8u  NumberOfBanks*/ %d,\n",
151              (pm->height * pitch + 65535) / 65536);
152 
153       if (pm->depth == 4)
154         str = "VBE_MEMORYMODEL_PLANAR";
155       else if (pm->depth == 8)
156         str = "VBE_MEMORYMODEL_PACKED_PIXEL";
157       else
158         str = "VBE_MEMORYMODEL_DIRECT_COLOR";
159       printf("/*Bit8u  MemoryModel*/ %s,\n", str);
160       printf("/*Bit8u  BankSize*/ %d,\n", 0);
161       if (pm->depth == 4)
162         printf("/*Bit8u  NumberOfImagePages*/ %d,\n", (pages / 4) - 1);
163       else
164         printf("/*Bit8u  NumberOfImagePages*/ %d,\n", pages - 1);
165       printf("/*Bit8u  Reserved_page*/ %d,\n", 0);
166 
167       // Direct Color fields (required for direct/6 and YUV/7 memory models)
168       switch(pm->depth) {
169         case 15:
170           r_size = 5;
171           r_pos = 10;
172           g_size = 5;
173           g_pos = 5;
174           b_size = 5;
175           b_pos = 0;
176           a_size = 1;
177           a_pos = 15;
178           break;
179         case 16:
180           r_size = 5;
181           r_pos = 11;
182           g_size = 6;
183           g_pos = 5;
184           b_size = 5;
185           b_pos = 0;
186           a_size = 0;
187           a_pos = 0;
188           break;
189         case 24:
190           r_size = 8;
191           r_pos = 16;
192           g_size = 8;
193           g_pos = 8;
194           b_size = 8;
195           b_pos = 0;
196           a_size = 0;
197           a_pos = 0;
198           break;
199         case 32:
200           r_size = 8;
201           r_pos = 16;
202           g_size = 8;
203           g_pos = 8;
204           b_size = 8;
205           b_pos = 0;
206           a_size = 8;
207           a_pos = 24;
208           break;
209         default:
210           r_size = 0;
211           r_pos = 0;
212           g_size = 0;
213           g_pos = 0;
214           b_size = 0;
215           b_pos = 0;
216           a_size = 0;
217           a_pos = 0;
218           break;
219       }
220 
221       printf("/*Bit8u  RedMaskSize*/ %d,\n", r_size);
222       printf("/*Bit8u  RedFieldPosition*/ %d,\n", r_pos);
223       printf("/*Bit8u  GreenMaskSize*/ %d,\n", g_size);
224       printf("/*Bit8u  GreenFieldPosition*/ %d,\n", g_pos);
225       printf("/*Bit8u  BlueMaskSize*/ %d,\n", b_size);
226       printf("/*Bit8u  BlueFieldPosition*/ %d,\n", b_pos);
227       printf("/*Bit8u  RsvdMaskSize*/ %d,\n", a_size);
228       printf("/*Bit8u  RsvdFieldPosition*/ %d,\n", a_pos);
229       if (pm->depth == 32)
230         printf("/*Bit8u  DirectColorModeInfo*/ %s,\n",
231                "VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE");
232       else
233         printf("/*Bit8u  DirectColorModeInfo*/ %s,\n", "0");
234 
235 // Mandatory information for VBE 2.0 and above
236       if (pm->depth > 4)
237         printf("/*Bit32u PhysBasePtr*/ %s,\n",
238                "VBE_DISPI_LFB_PHYSICAL_ADDRESS");
239       else
240         printf("/*Bit32u PhysBasePtr*/ %s,\n", "0");
241       printf("/*Bit32u OffScreenMemOffset*/ %d,\n", 0);
242       printf("/*Bit16u OffScreenMemSize*/ %d,\n", 0);
243       // Mandatory information for VBE 3.0 and above
244       printf("/*Bit16u LinBytesPerScanLine*/ %d,\n", pitch);
245       printf("/*Bit8u  BnkNumberOfPages*/ %d,\n", 0);
246       printf("/*Bit8u  LinNumberOfPages*/ %d,\n", 0);
247       printf("/*Bit8u  LinRedMaskSize*/ %d,\n", r_size);
248       printf("/*Bit8u  LinRedFieldPosition*/ %d,\n", r_pos);
249       printf("/*Bit8u  LinGreenMaskSize*/ %d,\n", g_size);
250       printf("/*Bit8u  LinGreenFieldPosition*/ %d,\n", g_pos);
251       printf("/*Bit8u  LinBlueMaskSize*/ %d,\n", b_size);
252       printf("/*Bit8u  LinBlueFieldPosition*/ %d,\n", b_pos);
253       printf("/*Bit8u  LinRsvdMaskSize*/ %d,\n", a_size);
254       printf("/*Bit8u  LinRsvdFieldPosition*/ %d,\n", a_pos);
255       printf("/*Bit32u MaxPixelClock*/ %d,\n", 0);
256       printf("} },\n");
257     }
258   }
259   printf("{ VBE_VESA_MODE_END_OF_LIST,\n");
260   printf("{ 0,\n");
261   printf("} },\n");
262   printf("};\n");
263   return 0;
264 }
265