1 /* FCE Ultra - NES/Famicom Emulator
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "../../state.h"
19 #include "../../general.h"
20 #include "../../input.h"
21 #include "../../svga.h"
22 #include "../../video.h"
23 #include "../libpicofe/input.h"
26 /* UsrInputType[] is user-specified. InputType[] is current
27 (game loading can override user settings)
29 static int UsrInputType[2]={SI_GAMEPAD,SI_GAMEPAD};
30 static int UsrInputTypeFC={SI_NONE};
32 static int InputType[2];
33 static int InputTypeFC;
35 static uint32 JSreturn;
37 static int powerpadsc[2][12];
38 static int powerpadside=0;
40 static uint32 MouseData[3];
41 static uint8 fkbkeys[0x48];
43 static uint32 combo_acts = 0, combo_keys = 0;
44 static uint32 prev_emu_acts = 0;
47 static void setsoundvol(int soundvolume)
50 static char soundvolmeter[24];
51 static int prev_snd_on = 0;
53 if ((!!soundvolume) ^ prev_snd_on)
55 FCEUI_Sound(Settings.sound_rate);
56 prev_snd_on = !!soundvolume;
59 platform_set_volume(soundvolume);
62 int meterval=soundvolume/5;
63 for (soundvolIndex = 0; soundvolIndex < 20; soundvolIndex++)
65 if (soundvolIndex < meterval)
67 soundvolmeter[soundvolIndex]='*';
71 soundvolmeter[soundvolIndex]='_';
75 FCEU_DispMessage("|%s|", soundvolmeter);
79 static void do_emu_acts(uint32 acts)
82 acts &= acts ^ prev_emu_acts;
83 prev_emu_acts = actsc;
85 if (acts & (EACT_SAVE_STATE | EACT_LOAD_STATE))
93 if (acts & EACT_LOAD_STATE)
95 if (Settings.sstate_confirm & 2)
102 if (Settings.sstate_confirm & 1)
104 char *fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
105 FILE *st = fopen(fname, "rb");
116 strcpy(tmp, (acts & EACT_LOAD_STATE) ?
117 "LOAD STATE?" : "OVERWRITE SAVE?");
119 nm = in_get_key_name(-1, -PBTN_MA3);
120 snprintf(tmp + len, sizeof(tmp) - len, "(%s=yes, ", nm);
122 nm = in_get_key_name(-1, -PBTN_MBACK);
123 snprintf(tmp + len, sizeof(tmp) - len, "%s=no)", nm);
125 FCEU_DispMessage(tmp);
127 FCEUD_Update(XBuf+8, NULL, 0);
129 in_set_config_int(0, IN_CFG_BLOCKING, 1);
130 while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))
132 while ( !((keys = in_menu_wait_any(NULL, 50)) & (PBTN_MA3|PBTN_MBACK)) )
134 if (keys & PBTN_MBACK)
136 while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))
138 in_set_config_int(0, IN_CFG_BLOCKING, 0);
140 FCEU_CancelDispMessage();
143 if (acts & EACT_LOAD_STATE)
149 RefreshThrottleFPS();
151 else if (acts & (EACT_NEXT_SLOT|EACT_PREV_SLOT))
156 CurrentState += (acts & EACT_NEXT_SLOT) ? 1 : -1;
157 if (CurrentState > 9) CurrentState = 0;
158 if (CurrentState < 0) CurrentState = 9;
160 fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
161 st=fopen(fname,"rb");
163 FCEU_DispMessage("[%s] State Slot %i", st ? "USED" : "FREE", CurrentState);
166 else if (acts & EACT_FDS_INSERT)
168 if(FCEUGameInfo.type == GIT_FDS)
169 FCEU_DoSimpleCommand(FCEUNPCMD_FDSINSERT);
171 else if (acts & EACT_FDS_SELECT)
173 if(FCEUGameInfo.type == GIT_FDS)
174 FCEU_DoSimpleCommand(FCEUNPCMD_FDSSELECT);
176 else if (acts & EACT_INSERT_COIN)
178 if(FCEUGameInfo.type == GIT_VSUNI)
179 FCEU_DoSimpleCommand(FCEUNPCMD_VSUNICOIN);
184 static void do_fake_mouse(uint32 acts)
186 static int x=256/2, y=240/2;
189 if (acts & NKEY_B_TURBO) speed = 1;
190 if (acts & NKEY_A_TURBO) speed = 5;
192 if (acts & NKEY_LEFT)
197 else if (acts & NKEY_RIGHT)
200 if (x > 255) x = 255;
208 else if (acts & NKEY_DOWN)
211 if (y > 239) y = 239;
217 if (acts & NKEY_A) MouseData[2] |= 1;
218 if (acts & NKEY_B) MouseData[2] |= 2;
222 static void FCEUD_UpdateInput(void)
224 static int volpushed_frames = 0;
225 static int turbo_rate_cnt_a[2] = {0,0}, turbo_rate_cnt_b[2] = {0,0};
226 uint32 all_acts[2], emu_acts;
227 int actions[IN_BINDTYPE_COUNT] = { 0, };
230 all_acts[0] = actions[IN_BINDTYPE_PLAYER12];
231 all_acts[1] = actions[IN_BINDTYPE_PLAYER12] >> 16;
232 emu_acts = actions[IN_BINDTYPE_EMU];
234 if (emu_acts & EACT_ENTER_MENU)
239 else if (emu_acts & EACT_VOLUME_UP)
241 /* wait for at least 10 updates, because user may be just trying to enter menu */
242 if (volpushed_frames++ > 10 && (volpushed_frames&1)) {
244 if (soundvol > 100) soundvol=100;
245 //FCEUI_SetSoundVolume(soundvol);
246 setsoundvol(soundvol);
249 else if (emu_acts & EACT_VOLUME_DOWN)
251 if (volpushed_frames++ > 10 && (volpushed_frames&1)) {
253 if (soundvol < 0) soundvol=0;
254 //FCEUI_SetSoundVolume(soundvol);
255 setsoundvol(soundvol);
260 volpushed_frames = 0;
263 JSreturn = 0; // RLDU SEBA
265 if (InputType[1] != SI_GAMEPAD)
267 /* try to feed fake mouse there */
268 do_fake_mouse(all_acts[0]);
272 JSreturn |= all_acts[0] & 0xff;
273 if (all_acts[0] & NKEY_A_TURBO) {
274 turbo_rate_cnt_a[0] += Settings.turbo_rate_add;
275 JSreturn |= (turbo_rate_cnt_a[0] >> 24) & 1;
277 if (all_acts[0] & NKEY_B_TURBO) {
278 turbo_rate_cnt_b[0] += Settings.turbo_rate_add;
279 JSreturn |= (turbo_rate_cnt_b[0] >> 23) & 2;
283 JSreturn |= (all_acts[1] & 0xff) << 16;
284 if (all_acts[1] & NKEY_A_TURBO) {
285 turbo_rate_cnt_a[1] += Settings.turbo_rate_add;
286 JSreturn |= (turbo_rate_cnt_a[1] >> 8) & 0x10000;
288 if (all_acts[1] & NKEY_B_TURBO) {
289 turbo_rate_cnt_b[1] += Settings.turbo_rate_add;
290 JSreturn |= (turbo_rate_cnt_b[1] >> 7) & 0x20000;
293 do_emu_acts(emu_acts);
297 static void InitOtherInput(void)
306 printf("InitOtherInput: InputType[0]: %i, InputType[1]: %i, InputTypeFC: %i\n",
307 InputType[0], InputType[1], InputTypeFC);
315 //case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break;
316 case SI_GAMEPAD:InputDPtr=((uint8 *)&JSreturn)+(x<<1);break;
317 case SI_ARKANOID:InputDPtr=MouseData;t|=1;break;
318 case SI_ZAPPER:InputDPtr=MouseData;
323 FCEUI_SetInput(x,InputType[x],InputDPtr,attrib);
330 case SIFC_SHADOW:InputDPtr=MouseData;t|=1;attrib=1;break;
331 case SIFC_ARKANOID:InputDPtr=MouseData;t|=1;break;
332 case SIFC_FKB:InputDPtr=fkbkeys;break;
335 FCEUI_SetInputFC(InputTypeFC,InputDPtr,attrib);
336 FCEUI_DisableFourScore(eoptions&EO_NOFOURSCORE);
342 static void PrepareOtherInput(void)
346 combo_acts = combo_keys = prev_emu_acts = 0;
348 for (act = 0; act < 32; act++)
350 int u, keyc = 0, keyc2 = 0;
351 if (act == 16 || act == 17) continue; // player2 flag
354 for (u = 0; u < 32; u++)
355 if (Settings.KeyBinds[u] & (1 << act)) keyc++;
359 for (u = 0; u < 32; u++)
360 if ((Settings.KeyBinds[u] & 0x30000) == 0 && // pl. 1
361 (Settings.KeyBinds[u] & (1 << act))) keyc++;
362 for (u = 0; u < 32; u++)
363 if ((Settings.KeyBinds[u] & 0x30000) == 1 && // pl. 2
364 (Settings.KeyBinds[u] & (1 << act))) keyc2++;
365 if (keyc2 > keyc) keyc = keyc2;
369 // loop again and mark those keys and actions as combo
370 for (u = 0; u < 32; u++)
372 if (Settings.KeyBinds[u] & (1 << act)) {
373 combo_keys |= 1 << u;
374 combo_acts |= 1 << act;
380 // printf("generated combo_acts: %08x, combo_keys: %08x\n", combo_acts, combo_keys);
384 char *GetKeyboard(void)
386 static char dummy[256];