Esempio n. 1
0
static void on_resize(int width, int height) {
    if (width == g_fs_ml_video_width && height == g_fs_ml_video_height) {
        fs_log("got resize event, but size was unchanged\n");
        return;
    }
    if (g_fs_emu_video_fullscreen) {
        fs_log("not updating window size in fullscreen\n");
    }
    else if (width == g_fullscreen_width &&
        height == g_fullscreen_height) {
        fs_log("not setting window size to fullscreen size\n");
    }
    else {
        g_window_width = width;
        g_window_height = height;
        fs_log("resize event %d %d\n", width, height);
    }
#ifdef USE_SDL2
    g_fs_ml_video_width = width;
    g_fs_ml_video_height = height;
#else
#ifdef MACOSX
        destroy_opengl_state();
#endif
        set_video_mode();
#ifdef MACOSX
        recreate_opengl_state();
#endif
#endif
}
Esempio n. 2
0
static void check_opengl_sync_capabilities() {
    fs_log("checking OpenGL capabilities\n");
    const char *ext = (const char *) glGetString(GL_EXTENSIONS);
    if (ext) {
        if (strstr(ext, "GL_NV_fence") != NULL) {
            g_has_nv_fence = 1;
            fs_log("GL_NV_fence extension found \n");
        }
        if (strstr(ext, "GL_APPLE_fence") != NULL) {
            g_has_apple_fence = 1;
            fs_log("GL_APPLE_fence extension found\n");
        }
        if (strstr(ext, "GL_ARB_sync") != NULL) {
            fs_log("GL_ARB_sync extension found\n");
#ifdef USE_GLEE
            glFenceSync = __GLeeGetProcAddress("glFenceSync");
            glWaitSync = __GLeeGetProcAddress("glWaitSync");
            glClientWaitSync = __GLeeGetProcAddress("glClientWaitSync");
#endif
            if (glFenceSync && glClientWaitSync) {
                g_has_arb_sync = 1;
            }
            else {
                fs_log("error looking up functions\n");
            }
        }
    }
}
Esempio n. 3
0
static int input_device_function(fs_emu_menu_item *menu_item,
                                 void **result_data) {
    int port = fs_emu_menu_item_get_idata(menu_item);
    int index = port & 0xff;
    port = port >> 8;

    if (index == 255) {
        fs_log("[menu] port %d set device to \"%s\"\n", port, "");
        set_input_port(port, "", 0);
    }
#if 0
    else if (index == 254) {
        fs_log("[menu] port %d set device to \"%s\"\n", port, "MOUSE");
        set_input_port(port, "MOUSE", 1);
    }
    else if (index == 253) {
        fs_log("[menu] port %d set device to \"%s\"\n", port, "KEYBOARD");
        set_input_port(port, "KEYBOARD", 1);
    }
#endif
    else {
        fs_emu_input_device device;
        if (!fs_ml_input_device_get(index, &device)) {
            return FS_EMU_MENU_RESULT_NONE;
        }
        fs_log("[menu] port %d set device to %s\n", port, device.name);
        set_input_port(port, device.name, 1);
    }
    fs_uae_reconfigure_input_ports_host();
    return FS_EMU_MENU_RESULT_BACK;
}
Esempio n. 4
0
void fs_uae_read_override_actions_for_port(int port)
{
    fs_log("fs_uae_read_override_actions_for_port %d\n", port);
    fs_emu_input_mapping *mapping = g_joystick_mappings[port];
    for (int i = 0; mapping[i].name != NULL; i++) {
        const char* name = mapping[i].name;
        if (strcmp(name, "1") == 0) {
            name = "primary";
        } else if (strcmp(name, "2") == 0) {
            name = "secondary";
        }
        char *key = g_strdup_printf("joystick_port_%d_%s", port, name);
        const char *value = fs_config_get_const_string(key);
        if (value == NULL) {
            continue;
        }
        fs_log("check %s = %s\n", key, value);
        int action = fs_emu_input_action_from_string(value);
        if (action > -1) {
            fs_log("override %s => %s (%d)\n", key, value, action);
            mapping[i].action = action;
        }
        free(key);
    }
}
Esempio n. 5
0
void fs_uae_reconfigure_input_ports_amiga()
{
    fs_emu_log("fs_uae_reconfigure_input_ports_amiga\n");
    int modes = INPUTEVENT_AMIGA_JOYPORT_MODE_0_LAST -
            INPUTEVENT_AMIGA_JOYPORT_MODE_0_NONE + 1;
    //for (int i = 0; i < FS_UAE_NUM_INPUT_PORTS; i++) {
    // only the 4 real ports are reconfigured via input events, the 5th
    // custom joystick port is a local virtual joystick for mapping custom
    // input events only
    for (int i = 0; i < 4; i++) {
        fs_uae_input_port *port = g_fs_uae_input_ports + i;
        if (port->new_mode != port->mode) {
            fs_log("sending event to set port %d to mode %d\n", i, port->new_mode);
            int action = INPUTEVENT_AMIGA_JOYPORT_MODE_0_NONE + modes * i + \
                    port->new_mode;
            fs_emu_queue_action(action, 1);
        }
        if (port->new_autofire_mode != port->autofire_mode) {
            fs_log("sending event to set port %d to autofire mode %d\n", i,
                    port->new_autofire_mode);
            int action = INPUTEVENT_AMIGA_JOYPORT_0_AUTOFIRE + i;
            fs_emu_queue_action(action, 1);
        }
    }
}
Esempio n. 6
0
void fs_uae_set_uae_paths() {
    fs_log("fs_uae_set_uae_paths\n");
    amiga_set_paths(g_paths[FS_UAE_ROM_PATHS].path,
            g_paths[FS_UAE_FLOPPY_PATHS].path,
            g_paths[FS_UAE_CD_PATHS].path,
            g_paths[FS_UAE_HD_PATHS].path);

    static const char *library_dirs[2];
    library_dirs[0] = fs_uae_plugins_dir();
    library_dirs[1] = NULL; // terminates the list
    amiga_set_native_library_dirs(library_dirs);

    // find path for built-in drive sounds
    char *path = fs_get_program_data_file("floppy_sounds");
    if (path) {
        fs_log("found \"built-in\" driveclick directory at %s\n", path);
        amiga_set_builtin_driveclick_path(path);
        free(path);
    }
    else {
        fs_log("did not find \"built-in\" driveclick directory\n");
    }

    // find path for custom drive sounds
    path = g_build_filename(fs_uae_base_dir(), "Floppy Sounds", NULL);
    amiga_set_floppy_sounds_dir(path);
    free(path);
}
Esempio n. 7
0
void fs_emu_init_audio_stream(int stream,
        fs_emu_audio_stream_options *options) {
    fs_log("initializing audio stream %d\n", stream);
    audio_stream *s = g_malloc0(sizeof(audio_stream));
    s->buffer_size = options->buffer_size;
    s->frequency = options->frequency;
    s->num_buffers = MAX_BUFFERS;
    s->min_buffers = options->min_buffers;
    fs_log("frequency: %d, buffers: %d buffer size: %d bytes\n",
            s->frequency, s->num_buffers, s->buffer_size);
    s->mutex = g_mutex_new();
    s->queue = g_queue_new();
    alGenSources(1, &s->source);
    check_al_error("alGenSources");
    for (int i = 0; i < s->num_buffers; i++) {
        ALuint buffer;
        alGenBuffers(1, &buffer);
        check_al_error("alGenBuffers");
        g_queue_push_tail(s->queue, GUINT_TO_POINTER(buffer));
    }
    s->buffers_queued = 0;

    // FIXME: configure elsewhere
    if (stream == 0) {
        s->fill_target = 8 * 1024;
    }
    else {
        s->fill_target = 0;
    }
    s->pid_last_error = 0;
    s->pid_last_last_error = 0;
    s->pid_last_time = 0;
    s->pid_last_last_time = 0;
    g_streams[stream] = s;
}
Esempio n. 8
0
static void setup_pixel_format(HDC hdc)
{
    static PIXELFORMATDESCRIPTOR pfd = {
            sizeof(PIXELFORMATDESCRIPTOR),          //size of structure
            1,                                      //default version
            PFD_DRAW_TO_WINDOW |                    //window drawing support
            PFD_SUPPORT_OPENGL |                    //opengl support
            PFD_DOUBLEBUFFER,                       //double buffering support
            PFD_TYPE_RGBA,                          //RGBA color mode
            32,                                     //32 bit color mode
            0, 0, 0, 0, 0, 0,                       //ignore color bits
            0,                                      //no alpha buffer
            0,                                      //ignore shift bit
            0,                                      //no accumulation buffer
            0, 0, 0, 0,                             //ignore accumulation bits
            16,                                     //16 bit z-buffer size
            0,                                      //no stencil buffer
            0,                                      //no aux buffer
            PFD_MAIN_PLANE,                         //main drawing plane
            0,                                      //reserved
            0, 0, 0 };                              //layer masks ignored
    // choose best matching format
    int nPixelFormat = ChoosePixelFormat(hdc, &pfd);
    fs_log("pixel format flags: %d\n", pfd.dwFlags);
    fs_log("double buffering: %d\n", (pfd.dwFlags & PFD_DOUBLEBUFFER) != 0);
    // set the pixel format to the device context
    SetPixelFormat(hdc, nPixelFormat, &pfd);
}
Esempio n. 9
0
static void context_notification_handler(int notification, void *data) {
    static int recreate = 0;
    fs_emu_shader *shader = (fs_emu_shader *) data;
    if (notification == FS_GL_CONTEXT_DESTROY) {
        fs_log("FS_GL_CONTEXT_DESTROY handler for shader\n");
        GList *link = shader->passes;
        if (shader->passes == NULL) {
            return;
        }
        printf("destroying shaders\n");
        fs_log("destroying shaders\n");
        while (link) {
            shader_pass *pass = link->data;
            glDeleteProgram(pass->program);
            g_free(pass);
            GList *delete_link = link;
            link = link->next;
            g_list_free_1(delete_link);
        }
        recreate = 1;
        shader->passes = NULL;
    }
    else if (notification == FS_GL_CONTEXT_CREATE) {
        fs_log("FS_GL_CONTEXT_CREATE handler for shader\n");
        if (recreate) {
            fs_emu_load_shader(shader);
        }
    }
}
Esempio n. 10
0
static char* read_custom_path(const char *key) {
    char *key_path = g_build_filename(fs_get_user_config_dir(),
            "fs-uae", key, NULL);
    fs_log("- checking %s\n", key_path);
    if (fs_path_is_file(key_path)) {
        FILE * f = fopen(key_path, "rb");
        free(key_path);
        if (f == NULL) {
            fs_log("- file exists but could not open\n");
            return NULL;
        }

        char *buffer = (char *) malloc(PATH_MAX + 1);
        int read_bytes = fread(buffer, 1, PATH_MAX, f);
        int eof = feof(f);
        fclose(f);
        if (!eof) {
            fs_log("- did not get EOF\n");
            free(buffer);
            return NULL;
        }
        buffer[read_bytes] = '\0';
        g_strchomp(buffer);
        fs_log("- read from file: %s\n", buffer);
        char *result = fs_uae_expand_path(buffer);
        free(buffer);
        fs_log("- expanded path: %s\n", result);
        return result;
    }
    return NULL;
}
Esempio n. 11
0
static void configure_logging(const char *logstr)
{
    if (fs_config_get_int(OPTION_LOG_BSDSOCKET) == 1) {
        log_bsd = 1;
    }

    if (!logstr) {
        fs_log("configure logging: none\n");
        return;
    }
    fs_log("configure logging: %s\n", logstr);
    int all = strstr(logstr, "all") != 0;
    int uae_all = all || strstr(logstr, "uae") != 0;
    if (uae_all || strstr(logstr, "uae_disk")) {
        disk_debug_logging = 2;
    }
    if (uae_all || strstr(logstr, "uae_rand")) {
        g_random_debug_logging = 2;
    }
    if (uae_all || strstr(logstr, "uae_input")) {
        inputdevice_logging = 0xffff;
    }
    if (uae_all || strstr(logstr, "uae_fs")) {
        g_fsdb_debug = 1;
    }
    if (uae_all || strstr(logstr, "uae_frame")) {
        g_frame_debug_logging = 1;
    }
}
Esempio n. 12
0
void fse_init_theme()
{
    fs_log("THEME: Init\n");

    fs_emu_theme_overlay* o = g_fs_emu_theme.overlays;
    o[FS_EMU_TOP_LEFT_OVERLAY].name = g_strdup("top_left_overlay");
    o[FS_EMU_TOP_RIGHT_OVERLAY].name = g_strdup("top_right_overlay");
    o[FS_EMU_TOP_RIGHT_OVERLAY].anchor = FS_EMU_ANCHOR_TOP_RIGHT;
    o[FS_EMU_BOTTOM_RIGHT_OVERLAY].name = g_strdup("bottom_right_overlay");
    o[FS_EMU_BOTTOM_RIGHT_OVERLAY].anchor = FS_EMU_ANCHOR_BOTTOM_RIGHT;
    o[FS_EMU_BOTTOM_LEFT_OVERLAY].name = g_strdup("bottom_left_overlay");
    o[FS_EMU_BOTTOM_LEFT_OVERLAY].anchor = FS_EMU_ANCHOR_BOTTOM_LEFT;

    o[FS_EMU_AUDIO_LED_OVERLAY].name = g_strdup("audio_led");
    o[FS_EMU_FPS_LED_OVERLAY].name = g_strdup("fps_led");
    o[FS_EMU_VSYNC_LED_OVERLAY].name = g_strdup("vsync_led");
    o[FS_EMU_FPS_D0_OVERLAY].name = g_strdup("fps_d0");
    o[FS_EMU_FPS_D1_OVERLAY].name = g_strdup("fps_d1");

    const char *theme = fs_config_get_const_string("theme");
    if (theme) {
        g_fs_emu_theme.name = g_strdup(theme);
        // first try to find the theme in the user's theme dir
        const char *themes_dir = fs_config_get_const_string("themes_dir");
        if (themes_dir) {
            g_fs_emu_theme.path = g_build_filename(themes_dir,
                    g_fs_emu_theme.name, NULL);
            if (!fs_path_exists(g_fs_emu_theme.path)) {
                free(g_fs_emu_theme.path);
                g_fs_emu_theme.path = NULL;
            }
        }
        // or by direct path lookup
        if (!g_fs_emu_theme.path) {
            if (fs_path_exists(theme)) {
                g_fs_emu_theme.path = g_strdup(theme);
            }
        }
        // then try to find a bundled / installed theme
        if (!g_fs_emu_theme.path) {
            g_fs_emu_theme.path = fs_get_program_data_file(
                    g_fs_emu_theme.name);
        }
        if (g_fs_emu_theme.path) {
            fs_log("theme found at %s\n", g_fs_emu_theme.path);
        } else {
            fs_emu_warning(_("Theme not found: %s"), g_fs_emu_theme.name);
            free(g_fs_emu_theme.name);
            // resources will not be found, but path should not be NULL...
            g_fs_emu_theme.path = g_strdup("");
        }
    } else {
        g_fs_emu_theme.name = g_strdup("");
        g_fs_emu_theme.path = g_strdup("");
    }

    load_defaults();
    load_theme();
}
Esempio n. 13
0
void fs_ml_fatal(const char *msg)
{
    fs_log("FATAL: %s\n", msg);
    int error = GetLastError();
    fs_log("GetLastError returned %d (not necessarily related)\n", error);
    fs_log("exiting...\n");
    exit(1);
}
Esempio n. 14
0
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam,
        LPARAM lparam) {
    //fs_log("WndProc %d\n", message);

    //static HGLRC hRC; //rendering context
    //static HDC hDC;   //device context
    HRAWINPUT raw_input_handle;

    switch (message) {
    case WM_CREATE:
        g_hdc = GetDC(hwnd);    //get the device context for window
        if (g_hdc == NULL) {
            fs_log("could not get window dc\n");
        }
        setup_pixel_format(g_hdc);
        g_hrc = wglCreateContext(g_hdc);    //create rendering context
        if (g_hrc == NULL) {
            fs_log("could not create wgl context\n");
        }
        //make rendering context current
        if (!wglMakeCurrent(g_hdc, g_hrc)) {
            fs_log("could not set current wgl context in main thread\n");
        }
        break;
    case WM_DESTROY:
        wglMakeCurrent(g_hdc, NULL); //deselect rendering context
        wglDeleteContext(g_hrc); //delete rendering context
        PostQuitMessage(0); //send wm_quit
        break;
    case WM_ERASEBKGND:
        break;
    case WM_INPUT:
        raw_input_handle = (HRAWINPUT) lparam;
        /*
        unsigned int size;
        if (GetRawInputData(raw_input_handle, RID_INPUT, NULL, &size,
                sizeof(RAWINPUTHEADER)) != -1) {
            void *data = malloc(size);
            if (GetRawInputData(raw_input_handle, RID_INPUT, data, &size,
                    sizeof(RAWINPUTHEADER)) != -1) {
                process_input(data);
            }
            free(data);
        }
        */
        unsigned int size = RAW_INPUT_MAX_SIZE;
        if (GetRawInputData(raw_input_handle, RID_INPUT,
                &g_raw_input_data, &size, sizeof(RAWINPUTHEADER)) != -1) {
            process_input(&g_raw_input_data);
        }
        // must call DefWindowProc according to http://msdn.microsoft.com/
        // en-us/library/windows/desktop/ms645590(v=vs.85).aspx
        return DefWindowProc(hwnd, message, wparam, lparam);
    default:
        return DefWindowProc(hwnd, message, wparam, lparam);
    }
    return 0;
}
Esempio n. 15
0
File: x11.c Progetto: engur/fs-uae
static void set_window_icon() {
    fs_log("setting _NET_WM_ICON from icon images\n");

    int max_size = (16 * 16 + 32 * 32 + 48 * 48 + 64 * 64 + 128 * 128) * \
            sizeof(unsigned long);
    // add space for width, height cardinals
    max_size += 2 * 5 * sizeof(unsigned long);

    unsigned long *icon_data = (unsigned long *) g_malloc(max_size);
    unsigned long *op = icon_data;
    int card_count  = 0;

    int sizes[] = {128, 64, 48, 32, 16, 0};
    for(int *size = sizes; *size; size++) {
        char *rel = g_strdup_printf("icons/hicolor/%dx%d/apps/fs-uae.png",
                *size, *size);
        char *path = fs_get_data_file(rel);
        g_free(rel);
        if (!path) {
            fs_log("did not find icon for %dx%d\n", *size, *size);
            continue;
        }

        fs_image *image = fs_image_new_from_file(path);
        if (!image) {
            fs_log("could not load icon from %s\n", path);
            continue;
        }
        g_free(path);

        //printf("%d\n", image->width);
        int pixel_count = image->width * image->height;
        unsigned char *p = image->data;
        *op++ = image->width;
        *op++ = image->height;
        for (int i = 0; i < pixel_count; i++) {
            //*op = 0xffff0000;
            *op = (((unsigned long) p[3]) << 24) |
                    (p[0] << 16) |
                    (p[1] << 8) |
                    p[2];
            p += 4;
            op++;
        }
        card_count += 2 + pixel_count;

        fs_unref(image);

        // FIXME

    }

    Atom _NET_WM_ICON = XInternAtom(g_display, "_NET_WM_ICON", False);
    XChangeProperty(g_display, g_window, _NET_WM_ICON, XA_CARDINAL, 32,
            PropModeReplace, (unsigned char *) icon_data, card_count);
    g_free(icon_data);
}
Esempio n. 16
0
void fs_emu_video_sdl_software_init(void)
{
    fs_log("fs_emu_video_sdl_software_init\n");
#else
void fs_emu_video_sdl_init(void)
{
    fs_log("fs_emu_video_sdl_init\n");
#endif
    register_functions();
}
Esempio n. 17
0
static void *force_quit_thread(void *data)
{
    for (int i = 0; i < 10; i++) {
        fs_ml_usleep(1000 * 1000);
        fs_log("force_quit_thread: %d seconds passed\n", i + 1);
    }
    fs_log("force_quit_thread: should force quit (FIXME: not implemented)\n");
    printf("force_quit_thread: should force quit (FIXME: not implemented)\n");
    return NULL;
}
Esempio n. 18
0
void fs_ml_quit() {
    if (g_quit) {
        fs_log("fs_ml_quit already called\n");
        return;
    }
    fs_log("fs_ml_quit called\n");
    if (g_quit_function) {
        g_quit_function();
    }
    g_quit = 1;
}
Esempio n. 19
0
static void on_quit()
{
    g_fs_emu_quit_time = fs_emu_monotonic_time();
    if (g_quit_function) {
        fs_log("libfsemu on_quit: executing quit function\n");
        g_quit_function();
    } else {
        fs_log("libfsemu on_quit: no quit function\n");
    }
    // FIXME: detached?
    fs_thread_create("force-quit", force_quit_thread, NULL);
}
Esempio n. 20
0
void fs_emu_quit()
{
    fs_log("fs_emu_quit\n");
    if (g_quit_function) {
        fs_log("executing quit function\n");
        if (!g_quit_function()) {
            fs_log("quit aborted\n");
            return;
        }
    }
    fs_ml_quit();
}
Esempio n. 21
0
static const char* fs_uae_home_dir() {
    static const char* path = NULL;
    if (path == NULL) {
        path = fs_get_home_dir();
        if (path == NULL) {
            fs_log("WARNING: did not find home directory\n");
            path = g_strdup("");
        }
        fs_log("- using home directory \"%s\"\n", path);
    }
    return path;
}
Esempio n. 22
0
File: emu.c Progetto: eehrich/fs-uae
int fs_emu_run(fs_emu_main_function function) {
    fs_emu_log("fs_emu_run, main_function at %p\n", function);

    // FIXME: should wait until we are certain that the video thread is
    // running (i.e. wait for a status / flag)

#ifdef WITH_NETPLAY
    // FIXME: MOVE
    if (fs_emu_netplay_enabled()) {
        fs_log("netplay is enabled\n");
        fs_emu_netplay_start();
    }
#endif

    g_emulation_thread = fs_thread_create(
                             "emulation", emulation_thread_entry, function);
    if (g_emulation_thread == NULL) {
        fs_emu_log("error starting video thread\n");
        // FIXME: ERROR MESSAGE HERE
        // FIXME: FATAL
    }

#ifdef FS_EMU_DRIVERS
    int result = fs_emu_main_loop();
#else
    int result = fs_ml_main_loop();
#endif
    fs_emu_log("fs_emu_run: main loop is done\n");

    if (g_fs_emu_benchmark_start_time) {
        int64_t t2 = fs_emu_monotonic_time();
        double ttime = ((t2 - g_fs_emu_benchmark_start_time) / 1000000.0);
        double sys_fps = g_fs_emu_total_sys_frames / ttime;
        double emu_fps = g_fs_emu_total_emu_frames / ttime;
        fs_log("average fps sys: %0.1f emu: %0.1f\n", sys_fps, emu_fps);
    }

    fs_emu_log("fs_emu_run: waiting for emulation thread to stop\n");
    while (g_fs_emu_emulation_thread_running) {
        fs_emu_msleep(1);
    }
    fs_emu_log("fs_emu_run: emulation thread stopped\n");

#ifdef USE_SDL_AUDIO
    fs_emu_log("fs_emu_run: calling SDL_CloseAudio\n");
    SDL_CloseAudio();
#endif

    fs_emu_audio_shutdown();
    fs_emu_log("fs_emu_run: returning\n");
    return result;
}
Esempio n. 23
0
int fs_emu_queue_audio_buffer(int stream, int16_t* data, int size) {
	if (g_fs_emu_benchmarking) {
		// no audio output while benchmarking
		return 0;
	}
    //fs_log("fs_emu_queue_audio_buffer stream %d\n", stream);
    audio_stream *s = g_streams[stream];

    ALuint buffer = 0;
    g_mutex_lock(s->mutex);
    //while (1) {
    buffer = GPOINTER_TO_UINT(g_queue_pop_head(s->queue));
    if (!buffer) {
        fs_log("no audio buffer available - dropping data\n");
        g_mutex_unlock(s->mutex);
        return 0;
    }
    s->buffers_queued += 1;
    // create a local copy while we have the lock
    int buffers_queued = s->buffers_queued;
    g_mutex_unlock(s->mutex);

    alBufferData(buffer, AL_FORMAT_STEREO16, data, size, s->frequency);
    check_al_error("alBufferData");
    alSourceQueueBuffers(s->source, 1, &buffer);
    check_al_error("alSourceQueueBuffers");

    ALint state;
    alGetSourcei(s->source, AL_SOURCE_STATE, &state);
    check_al_error("alGetSourcei (AL_SOURCE_STATE)");
    if (state != AL_PLAYING) {
        // we have had a buffer underrun - we now wait until we have queued
        // some buffers
        if (buffers_queued < s->min_buffers) {
            // want more buffers
        }
        else {
            fs_log("restarting audio stream %d (buffer underrun)\n", stream);
            alSourcePlay(s->source);
            check_al_error("alSourcePlay");
        }
    }

	double want_volume = g_volume * 0.9;
	if (want_volume != s->source_volume_current) {
		s->source_volume_current = want_volume;
		alSourcef(s->source, AL_GAIN, want_volume);
	}

    unqueue_old_buffers(stream);
    return buffer;
}
Esempio n. 24
0
void fs_ml_init_raw_input() {
    fs_log("fs_ml_init_raw_input\n");

    g_debug_keys = getenv("FS_DEBUG_INPUT") && \
            getenv("FS_DEBUG_INPUT")[0] == '1';

    //list_input_devices();
    init_key_mapping();

    SDL_SysWMinfo info;
    SDL_VERSION(&info.version); // this is important!
#if SDL_VERSION_ATLEAST(2, 0, 0)
    if (SDL_GetWindowWMInfo(g_fs_ml_window, &info)) {
#else
    if (SDL_GetWMInfo(&info)) {
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
        g_window = info.info.win.window;
#else
        g_window = info.window;
#endif
        //g_hglrc = info.hglrc;
    }
 
    g_wndproc = (WNDPROC) GetWindowLongPtr(g_window, GWLP_WNDPROC);
    SetWindowLongPtr(g_window, GWLP_WNDPROC, (LONG_PTR) WndProc);
    fs_log("old window proc: %p new window proc: %p\n", g_wndproc, WndProc);

    RAWINPUTDEVICE rid;
    /*
    // mice
    rid.usUsagePage = 0x01;
    rid.usUsage = 0x02;
    rid.dwFlags = 0;
    //rid.dwFlags = RIDEV_INPUTSINK;
    //rid.dwFlags = RIDEV_NOLEGACY;
    rid.hwndTarget = hWnd;
    RegisterRawInputDevices(&rid, 1, sizeof(rid));
    */
    // keyboards
    rid.usUsagePage = 0x01;
    rid.usUsage = 0x06;
    rid.dwFlags = RIDEV_NOLEGACY | RIDEV_NOHOTKEYS;
    rid.hwndTarget = g_window;
    RegisterRawInputDevices(&rid, 1, sizeof(rid));

    g_keyboard_layout = GetKeyboardLayout(0);
}

#else

int libfsemu_ml_rawinput_dummy;
Esempio n. 25
0
int fs_data_init(const char *app_name, const char *dat_name)
{
    fs_log("fs_data_init %s %s\n", app_name, dat_name);
    char exe_path[PATH_MAX + 1];
    int result = fs_get_application_exe_path(exe_path, PATH_MAX);
    if (result != 1) {
        return 1;
    }

    g_dat_table = g_hash_table_new(g_str_hash, g_str_equal);

    /* Check for embedded dat file */
    fs_log("checking dat file: %s\n", exe_path);
    g_dat_file = g_fopen(exe_path, "rb");
    int error = read_zip_entries(g_dat_file);
    if (error == 0) {
        return 0;
    }
    fs_log("no dat file: %s\n", exe_path);
    fclose(g_dat_file);
    g_dat_file = NULL;

    result = fs_get_application_exe_dir(exe_path, PATH_MAX);
    if (result != 1) {
        return 1;
    }

    /* Check if dat file is placed alongside the executable */
    char *dat_path = g_build_filename(exe_path, dat_name, NULL);
    fs_log("checking dat file: %s\n", dat_path);
    g_dat_file = g_fopen(dat_path, "rb");
    free(dat_path);

    if (g_dat_file == NULL) {
        char *dat_path = g_build_filename(
            exe_path, "..", "share", app_name, dat_name, NULL);
        fs_log("checking dat file: %s\n", dat_path);
        g_dat_file = g_fopen(dat_path, "rb");
        free(dat_path);
    }

    if (g_dat_file == NULL) {
        error = 10;
    } else {
        error = read_zip_entries(g_dat_file);
        if (error == 0) {
            return 0;
        }
    }
    return error;
}
Esempio n. 26
0
static void parse_option(char *key, char *value) {
	static int first = 1;
	if (key[0] == 'u' && key[1] == 'a' && key[2] == 'e' && key[3] == '_') {
		if (first) {
			fs_log("WARNING: custom uae_* options used! Your warranty is "
			        "now void! ;)\n");
			fs_log("(not that there was any warranty before...)\n");
			first = 0;
		}
		fs_strchomp(value);
		//amiga_set_hardware_option(key + 4, value);
		amiga_set_option(key + 4, value);
	}
}
Esempio n. 27
0
void fs_ml_video_init() {
    fs_log("creating condition\n");
    g_video_cond = g_cond_new();
    fs_log("creating mutex\n");
    g_video_mutex = g_mutex_new();

    g_video_event_queue = g_queue_new();
    g_video_event_mutex = g_mutex_new();

    g_debug_keys = getenv("FS_DEBUG_INPUT") && \
            getenv("FS_DEBUG_INPUT")[0] == '1';

    fs_ml_render_init();
}
Esempio n. 28
0
void fs_ml_init_raw_input(void)
{
    fs_log("[INPUT ]fs_ml_init_raw_input\n");

    init_key_mapping();

    SDL_SysWMinfo info;
    SDL_VERSION(&info.version); /* This is important! */
#if SDL_VERSION_ATLEAST(2, 0, 0)
    if (SDL_GetWindowWMInfo(g_fs_ml_window, &info)) {
#else
    if (SDL_GetWMInfo(&info)) {
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
        g_window = info.info.win.window;
#else
        g_window = info.window;
#endif
        //g_hglrc = info.hglrc;
    }
 
    g_wndproc = (WNDPROC) GetWindowLongPtr(g_window, GWLP_WNDPROC);
    SetWindowLongPtr(g_window, GWLP_WNDPROC, (LONG_PTR) WndProc);
    fs_log("[RAWINPUT ]Old wndproc: %p new wndproc: %p\n", g_wndproc, WndProc);

    RAWINPUTDEVICE rid;
#if 0
    /* Mice */
    rid.usUsagePage = 0x01;
    rid.usUsage = 0x02;
    rid.dwFlags = 0;
    //rid.dwFlags = RIDEV_INPUTSINK;
    //rid.dwFlags = RIDEV_NOLEGACY;
    rid.hwndTarget = hWnd;
    RegisterRawInputDevices(&rid, 1, sizeof(rid));
#endif
    /* Keyboards */
    rid.usUsagePage = 0x01;
    rid.usUsage = 0x06;
    rid.dwFlags = RIDEV_NOLEGACY | RIDEV_NOHOTKEYS;
    rid.hwndTarget = g_window;
    RegisterRawInputDevices(&rid, 1, sizeof(rid));

    g_keyboard_layout = GetKeyboardLayout(0);
}

#else

int libfsemu_ml_rawinput_dummy;
Esempio n. 29
0
void fs_emu_load_shader(fs_emu_shader *shader) {
    parse_data *data = g_new0(parse_data, 1);
    data->shader = shader;
    data->buffer = malloc(MAX_TEXT_SIZE);

    GMarkupParseContext *context = g_markup_parse_context_new(
            &counter_subparser, G_MARKUP_TREAT_CDATA_AS_TEXT, data, NULL);

    FILE *f = g_fopen(data->shader->path, "rb");
    if (f == NULL) {
        fs_log("could not open shader file\n");
        return;
    }
    char *buffer = malloc(8192);
    int read = fread(buffer, 1, 8192, f);
    while (read > 0) {
        g_markup_parse_context_parse(context, buffer, read, NULL);
        read = fread(buffer, 1, 8192, f);
    }
    fclose(f);
    free(buffer);

    // If the list of shader passes is empty, this shader file is invalid.
    // Abort this algorithm, do not continue trying to load the file. Host
    // applications should alert the user that there was a problem loading
    // the file.

    if (data->shader->passes == NULL) {
        fs_emu_warning("no shader passes loaded");
        data->shader->ok = 0;
    }
    else if (data->error) {
        fs_emu_warning("error occured while loading shader");
        data->shader->ok = 0;
    }
    else {
        fs_log("shader ok\n");
        data->shader->ok = 1;
    }

    free(data->buffer);
    free(data);
    g_markup_parse_context_free(context);

    CHECK_GL_ERROR();

    fs_log("done loading shader\n");
    //exit(1);
}
Esempio n. 30
0
static void cleanup_old_file(const char *path)
{
    char *p = fs_uae_expand_path(path);
    if (fs_path_exists(p)) {
        if (fs_path_is_dir(p)) {
            fs_log("trying to remove old directory %s\n", p);
            g_rmdir(p);
        }
        else {
            fs_log("trying to remove old file %s\n", p);
            g_unlink(p);
        }
    }
    free(p);
}