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