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