changeset 340:58a085cfc6bd

Set window title based on ROM header name
author Mike Pavone <pavone@retrodev.com>
date Wed, 15 May 2013 23:32:21 -0700
parents 80d934369fd5
children 6ad8e36de685
files blastem.c render.h render_sdl.c
diffstat 3 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/blastem.c	Wed May 15 22:39:36 2013 -0700
+++ b/blastem.c	Wed May 15 23:32:21 2013 -0700
@@ -1023,6 +1023,39 @@
 	m68k_reset(&context);
 }
 
+char title[64];
+
+#define TITLE_START 0x150
+#define TITLE_END (TITLE_START+48)
+
+void update_title()
+{
+	uint16_t *last = cart + TITLE_END/2 - 1;
+	while(last > cart + TITLE_START/2 && *last == 0x2020)
+	{
+		last--;
+	}
+	uint16_t *start = cart + TITLE_START/2;
+	char *cur = title;
+	char last_char = ' ';
+	for (; start != last; start++)
+	{
+		if ((last_char != ' ' || (*start >> 8) != ' ') && (*start >> 8) < 0x80) {
+			*(cur++) = *start >> 8;
+			last_char = *start >> 8;
+		}
+		if (last_char != ' ' || (*start & 0xFF) != ' ' && (*start & 0xFF) < 0x80) {
+			*(cur++) = *start;
+			last_char = *start & 0xFF;
+		}
+	}
+	*(cur++) = *start >> 8;
+	if ((*start & 0xFF) != ' ') {
+		*(cur++) = *start;
+	}
+	strcpy(cur, " - BlastEm");
+}
+
 int main(int argc, char ** argv)
 {
 	if (argc < 2) {
@@ -1065,10 +1098,11 @@
 			height = atoi(argv[i]);
 		}
 	}
+	update_title();
 	width = width < 320 ? 320 : width;
 	height = height < 240 ? (width/320) * 240 : height;
 	if (!headless) {
-		render_init(width, height);
+		render_init(width, height, title);
 	}
 	vdp_context v_context;
 	
--- a/render.h	Wed May 15 22:39:36 2013 -0700
+++ b/render.h	Wed May 15 23:32:21 2013 -0700
@@ -2,7 +2,7 @@
 #define RENDER_SDL_H_
 
 #include "vdp.h"
-void render_init(int width, int height);
+void render_init(int width, int height, char * title);
 void render_context(vdp_context * context);
 void render_wait_quit(vdp_context * context);
 int wait_render_frame(vdp_context * context, int frame_limit);
--- a/render_sdl.c	Wed May 15 22:39:36 2013 -0700
+++ b/render_sdl.c	Wed May 15 23:32:21 2013 -0700
@@ -15,7 +15,7 @@
 
 uint32_t min_delay;
 
-void render_init(int width, int height)
+void render_init(int width, int height, char * title)
 {
 	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
         fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
@@ -32,6 +32,7 @@
     	fprintf(stderr, "BlastEm requires at least a 16-bit surface, SDL returned a %d-bit surface\n", screen->format->BytesPerPixel * 8);
     	exit(1);
     }
+    SDL_WM_SetCaption(title, title);
     uint8_t b,g,r;
     for (uint16_t color = 0; color < (1 << 12); color++) {
     	if (color & FBUF_SHADOW) {