Exemple #1
0
static int hotkey_function(int key_code, int key_mod) {
    //write_log("hotkey: %d mod %d\n", key_code, key_mod);
    switch (key_code) {
    case FS_ML_KEY_R:
        fs_emu_log("hot key: soft reset\n");
        fs_emu_warning(_("Soft Reset"));
        fs_emu_queue_action(INPUTEVENT_SPC_SOFTRESET, 1);
        return 0;
    case FS_ML_KEY_T:
        fs_emu_log("hot key: hard reset\n");
        fs_emu_warning(_("Hard Reset"));
        fs_emu_queue_action(INPUTEVENT_SPC_HARDRESET, 1);
        return 0;
    case FS_ML_KEY_A:
        fs_emu_log("hot key: freeze button\n");
        fs_emu_queue_action(INPUTEVENT_SPC_FREEZEBUTTON, 1);
        return 0;
    case FS_ML_KEY_D:
        fs_emu_log("hot key: enter debugger\n");
        if (fs_config_get_boolean("console_debugger") == 1) {
            fs_emu_warning(_("Activated debugger"));
            fs_emu_queue_action(INPUTEVENT_SPC_ENTERDEBUGGER, 1);
        }
        else {
            fs_emu_warning(_("Option \"%s\" is not enabled"),
                           "console_debugger");
        }
        return 0;
    }
    return 0;
}
Exemple #2
0
void fs_emu_pause(int pause) {
    if (pause == g_pause_mode) {
        return;
    }
    if (g_pause_function == NULL) {
        fs_emu_log("no pause function set");
        return;
    }
    fs_emu_log("fs_menu_pause %d\n", pause);
    //fs_emu_grab_input(g_pause_mode == 1);
    g_pause_mode = pause;
    g_pause_function(pause);
}
Exemple #3
0
static void insert_disk(int drive_index, int disk_index) {
    if (disk_index == -1) {
        fs_emu_log("menu: eject disk from drive %d\n", drive_index);
        int action = INPUTEVENT_SPC_EFLOPPY0 + drive_index;
        fs_emu_queue_action(action, 1);
        //fs_emu_queue_action(action, 0);
        return;
    }
    fs_emu_log("menu: insert disk index %d into df%d\n", disk_index,
               drive_index);
    int action = INPUTEVENT_SPC_DISKSWAPPER_0_0;
    action += drive_index * AMIGA_FLOPPY_LIST_SIZE + disk_index;
    fs_emu_queue_action(action, 1);
}
Exemple #4
0
static char *get_floppy_label(const char* path) {
    if (!path || path[0] == '\0') {
        return g_strdup("");
    }
    char *name = g_path_get_basename(path);
#ifdef USE_GLIB
    GError *error = NULL;
    GRegex *re = g_regex_new(
                     "([A-Za-z0-9_ ]*[Dd][Ii][Ss][Kk][A-Za-z0-9_ ]*)",
                     0, 0, &error);
    if (error) {
        fs_emu_log(" *** error\n");
        return name;
    }
    GMatchInfo *mi = NULL;
    if (!g_regex_match(re, name, 0, &mi) || !g_match_info_matches(mi)) {
        //fs_emu_log(" *** false\n");
        g_match_info_free(mi);
        g_regex_unref(re);
        return name;
    }
    //fs_emu_log(" *** ok?\n");
    char *result = g_match_info_fetch(mi, 1);
    g_match_info_free(mi);
    g_regex_unref(re);
    if (!result) {
        return name;
    }
    g_free(name);
    return result;
#else
    return name;
#endif
}
Exemple #5
0
static int save_states_menu_function(fs_emu_menu_item *unused,
                                     void **result_data) {
    fs_emu_log("save_states_menu_function\n");
    fs_emu_menu_item *item;
    fs_emu_menu *menu = fs_emu_menu_new();
    fs_emu_menu_set_update_function(menu, update_save_states_menu);

    item = fs_emu_menu_item_new();
    fs_emu_menu_append_item(menu, item);
    fs_emu_menu_item_set_title(item, _("Save State"));
    fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_HEADING);

    for (int i = 0; i < NUM_SAVE_SLOTS; i++) {
        item = fs_emu_menu_item_new();
        fs_emu_menu_append_item(menu, item);
        fs_emu_menu_item_set_idata(item, i);
        fs_emu_menu_item_set_activate_function(item,
                                               //save_state_menu_function);
                                               save_function);
    }

    // focus on the last used slot
    menu->index = g_last_save_slot + 1;

    //create_save_state_menu(menu, 1);
    *result_data = menu;
    return FS_EMU_MENU_RESULT_MENU;
}
Exemple #6
0
static int check_save_state_exists(int slot) {
    char *state_file = get_state_file(slot, "uss");
    fs_emu_log("check %s\n", state_file);
    int result = fs_path_exists(state_file);
    free(state_file);
    return result;
}
Exemple #7
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);
        }
    }
}
Exemple #8
0
fs_emu_font *fs_emu_font_new_from_file(const char *name)
{
    fs_emu_log("load font %s\n", name);
    fs_emu_font *font = g_malloc0(sizeof(fs_emu_font));
    font->image = load_font_from_file(name);
    prepare_font(font);
    return font;
}
Exemple #9
0
static int save_function(fs_emu_menu_item *item, void **data) {
    int slot = item->idata;
    fs_emu_log("save_function slot = %d\n", slot);
    g_last_save_slot = slot;

    //amiga_state_save(slot);
    fs_emu_queue_action(INPUTEVENT_SPC_STATESAVE1 + slot, 1);
    return FS_EMU_MENU_RESULT_CLOSE | FS_EMU_MENU_RESULT_ROOT;
}
Exemple #10
0
static void init_freetype(void) {
    int error = FT_Init_FreeType(&library);
    if (error) {
        fs_emu_warning("Could not initialize freetype");
    }
    else {
        fs_emu_log("freetype initialized\n");
    }
}
Exemple #11
0
static void auto_joystick(
    fs_uae_input_port *p, int port, int mode, const char *type)
{
    fs_emu_log("trying to auto-configure joystick in port %d\n", port);
    p->new_mode = mode;
    int result = fs_emu_configure_joystick(
            "JOYSTICK", type, g_joystick_mappings[port], 1,
            g_fs_uae_input_ports[port].device, MAX_DEVICE_NAME_LEN, false);
    if (!result) {
        result = fs_emu_configure_joystick(
            "JOYSTICK #2", type, g_joystick_mappings[port], 1,
            g_fs_uae_input_ports[port].device, MAX_DEVICE_NAME_LEN, false);
    }
    if (!result) {
        fs_emu_log("could not auto-configure joystick,"
                   "using keyboard emulation\n");
        strcpy(p->device, "KEYBOARD");
    }
}
Exemple #12
0
static void insert_cdrom(int drive_index, int disk_index) {
    if (disk_index == -1) {
        fs_emu_log("menu: eject CD from drive %d\n", drive_index);
        amiga_cdrom_set_file(drive_index, "");
        return;
    }
    fs_emu_log("menu: insert CD index %d into drive %d\n", disk_index,
               drive_index);
    char *key = g_strdup_printf("cdrom_image_%d", disk_index);
    char* path = fs_config_get_string(key);
    free(key);
    if (path == NULL) {
        fs_emu_log("no CD at this index in CD-ROM list\n");
    }
    path = fs_uae_expand_path_and_free(path);
    path = fs_uae_resolve_path_and_free(path, FS_UAE_CD_PATHS);
    amiga_cdrom_set_file(drive_index, path);
    free(path);
}
Exemple #13
0
fs_emu_font *fs_emu_font_new_from_data(char *data, int size)
{
    fs_emu_log("load font from data\n");
    fs_emu_font *font = g_malloc0(sizeof(fs_emu_font));
    if (data != NULL) {
        font->image = load_font_from_data(data, size);
    }
    prepare_font(font);
    return font;
}
Exemple #14
0
static int input_menu_function(fs_emu_menu_item *menu_item,
                               void **result_data) {
    int port = fs_emu_menu_item_get_idata(menu_item);
    fs_emu_log("input_menu_function for port %d\n", port);

    char *str;
    fs_emu_menu_item *item;
    fs_emu_menu *menu = fs_emu_menu_new();
    menu->idata = port;
    fs_emu_menu_set_update_function(menu, update_input_menu);

    item = fs_emu_menu_item_new();
    fs_emu_menu_append_item(menu, item);
    /// TRANSLATORS: This is a menu entry and must not be too long
    if (port == 0) {
        str = g_strdup_printf(_("Mouse Port"));
    }
    else if (port == 1) {
        str = g_strdup_printf(_("Joystick Port"));
    }
    else {
        str = g_strdup_printf(_("Joystick Port %d"), port);
    }
    fs_emu_menu_item_set_title(item, str);
    g_free(str);
    fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_HEADING);

    item = fs_emu_menu_item_new();
    fs_emu_menu_append_item(menu, item);
    fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_MENU);
    fs_emu_menu_item_set_idata(item, port);
    fs_emu_menu_item_set_activate_function(item, input_host_menu_function);

    if (port < 4) {
        item = fs_emu_menu_item_new();
        fs_emu_menu_append_item(menu, item);
        fs_emu_menu_item_set_title(item, _("Port Settings"));
        fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_HEADING);

        item = fs_emu_menu_item_new();
        fs_emu_menu_append_item(menu, item);
        fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_MENU);
        fs_emu_menu_item_set_idata(item, port);
        fs_emu_menu_item_set_activate_function(item, input_amiga_menu_function);

        // autofire option
        item = fs_emu_menu_item_new();
        fs_emu_menu_append_item(menu, item);
        fs_emu_menu_item_set_idata(item, port);
        fs_emu_menu_item_set_activate_function(item, input_autofire_function);
    }

    *result_data = menu;
    return FS_EMU_MENU_RESULT_MENU;
}
Exemple #15
0
/**
 * This function is called at the end of the frame rendering function
 */
