ROM search paths

11 views
Skip to first unread message

Marcos Cruz

unread,
Nov 27, 2012, 2:28:46 PM11/27/12
to xAce development group
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
xmain.c.gz

Marcos Cruz

unread,
Nov 27, 2012, 2:36:38 PM11/27/12
to xAce development group
En/Je/On 2012-11-27 20:28, Marcos Cruz escribi� / skribis / wrote :
> I attach the whole xmain.c gziped.

Oops, with my own ints/sec in fast_speed(). Should be 500.

--
http://programandala.net

Edward Patel

unread,
Nov 27, 2012, 5:22:25 PM11/27/12
to xace...@googlegroups.com
How about trying to package the ROM into the binary/executable itself?

/Edward
> <xmain.c.gz>

Edward Patel

unread,
Nov 27, 2012, 5:30:34 PM11/27/12
to xace...@googlegroups.com
xxd is a nice tool for things like that.

"xxd -i ace.rom > ace.rom.h"

Gives this

ace.rom.h

Marcos Cruz

unread,
Nov 27, 2012, 5:49:14 PM11/27/12
to xace...@googlegroups.com
En/Je/On 2012-11-27 23:22, Edward Patel escribi� / skribis / wrote :
> How about trying to package the ROM into the binary/executable itself?

Good idea, simpler for the user.

But IMO there should be always an option to load an alternative (e.g.
patched or improved) ROM anyway. Because of that, it looks simpler to
load the ROM from a file, the way it works now, than package it and then
create a command line and/or menu option to substitute it.

A command line option to choose an alternative ROM would be nice anyway.

Marcos

--
http://programandala.net

Lawrence Woodman

unread,
Nov 28, 2012, 5:49:40 AM11/28/12
to xace...@googlegroups.com
On 27/11/12 19:28, Marcos Cruz wrote:
> 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.
Great idea and thanks for the code. It has inspired me to use a config file
to configure xace. Probably /etc/xacerc for system wide defaults and
~/.xacerc for user configuration. In here the amount of memory, location
of the rom, default tape path, etc could be configured.

What do you think?

bfn



Lorry

--
vLife Systems Ltd
Registered Office: The Meridian, 4 Copthall House, Station Square, Coventry, CV1 2FL
Registered in England and Wales No. 06477649
http://vlifesystems.com

Lawrence Woodman

unread,
Nov 28, 2012, 5:51:18 AM11/28/12
to xace...@googlegroups.com
I tend to agree with you Marcos; I too like the option of using
different ROMs.
If it is implemented properly then I don't see a separate ROM file being a
huge problem for the user.

Marcos Cruz

unread,
Nov 28, 2012, 7:03:51 AM11/28/12
to xace...@googlegroups.com
En/Je/On 2012-11-28 10:49, Lawrence Woodman escribi� / skribis / wrote :

> a config file to configure xace. Probably /etc/xacerc for system wide
> defaults and ~/.xacerc for user configuration. In here the amount of
> memory, location of the rom, default tape path, etc could be
> configured.

Perfect. I suggest a command line option to load an alternative config
file. That will let the user to keep "different" Aces ready to run.

I suggest to adhere the XDG specs
(<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>).
In most cases it means <~/.config/xace/> and </etc/xdg/xace/>.

I also suggest a unique name for the standard config file, for every
possible location. This way it can be simply moved or copied when
needed. E.g. <xacerc>.

One option is to load only the first file found in a list, in priority
order, and ignore the rest:

1) ./xacerc
2) ~/.config/xace/xacerc
3) /etc/xdg/xace/xacerc

The file <./xacerc> is just an idea: it would provide a default
configuration in case the user doesn't install the program. Maybe this
is not needed, because the default configuration can be hardcoded.

Another option is to load all files found, in reverse priority order,
and overwrite previous configurations every time:

1) /etc/xdg/xace/xacerc
2) ~/.config/xace/xacerc
3) ./xacerc

I don't know what's the usual, more useful or recommended behaviour.

Marcos

--
http://programandala.net

Marcos Cruz

unread,
Nov 28, 2012, 7:11:28 AM11/28/12
to xace...@googlegroups.com
I see an interesting advantage in your idea: the emulator could run even
when the configured ROM file is missing or corrupted. This feature would
make xAce more robust, easy to use and distribute, because the
executable file alone would run out of the box with the standard ROM and
a default configuration.

Marcos

--
http://programandala.net

Marcos Cruz

unread,
Nov 28, 2012, 7:18:29 AM11/28/12
to xace...@googlegroups.com
En/Je/On 2012-11-28 10:51, Lawrence Woodman escribi� / skribis / wrote :

> I too like the option of using different ROMs.

I think it's almost a moral duty for emulators :-)

> If it is implemented properly then I don't see a separate ROM file being a
> huge problem for the user.

I agree. But what Edward suggests is compatible with separate and
alternative ROM files: the standard ROM would be hardcoded, ready to use
just in case no ROM file can be found. It's an interesting feature.

Marcos

--
http://programandala.net

Lawrence Woodman

unread,
Dec 2, 2012, 3:13:58 AM12/2/12
to xace...@googlegroups.com
Embedding the ROM into the code using something like xxd is quite cool.
However, I see the ROM as just another dependency that needs to be
present to allow xAce to run. In the same way that I wouldn't statically
link libx11-dev and libxext-dev into the executable, I see no reason to link
in the ROM.

That said, I do see the value of making xAce easy to run out of the box
and am therefore looking at how I can get rid of the need for the separate
console and having to run xAce from the same directory as the ROM.
Ultimately I want to get to the point where people can download xAce as a
package and use it the same as any other package. The first job after
sorting
out the config file and GUI, will be to create an AUR package for Arch
Linux.

Hopefully this will increase the popularity of xAce and by extension the
Jupiter Ace.
Reply all
Reply to author
Forward
0 new messages