Example #1
0
File: emu.c Project: eehrich/fs-uae
static void *emulation_thread_entry(void *data) {
    fs_emu_log("emulation thread started\n");
    g_fs_emu_emulation_thread_running = 1;
#ifdef WINDOWS
    if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL)) {
        fs_emu_log("thread priority set to THREAD_PRIORITY_ABOVE_NORMAL\n");
    }
    else {
        int dwError = GetLastError();
        fs_emu_log("Failed to set thread priority (%d)\n", dwError);
    }
#endif

#ifdef WITH_NETPLAY
    if (fs_emu_netplay_enabled()) {
        fs_emu_log("netplay is enabled - waiting for connection\n");
        while (!fs_emu_netplay_connected()) {
            // waiting for connection
            fs_emu_msleep(10);
            if (!fs_emu_netplay_enabled()) {
                // net play mode was aborted
                fs_emu_log("netplay aborted\n");
                break;
            }
        }
    }
#endif

    void (*main_function)() = data;
    if (main_function) {
        fs_emu_log("main function at %p\n", data);
        main_function();
    }
    else {
        fs_emu_fatal("main function is NULL pointer\n");
    }

    // call fs_ml_quit in case the quit was not explicitly requested already
    fs_ml_quit();

    g_fs_emu_emulation_thread_running = 0;

    // with this set, and fs_ml_quit being called, the frame render
    // function will call fs_ml_stop when the fadeout effect is done
    g_fs_emu_emulation_thread_stopped = 1;

    //fs_emu_log("calling fs_ml_stop because emulation thread has ended\n");
    //fs_ml_stop();
    return NULL;
}
Example #2
0
void fs_emu_netplay_init() {
    const char *value;

    g_send_mutex = fs_mutex_create();
    g_connection_mutex = fs_mutex_create();
    g_input_event_mutex = fs_mutex_create();
    g_input_event_queue = g_queue_new();
    g_wait_for_frame_cond = fs_condition_create();
    g_wait_for_frame_mutex = fs_mutex_create();

    value = fs_config_get_const_string("netplay_server");
    if (value) {
        g_fs_emu_netplay_server = g_strdup(value);
    }
    if (!fs_emu_netplay_enabled()) {
        return;
    }

    value = fs_config_get_const_string("netplay_tag");
    if (value) {
        strncpy(g_fs_emu_netplay_tag, value, 4);
    }
    else {
        g_fs_emu_netplay_tag[0] = 'U';
        g_fs_emu_netplay_tag[1] = 'N';
        g_fs_emu_netplay_tag[2] = 'K';
    }
    g_fs_emu_netplay_tag[3] = '\0';

    value = fs_config_get_const_string("netplay_port");
    if (value) {
        g_fs_emu_netplay_port = g_strdup(value);
    }

    char *password_value = fs_config_get_string("netplay_password");
    if (password_value) {
        GChecksum *cs = g_checksum_new(G_CHECKSUM_SHA1);
        g_checksum_update(cs, (unsigned char *) "FSNP", 4);
        int len = strlen(password_value);
        for (int i = 0; i < len; i++) {
            unsigned char c = password_value[i];
            // only include ASCII characters
            if (c < 128) {
                g_checksum_update(cs, &c, 1);
            }
        }
        gsize digest_len = 20;
        g_checksum_get_digest(cs, g_fs_emu_netplay_password, &digest_len);
        free(password_value);
        g_checksum_free(cs);
    }

}
Example #3
0
File: emu.c Project: 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;
}
Example #4
0
File: emu.c Project: eehrich/fs-uae
int fs_emu_wait_for_frame(int frame) {
#ifdef WITH_NETPLAY
    if (!fs_emu_netplay_enabled()) {
#endif
        if (fs_emu_get_video_sync()) {
            return 1;
        }
        return wait_for_frame_no_netplay();
#ifdef WITH_NETPLAY
    }
    return fs_emu_netplay_wait_for_frame(frame);
#endif
}
Example #5
0
static void *emulation_thread(void *data)
{
    fse_log("[FSE] Emulation thread started\n");
#ifdef WINDOWS
    set_windows_thread_priority();
#endif
#ifdef WITH_NETPLAY
    if (fs_emu_netplay_enabled()) {
        fse_log("[NETPLAY] Enabled - waiting for connection...\n");
        while (!fs_emu_netplay_connected()) {
            /* Waiting for connection... */
            fs_emu_msleep(10);
            if (!fs_emu_netplay_enabled()) {
                /* Net play mode was aborted. */
                fse_log("netplay aborted\n");
                break;
            }
        }
    }
#endif
    g_fs_emu_emulation_thread_running = 1;
    void (*main_function)() = data;
    if (main_function) {
        fse_log("[FSE] Run main function at %p\n", data);
        main_function();
    } else {
        fs_emu_fatal("[FSE] NULL pointer main function\n");
    }
    /* Call fs_ml_quit in case quit was not explicitly requested already. */
    fs_ml_quit();
    g_fs_emu_emulation_thread_running = 0;
    /* With this set, and fs_ml_quit being called, the frame render
     * function will call fs_ml_stop when the fadeout effect is done. */
    g_fs_emu_emulation_thread_stopped = 1;
    return NULL;
}
Example #6
0
void fs_emu_video_render_function() {
    static int initialized_menu = 0;
    if (!initialized_menu) {
        // render menu once (without really showing it, so all menu
        // resources are initialized and loaded, -prevents flickering
        // when really opening the menu later
        fs_emu_render_menu(g_menu_transition);
        initialized_menu = 1;
    }

    if (g_fs_emu_video_debug) {
        int quarter_height = fs_ml_video_height() / 4;
        fs_gl_viewport(0, quarter_height, fs_ml_video_width(),
                fs_ml_video_height() - quarter_height);
    }
    else {
        fs_gl_viewport(0, 0, fs_ml_video_width(), fs_ml_video_height());
    }

    // FIXME: can perhaps remove this soon..
    fs_emu_video_render_mutex_lock();

    int in_menu = fs_emu_menu_is_active();
    if (in_menu && g_menu_transition_target < 1.0) {
        g_menu_transition_target = 1.0;
    }
    if (!in_menu && g_menu_transition_target > 0.0) {
        g_menu_transition_target = 0.0;
    }

    // FIXME: ideally, we would use time-based animation - for now, we use a
    // simple frame-based animation
    if (g_menu_transition < g_menu_transition_target) {
        if (g_menu_transition_target == 1.0) {
            g_menu_transition += 0.10;
        }
    }
    if (g_menu_transition > g_menu_transition_target) {
        if (g_menu_transition_target == 0.0) {
            g_menu_transition -= 0.10;
        }
    }
    if (g_menu_transition > 1.0) {
        g_menu_transition = 1.0;
    }
    else if (g_menu_transition < 0.0) {
        g_menu_transition = 0.0;
    }

    int matrix_pushed = 0;

    double t0_x = 0.0;
    double t0_y = 0.0;
    double t0_z = -2.42;
    double r0_a = 0.0;

    double t1_x = -0.31;
    //double t1_y = -0.04;
    double t1_y = 0.0;
    double t1_z = -3.7;
    double r1_a = 30.0;

    int perspective = 0;
    if (g_menu_transition == 0.0) {
        perspective = 0;
        fs_gl_ortho();
        //glTranslated(1920.0 / 2.0, 1080.0 / 2.0, 0.0);
        //glScaled(1920.0 / 2.0, 1080.0 / 2.0, 1.0);
    }
    else {
        perspective = 1;

        glClearColor(0.1, 0.1, 0.1, 1.0);
        glClear(GL_DEPTH_BUFFER_BIT);
        CHECK_GL_ERROR();
        fs_gl_ortho_hd();

        // transition y-coordinate between floor and wall
        int splt = 361;
        fs_gl_blending(FALSE);
        fs_gl_texturing(FALSE);
        GLfloat color[] = {
            39.0 / 255.0, 44.0 / 255.0, 51.0 / 255.0, 1.0,
            39.0 / 255.0, 44.0 / 255.0, 51.0 / 255.0, 1.0,
            0.0, 0.0, 0.0, 1.0,
            0.0, 0.0, 0.0, 1.0,

            0.0, 0.0, 0.0, 1.0,
            0.0, 0.0, 0.0, 1.0,
            0.0, 0.0, 0.0, 1.0,
            0.0, 0.0, 0.0, 1.0,

            0.0, 0.0, 0.0, 1.0,
            0.0, 0.0, 0.0, 1.0,
            20.0 / 255.0, 22.0 / 255.0, 26.0 / 255.0, 1.0,
            20.0 / 255.0, 22.0 / 255.0, 26.0 / 255.0, 1.0
        };
        GLfloat vert[] = {
               0, splt, -0.9,
            1920, splt, -0.9,
            1920, 1020, -0.9,
               0, 1020, -0.9,

               0, 1020, -0.9,
            1920, 1020, -0.9,
            1920, 1080, -0.9,
               0, 1080, -0.9,

               0,    0, -0.9,
            1920,    0, -0.9,
            1920, splt, -0.9,
               0, splt, -0.9
        };

        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);

        glColorPointer(4, GL_FLOAT, 0, color);
        glVertexPointer(3, GL_FLOAT, 0, vert);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 12);

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
        CHECK_GL_ERROR();

        fs_gl_perspective();
        double t_x = t0_x + (t1_x - t0_x) * g_menu_transition;
        double t_y = t0_y + (t1_y - t0_y) * g_menu_transition;
        double t_z = t0_z + (t1_z - t0_z) * g_menu_transition;
        double r_a = r0_a + (r1_a - r0_a) * g_menu_transition;

        glPushMatrix();
        matrix_pushed = 1;

        glScaled(16.0 / 9.0, 1.0, 1.0);
        glTranslated(t_x, t_y, t_z);
        glRotated(r_a, 0.0, 1.0, 0.0);
        CHECK_GL_ERROR();
    }

    if (perspective) {
        render_glow(g_menu_transition);
    }
    if (perspective) {
        glPushMatrix();
        glTranslatef(0.0, -2.0, 0.0);
        //glTranslatef(0.0, -1.0, 0.0);
        //glScalef(1.0, -1.0, 1.0);
        glScalef(1.0, -0.5, 1.0);
        glTranslatef(0.0, -1.0, 0.0);
        CHECK_GL_ERROR();
        render_frame(0.33, perspective);
        CHECK_GL_ERROR();
        render_gloss(g_menu_transition * 0.66);
        CHECK_GL_ERROR();
        glPopMatrix();
        CHECK_GL_ERROR();
    }
    render_frame(1.0, perspective);
    if (perspective) {
        render_gloss(g_menu_transition);
    }
    /*
    if (fs_emu_is_paused()) {
        render_pause_fade();
    }
    */

    if (matrix_pushed) {
        glPopMatrix();
        CHECK_GL_ERROR();
        matrix_pushed = 0;
    }

    fs_emu_acquire_gui_lock();
    fs_emu_render_chat();

    //if (fs_emu_menu_is_active()) {
    if (g_menu_transition > 0.0) {
        fs_emu_render_menu(g_menu_transition);
    }

	fs_emu_render_dialog();
    fs_emu_release_gui_lock();

    if (g_fs_emu_hud_mode && fs_emu_netplay_enabled()) {
        fs_gl_ortho_hd();
        fs_gl_texturing(0);
        fs_gl_blending(1);
	fs_gl_color4f(0.0, 0.0, 0.0, 0.5);
        GLfloat vert[] = {
            0, 1030,
            1920, 1030,
            1920, 1080,
            0, 1080
        };
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, vert);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
        glDisableClientState(GL_VERTEX_ARRAY);
        CHECK_GL_ERROR();
