1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define JOY_RIGHT 0x80
32 extern int swapbuttons;
33 extern int scaled_display;
34 extern int FSkip_setting;
36 extern void SetVideoScaling(int pixels,int width,int height);
37 static INLINE long UpdateGamepadGP2X(void);
41 /* UsrInputType[] is user-specified. InputType[] is current
42 (game loading can override user settings)
44 static int UsrInputType[2]={SI_GAMEPAD,SI_GAMEPAD};
45 static int InputType[2];
47 static int UsrInputTypeFC={SI_NONE};
48 static int InputTypeFC;
50 static uint32 JSreturn;
53 static int powerpadsc[2][12];
54 static int powerpadside=0;
57 static uint32 MouseData[3];
58 static uint8 fkbkeys[0x48];
59 unsigned long lastpad=0;
61 void FCEUD_UpdateInput(void)
64 long lastpad2=lastpad;
65 long pad = UpdateGamepadGP2X();
67 // JSreturn=(JSreturn&0xFF000000)|(JSreturn&0xFF)|((JSreturn&0xFF0000)>>8)|((JSreturn&0xFF00)<<8);
71 if ((pad & GP2X_PUSH) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_L)) && (!(pad & GP2X_R)) && (!(lastpad2 & GP2X_PUSH)))
73 DriverInterface(DES_FDSSELECT,0);
75 else if ((pad & GP2X_L) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_PUSH)) && (!(pad & GP2X_R))&& (!(lastpad2 & GP2X_L)))
77 DriverInterface(DES_FDSINSERT,0);
79 else if ((pad & GP2X_R) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_L)) && (!(pad & GP2X_PUSH)) && (!(lastpad2 & GP2X_R)))
81 DriverInterface(DES_FDSEJECT,0);
90 extern void ResetNES(void);
91 extern void CleanSurface(void);
93 char soundvolmeter[21];
97 extern int CurrentState;
99 int TurboFireTop=0; // 0 is none // 1 is A & X turbo // 2 is Y & B turbo
100 int TurboFireBottom=0;
101 int turbo_toggle_A=0;
102 int turbo_toggle_B=0;
104 static void setsoundvol(int soundvolume)
106 //FCEUI_SetSoundVolume(soundvol);
108 gp2x_sound_volume(soundvolume, soundvolume);
109 int meterval=soundvolume/5;
110 for (soundvolIndex=0; soundvolIndex < 20; soundvolIndex++)
112 if (soundvolIndex < meterval)
114 soundvolmeter[soundvolIndex]='*';
118 soundvolmeter[soundvolIndex]='_';
122 FCEU_DispMessage("|%s|", soundvolmeter);
125 * GP2x joystick reader
128 static INLINE long UpdateGamepadGP2X(void)
132 unsigned long pad=gp2x_joystick_read();
133 #define down(b) (pad & GP2X_##b)
134 #define last_down(b) (lastpad & GP2X_##b)
135 #define L_down (pad & GP2X_L)
136 #define R_down (pad & GP2X_R)
137 #define last_L_down (lastpad & GP2X_L)
138 #define last_R_down (lastpad & GP2X_R)
139 #define shift ((pad & GP2X_PUSH) || ((pad & (GP2X_VOL_UP|GP2X_VOL_DOWN)) == (GP2X_VOL_UP|GP2X_VOL_DOWN)))
140 #define last_shift ((lastpad & GP2X_PUSH) || ((lastpad & (GP2X_VOL_UP|GP2X_VOL_DOWN)) == (GP2X_VOL_UP|GP2X_VOL_DOWN)))
142 if (L_down && R_down && !(pad & GP2X_PUSH) && !(last_R_down && last_L_down))
149 if (down(VOL_UP) && !down(VOL_DOWN))
152 if (soundvol >= 100) soundvol=100;
153 //FCEUI_SetSoundVolume(soundvol);
154 setsoundvol(soundvol);
156 else if (down(VOL_DOWN) && !down(VOL_UP))
159 if (soundvol < 0) soundvol=0;
160 //FCEUI_SetSoundVolume(soundvol);
161 setsoundvol(soundvol);
166 // only if it's something else then last time, and not moving around the joystick
167 if (!(pad & (GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT)))
171 if (last_down(SELECT) && last_shift)
173 // still pressed down from stretching from last one
176 scaled_display = !scaled_display;
180 SetVideoScaling(320, 256, 240);
184 SetVideoScaling(320, 320, 240);
189 else if (L_down && R_down)
195 else if (R_down && !(last_R_down && last_shift))
200 else if (L_down && !(last_L_down && last_shift))
205 else if (down(A) && !(last_down(A) && last_shift))
208 if (FSkip_setting < 0) {
210 FCEUI_DispMessage("Auto frameskip");
213 FCEUI_DispMessage("Frameskip: %i", FSkip_setting);
216 else if (down(Y) && !(last_down(Y) && last_shift))
219 if (FSkip_setting > 8) FSkip_setting = 8;
220 FCEUI_DispMessage("Frameskip: %i", FSkip_setting);
226 // r is toggle savestate
232 if ((R_count & 31)== 31)
234 CurrentState=(CurrentState+1) % 10;
235 FCEUI_DispMessage("Now Using Save State %d", CurrentState);
250 if ((L_count & 31)== 31)
252 // 0 is none // 1 is Y & B turbo // 2 is X & A turbo
253 if ((!TurboFireTop) && (!TurboFireBottom))
260 FCEUI_DispMessage("Turbo A and Y");
264 FCEUI_DispMessage("Turbo Y and B");
267 else if (TurboFireTop)
273 FCEUI_DispMessage("Turbo X and B");
277 FCEUI_DispMessage("Turbo A and X");
284 FCEUI_DispMessage("Turbo Off");
295 //unsigned long padTmp=0;
298 //padTmp=(pad & GP2X_UP) ; // 1 is 2^0,
299 JS |= ((pad & GP2X_UP) << (4-0)); // 0x10 is 2^4
301 //padTmp=(pad & GP2X_DOWN); // 0x10 is 2^4,
302 JS |= ((pad & GP2X_DOWN) << (5-4)); // 0x20 is 2^5
304 //padTmp=(pad & GP2X_LEFT); // 0x4 is 2^2,
305 JS |= ((pad & GP2X_LEFT) << (6-2)); // 0x40 is 2^6
307 //padTmp=(pad & GP2X_RIGHT); // 0x40 is 2^6,
308 JS |= ((pad & GP2X_RIGHT) << (7-6)); // 0x80 is 2^7
311 #define A_down (pad & GP2X_A)
312 #define B_down (pad & GP2X_B)
313 #define X_down (pad & GP2X_X)
314 #define Y_down (pad & GP2X_Y)
316 // should be 2 cycles held, 1 cycle release
317 turbo_toggle_A=(turbo_toggle_A+1) % 3;
318 turbo_toggle_B=(turbo_toggle_B+1) % 3;
320 // 0 is none // 1 is Y & B turbo // 2 is X & A turbo
321 // B or X are both considered A
322 //padTmp=B_down >> 13; // 2^13,
324 if (!(TurboFireTop && (!turbo_toggle_A)))
326 JS |= ((B_down >> 13) << 0); // 0x1 is 2^0
328 // A or Y are both considered B
329 //padTmp=A_down >> 12; // 2^13,
330 if (!(TurboFireBottom && (!turbo_toggle_B)))
332 JS |= ((A_down >> 12) << 1); // 0x2 is 2^1
337 //padTmp=X_down >> 14; // 2^13,
338 if (!(TurboFireBottom && (!turbo_toggle_A)))
340 // JS |= ((X_down >> 14) << 0); // 0x1 is 2^0
341 JS |= ((Y_down >> 15) << 0); // 0x1 is 2^0
344 //padTmp=Y_down >> 15; // 2^13,
345 if (!(TurboFireTop && (!turbo_toggle_B)))
347 JS |= ((X_down >> 14) << 1); // 0x2 is 2^1
352 //padTmp=X_down >> 14; // 2^13,
353 if (!(TurboFireBottom && (!turbo_toggle_A)))
355 JS |= ((X_down >> 14) << 0); // 0x1 is 2^0
358 //padTmp=Y_down >> 15; // 2^13,
359 if (!(TurboFireTop && (!turbo_toggle_B)))
361 JS |= ((Y_down >> 15) << 1); // 0x2 is 2^1
366 //padTmp=(pad & GP2X_SELECT) >> 9; // 0x40 is 2^9,
367 JS |= (((pad & GP2X_SELECT) >> 9) << 2); // 0x4 is 2^2
370 //padTmp=(pad & GP2X_START) >> 8; // 2^8,
371 JS |= (((pad & GP2X_START) >> 8) << 3); // 0x8 is 2^3
378 //JSreturn=(JS&0xFF000000)|(JS&0xFF)|((JS&0xFF0000)>>8)|((JS&0xFF00)<<8);
387 static void InitOtherInput(void)
402 //case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break;
403 case SI_GAMEPAD:InputDPtr=((uint8 *)&JSreturn)+(x<<1);break;
404 case SI_ARKANOID:InputDPtr=MouseData;t|=1;break;
405 case SI_ZAPPER:InputDPtr=MouseData;
410 FCEUI_SetInput(x,InputType[x],InputDPtr,attrib);
417 case SIFC_SHADOW:InputDPtr=MouseData;t|=1;attrib=1;break;
418 case SIFC_ARKANOID:InputDPtr=MouseData;t|=1;break;
419 case SIFC_FKB:InputDPtr=fkbkeys;break;
422 FCEUI_SetInputFC(InputTypeFC,InputDPtr,attrib);
423 FCEUI_DisableFourScore(eoptions&EO_NOFOURSCORE);
425 if(t && !(inited&16))