vbeinfo

view src/main.c @ 0:4b33fa83e381

vbeinfo initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 05 Dec 2015 07:28:47 +0200
parents
children d2d777a5da95
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);
15 /*int modecmp(const void *pa, const void *pb);*/
17 int main(int argc, char **argv)
18 {
19 int i, nmodes;
20 struct vbe_info *vbe;
21 struct vbe_mode_info *mode;
22 uint16_t *modes;
23 struct video_mode *vmodes;
25 if(!(vbe = vbe_get_info())) {
26 fprintf(stderr, "VBE not found\n");
27 return 1;
28 }
29 printf("VBE version: %x.%x\n", vbe->version >> 8, vbe->version & 0xff);
30 printf("Graphics adapter: %s, %s (%s)\n", VBEPTR(vbe->oem_vendor_name_ptr),
31 VBEPTR(vbe->oem_product_name_ptr), VBEPTR(vbe->oem_product_rev_ptr));
32 printf("Video memory: %dmb\n", vbe->total_mem << 6);
34 modes = VBEPTR(vbe->vid_mode_ptr);
35 nmodes = 0;
36 for(i=0; i<1024; i++) {
37 if(modes[i] == 0xffff) break;
38 nmodes++;
39 }
40 printf("%d video modes found:\n", nmodes);
42 if(!(vmodes = malloc(nmodes * sizeof *vmodes))) {
43 fprintf(stderr, "failed to allocate video modes array\n");
44 return 1;
45 }
47 for(i=0; i<nmodes; i++) {
48 if(!(mode = vbe_get_mode_info(modes[i]))) {
49 fprintf(stderr, "failed to get mode %d info\n", i);
50 }
51 vmodes[i].xres = mode->xres;
52 vmodes[i].yres = mode->yres;
53 vmodes[i].bpp = mode->bpp;
54 }
56 /*qsort(vmodes, nmodes, sizeof *vmodes, modecmp);*/
57 sort_modes(vmodes, nmodes, 2);
58 sort_modes(vmodes, nmodes, 1);
60 for(i=0; i<nmodes; i++) {
61 if(i == 0 || vmodes[i].xres != vmodes[i - 1].xres ||
62 vmodes[i].yres != vmodes[i - 1].yres) {
63 printf("\n%4dx%d - depth:", vmodes[i].xres, vmodes[i].yres);
64 }
65 printf(" %d", vmodes[i].bpp);
66 }
67 putchar('\n');
69 free(vmodes);
70 return 0;
71 }
72 /*
73 int modecmp(const void *pa, const void *pb)
74 {
75 const struct video_mode *va = pa;
76 const struct video_mode *vb = pb;
78 return va->xres * va->yres < vb->xres * vb->yres;
79 }
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 }