1 /* libfsemu - a library with emulator support functions
2 * Copyright (C) 2011 Frode Solheim <frode-code@fengestad.no>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or (at
7 * your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <fs/emu.h>
24 #include <fs/emu/actions.h>
25 #include <fs/emu/input.h>
26 #include <fs/emu/render.h>
27 #include <fs/emu/video.h>
28 #include <fs/lazyness.h>
29 #include <fs/glib.h>
30 #include "video.h"
31 #include "libfsemu.h"
32 #include "input.h"
33 #include <stdlib.h>
34
35 static const char* g_taunts[] = {
36 "You play like a dairy farmer!",
37 "No one will ever catch ME playing as badly as you do!",
38 "I once owned a dog that played better then you!",
39 "Never before have I faced someone so sissified.",
40 "You're no match for my skills, you poor fool.",
41 "Go home and be a family man!",
42 "It's good to be the king.",
43 "Your mother was a hamster and your father smelt of elderberries",
44 NULL,
45 };
46 static int g_num_taunts = 8;
47
taunt()48 static void taunt()
49 {
50 char *text = g_strdup_printf(
51 "%c%s\n", 1, g_taunts[g_random_int_range(0, g_num_taunts)]);
52 fs_emu_netplay_say(text);
53 g_free(text);
54 }
55
56 #if 0
57 void fsuae_ppc_pause(int pause);
58 #endif
59
special_function(void)60 static void special_function(void)
61 {
62 fs_log("special action\n");
63 #if 0
64 static int paused = 0;
65 fsuae_ppc_pause(!paused);
66 paused = !paused;
67 #endif
68 }
69
switch_window(void)70 static void switch_window(void)
71 {
72 if (fs_ml_input_grab()) {
73 fs_log("Switch window\n");
74 fs_ml_set_input_grab(false);
75 fs_ml_set_input_grab_on_activate(true);
76 fs_ml_activate_window_switcher();
77 }
78 }
79
fs_emu_handle_libfsemu_action(int action,int state)80 void fs_emu_handle_libfsemu_action(int action, int state)
81 {
82 if (g_fs_log_input)
83 fs_log("fs_emu_handle_libfsemu_action %d %d\n", action, state);
84
85 switch (action) {
86 case FS_EMU_ACTION_FULL_KEYBOARD:
87 if (state) {
88 fs_emu_set_full_keyboard_emulation(
89 !fs_emu_full_keyboard_emulation(), true);
90 }
91 break;
92 case FS_EMU_ACTION_FULLSCREEN:
93 if (state)
94 fs_emu_toggle_fullscreen();
95 break;
96 case FS_EMU_ACTION_GRAB_INPUT:
97 if (state) {
98 if (g_fs_emu_grab_input_on_mod_release) {
99 /* We had grapped the input, but is holding the modifier
100 * key. So we just don't ungrab on release. */
101 g_fs_emu_grab_input_on_mod_release = false;
102 fs_emu_show_cursor_msec(FS_EMU_MOUSE_DEFAULT_DURATION);
103 } else {
104 fs_emu_set_input_grab(!fs_emu_input_grab());
105 }
106 }
107 break;
108 case FS_EMU_ACTION_MENU_ALT:
109 if (state)
110 fs_emu_menu_toggle();
111 break;
112 case FS_EMU_ACTION_PAUSE:
113 if (state)
114 fs_emu_pause(!fs_emu_is_paused());
115 break;
116 case FS_EMU_ACTION_QUIT:
117 if (state)
118 fs_emu_quit();
119 break;
120 case FS_EMU_ACTION_SCREENSHOT:
121 if (state)
122 g_fs_emu_screenshot = 1;
123 break;
124 case FS_EMU_ACTION_SPECIAL:
125 if (state)
126 special_function();
127 break;
128 case FS_EMU_ACTION_SWITCH_WINDOW:
129 if (state)
130 switch_window();
131 break;
132 case FS_EMU_ACTION_TAUNT:
133 if (state)
134 taunt();
135 break;
136 case FS_EMU_ACTION_VOLUME_DOWN:
137 if (state)
138 fs_emu_volume_control(-2);
139 break;
140 case FS_EMU_ACTION_VOLUME_MUTE:
141 if (state)
142 fs_emu_volume_control(-1);
143 break;
144 case FS_EMU_ACTION_VOLUME_UP:
145 if (state)
146 fs_emu_volume_control(-3);
147 break;
148 case FS_EMU_ACTION_WARP:
149 if (state) {
150 /* FIXME: UAE-specific hot key hack for warp function,
151 * should be moved out of libfsemu. */
152 fs_emu_queue_input_event(0x00010000 | 275);
153 }
154 break;
155 case FS_EMU_ACTION_ZOOM:
156 if (state) {
157 fs_emu_toggle_zoom(0);
158 }
159 break;
160 case FS_EMU_ACTION_ZOOM_BORDER:
161 if (state) {
162 fs_emu_toggle_zoom(1);
163 }
164 break;
165 case FSE_ACTION_CYCLE_STRETCH_MODE:
166 if (state) {
167 fse_cycle_stretch_mode();
168 }
169 break;
170 }
171 }
172