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"
27 /* UsrInputType[] is user-specified. InputType[] is current
28 (game loading can override user settings)
30 static int UsrInputType[2]={SI_GAMEPAD,SI_GAMEPAD};
31 static int UsrInputTypeFC={SI_NONE};
33 static int InputType[2];
34 static int InputTypeFC;
36 static uint32 JSreturn;
38 static int powerpadsc[2][12];
39 static int powerpadside=0;
41 static uint32 MouseData[3];
42 static uint8 fkbkeys[0x48];
44 static uint32 combo_acts = 0, combo_keys = 0;
45 static uint32 prev_emu_acts = 0;
48 static void setsoundvol(int soundvolume)
51 static char soundvolmeter[24];
54 gp2x_sound_volume(soundvolume, soundvolume);
55 int meterval=soundvolume/5;
56 for (soundvolIndex = 0; soundvolIndex < 20; soundvolIndex++)
58 if (soundvolIndex < meterval)
60 soundvolmeter[soundvolIndex]='*';
64 soundvolmeter[soundvolIndex]='_';
68 FCEU_DispMessage("|%s|", soundvolmeter);
72 static void do_emu_acts(uint32 acts)
75 acts &= acts ^ prev_emu_acts;
76 prev_emu_acts = actsc;
84 if (Settings.sstate_confirm & 2)
86 FCEU_DispMessage("LOAD STATE? (Y=yes, X=no)");
88 FCEUD_Update(XBuf+8,NULL,0);
89 while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
90 if (keys & GP2X_X) do_it = 0;
93 if (do_it) FCEUI_LoadState();
97 if (Settings.sstate_confirm & 1)
99 char *fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
100 FILE *st=fopen(fname,"rb");
105 FCEU_DispMessage("OVERWRITE SAVE? (Y=yes, X=no)");
107 FCEUD_Update(XBuf+8,NULL,0);
108 while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
109 if (keys & GP2X_X) do_it = 0;
110 FCEU_DispMessage("");
113 if (do_it) FCEUI_SaveState();
115 RefreshThrottleFPS();
117 else if (acts & (3 << 28)) // state slot next/prev
122 CurrentState += (acts & (1 << 29)) ? 1 : -1;
123 if (CurrentState > 9) CurrentState = 0;
124 if (CurrentState < 0) CurrentState = 9;
126 fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
127 st=fopen(fname,"rb");
129 FCEU_DispMessage("[%s] State Slot %i", st ? "USED" : "FREE", CurrentState);
132 else if (acts & (1 << 27)) // FDS insert/eject
134 if(FCEUGameInfo.type == GIT_FDS)
135 FCEU_DoSimpleCommand(FCEUNPCMD_FDSINSERT);
137 else if (acts & (1 << 26)) // FDS select
139 if(FCEUGameInfo.type == GIT_FDS)
140 FCEU_DoSimpleCommand(FCEUNPCMD_FDSSELECT);
142 else if (acts & (1 << 25)) // VS Unisystem insert coin
144 if(FCEUGameInfo.type == GIT_VSUNI)
145 FCEU_DoSimpleCommand(FCEUNPCMD_VSUNICOIN);
150 #define down(b) (keys & GP2X_##b)
151 static void do_fake_mouse(unsigned long keys)
153 static int x=256/2, y=240/2;
156 if (down(A)) speed = 1;
157 if (down(Y)) speed = 5;
164 else if (down(RIGHT))
167 if (x > 255) x = 255;
178 if (y > 239) y = 239;
184 if (down(B)) MouseData[2] |= 1;
185 if (down(X)) MouseData[2] |= 2;
189 static void FCEUD_UpdateInput(void)
191 static int volpushed_frames = 0;
192 static int turbo_rate_cnt_a[2] = {0,0}, turbo_rate_cnt_b[2] = {0,0};
193 unsigned long keys = gp2x_joystick_read(0);
194 uint32 all_acts[2] = {0,0};
197 if ((down(VOL_DOWN) && down(VOL_UP)) || (keys & (GP2X_L|GP2X_L|GP2X_START)) == (GP2X_L|GP2X_L|GP2X_START))
200 FSkip = 0; /* force rendering the last frame for menu */
203 else if (down(VOL_UP))
205 /* wait for at least 10 updates, because user may be just trying to enter menu */
206 if (volpushed_frames++ > 10) {
208 if (soundvol > 100) soundvol=100;
209 //FCEUI_SetSoundVolume(soundvol);
210 setsoundvol(soundvol);
213 else if (down(VOL_DOWN))
215 if (volpushed_frames++ > 10) {
217 if (soundvol < 0) soundvol=0;
218 //FCEUI_SetSoundVolume(soundvol);
219 setsoundvol(soundvol);
224 volpushed_frames = 0;
227 JSreturn = 0; // RLDU SEBA
229 if (InputType[1] != SI_GAMEPAD)
231 /* try to feed fake mouse there */
235 for (i = 0; i < 32; i++)
240 acts = Settings.KeyBinds[i];
242 if ((1 << i) & combo_keys)
244 // combo key detected, try to find if other is pressed
245 for (u = i+1; u < 32; u++)
247 if ((keys & (1 << u)) && (Settings.KeyBinds[u] & acts))
254 if (u != 32) acts &= combo_acts; // other combo key pressed
255 else acts &= ~combo_acts;
256 all_acts[(acts>>16)&1] |= acts;
264 gp2x_usbjoy_update();
265 for (joy = 0; joy < num_of_joys; joy++) {
266 int keys = gp2x_usbjoy_check2(joy);
267 for (i = 0; i < 32; i++) {
268 if (keys & (1 << i)) {
269 int acts = Settings.JoyBinds[joy][i];
270 all_acts[(acts>>16)&1] |= acts;
277 JSreturn |= all_acts[0] & 0xff;
278 if (all_acts[0] & 0x100) { // A turbo
279 turbo_rate_cnt_a[0] += Settings.turbo_rate_add;
280 JSreturn |= (turbo_rate_cnt_a[0] >> 24) & 1;
282 if (all_acts[0] & 0x200) { // B turbo
283 turbo_rate_cnt_b[0] += Settings.turbo_rate_add;
284 JSreturn |= (turbo_rate_cnt_b[0] >> 23) & 2;
288 JSreturn |= (all_acts[1] & 0xff) << 16;
289 if (all_acts[1] & 0x100) { // A turbo
290 turbo_rate_cnt_a[1] += Settings.turbo_rate_add;
291 JSreturn |= (turbo_rate_cnt_a[1] >> 8) & 0x10000;
293 if (all_acts[1] & 0x200) { // B turbo
294 turbo_rate_cnt_b[1] += Settings.turbo_rate_add;
295 JSreturn |= (turbo_rate_cnt_b[1] >> 7) & 0x20000;
298 do_emu_acts(all_acts[0]|all_acts[1]);
302 static void InitOtherInput(void)
311 printf("InitOtherInput: InputType[0]: %i, InputType[1]: %i, InputTypeFC: %i\n",
312 InputType[0], InputType[1], InputTypeFC);
320 //case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break;
321 case SI_GAMEPAD:InputDPtr=((uint8 *)&JSreturn)+(x<<1);break;
322 case SI_ARKANOID:InputDPtr=MouseData;t|=1;break;
323 case SI_ZAPPER:InputDPtr=MouseData;
328 FCEUI_SetInput(x,InputType[x],InputDPtr,attrib);
335 case SIFC_SHADOW:InputDPtr=MouseData;t|=1;attrib=1;break;
336 case SIFC_ARKANOID:InputDPtr=MouseData;t|=1;break;
337 case SIFC_FKB:InputDPtr=fkbkeys;break;
340 FCEUI_SetInputFC(InputTypeFC,InputDPtr,attrib);
341 FCEUI_DisableFourScore(eoptions&EO_NOFOURSCORE);
347 static void PrepareOtherInput(void)
349 uint32 act, key, seen_acts;
351 combo_acts = combo_keys = prev_emu_acts = seen_acts = 0;
354 for (act = 1; act; act <<= 1)
356 for (key = 1; key < 32; key++)
358 if (Settings.KeyBinds[key] & act)
360 if (seen_acts & act) combo_acts |= act;
361 else seen_acts |= act;
366 combo_acts &= ~0x00030000; // don't take player_id bits
369 for (act = 1; act; act <<= 1)
371 for (key = 0; key < 32; key++)
373 if (Settings.KeyBinds[key] & combo_acts)
375 combo_keys |= 1 << key;
380 // printf("generated combo_acts: %08x, combo_keys: %08x\n", combo_acts, combo_keys);