--- src/sdl/video.c.orig 2013-02-22 02:49:35.000000000 +1100 +++ src/sdl/video.c 2013-02-22 18:43:37.000000000 +1100 @@ -222,7 +222,7 @@ static void set_icon(sopsym_t *sym) static void Vid_UnsetMode() { - SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_FreeSurface(screenbuf); } @@ -364,17 +364,10 @@ static void Vid_SetMode() int n; int w, h; int flags = 0; - int status; printf("CGA Screen Emulation\n"); printf("init screen: "); - status = SDL_Init(SDL_INIT_VIDEO); - if (status == -1) - { - fprintf(stderr, "Unable to locate video device. Exiting.\n"); - exit(1); - } srand(time(NULL)); set_icon(symbol_plane[rand() % 2][rand() % 16]); @@ -400,6 +393,11 @@ static void Vid_SetMode() exit(-1); } + screenbuf = SDL_CreateRGBSurface(0, SCR_WDTH, SCR_HGHT, 8, + 0, 0, 0, 0); + vid_vram = screenbuf->pixels; + vid_pitch = screenbuf->pitch; + SDL_EnableUNICODE(1); for (n = 0; n < NUM_KEYS; ++n) @@ -409,6 +407,7 @@ static void Vid_SetMode() SDL_SetColors(screen, cga_pal, 0, sizeof(cga_pal)/sizeof(*cga_pal)); SDL_SetColors(screenbuf, cga_pal, 0, sizeof(cga_pal)/sizeof(*cga_pal)); + SDL_LockSurface(screenbuf); // create custom key file Create_Custom_File(); @@ -423,30 +422,32 @@ void Vid_Shutdown() Vid_UnsetMode(); - SDL_FreeSurface(screenbuf); + SDL_QuitSubSystem(SDL_INIT_VIDEO); initted = 0; } void Vid_Init() { + int status; + if (initted) return; fflush(stdout); - screenbuf = SDL_CreateRGBSurface(0, SCR_WDTH, SCR_HGHT, 8, - 0, 0, 0, 0); - vid_vram = screenbuf->pixels; - vid_pitch = screenbuf->pitch; + status = SDL_Init(SDL_INIT_VIDEO); + if (status == -1) + { + fprintf(stderr, "Unable to locate video device. Exiting.\n"); + exit(1); + } Vid_SetMode(); initted = 1; atexit(Vid_Shutdown); - - SDL_LockSurface(screenbuf); } void Vid_Reset()