starting input layer integration work
[picodrive.git] / platform / gp2x / main.c
... / ...
CommitLineData
1// (c) Copyright 2006 notaz, All rights reserved.\r
2// Free for non-commercial use.\r
3\r
4// For commercial use, separate licencing terms must be obtained.\r
5\r
6#include <stdio.h>\r
7#include <stdlib.h>\r
8#include <string.h>\r
9#include <unistd.h>\r
10#include <strings.h>\r
11#include <linux/limits.h>\r
12\r
13#include "gp2x.h"\r
14#include "menu.h"\r
15#include "../common/menu.h"\r
16#include "../common/emu.h"\r
17#include "../common/config.h"\r
18#include "../common/input.h"\r
19#include "emu.h"\r
20#include "940ctl.h"\r
21#include "version.h"\r
22\r
23#include "squidgehack.h"\r
24#include "cpuctrl.h"\r
25\r
26\r
27extern char *ext_menu, *ext_state;\r
28extern int select_exits;\r
29extern char *PicoConfigFile;\r
30static int load_state_slot = -1;\r
31int mmuhack_status = 0;\r
32char **g_argv;\r
33\r
34void parse_cmd_line(int argc, char *argv[])\r
35{\r
36 int x, unrecognized = 0;\r
37\r
38 for(x = 1; x < argc; x++)\r
39 {\r
40 if(argv[x][0] == '-')\r
41 {\r
42 if(strcasecmp(argv[x], "-menu") == 0) {\r
43 if(x+1 < argc) { ++x; ext_menu = argv[x]; } /* External Frontend: Program Name */\r
44 }\r
45 else if(strcasecmp(argv[x], "-state") == 0) {\r
46 if(x+1 < argc) { ++x; ext_state = argv[x]; } /* External Frontend: Arguments */\r
47 }\r
48 else if(strcasecmp(argv[x], "-config") == 0) {\r
49 if(x+1 < argc) { ++x; PicoConfigFile = argv[x]; }\r
50 }\r
51 else if(strcasecmp(argv[x], "-selectexit") == 0) {\r
52 select_exits = 1;\r
53 }\r
54 else if(strcasecmp(argv[x], "-loadstate") == 0) {\r
55 if(x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }\r
56 }\r
57 else {\r
58 unrecognized = 1;\r
59 break;\r
60 }\r
61 } else {\r
62 /* External Frontend: ROM Name */\r
63 FILE *f;\r
64 strncpy(romFileName, argv[x], PATH_MAX);\r
65 romFileName[PATH_MAX-1] = 0;\r
66 f = fopen(romFileName, "rb");\r
67 if (f) fclose(f);\r
68 else unrecognized = 1;\r
69 engineState = PGS_ReloadRom;\r
70 break;\r
71 }\r
72 }\r
73\r
74 if (unrecognized) {\r
75 printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2008\n");\r
76 printf("usage: %s [options] [romfile]\n", argv[0]);\r
77 printf( "options:\n"\r
78 "-menu <menu_path> launch a custom program on exit instead of default gp2xmenu\n"\r
79 "-state <param> pass '-state param' to the menu program\n"\r
80 "-config <file> use specified config file instead of default 'picoconfig.bin'\n"\r
81 " see currentConfig_t structure in emu.h for the file format\n"\r
82 "-selectexit pressing SELECT will exit the emu and start 'menu_path'\n"\r
83 "-loadstate <num> if ROM is specified, try loading slot <num>\n");\r
84 }\r
85}\r
86\r
87\r
88int main(int argc, char *argv[])\r
89{\r
90 g_argv = argv;\r
91\r
92 in_init();\r
93 emu_prepareDefaultConfig();\r
94 emu_ReadConfig(0, 0);\r
95 config_readlrom(PicoConfigFile);\r
96\r
97 in_probe();\r
98 in_debug_dump();\r
99 gp2x_init();\r
100 if (currentConfig.EmuOpt&0x10) {\r
101 int ret = mmuhack();\r
102 printf("squidge hack code finished and returned %i\n", ret); fflush(stdout);\r
103 mmuhack_status = ret;\r
104 }\r
105 cpuctrl_init();\r
106 // Reset940(1);\r
107 // Pause940(1);\r
108 if (currentConfig.EmuOpt&0x100) {\r
109 printf("setting RAM timings.. "); fflush(stdout);\r
110 // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2\r
111 set_RAM_Timings(6, 4, 1, 1, 1, 2, 2);\r
112 printf("done.\n"); fflush(stdout);\r
113 }\r
114 sharedmem_init();\r
115 emu_Init();\r
116 menu_init();\r
117\r
118 engineState = PGS_Menu;\r
119\r
120 if (argc > 1)\r
121 parse_cmd_line(argc, argv);\r
122\r
123 if (engineState == PGS_ReloadRom)\r
124 {\r
125 if (emu_ReloadRom(romFileName)) {\r
126 engineState = PGS_Running;\r
127 if (load_state_slot >= 0) {\r
128 state_slot = load_state_slot;\r
129 emu_SaveLoadGame(1, 0);\r
130 }\r
131 }\r
132 }\r
133\r
134 for (;;)\r
135 {\r
136 switch (engineState)\r
137 {\r
138 case PGS_Menu:\r
139 menu_loop();\r
140 break;\r
141\r
142 case PGS_ReloadRom:\r
143 if (emu_ReloadRom(romFileName))\r
144 engineState = PGS_Running;\r
145 else {\r
146 printf("PGS_ReloadRom == 0\n");\r
147 engineState = PGS_Menu;\r
148 }\r
149 break;\r
150\r
151 case PGS_RestartRun:\r
152 engineState = PGS_Running;\r
153\r
154 case PGS_Running:\r
155 emu_Loop();\r
156 break;\r
157\r
158 case PGS_Quit:\r
159 goto endloop;\r
160\r
161 default:\r
162 printf("engine got into unknown state (%i), exitting\n", engineState);\r
163 goto endloop;\r
164 }\r
165 }\r
166\r
167 endloop:\r
168\r
169 emu_Deinit();\r
170 sharedmem_deinit();\r
171 cpuctrl_deinit();\r
172 gp2x_deinit();\r
173 if(mmuhack_status)\r
174 mmuunhack();\r
175\r
176 return 0;\r
177}\r