9 struct vid_driver *vid_drvlist[MAX_DRV];
15 static struct vid_modeinfo **modes, *cur_mode;
16 static int num_modes, max_modes;
22 struct vid_modeinfo *vm;
28 num_modes = max_modes = 0;
33 if(dpmi_init() == -1) {
41 for(i=0; i<vid_numdrv; i++) {
42 struct vid_driver *drv = vid_drvlist[i];
46 for(j=0; j<drv->num_modes; j++) {
47 if(num_modes >= max_modes) {
48 int newsz = max_modes ? max_modes * 2 : 128;
49 void *tmp = realloc(modes, newsz * sizeof *modes);
51 fprintf(stderr, "failed to allocate modes list\n");
58 modes[num_modes++] = drv->modes + j;
62 printf("found %d modes:\n", num_modes);
63 for(i=0; i<num_modes; i+=2) {
65 len = printf("[%4s] %04x: %dx%d %dbpp", vm->drv->name, vm->modeno,
66 vm->width, vm->height, vm->bpp);
67 if(i + 1 >= num_modes) {
71 for(j=len; j<40; j++) putchar(' ');
73 printf("[%4s] %04x: %dx%d %dbpp\n", vm->drv->name, vm->modeno,
74 vm->width, vm->height, vm->bpp);
80 void vid_cleanup(void)
84 if(cur_mode && cur_mode->modeno != 3) {
88 if(vid_vmem >= (void*)0x100000) {
89 dpmi_munmap(vid_vmem);
92 for(i=0; i<vid_numdrv; i++) {
93 struct vid_driver *drv = vid_drvlist[i];
102 int vid_curmode(void)
105 return cur_mode->modeno;
110 void *vid_setmode(int mode)
113 struct vid_driver *drv;
115 for(i=0; i<num_modes; i++) {
116 if(modes[i]->modeno == mode) {
118 if(drv->ops->setmode(mode) == 0) {
121 if(vid_vmem >= (void*)0x100000) {
122 assert(vid_vmem_size);
123 dpmi_munmap(vid_vmem);
126 if(modes[i]->vmem_addr < 0x100000) {
127 vid_vmem = (void*)modes[i]->vmem_addr;
130 vid_vmem = dpmi_mmap(modes[i]->vmem_addr, modes[i]->vmem_size);
131 vid_vmem_size = modes[i]->vmem_size;
140 #define EQUIV_BPP(a, b) \
141 ((a) == (b) || ((a) == 16 && (b) == 15) || ((a) == 15 && (b) == 16) || \
142 ((a) == 24 && (b) == 32) || ((a) == 32 && (b) == 24))
144 int vid_findmode(int xsz, int ysz, int bpp)
148 for(i=0; i<num_modes; i++) {
149 if(modes[i]->width == xsz && modes[i]->height == ysz && modes[i]->bpp == bpp) {
150 return modes[i]->modeno;
154 /* try fuzzy bpp matching */
155 for(i=0; i<num_modes; i++) {
156 if(modes[i]->width == xsz && modes[i]->height == ysz &&
157 EQUIV_BPP(modes[i]->bpp, bpp)) {
158 return modes[i]->modeno;
166 struct vid_modeinfo *vid_modeinfo(int mode)
170 for(i=0; i<num_modes; i++) {
171 if(modes[i]->modeno == mode) {
183 void vid_setpal(int idx, int count, const struct vid_color *col)
185 cur_mode->ops.setpal(idx, count, col);
188 void vid_getpal(int idx, int count, struct vid_color *col)
190 cur_mode->ops.getpal(idx, count, col);