#if 0
        glBegin(GL_QUADS);
        glVertex2f(0, 1030);
        glVertex2f(1920, 1030);
        fs_gl_color4f(0.0, 0.0, 0.0, 0.0);
        glVertex2f(1920, 1030 - 50);
        glVertex2f(0, 1030 - 50);
        glEnd();
#endif
        fs_emu_font *menu_font = fs_emu_font_get_menu();
        char *str;

        for (int i = 0; i < MAX_PLAYERS; i++) {
            fs_emu_player *player = g_fs_emu_players + i;
            int x = i * 1920 / 6 + 20;
            int y = 1038;

            int rendered_tag = 0;
            if (player->tag && player->tag[0]) {
                str = g_strdup_printf("%s", player->tag);
                fs_emu_font_render(menu_font, str, x, y,
                        1.0, 1.0, 1.0, 1.0);
                g_free(str);
                rendered_tag = 1;
            }
            if (rendered_tag || player->ping) {
                str = g_strdup_printf("%03d", player->ping);
                fs_emu_font_render(menu_font, str, x + 100, y,
                        1.0, 1.0, 1.0, 1.0);
                g_free(str);
            }
            if (rendered_tag || player->lag) {
                str = g_strdup_printf("%03d", player->lag);
                fs_emu_font_render(menu_font, str, x + 200, y,
                        1.0, 1.0, 1.0, 1.0);
                g_free(str);
            }
        }
    }

    if (g_fs_emu_video_debug) {
        int quarter_height = fs_ml_video_height() / 4;
        fs_gl_viewport(0, 0, fs_ml_video_width(), quarter_height);
        CHECK_GL_ERROR();

        fs_emu_set_texture(NULL);
        CHECK_GL_ERROR();
        static GLuint debug_texture = 0;
        static uint32_t *debug_texture_data = NULL;
        if (debug_texture == 0) {
            debug_texture_data = g_malloc0(256 * 256 * 4);
            glGenTextures(1, &debug_texture);
            CHECK_GL_ERROR();
            fs_gl_bind_texture(debug_texture);
#ifndef HAVE_GLES
            fs_gl_unpack_row_length(0);
#endif
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,
                    GL_RGBA, GL_UNSIGNED_BYTE, NULL);
            CHECK_GL_ERROR();
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                    GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                    GL_CLAMP_TO_EDGE);
            CHECK_GL_ERROR();
        }
        else {
            fs_gl_bind_texture(debug_texture);
            CHECK_GL_ERROR();
        }

        memset(debug_texture_data, 0x00, 256 * 256 * 4);
        CHECK_GL_ERROR();
        fs_emu_video_render_debug_info(debug_texture_data);
        CHECK_GL_ERROR();
        fs_emu_audio_render_debug_info(debug_texture_data);
        CHECK_GL_ERROR();

