Description: Upstream changes introduced in version 1.23-12
 This patch has been created by dpkg-source during the package build.
 Here's the last changelog entry, hopefully it gives details on why
 those changes were made:
 .
 dgen (1.23-12) unstable; urgency=low
 .
   * Readded the makefiles
   * debian/rules. Removed the clean rule.
   * Switch to dpkg-source 3.0 (quilt) format
   * Switch to quilt for manage the patches.
   * debian/control: Switch any to i386 on arch field.
   * Fix for some warnings about the dgenrc.5 manpage
 .
 The person named in the Author field signed this changelog entry.
Author: Edgar Antonio Palma de la Cruz <xbytemx@gmail.com>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- a/pd.h
+++ b/pd.h
@@ -52,6 +52,8 @@
 // This should be a list of all the command-line options specific to this
 // platform, in the form given to getopt(3), i.e "a:b::c".
 extern char *pd_options;
+// This is called once, during startup, before pd_option is.
+void pd_initoptions();
 // And, this is called to handle platform-specific stuff.
 void pd_option(char c, const char *optarg);
 
--- a/dgen.1
+++ b/dgen.1
@@ -35,7 +35,7 @@
 .It Fl P
 Emulate 50Hz PAL mode (as used in European models of the MegaDrive).
 .It Fl R
-If running with root priviledges, set priority to -20, so no other processes
+If running with root priviledges, set priority to \-20, so no other processes
 interrupt (including the X server, which can be a Bad Thing).
 .It Fl f 
 Run fullscreen, if possible.
