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/PLEX86 '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 { 1280, 720, 16 , 0x18d}, 83 { 1280, 720, 24 , 0x18e}, 84 { 1280, 720, 32 , 0x18f}, 85 { 1920, 1080, 16 , 0x190}, 86 { 1920, 1080, 24 , 0x191}, 87 { 1920, 1080, 32 , 0x192}, 88 { 0, }, 89 }; 90 91 int main(int argc, char **argv) 92 { 93 const ModeInfo *pm; 94 int pages, pitch; 95 int r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos; 96 const char *str; 97 long vram_size = VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024 * 1024; 98 99 printf("/* THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n"); 100 printf("#define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB %d\n\n", VBE_DISPI_TOTAL_VIDEO_MEMORY_MB); 101 printf("static ModeInfoListItem mode_info_list[]=\n"); 102 printf("{\n"); 103 for (pm = modes; pm->mode != 0; pm++) { 104 if (pm->depth == 4) 105 pitch = (pm->width + 7) / 8; 106 else 107 pitch = pm->width * ((pm->depth + 7) / 8); 108 pages = vram_size / (pm->height * pitch); 109 if (pages > 0) { 110 printf("{ 0x%04x, /* %dx%dx%d */\n", 111 pm->mode, pm->width, pm->height, pm->depth); 112 if (pm->depth == 4) 113 printf("{ /*Bit16u ModeAttributes*/ %s,\n", 114 "VBE_MODE_ATTRIBUTE_SUPPORTED | " 115 "VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE | " 116 "VBE_MODE_ATTRIBUTE_COLOR_MODE | " 117 "VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT | " 118 "VBE_MODE_ATTRIBUTE_GRAPHICS_MODE"); 119 else 120 printf("{ /*Bit16u ModeAttributes*/ %s,\n", 121 "VBE_MODE_ATTRIBUTE_SUPPORTED | " 122 "VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE | " 123 "VBE_MODE_ATTRIBUTE_COLOR_MODE | " 124 "VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE | " 125 "VBE_MODE_ATTRIBUTE_GRAPHICS_MODE"); 126 printf("/*Bit8u WinAAttributes*/ %s,\n", 127 "VBE_WINDOW_ATTRIBUTE_RELOCATABLE | " 128 "VBE_WINDOW_ATTRIBUTE_READABLE | " 129 "VBE_WINDOW_ATTRIBUTE_WRITEABLE"); 130 131 printf("/*Bit8u WinBAttributes*/ %d,\n", 0); 132 133 printf("/*Bit16u WinGranularity*/ %s,\n", "VBE_DISPI_BANK_SIZE_KB"); 134 135 printf("/*Bit16u WinSize*/ %s,\n", "VBE_DISPI_BANK_SIZE_KB"); 136 137 printf("/*Bit16u WinASegment*/ %s,\n", "VGAMEM_GRAPH"); 138 139 printf("/*Bit16u WinBSegment*/ 0x%04x,\n", 0); 140 141 printf("/*Bit32u WinFuncPtr*/ %d,\n", 0); 142 143 printf("/*Bit16u BytesPerScanLine*/ %d,\n", pitch); 144 145 // Mandatory information for VBE 1.2 and above 146 printf("/*Bit16u XResolution*/ %d,\n", pm->width); 147 printf("/*Bit16u YResolution*/ %d,\n", pm->height); 148 printf("/*Bit8u XCharSize*/ %d,\n", 8); 149 printf("/*Bit8u YCharSize*/ %d,\n", 16); 150 if (pm->depth == 4) { 151 printf("/*Bit8u NumberOfPlanes*/ %d,\n", 4); 152 } else { 153 printf("/*Bit8u NumberOfPlanes*/ %d,\n", 1); 154 } 155 printf("/*Bit8u BitsPerPixel*/ %d,\n", pm->depth); 156 printf("/*Bit8u NumberOfBanks*/ %d,\n", 157 (pm->height * pitch + 65535) / 65536); 158 159 if (pm->depth == 4) 160 str = "VBE_MEMORYMODEL_PLANAR"; 161 else if (pm->depth == 8) 162 str = "VBE_MEMORYMODEL_PACKED_PIXEL"; 163 else 164 str = "VBE_MEMORYMODEL_DIRECT_COLOR"; 165 printf("/*Bit8u MemoryModel*/ %s,\n", str); 166 printf("/*Bit8u BankSize*/ %d,\n", 0); 167 if (pm->depth == 4) 168 printf("/*Bit8u NumberOfImagePages*/ %d,\n", (pages / 4) - 1); 169 else 170 printf("/*Bit8u NumberOfImagePages*/ %d,\n", pages - 1); 171 printf("/*Bit8u Reserved_page*/ %d,\n", 0); 172 173 // Direct Color fields (required for direct/6 and YUV/7 memory models) 174 switch(pm->depth) { 175 case 15: 176 r_size = 5; 177 r_pos = 10; 178 g_size = 5; 179 g_pos = 5; 180 b_size = 5; 181 b_pos = 0; 182 a_size = 1; 183 a_pos = 15; 184 break; 185 case 16: 186 r_size = 5; 187 r_pos = 11; 188 g_size = 6; 189 g_pos = 5; 190 b_size = 5; 191 b_pos = 0; 192 a_size = 0; 193 a_pos = 0; 194 break; 195 case 24: 196 r_size = 8; 197 r_pos = 16; 198 g_size = 8; 199 g_pos = 8; 200 b_size = 8; 201 b_pos = 0; 202 a_size = 0; 203 a_pos = 0; 204 break; 205 case 32: 206 r_size = 8; 207 r_pos = 16; 208 g_size = 8; 209 g_pos = 8; 210 b_size = 8; 211 b_pos = 0; 212 a_size = 8; 213 a_pos = 24; 214 break; 215 default: 216 r_size = 0; 217 r_pos = 0; 218 g_size = 0; 219 g_pos = 0; 220 b_size = 0; 221 b_pos = 0; 222 a_size = 0; 223 a_pos = 0; 224 break; 225 } 226 227 printf("/*Bit8u RedMaskSize*/ %d,\n", r_size); 228 printf("/*Bit8u RedFieldPosition*/ %d,\n", r_pos); 229 printf("/*Bit8u GreenMaskSize*/ %d,\n", g_size); 230 printf("/*Bit8u GreenFieldPosition*/ %d,\n", g_pos); 231 printf("/*Bit8u BlueMaskSize*/ %d,\n", b_size); 232 printf("/*Bit8u BlueFieldPosition*/ %d,\n", b_pos); 233 printf("/*Bit8u RsvdMaskSize*/ %d,\n", a_size); 234 printf("/*Bit8u RsvdFieldPosition*/ %d,\n", a_pos); 235 if (pm->depth == 32) 236 printf("/*Bit8u DirectColorModeInfo*/ %s,\n", 237 "VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE"); 238 else 239 printf("/*Bit8u DirectColorModeInfo*/ %s,\n", "0"); 240 241 // Mandatory information for VBE 2.0 and above 242 if (pm->depth > 4) 243 printf("/*Bit32u PhysBasePtr*/ %s,\n", 244 "VBE_DISPI_LFB_PHYSICAL_ADDRESS"); 245 else 246 printf("/*Bit32u PhysBasePtr*/ %s,\n", "0"); 247 printf("/*Bit32u OffScreenMemOffset*/ %d,\n", 0); 248 printf("/*Bit16u OffScreenMemSize*/ %d,\n", 0); 249 // Mandatory information for VBE 3.0 and above 250 printf("/*Bit16u LinBytesPerScanLine*/ %d,\n", pitch); 251 printf("/*Bit8u BnkNumberOfPages*/ %d,\n", 0); 252 printf("/*Bit8u LinNumberOfPages*/ %d,\n", 0); 253 printf("/*Bit8u LinRedMaskSize*/ %d,\n", r_size); 254 printf("/*Bit8u LinRedFieldPosition*/ %d,\n", r_pos); 255 printf("/*Bit8u LinGreenMaskSize*/ %d,\n", g_size); 256 printf("/*Bit8u LinGreenFieldPosition*/ %d,\n", g_pos); 257 printf("/*Bit8u LinBlueMaskSize*/ %d,\n", b_size); 258 printf("/*Bit8u LinBlueFieldPosition*/ %d,\n", b_pos); 259 printf("/*Bit8u LinRsvdMaskSize*/ %d,\n", a_size); 260 printf("/*Bit8u LinRsvdFieldPosition*/ %d,\n", a_pos); 261 printf("/*Bit32u MaxPixelClock*/ %d,\n", 0); 262 printf("} },\n"); 263 } 264 } 265 printf("{ VBE_VESA_MODE_END_OF_LIST,\n"); 266 printf("{ 0,\n"); 267 printf("} },\n"); 268 printf("};\n"); 269 return 0; 270 } 271