• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * vesainfo.c
3  *
4  * Dump information about what VESA graphics modes are supported.
5  */
6 
7 #include <string.h>
8 #include <stdio.h>
9 #include <console.h>
10 #include <com32.h>
11 #include <inttypes.h>
12 #include "../lib/sys/vesa/vesa.h"
13 
14 /* Wait for a keypress */
wait_key(void)15 static void wait_key(void)
16 {
17     char ch;
18     while (fread(&ch, 1, 1, stdin) == 0) ;
19 }
20 
print_modes(void)21 static void print_modes(void)
22 {
23 	static com32sys_t rm;
24 	struct vesa_general_info *gi;
25 	struct vesa_mode_info *mi;
26 	uint16_t mode, *mode_ptr;
27 	int lines;
28 
29 	struct vesa_info *vesa;
30 
31 	vesa = lmalloc(sizeof(*vesa));
32 	if (!vesa) {
33 		printf("vesainfo.c32: fail in lmalloc\n");
34 		return;
35 	}
36 	gi = &vesa->gi;
37 	mi = &vesa->mi;
38 
39         memset(&rm, 0, sizeof rm);
40 	gi->signature = VBE2_MAGIC;	/* Get VBE2 extended data */
41 	rm.eax.w[0] = 0x4F00;	/* Get SVGA general information */
42 	rm.edi.w[0] = OFFS(gi);
43 	rm.es = SEG(gi);
44 	__intcall(0x10, &rm, &rm);
45 
46     if (rm.eax.w[0] != 0x004F) {
47 	printf("No VESA BIOS detected\n");
48 	goto exit;
49     } else if (gi->signature != VESA_MAGIC) {
50 	printf("VESA information structure has bad magic, trying anyway...\n");
51     }
52 
53     printf("VBE version %d.%d\n"
54 	   "Mode   attrib h_res v_res bpp layout rpos gpos bpos\n",
55 	   (gi->version >> 8) & 0xff, gi->version & 0xff);
56 
57     lines = 1;
58 
59     mode_ptr = GET_PTR(gi->video_mode_ptr);
60 
61     while ((mode = *mode_ptr++) != 0xFFFF) {
62 	if (++lines >= 23) {
63 	    wait_key();
64 	    lines = 0;
65 	}
66 
67         memset(&rm, 0, sizeof rm);
68 	rm.eax.w[0] = 0x4F01;	/* Get SVGA mode information */
69 	rm.ecx.w[0] = mode;
70 	rm.edi.w[0] = OFFS(mi);
71 	rm.es = SEG(mi);
72 	__intcall(0x10, &rm, &rm);
73 
74 	/* Must be a supported mode */
75 	if (rm.eax.w[0] != 0x004f)
76 	    continue;
77 
78 	printf("0x%04x 0x%04x %5u %5u %3u %6u %4u %4u %4u\n",
79 	       mode, mi->mode_attr, mi->h_res, mi->v_res, mi->bpp,
80 	       mi->memory_layout, mi->rpos, mi->gpos, mi->bpos);
81     }
82 
83 exit:
84 	lfree(vesa);
85 	return;
86 }
87 
main(int argc __unused,char ** argv __unused)88 int main(int argc __unused, char **argv __unused)
89 {
90     print_modes();
91     return 0;
92 }
93