Search
lxdream.org :: lxdream/src/hotkeys.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/hotkeys.c
changeset 1038:f220d18c0615
prev1024:c67f2d61ab97
next1072:d82e04e6d497
author nkeynes
date Thu Jun 25 01:15:25 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Move configuration to .lxdream/lxdreamrc on *nix, Library/Application Support/Lxdream on OS X
Create standard directories on first run
Add current quick state to config file
Refactor quick-state handling into dreamcast.c, and use the save directory
file annotate diff log raw
nkeynes@1015
     1
/**
nkeynes@1015
     2
 * $Id:  $
nkeynes@1015
     3
 *
nkeynes@1015
     4
 * Handles hotkeys for pause/continue, save states, quit, etc
nkeynes@1015
     5
 *
nkeynes@1015
     6
 * Copyright (c) 2009 wahrhaft
nkeynes@1015
     7
 *
nkeynes@1015
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@1015
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@1015
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@1015
    11
 * (at your option) any later version.
nkeynes@1015
    12
 *
nkeynes@1015
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@1015
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1015
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@1015
    16
 * GNU General Public License for more details.
nkeynes@1015
    17
 */
nkeynes@1015
    18
#include <assert.h>
nkeynes@1015
    19
#include <glib.h>
nkeynes@1015
    20
#include <sys/stat.h>
nkeynes@1015
    21
#include <stdint.h>
nkeynes@1015
    22
#include <stdlib.h>
nkeynes@1015
    23
#include "lxdream.h"
nkeynes@1015
    24
#include "dreamcast.h"
nkeynes@1015
    25
#include "display.h"
nkeynes@1015
    26
#include "hotkeys.h"
nkeynes@1015
    27
#include "gui.h"
nkeynes@1015
    28
#include "config.h"
nkeynes@1015
    29
nkeynes@1015
    30
static void hotkey_resume_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    31
static void hotkey_stop_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    32
static void hotkey_reset_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    33
static void hotkey_exit_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    34
static void hotkey_state_select_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    35
static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    36
static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    37
nkeynes@1015
    38
nkeynes@1015
    39
struct lxdream_config_entry hotkeys_config[] = {
nkeynes@1015
    40
        {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY},
nkeynes@1015
    41
        {"stop", N_("Stop emulation"), CONFIG_TYPE_KEY},
nkeynes@1015
    42
        {"reset", N_("Reset emulator"), CONFIG_TYPE_KEY},
nkeynes@1015
    43
        {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY},
nkeynes@1015
    44
        {"save", N_("Save current quick save"), CONFIG_TYPE_KEY},
nkeynes@1015
    45
        {"load", N_("Load current quick save"), CONFIG_TYPE_KEY},
nkeynes@1038
    46
        {"state0", N_("Select quick save state 0"), CONFIG_TYPE_KEY},
nkeynes@1015
    47
        {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY},
nkeynes@1015
    48
        {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY},
nkeynes@1015
    49
        {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY},
nkeynes@1015
    50
        {"state4", N_("Select quick save state 4"), CONFIG_TYPE_KEY},
nkeynes@1015
    51
        {"state5", N_("Select quick save state 5"), CONFIG_TYPE_KEY},
nkeynes@1015
    52
        {"state6", N_("Select quick save state 6"), CONFIG_TYPE_KEY},
nkeynes@1015
    53
        {"state7", N_("Select quick save state 7"), CONFIG_TYPE_KEY},
nkeynes@1015
    54
        {"state8", N_("Select quick save state 8"), CONFIG_TYPE_KEY},
nkeynes@1015
    55
        {"state9", N_("Select quick save state 9"), CONFIG_TYPE_KEY},
nkeynes@1015
    56
        {NULL, CONFIG_TYPE_NONE}
nkeynes@1015
    57
};
nkeynes@1015
    58
nkeynes@1038
    59
void hotkeys_init() 
nkeynes@1038
    60
{
nkeynes@1015
    61
    hotkeys_register_keys();
nkeynes@1015
    62
}
nkeynes@1015
    63
nkeynes@1015
    64
