Example #1
0
/*********************************************************************************************************
* sdl event filter
*/
static int event_sdl_filter(const SDL_Event *event)
{
    int cmd, action;

    switch(event->type)
    {
        // user clicked on window close button
        case SDL_QUIT:
            main_stop();
            break;

        case SDL_KEYDOWN:
            event_sdl_keydown(event->key.keysym.sym, event->key.keysym.mod);
            return 0;
        case SDL_KEYUP:
            event_sdl_keyup(event->key.keysym.sym, event->key.keysym.mod);
            return 0;

        // if joystick action is detected, check if it's mapped to a special function
        case SDL_JOYAXISMOTION:
        case SDL_JOYBUTTONDOWN:
        case SDL_JOYBUTTONUP:
        case SDL_JOYHATMOTION:
            for (cmd = 0; cmd < NumJoyCommands; cmd++)
            {
                action = MatchJoyCommand(event, (eJoyCommand) cmd);
                if (action == 1) /* command was just activated (button down, etc) */
                {
                    if (cmd == joyFullscreen)
                        changeWindow();
                    else if (cmd == joyStop)
                        main_stop();
                    else if (cmd == joyPause)
                        main_toggle_pause();
                    else if (cmd == joySave)
                        main_state_save(0, NULL); /* save in mupen64plus format using current slot */
                    else if (cmd == joyLoad)
                        main_state_load(NULL); /* load using current slot */
                    else if (cmd == joyIncrement)
                        main_state_inc_slot();
                    else if (cmd == joyScreenshot)
                        main_take_next_screenshot();
                    else if (cmd == joyMute)
                    {
                        volumeMute();
                        main_draw_volume_osd();
                    }
                    else if (cmd == joyDecrease)
                    {
                        volumeDown();
                        main_draw_volume_osd();
                    }
                    else if (cmd == joyIncrease)
                    {
                        volumeUp();
                        main_draw_volume_osd();
                    }
                    else if (cmd == joyForward)
                        main_set_fastforward(1);
                }
                else if (action == -1) /* command was just de-activated (button up, etc) */
                {
                    if (cmd == joyForward)
                        main_set_fastforward(0);
                }
            }

            return 0;
            break;
    }

    return 1;
}
Example #2
0
void event_sdl_keydown(int keysym, int keymod)
{
    /* check for the only 2 hard-coded key commands: Alt-enter for fullscreen and 0-9 for save state slot */
    if (keysym == SDLK_RETURN && keymod & (KMOD_LALT | KMOD_RALT))
    {
        changeWindow();
    }
    else if (keysym >= SDLK_0 && keysym <= SDLK_9)
    {
        main_state_set_slot(keysym - SDLK_0);
    }
    /* check all of the configurable commands */
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdStop))
        main_stop();
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdFullscreen))
        changeWindow();
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdSave))
        main_state_save(0, NULL); /* save in mupen64plus format using current slot */
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdLoad))
        main_state_load(NULL); /* load using current slot */
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdIncrement))
        main_state_inc_slot();
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdReset))
    {
        add_interupt_event(HW2_INT, 0);  /* Hardware 2 Interrupt immediately */
        add_interupt_event(NMI_INT, 50000000);  /* Non maskable Interrupt after 1/2 second */
    }
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdSpeeddown))
        main_speeddown(5);
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdSpeedup))
        main_speedup(5);
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdScreenshot))
        main_take_next_screenshot();    /* screenshot will be taken at the end of frame rendering */
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdPause))
        main_toggle_pause();
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdMute))
    {
        volumeMute();
        main_draw_volume_osd();
    }
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdIncrease))
    {
        volumeUp();
        main_draw_volume_osd();
    }
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdDecrease))
    {
        volumeDown();
        main_draw_volume_osd();
    }
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdForward))
    {
        main_set_fastforward(1);
    }
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdAdvance))
    {
        main_advance_one();
    }
    else if (keysym == ConfigGetParamInt(g_CoreConfig, kbdGameshark))
    {
        KbdGamesharkPressed = 1;
    }
    else
    {
        /* pass all other keypresses to the input plugin */
        keyDown(keymod, keysym);
    }

}
Example #3
0
void lircCheckInput(void)
{
    struct pollfd lircpoll;
    lircpoll.fd = g_lircfd;
    lircpoll.events = POLLIN;

    if(poll(&lircpoll, 1, 0) > 0)
    {
        char *code;
        char *c;
        int ret;

        if(lirc_nextcode(&code) == 0 && code != NULL)
        {
            while((ret = lirc_code2char(g_config, code, &c)) == 0 && c!=NULL)
            {
                char *c_ind = c;
                while(*c_ind != '\0')
                {
                    *c_ind = toupper(*c_ind);
                    c_ind++;
                }
                DebugMessage(M64MSG_VERBOSE, "LIRC Execing command \"%s\"", c);

                if(strcmp(c, "SAVE") == 0)
                    savestates_job |= SAVESTATE;
                else if(strcmp(c, "LOAD") == 0)
                    savestates_job |= LOADSTATE;
                else if(strcmp(c, "QUIT") == 0)
                    main_stop();
                else if(strcmp(c, "FULLSCREEN") == 0)
                    changeWindow();
                else if(strcmp(c, "MUTE") == 0)
                {
                    volumeMute();
                    main_draw_volume_osd();
                }
                else if(strcmp(c, "VOL+") == 0)
                {
                    volumeUp();
                    main_draw_volume_osd();
                }
                else if(strcmp(c, "VOL-") == 0)
                {
                    volumeDown();
                    main_draw_volume_osd();
                }
                else if(strcmp(c, "SCREENSHOT") == 0)
                    main_take_next_screenshot();
                else if(strcmp(c, "SPEED+") == 0)
                    main_speedup(5);
                else if(strcmp(c, "SPEED-") == 0)
                    main_speeddown(5);
                else if(strcmp(c, "ADVANCE") == 0)
                    main_advance_one();
                else if(strcmp(c, "PAUSE") == 0)
                    main_toggle_pause();
                else
                {
                    int val = ((int)c[0])-((int) '0');
                    if (val >= 0 && val <= 9)
                        savestates_select_slot( val );
                }
            }
            free(code);
        }
    }
}