--- a/romload.c
+++ b/romload.c
@@ -7,6 +7,10 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/wait.h>
 
 static int load_bin_into(char *name,unsigned char *into)
 {
@@ -126,13 +130,32 @@
      (magicbuf[0] == 037 && magicbuf[1] == 0240) || /* LZH        (?)      */
      (magicbuf[0] == 'P' && magicbuf[1] == 'K'))    /* ZIP        (.zip ;) */
     {
-      char temp[0x100], temp2[0x80];
-      srand(time(NULL));
+      char temp[0x100], *temp2;
+      int f;
       /* Run it through gzip (I know this is cheap ;) */
-      sprintf(temp2, "/tmp/dgenrom_%d_%d", rand(), rand());
-      sprintf(temp, "gzip -S \"\" -cdq %s > %s", name, temp2);
-      /* If gzip returned an error, stop */
-      if(system(temp)) { remove(temp2); return -1; };
+      asprintf(&temp2, "/tmp/dgenrom_XXXXXX");
+      f = mkstemp(temp2);
+      if (f == -1) {
+	      perror("mkstemp");
+	      return -1;
+      }
+      close(f);
+
+      f = open(name, O_RDONLY);
+      if (f == -1) {
+	      perror("open");
+	      return -1;
+      }
+      if (dup2(f, 0) == -1) {
+	      perror("dup2");
+	      return -1;
+      }
+      sprintf(temp, "zcat > %s", temp2);
+      if (system(temp)) {
+	      perror("system");
+	      return -1;
+      }
+
       /* Recurse with the new file */
       len = load_rom_into(temp2, into);
       remove(temp2);
@@ -142,14 +165,32 @@
   /* Do bzip2 also */
   if(magicbuf[0] == 'B' && magicbuf[1] == 'Z' && magicbuf[2] == 'h')
     {
+      char temp[0x100], *temp2;
+      int f;
       /* Damn, this looks almost like the gzip stuff above. *lol* :) */
-      char temp[0x100], temp2[0x80];
-      srand(time(NULL));
-      /* Go through bzip2 */
-      sprintf(temp2, "/tmp/dgenrom_%d_%d", rand(), rand());
-      sprintf(temp, "bzip2 -cd %s > %s", name, temp2);
-      /* If we got an error, stop */
-      if(system(temp)) { remove(temp2); return -1; };
+      asprintf(&temp2, "/tmp/dgenrom_XXXXXX");
+      f = mkstemp(temp2);
+      if (f == -1) {
+	      perror("mkstemp");
+	      return -1;
+      }
+      close(f);
+
+      f = open(name, O_RDONLY);
+      if (f == -1) {
+	      perror("open");
+	      return -1;
+      }
+      if (dup2(f, 0) == -1) {
+	      perror("dup2");
+	      return -1;
+      }
+      sprintf(temp, "bzcat > %s", temp2);
+      if (system(temp)) {
+	      perror("system");
+	      return -1;
+      }
+
       /* Recurse with the uncompressed file */
       len = load_rom_into(temp2, into);
       remove(temp2);
@@ -161,7 +202,7 @@
     format = 1;
   /* Otherwise we can only hope it's binary */
   else format = 0;
-	    
+
   switch (format)
   {
     case 1:  return load_smd_into(name,into);
--- a/main.cpp
+++ b/main.cpp
@@ -92,7 +92,7 @@
     { /* Need to strip extension */
     	p = strtok(buf, ".");
     }
-    
+
     if(strchr(buf, '/'))
     { /* Need to strip /path/name */
         p = strtok(buf, "/");
@@ -169,7 +169,7 @@
       sprintf(temp, "Saved state to slot %d.", slot);
       pd_message(temp);
     }
-  else 
+  else
     {
       sprintf(temp, "Couldn't save state to slot %d!", slot);
       pd_message(temp);
@@ -193,7 +193,7 @@
       pd_message(temp);
     }
 }
- 
+
 // Load/save states from file
 static void ram_save(md& megad)
 {
@@ -236,6 +236,8 @@
   // Parse the RC file
   parse_rc(NULL);
 
+  pd_initoptions();
+
   // Check all our options
   strcpy(temp, "s:hvr:n:p:RPjd:D:");
   strcat(temp, pd_options);
@@ -326,7 +328,7 @@
   // BeOS snooze() sleeps in milliseconds, not microseconds
   dgen_nice /= 1000;
 #endif
-  
+
   // There should be a romname after all those options. If not, show help and
   // exit.
   if(optind >= argc)
@@ -388,7 +390,7 @@
   megad.reset();
   // Set PAL mode
   megad.pal = pal_mode;
-  
+
   // Make sure the .dgen hierarchy is setup
   mk_dgendir();
   // Load up save RAM
@@ -483,7 +485,7 @@
   gettimeofday(&endclk, NULL);
   printf("%d frames per second (optimal %d)\n",
 	 (unsigned)(f / (endclk.tv_sec - startclk.tv_sec)), (pal_mode? 50 : 60));
-  
+
   // Cleanup
   if(demo) fclose(demo);
   ram_save(megad);
@@ -493,5 +495,5 @@
   YM2612Shutdown();
 
   // Come back anytime :)
-  return 0; 
+  return 0;
 }
--- a/mkinstalldirs
+++ b/mkinstalldirs
@@ -4,7 +4,7 @@
 # Created: 1993-05-16
 # Public domain
 
-# $Id: mkinstalldirs,v 1.13 1999/01/05 03:18:55 bje Exp $
+# $Id: mkinstalldirs,v 1.1 2002/04/10 19:46:28 joey Rel $
 
 errstatus=0
 
--- a/tobin.1
+++ b/tobin.1
@@ -1,10 +1,10 @@
 .Dd February 21, 2001
 .Dt DGEN 1
 .Sh NAME
-.Nm tobin
+.Nm dgen_tobin
 .Nd Convert SMD-format Genesis/Megadrive image to raw (BIN) format
 .Sh SYNOPSIS
-.Nm tobin
+.Nm dgen_tobin
 .Ar FROMSMD
 .Ar TOBIN
 .Sh DESCRIPTION
@@ -27,4 +27,3 @@
 .An Joe Groff Aq joe@pknet.com .
 .Sh BUGS
 None (yet :-)
-
--- a/dgenrc.5
+++ b/dgenrc.5
@@ -13,7 +13,7 @@
 is parsed by
 .Xr dgen 1
 when the emuator is started. It is used to set controller keys, as well as other
-characteristics of the emulation. The contents of this file may be overriden
+characteristics of the emulation. The contents of this file may be overridden
 with the contents of another similarly-formatted file, via the
 .Fl r
 commandline switch.
@@ -170,7 +170,7 @@
 or any combination thereof, to require that the specified modifier be pressed
 in combination with the key. For example, the identifier "alt-enter" would
 correspond to holding down the Alt key while pressing Enter.
-
+.Pp
 The numbers "0" through "9" ("kp_0" through "kp_9" for the numeric keypad),
 letters "A" through "Z", and function keys "F1" through "F12" map to their key
 equivalents.
@@ -223,18 +223,18 @@
 kp_multiply
 kp_plus
 
-`	~
--	_
-=	+
-\	|
-[	{
-]	}
-:	;
-'	"
-,	<
-\.	>
-/	?
-
+ `	~
+ -	_
+ =	+
+ \\	|
+ [	{
+ ]	}
+ :	;
+ '	"
+ ,	<
+ .	>
+ /	?
+.Ed
 .Sh SEE ALSO
 .Xr dgen 1
 .Sh AUTHORS
--- a/musa/m68kmake.c
+++ b/musa/m68kmake.c
@@ -1029,9 +1029,10 @@
 	fprintf(filep, "/* ========================= OPCODE TABLE BUILDER ========================= */\n");
 	fprintf(filep, "/* ======================================================================== */\n\n");
 
+	fprintf(filep, "#include <stdlib.h>\n\n"); /* moved here for gcc 4.0 */
 	fprintf(filep, "#include \"m68kops.h\"\n");
 	fprintf(filep, "#include \"m68kcpu.h\"\n");
-	fprintf(filep, "#include <stdlib.h>\n\n");
+	/*fprintf(filep, "#include <stdlib.h>\n\n");*/
 	fprintf(filep, "#include <string.h>\n\n");
 
 	fprintf(filep, "extern void  (*m68k_instruction_jump_table[])(void); /* opcode handler jump table */\n\n");
--- a/star/star.c
+++ b/star/star.c
@@ -1931,7 +1931,6 @@
 	case aind: case ainc: case adec:
 	case adsp: case axdp:
 		usereg();
-	default:
 	}
 }
 
--- a/sdl/sdl.cpp
+++ b/sdl/sdl.cpp
@@ -157,13 +157,15 @@
   );
 }
 
+void pd_initoptions()
+{
+	fullscreen = dgen_fullscreen;
+	x_scale = y_scale = dgen_scale;
+}
+
 // Handle the switches
 void pd_option(char c, const char *)
 {
-  // Set stuff up from the rcfile first, so we can override it with commandline
-  // options
-  fullscreen = dgen_fullscreen;
-  x_scale = y_scale = dgen_scale;
 #ifdef SDL_OPENGL_SUPPORT
   opengl = dgen_opengl;
   if(opengl)
