vbeinfo

view src/main.c @ 1:d2d777a5da95

fixed wrong memory size report
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 26 Jul 2017 21:05:01 +0300
parents 4b33fa83e381
children 193757920de9
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;
24 char *vendor, *product, *prod_rev;
26 if(!(vbe = vbe_get_info())) {
27 fprintf(stderr, "VBE not found\n");
28 return 1;
29 }
31 if(!(vendor = VBEPTR(vbe->oem_vendor_name_ptr)) || !*vendor) {
32 vendor = "unknown";
33 }
34 if(!(product = VBEPTR(vbe->oem_product_name_ptr)) || !*product) {
35 product = "unknown";
36 }
37 if(!(prod_rev = VBEPTR(vbe->oem_product_rev_ptr)) || !*prod_rev) {
38 prod_rev = "unknown";
39 }
41 printf("VBE version: %x.%x\n", vbe->version >> 8, vbe->version & 0xff);
42 printf("Graphics adapter: %s, %s (%s)\n", vendor, product, prod_rev);
43 printf("Video memory: %dkb\n", vbe->total_mem << 6);
45 modes = VBEPTR(vbe->vid_mode_ptr);
46 nmodes = 0;
47 for(i=0; i<1024; i++) {
48 if(modes[i] == 0xffff) break;
49 nmodes++;
50 }
51 printf("%d video modes found:\n", nmodes);
53 if(!(vmodes = malloc(nmodes * sizeof *vmodes))) {
54 fprintf(stderr, "failed to allocate video modes array\n");
55 return 1;
56 }
58 for(i=0; i<nmodes; i++) {
59 if(!(mode = vbe_get_mode_info(modes[i]))) {
60 fprintf(stderr, "failed to get mode %d info\n", i);
61 }
62 vmodes[i].xres = mode->xres;
63 vmodes[i].yres = mode->yres;
64 vmodes[i].bpp = mode->bpp;
65 }
67 /*qsort(vmodes, nmodes, sizeof *vmodes, modecmp);*/
68 sort_modes(vmodes, nmodes, 2);
69 sort_modes(vmodes, nmodes, 1);
71 for(i=0; i<nmodes; i++) {
72 if(i == 0 || vmodes[i].xres != vmodes[i - 1].xres ||
73 vmodes[i].yres != vmodes[i - 1].yres) {
74 printf("\n%4dx%d - depth:", vmodes[i].xres, vmodes[i].yres);
75 }
76 printf(" %d", vmodes[i].bpp);
77 }
78 putchar('\n');
80 free(vmodes);
81 return 0;
82 }
83 /*
84 int modecmp(const void *pa, const void *pb)
85 {
86 const struct video_mode *va = pa;
87 const struct video_mode *vb = pb;
89 return va->xres * va->yres < vb->xres * vb->yres;
90 }
91 */
93 void sort_modes(struct video_mode *arr, int sz, int field)
94 {
95 int i, j;
96 struct video_mode tmp;
98 for(i=0; i<sz; i++) {
99 for(j=i+1; j<sz; j++) {
100 if(((int*)(arr + i))[field] >= ((int*)(arr + j))[field]) {
101 tmp = arr[i];
102 arr[i] = arr[j];
103 arr[j] = tmp;
104 }
105 }
106 }
107 }