use system's zlib
[picodrive.git] / platform / common / main.c
CommitLineData
cff531af 1/*\r
2 * PicoDrive\r
3 * (C) notaz, 2006-2010\r
4 *\r
5 * This work is licensed under the terms of MAME license.\r
6 * See COPYING file in the top-level directory.\r
7 */\r
cc68a136 8\r
9#include <stdio.h>\r
e163b67f 10#include <stdlib.h>\r
cc68a136 11#include <string.h>\r
cc68a136 12#include <strings.h>\r
cc68a136 13\r
e743be20 14#include "../libpicofe/input.h"\r
15#include "../libpicofe/plat.h"\r
16#include "menu_pico.h"\r
cc68a136 17#include "emu.h"\r
c6f91b0e 18#include "version.h"\r
5686d931 19#include <cpu/debug.h>\r
cc68a136 20\r
cc68a136 21\r
e163b67f 22static int load_state_slot = -1;\r
cc68a136 23char **g_argv;\r
24\r
25void parse_cmd_line(int argc, char *argv[])\r
26{\r
27 int x, unrecognized = 0;\r
28\r
42171343 29 for (x = 1; x < argc; x++)\r
cc68a136 30 {\r
42171343 31 if (argv[x][0] == '-')\r
cc68a136 32 {\r
42171343 33 if (strcasecmp(argv[x], "-config") == 0) {\r
34 if (x+1 < argc) { ++x; PicoConfigFile = argv[x]; }\r
cc68a136 35 }\r
d438a8dd 36 else if (strcasecmp(argv[x], "-loadstate") == 0\r
37 || strcasecmp(argv[x], "-load") == 0)\r
38 {\r
42171343 39 if (x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }\r
e163b67f 40 }\r
5686d931 41 else if (strcasecmp(argv[x], "-pdb") == 0) {\r
42 if (x+1 < argc) { ++x; pdb_command(argv[x]); }\r
43 }\r
44 else if (strcasecmp(argv[x], "-pdb_connect") == 0) {\r
45 if (x+2 < argc) { pdb_net_connect(argv[x+1], argv[x+2]); x += 2; }\r
46 }\r
cc68a136 47 else {\r
48 unrecognized = 1;\r
49 break;\r
50 }\r
51 } else {\r
636d5f25 52 FILE *f = fopen(argv[x], "rb");\r
53 if (f) {\r
54 fclose(f);\r
55 rom_fname_reload = argv[x];\r
56 engineState = PGS_ReloadRom;\r
57 }\r
58 else\r
59 unrecognized = 1;\r
cc68a136 60 break;\r
61 }\r
62 }\r
63\r
64 if (unrecognized) {\r
636d5f25 65 printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2009,2013\n");\r
cc68a136 66 printf("usage: %s [options] [romfile]\n", argv[0]);\r
42171343 67 printf("options:\n"\r
68 " -config <file> use specified config file instead of default 'config.cfg'\n"\r
636d5f25 69 " -loadstate <num> if ROM is specified, try loading savestate slot <num>\n");\r
70 exit(1);\r
cc68a136 71 }\r
72}\r
73\r
74\r
75int main(int argc, char *argv[])\r
76{\r
77 g_argv = argv;\r
78\r
636d5f25 79 plat_early_init();\r
ee2a3bdf 80\r
7e4c661a 81 in_init();\r
636d5f25 82 //in_probe();\r
58c86d00 83\r
e743be20 84 plat_target_init();\r
636d5f25 85 plat_init();\r
45285368 86\r
87 emu_prep_defconfig(); // depends on input\r
88 emu_read_config(NULL, 0);\r
42171343 89\r
f2cf8472 90 emu_init();\r
a12e0116 91 menu_init();\r
cc68a136 92\r
93 engineState = PGS_Menu;\r
94\r
95 if (argc > 1)\r
96 parse_cmd_line(argc, argv);\r
97\r
e163b67f 98 if (engineState == PGS_ReloadRom)\r
99 {\r
a47dd663 100 if (emu_reload_rom(rom_fname_reload)) {\r
e163b67f 101 engineState = PGS_Running;\r
102 if (load_state_slot >= 0) {\r
103 state_slot = load_state_slot;\r
a47dd663 104 emu_save_load_game(1, 0);\r
e163b67f 105 }\r
106 }\r
107 }\r
108\r
cc68a136 109 for (;;)\r
110 {\r
111 switch (engineState)\r
112 {\r
113 case PGS_Menu:\r
114 menu_loop();\r
115 break;\r
116\r
d687ef50 117 case PGS_TrayMenu:\r
118 menu_loop_tray();\r
119 break;\r
120\r
cc68a136 121 case PGS_ReloadRom:\r
a47dd663 122 if (emu_reload_rom(rom_fname_reload))\r
cc68a136 123 engineState = PGS_Running;\r
124 else {\r
125 printf("PGS_ReloadRom == 0\n");\r
126 engineState = PGS_Menu;\r
127 }\r
128 break;\r
129\r
721cd396 130 case PGS_RestartRun:\r
131 engineState = PGS_Running;\r
d687ef50 132 /* vvv fallthrough */\r
721cd396 133\r
cc68a136 134 case PGS_Running:\r
b24e0f6c 135 emu_loop();\r
cc68a136 136 break;\r
137\r
138 case PGS_Quit:\r
139 goto endloop;\r
b837b69b 140\r
cc68a136 141 default:\r
142 printf("engine got into unknown state (%i), exitting\n", engineState);\r
143 goto endloop;\r
144 }\r
145 }\r
146\r
147 endloop:\r
148\r
f2cf8472 149 emu_finish();\r
636d5f25 150 plat_finish();\r
e743be20 151 plat_target_finish();\r
cc68a136 152\r
153 return 0;\r
154}\r