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