embed build date to one of debug screens
[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
74f5e726 13#include "../gp2x/emu.h" // TODO rm\r
3a3947cd 14#include "../common/menu.h"\r
15#include "../common/emu.h"\r
16#include "../common/config.h"\r
b6820926 17#include "../common/input.h"\r
3a3947cd 18#include "../gp2x/version.h"\r
74f5e726 19#include "pandora.h"\r
3a3947cd 20\r
21\r
3a3947cd 22extern char *PicoConfigFile;\r
e163b67f 23static int load_state_slot = -1;\r
3a3947cd 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
e55f0cbb 34 if(strcasecmp(argv[x], "-config") == 0) {\r
3a3947cd 35 if(x+1 < argc) { ++x; PicoConfigFile = argv[x]; }\r
36 }\r
e163b67f 37 else if(strcasecmp(argv[x], "-loadstate") == 0) {\r
38 if(x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }\r
39 }\r
3a3947cd 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
74f5e726 47 strncpy(rom_fname_reload, argv[x], sizeof(rom_fname_reload));\r
48 rom_fname_reload[sizeof(rom_fname_reload) - 1] = 0;\r
713c9224 49 f = fopen(rom_fname_reload, "rb");\r
3a3947cd 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
74f5e726 58 printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2009\n");\r
3a3947cd 59 printf("usage: %s [options] [romfile]\n", argv[0]);\r
60 printf( "options:\n"\r
3a3947cd 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
e163b67f 63 "-loadstate <num> if ROM is specified, try loading slot <num>\n");\r
3a3947cd 64 }\r
65}\r
66\r
67\r
68int main(int argc, char *argv[])\r
69{\r
70 g_argv = argv;\r
71\r
b6820926 72 in_init();\r
3a3947cd 73 emu_prepareDefaultConfig();\r
74 emu_ReadConfig(0, 0);\r
75 config_readlrom(PicoConfigFile);\r
76\r
b6820926 77 in_probe();\r
78 in_debug_dump();\r
74f5e726 79 pnd_init();\r
3a3947cd 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
e163b67f 88 if (engineState == PGS_ReloadRom)\r
89 {\r
713c9224 90 if (emu_ReloadRom(rom_fname_reload)) {\r
e163b67f 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
3a3947cd 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
713c9224 108 if (emu_ReloadRom(rom_fname_reload))\r
3a3947cd 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
74f5e726 135 pnd_exit();\r
3a3947cd 136\r
137 return 0;\r
138}\r