int main(int argc,char *argv[]) { int mode,c; vga_init(); c=1; if(argc == 1) screen(10); /* G640x480x256 */ else c = 0; while(argc > 1) { argc--; c++; if(isdigit(*argv[c])) mode = atoi(argv[c]); else if(*argv[c] == 'G') mode = vga_getmodenumber(argv[c]); else { printf("Unknown mode %s\n",argv[c]); continue; } screen(mode); } vga_setmode(TEXT); return 0; }
int vga_getdefaultmode(void) { char *stmp = getenv("SVGALIB_DEFAULT_MODE"); /* Process env var first so mode might be overridden by it. */ if (stmp != NULL && strcmp(stmp, "") != 0) { int mode; if ( (mode = vga_getmodenumber(stmp)) != -1) return mode; } else if (__svgalib_default_mode) { return __svgalib_default_mode; } return -1; /* Not defined */ }
static int get_mode (char *name, int width, int height, int depth) { int i; int ok, match; match = (!!width) + (!!height)*2 + (!!depth)*4; if (name) { i = vga_getmodenumber(name); if (!modes[i].width) { Sys_Printf("Mode [%s] not supported\n", name); i = G320x200x256; } } else { for (i = 0; i < num_modes; i++) { if (modes[i].width) { ok = (modes[i].width == width) + (modes[i].height == height)*2 + (modes[i].bytesperpixel == depth/8)*4; if ((ok & match) == ok) break; } } if (i == num_modes) { Sys_Printf("Mode %dx%d (%d bits) not supported\n", width, height, depth); i = G320x200x256; } } return i; }
static int preinit(const char *arg) { int i; char s[64]; getch2_disable(); memset(zerobuf,0,sizeof(zerobuf)); force_vm=force_native=squarepix=0; sync_flip=vo_vsync; blackbar_osd=0; if(arg)while(*arg) { #ifdef CONFIG_VIDIX if(memcmp(arg,"vidix",5)==0) { i=6; while(arg[i] && arg[i]!=':') i++; strncpy(vidix_name, arg+6, i-6); vidix_name[i-5]=0; if(arg[i]==':')i++; arg+=i; vidix_preinit(vidix_name, &video_out_svga); } #endif if(!strncmp(arg,"sq",2)) { squarepix=1; arg+=2; if( *arg == ':' ) arg++; } if(!strncmp(arg,"native",6)) { force_native=1; arg+=6; if( *arg == ':' ) arg++; } if(!strncmp(arg,"bbosd",5)) { blackbar_osd=1; arg+=5; if( *arg == ':' ) arg++; } if(!strncmp(arg,"retrace",7)) { sync_flip=1; arg+=7; if( *arg == ':' ) arg++; } if(*arg) { i=0; while(arg[i] && arg[i]!=':')i++; if(i<64){ strncpy(s, arg, i); s[i]=0; force_vm=vga_getmodenumber(s); if(force_vm>0) { if( mp_msg_test(MSGT_VO,MSGL_V) ) mp_msg(MSGT_VO,MSGL_V, "vo_svga: Forcing mode %i\n",force_vm); }else{ force_vm = 0; } } arg+=i; if(*arg==':')arg++; } } vga_init(); return 0; }
static char *process_option(int command, int mode) { static char digits[] = ".0123456789"; char *ptr, **tabptr; //, *ptb; int i; float f; #ifdef DEBUG_CONF printf("command %d detected.\n", command); #endif switch (command) { case 5: #ifdef DEBUG_CONF puts("Allow override"); #endif break; case 0: /* mouse */ case 2: /* m */ ptr = strtok(NULL, " "); if (ptr == NULL) goto inv_mouse; if (check_digit(ptr, digits + 1)) { /* It is a number.. */ i = atoi(ptr); if ((i < 0) || (i > 9)) goto inv_mouse; mouse_type = i; } else { /* parse for symbolic name.. */ for (i = 0, tabptr = conf_mousenames; *tabptr; tabptr++, i++) { if (!strcasecmp(ptr, *tabptr)) { mouse_type = i; goto leave; } } inv_mouse: printf("svgalib: Illegal mouse setting: {mouse|m} %s\n" "Correct usage: {mouse|m} mousetype\n" "where mousetype is one of 0, 1, 2, 3, 4, 5, 6, 7, 9,\n", (ptr != NULL) ? ptr : ""); for (tabptr = conf_mousenames, i = 0; *tabptr; tabptr++, i++) { if (i == MOUSE_NONE) continue; printf("%s, ", *tabptr); } puts("or none."); return ptr; /* Allow a second parse of str */ } break; case 1: /* monitor */ case 3: /* M */ ptr = strtok(NULL, " "); if (check_digit(ptr, digits + 1)) { /* It is an int.. */ i = atoi(ptr); if (i < 7) { command = i + 12; goto monnum; } else { f = i; goto monkhz; } } else if (check_digit(ptr, digits)) { /* It is a float.. */ f = atof(ptr); monkhz: if (!mode) goto mon_deny; // __svgalib_horizsync.max = f * 1000.0f; } else { printf("svgalib: Illegal monitor setting: {monitor|M} %s\n" "Correct usage: {monitor|M} monitortype\n" "where monitortype is one of 0, 1, 2, 3, 4, 5, 6, or\n" "maximal horz. scan frequency in khz.\n" "Example: monitor 36.5\n", (ptr != NULL) ? ptr : ""); return ptr; /* Allow a second parse of str */ } break; case 4: /* chipset */ ptr = strtok(NULL, " "); break; case 6: /* oldstyle config: m0-m4 */ case 7: case 8: case 9: case 10: mouse_type = command - 6; break; case 11: /* m9 */ mouse_type = MOUSE_NONE; break; case 12: /* oldstyle config: M0-M6 */ case 13: case 14: case 15: case 16: case 17: case 18: monnum: if (!mode) { mon_deny: puts("Monitor setting from environment denied."); break; } break; case 19: /*nolinear */ break; case 20: /*linear */ break; case 21: /* oldstyle chipset C0 - C9 */ case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: break; case 31: /* c0-c1 color-text selection */ if (!mode) { coltexdeny: puts("Color/mono text selection from environment denied."); break; } color_text = 0; break; case 32: if (!mode) { puts("Color/mono text selection from environment denied."); break; } color_text = 1; break; case 33: case 34: if (!mode) goto coltexdeny; color_text = command - 32; break; case 35: /* Mouse type 5 - "PS2". */ mouse_type = 5; break; case 36: mouse_modem_ctl &= ~(MOUSE_CHG_DTR | MOUSE_DTR_HIGH); break; case 37: mouse_modem_ctl &= ~MOUSE_DTR_HIGH; mouse_modem_ctl |= MOUSE_CHG_DTR; break; case 38: mouse_modem_ctl |= (MOUSE_CHG_RTS | MOUSE_RTS_HIGH); break; case 39: mouse_modem_ctl &= ~(MOUSE_CHG_RTS | MOUSE_RTS_HIGH); break; case 40: mouse_modem_ctl &= ~MOUSE_RTS_HIGH; mouse_modem_ctl |= MOUSE_CHG_RTS; break; case 41: mouse_modem_ctl |= (MOUSE_CHG_RTS | MOUSE_RTS_HIGH); break; case 42: /* grayscale */ break; case 43: /* horizsync */ ptr = strtok(NULL, " "); if (check_digit(ptr, digits)) { /* It is a float.. */ f = atof(ptr); if (!mode) goto mon_deny; // __svgalib_horizsync.min = f * 1000; } else goto hs_bad; ptr = strtok(NULL, " "); if (check_digit(ptr, digits)) { /* It is a float.. */ f = atof(ptr); if (!mode) goto mon_deny; // __svgalib_horizsync.max = f * 1000; } else { hs_bad: printf("svgalib: Illegal HorizSync setting.\n" "Correct usage: HorizSync min_kHz max_kHz\n" "Example: HorizSync 31.5 36.5\n"); } break; case 44: /* vertrefresh */ ptr = strtok(NULL, " "); if (check_digit(ptr, digits)) { /* It is a float.. */ f = atof(ptr); if (!mode) goto mon_deny; // __svgalib_vertrefresh.min = f; } else goto vr_bad; ptr = strtok(NULL, " "); if (check_digit(ptr, digits)) { /* It is a float.. */ f = atof(ptr); if (!mode) goto mon_deny; // __svgalib_vertrefresh.max = f; } else { vr_bad: printf("svgalib: Illegal VertRefresh setting.\n" "Correct usage: VertRefresh min_Hz max_Hz\n" "Example: VertRefresh 50 70\n"); } break; case 45:{ /* modeline */ // MonitorModeTiming mmt; const struct { char *name; int val; } options[7]; /* = { */ /* { */ /* "-hsync", NHSYNC */ /* }, */ /* { */ /* "+hsync", PHSYNC */ /* }, */ /* { */ /* "-vsync", NVSYNC */ /* }, */ /* { */ /* "+vsync", PVSYNC */ /* }, */ /* { */ /* "interlace", INTERLACED */ /* }, */ /* { */ /* "interlaced", INTERLACED */ /* }, */ /* { */ /* "doublescan", DOUBLESCAN */ /* } */ /* }; */ #define ML_NR_OPTS (sizeof(options)/sizeof(*options)) /* Skip the name of the mode */ ptr = strtok(NULL, " "); if (!ptr) break; ptr = strtok(NULL, " "); if (!ptr) break; // mmt.pixelClock = atof(ptr) * 1000; #define ML_GETINT(x) \ ptr = strtok(NULL, " "); if(!ptr) break; // mmt.##x = atoi(ptr); ML_GETINT(HDisplay); ML_GETINT(HSyncStart); ML_GETINT(HSyncEnd); ML_GETINT(HTotal); ML_GETINT(VDisplay); ML_GETINT(VSyncStart); ML_GETINT(VSyncEnd); ML_GETINT(VTotal); // mmt.flags = 0; while ((ptr = strtok(NULL, " "))) { for (i = 0; i < ML_NR_OPTS; i++) /* if (!strcasecmp(ptr, options[i].name)) */ /* mmt.flags |= options[i].val; */ if (i == ML_NR_OPTS) break; } #undef ML_GETINT #undef ML_NR_OPTS return ptr; } case 46: if (!mode) { puts("Security setting from environment denied."); break; } if ( (ptr = strtok( NULL, " ")) ) { if (!strcasecmp("revoke-all-privs", ptr)) { // __svgalib_security_revokeallprivs = 1; break; } else if (!strcasecmp("compat", ptr)) { // __svgalib_security_revokeallprivs = 0; break; } } puts("svgalib: Unknown security options\n"); break; case 47: ptr = strtok(NULL," "); if (ptr) { mouse_device = strdup(ptr); if (mouse_device == NULL) { nomem: puts("svgalib: Fatal error: out of memory."); exit(1); } } else goto param_needed; break; case 48: /* default_mode */ if ( (ptr = strtok(NULL, " ")) != 0) { int mode = vga_getmodenumber(ptr); if (mode != -1) { __svgalib_default_mode = mode; } else { printf("svgalib: config: illegal mode \'%s\' for \'%s\'\n", ptr, vga_conf_commands[command]); } } else { param_needed: printf("svgalib: config: \'%s\' requires parameter(s)", vga_conf_commands[command]); break; } break; case 49: /* nosigint */ __svgalib_nosigint = 1; break; case 50: /* sigint */ __svgalib_nosigint = 0; break; case 51: /* joystick0 */ case 52: /* joystick1 */ case 53: /* joystick2 */ case 54: /* joystick3 */ if (! (ptr = strtok(NULL, " ")) ) goto param_needed; #ifndef SVGA_AOUT if (__joystick_devicenames[command - 51]) free(__joystick_devicenames[command - 51]); __joystick_devicenames[command - 51] = strdup(ptr); if (!__joystick_devicenames[command - 51]) goto nomem; #else printf("svgalib: No joystick support in a.out version.\n"); #endif break; case 55: /* TextProg */ ptr = strtok(NULL," "); if(ptr==NULL)break; /* __svgalib_textprog|=2; */ /* __svgalib_TextProg = strdup(ptr); */ /* if (!__svgalib_TextProg) */ /* goto nomem; */ i=1; while(((ptr=strtok(NULL," "))!=NULL) /* && */ /* (i< ((sizeof(__svgalib_TextProg_argv) / sizeof(char *)) + 1)) */ && strcmp(ptr,"END")){ /* __svgalib_TextProg_argv[i]=strdup(ptr); */ /* if (!__svgalib_TextProg_argv[i]) */ /* goto nomem; */ i++; }; /* __svgalib_TextProg_argv[i]=NULL; */ /* ptb=strrchr(__svgalib_TextProg,'/'); */ /* __svgalib_TextProg_argv[0]=ptb?ptb + 1:__svgalib_TextProg; */ /* printf("%s\n",__svgalib_TextProg); for(j=0;j<i;j++)printf("%i:%s\n",j,__svgalib_TextProg_argv[j]); */ break; } leave: return strtok(NULL, " "); }
int gr_set_mode(u_int32_t mode) { unsigned int w, h; char vgamode[16]; vga_modeinfo *modeinfo; int modenum, rowsize; void *framebuffer; #ifdef NOGRAPH return 0; #endif if (mode<=0) return 0; w=SM_W(mode); h=SM_H(mode); gr_palette_clear(); sprintf(vgamode, "G%dx%dx256", w, h); modenum = vga_getmodenumber(vgamode); vga_setmode(modenum); #ifdef SVGALIB_INPUT mouse_seteventhandler(mouse_handler); #endif modeinfo = vga_getmodeinfo(modenum); if (modeinfo->flags & CAPABLE_LINEAR) { usebuffer = 0; vga_setlinearaddressing(); // Set up physical screen only gl_setcontextvga(modenum); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); screenbuffer = physicalscreen; framebuffer = physicalscreen->vbuf; rowsize = physicalscreen->bytewidth; } else { usebuffer = 1; // Set up the physical screen gl_setcontextvga(modenum); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); // Set up the virtual screen gl_setcontextvgavirtual(modenum); screenbuffer = gl_allocatecontext(); gl_getcontext(screenbuffer); framebuffer = screenbuffer->vbuf; rowsize = screenbuffer->bytewidth; } memset(grd_curscreen, 0, sizeof(grs_screen)); grd_curscreen->sc_mode = mode; grd_curscreen->sc_w = w; grd_curscreen->sc_h = h; grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4); grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0; grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0; grd_curscreen->sc_canvas.cv_bitmap.bm_w = w; grd_curscreen->sc_canvas.cv_bitmap.bm_h = h; grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = rowsize; grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR; grd_curscreen->sc_canvas.cv_bitmap.bm_data = framebuffer; gr_set_current_canvas(NULL); gamefont_choose_game_font(w,h); return 0; }