// // inittimer() -- initialise timer // int inittimer(int tickspersecond) { if (timerfreq) return 0; // already installed buildputs("Initialising timer\n"); timerfreq = 1000; timerticspersec = tickspersecond; timerlastsample = SDL_GetTicks() * timerticspersec / timerfreq; usertimercallback = NULL; return 0; }
// // initinput() -- init input system // int initinput(void) { int i,j; #ifdef __APPLE__ // force OS X to operate in >1 button mouse mode so that LMB isn't adulterated if (!getenv("SDL_HAS3BUTTONMOUSE")) putenv("SDL_HAS3BUTTONMOUSE=1"); #endif if (SDL_EnableKeyRepeat(250, 30)) buildputs("Error enabling keyboard repeat.\n"); inputdevices = 1|2; // keyboard (1) and mouse (2) mouseacquired = 0; SDL_EnableUNICODE(1); // let's hope this doesn't hit us too hard memset(keynames,0,sizeof(keynames)); for (i=0; i<SDLK_LAST; i++) { if (!keytranslation[i]) continue; strncpy(keynames[ keytranslation[i] ], SDL_GetKeyName(i), sizeof(keynames[i])-1); } if (!SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { i = SDL_NumJoysticks(); buildprintf("%d joystick(s) found\n",i); for (j=0;j<i;j++) buildprintf(" %d. %s\n", j+1, SDL_JoystickName(j)); joydev = SDL_JoystickOpen(0); if (joydev) { SDL_JoystickEventState(SDL_ENABLE); inputdevices |= 4; joynumaxes = SDL_JoystickNumAxes(joydev); joynumbuttons = min(32,SDL_JoystickNumButtons(joydev)); joynumhats = SDL_JoystickNumHats(joydev); buildprintf("Joystick 1 has %d axes, %d buttons, and %d hat(s).\n", joynumaxes,joynumbuttons,joynumhats); joyaxis = Bcalloc(joynumaxes, sizeof(int)); if (joynumhats > 0) { joyhat = malloc(joynumhats * sizeof(int)); memset(joyhat, -1, sizeof(int)*joynumhats); } } } return 0; }
int loadsetup(const char *fn) { scriptfile *cfg; char *token; int item; cfg = scriptfile_fromfile(fn); if (!cfg) { return -1; } scriptfile_clearsymbols(); option[0] = 1; // vesa all the way... option[1] = 1; // sound all the way... option[4] = 0; // no multiplayer option[5] = 0; while (1) { token = scriptfile_gettoken(cfg); if (!token) break; //EOF for (item = 0; configspec[item].name; item++) { if (!Bstrcasecmp(token, configspec[item].name)) { // Seek past any = symbol. token = scriptfile_peektoken(cfg); if (!Bstrcasecmp("=", token)) { scriptfile_gettoken(cfg); } switch (configspec[item].type) { case type_bool: { int value = 0; if (scriptfile_getnumber(cfg, &value)) break; *(int*)configspec[item].store = (value != 0); break; } case type_int: { int value = 0; if (scriptfile_getnumber(cfg, &value)) break; *(int*)configspec[item].store = value; break; } case type_hex: { int value = 0; if (scriptfile_gethex(cfg, &value)) break; *(int*)configspec[item].store = value; break; } case type_double: { double value = 0.0; if (scriptfile_getdouble(cfg, &value)) break; *(double*)configspec[item].store = value; break; } default: { buildputs("loadsetup: unhandled value type\n"); break; } } break; } } if (!configspec[item].name) { buildprintf("loadsetup: error on line %d\n", scriptfile_getlinum(cfg, cfg->ltextptr)); continue; } } #if USE_POLYMOST if (tmprenderer >= 0) { setrendermode(tmprenderer); } #endif if (tmpbrightness >= 0) { brightness = min(max(tmpbrightness,0),15); } OSD_CaptureKey(keys[19]); scriptfile_close(cfg); scriptfile_clearsymbols(); return 0; }
void getvalidmodes(void) { static int cdepths[] = { 8, #ifdef USE_OPENGL 16,24,32, #endif 0 }; static int defaultres[][2] = { {1920,1200},{1920,1080},{1600,1200},{1680,1050},{1600,900},{1400,1050},{1440,900},{1366,768}, {1280,1024},{1280,960},{1280,800},{1280,720},{1152,864},{1024,768},{800,600},{640,480}, {640,400},{512,384},{480,360},{400,300},{320,240},{320,200},{0,0} }; SDL_Rect **modes; SDL_PixelFormat pf = { NULL, 8, 1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0 }; int i, j, maxx=0, maxy=0; if (modeschecked) return; validmodecnt=0; buildputs("Detecting video modes:\n"); #define ADDMODE(x,y,c,f) if (validmodecnt<MAXVALIDMODES) { \ int mn; \ for(mn=0;mn<validmodecnt;mn++) \ if (validmode[mn].xdim==x && validmode[mn].ydim==y && \ validmode[mn].bpp==c && validmode[mn].fs==f) break; \ if (mn==validmodecnt) { \ validmode[validmodecnt].xdim=x; \ validmode[validmodecnt].ydim=y; \ validmode[validmodecnt].bpp=c; \ validmode[validmodecnt].fs=f; \ validmodecnt++; \ buildprintf(" - %dx%d %d-bit %s\n", x, y, c, (f&1)?"fullscreen":"windowed"); \ } \ } #define CHECK(w,h) if ((w < maxx) && (h < maxy)) // do fullscreen modes first for (j=0; cdepths[j]; j++) { #ifdef USE_OPENGL if (nogl && cdepths[j] > 8) continue; #endif pf.BitsPerPixel = cdepths[j]; pf.BytesPerPixel = cdepths[j] >> 3; modes = SDL_ListModes(&pf, SURFACE_FLAGS | SDL_FULLSCREEN); if (modes == (SDL_Rect **)0) { if (cdepths[j] > 8) cdepths[j] = -1; continue; } if (modes == (SDL_Rect **)-1) { for (i=0; defaultres[i][0]; i++) ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],1) } else { for (i=0; modes[i]; i++) { if ((modes[i]->w > MAXXDIM) || (modes[i]->h > MAXYDIM)) continue; ADDMODE(modes[i]->w, modes[i]->h, cdepths[j], 1) if ((modes[i]->w > maxx) && (modes[i]->h > maxy)) { maxx = modes[i]->w; maxy = modes[i]->h; } } } }
// // initsystem() -- init SDL systems // int initsystem(void) { const SDL_VideoInfo *vid; const SDL_version *linked = SDL_Linked_Version(); SDL_version compiled; char drvname[32]; SDL_VERSION(&compiled); buildprintf("Initialising SDL system interface " "(compiled with SDL version %d.%d.%d, DLL version %d.%d.%d)\n", linked->major, linked->minor, linked->patch, compiled.major, compiled.minor, compiled.patch); if (SDL_Init(SDL_INIT_VIDEO //| SDL_INIT_TIMER #ifdef NOSDLPARACHUTE | SDL_INIT_NOPARACHUTE #endif )) { buildprintf("Initialisation failed! (%s)\n", SDL_GetError()); return -1; } atexit(uninitsystem); frameplace = 0; lockcount = 0; #ifdef USE_OPENGL if (loadgldriver(getenv("BUILD_GLDRV"))) { buildputs("Failed loading OpenGL driver. GL modes will be unavailable.\n"); nogl = 1; } #endif #ifndef __APPLE__ { SDL_Surface *icon; icon = loadappicon(); if (icon) { SDL_WM_SetIcon(icon, 0); SDL_FreeSurface(icon); } } #endif if (SDL_VideoDriverName(drvname, 32)) buildprintf("Using \"%s\" video driver\n", drvname); // dump a quick summary of the graphics hardware #ifdef DEBUGGINGAIDS vid = SDL_GetVideoInfo(); buildputs("Video device information:\n"); buildprintf(" Can create hardware surfaces? %s\n", (vid->hw_available)?"Yes":"No"); buildprintf(" Window manager available? %s\n", (vid->wm_available)?"Yes":"No"); buildprintf(" Accelerated hardware blits? %s\n", (vid->blit_hw)?"Yes":"No"); buildprintf(" Accelerated hardware colourkey blits? %s\n", (vid->blit_hw_CC)?"Yes":"No"); buildprintf(" Accelerated hardware alpha blits? %s\n", (vid->blit_hw_A)?"Yes":"No"); buildprintf(" Accelerated software blits? %s\n", (vid->blit_sw)?"Yes":"No"); buildprintf(" Accelerated software colourkey blits? %s\n", (vid->blit_sw_CC)?"Yes":"No"); buildprintf(" Accelerated software alpha blits? %s\n", (vid->blit_sw_A)?"Yes":"No"); buildprintf(" Accelerated colour fills? %s\n", (vid->blit_fill)?"Yes":"No"); buildprintf(" Total video memory: %dKB\n", vid->video_mem); #endif return 0; }