6 /* VGA DAC registers used for palette setting in 8bpp modes */
7 #define VGA_DAC_STATE 0x3c7
8 #define VGA_DAC_ADDR_RD 0x3c7
9 #define VGA_DAC_ADDR_WR 0x3c8
10 #define VGA_DAC_DATA 0x3c9
12 #define MODE_LFB (1 << 14)
15 struct vbe_info *vbe_get_info(void)
17 static unsigned short info_block_seg;
18 static struct vbe_info *info;
19 struct dpmi_real_regs regs;
22 /* allocate 32 paragraphs (512 bytes) */
23 info_block_seg = dpmi_alloc(32);
24 info = (struct vbe_info*)(info_block_seg << 4);
27 memcpy(info->sig, "VBE2", 4);
29 memset(®s, 0, sizeof regs);
30 regs.es = info_block_seg;
33 dpmi_real_int(0x10, ®s);
38 struct vbe_mode_info *vbe_get_mode_info(int mode)
40 static unsigned short mode_info_seg;
41 static struct vbe_mode_info *mi;
42 struct dpmi_real_regs regs;
45 /* allocate 16 paragraphs (256 bytes) */
46 mode_info_seg = dpmi_alloc(16);
47 mi = (struct vbe_mode_info*)(mode_info_seg << 4);
50 memset(®s, 0, sizeof regs);
51 regs.es = mode_info_seg;
54 regs.es = mode_info_seg;
56 dpmi_real_int(0x10, ®s);
57 if(regs.eax & 0xff00) {
64 int vbe_set_mode(int mode)
66 struct dpmi_real_regs regs;
68 memset(®s, 0, sizeof regs);
71 dpmi_real_int(0x10, ®s);
73 if(regs.eax == 0x100) {
79 int vbe_set_palette_bits(int bits)
81 struct dpmi_real_regs regs;
83 memset(®s, 0, sizeof regs);
85 regs.ebx = bits << 8; /* bits in bh */
86 dpmi_real_int(0x10, ®s);
88 if((regs.eax >> 8) & 0xff == 3) {
91 return regs.ebx >> 8 & 0xff; /* new color bits in bh */
94 /* TODO: implement palette setting through the VBE2 interface for
95 * non-VGA displays (actually don't).
97 void vbe_set_palette(int idx, int *col, int count, int bits)
99 int i, shift = 8 - bits;
102 mov dx, VGA_DAC_ADDR_WR
107 for(i=0; i<count; i++) {
108 unsigned char r = *col++;
109 unsigned char g = *col++;
110 unsigned char b = *col++;
130 static unsigned int get_mask(int sz, int pos)
132 unsigned int i, mask = 0;
134 for(i=0; i<sz; i++) {
140 void print_mode_info(FILE *fp, struct vbe_mode_info *mi)
142 fprintf(fp, "resolution: %dx%d\n", mi->xres, mi->yres);
143 fprintf(fp, "color depth: %d\n", mi->bpp);
144 fprintf(fp, "mode attributes: %x\n", mi->mode_attr);
145 fprintf(fp, "bytes per scanline: %d\n", mi->scanline_bytes);
146 fprintf(fp, "number of planes: %d\n", (int)mi->num_planes);
147 fprintf(fp, "number of banks: %d\n", (int)mi->num_banks);
148 fprintf(fp, "mem model: %d\n", (int)mi->mem_model);
149 fprintf(fp, "red bits: %d (mask: %x)\n", (int)mi->rmask_size, get_mask(mi->rmask_size, mi->rpos));
150 fprintf(fp, "green bits: %d (mask: %x)\n", (int)mi->gmask_size, get_mask(mi->gmask_size, mi->gpos));
151 fprintf(fp, "blue bits: %d (mask: %x)\n", (int)mi->bmask_size, get_mask(mi->bmask_size, mi->bpos));
152 fprintf(fp, "framebuffer address: %x\n", mi->fb_addr);