Exemple #1
0
void fse_init(int options)
{
    FSE_INIT_ONCE();
    fse_init_early();
    fs_log("[FSE] Init\n");
    read_config();

#ifdef USE_SDL
    fse_log("[FSE] Initializing SDL\n");
    SDL_Init(SDL_INIT_EVERYTHING);
#endif

    fse_init_hud_after_config();

    fse_init_theme();

#ifdef WITH_NETPLAY
    //g_random_set_seed(time(NULL));
    fse_init_netplay();
#endif

#ifdef FSE_DRIVERS
    fse_init_video();
#else
    if (options & FS_EMU_INIT_VIDEO) {
        fse_init_video();
    }

    fse_init_renderer();
#endif

    /* These must (currently) be called after renderer has been initialized,
     * due to a mutex that must be initialized first. */
    fs_emu_set_overlay_state(FS_EMU_TOP_LEFT_OVERLAY, 1);
    fs_emu_set_overlay_state(FS_EMU_TOP_RIGHT_OVERLAY, 1);
    fs_emu_set_overlay_state(FS_EMU_BOTTOM_RIGHT_OVERLAY, 1);
    fs_emu_set_overlay_state(FS_EMU_BOTTOM_LEFT_OVERLAY, 1);

    fse_log("[FSE] Calling fs_ml_init_2\n");
    fs_ml_init_2();
    fs_ml_set_quit_function(on_quit);

    if (options & FS_EMU_INIT_INPUT) {
        fse_init_input();
    }
    if (options & FS_EMU_INIT_AUDIO) {
        fse_init_audio();
    }
}
Exemple #2
0
void fs_emu_init_2(int options) {
    fs_log("fs_emu_init_2\n");

#ifdef USE_SDL
    fs_emu_log("initializing SDL\n");
    SDL_Init(SDL_INIT_EVERYTHING);
#endif

    fs_emu_hud_init_after_config();

    fs_emu_theme_init();

#ifdef WITH_NETPLAY
    //g_random_set_seed(time(NULL));
    fs_emu_netplay_init();
#endif

#ifdef FS_EMU_DRIVERS
    fs_emu_video_init();
#else
    if (options & FS_EMU_INIT_VIDEO) {
        fs_emu_video_init();
    }

    fs_emu_init_render();
#endif

    // these must (currently) be called after renderer has been initialized,
    // due to a mutex that must be initialized first
    fs_emu_set_overlay_state(FS_EMU_TOP_LEFT_OVERLAY, 1);
    fs_emu_set_overlay_state(FS_EMU_TOP_RIGHT_OVERLAY, 1);
    fs_emu_set_overlay_state(FS_EMU_BOTTOM_RIGHT_OVERLAY, 1);
    fs_emu_set_overlay_state(FS_EMU_BOTTOM_LEFT_OVERLAY, 1);

// #ifdef FS_EMU_DRIVERS_XXX
// #else
    fs_emu_log("calling fs_ml_init_2\n");
    fs_ml_init_2();
    fs_ml_set_quit_function(on_quit);

    fs_emu_log("read config\n");
    read_config();
// #endif

    if (options & FS_EMU_INIT_INPUT) {
        fs_emu_input_init();
#ifdef FS_EMU_DRIVERS
        fs_emu_input_init_2();
#endif
    }
    if (options & FS_EMU_INIT_AUDIO) {
        fs_emu_audio_init();
    }

#ifdef FS_EMU_DRIVERS

#else
    fs_ml_video_set_update_function(fs_emu_video_update_function);
    fs_ml_video_set_render_function(fs_emu_video_render_function);
    fs_ml_video_set_post_render_function(fs_emu_video_after_update);

    if (options & FS_EMU_INIT_VIDEO) {
        char *title;
        if (fs_emu_get_title()) {
            title = g_strdup(fs_emu_get_title());
        }
        else {
            title = g_strdup("Emulator");
        }
        if (fs_emu_get_sub_title()) {
            char *temp = title;
            // using 'MIDDLE DOT' (U+00B7) in UTF-8 format as separator
            title = g_strdup_printf("%s %c%c %s", temp, 0xC2, 0xB7,
                                    fs_emu_get_sub_title());
            free(temp);
        }
        fs_ml_video_create_window(title);
        free(title);
    }
#endif
}
Exemple #3
0
static void update_leds(int64_t t) {
    if (g_fs_emu_video_mode_change_time == 0) {
        // we use this variable to ignore sync warnings for a short while
        // after the emulation has started and/or video mode changes, since
        // it will be temporarily "unstable" then. (normal)
        g_fs_emu_video_mode_change_time = t;
    }

    int vsync_led_state = 0;
    int fps_led_state = 0;
    int audio_led_state = 0;

    double diff;
    int ignore_lossed_frames = 0;
    int ignore_repeated_frames = 0;
    if (fs_ml_get_vblank_sync()) {
        if (g_fs_emu_video_frame_rate_host == 0) {
            // ?
        }
        else if (g_fs_emu_video_frame_rate_host == g_video_frame_rate) {
            // should ideally not lose / get repeated frames
        }
        else if (g_fs_emu_video_frame_rate_host > g_video_frame_rate) {
            ignore_repeated_frames = 1;
        }
        else if (g_fs_emu_video_frame_rate_host < g_video_frame_rate) {
            ignore_lossed_frames = 1;
        }
        diff = g_fs_emu_video_frame_rate_host - fs_emu_get_average_sys_fps();
    }
    else {
        diff = g_video_frame_rate - fs_emu_get_average_sys_fps();
    }

    if (g_fs_emu_video_frame_rate_host == 0) {
        // unknown host frame rate
        diff = 0;
    }
    if (diff < 0) {
        diff = diff * -1;
    }

    if (diff > 0.2) {
        vsync_led_state = 3;
    }
    else if (fs_ml_get_vblank_sync()) {
        if (fs_ml_get_video_sync()) {
            vsync_led_state = 1;
        }
        else {
            vsync_led_state = 2;
        }
    }
    else {
        // leave at 0
    }

    diff = g_video_frame_rate - fs_emu_get_average_emu_fps();
    if (diff < 0) {
        diff = diff * -1;
    }

    if (diff > 0.1) {
        fps_led_state = 3;
    }
    else if (!ignore_lossed_frames &&
            t - g_fs_emu_lost_frame_time < 100000) {
        fps_led_state = 3;
    }
    else if (!ignore_repeated_frames &&
            t - g_fs_emu_repeated_frame_time < 100000) {
        fps_led_state = 3;
    }
    else if (g_video_frame_rate == 60) {
        fps_led_state = 2;
    }
    else {
        fps_led_state = 1;
    }

    if (t - g_fs_emu_audio_buffer_underrun_time < 100000) {
        audio_led_state = 3;
    }
    else {
        audio_led_state = g_fs_emu_audio_stream_playing[0];
    }

    int64_t time_since_change = t - g_fs_emu_video_mode_change_time;
    if (time_since_change < 6000000) { // 6 seconds
        //int state = ((t - g_fs_emu_video_mode_change_time) / 250000) % 2;
        //vsync_led_state = state ? vsync_led_state : 0;
        //fps_led_state = state ? fps_led_state : 0;
        //audio_led_state = state;
        fps_led_state = 0;
    }
    if (time_since_change < 5000000) {
        vsync_led_state = 0;
    }
    if (time_since_change < 2000000) {
        audio_led_state = 0;
    }

    fs_emu_set_overlay_state(FS_EMU_VSYNC_LED_OVERLAY, vsync_led_state);
    fs_emu_set_overlay_state(FS_EMU_FPS_LED_OVERLAY, fps_led_state);
    fs_emu_set_overlay_state(FS_EMU_AUDIO_LED_OVERLAY, audio_led_state);

    // adding 0.1 so 49.9 is rounded up to 50
    int emu_fps = fs_emu_get_average_emu_fps() + 0.1;
    int digit;
    digit = emu_fps / 10;
    if (digit == 0) digit = 10;
    fs_emu_set_overlay_state(FS_EMU_FPS_D1_OVERLAY, digit);
    digit = emu_fps % 10;
    if (digit == 0) digit = 10;
    fs_emu_set_overlay_state(FS_EMU_FPS_D0_OVERLAY, digit);
}