fix events loss
[picodrive.git] / platform / pandora / 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/gp2x.h"\r
14#include "../gp2x/menu.h"\r
15#include "../common/menu.h"\r
16#include "../common/emu.h"\r
17#include "../common/config.h"\r
18#include "../gp2x/emu.h"\r
19#include "../gp2x/version.h"\r
20\r
21\r
22extern int select_exits;\r
23extern char *PicoConfigFile;\r
24static int load_state_slot = -1;\r
25int mmuhack_status = 0; // TODO rm\r
26char **g_argv;\r
27\r
28void parse_cmd_line(int argc, char *argv[])\r
29{\r
30 int x, unrecognized = 0;\r
31\r
32 for(x = 1; x < argc; x++)\r
33 {\r
34 if(argv[x][0] == '-')\r
35 {\r
36 if(strcasecmp(argv[x], "-config") == 0) {\r
37 if(x+1 < argc) { ++x; PicoConfigFile = argv[x]; }\r
38 }\r
39 else if(strcasecmp(argv[x], "-selectexit") == 0) {\r
40 select_exits = 1;\r
41 }\r
42 else if(strcasecmp(argv[x], "-loadstate") == 0) {\r
43 if(x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }\r
44 }\r
45 else {\r
46 unrecognized = 1;\r
47 break;\r
48 }\r
49 } else {\r
50 /* External Frontend: ROM Name */\r
51 FILE *f;\r
52 strncpy(romFileName, argv[x], PATH_MAX);\r
53 romFileName[PATH_MAX-1] = 0;\r
54 f = fopen(romFileName, "rb");\r
55 if (f) fclose(f);\r
56 else unrecognized = 1;\r
57 engineState = PGS_ReloadRom;\r
58 break;\r
59 }\r
60 }\r
61\r
62 if (unrecognized) {\r
63 printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2008\n");\r
64 printf("usage: %s [options] [romfile]\n", argv[0]);\r
65 printf( "options:\n"\r
66 "-menu <menu_path> launch a custom program on exit instead of default gp2xmenu\n"\r
67 "-state <param> pass '-state param' to the menu program\n"\r
68 "-config <file> use specified config file instead of default 'picoconfig.bin'\n"\r
69 " see currentConfig_t structure in emu.h for the file format\n"\r
70 "-selectexit pressing SELECT will exit the emu and start 'menu_path'\n"\r
71 "-loadstate <num> if ROM is specified, try loading slot <num>\n");\r
72 }\r
73}\r
74\r
75\r
76int main(int argc, char *argv[])\r
77{\r
78 g_argv = argv;\r
79\r
80 emu_prepareDefaultConfig();\r
81 emu_ReadConfig(0, 0);\r
82 config_readlrom(PicoConfigFile);\r
83\r
84 gp2x_init();\r
85 emu_Init();\r
86 menu_init();\r
87\r
88 engineState = PGS_Menu;\r
89\r
90 if (argc > 1)\r
91 parse_cmd_line(argc, argv);\r
92\r
93 if (engineState == PGS_ReloadRom)\r
94 {\r
95 if (emu_ReloadRom(romFileName)) {\r
96 engineState = PGS_Running;\r
97 if (load_state_slot >= 0) {\r
98 state_slot = load_state_slot;\r
99 emu_SaveLoadGame(1, 0);\r
100 }\r
101 }\r
102 }\r
103\r
104 for (;;)\r
105 {\r
106 switch (engineState)\r
107 {\r
108 case PGS_Menu:\r
109 menu_loop();\r
110 break;\r
111\r
112 case PGS_ReloadRom:\r
113 if (emu_ReloadRom(romFileName))\r
114 engineState = PGS_Running;\r
115 else {\r
116 printf("PGS_ReloadRom == 0\n");\r
117 engineState = PGS_Menu;\r
118 }\r
119 break;\r
120\r
121 case PGS_RestartRun:\r
122 engineState = PGS_Running;\r
123\r
124 case PGS_Running:\r
125 emu_Loop();\r
126 break;\r
127\r
128 case PGS_Quit:\r
129 goto endloop;\r
130\r
131 default:\r
132 printf("engine got into unknown state (%i), exitting\n", engineState);\r
133 goto endloop;\r
134 }\r
135 }\r
136\r
137 endloop:\r
138\r
139 emu_Deinit();\r
140\r
141 return 0;\r
142}\r