#ifndef HAVE_GLES
        fs_gl_unpack_row_length(0);
#endif
        CHECK_GL_ERROR();
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 256,
                GL_RGBA, GL_UNSIGNED_BYTE, debug_texture_data);
        CHECK_GL_ERROR();
        fs_gl_ortho_hd();
        fs_gl_texturing(1);
        fs_gl_blending(0);
        fs_gl_color4f(1.0, 1.0, 1.0, 1.0);
        GLfloat tex[] = {
            0.0, 0.0,
            1.0, 0.0,
            1.0, 1.0,
            0.0, 1.0
        };
        GLfloat vert[] = {
            0, 0,
            1920, 0,
            1920, 1080,
            0, 1080
        };

        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        glTexCoordPointer(2, GL_FLOAT, 0, tex);
        glVertexPointer(2, GL_FLOAT, 0, vert);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        CHECK_GL_ERROR();

        glPushMatrix();
        glScalef(1.0, 4.0, 1.0);

        fs_emu_font *menu_font = fs_emu_font_get_menu();
        char *str;

        /*
        str = g_strdup_printf("%d", fs_emu_get_audio_frequency());
        fs_emu_font_render(menu_font, str, 1920 / 2 + 20, 3,
                1.0, 1.0, 1.0, 1.0);
        g_free(str);
        */

        str = g_strdup_printf("%0.1f",
                fs_emu_audio_get_measured_avg_buffer_fill(0) / 1000.0);
        fs_emu_font_render(menu_font, str, 1920 / 2 + 220, 3,
                1.0, 1.0, 1.0, 1.0);
        g_free(str);
        str = g_strdup_printf("%d", g_fs_emu_audio_buffer_underruns);
        fs_emu_font_render(menu_font, str, 1920 / 2 + 420, 3,
                1.0, 1.0, 1.0, 1.0);
        g_free(str);

        fs_emu_font_render(menu_font, "EMU", 20, 3, 1.0, 1.0, 1.0, 1.0);
        str = g_strdup_printf("%0.1f", fs_emu_get_average_emu_fps());
        fs_emu_font_render(menu_font, str, 220, 3, 1.0, 1.0, 1.0, 1.0);
        g_free(str);
        str = g_strdup_printf("%d", g_fs_emu_lost_frames);
        fs_emu_font_render(menu_font, str, 420, 3, 1.0, 1.0, 1.0, 1.0);
        g_free(str);
        str = g_strdup_printf("%d", g_fs_emu_repeated_frames);
        fs_emu_font_render(menu_font, str, 620, 3, 1.0, 1.0, 1.0, 1.0);
        g_free(str);

        fs_emu_font_render(menu_font, "SYS", 20, 140, 1.0, 1.0, 1.0, 1.0);
        str = g_strdup_printf("%0.1f", fs_emu_get_average_sys_fps());
        fs_emu_font_render(menu_font, str, 220, 140, 1.0, 1.0, 1.0, 1.0);
        g_free(str);
        str = g_strdup_printf("%d", g_fs_emu_lost_vblanks);
        fs_emu_font_render(menu_font, str, 420, 140, 1.0, 1.0, 1.0, 1.0);
        g_free(str);

        glPopMatrix();
        CHECK_GL_ERROR();
    }

    if (fs_emu_is_quitting()) {
        handle_quit_sequence();
    }

    fs_emu_video_render_mutex_unlock();
}
Example #7
0
void fs_uae_reconfigure_input_ports_host()
{
    fs_emu_log("fs_uae_reconfigure_input_ports_host\n");
    fs_emu_reset_input_mapping();
    fs_uae_map_keyboard();

    int mouse_mapped_to_port = -1;

    for (int i = 0; i < FS_UAE_NUM_INPUT_PORTS; i++) {
        fs_uae_input_port *port = g_fs_uae_input_ports + i;

        fs_log("configuring joystick port %d\n", i);
        if (port->mode == AMIGA_JOYPORT_NONE) {
            fs_log("* nothing in port\n");
            fs_log("* FIXME\n");
        }
        else if (port->mode == AMIGA_JOYPORT_MOUSE) {
            fs_log("* amiga mouse\n");
            // if (strcmp(port->device, "MOUSE") == 0) {
                // fs_log("* using host mouse\n");
                fs_log("* using device %s\n", port->device);
                map_mouse(port->device, i);
                mouse_mapped_to_port = i;
            // }
            // else {
            //     fs_log("* not mapping host device to amiga mouse\n");
            // }
        }
        else if (port->mode == AMIGA_JOYPORT_DJOY) {
            fs_log("* amiga joystick\n");
            if (strcmp(port->device, "MOUSE") == 0) {
                fs_log("* cannot map mouse to joystick\n");
            }
            else {
                fs_log("* using device %s\n", port->device);
                fs_emu_configure_joystick(port->device, "amiga",
                        g_joystick_mappings[i], 1, NULL, 0, true);
            }
        }
        else if (port->mode == AMIGA_JOYPORT_CD32JOY) {
            fs_log("* amiga cd32 gamepad\n");
            if (strcmp(port->device, "MOUSE") == 0) {
                fs_log("* cannot map mouse to cd32 gamepad\n");
            }
            else {
                fs_log("* using device %s\n", port->device);
                fs_emu_configure_joystick(port->device, "cd32",
                        g_joystick_mappings[i], 1, NULL, 0, true);
            }
        }
    }

    fs_uae_input_port *port0 = g_fs_uae_input_ports;

#if 0
    int autoswitch = fs_config_get_boolean("joystick_port_0_autoswitch");
    if (autoswitch == FS_CONFIG_NONE) {
        autoswitch = 0;
    }

    if (!autoswitch) {
        if (mouse_mapped_to_port == -1 && port0->mode != AMIGA_JOYPORT_NONE) {
            // there is a device in port 0, but mouse is not use in either
            // port
            fs_log("additionally mapping mouse buttons to port 0\n");
            fs_emu_configure_mouse("MOUSE", 0, 0, INPUTEVENT_JOY1_FIRE_BUTTON,
                    0, INPUTEVENT_JOY1_2ND_BUTTON, 0);
        }
    }
#endif

    if (mouse_mapped_to_port == -1 && port0->mode == AMIGA_JOYPORT_DJOY) {
        fs_log("additionally mapping mouse to port 0\n");
        map_mouse("mouse", 0);
    }

#if 0
    if (autoswitch && !fs_emu_netplay_enabled()) {
        // auto-select for other devices when not in netplay mode

        if (mouse_mapped_to_port == -1) {
            // FIXME: device "9" is a bit of a hack here, should promote
            fs_emu_configure_mouse("MOUSE",
                    0, 0, INPUTEVENT_AMIGA_JOYPORT_0_DEVICE_9, 0, 0, 0);
        }

        int count;
        fs_emu_input_device *input_device = fs_emu_get_input_devices(&count);
        for (int i = 0; i < count; i++) {
            //printf("---- %d %s\n", i, input_device->name);
            //printf("usage: %d\n", input_device->usage);
            if (input_device->usage) {
                // this device is used, so we don't want auto-select for this
                // device
                input_device++;
                continue;
            }

            if (strcmp(input_device->name, "KEYBOARD") == 0) {
                continue;
            }

            int input_event = INPUTEVENT_AMIGA_JOYPORT_0_DEVICE_0 + i;
            fs_emu_input_mapping mapping[] = {
                { "1", input_event },
                { NULL, 0 },
            };
            fs_emu_configure_joystick(input_device->name, "amiga",
                    mapping, 0, NULL, 0);
            input_device++;
        };
    }
#endif

    fs_emu_map_custom_actions();
}
Example #8
0
int main(int argc, char *argv[])
{
    fs_uae_argc = argc;
    fs_uae_argv = argv;
    fs_set_argv(argc, argv);

#ifdef WITH_CEF
    cef_init(argc, argv);
#endif

    char **arg;
    arg = argv + 1;
    while (arg && *arg) {
        if (strcmp(*arg, "--list-joysticks") == 0) {
            list_joysticks();
            exit(0);
        } else if (strcmp(*arg, "--list-devices") == 0) {
            list_joysticks();
            exit(0);
        } else if (strcmp(*arg, "--version") == 0) {
            printf("%s\n", PACKAGE_VERSION);
            exit(0);
        } else if (strcmp(*arg, "--help") == 0) {
            printf(COPYRIGHT_NOTICE, PACKAGE_VERSION, OS_NAME_2, ARCH_NAME_2);
            printf(EXTRA_HELP_TEXT);
            exit(0);
        }
        arg++;
    }

    fs_init();
    int error = fs_data_init("fs-uae", "fs-uae.dat");
    if (error) {
        printf("WARNING: error (%d) loading fs-uae.dat\n", error);
    }

    fs_set_prgname("fs-uae");
    fs_set_application_name("Amiga Emulator");

    amiga_set_log_function(log_to_libfsemu);

    //result = parse_options(argc, argv);

    printf(COPYRIGHT_NOTICE, PACKAGE_VERSION, OS_NAME_2, ARCH_NAME_2);
    fs_log(COPYRIGHT_NOTICE, PACKAGE_VERSION, OS_NAME_2, ARCH_NAME_2);

    char *current_dir = g_get_current_dir();
    fs_log("current directory is %s\n", current_dir);
    g_free(current_dir);

    amiga_init();

#if 0
    // FIXME: disabling fullscreen spaces must be done before
    // SDL_INIT_VIDEO, but we need to check config to see if this should
    // be done, and we initialize SDL early to check for config file
    // (catch 22)...
    // FIXME: check fullscreen_spaces option
    SDL_SetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, "0");
