nonacc mode removal, function return value audit
[picodrive.git] / platform / gp2x / main.c
CommitLineData
cc68a136 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
7#include <string.h>\r
8#include <unistd.h>\r
9#include <strings.h>\r
10#include <linux/limits.h>\r
11\r
12#include "gp2x.h"\r
13#include "menu.h"\r
e5f426aa 14#include "../common/menu.h"\r
ea8c405f 15#include "../common/emu.h"\r
58c86d00 16#include "../common/config.h"\r
cc68a136 17#include "emu.h"\r
85f8e929 18#include "940ctl.h"\r
cc68a136 19#include "version.h"\r
20\r
21#include "squidgehack.h"\r
22#include "cpuctrl.h"\r
23\r
24\r
25extern char *ext_menu, *ext_state;\r
26extern int select_exits;\r
27extern char *PicoConfigFile;\r
28int mmuhack_status = 0;\r
29char **g_argv;\r
30\r
31void parse_cmd_line(int argc, char *argv[])\r
32{\r
33 int x, unrecognized = 0;\r
34\r
35 for(x = 1; x < argc; x++)\r
36 {\r
37 if(argv[x][0] == '-')\r
38 {\r
39 if(strcasecmp(argv[x], "-menu") == 0) {\r
40 if(x+1 < argc) { ++x; ext_menu = argv[x]; } /* External Frontend: Program Name */\r
41 }\r
42 else if(strcasecmp(argv[x], "-state") == 0) {\r
43 if(x+1 < argc) { ++x; ext_state = argv[x]; } /* External Frontend: Arguments */\r
44 }\r
45 else if(strcasecmp(argv[x], "-config") == 0) {\r
46 if(x+1 < argc) { ++x; PicoConfigFile = argv[x]; }\r
47 }\r
48 else if(strcasecmp(argv[x], "-selectexit") == 0) {\r
49 select_exits = 1;\r
50 }\r
51 else {\r
52 unrecognized = 1;\r
53 break;\r
54 }\r
55 } else {\r
56 /* External Frontend: ROM Name */\r
57 FILE *f;\r
58 strncpy(romFileName, argv[x], PATH_MAX);\r
59 romFileName[PATH_MAX-1] = 0;\r
60 f = fopen(romFileName, "rb");\r
61 if (f) fclose(f);\r
62 else unrecognized = 1;\r
63 engineState = PGS_ReloadRom;\r
64 break;\r
65 }\r
66 }\r
67\r
68 if (unrecognized) {\r
d6114368 69 printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2008\n");\r
cc68a136 70 printf("usage: %s [options] [romfile]\n", argv[0]);\r
71 printf( "options:\n"\r
72 "-menu <menu_path> launch a custom program on exit instead of default gp2xmenu\n"\r
73 "-state <param> pass '-state param' to the menu program\n"\r
74 "-config <file> use specified config file instead of default 'picoconfig.bin'\n"\r
75 " see currentConfig_t structure in emu.h for the file format\n"\r
76 "-selectexit pressing SELECT will exit the emu and start 'menu_path'\n");\r
77 }\r
78}\r
79\r
80\r
81int main(int argc, char *argv[])\r
82{\r
83 g_argv = argv;\r
84\r
58c86d00 85 emu_prepareDefaultConfig();\r
d524c827 86 emu_ReadConfig(0, 0);\r
1ca2ea4f 87 config_readlrom(PicoConfigFile);\r
58c86d00 88\r
cc68a136 89 gp2x_init();\r
90 if (currentConfig.EmuOpt&0x10) {\r
91 int ret = mmuhack();\r
92 printf("squidge hack code finished and returned %i\n", ret); fflush(stdout);\r
93 mmuhack_status = ret;\r
94 }\r
95 cpuctrl_init();\r
b837b69b 96 // Reset940(1);\r
97 // Pause940(1);\r
cc68a136 98 if (currentConfig.EmuOpt&0x100) {\r
99 printf("setting RAM timings.. "); fflush(stdout);\r
100 // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2\r
101 set_RAM_Timings(6, 4, 1, 1, 1, 2, 2);\r
102 printf("done.\n"); fflush(stdout);\r
103 }\r
85f8e929 104 sharedmem_init();\r
cc68a136 105 emu_Init();\r
a12e0116 106 menu_init();\r
cc68a136 107\r
108 engineState = PGS_Menu;\r
109\r
110 if (argc > 1)\r
111 parse_cmd_line(argc, argv);\r
112\r
113 for (;;)\r
114 {\r
115 switch (engineState)\r
116 {\r
117 case PGS_Menu:\r
118 menu_loop();\r
119 break;\r
120\r
121 case PGS_ReloadRom:\r
122 if (emu_ReloadRom())\r
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
132\r
cc68a136 133 case PGS_Running:\r
134 emu_Loop();\r
135 break;\r
136\r
137 case PGS_Quit:\r
138 goto endloop;\r
b837b69b 139\r
cc68a136 140 default:\r
141 printf("engine got into unknown state (%i), exitting\n", engineState);\r
142 goto endloop;\r
143 }\r
144 }\r
145\r
146 endloop:\r
147\r
148 emu_Deinit();\r
85f8e929 149 sharedmem_deinit();\r
cc68a136 150 cpuctrl_deinit();\r
151 gp2x_deinit();\r
152 if(mmuhack_status)\r
153 mmuunhack();\r
154\r
155 return 0;\r
156}\r