root/morphix/trunk/ddcxinfo/svgamodes.c

Revision 2, 5.0 kB (checked in by nextime, 2 years ago)

Initial import, branching from morphix svn

Line 
1 #include <sys/types.h>
2 #include <sys/io.h>
3 #include <sys/stat.h>
4 #include <sys/vm86.h>
5 #include <sys/syscall.h>
6 #include <sys/mman.h>
7 #include <assert.h>
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <signal.h>
15 #include <netinet/in.h>
16 #include "vbe.h"
17 #include "vesamode.h"
18 #include "lrmi.h"
19 #ident "$Id: svgamodes.c 1815 2005-04-25 08:27:54Z alextreme $"
20
21 /* Callback for qsort(). */
22 static int compare_16(const void *i1, const void *i2)
23 {
24         const u_int16_t *I1, *I2;
25         I1 = (const u_int16_t*) i1;
26         I2 = (const u_int16_t*) i2;
27         if(*I1 < *I2) return -1;
28         if(*I1 > *I2) return 1;
29         return 0;
30 }
31
32 int main(int argc, char **argv)
33 {
34         struct vbe_info *vbe_info = NULL;
35         struct vbe_mode_info *mode_info = NULL;
36         u_int16_t *mode_list = NULL;
37         int mode_count = 0;
38         float vesa_version;
39
40         /* Get basic information. */
41         vbe_info = vbe_get_vbe_info();
42         if(vbe_info == NULL) {
43                 printf("VESA BIOS Extensions not detected.\n");
44                 exit(0);
45         }
46
47         /* Print the signature, should be "VESA <digit>.<digit>". */
48         printf("%c%c%c%c %d.%d detected.\n",
49                vbe_info->signature[0], vbe_info->signature[1],
50                vbe_info->signature[2], vbe_info->signature[3],
51                vbe_info->version[1], vbe_info->version[0]);
52         vesa_version =  (vbe_info->version[1]) + (vbe_info->version[0]) / 10.0;
53
54         /* List supported standard modes. */
55         mode_list = vbe_info->mode_list.list;
56         if(*mode_list != 0xffff) {
57                 printf("Supported modes:\n");
58         }
59         /* Count the number of modes. */
60         for(;*mode_list != 0xffff; mode_list++) {
61                 mode_count++;
62         }
63         /* Sort the mode list, because my ATI doesn't.  Grrr... */
64         mode_list = vbe_info->mode_list.list;
65         if(*mode_list != 0xffff) {
66                 qsort(mode_list, mode_count, sizeof(u_int16_t), compare_16);
67         }
68         /* Dump info about the video mode. */
69         for(;*mode_list != 0xffff; mode_list++) {
70                 int j;
71                 /* Mode number. */
72                 printf("0x%03x\t", *mode_list);
73                 for(j = 0; known_vesa_modes[j].x != 0; j++) {
74                 /* If it's a standard mode, print info about it. */
75                 if(known_vesa_modes[j].number == *mode_list) {
76                         printf("Specs list this as %dx%d, %d colors.",
77                                known_vesa_modes[j].x,
78                                known_vesa_modes[j].y,
79                                known_vesa_modes[j].colors);
80                 }}
81                 printf("\n");
82                 /* Get mode information from the BIOS.  Should never fail. */
83                 mode_info = vbe_get_mode_info(*mode_list);
84                 if(mode_info == NULL) {
85                         printf("Get mode information not supported by BIOS.\n");
86                         exit(0);
87                 }
88
89                 /* Report what the BIOS says about the mode, should agree
90                    with VESA on standard modes. */
91                 if(mode_info->w && mode_info->h && mode_info->bpp) {
92                         printf("\tBIOS reports this as %dx%d, %d bpp",
93                                mode_info->w, mode_info->h,
94                                mode_info->bpp);
95                 }
96                 if(mode_info->bytes_per_scanline) {
97                         printf(", %d bytes per scanline.",
98                                mode_info->bytes_per_scanline);
99                 }
100                 printf("\n");
101                 /* Check the 'supported' bit.  Should be set, because this is
102                    in the main supported modes list. */
103                 printf("\t%s, ", mode_info->mode_attributes.supported ?
104                        "Supported" : "Not supported");
105                 /* Color?  Graphics? */
106                 printf("%s ", mode_info->mode_attributes.color ?
107                        "Color" : "Monochrome");
108                 printf("%s.\n", mode_info->mode_attributes.graphics ?
109                        "Graphics" : "Text");
110                 /* Check for LFB stuff.  Ralf's list says that you need to
111                    query with bit 14 set to check if an LFB version of the mode
112                    is available, but the ATI always returns true. */
113                 if(vesa_version >= 2.0) {
114                         /* Regular info about the current mode. */
115                         struct vbe_mode_info *info = NULL;
116                         printf("\t%sVGA compatible.\n",
117                                mode_info->mode_attributes.not_vga_compatible ?
118                                "Not " : "");
119                         printf("\tThis is %san LFB mode.\n",
120                                mode_info->mode_attributes.lfb ?
121                                "" : "not ");
122                         /* Info about the LFB variant mode (bit 14 set). */
123                         info = vbe_get_mode_info(*mode_list |
124                                                  VBE_LINEAR_FRAMEBUFFER);
125                         if(info) {
126                                 if(info->mode_attributes.lfb) {
127                                         printf("\tLFB variant available.\n");
128                                 }
129                                 free(info);
130                         }
131                         if((mode_info->mode_attributes.lfb) ||
132                            (info && (info->mode_attributes.lfb))) {
133                                 printf("\tLFB at address 0x%8x.\n",
134                                        mode_info->linear_buffer_address);
135                         }
136                 }
137                 /* Memory model: EGA = icky bit planes, packed-pixel = palette,
138                    direct color = LFB compatible but needs bank switches. */
139                 printf("\tMemory model: ");
140                 switch(mode_info->memory_model) {
141                         case memory_model_text: {
142                                 printf("text.\n");
143                                 break;
144                         }
145                         case memory_model_cga: {
146                                 printf("CGA.\n");
147                                 break;
148                         }
149                         case memory_model_hgc: {
150                                 printf("Hercules.\n");
151                                 break;
152                         }
153                         case memory_model_ega16: {
154                                 printf("EGA.\n");
155                                 break;
156                         }
157                         case memory_model_packed_pixel: {
158                                 printf("packed-pixel.\n");
159                                 break;
160                         }
161                         case memory_model_sequ256: {
162                                 printf("sequential 256.\n");
163                                 break;
164                         }
165                         case memory_model_direct_color: {
166                                 printf("direct color.\n");
167                                 break;
168                         }
169                         case memory_model_yuv: {
170                                 printf("YUV.\n");
171                                 break;
172                         }
173                         default : {
174                                 printf("unknown/OEM.\n");
175                         }
176                 }
177         }
178         return 0;
179 }
Note: See TracBrowser for help on using the browser.