Esempio n. 1
0
static void configure_joystick_port(
    int port, const char *value, const char *port_name, const char *joy_dev)
{
    fs_emu_log("configuring joystick port %d (%s)\n", port, value);
    fs_uae_input_port *p = g_fs_uae_input_ports + port;

    const char *auto_type = "amiga";
    int auto_mode = AMIGA_JOYPORT_DJOY;
    if (g_fs_uae_amiga_model == MODEL_CD32) {
        auto_type = "cd32";
        auto_mode = AMIGA_JOYPORT_CD32JOY;
    }
    char *key = g_strdup_printf("joystick_port_%d_mode", port);
    const char *mode_string = fs_config_get_const_string(key);
    free(key);

    if (g_ascii_strcasecmp(value, "nothing") == 0
            || g_ascii_strcasecmp(value, "none") == 0) {
        fs_emu_log("nothing connected to port\n");
        strcpy(p->device, "");
        p->new_mode = AMIGA_JOYPORT_NONE;
    } else if (g_ascii_strcasecmp(value, "auto") == 0 && port < 2) {
        if (port == 0) {
            if (!mode_string
                    || g_ascii_strcasecmp(mode_string, "mouse") == 0) {
                p->new_mode = AMIGA_JOYPORT_MOUSE;
                strcpy(p->device, "MOUSE");
            } else if (g_ascii_strcasecmp(mode_string, "joystick") == 0) {
                auto_joystick(p, port, AMIGA_JOYPORT_DJOY, "amiga");
            } else if (g_ascii_strcasecmp(mode_string, "cd32 gamepad") == 0) {
                auto_joystick(p, port, AMIGA_JOYPORT_CD32JOY, "cd32");
            }
        } else {
            auto_joystick(p, port, auto_mode, auto_type);
#if 0
            fs_emu_log("trying to auto-configure joystick 1 in port 1\n");
            p->new_mode = auto_mode;
            int result = fs_emu_configure_joystick("JOYSTICK", auto_type,
                    g_joystick_mappings[port], 1,
                    g_fs_uae_input_ports[port].device, MAX_DEVICE_NAME_LEN);
            if (!result) {
                fs_emu_log("could not auto-configure joystick 1, "
                        "using keyboard emulation\n");
                strcpy(p->device, "KEYBOARD");
            }
#endif
        }
    } else if (g_ascii_strcasecmp(value, "dummy mouse") == 0) {
        p->new_mode = AMIGA_JOYPORT_MOUSE;
    } else if (g_ascii_strcasecmp(value, "dummy joystick") == 0) {
        p->new_mode = AMIGA_JOYPORT_DJOY;
    } else if (g_ascii_strcasecmp(value, "mouse") == 0) {
        strcpy(p->device, "MOUSE");
        p->new_mode = AMIGA_JOYPORT_MOUSE;
    }
    // deprecated
    else if (g_ascii_strcasecmp(value, "amiga_mouse") == 0) {
        p->new_mode = AMIGA_JOYPORT_MOUSE;
    }
    // deprecated
    else if (g_ascii_strcasecmp(value, "amiga_joystick") == 0) {
        p->new_mode = AMIGA_JOYPORT_DJOY;
    } else {
        p->new_mode = auto_mode;
        fs_emu_configure_joystick(value, auto_type,
                g_joystick_mappings[port], 1,
                p->device, MAX_DEVICE_NAME_LEN, false);
    }

    if (mode_string) {
        char *mode_lower = g_ascii_strdown(mode_string, -1);
        if (strcmp(mode_lower, "joystick") == 0) {
            p->new_mode = AMIGA_JOYPORT_DJOY;
        } else if (strcmp(mode_lower, "mouse") == 0) {
            p->new_mode = AMIGA_JOYPORT_MOUSE;
        } else if (strcmp(mode_lower, "cd32 gamepad") == 0) {
            p->new_mode = AMIGA_JOYPORT_CD32JOY;
        } else if (strcmp(mode_lower, "nothing") == 0) {
            p->new_mode = AMIGA_JOYPORT_NONE;
        } else if (strcmp(mode_lower, "none") == 0) {
            p->new_mode = AMIGA_JOYPORT_NONE;
        } else if (strcmp(mode_lower, "custom") == 0) {
            // FIXME: custom is not fully implemented as its own type
            p->new_mode = AMIGA_JOYPORT_DJOY;
        } else {
            fs_log("unknown joystick port mode: %s\n", mode_lower);
        }
        free(mode_lower);
    }

    if (port < 4) {
        // port 4 is "custom joystick"
        key = g_strdup_printf("joystick_port_%d_autofire", port);
        if (fs_config_get_boolean(key) == 1) {
            p->new_autofire_mode = 1;
            p->autofire_mode = 1;
            amiga_set_joystick_port_autofire(port, 1);
        }
        free(key);
    } else {
        /* This is a fake joystick, can be used to map keyboard pressed
         * for example, mode is not set throught input actions, since
         * this need not be synchronized in net play. */
        p->mode = p->new_mode;
    }
}
Esempio n. 2
0
void fs_uae_process_input_event(int line, int action, int state, int playback)
{
    static int first_time = 1;
    if (first_time == 1) {
        first_time = 0;
        int load_state_number = fs_config_get_int("load_state");
        if (load_state_number >= 1 && load_state_number <= 9) {
            // FIXME: improvement, check if state file exists and show
            // GUI warning if not...
            fs_log("trying to load state number: %d\n", load_state_number);
            amiga_send_input_event(
                INPUTEVENT_SPC_STATERESTORE1 - 1 + load_state_number, 1);
        }
    }

#if 0
    g_fs_uae_last_input_event = input_event;
    g_fs_uae_last_input_event_state = state;
    fs_emu_lua_run_handler("on_fs_uae_input_event");
    // handler can modify input event
    amiga_send_input_event(g_fs_uae_last_input_event,
            g_fs_uae_last_input_event_state);
#endif

#if 0
    if (action == INPUTEVENT_KEY_RETURN) {
        printf("FIXME: ignoring RETURN event for now\n");
        return;
    }
#endif

    if (action >= INPUTEVENT_AMIGA_JOYPORT_MODE_0_NONE &&
            action < INPUTEVENT_AMIGA_JOYPORT_MODE_3_LAST) {
        change_port_device_mode(
                action - INPUTEVENT_AMIGA_JOYPORT_MODE_0_NONE);
        return;

    }
    if (action >= INPUTEVENT_AMIGA_JOYPORT_0_DEVICE_0 &&
            action < INPUTEVENT_AMIGA_JOYPORT_0_DEVICE_LAST) {
        select_port_0_device(action - INPUTEVENT_AMIGA_JOYPORT_0_DEVICE_0);
        return;
    }
    if (state && action >= INPUTEVENT_AMIGA_JOYPORT_0_AUTOFIRE &&
            action <= INPUTEVENT_AMIGA_JOYPORT_3_AUTOFIRE) {
        int port = action - INPUTEVENT_AMIGA_JOYPORT_0_AUTOFIRE;
        if (g_fs_uae_input_ports[port].autofire_mode) {
            g_fs_uae_input_ports[port].autofire_mode = 0;
            amiga_set_joystick_port_autofire(port, 0);
            fs_emu_warning(_("Auto-fire disabled for port %d"), port);
        }
        else {
            g_fs_uae_input_ports[port].autofire_mode = 1;
            amiga_set_joystick_port_autofire(port, 1);
            fs_emu_warning(_("Auto-fire enabled for port %d"), port);
        }
        fs_emu_menu_update_current();
        // this event must be passed on to the Amiga core
    }

    int record_event = 1;
    if (playback) {
        record_event = 0;
    }

    int load_state = 0;
    int save_state = 0;
    if (action >= INPUTEVENT_SPC_STATESAVE1 &&
            action <= INPUTEVENT_SPC_STATESAVE9) {
        save_state = action - INPUTEVENT_SPC_STATESAVE1 + 1;
        g_fs_uae_state_number = save_state;
    }

    if (action >= INPUTEVENT_SPC_STATERESTORE1 &&
            action <= INPUTEVENT_SPC_STATERESTORE9) {
        load_state = action - INPUTEVENT_SPC_STATERESTORE1 + 1;
        g_fs_uae_state_number = load_state;
    }

    if (load_state) {
#ifdef WITH_LUA
        fs_log("run handler on_fs_uae_load_state\n");
        fs_emu_lua_run_handler("on_fs_uae_load_state");
#endif
        record_event = 0;
    }
    else if (save_state) {
#ifdef WITH_LUA
        fs_log("run handler on_fs_uae_save_state\n");
        fs_emu_lua_run_handler("on_fs_uae_save_state");
#endif
        record_event = 0;
    }

    if (record_event) {
        fs_uae_record_input_event(line, action, state);
    }
    amiga_send_input_event(action, state);

    if (load_state) {
#ifdef WITH_LUA
        fs_log("run handler on_fs_uae_load_state_done\n");
        fs_emu_lua_run_handler("on_fs_uae_load_state_done");
#endif
    }
    else if (save_state) {
#ifdef WITH_LUA
        fs_log("run handler on_fs_uae_save_state_done\n");
        fs_emu_lua_run_handler("on_fs_uae_save_state_done");
#endif
    }
}