[Rpcemu] Patch: better error checking on startup

Ed Avis ed at membled.com
Sun Jul 6 13:27:36 BST 2008


rpcemu isn't very friendly if no roms can be found.  This patch makes it report
the cause of errors better.  It also warns of unsupported command line options
(that is, any options at all).  Adding real options for --roms-dir, --help etc.
is to be done later ;-).

Index: src/rpcemu.c
===================================================================
--- src/rpcemu.c	(revision 132)
+++ src/rpcemu.c	(working copy)
@@ -43,15 +43,6 @@
 void loadconfig();
 void saveconfig();
 
-void fatal(const char *format, ...)
-{
-   va_list ap;
-   va_start(ap, format);
-   error(format, ap);
-   va_end(ap);
-   abort();
-}
-
 void resetrpc()
 {
         memset(ram,0,rammask+1);
@@ -81,11 +72,7 @@
         }
         initmem();
 //printf("Mem inited...\n");
-        if (loadroms())
-        {
-                error("RISC OS ROMs missing!");
-                return -1;
-        }
+	loadroms();
 //printf("ROMs loaded!\n");
         resetarm();
         resetfpa();
Index: src/rpc-dos.c
===================================================================
--- src/rpc-dos.c	(revision 132)
+++ src/rpc-dos.c	(working copy)
@@ -44,7 +44,19 @@
    vfprintf(stderr, format, ap);
    va_end(ap);
 }
+void fatal(const char *format, ...)
+{
+   char buf[256];
 
+   va_list ap;
+   va_start(ap, format);
+   fprintf(stderr, "RPCemu error: ");
+   vfprintf(stderr, format, ap);
+   va_end(ap);
+
+   abort();
+}
+
 FILE *arclog;
 void rpclog(const char *format, ...)
 {
Index: src/rpc-win.c
===================================================================
--- src/rpc-win.c	(revision 132)
+++ src/rpc-win.c	(working copy)
@@ -56,7 +56,19 @@
    va_end(ap);
    MessageBox(NULL,buf,"RPCemu error",MB_OK);;
 }
+void fatal(const char *format, ...)
+{
+   char buf[256];
 
+   va_list ap;
+   va_start(ap, format);
+   vsprintf(buf, format, ap);
+   va_end(ap);
+   MessageBox(NULL,buf,"RPCemu error",MB_OK);;
+
+   abort();
+}
+
 FILE *arclog;
 void rpclog(const char *format, ...)
 {
Index: src/rpc-linux.c
===================================================================
--- src/rpc-linux.c	(revision 132)
+++ src/rpc-linux.c	(working copy)
@@ -42,6 +42,23 @@
    va_end(ap);
 }
 
+// Similar to error() but aborts the program. 
+//
+// Because of varargs it's not straightforward to just call error()
+// from here.  So some code is duplicated.
+//
+void fatal(const char *format, ...)
+{
+   va_list ap;
+   va_start(ap, format);
+   fprintf(stderr, "RPCemu error: ");
+   vfprintf(stderr, format, ap);
+   fprintf(stderr,"\n");
+   va_end(ap);
+
+   abort();
+}
+
 FILE *arclog;
 void rpclog(const char *format, ...)
 {
@@ -141,8 +158,14 @@
 END_OF_FUNCTION(close_button_handler)
 
 
-int main (void) 
+int main (int argc, char ** argv) 
 { 
+	if (argc != 1)
+	{
+		fprintf(stderr, "No command line options supported.\n");
+		return 1;
+	}
+
         infocus=1;
         allegro_init();
 
Index: src/romload.c
===================================================================
--- src/romload.c	(revision 132)
+++ src/romload.c	(working copy)
@@ -9,7 +9,8 @@
 #define MAXROMS 16
 static char romfns[MAXROMS+1][256];
 
-int loadroms(void)
+// Load the ROM images, call fatal() on error.
+void loadroms(void)
 {
         FILE *f;
         int finished=0;
@@ -19,16 +20,23 @@
         struct al_ffblk ff;
         char olddir[512],fn[512];
         char *ext;
+	const char *wildcard = "*.*";
+	const char *dirname = "roms";
 
         getcwd(olddir,sizeof(olddir));
-        append_filename(fn,exname,"roms",sizeof(fn));
-        if (chdir(fn)) fatal("Cannot find roms directory %s",fn);
-        finished=al_findfirst("*.*",&ff,0xFFFF&~FA_DIREC);
+        append_filename(fn,exname,dirname,sizeof(fn));
+        if (chdir(fn))
+	{
+		error("Cannot find roms directory %s",dirname);
+		abort();
+	}
+        finished=al_findfirst(wildcard,&ff,0xFFFF&~FA_DIREC);
         if (finished)
-        {
-                chdir(olddir);
-                return -1;
-        }
+	{
+		error("Cannot find any file in roms directory '%s' matching '%s'",
+		      dirname, wildcard);
+		abort();
+	}
         while (!finished && file<MAXROMS)
         {
                 ext=get_extension(ff.name);
@@ -41,11 +49,7 @@
                 finished = al_findnext(&ff);
         }
         al_findclose(&ff);
-        if (file==0)
-        {
-                chdir(olddir);
-                return -1;
-        }
+        if (file==0) fatal("Could not load roms from directory '%s'", dirname);
 //printf("Loading file...\n");
         for (c=0;c<file;c++)
         {
@@ -101,6 +105,4 @@
            rom[0x14824>>2]=0xE3A06008; /*MOV R6,#8 - 8 megs*/
 
 //        initpodulerom();
-
-        return 0;
 }


-- 
Ed Avis <ed at membled.com>




More information about the Rpcemu mailing list