partially working menu
[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
35868d35 18int CLImain(int argc, char *argv[]);
35868d35 19
20//#define SOUND_RATE 44100
21#define SOUND_RATE 22050
b2b95d2e 22#define GP2X_PORT_VERSION "0.4"
35868d35 23
24DSETTINGS Settings;
25CFGSTRUCT DriverConfig[]={
b2b95d2e 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
35868d35 39 ENDCFGSTRUCT
40};
41
35868d35 42
43char *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
60static int docheckie[2]={0,0};
61#endif
62ARGPSTRUCT DriverArgs[]={
b2b95d2e 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},
35868d35 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
35868d35 81void GetBaseDirectory(char *BaseDirectory)
82{
b2b95d2e 83 strcpy(BaseDirectory, "fceultra");
35868d35 84}
85
86static void SetDefaults(void)
87{
b2b95d2e 88 memset(&Settings,0,sizeof(Settings));
89 Settings.cpuclock = 150;
90 Settings.frameskip = -1; // auto
91 Settings.mmuhack = 1;
92 Settings.sound=SOUND_RATE;
35868d35 93}
94
95void DoDriverArgs(void)
96{
97 int x;
98
35868d35 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++)
b2b95d2e 110 if(!Settings.joy[x])
35868d35 111 {
b2b95d2e 112 memset(Settings.joyBMap[x],0,sizeof(Settings.joyBMap[0]));
113 memset(Settings.joyAMap[x],0,sizeof(Settings.joyAMap[0]));
35868d35 114 }
115}
b2b95d2e 116
35868d35 117int InitMouse(void)
118{
119 return(0);
120}
b2b95d2e 121
35868d35 122void KillMouse(void){}
b2b95d2e 123
35868d35 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
b2b95d2e 148extern int swapbuttons; // TODO: rm
937bf65b 149char **g_argv;
35868d35 150
b2b95d2e 151
152// TODO: cleanup
35868d35 153int main(int argc, char *argv[])
154{
b2b95d2e 155 int ret;
937bf65b 156 g_argv = argv;
35868d35 157
937bf65b 158 puts("Starting GPFCE - Port version " GP2X_PORT_VERSION " (" __DATE__ ")");
35868d35 159 puts("Based on FCE Ultra "VERSION_STRING"...");
937bf65b 160 puts("Ported by Zheng Zhu");
161 puts("Additional optimization/misc work by notaz\n");
35868d35 162
b2b95d2e 163 gp2x_init();
164 cpuctrl_init();
35868d35 165
937bf65b 166 // unscale the screen, in case this is bad.
b2b95d2e 167 gp2x_video_changemode(8);
168 gp2x_video_RGB_setscaling(0, 320, 240);
937bf65b 169
35868d35 170 SetDefaults();
b2b95d2e 171
172 ret = CLImain(argc,argv);
35868d35 173
174 // unscale the screen, in case this is bad.
b2b95d2e 175 gp2x_video_RGB_setscaling(0, 320, 240);
35868d35 176
b2b95d2e 177 cpuctrl_deinit();
35868d35 178 gp2x_deinit();
b2b95d2e 179
35868d35 180 return(ret?0:-1);
181}
182
b2b95d2e 183
184int mmuhack_status = 0;
185
186/* optional GP2X stuff to be done after config is loaded */
187void 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