void hotkeys_register_keys()
nkeynes@1015
    65
{
nkeynes@1015
    66
    input_register_key(hotkeys_config[0].value, &hotkey_resume_callback, NULL, 0);
nkeynes@1015
    67
    input_register_key(hotkeys_config[1].value, &hotkey_stop_callback, NULL, 0);
nkeynes@1015
    68
    input_register_key(hotkeys_config[2].value, &hotkey_reset_callback, NULL, 0);
nkeynes@1015
    69
    input_register_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
nkeynes@1015
    70
    input_register_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
nkeynes@1015
    71
    input_register_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
nkeynes@1038
    72
    for (int i = 0; i < 10; i++)
nkeynes@1015
    73
    {
nkeynes@1015
    74
        input_register_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
nkeynes@1015
    75
    }
nkeynes@1015
    76
}
nkeynes@1015
    77
nkeynes@1015
    78
void hotkeys_unregister_keys()
nkeynes@1015
    79
{
nkeynes@1015
    80
    input_unregister_key(hotkeys_config[0].value, &hotkey_resume_callback, NULL, 0);
nkeynes@1015
    81
    input_unregister_key(hotkeys_config[1].value, &hotkey_stop_callback, NULL, 0);
nkeynes@1015
    82
    input_unregister_key(hotkeys_config[2].value, &hotkey_reset_callback, NULL, 0);
nkeynes@1015
    83
    input_unregister_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
nkeynes@1015
    84
    input_unregister_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
nkeynes@1015
    85
    input_unregister_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
nkeynes@1038
    86
    for (int i = 0; i < 10; i++)
nkeynes@1015
    87
    {
nkeynes@1015
    88
        input_unregister_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
nkeynes@1015
    89
    }
nkeynes@1015
    90
}
nkeynes@1015
    91
nkeynes@1015
    92
lxdream_config_entry_t hotkeys_get_config()
nkeynes@1015
    93
{
nkeynes@1015
    94
    return hotkeys_config;
nkeynes@1015
    95
}
nkeynes@1015
    96
nkeynes@1015
    97
nkeynes@1015
    98
static void hotkey_resume_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1015
    99
{
nkeynes@1015
   100
    if (isKeyDown && !dreamcast_is_running() ) {
nkeynes@1019
   101
        gui_do_later(dreamcast_run);
nkeynes@1015
   102
    }
nkeynes@1015
   103
}
nkeynes@1015
   104
nkeynes@1015
   105
static void hotkey_stop_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1015
   106
{
nkeynes@1015
   107
    if (isKeyDown && dreamcast_is_running() ) {
nkeynes@1019
   108
        gui_do_later(dreamcast_stop);
nkeynes@1015
   109
    }
nkeynes@1015
   110
}
nkeynes@1015
   111
nkeynes@1015
   112
static void hotkey_reset_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1015
   113
{
nkeynes@1015
   114
    if (isKeyDown) {
nkeynes@1015
   115
        dreamcast_reset();
nkeynes@1015
   116
    }
nkeynes@1015
   117
}
nkeynes@1015
   118
nkeynes@1015
   119
static void hotkey_exit_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1015
   120
{
nkeynes@1015
   121
    if (isKeyDown) {
nkeynes@1015
   122
        dreamcast_shutdown();
nkeynes@1015
   123
    }
nkeynes@1015
   124
    exit(0);
nkeynes@1015
   125
}
nkeynes@1015
   126
nkeynes@1015
   127
static void hotkey_state_select_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1015
   128
{
nkeynes@1015
   129
    if (isKeyDown) {
nkeynes@1038
   130
        dreamcast_set_quick_state(value);
nkeynes@1015
   131
    }
nkeynes@1015
   132
}
nkeynes@1015
   133
nkeynes@1015
   134
static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1015
   135
{
nkeynes@1015
   136
    if (isKeyDown) {
nkeynes@1038
   137
        dreamcast_quick_save();
nkeynes@1015
   138
    }
nkeynes@1015
   139
}
nkeynes@1015
   140
nkeynes@1015
   141
static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1015
   142
{
nkeynes@1015
   143
    if (isKeyDown) {
nkeynes@1038
   144
        dreamcast_quick_load();
nkeynes@1015
   145
    }
nkeynes@1015
   146
}
nkeynes@1015
   147
nkeynes@1015
   148
.