?? sdl_driver.c
字號:
scancodes[SDLK_SEMICOLON] = 0x27; scancodes[SDLK_QUOTE] = 0x28; scancodes[SDLK_BACKQUOTE] = 0x29; scancodes[SDLK_LSHIFT] = 0x2A; scancodes[SDLK_BACKSLASH] = 0x2B; scancodes[SDLK_z] = 0x2C; scancodes[SDLK_x] = 0x2D; scancodes[SDLK_c] = 0x2E; scancodes[SDLK_v] = 0x2F; scancodes[SDLK_b] = 0x30; scancodes[SDLK_n] = 0x31; scancodes[SDLK_m] = 0x32; scancodes[SDLK_COMMA] = 0x33; scancodes[SDLK_PERIOD] = 0x34; scancodes[SDLK_SLASH] = 0x35; scancodes[SDLK_RSHIFT] = 0x36; scancodes[SDLK_KP_DIVIDE] = 0xE035; scancodes[SDLK_KP_MULTIPLY] = 0x37; scancodes[SDLK_LALT] = 0x38; scancodes[SDLK_RALT] = 0xB8; scancodes[SDLK_RCTRL] = 0x9D; scancodes[SDLK_SPACE] = 0x39; scancodes[SDLK_CAPSLOCK] = 0x3A; scancodes[SDLK_F1] = 0x3B; scancodes[SDLK_F2] = 0x3C; scancodes[SDLK_F3] = 0x3D; scancodes[SDLK_F4] = 0x3E; scancodes[SDLK_F5] = 0x3F; scancodes[SDLK_F6] = 0x40; scancodes[SDLK_F7] = 0x41; scancodes[SDLK_F8] = 0x42; scancodes[SDLK_F9] = 0x43; scancodes[SDLK_F10] = 0x44; scancodes[SDLK_F11] = 0x57; scancodes[SDLK_F12] = 0x58; scancodes[SDLK_NUMLOCK] = 0x45; scancodes[SDLK_SCROLLOCK] = 0x46; scancodes[SDLK_MINUS] = 0x4A; scancodes[SDLK_KP7] = 0x47; scancodes[SDLK_KP8] = 0x48; scancodes[SDLK_KP9] = 0x49; scancodes[SDLK_HOME] = 0xE047; scancodes[SDLK_UP] = 0xE048; scancodes[SDLK_PAGEUP] = 0xE0C9; scancodes[SDLK_KP_MINUS] = 0xE04A; scancodes[SDLK_KP4] = 0x4B; scancodes[SDLK_KP5] = 0x4C; scancodes[SDLK_KP6] = 0x4D; scancodes[SDLK_LEFT] = 0xE04B; scancodes[SDLK_RIGHT] = 0xE04D; scancodes[SDLK_KP_PLUS] = 0xE04E; scancodes[SDLK_KP1] = 0x4F; scancodes[SDLK_KP2] = 0x50; scancodes[SDLK_KP3] = 0x51; scancodes[SDLK_END] = 0xE04F; scancodes[SDLK_DOWN] = 0xE050; scancodes[SDLK_PAGEDOWN] = 0xE0D1; scancodes[SDLK_DELETE] = 0xE0D3; scancodes[SDLK_KP0] = 0xE052; scancodes[SDLK_INSERT] = 0xE052; scancodes[SDLK_KP_ENTER] = 0xE01C; set_sdl_renderer(); output_sdl_versions(); output_driver_info(); detect_vmware();} /* _platform_init */int setvesa(long x, long y){ fprintf(stderr, "setvesa() called in SDL driver!\n"); exit(23); return(0);} /* setvesa */int screencapture(char *filename, char inverseit){ fprintf(stderr, "screencapture() is a stub in the SDL driver.\n"); return(0);} /* screencapture */void setvmode(int mode){ int w = -1; int h = -1; if (mode == 0x3) /* text mode. */ { SDL_QuitSubSystem(SDL_INIT_VIDEO); return; } /* if */ if (mode == 0x13) { w = 800; h = 600; } /* if */ else { fprintf(stderr, "setvmode(0x%x) is unsupported in SDL driver.\n", mode); exit(13); } /* if */ assert(w > 0); assert(h > 0); go_to_new_vid_mode(-1, w, h);} /* setvmode */int _setgamemode(char davidoption, long daxdim, long daydim){#ifdef USE_OPENGL static int shown_gl_strings = 0; int gl = using_opengl(); if (gl) sdl_flags |= SDL_OPENGL;#endif if (in_egapalette) restore256_palette(); go_to_new_vid_mode((int) davidoption, daxdim, daydim); #ifdef USE_OPENGL if (gl) { if (!shown_gl_strings) { sgldebug("GL_VENDOR [%s]", (char *) dglGetString(GL_VENDOR)); sgldebug("GL_RENDERER [%s]", (char *) dglGetString(GL_RENDERER)); sgldebug("GL_VERSION [%s]", (char *) dglGetString(GL_VERSION)); sgldebug("GL_EXTENSIONS [%s]", (char *) dglGetString(GL_EXTENSIONS)); shown_gl_strings = 1; } /* if */ dglViewport(0, 0, daxdim, daydim); dglEnable(GL_TEXTURE_2D); dglPixelTransferi(GL_MAP_COLOR, GL_TRUE); dglPixelTransferi(GL_INDEX_SHIFT, 0); dglPixelTransferi(GL_INDEX_OFFSET, 0); dglClearDepth(1.0); dglDepthFunc(GL_LESS); dglEnable(GL_DEPTH_TEST); dglShadeModel(GL_SMOOTH); dglMatrixMode(GL_PROJECTION); dglLoadIdentity(); dglMatrixMode(GL_MODELVIEW); } /* if */ #endif qsetmode = 200; last_render_ticks = SDL_GetTicks(); return(0);} /* setgamemode */void qsetmode640350(void){ assert(0); #ifdef USE_OPENGL if (using_opengl()) sdl_flags |= SDL_OPENGL; #endif go_to_new_vid_mode(-1, 640, 350);} /* qsetmode640350 */void qsetmode640480(void){ if (!in_egapalette) set16color_palette(); #ifdef USE_OPENGL if (using_opengl()) sdl_flags |= SDL_OPENGL; #endif go_to_new_vid_mode(-1, 640, 480); pageoffset = 0; /* Make sure it goes to the right place - DDOI */ fillscreen16(0L,8L,640L*144L);} /* qsetmode640480 */static int get_dimensions_from_str(const char *str, long *_w, long *_h){ char *xptr = NULL; char *ptr = NULL; long w = -1; long h = -1; if (str == NULL) return(0); xptr = strchr(str, 'x'); if (xptr == NULL) return(0); w = strtol(str, &ptr, 10); if (ptr != xptr) return(0); xptr++; h = strtol(xptr, &ptr, 10); if ( (*xptr == '\0') || (*ptr != '\0') ) return(0); if ((w <= 1) || (h <= 1)) return(0); if (_w != NULL) *_w = w; if (_h != NULL) *_h = h; return(1);} /* get_dimensions_from_str */static inline void get_max_screen_res(long *max_w, long *max_h){ long w = DEFAULT_MAXRESWIDTH; long h = DEFAULT_MAXRESHEIGHT; const char *envr = getenv(BUILD_MAXSCREENRES); if (envr != NULL) { if (!get_dimensions_from_str(envr, &w, &h)) { sdldebug("User's resolution ceiling [%s] is bogus!", envr); w = DEFAULT_MAXRESWIDTH; h = DEFAULT_MAXRESHEIGHT; } /* if */ } /* if */ if (max_w != NULL) *max_w = w; if (max_h != NULL) *max_h = h;} /* get_max_screen_res */static void add_vesa_mode(const char *typestr, int w, int h){ sdldebug("Adding %s resolution (%dx%d).", typestr, w, h); validmode[validmodecnt] = validmodecnt; validmodexdim[validmodecnt] = w; validmodeydim[validmodecnt] = h; validmodecnt++;} /* add_vesa_mode *//* Let the user specify a specific mode via environment variable. */static inline void add_user_defined_resolution(void){ long w; long h; const char *envr = getenv(BUILD_USERSCREENRES); if (envr == NULL) return; if (get_dimensions_from_str(envr, &w, &h)) add_vesa_mode("user defined", w, h); else sdldebug("User defined resolution [%s] is bogus!", envr);} /* add_user_defined_resolution */static inline SDL_Rect **get_physical_resolutions(void){ const SDL_VideoInfo *vidInfo = SDL_GetVideoInfo(); SDL_Rect **modes = SDL_ListModes(vidInfo->vfmt, sdl_flags | SDL_FULLSCREEN); if (modes == NULL) { sdl_flags &= ~SDL_FULLSCREEN; modes = SDL_ListModes(vidInfo->vfmt, sdl_flags); /* try without fullscreen. */ if (modes == NULL) modes = (SDL_Rect **) -1; /* fuck it. */ } /* if */ if (modes == (SDL_Rect **) -1) sdldebug("Couldn't get any physical resolutions."); else { sdldebug("Highest physical resolution is (%dx%d).", modes[0]->w, modes[0]->h); } /* else */ return(modes);} /* get_physical_resolutions */static void remove_vesa_mode(int index, const char *reason){ int i; assert(index < validmodecnt); sdldebug("Removing resolution #%d, %dx%d [%s].", index, validmodexdim[index], validmodeydim[index], reason); for (i = index; i < validmodecnt - 1; i++) { validmode[i] = validmode[i + 1]; validmodexdim[i] = validmodexdim[i + 1]; validmodeydim[i] = validmodeydim[i + 1]; } /* for */ validmodecnt--;} /* remove_vesa_mode */static inline void cull_large_vesa_modes(void){ long max_w; long max_h; int i; get_max_screen_res(&max_w, &max_h); sdldebug("Setting resolution ceiling to (%ldx%ld).", max_w, max_h); for (i = 0; i < validmodecnt; i++) { if ((validmodexdim[i] > max_w) || (validmodeydim[i] > max_h)) { remove_vesa_mode(i, "above resolution ceiling"); i--; /* list shrinks. */ } /* if */ } /* for */} /* cull_large_vesa_modes */static inline void cull_duplicate_vesa_modes(void){ int i; int j; for (i = 0; i < validmodecnt; i++) { for (j = i + 1; j < validmodecnt; j++) { if ( (validmodexdim[i] == validmodexdim[j]) && (validmodeydim[i] == validmodeydim[j]) ) { remove_vesa_mode(j, "duplicate"); j--; /* list shrinks. */ } /* if */ } /* for */ } /* for */} /* cull_duplicate_vesa_modes */#define swap_macro(tmp, x, y) { tmp = x; x = y; y = tmp; }/* be sure to call cull_duplicate_vesa_modes() before calling this. */static inline void sort_vesa_modelist(void){ int i; int sorted; long tmp; do { sorted = 1; for (i = 0; i < validmodecnt - 1; i++) { if ( (validmodexdim[i] >= validmodexdim[i+1]) && (validmodeydim[i] >= validmodeydim[i+1]) ) { sorted = 0; swap_macro(tmp, validmode[i], validmode[i+1]); swap_macro(tmp, validmodexdim[i], validmodexdim[i+1]); swap_macro(tmp, validmodeydim[i], validmodeydim[i+1]); } /* if */ } /* for */ } while (!sorted);} /* sort_vesa_modelist */static inline void cleanup_vesa_modelist(void){ cull_large_vesa_modes(); cull_duplicate_vesa_modes(); sort_vesa_modelist();} /* cleanup_vesa_modelist */static inline void output_vesa_modelist(void){ char buffer[256]; char numbuf[20]; int i; if (!_sdl_debug_file) return; buffer[0] = '\0'; for (i = 0; i < validmodecnt; i++) { sprintf(numbuf, " (%ldx%ld)", (long) validmodexdim[i], (long) validmodeydim[i]); if ( (strlen(buffer) + strlen(numbuf)) >= (sizeof (buffer) - 1) ) strcpy(buffer + (sizeof (buffer) - 5), " ..."); else strcat(buffer, numbuf); } /* for */ sdldebug("Final sorted modelist:%s", buffer);} /* output_vesa_modelist */void getvalidvesamodes(void){ static int already_checked = 0; int i; SDL_Rect **modes = NULL; int stdres[][2] = { {320, 200}, {640, 350}, {640, 480}, {800, 600}, {1024, 768} }; if (already_checked) return; already_checked = 1; validmodecnt = 0; vidoption = 1; /* !!! tmp */ /* fill in the standard resolutions... */ for (i = 0; i < sizeof (stdres) / sizeof (stdres[0]); i++) add_vesa_mode("standard", stdres[i][0], stdres[i][1]); /* Anything the hardware can specifically do is added now... */ modes = get_physical_resolutions(); for (i = 0; (modes != (SDL_Rect **) -1) && (modes[i] != NULL); i++) add_vesa_mode("physical", modes[i]->w, modes[i]->h); /* Now add specific resolutions that the user wants... */ add_user_defined_resolution(); /* get rid of dupes and bogus resolutions... */ cleanup_vesa_modelist(); /* print it out for debugging purposes... */ output_vesa_modelist();} /* getvalidvesamodes */int VBE_setPalette(long start, long num, char *palettebuffer)/* * (From Ken's docs:) * Set (num) palette palette entries starting at (start) * palette entries are in a 4-byte format in this order: * 0: Blue (0-63) * 1: Green (0-63) * 2: Red (0-63) * 3: Reserved * * Naturally, the bytes are in the reverse order that SDL wants them... * More importantly, SDL wants the color elements in a range from 0-255, * so we do a conversion. */{ SDL_Color fmt_swap[256]; SDL_Color *sdlp = &fmt_swap[start]; char *p = palettebuffer; int i;#if (defined USE_OPENGL) int gl = using_opengl(); GLfloat gl_reds[256]; GLfloat gl_greens[256]; GLfloat gl_blues[256]; GLfloat gl_alphas[256]; if (gl) { dglGetPixelMapfv(GL_PIXEL_MAP_I_TO_R, gl_reds); dglGetPixelMapfv(GL_PIXEL_MAP_I_TO_G, gl_greens); dglGetPixelMapfv(GL_PIXEL_MAP_I_TO_B, gl_blues); dglGetPixelMapfv(GL_PIXEL_MAP_I_TO_A, gl_alphas); } /* if */#endif assert( (start + num) <= (sizeof (fmt_swap) / sizeof (SDL_Color)) ); for (i = 0; i < num; i++) { sdlp->b = (Uint8) ((((float) *p++) / 63.0) * 255.0); sdlp->g = (Uint8) ((((float) *p++) / 63.0) * 255.0); sdlp->r = (Uint8) ((((float) *p++) / 63.0) * 255.0); sdlp->unused = *p++; /* This byte is unused in BUILD, too. */#if (defined USE_OPENGL) if (gl) { gl_reds[i+start] = ((GLfloat) sdlp->r) / 255.0f; gl_greens[i+start] = ((GLfloat) sdlp->g) / 255.0f; gl_blues[i+start] = ((GLfloat) sdlp->b) / 255.0f; gl_alphas[i+start] = 1.0f; } /* if */#endif sdlp++; } /* for */#if (defined USE_OPENGL) if (gl) { dglPixelMapfv(GL_PIXEL_MAP_I_TO_R, start + num, gl_reds); dglPixelMapfv(GL_PIXEL_MAP_I_TO_G, start + num, gl_greens); dglPixelMapfv(GL_PIXEL_MAP_I_TO_B, start + num, gl_blues); dglPixelMapfv(GL_PIXEL_MAP_I_TO_A, start + num, gl_alphas); } /* if */#endif return(SDL_SetColors(surface, fmt_swap, start, num));} /* VBE_setPalette */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -