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"
25 /* UsrInputType[] is user-specified. InputType[] is current
26 (game loading can override user settings)
28 static int UsrInputType[2]={SI_GAMEPAD,SI_GAMEPAD};
29 static int UsrInputTypeFC={SI_NONE};
31 static int InputType[2];
32 static int InputTypeFC;
34 static uint32 JSreturn;
36 static int powerpadsc[2][12];
37 static int powerpadside=0;
39 static uint32 MouseData[3];
40 static uint8 fkbkeys[0x48];
42 static uint32 combo_acts = 0, combo_keys = 0;
43 static uint32 prev_emu_acts = 0;
46 static void setsoundvol(int soundvolume)
49 static char soundvolmeter[24];
50 static int prev_snd_on = 0;
52 if ((!!soundvolume) ^ prev_snd_on)
54 FCEUI_Sound(Settings.sound_rate);
55 prev_snd_on = !!soundvolume;
59 gp2x_sound_volume(soundvolume, soundvolume);
60 int meterval=soundvolume/5;
61 for (soundvolIndex = 0; soundvolIndex < 20; soundvolIndex++)
63 if (soundvolIndex < meterval)
65 soundvolmeter[soundvolIndex]='*';
69 soundvolmeter[soundvolIndex]='_';
73 FCEU_DispMessage("|%s|", soundvolmeter);
77 static void do_emu_acts(uint32 acts)
80 acts &= acts ^ prev_emu_acts;
81 prev_emu_acts = actsc;
89 if (Settings.sstate_confirm & 2)
91 FCEU_DispMessage("LOAD STATE? (Y=yes, X=no)");
93 FCEUD_Update(XBuf+8,NULL,0);
94 while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
95 if (keys & GP2X_X) do_it = 0;
96 FCEU_CancelDispMessage();
98 if (do_it) FCEUI_LoadState();
102 if (Settings.sstate_confirm & 1)
104 char *fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
105 FILE *st=fopen(fname,"rb");
110 FCEU_DispMessage("OVERWRITE SAVE? (Y=yes, X=no)");
112 FCEUD_Update(XBuf+8,NULL,0);
113 while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
114 if (keys & GP2X_X) do_it = 0;
115 FCEU_CancelDispMessage();
118 if (do_it) FCEUI_SaveState();
120 RefreshThrottleFPS();
122 else if (acts & (3 << 28)) // state slot next/prev
127 CurrentState += (acts & (1 << 29)) ? 1 : -1;
128 if (CurrentState > 9) CurrentState = 0;
129 if (CurrentState < 0) CurrentState = 9;
131 fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
132 st=fopen(fname,"rb");
134 FCEU_DispMessage("[%s] State Slot %i", st ? "USED" : "FREE", CurrentState);
137 else if (acts & (1 << 27)) // FDS insert/eject
139 if(FCEUGameInfo.type == GIT_FDS)
140 FCEU_DoSimpleCommand(FCEUNPCMD_FDSINSERT);
142 else if (acts & (1 << 26)) // FDS select
144 if(FCEUGameInfo.type == GIT_FDS)
145 FCEU_DoSimpleCommand(FCEUNPCMD_FDSSELECT);
147 else if (acts & (1 << 25)) // VS Unisystem insert coin
149 if(FCEUGameInfo.type == GIT_VSUNI)
150 FCEU_DoSimpleCommand(FCEUNPCMD_VSUNICOIN);
155 #define down(b) (keys & GP2X_##b)
156 static void do_fake_mouse(unsigned long keys)
158 static int x=256/2, y=240/2;
161 if (down(A)) speed = 1;
162 if (down(Y)) speed = 5;
169 else if (down(RIGHT))
172 if (x > 255) x = 255;
183 if (y > 239) y = 239;
189 if (down(B)) MouseData[2] |= 1;
190 if (down(X)) MouseData[2] |= 2;
194 static void FCEUD_UpdateInput(void)
196 static int volpushed_frames = 0;
197 static int turbo_rate_cnt_a[2] = {0,0}, turbo_rate_cnt_b[2] = {0,0};
198 unsigned long keys = gp2x_joystick_read(0);
199 uint32 all_acts[2] = {0,0};
202 if ((down(VOL_DOWN) && down(VOL_UP)) || (keys & (GP2X_L|GP2X_START)) == (GP2X_L|GP2X_START))
207 else if (down(VOL_UP))
209 /* wait for at least 10 updates, because user may be just trying to enter menu */
210 if (volpushed_frames++ > 10) {
212 if (soundvol > 100) soundvol=100;
213 //FCEUI_SetSoundVolume(soundvol);
214 setsoundvol(soundvol);
217 else if (down(VOL_DOWN))
219 if (volpushed_frames++ > 10) {
221 if (soundvol < 0) soundvol=0;
222 //FCEUI_SetSoundVolume(soundvol);
223 setsoundvol(soundvol);
228 volpushed_frames = 0;
231 JSreturn = 0; // RLDU SEBA
233 if (InputType[1] != SI_GAMEPAD)
235 /* try to feed fake mouse there */
239 for (i = 0; i < 32; i++)
244 acts = Settings.KeyBinds[i];
246 if ((1 << i) & combo_keys)
248 // combo key detected, try to find if other is pressed
249 for (u = i+1; u < 32; u++)
251 if ((keys & (1 << u)) && (Settings.KeyBinds[u] & acts))
258 if (u != 32) acts &= combo_acts; // other combo key pressed
259 else acts &= ~combo_acts;
260 all_acts[(acts>>16)&1] |= acts;
268 gp2x_usbjoy_update();
269 for (joy = 0; joy < num_of_joys; joy++) {
270 int keys = gp2x_usbjoy_check2(joy);
271 for (i = 0; i < 32; i++) {
272 if (keys & (1 << i)) {
273 int acts = Settings.JoyBinds[joy][i];
274 all_acts[(acts>>16)&1] |= acts;
281 JSreturn |= all_acts[0] & 0xff;
282 if (all_acts[0] & 0x100) { // A turbo
283 turbo_rate_cnt_a[0] += Settings.turbo_rate_add;
284 JSreturn |= (turbo_rate_cnt_a[0] >> 24) & 1;
286 if (all_acts[0] & 0x200) { // B turbo
287 turbo_rate_cnt_b[0] += Settings.turbo_rate_add;
288 JSreturn |= (turbo_rate_cnt_b[0] >> 23) & 2;
292 JSreturn |= (all_acts[1] & 0xff) << 16;
293 if (all_acts[1] & 0x100) { // A turbo
294 turbo_rate_cnt_a[1] += Settings.turbo_rate_add;
295 JSreturn |= (turbo_rate_cnt_a[1] >> 8) & 0x10000;
297 if (all_acts[1] & 0x200) { // B turbo
298 turbo_rate_cnt_b[1] += Settings.turbo_rate_add;
299 JSreturn |= (turbo_rate_cnt_b[1] >> 7) & 0x20000;
302 do_emu_acts(all_acts[0]|all_acts[1]);
306 static void InitOtherInput(void)
315 printf("InitOtherInput: InputType[0]: %i, InputType[1]: %i, InputTypeFC: %i\n",
316 InputType[0], InputType[1], InputTypeFC);
324 //case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break;
325 case SI_GAMEPAD:InputDPtr=((uint8 *)&JSreturn)+(x<<1);break;
326 case SI_ARKANOID:InputDPtr=MouseData;t|=1;break;
327 case SI_ZAPPER:InputDPtr=MouseData;
332 FCEUI_SetInput(x,InputType[x],InputDPtr,attrib);
339 case SIFC_SHADOW:InputDPtr=MouseData;t|=1;attrib=1;break;
340 case SIFC_ARKANOID:InputDPtr=MouseData;t|=1;break;
341 case SIFC_FKB:InputDPtr=fkbkeys;break;
344 FCEUI_SetInputFC(InputTypeFC,InputDPtr,attrib);
345 FCEUI_DisableFourScore(eoptions&EO_NOFOURSCORE);
351 static void PrepareOtherInput(void)
353 uint32 act, key, seen_acts;
355 combo_acts = combo_keys = prev_emu_acts = seen_acts = 0;
358 for (act = 1; act; act <<= 1)
360 for (key = 1; key < 32; key++)
362 if (Settings.KeyBinds[key] & act)
364 if (seen_acts & act) combo_acts |= act;
365 else seen_acts |= act;
370 combo_acts &= ~0x00030000; // don't take player_id bits
373 for (act = 1; act; act <<= 1)
375 for (key = 0; key < 32; key++)
377 if (Settings.KeyBinds[key] & combo_acts)
379 combo_keys |= 1 << key;
384 // printf("generated combo_acts: %08x, combo_keys: %08x\n", combo_acts, combo_keys);