more opt. in sound.c, vol incresed
[fceu.git] / drivers / gp2x / input.c
CommitLineData
35868d35 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
5 *
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.
10 *
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.
15 *
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
19 */
20
21#define JOY_A 1
22#define JOY_B 2
23#define JOY_SELECT 4
24#define JOY_START 8
25#define JOY_UP 0x10
26#define JOY_DOWN 0x20
27#define JOY_LEFT 0x40
28#define JOY_RIGHT 0x80
29
35868d35 30#include "minimal.h"
13624c8f 31
b2b95d2e 32extern uint8 Exit; // exit emu loop
13624c8f 33
35868d35 34
35/* UsrInputType[] is user-specified. InputType[] is current
36 (game loading can override user settings)
37*/
38static int UsrInputType[2]={SI_GAMEPAD,SI_GAMEPAD};
39static int InputType[2];
40
41static int UsrInputTypeFC={SI_NONE};
42static int InputTypeFC;
43
44static uint32 JSreturn;
45int NoWaiting=0;
46
47static int powerpadsc[2][12];
48static int powerpadside=0;
49
50
51static uint32 MouseData[3];
52static uint8 fkbkeys[0x48];
53unsigned long lastpad=0;
54
35868d35 55char soundvolmeter[21];
56int soundvolIndex=0;
35868d35 57
13624c8f 58
35868d35 59static void setsoundvol(int soundvolume)
60{
61 //FCEUI_SetSoundVolume(soundvol);
62 // draw on screen :D
63 gp2x_sound_volume(soundvolume, soundvolume);
64 int meterval=soundvolume/5;
65 for (soundvolIndex=0; soundvolIndex < 20; soundvolIndex++)
66 {
67 if (soundvolIndex < meterval)
68 {
69 soundvolmeter[soundvolIndex]='*';
70 }
71 else
72 {
73 soundvolmeter[soundvolIndex]='_';
74 }
75 }
76 soundvolmeter[20]=0;
77 FCEU_DispMessage("|%s|", soundvolmeter);
78}
13624c8f 79
80
81
82void FCEUD_UpdateInput(void)
35868d35 83{
b547bda7 84 static int volpushed_frames = 0;
989672f4 85 static int turbo_rate_cnt_a = 0, turbo_rate_cnt_b = 0;
b547bda7 86 long lastpad2 = lastpad;
87 unsigned long keys = gp2x_joystick_read(0);
88 uint32 JS = 0; // RLDU SEBA
89 int i;
90
91 #define down(b) (keys & GP2X_##b)
92 if ((down(VOL_DOWN) && down(VOL_UP)) || (keys & (GP2X_L|GP2X_L|GP2X_START)) == (GP2X_L|GP2X_L|GP2X_START))
35868d35 93 {
b547bda7 94 Exit = 1;
95 JSreturn = 0;
96 return;
35868d35 97 }
b547bda7 98 else if (down(VOL_UP))
35868d35 99 {
b547bda7 100 /* wait for at least 10 updates, because user may be just trying to enter menu */
101 if (volpushed_frames++ > 10) {
102 soundvol++;
103 if (soundvol > 100) soundvol=100;
104 //FCEUI_SetSoundVolume(soundvol);
105 setsoundvol(soundvol);
106 }
35868d35 107 }
b547bda7 108 else if (down(VOL_DOWN))
35868d35 109 {
b547bda7 110 if (volpushed_frames++ > 10) {
111 soundvol-=1;
112 if (soundvol < 0) soundvol=0;
113 //FCEUI_SetSoundVolume(soundvol);
114 setsoundvol(soundvol);
115 }
116 }
117 else
118 {
119 volpushed_frames = 0;
35868d35 120 }
121
35868d35 122
b547bda7 123 for (i = 0; i < 32; i++)
124 {
125 if (keys & (1 << i)) {
126 int acts = Settings.KeyBinds[i];
127 if (!acts) continue;
128 JS |= acts & 0xff;
989672f4 129 if (acts & 0x100) { // A turbo
130 turbo_rate_cnt_a += Settings.turbo_rate_add;
131 JS |= (turbo_rate_cnt_a >> 24) & 1;
132 }
133 if (acts & 0x200) { // B turbo
134 turbo_rate_cnt_b += Settings.turbo_rate_add;
135 JS |= (turbo_rate_cnt_b >> 23) & 2;
136 }
b547bda7 137 }
138 }
35868d35 139
35868d35 140
b547bda7 141 JSreturn = JS;
142 lastpad=keys;
35868d35 143
b547bda7 144 //JSreturn=(JS&0xFF000000)|(JS&0xFF)|((JS&0xFF0000)>>8)|((JS&0xFF00)<<8);
13624c8f 145
b547bda7 146#define pad keys
13624c8f 147
148 // JSreturn=(JSreturn&0xFF000000)|(JSreturn&0xFF)|((JSreturn&0xFF0000)>>8)|((JSreturn&0xFF00)<<8);
149 // TODO: make these bindable, use new interface
150 if(gametype==GIT_FDS)
151 {
152 NoWaiting&=~1;
153 if ((pad & GP2X_PUSH) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_L)) && (!(pad & GP2X_R)) && (!(lastpad2 & GP2X_PUSH)))
154 {
155 DriverInterface(DES_FDSSELECT,0);
156 }
157 else if ((pad & GP2X_L) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_PUSH)) && (!(pad & GP2X_R))&& (!(lastpad2 & GP2X_L)))
158 {
159 DriverInterface(DES_FDSINSERT,0);
160 }
161 else if ((pad & GP2X_R) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_L)) && (!(pad & GP2X_PUSH)) && (!(lastpad2 & GP2X_R)))
162 {
163 DriverInterface(DES_FDSEJECT,0);
164 }
165 }
166 return;
35868d35 167}
35868d35 168
169
170static void InitOtherInput(void)
171{
172
173 void *InputDPtr;
174
175 int t;
176 int x;
177 int attrib;
178
179 for(t=0,x=0;x<2;x++)
180 {
181 attrib=0;
182 InputDPtr=0;
183 switch(InputType[x])
184 {
185 //case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break;
186 case SI_GAMEPAD:InputDPtr=((uint8 *)&JSreturn)+(x<<1);break;
187 case SI_ARKANOID:InputDPtr=MouseData;t|=1;break;
188 case SI_ZAPPER:InputDPtr=MouseData;
189 t|=1;
190 attrib=1;
191 break;
192 }
193 FCEUI_SetInput(x,InputType[x],InputDPtr,attrib);
194 }
195
196 attrib=0;
197 InputDPtr=0;
198 switch(InputTypeFC)
199 {
200 case SIFC_SHADOW:InputDPtr=MouseData;t|=1;attrib=1;break;
201 case SIFC_ARKANOID:InputDPtr=MouseData;t|=1;break;
202 case SIFC_FKB:InputDPtr=fkbkeys;break;
203 }
204
205 FCEUI_SetInputFC(InputTypeFC,InputDPtr,attrib);
206 FCEUI_DisableFourScore(eoptions&EO_NOFOURSCORE);
207
208 if(t && !(inited&16))
209 {
210 InitMouse();
211 inited|=16;
212 }
213}