void VID_InitModes(void) { int i; // get complete information on all modes num_modes = vga_lastmodenumber()+1; modes = malloc(num_modes * sizeof(vga_modeinfo)); for (i=0 ; i<num_modes ; i++) { if (vga_hasmode(i)) memcpy(&modes[i], vga_getmodeinfo(i), sizeof (vga_modeinfo)); else modes[i].width = 0; // means not available } // filter for modes i don't support for (i=0 ; i<num_modes ; i++) { if (modes[i].bytesperpixel != 1 && modes[i].colors != 256) modes[i].width = 0; } for (i = 0; i < num_modes; i++) if (modes[i].width) ri.Con_Printf(PRINT_ALL, "mode %d: %d %d\n", modes[i].width, modes[i].height); }
static int find_best_svga_mode(int req_w,int req_h, int req_bpp){ int badness,prev_badness; int bestmode,lastmode; int i; vga_modeinfo *vminfo; //int best aspect mode // best linear mode // best normal mode (no modeX) prev_badness = 0;//take care of special case below bestmode = 0; //0 is the TEXT mode lastmode = vga_lastmodenumber(); for(i=1;i<=lastmode;i++){ vminfo = vga_getmodeinfo(i); if( vminfo == NULL ) continue; if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i)); if( vga_hasmode(i) == 0 ) continue; if( req_bpp != bpp_from_vminfo(vminfo) )continue; if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue; badness=(vminfo->width * vminfo->height) - (req_h * req_w); //put here aspect calculations if(squarepix) if( vminfo->width*3 != vminfo->height*4 ) continue; if( bestmode==0 || prev_badness >= badness ){//modeX etc... prev_badness=badness; bestmode=i; if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness); } } return bestmode; }
d_rasterdescription_t *d_raster_getmodes(int *nmodes) { d_rasterdescription_t *modes; vga_modeinfo *minf; int i; modes = NULL; *nmodes = 0; for(i = 1; i < vga_lastmodenumber(); i++) { if(vga_hasmode(i) == 0) continue; (*nmodes)++; modes = d_memory_resize(modes, *nmodes*sizeof(d_rasterdescription_t)); if(modes == NULL) { d_error_push("d_raster_getmodes: d_memory_resize failed."); return NULL; } minf = vga_getmodeinfo(i); modes[*nmodes-1].w = minf->width; modes[*nmodes-1].h = minf->height; modes[*nmodes-1].bpp = log2(minf->colors); modes[*nmodes-1].alpha = 0; if(modes[*nmodes-1].bpp == 8) modes[*nmodes-1].paletted = true; else modes[*nmodes-1].paletted = false; modes[*nmodes-1].cspace = RGB; } return modes; }
void find_mode( int exact ) { vga_modeinfo *inf; int i, j, w, h; for( i = 0; i <= vga_lastmodenumber(); i++ ) { if( vga_hasmode( i ) ) { inf = vga_getmodeinfo( i ); if( inf->colors >= 16 && !( inf->flags & IS_MODEX ) && inf->width >= 320 && inf->height >= 240 && inf->width <= 1280 && inf->height <= 1024 ) { /* try exact match */ for( j = 0; j < 3; j++ ) { w = DISPLAY_ASPECT_WIDTH * ( j + 1 ); h = DISPLAY_SCREEN_HEIGHT * ( j + 1 ); if( exact == 0 && inf->width == w && inf->height == h && ( modes[j].n == -1 || ( ( modes[j].width != w || modes[j].height != h || modes[j].depth != 16 ) && ( inf->colors == 65536 || inf->colors > modes[j].colors ) ) ) ) { set_mode( j, i, inf ); } if( exact == 1 && inf->width >= w && inf->height >= h && inf->width < w * 5 / 4 && inf->height < h * 5 / 4 && ( modes[j].n == -1 || ( ( modes[j].width > inf->width || modes[j].height > inf->height || modes[j].depth != 16 ) && ( inf->colors == 65536 || inf->colors > modes[j].colors ) ) ) ) { set_mode( j, i, inf ); } if( exact == -1 && inf->width <= w && inf->height <= h && inf->width > w * 3 / 4 && inf->height > h * 3 / 4 && ( modes[j].n == -1 || ( ( modes[j].width < inf->width || modes[j].height < inf->height || modes[j].depth != 16 ) && ( inf->colors == 65536 || inf->colors > modes[j].colors ) ) ) ) { set_mode( j, i, inf ); } } } } } }
bool d_raster_setmode(d_rasterdescription_t mode) { vga_modeinfo *minf; int i, ret; if(mode.cspace == grayscale) { d_error_push(__FUNCTION__": grayscale modes are not supported " "with this driver."); return failure; } for(i = 1; i < vga_lastmodenumber(); i++) { if(vga_hasmode(i) == 0) continue; minf = vga_getmodeinfo(i); if(minf->width == mode.w && minf->height == mode.h && minf->colors == 1<<mode.bpp) { ret = vga_setmode(i); if(ret != 0) { d_error_push(__FUNCTION__": vga_setmode failed."); return failure; } raster_curmode = mode; if(raster_vbuf != NULL) d_memory_delete(raster_vbuf); raster_vbuf = d_memory_new((mode.w*mode.h*mode.bpp+7)/8); if(raster_vbuf == NULL) { d_error_push(__FUNCTION__": memory allocation failed for " "raster_vbuf."); return failure; } return success; } } d_error_push(__FUNCTION__": no such mode available."); return failure; }
static void VID_InitModes (void) { int i; /* get complete information on all modes */ num_modes = vga_lastmodenumber() + 1; modes = (vga_modeinfo *) Z_Malloc(num_modes * sizeof(vga_modeinfo), Z_MAINZONE); for (i = 0; i < num_modes; i++) { if (vga_hasmode(i)) memcpy(&modes[i], vga_getmodeinfo(i), sizeof(vga_modeinfo)); else modes[i].width = 0; /* means not available */ } /* filter for modes i don't support */ for (i = 0; i < num_modes; i++) { if (modes[i].bytesperpixel != 1 && modes[i].colors != 256) modes[i].width = 0; } }
int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat) { int keyboard; int i, j; int mode, total_modes; /* Initialize all variables that we clean on shutdown */ for ( i=0; i<NUM_MODELISTS; ++i ) { SDL_nummodes[i] = 0; SDL_modelist[i] = NULL; SDL_vgamode[i] = NULL; } /* Initialize the library */ vga_disabledriverreport(); if ( vga_init() < 0 ) { SDL_SetError("Unable to initialize SVGAlib"); return(-1); } vga_setmode(TEXT); /* Enable mouse and keyboard support */ vga_setmousesupport(1); keyboard = keyboard_init_return_fd(); if ( keyboard < 0 ) { SDL_SetError("Unable to initialize keyboard"); return(-1); } if ( SVGA_initkeymaps(keyboard) < 0 ) { return(-1); } keyboard_seteventhandler(SVGA_keyboardcallback); /* Determine the screen depth (use default 8-bit depth) */ vformat->BitsPerPixel = 8; /* Enumerate the available fullscreen modes */ total_modes = 0; for ( mode=vga_lastmodenumber(); mode; --mode ) { if ( vga_hasmode(mode) ) { if ( SVGA_AddMode(this, mode, 0, 0) ) { ++total_modes; } } } if ( SVGA_AddMode(this, G320x200x256, 0, 1) ) ++total_modes; if ( total_modes == 0 ) { SDL_SetError("No linear video modes available"); return(-1); } for ( i=0; i<NUM_MODELISTS; ++i ) { SDL_vgamode[i] = (int *)malloc(SDL_nummodes[i]*sizeof(int)); if ( SDL_vgamode[i] == NULL ) { SDL_OutOfMemory(); return(-1); } SDL_modelist[i] = (SDL_Rect **) malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *)); if ( SDL_modelist[i] == NULL ) { SDL_OutOfMemory(); return(-1); } for ( j=0; j<SDL_nummodes[i]; ++j ) { SDL_modelist[i][j]=(SDL_Rect *)malloc(sizeof(SDL_Rect)); if ( SDL_modelist[i][j] == NULL ) { SDL_OutOfMemory(); return(-1); } memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect)); } SDL_modelist[i][j] = NULL; } for ( mode=vga_lastmodenumber(); mode; --mode ) { if ( vga_hasmode(mode) ) { SVGA_AddMode(this, mode, 1, 0); } } SVGA_AddMode(this, G320x200x256, 1, 1); /* Free extra (duplicated) modes */ for ( i=0; i<NUM_MODELISTS; ++i ) { j = 0; while ( SDL_modelist[i][j] && SDL_modelist[i][j]->w ) { j++; } while ( SDL_modelist[i][j] ) { free(SDL_modelist[i][j]); SDL_modelist[i][j] = NULL; j++; } } /* Fill in our hardware acceleration capabilities */ SVGA_UpdateVideoInfo(this); /* We're done! */ return(0); }
int main(int argc, char *argv[]) { int mode, mode2; int i, high; vga_init(); /* Initialize. */ mode = -1; mode2= -1; if(argc==2) { mode = atoi(argv[1]); } else if(argc==3) { mode = atoi(argv[1]); mode2= atoi(argv[2]); } if (mode == -1) { printf("Choose one of the following video modes: \n"); high = 0; for (i = 1; i <= vga_lastmodenumber(); i++) if (vga_hasmode(i)) { vga_modeinfo *info; char expl[100]; const char *cols = NULL; *expl = '\0'; info = vga_getmodeinfo(i); switch (info->colors) { case 2: cols = "2"; strcpy(expl, "1 bitplane, monochrome"); break; case 16: cols = "16"; strcpy(expl, "4 bitplanes"); break; case 256: if (i == G320x200x256) strcpy(expl, "packed-pixel"); else if (i == G320x240x256 || i == G320x400x256 || i == G360x480x256) strcpy(expl, "Mode X"); else strcpy(expl, "packed-pixel, banked"); break; case 1 << 15: cols = "32K"; strcpy(expl, "5-5-5 RGB, blue at LSB, banked"); break; case 1 << 16: cols = "64K"; strcpy(expl, "5-6-5 RGB, blue at LSB, banked"); break; case 1 << 24: cols = "16M"; if (info->bytesperpixel == 3) { if (info->flags & RGB_MISORDERED) strcpy(expl, "8-8-8 BGR, red byte first, banked"); else strcpy(expl, "8-8-8 RGB, blue byte first, banked"); } else if (info->flags & RGB_MISORDERED) strcpy(expl, "8-8-8 RGBX, 32-bit pixels, X byte first, banked"); else strcpy(expl, "8-8-8 XRGB, 32-bit pixels, blue byte first, banked"); break; } if (info->flags & IS_INTERLACED) { if (*expl != '\0') strcat(expl, ", "); strcat(expl, "interlaced"); } if (info->flags & IS_DYNAMICMODE) { if (*expl != '\0') strcat(expl, ", "); strcat(expl, "dynamically loaded"); } high = i; printf("%5d: %dx%d, ", i, info->width, info->height); if (cols == NULL) printf("%d", info->colors); else printf("%s", cols); printf(" colors "); if (*expl != '\0') printf("(%s)", expl); printf("\n"); } printf("Enter mode number (1-%d): ", high); scanf("%d", &mode); getchar(); printf("\n"); if (mode < 1 || mode > GLASTMODE) { printf("Error: Mode number out of range \n"); exit(-1); } } if (vga_hasmode(mode)) { testmode(mode); if(mode2!=-1 && vga_hasmode(mode2)) { testmode(mode2); } } else { printf("Error: Video mode not supported by driver\n"); exit(-1); } vga_setmode(TEXT); return 0; }