22 static char *defaultconfig
[] =
39 "bind joyright +right",
44 "bind 1 \"set saveslot 1\"",
45 "bind 2 \"set saveslot 2\"",
46 "bind 3 \"set saveslot 3\"",
47 "bind 4 \"set saveslot 4\"",
48 "bind 5 \"set saveslot 5\"",
49 "bind 6 \"set saveslot 6\"",
50 "bind 7 \"set saveslot 7\"",
51 "bind 8 \"set saveslot 8\"",
52 "bind 9 \"set saveslot 9\"",
53 "bind 0 \"set saveslot 0\"",
63 printf("\ngnuboy " VERSION
"\n");
66 static void copyright()
70 "Copyright (C) 2000-2001 Laguna and Gilgamesh\n"
71 "Portions contributed by other authors; see CREDITS for details.\n"
73 "This program is free software; you can redistribute it and/or modify\n"
74 "it under the terms of the GNU General Public License as published by\n"
75 "the Free Software Foundation; either version 2 of the License, or\n"
76 "(at your option) any later version.\n"
78 "This program is distributed in the hope that it will be useful,\n"
79 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
80 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
81 "GNU General Public License for more details.\n"
83 "You should have received a copy of the GNU General Public License\n"
84 "along with this program; if not, write to the Free Software\n"
85 "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
89 static void usage(char *name
)
92 printf("Type %s --help for detailed help.\n\n", name
);
102 static void joytest()
106 printf("press joystick buttons to see their name mappings\n");
110 if(ev_getevent(&e
)) {
112 case EV_NONE
: ename
= "none"; break;
113 case EV_PRESS
: ename
= "press"; break;
114 case EV_RELEASE
: ename
= "release"; break;
115 case EV_REPEAT
: ename
= "repeat"; break;
116 case EV_MOUSE
: ename
= "mouse"; break;
117 default: ename
= "unknown";
119 kname
= k_keyname(e
.code
);
120 printf("%s: %s\n", ename
, kname
? kname
: "<null>");
129 static void help(char *name
)
132 printf("Usage: %s [options] romfile\n", name
);
134 " --source FILE read rc commands from FILE\n"
135 " --bind KEY COMMAND bind KEY to perform COMMAND\n"
136 " --VAR=VALUE set rc variable VAR to VALUE\n"
137 " --VAR set VAR to 1 (turn on boolean options)\n"
138 " --no-VAR set VAR to 0 (turn off boolean options)\n"
139 " --showvars list all available rc variables\n"
140 " --help display this help and exit\n"
141 " --version output version information and exit\n"
142 " --copying show copying permissions\n"
143 " --joytest init joystick and show button names pressed\n"
144 " --rominfo show some info about the rom\n"
149 static void rominfo(char* fn
) {
150 extern int rom_load_simple(char *fn
);
152 printf( "rom name:\t%s\n"
156 , rom
.name
, mbc_to_string(mbc
.type
), mbc
.romsize
*16, mbc
.ramsize
*8);
160 static void version(char *name
)
162 printf("%s-" VERSION
"\n", name
);
173 while (ev_getevent(&ev
))
175 if (ev
.type
!= EV_PRESS
&& ev
.type
!= EV_RELEASE
)
177 st
= (ev
.type
!= EV_RELEASE
);
178 rc_dokey(ev
.code
, st
);
185 static void shutdown()
192 void die(char *fmt
, ...)
197 vfprintf(stderr
, fmt
, ap
);
202 static int bad_signals
[] =
204 /* These are all standard, so no need to #ifdef them... */
205 SIGINT
, SIGSEGV
, SIGTERM
, SIGFPE
, SIGABRT
, SIGILL
,
215 static void fatalsignal(int s
)
217 die("Signal %d\n", s
);
220 static void catch_signals()
223 for (i
= 0; bad_signals
[i
]; i
++)
224 signal(bad_signals
[i
], fatalsignal
);
229 static char *base(char *s
)
238 int main(int argc
, char *argv
[])
240 int i
, ri
= 0, sv
= 0;
241 char *opt
, *arg
, *cmd
, *s
, *rom
= 0;
243 /* Avoid initializing video if we don't have to */
244 for (i
= 1; i
< argc
; i
++)
246 if (!strcmp(argv
[i
], "--help"))
248 else if (!strcmp(argv
[i
], "--version"))
249 version(base(argv
[0]));
250 else if (!strcmp(argv
[i
], "--copying"))
252 else if (!strcmp(argv
[i
], "--bind")) i
+= 2;
253 else if (!strcmp(argv
[i
], "--source")) i
++;
254 else if (!strcmp(argv
[i
], "--showvars")) sv
= 1;
255 else if (!strcmp(argv
[i
], "--joytest"))
257 else if (!strcmp(argv
[i
], "--rominfo")) ri
= 1;
258 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-');
259 else if (argv
[i
][0] == '-' && argv
[i
][1]);
263 if (!rom
&& !sv
) usage(base(argv
[0]));
264 if (ri
) rominfo(rom
);
266 /* If we have special perms, drop them ASAP! */
275 for (i
= 0; defaultconfig
[i
]; i
++)
276 rc_command(defaultconfig
[i
]);
283 cmd
= malloc(strlen(rom
) + 11);
284 sprintf(cmd
, "source %s", rom
);
285 s
= strchr(cmd
, '.');
290 for (i
= 1; i
< argc
; i
++)
292 if (!strcmp(argv
[i
], "--bind"))
294 if (i
+ 2 >= argc
) die("missing arguments to bind\n");
295 cmd
= malloc(strlen(argv
[i
+1]) + strlen(argv
[i
+2]) + 9);
296 sprintf(cmd
, "bind %s \"%s\"", argv
[i
+1], argv
[i
+2]);
301 else if (!strcmp(argv
[i
], "--source"))
303 if (i
+ 1 >= argc
) die("missing argument to source\n");
304 cmd
= malloc(strlen(argv
[i
+1]) + 6);
305 sprintf(cmd
, "source %s", argv
[++i
]);
309 else if (!strncmp(argv
[i
], "--no-", 5))
311 opt
= strdup(argv
[i
]+5);
312 while ((s
= strchr(opt
, '-'))) *s
= '_';
313 cmd
= malloc(strlen(opt
) + 7);
314 sprintf(cmd
, "set %s 0", opt
);
319 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
321 opt
= strdup(argv
[i
]+2);
322 if ((s
= strchr(opt
, '=')))
328 while ((s
= strchr(opt
, '-'))) *s
= '_';
329 while ((s
= strchr(arg
, ','))) *s
= ' ';
331 cmd
= malloc(strlen(opt
) + strlen(arg
) + 6);
332 sprintf(cmd
, "set %s %s", opt
, arg
);
338 /* short options not yet implemented */
339 else if (argv
[i
][0] == '-' && argv
[i
][1]);
342 /* FIXME - make interface modules responsible for atexit() */