menu and controls wip..
[fceu.git] / drivers / gp2x / gp2x.c
... / ...
CommitLineData
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "../../driver.h"
6#include "../common/config.h"
7#include "../common/args.h"
8#include "gp2x.h"
9#include "gp2x-video.h"
10#ifdef NETWORK
11#include "unix-netplay.h"
12#endif
13
14#include "minimal.h"
15#include "cpuctrl.h"
16#include "squidgehack.h"
17
18int CLImain(int argc, char *argv[]);
19
20//#define SOUND_RATE 44100
21#define SOUND_RATE 22050
22
23DSETTINGS Settings;
24CFGSTRUCT DriverConfig[]={
25 ACA(Settings.KeyBinds),
26 ACA(Settings.JoyBinds),
27 AC(Settings.turbo_rate_add),
28 AC(Settings.sound),
29 AC(Settings.showfps),
30 AC(Settings.scaling),
31 AC(Settings.frameskip),
32 AC(Settings.sstate_confirm),
33 AC(Settings.region_force),
34 AC(Settings.cpuclock),
35 AC(Settings.mmuhack),
36 AC(Settings.ramtimings),
37 AC(Settings.gamma),
38 // TODO
39 ENDCFGSTRUCT
40};
41
42
43char *DriverUsage=
44"-joyx y Use joystick y as virtual joystick x.\n\
45-sound x Sound.\n\
46 0 = Disabled.\n\
47 Otherwise, x = playback rate.\n\
48-showfps x Display fps counter if x is nonzero\n\
49-mmuhack x Enable squidge's MMU hack if x is nonzero (GP2X).\n\
50-ramtimings x Enable RAM overclocking if x is nonzero (GP2X).\n\
51"
52#ifdef NETWORK
53"-connect s Connect to server 's' for TCP/IP network play.\n\
54-server Be a host/server for TCP/IP network play.\n\
55-netport x Use TCP/IP port x for network play."
56#endif
57;
58
59#ifdef NETWORK
60static int docheckie[2]={0,0};
61#endif
62ARGPSTRUCT DriverArgs[]={
63 {"-sound",0,&Settings.sound,0},
64 {"-showfps",0,&Settings.showfps,0},
65 {"-mmuhack",0,&Settings.mmuhack,0},
66 {"-ramtimings",0,&Settings.ramtimings,0},
67 {"-menu",0,&ext_menu,0x4001},
68 {"-menustate",0,&ext_state,0x4001},
69 #ifdef NETWORK
70 {"-connect",&docheckie[0],&netplayhost,0x4001},
71 {"-server",&docheckie[1],0,0},
72 {"-netport",0,&Port,0},
73 #endif
74 {0,0,0,0}
75};
76
77
78
79void GetBaseDirectory(char *BaseDirectory)
80{
81 strcpy(BaseDirectory, "fceultra");
82}
83
84static void SetDefaults(void)
85{
86 memset(&Settings,0,sizeof(Settings));
87 Settings.cpuclock = 150;
88 Settings.frameskip = -1; // auto
89 Settings.mmuhack = 1;
90 Settings.sound = SOUND_RATE;
91 // default controls, RLDU SEBA
92 Settings.KeyBinds[ 0] = 0x010; // GP2X_UP
93 Settings.KeyBinds[ 4] = 0x020; // GP2X_DOWN
94 Settings.KeyBinds[ 2] = 0x040; // GP2X_LEFT
95 Settings.KeyBinds[ 6] = 0x080; // GP2X_RIGHT
96 Settings.KeyBinds[13] = 0x001; // GP2X_B
97 Settings.KeyBinds[14] = 0x002; // GP2X_X
98 Settings.KeyBinds[15] = 0x100; // GP2X_Y
99 Settings.KeyBinds[12] = 0x200; // GP2X_A
100 Settings.KeyBinds[ 8] = 0x008; // GP2X_START
101 Settings.KeyBinds[ 9] = 0x004; // GP2X_SELECT
102}
103
104void DoDriverArgs(void)
105{
106 #ifdef NETWORK
107 if(docheckie[0])
108 netplay=2;
109 else if(docheckie[1])
110 netplay=1;
111
112 if(netplay)
113 FCEUI_SetNetworkPlay(netplay);
114 #endif
115}
116
117int InitMouse(void)
118{
119 return(0);
120}
121
122void KillMouse(void){}
123
124void GetMouseData(uint32 *d)
125{
126}
127
128int InitKeyboard(void)
129{
130 return(1);
131}
132
133int UpdateKeyboard(void)
134{
135 return(1);
136}
137
138void KillKeyboard(void)
139{
140
141}
142
143char *GetKeyboard(void)
144{
145 return NULL;
146}
147
148
149char **g_argv;
150int mmuhack_status = 0;
151
152
153// TODO: cleanup
154int main(int argc, char *argv[])
155{
156 int ret;
157 g_argv = argv;
158
159 puts("Starting GPFCE - Port version " GP2X_PORT_VERSION " (" __DATE__ ")");
160 puts("Based on FCE Ultra "VERSION_STRING"...");
161 puts("Ported by Zheng Zhu");
162 puts("Additional optimization/misc work by notaz\n");
163
164 gp2x_init();
165 cpuctrl_init();
166
167 SetDefaults();
168
169 ret = CLImain(argc,argv);
170
171 // unscale the screen, in case this is bad.
172 gp2x_video_RGB_setscaling(0, 320, 240);
173
174 if (mmuhack_status > 0)
175 mmuunhack();
176
177 cpuctrl_deinit();
178 gp2x_deinit();
179
180 return(ret?0:-1);
181}
182
183
184/* optional GP2X stuff to be done after config is loaded */
185void gp2x_opt_setup(void)
186{
187 if (Settings.mmuhack) {
188 int ret = mmuhack();
189 printf("squidge hack code finished and returned %s\n", ret > 0 ? "ok" : "fail");
190 fflush(stdout);
191 mmuhack_status = ret;
192 }
193 if (Settings.ramtimings) {
194 printf("setting RAM timings.. "); fflush(stdout);
195 // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2
196 set_RAM_Timings(6, 4, 1, 1, 1, 2, 2);
197 printf("done.\n"); fflush(stdout);
198 }
199}
200
201void gp2x_cpuclock_update(void)
202{
203 static int prev_cpuclock = 200;
204 if (Settings.cpuclock != 0 && Settings.cpuclock != prev_cpuclock)
205 {
206 set_FCLK(Settings.cpuclock);
207 prev_cpuclock = Settings.cpuclock;
208 }
209}
210
211