/** * Setup SDL audio, video and window subsystems. */ void av_setup(void) { unsigned video_flags = SDL_SWSURFACE; #ifndef CONFIG_MACOSX char *icon_path = NULL; #endif if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { CRITICAL2("SDL_Init error: %s", SDL_GetError()); exit(EXIT_FAILURE); } atexit(SDL_Quit); if (options.want_audio) { #ifdef CONFIG_WIN32 /* * default direct-audio-something has got unreasonably long audio buffers, * but if user knows what he's doing then no problemo... */ if (!SDL_getenv("SDL_AUDIODRIVER")) { INFO1("fixing WIN32 audio driver setup"); SDL_putenv("SDL_AUDIODRIVER=waveout"); } /* * also some sources mention that on win audio needs to be initialised * together with video. Maybe, it works for me as it is now. */ #endif if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { ERROR2("audio initialization failed: %s", SDL_GetError()); } else { INFO1("audio subsystem initialized"); have_audio = 1; } } else NOTICE1("no audio"); if (options.want_fullscreen) { video_flags |= SDL_FULLSCREEN; NOTICE1("fullscreen mode enabled"); } #ifndef CONFIG_MACOSX if ((icon_path = locate_file("moon_32x32.bmp", FT_IMAGE))) { SDL_Surface *icon = SDL_LoadBMP(icon_path); if (icon != NULL) SDL_WM_SetIcon(icon, NULL); else INFO2("setting icon failed: %s\n", SDL_GetError()); free(icon_path); } #endif #ifdef PACKAGE_BUILD SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION " build " PACKAGE_BUILD, NULL); #else SDL_WM_SetCaption(PACKAGE_STRING, NULL); #endif if ((display = SDL_SetVideoMode(MAX_X * 2, MAX_Y * 2, 24, video_flags)) == NULL) { CRITICAL2("SDL_SetVideoMode failed: %s", SDL_GetError()); exit(EXIT_FAILURE); } screen = xcalloc(MAX_X * MAX_Y, 1); screen_surf = SDL_CreateRGBSurfaceFrom(screen, MAX_X, MAX_Y, 8, MAX_X, 0, 0, 0, 0); if (!screen_surf) { CRITICAL2("can't create screen surface: %s", SDL_GetError()); exit(EXIT_FAILURE); } screen_surf2x = SDL_CreateRGBSurface(SDL_SWSURFACE, MAX_X * 2, MAX_Y * 2, 8, ~0, ~0, ~0, 0); if (!screen_surf2x) { CRITICAL2("can't create screen_2x surface: %s", SDL_GetError()); exit(EXIT_FAILURE); } /* XXX: Hardcoded video width & height */ video_overlay = SDL_CreateYUVOverlay(160, 100, SDL_YV12_OVERLAY, display); if (!video_overlay) { CRITICAL2("can't create video_overlay: %s", SDL_GetError()); exit(EXIT_FAILURE); } news_overlay = SDL_CreateYUVOverlay(312, 106, SDL_YV12_OVERLAY, display); /* XXX: Hardcoded video width & height */ if (!news_overlay) { CRITICAL2("can't create news_overlay: %s", SDL_GetError()); exit(EXIT_FAILURE); } fade_info.step = 1; fade_info.steps = 1; do_fading = 1; alloc_dirty_tree(); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); if (have_audio) { int i = 0; audio_desired.freq = 11025; audio_desired.format = AUDIO_S16SYS; audio_desired.channels = 1; /* audio was unresponsive on win32 so let's use shorter buffer */ audio_desired.samples = 2048; /* was 8192 */ audio_desired.callback = audio_callback; /* initialize audio channels */ for (i = 0; i < AV_NUM_CHANNELS; ++i) { Channels[i].volume = AV_MAX_VOLUME; Channels[i].mute = 0; Channels[i].chunk = NULL; Channels[i].chunk_tailp = &Channels[i].chunk; Channels[i].offset = 0; } /* we don't care what we got, library will convert for us */ if (SDL_OpenAudio(&audio_desired, NULL) < 0) { ERROR2("SDL_OpenAudio error: %s", SDL_GetError()); NOTICE1("disabling audio"); have_audio = 0; } else SDL_PauseAudio(0); } SDL_AddTimer(30, sdl_timer_callback, NULL); }
char DoModem(int sel) { NOTICE1("DoModem not implemented"); return (0); }
/** read the config file * * * * \return -1 if the config file is unavailable */ static int read_config_file(void) { FILE *f = open_savedat("config", "rt"); char config_word[32 + 1]; int err = 0, res = 0, i = 0; char c[2]; if (!f) { INFO1("could not open config file"); return -1; } while (1) { /* skip comments */ if ((res = fscanf(f, " %1[#]", c)) == 1) goto skip_newline; if (res == EOF) break; /* get configuration variable name */ /** \note config variables may be 32 characters of alphas plus dash and underscore */ res = fscanf(f, "%32[a-zA-Z_-]", config_word); /* do we have a match? */ if (res == 1) { for (i = 0; i < (int) ARRAY_LENGTH(config_strings); ++i) { if (strcmp(config_word, config_strings[i].name) == 0) { res = parse_var_value(f, i); if (res != 0 && feof(f)) goto skip_newline; else if (res != 0) { NOTICE2("wrong value type for variable `%s'", config_word); goto skip_newline; } else break; } } /* none matched */ if (i == (int) ARRAY_LENGTH(config_strings)) { NOTICE2("unknown variable in file `%s'", config_word); goto skip_newline; } } else if (res == EOF) break; else { NOTICE1("expected variable name"); goto skip_newline; } skip_newline: if (EOF == skip_past_newline(f)) break; } err = !feof(f); fclose(f); return -err; }
/** * Setup SDL audio, video and window subsystems. */ void av_setup(void) { #ifdef PACKAGE_BUILD std::string title(PACKAGE_NAME " " PACKAGE_VERSION " build " PACKAGE_BUILD); #else std::string title(PACKAGE_STRING); #endif display::graphics.create(title, (options.want_fullscreen == 1)); #ifdef SET_SDL_ICON char *icon_path; if ((icon_path = locate_file("moon_32x32.bmp", FT_IMAGE))) { SDL_Surface *icon = SDL_LoadBMP(icon_path); if (icon != NULL) { SDL_WM_SetIcon(icon, NULL); } else { INFO2("setting icon failed: %s\n", SDL_GetError()); } free(icon_path); } #endif fade_info.step = 1; fade_info.steps = 1; do_fading = 1; SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); if (have_audio) { int i = 0; audio_desired.freq = 11025; audio_desired.format = AUDIO_S16SYS; audio_desired.channels = 1; /* audio was unresponsive on win32 so let's use shorter buffer */ audio_desired.samples = 2048; /* was 8192 */ audio_desired.callback = audio_callback; /* initialize audio channels */ for (i = 0; i < AV_NUM_CHANNELS; ++i) { Channels[i].volume = AV_MAX_VOLUME; Channels[i].mute = 0; Channels[i].chunk = NULL; Channels[i].chunk_tailp = &Channels[i].chunk; Channels[i].offset = 0; } /* we don't care what we got, library will convert for us */ if (SDL_OpenAudio(&audio_desired, NULL) < 0) { ERROR2("SDL_OpenAudio error: %s", SDL_GetError()); NOTICE1("disabling audio"); have_audio = 0; } else { SDL_PauseAudio(0); } } SDL_AddTimer(30, sdl_timer_callback, NULL); }