vbeinfo

view src/main.c @ 3:5b0ef094b8fd

backported changes from more recent VBE projects
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 07 Jan 2019 12:07:53 +0200
parents d2d777a5da95
children d2c44edd8b77
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "vbe.h"
5 #define REALPTR(s, o) (void*)(((uint32_t)(s) << 4) + (uint32_t)(o))
6 #define VBEPTR(x) REALPTR(((x) & 0xffff0000) >> 16, (x) & 0xffff)
7 #define VBEPTR_SEG(x) (((x) & 0xffff0000) >> 16)
8 #define VBEPTR_OFF(x) ((x) & 0xffff)
10 struct video_mode {
11 int xres, yres, bpp;
12 };
14 void sort_modes(struct video_mode *arr, int sz, int field);
16 int main(int argc, char **argv)
17 {
18 int i, nmodes;
19 struct vbe_info *vbe;
20 struct vbe_mode_info *mode;
21 uint16_t *modes;
22 struct video_mode *vmodes;
23 char *vendor, *product, *prod_rev;
25 if(!(vbe = vbe_get_info())) {
26 fprintf(stderr, "VBE not found\n");
27 return 1;
28 }
30 if(!(vendor = VBEPTR(vbe->oem_vendor_name_ptr)) || !*vendor) {
31 vendor = "unknown";
32 }
33 if(!(product = VBEPTR(vbe->oem_product_name_ptr)) || !*product) {
34 product = "unknown";
35 }
36 if(!(prod_rev = VBEPTR(vbe->oem_product_rev_ptr)) || !*prod_rev) {
37 prod_rev = "unknown";
38 }
40 printf("VBE version: %x.%x\n", vbe->version >> 8, vbe->version & 0xff);
41 printf("Graphics adapter: %s, %s (%s)\n", vendor, product, prod_rev);
42 printf("Video memory: %dkb\n", vbe->total_mem << 6);
44 modes = VBEPTR(vbe->vid_mode_ptr);
45 nmodes = 0;
46 for(i=0; i<1024; i++) {
47 if(modes[i] == 0xffff) break;
48 nmodes++;
49 }
50 printf("%d video modes found:\n", nmodes);
52 if(!(vmodes = malloc(nmodes * sizeof *vmodes))) {
53 fprintf(stderr, "failed to allocate video modes array\n");
54 return 1;
55 }
57 for(i=0; i<nmodes; i++) {
58 if(!(mode = vbe_get_mode_info(modes[i]))) {
59 fprintf(stderr, "failed to get mode %d info\n", i);
60 }
61 vmodes[i].xres = mode->xres;
62 vmodes[i].yres = mode->yres;
63 vmodes[i].bpp = mode->bpp;
64 }
66 sort_modes(vmodes, nmodes, 2);
67 sort_modes(vmodes, nmodes, 1);
69 for(i=0; i<nmodes; i++) {
70 if(i == 0 || vmodes[i].xres != vmodes[i - 1].xres ||
71 vmodes[i].yres != vmodes[i - 1].yres) {
72 printf("\n%4dx%d - depth:", vmodes[i].xres, vmodes[i].yres);
73 }
74 printf(" %d", vmodes[i].bpp);
75 }
76 putchar('\n');
78 free(vmodes);
79 return 0;
80 }
82 void sort_modes(struct video_mode *arr, int sz, int field)
83 {
84 int i, j;
85 struct video_mode tmp;
87 for(i=0; i<sz; i++) {
88 for(j=i+1; j<sz; j++) {
89 if(((int*)(arr + i))[field] >= ((int*)(arr + j))[field]) {
90 tmp = arr[i];
91 arr[i] = arr[j];
92 arr[j] = tmp;
93 }
94 }
95 }
96 }