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