#endif

#ifdef MACOSX
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_PumpEvents();
    SDL_Event event;
    fs_log("OS X: Check for pending SDL_DROPFILE event\n");
    while (SDL_PollEvent(&event)) {
        fs_log("Got SDL event 0x%x\n", event.type);
        if (event.type == SDL_DROPFILE) {
            if (event.drop.file != NULL) {
                g_fs_uae_config_file_path = strdup(event.drop.file);
            }
            SDL_free(event.drop.file);
        }
    }
#endif

    // skip first entry
    arg = argv + 1;
    if (g_fs_uae_config_file_path == NULL) {
        while (arg && *arg) {
            const gchar *test_path = *arg;
            if (test_path && fs_path_exists(test_path)) {
                if (check_extension(test_path, ".fs-uae")) {
                    g_fs_uae_config_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".conf")) {
                    g_fs_uae_config_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".adf")) {
                    g_fs_uae_disk_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".ipf")) {
                    g_fs_uae_disk_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".dms")) {
                    g_fs_uae_disk_file_path = g_strdup(test_path);
                }
            }
            arg++;
        }
    }

    /* Parse options first, in case base_dir, logging  options etc is
     * specified on the command line. */
    fs_config_parse_options(argc - 1, argv + 1);

    fs_log("\n");
    fs_log(LOG_LINE);
    fs_log("libfsemu init\n");
    fs_log(LOG_LINE);
    fs_log("\n");

    fs_emu_path_set_expand_function(fs_uae_expand_path);

    fs_emu_init_overlays(overlay_names);
    fs_emu_init();

    // then load the config file
    load_config_file();

    init_i18n();

    if (g_fs_uae_disk_file_path) {
        fs_config_set_string(OPTION_FLOPPY_DRIVE_0, g_fs_uae_disk_file_path);
        g_warn_about_missing_config_file = 0;
    }

    if (g_warn_about_missing_config_file) {
        fs_emu_warning(_("No configuration file was found"));
    }

    fs_log("\n");
    fs_log(LOG_LINE);
    fs_log("fs-uae init\n");
    fs_log(LOG_LINE);
    fs_log("\n");

    configure_logging(fs_config_get_const_string("log"));
    fs_emu_set_state_check_function(amiga_get_state_checksum);
    fs_emu_set_rand_check_function(amiga_get_rand_checksum);

    // force creation of some recommended default directories
    fs_uae_kickstarts_dir();
    fs_uae_configurations_dir();
    fs_uae_init_path_resolver();

    fs_uae_plugins_init();

    // must be called early, before fs_emu_init -affects video output
    fs_uae_configure_amiga_model();

    // force creation of state directories
    //fs_uae_flash_memory_dir();
    //fs_uae_save_states_dir();
    //fs_uae_floppy_overlays_dir();
    fs_uae_state_dir();

    const char *controllers_dir = fs_uae_controllers_dir();
    if (controllers_dir) {
        fs_emu_set_controllers_dir(controllers_dir);
    }
    const char *logs_dir = fs_uae_logs_dir();
    if (logs_dir) {
        char *log_file;

        log_file = g_build_filename(logs_dir, "FS-UAE.log", NULL);
        if (fs_path_exists(log_file)) {
            g_unlink(log_file);
        }
        g_free(log_file);

        log_file = g_build_filename(logs_dir, "FS-UAE.log.txt", NULL);
        if (fs_path_exists(log_file)) {
            g_unlink(log_file);
        }
        g_free(log_file);

        log_file = g_build_filename(logs_dir, "Emulator.log.txt", NULL);
        if (fs_path_exists(log_file)) {
            g_unlink(log_file);
        }
        g_free(log_file);

        log_file = g_build_filename(logs_dir, "fs-uae.log.txt", NULL);
        fs_config_set_log_file(log_file);
        g_free(log_file);
    }

    fs_config_set_string_if_unset("themes_dir", fs_uae_themes_dir());

    fs_emu_set_pause_function(pause_function);

    //fs_uae_init_input();
    fs_emu_init_2(FS_EMU_INIT_EVERYTHING);

    // we initialize the recording module either it is used or not, so it
    // can delete state-specific recordings (if necessary) when states are
    // saved
    fs_uae_init_recording();

    int deterministic_mode = 0;
    const char* record_file = fs_config_get_const_string("record");
    if (record_file) {
        fs_log("record file specified: %s, forcing deterministic mode\n",
            record_file);
        deterministic_mode = 1;
        fs_uae_enable_recording(record_file);
    } else {
        fs_log("not running in record mode\n");
    }
    if (fs_emu_netplay_enabled() ||
            fs_config_get_boolean(OPTION_DETERMINISTIC) == 1) {
        deterministic_mode = 1;
    }
    if (deterministic_mode) {
        amiga_set_deterministic_mode();
    }

    if (logs_dir) {
        if (fs_emu_netplay_enabled()) {
            char *sync_log_file = g_build_filename(logs_dir,
                    "Synchronization.log", NULL);
            amiga_set_synchronization_log_file(sync_log_file);
            free(sync_log_file);
        }
    }

