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