0f3b9aa7dc68d5dc90c5d67bd966de9f127d00ae
[fceu.git] / drivers / gp2x / gp2x.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "gp2x.h"
6 #include "gp2x-video.h"
7 #ifdef NETWORK
8 #include "unix-netplay.h"
9 #endif
10 #include "minimal.h"
11
12 int CLImain(int argc, char *argv[]);
13 extern void SetVideoScaling(int, int, int);
14
15 //#define SOUND_RATE 44100
16 #define SOUND_RATE 22050
17
18 DSETTINGS Settings;
19 CFGSTRUCT DriverConfig[]={
20         AC(_xscale),
21         AC(_yscale),
22         AC(_xscalefs),
23         AC(_yscalefs),
24         AC(_efx),
25         AC(_efxfs),
26         AC(_sound),
27         #ifdef DSPSOUND
28         AC(_f8bit),
29         #else
30         AC(_ebufsize),
31         AC(_lbufsize),
32         #endif
33         AC(_fullscreen),
34         AC(_xres),
35         AC(_yres),
36         ACA(joyBMap),
37         ACA(joyAMap),
38         ACA(joy),
39         //ACS(_fshack),
40         ENDCFGSTRUCT
41 };
42
43 //-fshack x       Set the environment variable SDL_VIDEODRIVER to \"x\" when
44 //                entering full screen mode and x is not \"0\".
45
46 char *DriverUsage=
47 "-xres   x       Set horizontal resolution to x for full screen mode.\n\
48 -yres   x       Set vertical resolution to x for full screen mode.\n\
49 -xscale(fs) x   Multiply width by x.\n\
50 -yscale(fs) x   Multiply height by x.\n\
51 -efx(fs) x      Enable scanlines effect if x is non zero.  yscale must be >=2\n\
52                 and preferably a multiple of 2.\n\
53 -fs      x      Select full screen mode if x is non zero.\n\
54 -joyx   y       Use joystick y as virtual joystick x.\n\
55 -sound x        Sound.\n\
56                  0 = Disabled.\n\
57                  Otherwise, x = playback rate.\n\
58 "
59 #ifdef DSPSOUND
60 "-f8bit x        Force 8-bit sound.\n\
61                  0 = Disabled.\n\
62                  1 = Enabled.\n\
63 "
64 #else
65 "-lbufsize x    Internal FCE Ultra sound buffer size. Size = 2^x samples.\n\
66 -ebufsize x     External SDL sound buffer size. Size = 2^x samples.\n\
67 "
68 #endif
69 "-connect s      Connect to server 's' for TCP/IP network play.\n\
70 -server         Be a host/server for TCP/IP network play.\n\
71 -netport x      Use TCP/IP port x for network play.";
72
73 #ifdef NETWORK
74 static int docheckie[2]={0,0};
75 #endif
76 ARGPSTRUCT DriverArgs[]={
77          {"-joy1",0,&joy[0],0},{"-joy2",0,&joy[1],0},
78          {"-joy3",0,&joy[2],0},{"-joy4",0,&joy[3],0},
79          {"-xscale",0,&_xscale,0},
80          {"-yscale",0,&_yscale,0},
81          {"-efx",0,&_efx,0},
82          {"-xscalefs",0,&_xscalefs,0},
83          {"-yscalefs",0,&_yscalefs,0},
84          {"-efxfs",0,&_efxfs,0},
85          {"-xres",0,&_xres,0},
86          {"-yres",0,&_yres,0},
87          {"-fs",0,&_fullscreen,0},
88          //{"-fshack",0,&_fshack,0x4001},
89          {"-sound",0,&_sound,0},
90          #ifdef DSPSOUND
91          {"-f8bit",0,&_f8bit,0},
92          #else
93          {"-lbufsize",0,&_lbufsize,0},
94          {"-ebufsize",0,&_ebufsize,0},
95          #endif
96          #ifdef NETWORK
97          {"-connect",&docheckie[0],&netplayhost,0x4001},
98          {"-server",&docheckie[1],0,0},
99          {"-netport",0,&Port,0},
100          #endif
101          {0,0,0,0}
102 };
103
104
105
106
107
108 void GetBaseDirectory(char *BaseDirectory)
109 {
110  char *ol;
111
112  ol="/mnt/sd/roms/nes";
113  BaseDirectory[0]=0;
114  if(ol)
115  {
116   strncpy(BaseDirectory,ol,2047);
117   BaseDirectory[2047]=0;
118   strcat(BaseDirectory,"/fceultra");
119  }
120 }
121
122 static void SetDefaults(void)
123 {
124  _xres=320;
125  _yres=240;
126  _fullscreen=0;
127  _sound=SOUND_RATE; // 48000 wrong
128  #ifdef DSPSOUND
129  _f8bit=0;
130  #else
131  _lbufsize=10;
132  _ebufsize=8;
133  #endif
134  _xscale=_yscale=_xscalefs=_yscalefs=1;
135  _efx=_efxfs=0;
136  //_fshack=_fshacksave=0;
137  memset(joy,0,sizeof(joy));
138 }
139
140 void DoDriverArgs(void)
141 {
142         int x;
143
144         #ifdef BROKEN
145         if(_fshack)
146         {
147          if(_fshack[0]=='0')
148           if(_fshack[1]==0)
149           {
150            free(_fshack);
151            _fshack=0;
152           }
153         }
154         #endif
155
156         #ifdef NETWORK
157         if(docheckie[0])
158          netplay=2;
159         else if(docheckie[1])
160          netplay=1;
161
162         if(netplay)
163          FCEUI_SetNetworkPlay(netplay);
164         #endif
165
166         for(x=0;x<4;x++)
167          if(!joy[x])
168          {
169           memset(joyBMap[x],0,sizeof(joyBMap[0]));
170           memset(joyAMap[x],0,sizeof(joyAMap[0]));
171          }
172 }
173 int InitMouse(void)
174 {
175  return(0);
176 }
177 void KillMouse(void){}
178 void GetMouseData(uint32 *d)
179 {
180 }
181
182 int InitKeyboard(void)
183 {
184  return(1);
185 }
186
187 int UpdateKeyboard(void)
188 {
189  return(1);
190 }
191
192 void KillKeyboard(void)
193 {
194
195 }
196
197 char *GetKeyboard(void)
198 {
199  return NULL;
200 }
201
202 #include "unix-basedir.h"
203 extern int showfps;
204 extern int swapbuttons;
205
206 int main(int argc, char *argv[])
207 {
208
209         puts("Starting GPFCE - Port version 0.2 05-29-2006");
210         puts("Based on FCE Ultra "VERSION_STRING"...");
211         puts("Ported by Zheng Zhu\n");
212
213          //  stereo
214          //gp2x_init (1000, 8, SOUND_RATE, 16, 1, 60);
215
216          // mono 44khz
217         //gp2x_init (1000, 8, SOUND_RATE<<1, 16, 0, 60);
218          // mono 22khz
219         gp2x_init (1000, 8, SOUND_RATE, 16, 0, 60);
220
221         SetDefaults();
222         int ret=CLImain(argc,argv);
223
224         // unscale the screen, in case this is bad.
225         SetVideoScaling(320, 320, 240);
226
227         gp2x_deinit();
228         // make sure sound thread has exited cleanly
229         printf("Exiting main().  terminated");
230         if (showfps && swapbuttons)
231         {
232           execl("./selector","./selector","./gpfce_showfps_swapbuttons_config",NULL);
233         }
234         else if (showfps)
235         {
236           execl("./selector","./selector","./gpfce_showfps_config",NULL);
237         }
238         else if (swapbuttons)
239         {
240           execl("./selector","./selector","./gpfce_swapbuttons_config",NULL);
241         }
242         else
243         {
244           execl("./selector","./selector","./gpfce_config",NULL);
245         }
246         return(ret?0:-1);
247 }
248