e7c3a0e9648b5b2372c35bdbe61839a97e3d5bc8
[fceu.git] / drivers / gp2x / gp2x.c
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
18 int CLImain(int argc, char *argv[]);
19
20 //#define SOUND_RATE 44100
21 #define SOUND_RATE 22050
22 #define GP2X_PORT_VERSION "0.4"
23
24 DSETTINGS Settings;
25 CFGSTRUCT DriverConfig[]={
26         AC(Settings.sound),
27         ACA(Settings.joyBMap),
28         ACA(Settings.joyAMap),
29         ACA(Settings.joy),
30         AC(Settings.showfps),
31         AC(Settings.scaling),
32         AC(Settings.frameskip),
33         AC(Settings.sstate_confirm),
34         AC(Settings.region_force),
35         AC(Settings.cpuclock),
36         AC(Settings.mmuhack),
37         AC(Settings.ramtimings),
38         // TODO
39         ENDCFGSTRUCT
40 };
41
42
43 char *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
60 static int docheckie[2]={0,0};
61 #endif
62 ARGPSTRUCT DriverArgs[]={
63          {"-joy1",0,&Settings.joy[0],0},{"-joy2",0,&Settings.joy[1],0},
64          {"-joy3",0,&Settings.joy[2],0},{"-joy4",0,&Settings.joy[3],0},
65          {"-sound",0,&Settings.sound,0},
66          {"-showfps",0,&Settings.showfps,0},
67          {"-mmuhack",0,&Settings.mmuhack,0},
68          {"-ramtimings",0,&Settings.ramtimings,0},
69          {"-menu",0,&ext_menu,0x4001},
70          {"-menustate",0,&ext_state,0x4001},
71          #ifdef NETWORK
72          {"-connect",&docheckie[0],&netplayhost,0x4001},
73          {"-server",&docheckie[1],0,0},
74          {"-netport",0,&Port,0},
75          #endif
76          {0,0,0,0}
77 };
78
79
80
81 void GetBaseDirectory(char *BaseDirectory)
82 {
83  strcpy(BaseDirectory, "fceultra");
84 }
85
86 static void SetDefaults(void)
87 {
88  memset(&Settings,0,sizeof(Settings));
89  Settings.cpuclock = 150;
90  Settings.frameskip = -1; // auto
91  Settings.mmuhack = 1;
92  Settings.sound=SOUND_RATE;
93 }
94
95 void DoDriverArgs(void)
96 {
97         int x;
98
99         #ifdef NETWORK
100         if(docheckie[0])
101          netplay=2;
102         else if(docheckie[1])
103          netplay=1;
104
105         if(netplay)
106          FCEUI_SetNetworkPlay(netplay);
107         #endif
108
109         for(x=0;x<4;x++)
110          if(!Settings.joy[x])
111          {
112           memset(Settings.joyBMap[x],0,sizeof(Settings.joyBMap[0]));
113           memset(Settings.joyAMap[x],0,sizeof(Settings.joyAMap[0]));
114          }
115 }
116
117 int InitMouse(void)
118 {
119  return(0);
120 }
121
122 void KillMouse(void){}
123
124 void GetMouseData(uint32 *d)
125 {
126 }
127
128 int InitKeyboard(void)
129 {
130  return(1);
131 }
132
133 int UpdateKeyboard(void)
134 {
135  return(1);
136 }
137
138 void KillKeyboard(void)
139 {
140
141 }
142
143 char *GetKeyboard(void)
144 {
145  return NULL;
146 }
147
148 extern int swapbuttons; // TODO: rm
149 char **g_argv;
150
151
152 // TODO: cleanup
153 int main(int argc, char *argv[])
154 {
155         int ret;
156         g_argv = argv;
157
158         puts("Starting GPFCE - Port version " GP2X_PORT_VERSION " (" __DATE__ ")");
159         puts("Based on FCE Ultra "VERSION_STRING"...");
160         puts("Ported by Zheng Zhu");
161         puts("Additional optimization/misc work by notaz\n");
162
163         gp2x_init();
164         cpuctrl_init();
165
166         // unscale the screen, in case this is bad.
167         gp2x_video_changemode(8);
168         gp2x_video_RGB_setscaling(0, 320, 240);
169
170         SetDefaults();
171
172         ret = CLImain(argc,argv);
173
174         // unscale the screen, in case this is bad.
175         gp2x_video_RGB_setscaling(0, 320, 240);
176
177         cpuctrl_deinit();
178         gp2x_deinit();
179
180         return(ret?0:-1);
181 }
182
183
184 int mmuhack_status = 0;
185
186 /* optional GP2X stuff to be done after config is loaded */
187 void gp2x_opt_setup(void)
188 {
189         if (Settings.mmuhack) {
190                 int ret = mmuhack();
191                 printf("squidge hack code finished and returned %i\n", ret); fflush(stdout);
192                 mmuhack_status = ret;
193         }
194         if (Settings.ramtimings) {
195                 printf("setting RAM timings.. "); fflush(stdout);
196                 // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2
197                 set_RAM_Timings(6, 4, 1, 1, 1, 2, 2);
198                 printf("done.\n"); fflush(stdout);
199         }
200 }
201