23 #include <pspmoduleinfo.h>
24 #include <pspthreadman.h>
25 PSP_MODULE_INFO("GnuBoy", 0, 1, 0);
26 PSP_MAIN_THREAD_ATTR(THREAD_ATTR_VFPU
| THREAD_ATTR_USER
);
30 static char *defaultconfig
[] =
47 "bind joyright +right",
52 "bind 1 \"set saveslot 1\"",
53 "bind 2 \"set saveslot 2\"",
54 "bind 3 \"set saveslot 3\"",
55 "bind 4 \"set saveslot 4\"",
56 "bind 5 \"set saveslot 5\"",
57 "bind 6 \"set saveslot 6\"",
58 "bind 7 \"set saveslot 7\"",
59 "bind 8 \"set saveslot 8\"",
60 "bind 9 \"set saveslot 9\"",
61 "bind 0 \"set saveslot 0\"",
72 printf("\ngnuboy " VERSION
"\n");
75 static void copyright()
79 "Copyright (C) 2000-2001 Laguna and Gilgamesh\n"
80 "Portions contributed by other authors; see CREDITS for details.\n"
82 "This program is free software; you can redistribute it and/or modify\n"
83 "it under the terms of the GNU General Public License as published by\n"
84 "the Free Software Foundation; either version 2 of the License, or\n"
85 "(at your option) any later version.\n"
87 "This program is distributed in the hope that it will be useful,\n"
88 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
89 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
90 "GNU General Public License for more details.\n"
92 "You should have received a copy of the GNU General Public License\n"
93 "along with this program; if not, write to the Free Software\n"
94 "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
98 static void usage(char *name
)
101 printf("Type %s --help for detailed help.\n\n", name
);
105 static void copying()
111 static void joytest()
115 printf("press joystick buttons to see their name mappings\n");
119 if(ev_getevent(&e
)) {
121 case EV_NONE
: ename
= "none"; break;
122 case EV_PRESS
: ename
= "press"; break;
123 case EV_RELEASE
: ename
= "release"; break;
124 case EV_REPEAT
: ename
= "repeat"; break;
125 case EV_MOUSE
: ename
= "mouse"; break;
126 default: ename
= "unknown";
128 kname
= k_keyname(e
.code
);
129 printf("%s: %s\n", ename
, kname
? kname
: "<null>");
138 static void help(char *name
)
141 printf("Usage: %s [options] romfile\n", name
);
143 " --source FILE read rc commands from FILE\n"
144 " --bind KEY COMMAND bind KEY to perform COMMAND\n"
145 " --VAR=VALUE set rc variable VAR to VALUE\n"
146 " --VAR set VAR to 1 (turn on boolean options)\n"
147 " --no-VAR set VAR to 0 (turn off boolean options)\n"
148 " --showvars list all available rc variables\n"
149 " --help display this help and exit\n"
150 " --version output version information and exit\n"
151 " --copying show copying permissions\n"
152 " --joytest init joystick and show button names pressed\n"
153 " --rominfo show some info about the rom\n"
158 static void rominfo(char* fn
) {
159 extern int rom_load_simple(char *fn
);
160 if(rom_load_simple(fn
)) {
161 fprintf(stderr
, "rom load failed: %s\n", loader_get_error()?loader_get_error():"");
164 printf( "rom name:\t%s\n"
168 , rom
.name
, mbc_to_string(mbc
.type
), mbc
.romsize
*16, mbc
.ramsize
*8);
172 static void version(char *name
)
174 printf("%s-" VERSION
"\n", name
);
185 while (ev_getevent(&ev
))
187 if (ev
.type
!= EV_PRESS
&& ev
.type
!= EV_RELEASE
)
189 st
= (ev
.type
!= EV_RELEASE
);
190 rc_dokey(ev
.code
, st
);
197 static void shutdown()
204 void die(char *fmt
, ...)
209 vfprintf(stderr
, fmt
, ap
);
214 static int bad_signals
[] =
216 /* These are all standard, so no need to #ifdef them... */
217 SIGINT
, SIGSEGV
, SIGTERM
, SIGFPE
, SIGABRT
, SIGILL
,
227 static void fatalsignal(int s
)
229 die("Signal %d\n", s
);
232 static void catch_signals()
235 for (i
= 0; bad_signals
[i
]; i
++)
236 signal(bad_signals
[i
], fatalsignal
);
241 static char *base(char *s
)
249 int load_rom_and_rc(char *rom
) {
250 char *s
, *cmd
= malloc(strlen(rom
) + 11);
251 sprintf(cmd
, "source %s", rom
);
252 s
= strchr(cmd
, '.');
259 if(loader_init(rom
)) {
260 /*loader_get_error();*/
268 int main(int argc
, char *argv
[])
270 int i
, ri
= 0, sv
= 0;
271 char *opt
, *arg
, *cmd
, *s
, *rom
= 0;
273 /* Avoid initializing video if we don't have to */
274 for (i
= 1; i
< argc
; i
++)
276 if (!strcmp(argv
[i
], "--help"))
278 else if (!strcmp(argv
[i
], "--version"))
279 version(base(argv
[0]));
280 else if (!strcmp(argv
[i
], "--copying"))
282 else if (!strcmp(argv
[i
], "--bind")) i
+= 2;
283 else if (!strcmp(argv
[i
], "--source")) i
++;
284 else if (!strcmp(argv
[i
], "--showvars")) sv
= 1;
285 else if (!strcmp(argv
[i
], "--joytest"))
287 else if (!strcmp(argv
[i
], "--rominfo")) ri
= 1;
288 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-');
289 else if (argv
[i
][0] == '-' && argv
[i
][1]);
293 if (ri
&& !rom
) usage(base(argv
[0]));
294 if (ri
) rominfo(rom
);
296 /* If we have special perms, drop them ASAP! */
305 for (i
= 0; defaultconfig
[i
]; i
++)
306 rc_command(defaultconfig
[i
]);
313 for (i
= 1; i
< argc
; i
++)
315 if (!strcmp(argv
[i
], "--bind"))
317 if (i
+ 2 >= argc
) die("missing arguments to bind\n");
318 cmd
= malloc(strlen(argv
[i
+1]) + strlen(argv
[i
+2]) + 9);
319 sprintf(cmd
, "bind %s \"%s\"", argv
[i
+1], argv
[i
+2]);
324 else if (!strcmp(argv
[i
], "--source"))
326 if (i
+ 1 >= argc
) die("missing argument to source\n");
327 cmd
= malloc(strlen(argv
[i
+1]) + 8);
328 sprintf(cmd
, "source %s", argv
[++i
]);
332 else if (!strncmp(argv
[i
], "--no-", 5))
334 opt
= strdup(argv
[i
]+5);
335 while ((s
= strchr(opt
, '-'))) *s
= '_';
336 cmd
= malloc(strlen(opt
) + 7);
337 sprintf(cmd
, "set %s 0", opt
);
342 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
344 opt
= strdup(argv
[i
]+2);
345 if ((s
= strchr(opt
, '=')))
351 while ((s
= strchr(opt
, '-'))) *s
= '_';
352 while ((s
= strchr(arg
, ','))) *s
= ' ';
354 cmd
= malloc(strlen(opt
) + strlen(arg
) + 6);
355 sprintf(cmd
, "set %s %s", opt
, arg
);
361 /* short options not yet implemented */
362 else if (argv
[i
][0] == '-' && argv
[i
][1]);
365 /* FIXME - make interface modules responsible for atexit() */
373 if(rom
) load_rom_and_rc(rom
);
375 rc_command("bind esc menu");
376 menu_initpage(mp_romsel
);
381 /* if we get here it means emu was paused, so enter menu. */
383 menu_initpage(mp_main
);