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
);
151 if(rom_load_simple(fn
)) {
152 fprintf(stderr
, "rom load failed: %s\n", loader_get_error()?loader_get_error():"");
155 printf( "rom name:\t%s\n"
159 , rom
.name
, mbc_to_string(mbc
.type
), mbc
.romsize
*16, mbc
.ramsize
*8);
163 static void version(char *name
)
165 printf("%s-" VERSION
"\n", name
);
176 while (ev_getevent(&ev
))
178 if (ev
.type
!= EV_PRESS
&& ev
.type
!= EV_RELEASE
)
180 st
= (ev
.type
!= EV_RELEASE
);
181 rc_dokey(ev
.code
, st
);
188 static void shutdown()
195 void die(char *fmt
, ...)
200 vfprintf(stderr
, fmt
, ap
);
205 static int bad_signals
[] =
207 /* These are all standard, so no need to #ifdef them... */
208 SIGINT
, SIGSEGV
, SIGTERM
, SIGFPE
, SIGABRT
, SIGILL
,
218 static void fatalsignal(int s
)
220 die("Signal %d\n", s
);
223 static void catch_signals()
226 for (i
= 0; bad_signals
[i
]; i
++)
227 signal(bad_signals
[i
], fatalsignal
);
232 static char *base(char *s
)
241 int main(int argc
, char *argv
[])
243 int i
, ri
= 0, sv
= 0;
244 char *opt
, *arg
, *cmd
, *s
, *rom
= 0;
246 /* Avoid initializing video if we don't have to */
247 for (i
= 1; i
< argc
; i
++)
249 if (!strcmp(argv
[i
], "--help"))
251 else if (!strcmp(argv
[i
], "--version"))
252 version(base(argv
[0]));
253 else if (!strcmp(argv
[i
], "--copying"))
255 else if (!strcmp(argv
[i
], "--bind")) i
+= 2;
256 else if (!strcmp(argv
[i
], "--source")) i
++;
257 else if (!strcmp(argv
[i
], "--showvars")) sv
= 1;
258 else if (!strcmp(argv
[i
], "--joytest"))
260 else if (!strcmp(argv
[i
], "--rominfo")) ri
= 1;
261 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-');
262 else if (argv
[i
][0] == '-' && argv
[i
][1]);
266 if (!rom
&& !sv
) usage(base(argv
[0]));
267 if (ri
) rominfo(rom
);
269 /* If we have special perms, drop them ASAP! */
278 for (i
= 0; defaultconfig
[i
]; i
++)
279 rc_command(defaultconfig
[i
]);
286 cmd
= malloc(strlen(rom
) + 11);
287 sprintf(cmd
, "source %s", rom
);
288 s
= strchr(cmd
, '.');
293 for (i
= 1; i
< argc
; i
++)
295 if (!strcmp(argv
[i
], "--bind"))
297 if (i
+ 2 >= argc
) die("missing arguments to bind\n");
298 cmd
= malloc(strlen(argv
[i
+1]) + strlen(argv
[i
+2]) + 9);
299 sprintf(cmd
, "bind %s \"%s\"", argv
[i
+1], argv
[i
+2]);
304 else if (!strcmp(argv
[i
], "--source"))
306 if (i
+ 1 >= argc
) die("missing argument to source\n");
307 cmd
= malloc(strlen(argv
[i
+1]) + 6);
308 sprintf(cmd
, "source %s", argv
[++i
]);
312 else if (!strncmp(argv
[i
], "--no-", 5))
314 opt
= strdup(argv
[i
]+5);
315 while ((s
= strchr(opt
, '-'))) *s
= '_';
316 cmd
= malloc(strlen(opt
) + 7);
317 sprintf(cmd
, "set %s 0", opt
);
322 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
324 opt
= strdup(argv
[i
]+2);
325 if ((s
= strchr(opt
, '=')))
331 while ((s
= strchr(opt
, '-'))) *s
= '_';
332 while ((s
= strchr(arg
, ','))) *s
= ' ';
334 cmd
= malloc(strlen(opt
) + strlen(arg
) + 6);
335 sprintf(cmd
, "set %s %s", opt
, arg
);
341 /* short options not yet implemented */
342 else if (argv
[i
][0] == '-' && argv
[i
][1]);
345 /* FIXME - make interface modules responsible for atexit() */