#ifdef FS_EMU_DRIVERS
    fs_emu_audio_stream_options **options = fs_emu_audio_alloc_stream_options(2);
    options[0]->frequency = fs_emu_audio_output_frequency();
    /* 12 * 2352 is CDDA_BUFFERS * 2352 (blkdev_cdimage.cpp) */
    options[1]->buffer_size = 12 * 2352;
    // begin playing with only one buffer queued
    options[1]->min_buffers = 1;
    fs_emu_audio_configure(options);
    amiga_set_audio_buffer_size(options[0]->buffer_size);
    fs_emu_audio_free_stream_options(options);
#else
    // this stream is for paula output and drive clicks
    // FIXME: could mix drive clicks in its own stream instead, -might
    // give higher quality mixing
    fs_emu_audio_stream_options options;
    options.struct_size = sizeof(fs_emu_audio_stream_options);
    fs_emu_init_audio_stream_options(&options);
    options.frequency = fs_emu_audio_output_frequency();
    fs_emu_init_audio_stream(0, &options);
    amiga_set_audio_buffer_size(options.buffer_size);

    // this stream is for CD audio output (CDTV/CD32)
    fs_emu_init_audio_stream_options(&options);
    // 12 * 2352 is CDDA_BUFFERS * 2352 (blkdev_cdimage.cpp)
    options.buffer_size = 12 * 2352;
    // begin playing with only one buffer queued
    options.min_buffers = 1;
    fs_emu_init_audio_stream(1, &options);
