35868d35 |
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <string.h> |
35868d35 |
4 | |
b2b95d2e |
5 | #include "../../driver.h" |
6 | #include "../common/config.h" |
7 | #include "../common/args.h" |
22f08d95 |
8 | #include "gp2x.h" |
9 | #include "gp2x-video.h" |
35868d35 |
10 | #ifdef NETWORK |
11 | #include "unix-netplay.h" |
12 | #endif |
b2b95d2e |
13 | |
35868d35 |
14 | #include "minimal.h" |
b2b95d2e |
15 | #include "cpuctrl.h" |
16 | #include "squidgehack.h" |
22f08d95 |
17 | |
35868d35 |
18 | int CLImain(int argc, char *argv[]); |
35868d35 |
19 | |
20 | //#define SOUND_RATE 44100 |
21 | #define SOUND_RATE 22050 |
22 | |
23 | DSETTINGS Settings; |
24 | CFGSTRUCT DriverConfig[]={ |
b547bda7 |
25 | ACA(Settings.KeyBinds), |
26 | ACA(Settings.JoyBinds), |
27 | AC(Settings.turbo_rate_add), |
989672f4 |
28 | AC(Settings.sound_rate), |
b2b95d2e |
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), |
b547bda7 |
37 | AC(Settings.gamma), |
b2b95d2e |
38 | // TODO |
35868d35 |
39 | ENDCFGSTRUCT |
40 | }; |
41 | |
35868d35 |
42 | |
43 | char *DriverUsage= |
b2b95d2e |
44 | "-joyx y Use joystick y as virtual joystick x.\n\ |
35868d35 |
45 | -sound x Sound.\n\ |
46 | 0 = Disabled.\n\ |
47 | Otherwise, x = playback rate.\n\ |
b2b95d2e |
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\ |
35868d35 |
51 | " |
b2b95d2e |
52 | #ifdef NETWORK |
35868d35 |
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\ |
b2b95d2e |
55 | -netport x Use TCP/IP port x for network play." |
56 | #endif |
57 | ; |
35868d35 |
58 | |
59 | #ifdef NETWORK |
60 | static int docheckie[2]={0,0}; |
61 | #endif |
62 | ARGPSTRUCT DriverArgs[]={ |
989672f4 |
63 | {"-sound",0,&Settings.sound_rate,0}, |
b2b95d2e |
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}, |
35868d35 |
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 | |
35868d35 |
79 | void GetBaseDirectory(char *BaseDirectory) |
80 | { |
b2b95d2e |
81 | strcpy(BaseDirectory, "fceultra"); |
35868d35 |
82 | } |
83 | |
84 | static void SetDefaults(void) |
85 | { |
b2b95d2e |
86 | memset(&Settings,0,sizeof(Settings)); |
87 | Settings.cpuclock = 150; |
88 | Settings.frameskip = -1; // auto |
89 | Settings.mmuhack = 1; |
989672f4 |
90 | Settings.sound_rate = SOUND_RATE; |
91 | Settings.turbo_rate_add = (8*2 << 24) / 60 + 1; // 8Hz turbofire |
92 | Settings.gamma = 100; |
b547bda7 |
93 | // default controls, RLDU SEBA |
94 | Settings.KeyBinds[ 0] = 0x010; // GP2X_UP |
95 | Settings.KeyBinds[ 4] = 0x020; // GP2X_DOWN |
96 | Settings.KeyBinds[ 2] = 0x040; // GP2X_LEFT |
97 | Settings.KeyBinds[ 6] = 0x080; // GP2X_RIGHT |
98 | Settings.KeyBinds[13] = 0x001; // GP2X_B |
99 | Settings.KeyBinds[14] = 0x002; // GP2X_X |
989672f4 |
100 | Settings.KeyBinds[12] = 0x100; // GP2X_A |
101 | Settings.KeyBinds[15] = 0x200; // GP2X_Y |
b547bda7 |
102 | Settings.KeyBinds[ 8] = 0x008; // GP2X_START |
103 | Settings.KeyBinds[ 9] = 0x004; // GP2X_SELECT |
35868d35 |
104 | } |
105 | |
106 | void DoDriverArgs(void) |
107 | { |
35868d35 |
108 | #ifdef NETWORK |
109 | if(docheckie[0]) |
110 | netplay=2; |
111 | else if(docheckie[1]) |
112 | netplay=1; |
113 | |
114 | if(netplay) |
115 | FCEUI_SetNetworkPlay(netplay); |
116 | #endif |
35868d35 |
117 | } |
b2b95d2e |
118 | |
b547bda7 |
119 | |
937bf65b |
120 | char **g_argv; |
b547bda7 |
121 | int mmuhack_status = 0; |
35868d35 |
122 | |
b2b95d2e |
123 | |
124 | // TODO: cleanup |
35868d35 |
125 | int main(int argc, char *argv[]) |
126 | { |
b2b95d2e |
127 | int ret; |
937bf65b |
128 | g_argv = argv; |
35868d35 |
129 | |
937bf65b |
130 | puts("Starting GPFCE - Port version " GP2X_PORT_VERSION " (" __DATE__ ")"); |
35868d35 |
131 | puts("Based on FCE Ultra "VERSION_STRING"..."); |
937bf65b |
132 | puts("Ported by Zheng Zhu"); |
133 | puts("Additional optimization/misc work by notaz\n"); |
35868d35 |
134 | |
b2b95d2e |
135 | gp2x_init(); |
136 | cpuctrl_init(); |
35868d35 |
137 | |
138 | SetDefaults(); |
b2b95d2e |
139 | |
140 | ret = CLImain(argc,argv); |
35868d35 |
141 | |
142 | // unscale the screen, in case this is bad. |
b2b95d2e |
143 | gp2x_video_RGB_setscaling(0, 320, 240); |
35868d35 |
144 | |
b547bda7 |
145 | if (mmuhack_status > 0) |
146 | mmuunhack(); |
147 | |
989672f4 |
148 | set_gamma(100); |
b2b95d2e |
149 | cpuctrl_deinit(); |
35868d35 |
150 | gp2x_deinit(); |
b2b95d2e |
151 | |
35868d35 |
152 | return(ret?0:-1); |
153 | } |
154 | |
b2b95d2e |
155 | |
b2b95d2e |
156 | /* optional GP2X stuff to be done after config is loaded */ |
157 | void gp2x_opt_setup(void) |
158 | { |
159 | if (Settings.mmuhack) { |
160 | int ret = mmuhack(); |
b547bda7 |
161 | printf("squidge hack code finished and returned %s\n", ret > 0 ? "ok" : "fail"); |
162 | fflush(stdout); |
b2b95d2e |
163 | mmuhack_status = ret; |
164 | } |
165 | if (Settings.ramtimings) { |
166 | printf("setting RAM timings.. "); fflush(stdout); |
167 | // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2 |
168 | set_RAM_Timings(6, 4, 1, 1, 1, 2, 2); |
169 | printf("done.\n"); fflush(stdout); |
170 | } |
171 | } |
172 | |
989672f4 |
173 | void gp2x_cpuclock_gamma_update(void) |
b547bda7 |
174 | { |
989672f4 |
175 | static int prev_cpuclock = 200, prev_gamma = 100; |
b547bda7 |
176 | if (Settings.cpuclock != 0 && Settings.cpuclock != prev_cpuclock) |
177 | { |
178 | set_FCLK(Settings.cpuclock); |
179 | prev_cpuclock = Settings.cpuclock; |
180 | } |
989672f4 |
181 | |
182 | if (Settings.gamma != 0 && Settings.gamma != prev_gamma) |
183 | { |
184 | set_gamma(Settings.gamma); |
185 | prev_gamma = Settings.gamma; |
186 | } |
b547bda7 |
187 | } |
188 | |
189 | |