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