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