adv_error joystickb_lgallegro_load(adv_conf* context) { lgallegro_option.calibration = conf_int_get_default(context, "device_lgallegro_calibration"); lgallegro_option.filter = conf_int_get_default(context, "device_lgallegro_filter"); return 0; }
adv_error soundb_sdl_load(adv_conf* context) { sdl_option.samples = conf_int_get_default(context, "device_sdl_samples"); sdl_option.initialized = 1; return 0; }
adv_error mouseb_raw_load(adv_conf* context) { unsigned i; for (i = 0; i < RAW_MOUSE_MAX; ++i) { char buf[64]; const char* s; snprintf(buf, sizeof(buf), "device_raw_mousetype[%d]", i); raw_state.map[i].context.type = conf_int_get_default(context, buf); snprintf(buf, sizeof(buf), "device_raw_mousedev[%d]", i); s = conf_string_get_default(context, buf); if (strcmp(s, "auto") == 0) { if (i == 0 && access("/dev/mouse", F_OK) == 0) { sncpy(raw_state.map[i].context.dev, sizeof(raw_state.map[i].context.dev), "/dev/mouse"); if (raw_state.map[i].context.type < 0) raw_state.map[i].context.type = MOUSE_PNP; } else { snprintf(raw_state.map[i].context.dev, sizeof(raw_state.map[i].context.dev), "/dev/input/mouse%d", i); switch (raw_state.map[i].context.type) { case MOUSE_PS2: case MOUSE_IMPS2: case MOUSE_EXPPS2: /* the /dev/input/mouse interfaces is compatible only with these three protocols */ break; default: raw_state.map[i].context.type = MOUSE_IMPS2; break; } } } else { sncpy(raw_state.map[i].context.dev, sizeof(raw_state.map[i].context.dev), s); if (raw_state.map[i].context.type < 0) raw_state.map[i].context.type = MOUSE_PNP; } } return 0; }
adv_error joystickb_lgrawinput_load(adv_conf* context) { raw_option.calibration = conf_int_get_default(context, "device_lgrawinput_calibration"); return 0; }
int os_main(int argc, char* argv[]) { int keyboard_id; adv_conf* context; const char* s; char* section_map[1]; const char** file_map; unsigned file_mac; int i; double latency_time; double buffer_time; double volume; unsigned rate; int attenuation; adv_bool opt_log; adv_bool opt_logsync; opt_log = 0; opt_logsync = 0; file_map = 0; file_mac = 0; context = conf_init(); if (os_init(context) != 0) goto err_conf; mixer_reg(context); conf_int_register_limit_default(context, "sound_volume", -32, 0, 0); conf_int_register_limit_default(context, "sound_samplerate", 5000, 96000, 44100); conf_float_register_limit_default(context, "sound_latency", 0.01, 2.0, 0.1); conf_float_register_limit_default(context, "sound_buffer", 0.05, 2.0, 0.1); if (conf_input_args_load(context, 0, "", &argc, argv, error_callback, 0) != 0) goto err_os; file_map = malloc(argc * sizeof(const char*)); for(i=1;i<argc;++i) { if (target_option_compare(argv[i], "log")) { opt_log = 1; } else if (target_option_compare(argv[i], "logsync")) { opt_logsync = 1; } else if (target_option_extract(argv[i]) == 0) { file_map[file_mac++] = argv[i]; } else { target_err("Unknown command line option '%s'.\n", argv[i]); goto err_os; } } if (argc <= 1 || file_mac == 0) { target_err("Syntax: advs FILES...\n"); goto err_os; } if (opt_log || opt_logsync) { const char* log = "advs.log"; remove(log); log_init(log, opt_logsync); } section_map[0] = ""; conf_section_set(context, section_map, 1); if (mixer_load(context) != 0) { goto err_os; } attenuation = conf_int_get_default(context, "sound_volume"); latency_time = conf_float_get_default(context, "sound_latency"); buffer_time = conf_float_get_default(context, "sound_buffer"); rate = conf_int_get_default(context, "sound_samplerate"); volume = 1.0; while (attenuation++ < 0) volume /= 1.122018454; /* = (10 ^ (1/20)) = 1dB */ if (os_inner_init("AdvanceSOUND") != 0) goto err_os; if (file_mac > MIXER_CHANNEL_MAX) { target_err("Too many files\n"); goto err_os_inner; } if (mixer_init(rate, file_mac, 1, buffer_time + latency_time, latency_time) != 0) { target_err("%s\n", error_get()); goto err_os_inner; } mixer_volume(volume); for(i=0;i<file_mac;++i) run(i, file_map[i]); free(file_map); signal(SIGINT, sigint); while (!done) { for(i=0;i<file_mac;++i) if (mixer_is_playing(i)) break; if (i==file_mac) break; mixer_poll(); target_idle(); } log_std(("s: shutdown\n")); mixer_done(); os_inner_done(); log_std(("s: the end\n")); if (opt_log || opt_logsync) { log_done(); } os_done(); conf_done(context); return EXIT_SUCCESS; err_os_inner: os_inner_done(); log_done(); err_os: os_done(); err_conf: conf_done(context); err: return EXIT_FAILURE; }