static void handle_quit_sequence() {
    int fade_time = 750 * 1000;

    int64_t dt = fs_emu_monotonic_time() - g_fs_emu_quit_time;
    if (dt > fade_time && g_fs_emu_emulation_thread_stopped) {
        fs_emu_log("calling fs_ml_stop because emu thread is done\n");
        fs_ml_stop();

    }
    else if (dt > 5 * 1000 * 1000) {
        // 5 seconds has passed after shutdown was requested
        fs_emu_log("calling fs_ml_stop because emu does not stop\n");
        // FIXME: FORCE STOP
        fs_ml_stop();
        fs_emu_log("force-closing the emulator\n");
        exit(1);
    }

    // fade out over 750ms
    float fade = (1.0 * dt) / fade_time;
    if (fade > 1.0) {
        fade = 1.0;
    }

    // draw fading effect
    fs_gl_viewport(0, 0, fs_ml_video_width(), fs_ml_video_height());
    fs_gl_ortho_hd();
    fs_gl_blending(1);
    fs_gl_texturing(0);
    fs_gl_color4f(0.0, 0.0, 0.0, fade);
    GLfloat vert[] = {
        0, 0,
        1920, 0,
        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();
}
Exemple #16
0
static int l_fs_emu_log(lua_State *L) {
    int n = lua_gettop(L);
    if (n != 1 || lua_isstring(L, 1)) {
        lua_pushstring(L, "incorrect argument");
        lua_error(L);
    }

    const char *s = luaL_checkstring(L, 1);
    fs_emu_log("%s\n", s);
    return 0;
}
Exemple #17
0
static char *check_save_state(int slot) {
    char *title = NULL;
    char *state_file = get_state_file(slot, "uss");
    fs_emu_log("check %s\n", state_file);
    if (fs_path_exists(state_file)) {
        fs_emu_log("exists\n");
        struct fs_stat buf;
        if (fs_stat(state_file, &buf) == 0) {
            //GDate date;
            //g_date_clear(&date, 1);
            //g_date_set_time_t(&date, buf.mtime);
            struct tm tm_struct;
            fs_localtime_r(&buf.mtime, &tm_struct);
            char strbuf[32];
            //g_date_strftime(strbuf, 32, "");
            strftime(strbuf, 32, "%Y-%m-%d %H:%M:%S", &tm_struct);
            //title = fs_strdup_printf("%d", buf.mtime);
            title = g_strdup(strbuf);
        }
    }
    g_free(state_file);
    return title;
}
Exemple #18
0
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;
}
Exemple #19
0
static fs_image *load_font_from_file(const char *path)
{
    if (path == NULL) {
        fs_emu_warning(_("Could not find font: %s"), path);
        return NULL;
    }
    fs_emu_log("loading image \"%s\"\n", path);
    fs_image *image = fs_image_new_from_file(path);
    if (image == NULL) {
        fs_emu_warning(_("Error loading font: %s"), path);
        return NULL;
    }
    convert_to_premultiplied_alpha(image);
    return image;
}
Exemple #20
0
static void log_shader_log(int shader) {
    GLint info_length = 0;
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_length);
    if (info_length > 0) {
        char *buffer = (char *) malloc(info_length + 1);
        GLsizei length;
        glGetShaderInfoLog(shader, info_length, &length, buffer);
        buffer[length] = 0;
        fs_emu_log("%s\n", buffer);
        free(buffer);
    }
    else {
        fs_log("GL_INFO_LENGTH was %d\n", info_length);
    }
}
Exemple #21
0
void fs_uae_configure_input()
{
    fs_uae_configure_mouse();
    fs_emu_log("configuring joystick ports:\n");
    amiga_set_option("joyport0", "none");
    amiga_set_option("joyport1", "none");

    fs_uae_configure_actions();

    //fs_emu_set_action_function(joystick_action);
    char *value;
    value = fs_config_get_string("joystick_port_0");
    if (value == NULL) {
        value = g_strdup("mouse");
    }
    configure_joystick_port(0, value, "joyport0", "joy0");
    g_free(value);

    value = fs_config_get_string("joystick_port_1");
    if (value == NULL) {
        value = g_strdup("auto");
    }
    configure_joystick_port(1, value, "joyport1", "joy1");
    g_free(value);

    value = fs_config_get_string("joystick_port_2");
    if (value == NULL) {
        value = g_strdup("nothing");
    }
    configure_joystick_port(2, value, "joyport2", "joy2");
    g_free(value);

    value = fs_config_get_string("joystick_port_3");
    if (value == NULL) {
        value = g_strdup("nothing");
    }
    configure_joystick_port(3, value, "joyport3", "joy3");
    g_free(value);

    value = fs_config_get_string("joystick_port_4");
    if (value == NULL) {
        value = g_strdup("nothing");
    }
    configure_joystick_port(4, value, "joyport4", "joy4");
    g_free(value);
}
Exemple #22
0
void fs_emu_volume_control(int volume) {
    if (volume == -1) {
        if (fs_emu_audio_get_mute()) {
            fs_emu_audio_set_mute(0);
            if (fs_emu_audio_get_volume() == 0) {
                fs_emu_audio_set_volume(10);
            }
        }
        else {
            fs_emu_audio_set_mute(1);
        }
    }
    else if (volume == -2) {
        int volume = MAX(0, fs_emu_audio_get_volume() - 10);
        fs_emu_audio_set_volume(volume);
        if (fs_emu_audio_get_mute()) {
            fs_emu_audio_set_mute(0);
        }
    }
    else if (volume == -3) {
        int volume = MIN(100, fs_emu_audio_get_volume() + 10);
        fs_emu_audio_set_volume(volume);
        if (fs_emu_audio_get_mute()) {
            fs_emu_audio_set_mute(0);
        }
    }

    if (fs_emu_audio_get_mute()) {
        fs_emu_notification(1418909137, _("Volume: Muted"));
    }
    else {
        fs_emu_notification(1418909137, _("Volume: %d%%"),
                fs_emu_audio_get_volume());
    }
#if 0


    fs_emu_log("decrease volume\n");
    if (fs_emu_audio_get_mute()) {
        fs_emu_audio_set_mute(0);
    }
    int volume = MAX(0, fs_emu_audio_get_volume() - 10);
    fs_emu_audio_set_volume(volume);
    fs_emu_notification(1418909137, _("Volume: %d%%"), volume);
}
Exemple #23
0
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;
}
Exemple #24
0
static int input_options_menu_function(fs_emu_menu_item *menu_item,
                                       void **result_data) {
    fs_emu_log("input_options_menu_function\n");

    fs_emu_menu_item *item;
    fs_emu_menu *menu = fs_emu_menu_new();
    fs_emu_menu_set_update_function(menu, update_input_options_menu);

    item = fs_emu_menu_item_new();
    fs_emu_menu_append_item(menu, item);
    fs_emu_menu_item_set_title(item, _("Joystick Port"));
    fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_HEADING);

    add_input_item(menu, 1);

    item = fs_emu_menu_item_new();
    fs_emu_menu_append_item(menu, item);
    fs_emu_menu_item_set_title(item, _("Mouse Port"));
    fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_HEADING);

    add_input_item(menu, 0);

    item = fs_emu_menu_item_new();
    fs_emu_menu_append_item(menu, item);
    /// TRANSLATORS: This is a menu entry and must not be too long
    fs_emu_menu_item_set_title(item, _("Parallel Joystick Ports"));
    fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_HEADING);

    add_input_item(menu, 2);
    add_input_item(menu, 3);

    item = fs_emu_menu_item_new();
    fs_emu_menu_append_item(menu, item);
    /// TRANSLATORS: This is a menu entry and must not be too long
    fs_emu_menu_item_set_title(item, _("Custom Joystick Port"));
    fs_emu_menu_item_set_type(item, FS_EMU_MENU_ITEM_TYPE_HEADING);

    add_input_item(menu, 4);

    *result_data = menu;
    return FS_EMU_MENU_RESULT_MENU;
}
Exemple #25
0
fs_image *load_font_from_file(const char *name) {
    char *full_name = g_strconcat(name, ".png", NULL);
    //char *path = g_build_filename(fs_emu_get_share_dir(), full_name, NULL);
    char *path = fs_get_program_data_file(full_name);
    if (path == NULL) {
        fs_emu_warning("Could not find font %s", full_name);
        return NULL;
    }
    fs_emu_log("loading image \"%s\"\n", path);
    fs_image *image = fs_image_new_from_file(path);
    g_free(path);
    if (image == NULL) {
        fs_emu_warning("Error loading font from %s", full_name);
        g_free(full_name);
        return NULL;
    }
    g_free(full_name);

    // convert to premultiplied alpha
    if (image->format == FS_IMAGE_FORMAT_RGBA) {
        int num_pixels = image->width * image->height;
        unsigned char *pixels = image->data;
        for (int i = 0; i < num_pixels; i++) {
            unsigned char alpha = pixels[3];
            // should really divide by 255, but 256 is faster...
            //pixels[0] = ((int) pixels[0]) * alpha / 256;
            //pixels[1] = ((int) pixels[1]) * alpha / 256;
            //pixels[2] = ((int) pixels[2]) * alpha / 256;
            pixels[0] = ((int) pixels[0]) * alpha / 255;
            pixels[1] = ((int) pixels[1]) * alpha / 255;
            pixels[2] = ((int) pixels[2]) * alpha / 255;
            //pixels[0] = (unsigned char) ((pixels[0] * alpha + 0.5) / 255.0);
            //pixels[1] = (unsigned char) ((pixels[1] * alpha + 0.5) / 255.0);
            //pixels[2] = (unsigned char) ((pixels[2] * alpha + 0.5) / 255.0);
            pixels += 4;
        }
    }
    return image;
}
Exemple #26
0
void fs_uae_configure_input()
{
    fs_uae_configure_mouse();
    fs_emu_log("configuring joystick ports:\n");
    amiga_set_option("joyport0", "none");
    amiga_set_option("joyport1", "none");

    fs_uae_configure_actions();

    char *value;
    value = fs_config_get_string("joystick_port_1");
    if (!value) {
        value = g_strdup("auto");
    }
    configure_joystick_port(1, value, "joyport1", "joy1");
    g_free(value);
    value = fs_config_get_string("joystick_port_0");
    if (!value) {
        value = g_strdup("auto");
    }
    configure_joystick_port(0, value, "joyport0", "joy0");
    g_free(value);

    for (int i = 2; i < FS_UAE_NUM_INPUT_PORTS; i++) {
        gchar *key = g_strdup_printf("joystick_port_%d", i);
        value = fs_config_get_string(key);
        g_free(key);
        if (value == NULL) {
            value = g_strdup("nothing");
        }
        gchar *key2 = g_strdup_printf("joyport%d", i);
        gchar *key3 = g_strdup_printf("joy%d", i);
        configure_joystick_port(i, value, key2, key3);
        g_free(key3);
        g_free(key2);
        g_free(value);
    }
}
Exemple #27
0
void fs_emu_init(void)
{
    fs_log("fs_emu_init\n");
    //if (!g_fs_emu_config) {
    //    g_fs_emu_config = g_key_file_new();
    //}
    fs_time_init();

    if (fs_config_get_boolean("stdout") == 1) {
        fs_log_enable_stdout();
    }

    fs_emu_log("calling fs_ml_init\n");
    fs_ml_init();

#ifdef WITH_LUA
    fs_emu_lua_init();
#endif

    g_gui_mutex = fs_mutex_create();
    fs_emu_hud_init();
    fs_emu_dialog_init();

}
Exemple #28
0
void fs_uae_configure_cdrom() {
    /*
    if (g_fs_uae_amiga_model != MODEL_CDTV && g_fs_uae_amiga_model != MODEL_CD32) {
        return;
    }
    */
    fs_emu_log("configure_cdrom\n");
    char *path = fs_config_get_string("cdrom_drive_0");
    if (path) {
        path = fs_uae_expand_path_and_free(path);
        path = fs_uae_resolve_path_and_free(path, FS_UAE_CD_PATHS);
        //set_default_dirs_from_file_path(path);
        char* temp = fs_strconcat(path, ",", NULL);
        amiga_set_option("cdimage0", temp);
        free(temp);
        free(path);

        if (g_fs_uae_amiga_model != MODEL_CDTV &&
                g_fs_uae_amiga_model != MODEL_CD32) {
            amiga_set_option("scsi", "true");
            amiga_map_cd_drives(1);
        }
    }
}
Exemple #29
0
fs_emu_font *fs_emu_font_new_from_file(const char *name) {
    fs_emu_log("load font %s\n", name);
    fs_emu_font *font = g_malloc0(sizeof(fs_emu_font));
    font->image = load_font_from_file(name);
    
    if (font->image) {
        unsigned char *data = font->image->data;
        uint32_t *idata = (uint32_t *) data;
        uint32_t *line = idata;
        int width = font->image->width;
        int height = font->image->height;

        int x = 1;
        int y = 1;
        int h = 0;
        //uint32_t blank = line[0] & MASK;
        uint32_t blank = line[0];

        for (int i = 0; i < height; i++) {
            //if (i > 0 && h == 0 && (idata[i * width] & MASK) == blank) {
            if (i > 0 && h == 0 && idata[i * width] == blank) {
                h = i - 1;
            }
            idata[i * width] = 0x00000000;
        }
        fs_emu_log("font height: %d pixels\n", h);
        font->h = h;

        unsigned char c = 31; // first actual character is 32
        int in_character = 0;
        while (1) {
            if (in_character) {
                //if ((line[x] & MASK) == blank) {
                if (line[x] == blank) {
                    //fs_log("blank at %d %d\n", x, y);
                    in_character = 0;
                    font->w[c] = x - font->x[c];
                }
            }
            else {
                //if ((line[x] & MASK) != blank) {
                if ((line[x]) != blank) {
                    c++;
                    //fs_log("char %c at %d %d\n", c, x, y);
                    font->x[c] = x;
                    font->y[c] = y;
                    in_character = 1;
                }
            }
            //fs_log("%d %x\n", x, idata[x]);
            line[x] = 0x00000000;
            x++;
            if (x == width) {
                x = 1;
                y = y + (h + 1);
                if (y >= height) {
                    break;
                }
                line = line + width * (h + 1);
                //exit(1);
            }
        }
    }
//#define FONT_DEBUG
#ifdef FONT_DEBUG
    char *out_name;
    out_name = g_strdup_printf("%s.json", name);
    FILE *f = fopen(out_name, "wb");
    ffs_log(f, "{\"x\":[");
    for (int i = 0; i < 256; i++) {
        if (i > 0) {
            ffs_log(f, ",");
        }
        ffs_log(f, "%d", font->x[i]);
    }
    ffs_log(f, "],\"y\":[");
    for (int i = 0; i < 256; i++) {
        if (i > 0) {
            ffs_log(f, ",");
        }
        ffs_log(f, "%d", font->y[i]);
    }
    ffs_log(f, "],\"w\":[");
    for (int i = 0; i < 256; i++) {
        if (i > 0) {
            ffs_log(f, ",");
        }
        ffs_log(f, "%d", font->w[i]);
    }
    ffs_log(f, "],\"h\":[");
    for (int i = 0; i < 256; i++) {
        if (i > 0) {
            ffs_log(f, ",");
        }
        ffs_log(f, "%d", font->h);
    }
    ffs_log(f, "]}");
    g_free(out_name);
    fclose(f);

    out_name = g_strdup_printf("%s.raw", name);
    f = fopen(out_name, "wb");
    fwrite(data, 1, width * height * 4, f);
    fclose(f);
    g_free(out_name);
#endif
    return font;
}
Exemple #30
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();
}