0d9bf4fc |
1 | // (c) Copyright 2006-2009 notaz, All rights reserved.\r |
cc68a136 |
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 |
e163b67f |
7 | #include <stdlib.h>\r |
cc68a136 |
8 | #include <string.h>\r |
cc68a136 |
9 | #include <strings.h>\r |
cc68a136 |
10 | \r |
bcd94522 |
11 | #include "menu.h"\r |
cc68a136 |
12 | #include "emu.h"\r |
bcd94522 |
13 | #include "config.h"\r |
14 | #include "input.h"\r |
15 | #include "plat.h"\r |
16 | #include <version.h>\r |
cc68a136 |
17 | \r |
cc68a136 |
18 | \r |
cc68a136 |
19 | extern char *PicoConfigFile;\r |
e163b67f |
20 | static int load_state_slot = -1;\r |
cc68a136 |
21 | char **g_argv;\r |
22 | \r |
23 | void parse_cmd_line(int argc, char *argv[])\r |
24 | {\r |
25 | int x, unrecognized = 0;\r |
26 | \r |
42171343 |
27 | for (x = 1; x < argc; x++)\r |
cc68a136 |
28 | {\r |
42171343 |
29 | if (argv[x][0] == '-')\r |
cc68a136 |
30 | {\r |
42171343 |
31 | if (strcasecmp(argv[x], "-config") == 0) {\r |
32 | if (x+1 < argc) { ++x; PicoConfigFile = argv[x]; }\r |
cc68a136 |
33 | }\r |
42171343 |
34 | else if (strcasecmp(argv[x], "-loadstate") == 0) {\r |
35 | if (x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }\r |
e163b67f |
36 | }\r |
cc68a136 |
37 | else {\r |
38 | unrecognized = 1;\r |
39 | break;\r |
40 | }\r |
41 | } else {\r |
42 | /* External Frontend: ROM Name */\r |
43 | FILE *f;\r |
74f5e726 |
44 | strncpy(rom_fname_reload, argv[x], sizeof(rom_fname_reload));\r |
45 | rom_fname_reload[sizeof(rom_fname_reload) - 1] = 0;\r |
713c9224 |
46 | f = fopen(rom_fname_reload, "rb");\r |
cc68a136 |
47 | if (f) fclose(f);\r |
48 | else unrecognized = 1;\r |
49 | engineState = PGS_ReloadRom;\r |
50 | break;\r |
51 | }\r |
52 | }\r |
53 | \r |
54 | if (unrecognized) {\r |
42171343 |
55 | printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2009\n");\r |
cc68a136 |
56 | printf("usage: %s [options] [romfile]\n", argv[0]);\r |
42171343 |
57 | printf("options:\n"\r |
58 | " -config <file> use specified config file instead of default 'config.cfg'\n"\r |
59 | " -loadstate <num> if ROM is specified, try loading slot <num>\n");\r |
cc68a136 |
60 | }\r |
61 | }\r |
62 | \r |
63 | \r |
64 | int main(int argc, char *argv[])\r |
65 | {\r |
66 | g_argv = argv;\r |
67 | \r |
ee2a3bdf |
68 | plat_early_init();\r |
69 | \r |
42171343 |
70 | /* in_init() must go before config, config accesses in_ fwk */\r |
7e4c661a |
71 | in_init();\r |
f2cf8472 |
72 | pemu_prep_defconfig();\r |
a47dd663 |
73 | emu_read_config(0, 0);\r |
1ca2ea4f |
74 | config_readlrom(PicoConfigFile);\r |
58c86d00 |
75 | \r |
42171343 |
76 | plat_init();\r |
7e4c661a |
77 | in_probe();\r |
78 | in_debug_dump();\r |
42171343 |
79 | \r |
f2cf8472 |
80 | emu_init();\r |
a12e0116 |
81 | menu_init();\r |
cc68a136 |
82 | \r |
83 | engineState = PGS_Menu;\r |
84 | \r |
85 | if (argc > 1)\r |
86 | parse_cmd_line(argc, argv);\r |
87 | \r |
e163b67f |
88 | if (engineState == PGS_ReloadRom)\r |
89 | {\r |
a47dd663 |
90 | if (emu_reload_rom(rom_fname_reload)) {\r |
e163b67f |
91 | engineState = PGS_Running;\r |
92 | if (load_state_slot >= 0) {\r |
93 | state_slot = load_state_slot;\r |
a47dd663 |
94 | emu_save_load_game(1, 0);\r |
e163b67f |
95 | }\r |
96 | }\r |
97 | }\r |
98 | \r |
cc68a136 |
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 |
d687ef50 |
107 | case PGS_TrayMenu:\r |
108 | menu_loop_tray();\r |
109 | break;\r |
110 | \r |
cc68a136 |
111 | case PGS_ReloadRom:\r |
a47dd663 |
112 | if (emu_reload_rom(rom_fname_reload))\r |
cc68a136 |
113 | engineState = PGS_Running;\r |
114 | else {\r |
115 | printf("PGS_ReloadRom == 0\n");\r |
116 | engineState = PGS_Menu;\r |
117 | }\r |
118 | break;\r |
119 | \r |
721cd396 |
120 | case PGS_RestartRun:\r |
121 | engineState = PGS_Running;\r |
d687ef50 |
122 | /* vvv fallthrough */\r |
721cd396 |
123 | \r |
cc68a136 |
124 | case PGS_Running:\r |
b24e0f6c |
125 | emu_loop();\r |
cc68a136 |
126 | break;\r |
127 | \r |
128 | case PGS_Quit:\r |
129 | goto endloop;\r |
b837b69b |
130 | \r |
cc68a136 |
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 |
f2cf8472 |
139 | emu_finish();\r |
42171343 |
140 | plat_finish();\r |
cc68a136 |
141 | \r |
142 | return 0;\r |
143 | }\r |