1 // (c) Copyright 2006 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
10 #include <strings.h>
\r
11 #include <linux/limits.h>
\r
15 #include "../common/menu.h"
\r
16 #include "../common/emu.h"
\r
17 #include "../common/config.h"
\r
18 #include "../common/input.h"
\r
21 #include "version.h"
\r
23 #include "squidgehack.h"
\r
24 #include "cpuctrl.h"
\r
27 extern char *ext_menu, *ext_state;
\r
28 extern int select_exits;
\r
29 extern char *PicoConfigFile;
\r
30 static int load_state_slot = -1;
\r
31 int mmuhack_status = 0;
\r
34 void parse_cmd_line(int argc, char *argv[])
\r
36 int x, unrecognized = 0;
\r
38 for(x = 1; x < argc; x++)
\r
40 if(argv[x][0] == '-')
\r
42 if(strcasecmp(argv[x], "-menu") == 0) {
\r
43 if(x+1 < argc) { ++x; ext_menu = argv[x]; } /* External Frontend: Program Name */
\r
45 else if(strcasecmp(argv[x], "-state") == 0) {
\r
46 if(x+1 < argc) { ++x; ext_state = argv[x]; } /* External Frontend: Arguments */
\r
48 else if(strcasecmp(argv[x], "-config") == 0) {
\r
49 if(x+1 < argc) { ++x; PicoConfigFile = argv[x]; }
\r
51 else if(strcasecmp(argv[x], "-selectexit") == 0) {
\r
54 else if(strcasecmp(argv[x], "-loadstate") == 0) {
\r
55 if(x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }
\r
62 /* External Frontend: ROM Name */
\r
64 strncpy(romFileName, argv[x], PATH_MAX);
\r
65 romFileName[PATH_MAX-1] = 0;
\r
66 f = fopen(romFileName, "rb");
\r
68 else unrecognized = 1;
\r
69 engineState = PGS_ReloadRom;
\r
75 printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2008\n");
\r
76 printf("usage: %s [options] [romfile]\n", argv[0]);
\r
77 printf( "options:\n"
\r
78 "-menu <menu_path> launch a custom program on exit instead of default gp2xmenu\n"
\r
79 "-state <param> pass '-state param' to the menu program\n"
\r
80 "-config <file> use specified config file instead of default 'picoconfig.bin'\n"
\r
81 " see currentConfig_t structure in emu.h for the file format\n"
\r
82 "-selectexit pressing SELECT will exit the emu and start 'menu_path'\n"
\r
83 "-loadstate <num> if ROM is specified, try loading slot <num>\n");
\r
88 int main(int argc, char *argv[])
\r
93 emu_prepareDefaultConfig();
\r
94 emu_ReadConfig(0, 0);
\r
95 config_readlrom(PicoConfigFile);
\r
100 if (currentConfig.EmuOpt&0x10) {
\r
101 int ret = mmuhack();
\r
102 printf("squidge hack code finished and returned %i\n", ret); fflush(stdout);
\r
103 mmuhack_status = ret;
\r
108 if (currentConfig.EmuOpt&0x100) {
\r
109 printf("setting RAM timings.. "); fflush(stdout);
\r
110 // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2
\r
111 set_RAM_Timings(6, 4, 1, 1, 1, 2, 2);
\r
112 printf("done.\n"); fflush(stdout);
\r
118 engineState = PGS_Menu;
\r
121 parse_cmd_line(argc, argv);
\r
123 if (engineState == PGS_ReloadRom)
\r
125 if (emu_ReloadRom(romFileName)) {
\r
126 engineState = PGS_Running;
\r
127 if (load_state_slot >= 0) {
\r
128 state_slot = load_state_slot;
\r
129 emu_SaveLoadGame(1, 0);
\r
136 switch (engineState)
\r
142 case PGS_ReloadRom:
\r
143 if (emu_ReloadRom(romFileName))
\r
144 engineState = PGS_Running;
\r
146 printf("PGS_ReloadRom == 0\n");
\r
147 engineState = PGS_Menu;
\r
151 case PGS_RestartRun:
\r
152 engineState = PGS_Running;
\r
162 printf("engine got into unknown state (%i), exitting\n", engineState);
\r
170 sharedmem_deinit();
\r