#endif

    amiga_set_audio_callback(audio_callback_function);
    amiga_set_cd_audio_callback(audio_callback_function);
    amiga_set_event_function(event_handler);

    amiga_set_led_function(led_function);
    amiga_on_update_leds(on_update_leds);

    amiga_set_media_function(media_function);
    amiga_set_init_function(on_init);

    if (fs_config_get_boolean(OPTION_JIT_COMPILER) == 1) {
        amiga_init_jit_compiler();
    }

#ifdef WITH_LUA
    amiga_init_lua(fs_emu_acquire_lua, fs_emu_release_lua);
    amiga_init_lua_state(fs_emu_get_lua_state());
    fs_uae_init_lua_state(fs_emu_get_lua_state());
#endif

    if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_RGBA) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_RGBA);
    } else if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_BGRA) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_BGRA);
    } else if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_R5G6B5) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_R5G6B5);
    } else if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_R5G5B5A1) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_R5G5B5A1);
    } else {
        fs_emu_warning("Unsupported video format requested");
    }
    amiga_add_rtg_resolution(672, 540);
    amiga_add_rtg_resolution(960, 540);
    amiga_add_rtg_resolution(672 * 2, 540 * 2);
    amiga_add_rtg_resolution(fs_emu_get_windowed_width(),
            fs_emu_get_windowed_height());
    amiga_add_rtg_resolution(fs_emu_get_fullscreen_width(),
            fs_emu_get_fullscreen_height());
    fs_uae_init_video();

    //fs_uae_init_keyboard();
    fs_uae_init_mouse();
    fs_uae_configure_menu();

    fs_emu_run(main_function);
    fs_log("fs-uae shutting down, fs_emu_run returned\n");
    if (g_rmdir(fs_uae_state_dir()) == 0) {
        fs_log("state dir %s was removed because it was empty\n",
                fs_uae_state_dir());
    }
    else {
        fs_log("state dir %s was not removed (non-empty)\n",
                fs_uae_state_dir());
    }
    fs_log("end of main function\n");
    cleanup_old_files();

