changeset 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 9ac3828ea560
children 80a9527c812c
files blastem.c default.cfg io.c render.h render_sdl.c
diffstat 5 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/blastem.c	Wed Jul 17 00:23:45 2013 -0700
+++ b/blastem.c	Wed Jul 17 22:26:11 2013 -0700
@@ -1907,6 +1907,7 @@
 	int ym_log = 0;
 	FILE *address_log = NULL;
 	char * statefile = NULL;
+	uint8_t fullscreen = 0;
 	for (int i = 2; i < argc; i++) {
 		if (argv[i][0] == '-') {
 			switch(argv[i][1]) {
@@ -1914,7 +1915,7 @@
 				debug = 1;
 				break;
 			case 'f':
-				frame_limit = 1;
+				fullscreen = 1;
 				break;
 			case 'l':
 				address_log = fopen("address.log", "w");
@@ -1988,7 +1989,7 @@
 		fps = 50;
 	}
 	if (!headless) {
-		render_init(width, height, title, fps);
+		render_init(width, height, title, fps, fullscreen);
 	}
 	vdp_context v_context;
 	
--- a/default.cfg	Wed Jul 17 00:23:45 2013 -0700
+++ b/default.cfg	Wed Jul 17 22:26:11 2013 -0700
@@ -17,6 +17,7 @@
 		[ ui.vdp_debug_mode
 		] ui.vdp_debug_pal
 		u ui.enter_debugger
+		esc ui.exit
 	}
 	pads {
 		0 {
--- a/io.c	Wed Jul 17 00:23:45 2013 -0700
+++ b/io.c	Wed Jul 17 22:26:11 2013 -0700
@@ -12,7 +12,8 @@
 typedef enum {
 	UI_DEBUG_MODE_INC,
 	UI_DEBUG_PAL_INC,
-	UI_ENTER_DEBUGGER
+	UI_ENTER_DEBUGGER,
+	UI_EXIT
 } ui_action;
 
 typedef struct {
@@ -209,6 +210,8 @@
 		case UI_ENTER_DEBUGGER:
 			break_on_sync = 1;
 			break;
+		case UI_EXIT:
+			exit(0);
 		}
 		break;
 	}
@@ -280,6 +283,8 @@
 			*ui_out = UI_DEBUG_PAL_INC;
 		} else if(!strcmp(target + 3, "enter_debugger")) {
 			*ui_out = UI_ENTER_DEBUGGER;
+		} else if(!strcmp(target + 3, "exit")) {
+			*ui_out = UI_EXIT;
 		} else {
 			fprintf(stderr, "Unreconized UI binding type %s\n", target);
 			return 0;
@@ -339,6 +344,7 @@
 	special = tern_insert_int(special, "left", RENDERKEY_LEFT);
 	special = tern_insert_int(special, "right", RENDERKEY_RIGHT);
 	special = tern_insert_int(special, "enter", '\r');
+		special = tern_insert_int(special, "esc", RENDERKEY_ESC);
 	
 	tern_node * padbuttons = tern_insert_int(NULL, ".up", DPAD_UP);
 	padbuttons = tern_insert_int(padbuttons, ".down", DPAD_DOWN);
--- a/render.h	Wed Jul 17 00:23:45 2013 -0700
+++ b/render.h	Wed Jul 17 22:26:11 2013 -0700
@@ -6,7 +6,7 @@
 #include "ym2612.h"
 uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b);
 uint8_t render_depth();
-void render_init(int width, int height, char * title, uint32_t fps);
+void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen);
 void render_context(vdp_context * context);
 void render_wait_quit(vdp_context * context);
 void render_wait_psg(psg_context * context);
@@ -28,6 +28,7 @@
 #define RENDERKEY_DOWN    SDLK_DOWN
 #define RENDERKEY_LEFT    SDLK_LEFT
 #define RENDERKEY_RIGHT   SDLK_RIGHT
+#define RENDERKEY_ESC     SDLK_ESCAPE
 #define RENDER_DPAD_UP    SDL_HAT_UP
 #define RENDER_DPAD_DOWN  SDL_HAT_DOWN
 #define RENDER_DPAD_LEFT  SDL_HAT_LEFT
--- a/render_sdl.c	Wed Jul 17 00:23:45 2013 -0700
+++ b/render_sdl.c	Wed Jul 17 22:26:11 2013 -0700
@@ -88,7 +88,7 @@
 	return screen->format->BytesPerPixel * 8;
 }
 
-void render_init(int width, int height, char * title, uint32_t fps)
+void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen)
 {
 	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) {
         fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
@@ -97,7 +97,13 @@
     atexit(SDL_Quit);
     atexit(render_close_audio);
     printf("width: %d, height: %d\n", width, height);
-    screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_ANYFORMAT);
+    uint32_t flags = SDL_ANYFORMAT;
+    if (fullscreen) {
+    	flags |= SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF;
+    } else {
+    	flags |= SDL_SWSURFACE;
+    }
+    screen = SDL_SetVideoMode(width, height, 32, flags);
     if (!screen) {
     	fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError());
         exit(1);
@@ -216,7 +222,8 @@
     if ( SDL_MUSTLOCK(screen) ) {
         SDL_UnlockSurface(screen);
     }
-    SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h);
+    //SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h);
+    SDL_Flip(screen);
     if (context->regs[REG_MODE_4] & BIT_INTERLACE)
     {
     	context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf;