Hi,
Currently the ROM file has to be in the directory where xAce is started,
what is a limitation. In order to start it from any directory, I use a
little loader in Bash. It would be nice if the ROM could be stored in
any standard location, and the emulator could find it.
I was about to suggest the implementation of search paths, but I decided
to code it myself --with the help of some web searches (my knowledge of
C is very basic).
It works fine (except the user directory paths, the most important).
Please review, fix and improve my changes.
----8<----------------------------------------------------------
void
loadrom(unsigned char *x)
{
/* Original code: */
/*
FILE *in;
if((in=fopen("ace.rom", "rb"))!=NULL)
{
if (fread(x,1,8192,in) != 8192) {
printf("Couldn't load ROM.\n");
fclose(in);
exit(1);
}
fclose(in);
}
else
{
printf("Couldn't load ROM.\n");
exit(1);
}
*/
/* Suggested code, based on an example found at
* <
http://stackoverflow.com/questions/8147330/fopen-search-paths>
*/
FILE *in;
/*
* Search paths:
*
* "~/.xace" and "~/.config/xace" don't work. I've read
* (<
http://www.mathworks.com/help/matlab/ref/fopen.html>)
* that "~/" works with fopen in Unix environments, but it
* seems I'm doing something wrong.
*
* "/etc/default/xace" and "/usr/local/lib/xace" are just
* suggestions; maybe they are not standard or orthodox.
*
*/
char *paths[] = {
".",
"~/.xace",
"~/.config/xace",
"/etc/default/xace",
"/usr/local/lib/xace",
NULL
};
char path[32];
int i;
i=0;
while (!in && paths[i]) {
sprintf(path, "%s/ace.rom", paths[i]);
in = fopen(path, "rb");
i++;
}
if(in != NULL)
/*
* xxx The rest is copied from the original;
* only the messages have been changed.
* */
{
printf("Chosen ROM: %s\n",path); /* xxx Temporary debug check */
if (fread(x,1,8192,in) != 8192) {
printf("Couldn't load %s.\n",path);
fclose(in);
exit(1);
}
fclose(in);
}
else
{
printf("Couldn't find a ROM file.\n");
exit(1);
}
}
----8<----------------------------------------------------------
I attach the whole xmain.c gziped.
Marcos
--
http://programandala.net