comparison render_sdl.c @ 444:cc754a309ead

Add fullscreen support and add a keybinding for exiting the emulator
author Mike Pavone <pavone@retrodev.com>
date Wed, 17 Jul 2013 22:26:11 -0700
parents 18cde14e8c10
children 80a9527c812c
comparison
equal deleted inserted replaced
443:9ac3828ea560 444:cc754a309ead
86 uint8_t render_depth() 86 uint8_t render_depth()
87 { 87 {
88 return screen->format->BytesPerPixel * 8; 88 return screen->format->BytesPerPixel * 8;
89 } 89 }
90 90
91 void render_init(int width, int height, char * title, uint32_t fps) 91 void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen)
92 { 92 {
93 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { 93 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) {
94 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); 94 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
95 exit(1); 95 exit(1);
96 } 96 }
97 atexit(SDL_Quit); 97 atexit(SDL_Quit);
98 atexit(render_close_audio); 98 atexit(render_close_audio);
99 printf("width: %d, height: %d\n", width, height); 99 printf("width: %d, height: %d\n", width, height);
100 screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_ANYFORMAT); 100 uint32_t flags = SDL_ANYFORMAT;
101 if (fullscreen) {
102 flags |= SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF;
103 } else {
104 flags |= SDL_SWSURFACE;
105 }
106 screen = SDL_SetVideoMode(width, height, 32, flags);
101 if (!screen) { 107 if (!screen) {
102 fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError()); 108 fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError());
103 exit(1); 109 exit(1);
104 } 110 }
105 if (screen->format->BytesPerPixel != 2 && screen->format->BytesPerPixel != 4) { 111 if (screen->format->BytesPerPixel != 2 && screen->format->BytesPerPixel != 4) {
214 } 220 }
215 } 221 }
216 if ( SDL_MUSTLOCK(screen) ) { 222 if ( SDL_MUSTLOCK(screen) ) {
217 SDL_UnlockSurface(screen); 223 SDL_UnlockSurface(screen);
218 } 224 }
219 SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h); 225 //SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h);
226 SDL_Flip(screen);
220 if (context->regs[REG_MODE_4] & BIT_INTERLACE) 227 if (context->regs[REG_MODE_4] & BIT_INTERLACE)
221 { 228 {
222 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf; 229 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf;
223 } 230 }
224 } 231 }