#ifdef WITH_CEF
    cef_destroy();
#endif
    return 0;
}
Example #9
0
void fs_emu_video_init_options(void) {

	//int auto_sync_mode = 1;
    //int sync_to_vblank = 1;
    //int sync_with_emu = 0;
    char *sync_mode_str = NULL;

    int fsaa = fs_config_get_int_clamped("fsaa", 0, 4);
    if (fsaa != FS_CONFIG_NONE) {
        fs_log("setting full-scene anti-aliasing (FSAA) to %dx%d\n",
                fsaa, fsaa);
        fs_ml_set_video_fsaa(fsaa);
    }
    else {
        fs_log("full-scene anti-aliasing is not requested\n");
    }

    fs_ml_video_mode mode;
    memset(&mode, 0, sizeof(fs_ml_video_mode));
    if (fs_ml_video_mode_get_current(&mode) == 0) {
        fs_log("current display mode is %dx%d @ %d Hz\n", mode.width,
                mode.height, mode.fps);
        int assume_refresh_rate = fs_config_get_int("assume_refresh_rate");
        if (assume_refresh_rate != FS_CONFIG_NONE) {
            fs_log("assuming host refresh rate: %d Hz (from config)\n",
                    assume_refresh_rate);
            g_fs_emu_video_frame_rate_host = assume_refresh_rate;
        }
        else {
            g_fs_emu_video_frame_rate_host = mode.fps;
        }
    }
    else {
        fs_log("could not get display mode\n");
    }

    fs_log("checking video sync mode\n");

    sync_mode_str = fs_config_get_string("video_sync");
    if (!sync_mode_str) {
        // compatibility key, FIXME: remove when FS-UAE translates compat
        // option names when loading config.
        sync_mode_str = fs_config_get_string("sync");
    }
    if (sync_mode_str) {
        if (g_ascii_strcasecmp(sync_mode_str, "auto") == 0) {
            g_fs_emu_video_sync_to_vblank = 1;
            g_fs_emu_video_allow_full_sync = 1;
        }
        else if (g_ascii_strcasecmp(sync_mode_str, "1") == 0) {
            // shortcut option, nice from command line (e.g. --video-sync)
            g_fs_emu_video_sync_to_vblank = 1;
            g_fs_emu_video_allow_full_sync = 1;
        }
        else if (g_ascii_strcasecmp(sync_mode_str, "full") == 0) {
            // old compatibility option
            g_fs_emu_video_sync_to_vblank = 1;
            g_fs_emu_video_allow_full_sync = 1;
        }
        else if (g_ascii_strcasecmp(sync_mode_str, "0") == 0) {
            // shortcut option, nice from command line (e.g. --no-video-sync)
            g_fs_emu_video_sync_to_vblank = 0;
            g_fs_emu_video_allow_full_sync = 0;
        }
        else if (g_ascii_strcasecmp(sync_mode_str, "off") == 0) {
            //g_fs_emu_video_sync_to_vblank = 0;
            //g_fs_emu_video_allow_full_sync = 0;
        }
        else if (g_ascii_strcasecmp(sync_mode_str, "vblank") == 0) {
            g_fs_emu_video_sync_to_vblank = 1;
        }
        else {
            fs_log("WARNING: invalid value for video-sync: %s\n",
                    sync_mode_str);
        }
        free(sync_mode_str);
    }
    else {
        //fs_log("not specified: using automatic video sync mode\n");

        fs_log("not specified: no video sync\n");
        //g_fs_emu_video_sync_to_vblank = 0;
        //g_fs_emu_video_allow_full_sync = 0;
    }

/*
    if (auto_sync_mode) {
        fs_log("auto sync mode is enabled\n");
        if (frame_rate && frame_rate == mode.fps) {
            fs_log("frame rate (%d) equals screen refresh (%d)\n",
                    frame_rate, mode.fps);
            sync_to_vblank = 1;
            sync_with_emu = 1;
        }
        else {
            fs_log("frame rate (%d) does not equal screen refresh (%d)\n",
                    frame_rate, mode.fps);
            sync_to_vblank = 1;
        }
    }
*/

    if (fs_emu_netplay_enabled()) {
        fs_log("netplay is enabled, disabling full video/emulator sync\n");
        g_fs_emu_video_allow_full_sync = 0;
        //sync_with_emu = 0;
        //sync_to_vblank = 0;
    }

    if (fs_config_get_boolean("benchmark") != FS_CONFIG_NONE) {
        fs_log("benchmarking enable, disabling video sync\n");
        g_fs_emu_video_sync_to_vblank = 0;
        //sync_with_emu = 0;
        g_fs_emu_benchmarking = 1;
        g_fs_ml_benchmarking = 1;

        g_fs_emu_video_allow_full_sync = 0;
    }

    //if (sync_with_emu && !g_fs_emu_full_sync_allowed) {

    // FIXME: check where g_fs_emu_full_sync_allowed is used
    if (!g_fs_emu_full_sync_allowed) {
        fs_log("full video/emu sync is not allowed in this mode\n");
        //sync_with_emu = 0;
        g_fs_emu_video_allow_full_sync = 0;
    }

    /*
    if (sync_with_emu) {
        fs_log("will sync emulation and video with vblank\n");
        fs_ml_video_sync_enable();

        if (frame_rate && mode.fps) {
            double pitch = (1.0 * mode.fps) / frame_rate;
            fs_log("changing audio pitch to %0.2f based on frame rates\n",
                    pitch);
            fs_emu_audio_set_default_pitch(pitch);
        }
    }
    else if (sync_to_vblank) {
        fs_log("will sync video output only to vblank (no tearing)\n");
        fs_ml_vblank_sync_enable();
    }
    else {
        fs_log("no video sync\n");
    }
    */

    if (g_fs_emu_video_sync_to_vblank) {
        fs_log("will sync video updates to vblank\n");
        fs_ml_vblank_sync_enable();
    }
    else {
        fs_log("no video sync (using timers only)\n");
    }

    if (fs_config_get_boolean("disable_aspect_correction") == 1) {
        g_fs_emu_disable_aspect_correction = 1;
    }
    else if (fs_config_get_boolean("keep_aspect") == 1) {
        fs_emu_video_set_aspect_correction(1);
    }

    // the default texture format is RGB, set here because some video
    // formats implicitly changes the default texture format
    g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGB;

    const char *s = fs_config_get_const_string("video_format");
    if (s) {
        if (g_ascii_strcasecmp(s, "bgra") == 0) {
            fs_log("using video format BGRA\n");
            g_fs_emu_video_format = FS_EMU_VIDEO_FORMAT_BGRA;
            g_fs_emu_video_bpp = 4;
        }
        else if (g_ascii_strcasecmp(s, "rgba") == 0) {
            fs_log("using video format RGBA\n");
            g_fs_emu_video_format = FS_EMU_VIDEO_FORMAT_RGBA;
            g_fs_emu_video_bpp = 4;
        }
        else if (g_ascii_strcasecmp(s, "rgb") == 0) {
            fs_log("using video format RGB\n");
            g_fs_emu_video_format = FS_EMU_VIDEO_FORMAT_RGB;
            g_fs_emu_video_bpp = 3;
        }
        else if (g_ascii_strcasecmp(s, "rgb565") == 0) {
            fs_log("using video format RGB565\n");
            g_fs_emu_video_format = FS_EMU_VIDEO_FORMAT_R5G6B5;
            g_fs_emu_video_bpp = 2;
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGB5;
        }
        else if (g_ascii_strcasecmp(s, "rgba5551") == 0) {
            fs_log("using video format RGBA5551\n");
            g_fs_emu_video_format = FS_EMU_VIDEO_FORMAT_R5G5B5A1;
            g_fs_emu_video_bpp = 2;
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGB5_A1;
        }
        else {
            fs_emu_warning("Unknown video format");
        }
    }
    if (!g_fs_emu_video_format) {
        fs_log("using default video format BGRA\n");
        g_fs_emu_video_format = FS_EMU_VIDEO_FORMAT_BGRA;
        g_fs_emu_video_bpp = 4;
    }

    s = fs_config_get_const_string("texture_format");
    if (s) {
        if (g_ascii_strcasecmp(s, "rgb") == 0) {
            fs_log("using texture format RGB\n");
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGB;
        }
        else if (g_ascii_strcasecmp(s, "rgb8") == 0) {
            fs_log("using texture format RGB8\n");
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGB8;
        }
        else if (g_ascii_strcasecmp(s, "rgba") == 0) {
            fs_log("using texture format RGBA\n");
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGBA;
        }
        else if (g_ascii_strcasecmp(s, "rgba8") == 0) {
            fs_log("using texture format RGBA8\n");
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGBA8;
        }
        else if (g_ascii_strcasecmp(s, "rgb5") == 0) {
            fs_log("using texture format RGB5\n");
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGB5;
        }
        else if (g_ascii_strcasecmp(s, "rgb5_a1") == 0) {
            fs_log("using texture format RGB5_A1\n");
            g_fs_emu_texture_format = FS_EMU_TEXTURE_FORMAT_RGB5_A1;
        }
        else {
            fs_emu_warning("Unknown texture format (using default)");
        }
    }
    else {
        fs_log("using default texture format\n");
    }

    double dval;

    if (fs_config_get_boolean("scanlines") == 1) {
        g_fs_emu_scanlines = 1;
    }
    dval = fs_config_get_double_clamped("scanlines_light", 0, 100);
    if (dval != FS_CONFIG_NONE) {
        g_fs_emu_scanlines_light = 255.0 * dval / 100.0;
    }
    dval = fs_config_get_double_clamped("scanlines_dark", 0, 100);
    if (dval != FS_CONFIG_NONE) {
        g_fs_emu_scanlines_dark = 255.0 * dval / 100.0;
    }
}