# HG changeset patch # User Mike Pavone # Date 1368685941 25200 # Node ID 58a085cfc6bdfa994d39d76a515e8a3792ab3e0d # Parent 80d934369fd5f5a75019842ca0ea7fe1c1405eab Set window title based on ROM header name diff -r 80d934369fd5 -r 58a085cfc6bd blastem.c --- 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; diff -r 80d934369fd5 -r 58a085cfc6bd render.h --- 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); diff -r 80d934369fd5 -r 58a085cfc6bd render_sdl.c --- 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) {