diff -Nru xmame-0.106/makefile.unix.orig xmame-0.106/makefile.unix
--- xmame-0.106/makefile.unix.orig	2007-12-07 22:34:43.000000000 -0800
+++ xmame-0.106/makefile.unix	2007-12-07 22:34:57.000000000 -0800
@@ -97,7 +97,7 @@
 # just as well.  However, stay away from the `cc' Ultrix compiler if 
 # possible.
 
-CC	= @gcc
+CC	= @gcc -m32
 # CC    = @cc
 # CC	= @icc
 # CC	= @c89
diff -Nru xmame-0.101.orig/src/core.mak xmame-0.101/src/core.mak
--- xmame-0.101.orig/src/core.mak	2005-10-12 22:39:20.000000000 -0700
+++ xmame-0.101/src/core.mak	2005-11-12 09:21:20.000000000 -0800
@@ -16,6 +16,7 @@
 	$(OBJ)/hash.o \
 	$(OBJ)/hiscore.o \
 	$(OBJ)/info.o \
+	$(OBJ)/infofile.o \
 	$(OBJ)/input.o \
 	$(OBJ)/inptport.o \
 	$(OBJ)/mame.o \
diff -Nru xmame-0.101.orig/src/drivers/namcos12.c xmame-0.101/src/drivers/namcos12.c
--- xmame-0.101.orig/src/drivers/namcos12.c	2005-10-12 22:39:21.000000000 -0700
+++ xmame-0.101/src/drivers/namcos12.c	2005-11-12 09:21:20.000000000 -0800
@@ -968,6 +971,9 @@
 	struct tm *exptime;
 	static int weekday[7] = { 7, 1, 2, 3, 4, 5, 6 };
 
+	if (Machine->record_file || Machine->playback_file)
+			  return 0; // keep time seeds static when recording/playingback;
+
 	time(&curtime);
 	exptime = localtime(&curtime);
 
diff -Nru xmame-0.101.orig/src/drivers/othldrby.c xmame-0.101/src/drivers/othldrby.c
--- xmame-0.101.orig/src/drivers/othldrby.c	2005-10-12 22:39:21.000000000 -0700
+++ xmame-0.101/src/drivers/othldrby.c	2005-11-12 09:21:20.000000000 -0800
@@ -69,6 +71,8 @@
 	time_t ltime;
 	struct tm *today;
 
+	if (Machine->record_file || Machine->playback_file)
+			  return 0; // Keep time static when recording or playing back
 
 	time(&ltime);
 	today = localtime(&ltime);
diff -Nru xmame-0.101.orig/src/drivers/pgm.c xmame-0.101/src/drivers/pgm.c
--- xmame-0.101.orig/src/drivers/pgm.c	2005-10-12 22:39:21.000000000 -0700
+++ xmame-0.101/src/drivers/pgm.c	2005-11-12 09:21:20.000000000 -0800
@@ -427,6 +429,8 @@
 				today = localtime(&ltime);
 				break;
 		}
+		if (Machine->record_file || Machine->playback_file)
+			CalVal = 1;
 	}
 }
 
diff -Nru xmame-0.101.orig/src/drivers/rohga.c xmame-0.101/src/drivers/rohga.c
--- xmame-0.101.orig/src/drivers/rohga.c	2005-10-12 22:39:21.000000000 -0700
+++ xmame-0.101/src/drivers/rohga.c	2005-11-12 09:21:20.000000000 -0800
@@ -356,7 +356,7 @@
 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 )
 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 )
 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 )
-	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )
+	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 ) PORT_IMPULSE(1)
 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
@@ -364,7 +364,7 @@
 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
-	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )
+	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 ) PORT_IMPULSE(1)
 
 	PORT_START
 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
@@ -454,7 +454,7 @@
 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 )
 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 )
 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED )
-	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )
+	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 ) PORT_IMPULSE(1)
 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
@@ -462,7 +462,7 @@
 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNUSED )
-	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )
+	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 ) PORT_IMPULSE(1)
 
 	PORT_START
 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
@@ -527,7 +527,7 @@
 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 )
 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 )
 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED )
-	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )
+	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 ) PORT_IMPULSE(1)
 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
@@ -535,7 +535,7 @@
 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNUSED )
-	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )
+	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 ) PORT_IMPULSE(1)
 
 	PORT_START
 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
@@ -611,7 +611,7 @@
 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 )
 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 )
 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 )
-	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )
+	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 ) PORT_IMPULSE(1)
 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
@@ -619,7 +619,7 @@
 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
-	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )
+	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 ) PORT_IMPULSE(1)
 
 	PORT_START
 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
diff -Nru xmame-0.101.orig/src/drivers/stv.c xmame-0.101/src/drivers/stv.c
--- xmame-0.101.orig/src/drivers/stv.c	2005-10-12 22:39:21.000000000 -0700
+++ xmame-0.101/src/drivers/stv.c	2005-11-12 09:21:20.000000000 -0800
@@ -172,6 +172,9 @@
 extern UINT32* stv_vdp2_cram;
 extern UINT32* stv_vdp1_vram;
 
+//extern void *record;
+//extern void *playback;
+
 #define USE_SLAVE 1
 /*Enable the following to play 'myfairld' without using the -nosound switch.*/
 #define UGLY_SOUND_HACK 0
@@ -325,6 +328,8 @@
 {
 	int i, cnt = 0, tmp, res = 0;
 
+	if (Machine->playback_file || Machine->record_file)
+		return 0;
 	while (num > 0) {
 		tmp = num;
 		while (tmp >= 10) tmp %= 10;
@@ -2141,7 +2146,10 @@
 				smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
 			  	smpc_ram[0x23] = DectoBCD((today->tm_year + 1900)/100);
 		    	smpc_ram[0x25] = DectoBCD((today->tm_year + 1900)%100);
-	    		smpc_ram[0x27] = (today->tm_wday << 4) | (today->tm_mon+1);
+				if (Machine->playback_file || Machine->record_file)
+		    		smpc_ram[0x27] = 0;
+				else
+		    		smpc_ram[0x27] = (today->tm_wday << 4) | (today->tm_mon+1);
 		    	smpc_ram[0x29] = DectoBCD(today->tm_mday);
 		    	smpc_ram[0x2b] = DectoBCD(today->tm_hour);
 		    	smpc_ram[0x2d] = DectoBCD(today->tm_min);
@@ -4181,7 +4189,10 @@
 
   	smpc_ram[0x23] = DectoBCD((today->tm_year + 1900)/100);
     smpc_ram[0x25] = DectoBCD((today->tm_year + 1900)%100);
-    smpc_ram[0x27] = (today->tm_wday << 4) | (today->tm_mon+1);
+	 if (Machine->playback_file || Machine->record_file)
+	    smpc_ram[0x27] = 0;
+	 else
+	    smpc_ram[0x27] = (today->tm_wday << 4) | (today->tm_mon+1);
     smpc_ram[0x29] = DectoBCD(today->tm_mday);
     smpc_ram[0x2b] = DectoBCD(today->tm_hour);
     smpc_ram[0x2d] = DectoBCD(today->tm_min);
diff -Nru xmame-0.101.orig/src/drivers/suprnova.c xmame-0.101/src/drivers/suprnova.c
--- xmame-0.101.orig/src/drivers/suprnova.c	2005-10-12 22:39:21.000000000 -0700
+++ xmame-0.101/src/drivers/suprnova.c	2005-11-12 09:21:20.000000000 -0800
@@ -791,7 +791,7 @@
 	long value;
 
 	if (Machine->record_file != NULL || Machine->playback_file != NULL)
-		return 0;
+		return 0x00010001;
 
 	time(&tms);
 	tm = localtime(&tms);
diff -Nru xmame-0.101.orig/src/fileio.c xmame-0.101/src/fileio.c
--- xmame-0.101.orig/src/fileio.c	2005-10-12 22:39:22.000000000 -0700
+++ xmame-0.101/src/fileio.c	2005-11-12 09:21:20.000000000 -0800
@@ -212,6 +212,9 @@
 		case FILETYPE_INPUTLOG:
 			return generic_fopen(filetype, NULL, gamename, 0, openforwrite ? FILEFLAG_OPENWRITE : FILEFLAG_OPENREAD, error);
 
+		case FILETYPE_WLF:
+			return generic_fopen(filetype, NULL, gamename, 0, openforwrite ? FILEFLAG_OPENWRITE : FILEFLAG_OPENREAD, error);
+
 		/* save state files */
 		case FILETYPE_STATE:
 #ifndef MESS
@@ -851,6 +854,10 @@
 			extension = "inp";
 			break;
 
+		case FILETYPE_WLF:
+			extension = "wlf";
+			break;
+
 		case FILETYPE_STATE:		/* save state files */
 			extension = "sta";
 			break;
diff -Nru xmame-0.101.orig/src/fileio.h xmame-0.101/src/fileio.h
--- xmame-0.101.orig/src/fileio.h	2005-10-12 22:39:22.000000000 -0700
+++ xmame-0.101/src/fileio.h	2005-11-12 09:21:20.000000000 -0800
@@ -42,6 +42,7 @@
 	FILETYPE_COMMENT,
 	FILETYPE_DEBUGLOG,
 	FILETYPE_HASH,	/* MESS-specific */
+	FILETYPE_WLF,
 	FILETYPE_end 	/* dummy last entry */
 };
 
diff -Nru xmame-0.101.orig/src/infofile.c xmame-0.101/src/infofile.c
--- xmame-0.101.orig/src/infofile.c	1969-12-31 16:00:00.000000000 -0800
+++ xmame-0.101/src/infofile.c	2005-11-12 09:21:20.000000000 -0800
@@ -0,0 +1,282 @@
+// infofile.c  -- stores various info about a MAME inp recording, the
+//                settings used and the system it was recorded on.
+// This source is to be kept private - DO NOT DISTRIBUTE!
+
+// Last update: 31 Aug, 2005
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "osdepend.h"  // for the inp header structure
+#include "fileio.h"  // for INP file reading functions
+#include "infofile.h"
+
+mame_file* infofile;
+static char filename[200];
+extern char build_version[];
+
+struct infodata
+{
+	char header[3];  // 3 character ID - "WLF" for now
+	int rev;  // File format revision
+	char shortname[9]; // MAME game's shortname (wow, that rhymes!)
+	char version[80]; // version string, copied from build_version[]
+	int cpuvendor;  // as in the INP header:
+	                //  1 = Intel, 2 = AMD, 3 = Transmeta,
+	                //  4 = Cyrix, 0 = Unknown.  
+	                // Other CPUs could be added here for other systems
+	                // ie: if Rick ever gets off his ass and does a Mac version ;)
+	long cputype;  // stores the CPU family/model info.  Just a copy of 
+	               // what is returned in EAX after CPUID function 1.
+                   // Determining the exact CPU type from here is beyond the
+	               // scope of this code.  External apps can do that for us.
+	INT64 cpuspeed;  // approximate CPU speed in Hz
+	int ostype;  // 0 = Windows, 1 = Windows NT, 2 = Win32s (yeah, right)
+	int osvermin; // OS version - NT4 = 4.0, Win95 = 4.0, Win98 = 4.10,
+	int osvermaj; // WinMe = 4.90, Win2k = 5.0, WinXP = 5.1, Server 2003 = 5.2
+	char osstring[128];  // extra OS string: "C" for Win95OSR2, "A" for Win98se,
+	                                     //  "Service Pack X" for WinNT 
+	long starttime;  // recording start time/date
+	long endtime;  // recording end time/date
+	long framecount;  // number of frames in recording
+	double avgspeed;  // average recorded speed
+	char biosstr[20];  // BIOS string, from -bios switch
+	int optsize; // size of the global_options
+	global_options opt;  // MAME global_options
+	short headercheck1;
+	short headercheck2;
+	short infocheck;  // redundancy check for the infofile
+} info;
+
+void getcpuvendor(char* v)
+{
+	char vendor[13];
+	long val1,val2,val3;
+	int i;
+	char* ptr;
+
+#ifdef _MSC_VER
+	__asm
+	{
+		mov eax,0
+		cpuid
+		mov val1,ebx
+		mov val2,edx
+		mov val3,ecx
+	}
+#else
+	// use CPUID
+	__asm__ __volatile__ (
+		"movl $0,%%eax\n\t" \
+		"cpuid"
+		: "=b" (val1), "=d" (val2), "=c" (val3)
+	);
+#endif
+	
+	for(i=0;i<4;i++)
+	{
+		ptr = (char*)&val1;
+		vendor[i] = (char)*(ptr+i);
+		ptr = (char*)&val2;
+		vendor[i+4] = (char)*(ptr+i);
+		ptr = (char*)&val3;
+		vendor[i+8] = (char)*(ptr+i);
+	}
+	vendor[12] = '\0'; // Terminate string with NULL
+	strcpy(v,vendor);
+}
+
+long getcpufamily(void)
+{
+	long cpuinfo;
+
+#ifdef _MSC_VER
+	__asm
+	{
+		mov ecx,0x119  
+		rdmsr
+		and eax,0xffdfffff
+		wrmsr  // disable CPU serial number on P3 CPUs
+		mov eax,$1
+		cpuid
+		mov cpuinfo,eax
+	}
+#else
+/*	if(info.cpuvendor == 1) // Intel CPU
+	{
+		__asm__ __volatile__
+		(
+			"movl 0x119,%ecx\n\t"      \
+			"rdmsr\n\t"                \
+			"andl 0xffdfffff,%eax\n\t"  \
+			"wrmsr\n\t"
+		);
+	}*/
+
+	__asm__ __volatile__
+	(
+		"movl $1,%%eax\n\t"        \
+		"cpuid"
+		: "=a" (cpuinfo)
+	);
+#endif
+
+	return cpuinfo;
+}
+
+int infoRead(global_options* o)
+{
+	char fullname[250];
+
+	strcpy(fullname,filename);
+//	strcat(fullname,".wlf");
+	infofile = mame_fopen(fullname,NULL,FILETYPE_WLF,0);
+	if(infofile == NULL)
+		return 0;
+
+	mame_fread(infofile,&info,sizeof(struct infodata));
+	mame_fclose(infofile);
+
+	o->cheat = info.opt.cheat;
+	o->gui_host = info.opt.gui_host;
+	o->skip_disclaimer = info.opt.skip_disclaimer;
+	o->skip_gameinfo = info.opt.skip_gameinfo;
+	o->skip_warnings = info.opt.skip_warnings;
+	o->samplerate = info.opt.samplerate;
+	o->use_samples = info.opt.use_samples;
+
+	/* not  possible with xmame, since 68 is not option
+	o->use_filter = info.opt.use_filter;
+#if defined(A68K0)
+	o->m68k_core = 1;
+#else
+	o->m68k_core = 0;
+#endif
+	*/
+
+	o->allownvram = info.opt.allownvram;
+
+	return 1;
+}
+
+int infoWrite(void)
+{
+	char fullname[250];
+	char vendor[13];
+	mame_file* inpfile;
+	inp_header* hdr;
+	unsigned short chk;
+	short* ptr;
+	int a;
+
+	// Allocate RAM for header
+	hdr = malloc(sizeof(inp_header));
+
+	strcpy(fullname,filename);
+//	strcat(fullname,".wlf");
+	infofile = mame_fopen(fullname,NULL,FILETYPE_WLF,1);
+	if(infofile == NULL)
+		return 0;
+
+	// header
+	strcpy(info.header,"WLF");
+	info.rev = 8;
+
+	// MAME version string
+	strcpy(info.version,build_version);
+
+	// CPU info
+	getcpuvendor(vendor);
+	if(strcmp(vendor,"GenuineIntel") == 0)
+		info.cpuvendor = 1;  // Intel CPU
+	if(strcmp(vendor,"AuthenticAMD") == 0)
+		info.cpuvendor = 2;  // AMD CPU
+	if(strcmp(vendor,"GenuineTMx86") == 0)
+		info.cpuvendor = 3;  // Transmeta CPU
+	if(strcmp(vendor,"CyrixInstead") == 0)
+		info.cpuvendor = 4;  // Cyrix CPU
+
+	info.cputype = getcpufamily();
+
+	// OS info
+		info.ostype = 5;  // Linux
+
+	info.osvermin = 0;
+	info.osvermaj = 0;
+	strcpy(info.osstring,"\0");
+
+	// INP and WLF file validity checks
+	sprintf(fullname,"%s.inp",filename);
+	inpfile = mame_fopen(filename,0,FILETYPE_INPUTLOG,0);
+	if(inpfile == NULL)
+		return 0;
+
+	mame_fread(inpfile,hdr,sizeof(inp_header));
+	info.headercheck1 = hdr->check;
+
+	mame_fseek(inpfile,0,SEEK_SET);
+
+	while(mame_fread(inpfile,&chk,2) != 0)
+	{
+		info.headercheck2 += chk;
+	}
+
+	mame_fclose(inpfile);
+
+	chk = 0;
+	ptr = (short*)&info;
+	for(a=0;a<(sizeof(struct infodata)/2)-4;a++)
+		chk+=(short)*(ptr+a);
+	info.infocheck = chk;
+
+	// write file
+	mame_fwrite(infofile,&info,sizeof(struct infodata));
+	mame_fclose(infofile);
+
+	// Free allocated RAM for header
+	free(hdr);
+
+	return 1;
+}
+
+void infoSetFilename(char* name)
+{
+	strcpy(filename,name);
+}
+
+void infoSetOptions(global_options* o)
+{
+	memcpy(&(info.opt),o,sizeof(global_options));
+	info.optsize = sizeof(global_options);
+}
+
+void infoSetTimeStart(long t)
+{
+	info.starttime = t;
+}
+
+void infoSetTimeEnd(long t)
+{
+	info.endtime = t;
+}
+
+void infoSetShortName(const char* name)
+{
+	strcpy(info.shortname,name);
+}
+
+void infoSetSpeed(INT64 spd)
+{
+	info.cpuspeed = spd;
+}
+
+void infoSetFrameCount(long f, double spd)
+{
+	info.framecount = f;
+	info.avgspeed = spd;
+}
+
+void infoSetBIOSString(char* str)
+{
+	strcpy(info.biosstr,str);
+}
diff -Nru xmame-0.101.orig/src/infofile.h xmame-0.101/src/infofile.h
--- xmame-0.101.orig/src/infofile.h	1969-12-31 16:00:00.000000000 -0800
+++ xmame-0.101/src/infofile.h	2005-11-12 09:21:20.000000000 -0800
@@ -0,0 +1,25 @@
+// infofile header
+
+#include "mame.h"
+
+// Function prototypes
+
+int infoRead(global_options*);
+
+int infoWrite(void);
+
+void infoSetFilename(char*);
+
+void infoSetOptions(global_options*);
+
+void infoSetTimeStart(long);
+
+void infoSetTimeEnd(long);
+
+void infoSetShortName(const char*);
+
+void infoSetSpeed(INT64);
+
+void infoSetFrameCount(long,double);  // and speed too :)
+
+void infoSetBIOSString(char* str);
diff -Nru xmame-0.101.orig/src/inptport.c xmame-0.101/src/inptport.c
--- xmame-0.101.orig/src/inptport.c	2005-10-12 22:39:22.000000000 -0700
+++ xmame-0.101/src/inptport.c	2005-11-12 09:21:20.000000000 -0800
@@ -92,6 +92,7 @@
 #include "xmlfile.h"
 #include "profiler.h"
 #include <math.h>
+#include "ui_text.h"
 
 #ifdef MESS
 #include "inputx.h"
@@ -259,7 +260,22 @@
 /* original input_ports without modifications */
 input_port_entry *input_ports_default;
 
+int pbackNotEof=0;
 
+// W: game speed storage
+unsigned long framer;
+static unsigned long hold;
+#define WOLFMASK 0xe143823e 
+
+// W: Average speed calculation
+double speed_total;
+unsigned int speed_counter;
+
+// W: For regular INP usage
+int isnotwolf;
+
+// W: For input view
+char inputstr[80];
 
 
 /*************************************
@@ -962,6 +979,12 @@
 	/* reset the port info */
 	memset(port_info, 0, sizeof(port_info));
 
+	/* W: setting playback flag that can get turned off at eof */
+	if (Machine->playback_file)
+		pbackNotEof = 1;
+	else
+		pbackNotEof = 0;
+
 	/* if we have inputs, process them now */
 	if (construct_ipt)
 	{
@@ -1096,9 +1119,6 @@
 						break;
 
 					/* dials, mice and trackballs are relative devices */
-					/* these have fixed "min" and "max" values based on how many bits are in the port */
-					/* in addition, we set the wrap around min/max values to 512 * the min/max values */
-					/* this takes into account the mapping that one mouse unit ~= 512 analog units */
 					case IPT_DIAL:
 					case IPT_DIAL_V:
 					case IPT_MOUSE_X:
@@ -1108,8 +1128,6 @@
 						info->absolute = 0;
 						port->analog.min = 0;
 						port->analog.max = (1 << info->bits) - 1;
-						info->minimum = 0;
-						info->maximum = port->analog.max * 512;
 						break;
 
 					default:
@@ -1132,11 +1150,14 @@
 					}
 				}
 
-				/* relative controls all map directly with a 512x scale factor */
 				else
-					info->scalepos = info->scaleneg = 1.0 / 512.0;
+				{
+					if (port->analog.max > port->analog.min)
+						info->scalepos = info->scaleneg = (double)(port->analog.max - port->analog.min) / (double)(ANALOG_VALUE_MAX - ANALOG_VALUE_MIN);
+					else
+						info->scalepos = info->scaleneg = (double)((INT32)((port->analog.max - port->analog.min) << (32 - info->bits)) >> (32 - info->bits)) / (double)(ANALOG_VALUE_MAX - ANALOG_VALUE_MIN);
+				}
 
-				/* compute scale for keypresses */
 				info->keyscale = 1.0 / (0.5 * (info->scalepos + info->scaleneg));
 
 				/* hook in the list */
@@ -1976,22 +1997,25 @@
 	/* handle playback */
 	if (Machine->playback_file != NULL)
 	{
-		UINT32 result;
-
-		/* a successful read goes into the playback field which overrides everything else */
-		if (mame_fread(Machine->playback_file, &result, sizeof(result)) == sizeof(result))
-			portvalue = port_info[portnum].playback = BIG_ENDIANIZE_INT32(result);
-
-		/* a failure causes us to close the playback file and stop playback */
-		else
+		if (pbackNotEof)
 		{
-			mame_fclose(Machine->playback_file);
-			Machine->playback_file = NULL;
+			UINT32 result;
+
+			/* a successful read goes into the playback field which overrides everything else */
+			if (mame_fread(Machine->playback_file, &result, sizeof(result)) == sizeof(result))
+				port_info[portnum].playback = BIG_ENDIANIZE_INT32(result);
+	
+			/* a failure causes us to close the playback file and stop playback */
+			else
+			{
+				mame_fclose(Machine->playback_file);
+				Machine->playback_file = NULL;
+			}
 		}
 	}
 
 	/* handle recording */
-	if (Machine->record_file != NULL)
+	else if (Machine->record_file != NULL)
 	{
 		UINT32 result = BIG_ENDIANIZE_INT32(portvalue);
 
@@ -2160,6 +2184,148 @@
 			update_playback_record(portnum, readinputport(portnum));
 	}
 
+	// portnum is now one beyond normal mame ports
+	// now do something with the final wolf port
+	if (Machine->playback_file)
+	{
+		if (pbackNotEof)
+		{
+			UINT32 result;
+
+			mame_fread(Machine->playback_file, &result, sizeof(result));
+			framer = result; /*BIG_ENDIANIZE_INT32(result);*/
+			if (!mame_feof(Machine->playback_file))
+			{
+				++speed_counter;
+				speed_total += (framer - WOLFMASK);
+			}
+			else
+			{
+				pbackNotEof = 0;
+				ui_popup("End of playback");
+#ifdef AUTO_PAUSE_PLAYBACK
+				if (options.auto_pause_playback)
+					ui_auto_pause();
+#endif
+			}
+		}
+	}
+	else if (Machine->record_file)
+	{
+		// framer is speed writen somewhere else
+		hold = WOLFMASK + framer;
+		// so average speed can be calculated for .wlf file
+		++speed_counter;
+		speed_total += framer;
+		UINT32 result = hold; /*BIG_ENDIANIZE_INT32(hold);*/
+		mame_fwrite(Machine->record_file, &result, sizeof(result));
+	}
+
+	memset(inputstr,32,79);
+	inputstr[79] = '\0';
+	for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
+	{
+		input_bit_info *info;
+		input_port_info *portinfo = &port_info[portnum];
+		for (bitnum = 0, info = &portinfo->bit[0]; bitnum < MAX_BITS_PER_PORT && info->port; bitnum++, info++)
+		{
+			input_port_entry *port = info->port;
+			unsigned long portval=0;
+
+			if(port->player == options.inpview - 1)
+			{
+			  const char *uparrow = ui_getstring (UI_uparrow);
+			  const char *downarrow = ui_getstring (UI_downarrow);
+			  const char *leftarrow = ui_getstring (UI_righthilight);
+			  const char *rightarrow = ui_getstring (UI_lefthilight);
+
+				if(Machine->playback_file)
+					portval = portinfo->playback ^ 0xffff;
+				else
+					portval = portinfo->digital;
+
+			  if(port->type == IPT_JOYSTICK_LEFT && (portval
+				& port->mask) == (port->default_value & port->mask))
+			  {
+				inputstr[2] = *leftarrow;
+//			      inputstr[3] = '4';
+			  }
+			  if(port->type == IPT_JOYSTICK_UP && (portval
+				& port->mask) == (port->default_value & port->mask))
+			  {
+				inputstr[4] = *uparrow;
+//			      inputstr[5] = '8';
+			  }
+			  if(port->type == IPT_JOYSTICK_RIGHT && (portval
+				& port->mask) == (port->default_value & port->mask))
+			  {
+				inputstr[6] = *rightarrow;
+//				inputstr[7] = '6';
+			  }
+			  if(port->type == IPT_JOYSTICK_DOWN && (portval
+				& port->mask) == (port->default_value & port->mask))
+			  {
+				inputstr[8] = *downarrow;
+//			      inputstr[9] = '2';
+			  }
+			  if(port->type == IPT_BUTTON1 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[12] = '1';
+			  if(port->type == IPT_BUTTON2 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[13] = '2';
+			  if(port->type == IPT_BUTTON3 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[14] = '3';
+			  if(port->type == IPT_BUTTON4 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[15] = '4';
+			  if(port->type == IPT_BUTTON5 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[16] = '5';
+			  if(port->type == IPT_BUTTON6 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[17] = '6';
+			  if(port->type == IPT_BUTTON7 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[18] = '7';
+			  if(port->type == IPT_BUTTON8 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[19] = '8';
+			  if(port->type == IPT_BUTTON9 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[20] = '9';
+			  if(port->type == IPT_BUTTON10 && (portval
+				& port->mask) == (port->default_value & port->mask))
+				inputstr[21] = '0';
+			}
+			if(port->type == IPT_START1 && (portval
+				& port->mask) == (port->default_value & port->mask))
+			{
+				inputstr[24] = '1';
+				inputstr[25] = 'P';
+			}
+			if(port->type == IPT_START2 && (portval
+				& port->mask) == (port->default_value & port->mask))
+			{
+				inputstr[27] = '2';
+				inputstr[28] = 'P';
+			}
+			if(port->type == IPT_START3 && (portval
+			& port->mask) == (port->default_value & port->mask))
+			{
+				inputstr[30] = '3';
+				inputstr[31] = 'P';
+			}
+			if(port->type == IPT_START4 && (portval
+				& port->mask) == (port->default_value & port->mask))
+			{
+				inputstr[33] = '4';
+				inputstr[34] = 'P';
+			}
+		}
+	}
+
 profiler_mark(PROFILER_END);
 }
 
diff -Nru xmame-0.101.orig/src/machine/midwayic.c xmame-0.101/src/machine/midwayic.c
--- xmame-0.101.orig/src/machine/midwayic.c	2005-10-12 22:39:22.000000000 -0700
+++ xmame-0.101/src/machine/midwayic.c	2005-11-12 09:21:20.000000000 -0800
@@ -29,6 +29,9 @@
 #define FIFO_SIZE			512
 
 
+//extern void *record;
+//extern void *playback;
+
 
 /*************************************
  *
@@ -363,13 +366,26 @@
 					time(&curtime);
 					exptime = localtime(&curtime);
 
-					pic.buffer[pic.total++] = make_bcd(exptime->tm_sec);
-					pic.buffer[pic.total++] = make_bcd(exptime->tm_min);
-					pic.buffer[pic.total++] = make_bcd(exptime->tm_hour);
-					pic.buffer[pic.total++] = make_bcd(exptime->tm_wday + 1);
-					pic.buffer[pic.total++] = make_bcd(exptime->tm_mday);
-					pic.buffer[pic.total++] = make_bcd(exptime->tm_mon + 1);
-					pic.buffer[pic.total++] = make_bcd(exptime->tm_year - pic.yearoffs);
+					if (Machine->playback_file || Machine->record_file)
+					{
+						pic.buffer[pic.total++] = 0;
+						pic.buffer[pic.total++] = 0;
+						pic.buffer[pic.total++] = 0;
+						pic.buffer[pic.total++] = 0;
+						pic.buffer[pic.total++] = 0;
+						pic.buffer[pic.total++] = 0;
+						pic.buffer[pic.total++] = 0;
+					}
+					else
+					{
+						pic.buffer[pic.total++] = make_bcd(exptime->tm_sec);
+						pic.buffer[pic.total++] = make_bcd(exptime->tm_min);
+						pic.buffer[pic.total++] = make_bcd(exptime->tm_hour);
+						pic.buffer[pic.total++] = make_bcd(exptime->tm_wday + 1);
+						pic.buffer[pic.total++] = make_bcd(exptime->tm_mday);
+						pic.buffer[pic.total++] = make_bcd(exptime->tm_mon + 1);
+						pic.buffer[pic.total++] = make_bcd(exptime->tm_year - pic.yearoffs);
+					}
 				}
 
 				/* otherwise, just parrot back what was written to pass self tests */
diff -Nru xmame-0.101.orig/src/mame.c xmame-0.101/src/mame.c
--- xmame-0.101.orig/src/mame.c	2005-10-16 22:05:54.000000000 -0700
+++ xmame-0.101/src/mame.c	2005-11-12 09:21:20.000000000 -0800
@@ -256,6 +256,8 @@
 
 ***************************************************************************/
 
+extern void writeInpStartTime(void);
+
 /*-------------------------------------------------
     run_game - run the given game in a session
 -------------------------------------------------*/
@@ -316,6 +318,9 @@
 			/* to clear out resources allocated between resets */
 			begin_resource_tracking();
 
+			if (!Machine->playback_file && Machine->record_file)
+				writeInpStartTime();
+
 			/* perform a soft reset -- this takes us to the running phase */
 			soft_reset(0);
 
@@ -449,7 +454,7 @@
 	*cur = cb;
 }
 
-
+extern void writeInpStartTime(void);
 
 /***************************************************************************
 
diff -Nru xmame-0.101.orig/src/mame.h xmame-0.101/src/mame.h
--- xmame-0.101.orig/src/mame.h	2005-10-16 22:06:02.000000000 -0700
+++ xmame-0.101/src/mame.h	2005-11-12 09:21:20.000000000 -0800
@@ -242,6 +242,8 @@
 	int		min_width;		/* minimum width for the display */
 	int		min_height;		/* minimum height for the display */
 #endif /* MESS */
+	int		allownvram; /* allows NVRAM to be used when recording or playing INPs */
+	int		inpview; /* enables input viewing and determines which player's to show */
 };
 typedef struct _global_options global_options;
 
diff -Nru xmame-0.101.orig/src/osdepend.h xmame-0.101/src/osdepend.h
--- xmame-0.101.orig/src/osdepend.h	2005-10-12 22:39:22.000000000 -0700
+++ xmame-0.101/src/osdepend.h	2005-11-12 09:21:20.000000000 -0800
@@ -226,7 +226,14 @@
 {
 	char name[9];      /* 8 bytes for game->name + NUL */
 	char version[3];   /* byte[0] = 0, byte[1] = version byte[2] = beta_version */
-	char reserved[20]; /* for future use, possible store game options? */
+	char options;  /* Store some options */
+	char fskip;    /* Store fskip value */
+	char options2; /* more gameoptions Bit 0: Sound Enabled */
+	char cputype; /* Intel/AMD CPU type */
+	INT64 spd;  /* recorded clock speed */
+	long starttime; /* date/time INP was started */
+	short endtime; /* date/time INP was started */
+	unsigned short check;  /* checksum */
 };
 typedef struct _inp_header inp_header;
 
diff -Nru xmame-0.101.orig/src/sound/pokey.c xmame-0.101/src/sound/pokey.c
--- xmame-0.101.orig/src/sound/pokey.c	2005-10-12 22:39:21.000000000 -0700
+++ xmame-0.101/src/sound/pokey.c	2005-11-12 09:21:20.000000000 -0800
@@ -49,6 +49,7 @@
 
 #include "driver.h"
 #include "pokey.h"
+//#include "machine/random.h"
 
 /*
  * Defining this produces much more (about twice as much)
@@ -903,7 +904,7 @@
          ****************************************************************/
 		if( p->SKCTL & SK_RESET )
 		{
-			adjust = (UINT32)(timer_timeelapsed(p->rtimer) * p->clock + 0.5);
+			adjust = mame_rand();
 			p->r9 = (p->r9 + adjust) % 0x001ff;
 			p->r17 = (p->r17 + adjust) % 0x1ffff;
 		}
diff -Nru xmame-0.101.orig/src/unix/config.c xmame-0.101/src/unix/config.c
--- xmame-0.101.orig/src/unix/config.c	2005-10-16 22:12:33.000000000 -0700
+++ xmame-0.101/src/unix/config.c	2005-11-12 17:57:17.000000000 -0800
@@ -13,6 +13,9 @@
 #include "sysdep/sysdep_dsp.h"
 #include "sysdep/sysdep_mixer.h"
 #include "sysdep/misc.h"
+#include "infofile.h"
+
+//extern int global_sound_enabled;
 
 /* be sure that device names are nullified */
 extern void XInput_trackballs_reset();
@@ -24,6 +27,12 @@
 extern char *playbackname;
 extern char *recordname;
 
+#include <time.h>
+extern int frameskip;
+//W: for regular INP usage
+extern int isnotwolf;
+static int override;
+
 /* some local vars */
 static int showconfig = 0;
 static int showmanusage = 0;
@@ -111,6 +120,9 @@
 #endif
 	{ NULL, NULL, rc_link, frontend_list_opts, NULL, 0, 0, NULL, NULL },
 	{ NULL, NULL, rc_link, frontend_ident_opts, NULL, 0, 0, NULL, NULL },
+	{ "allownvram", "allownv", rc_bool, &options.allownvram, "0", 0, 0, NULL, "Allow the use of NVRAM when recording or playing back INPs" },
+	{ "inpview", "iv", rc_int, &options.inpview, "0", 0, 0, NULL, "Shows a certain play's input on screen in real-time (default 0=disable)" },
+	{ "override", NULL, rc_bool, &override, "0", 0, 0, NULL, "Overrides the default action of forcing the use of certain options that were used when recording an INP" },
 	{ "General Options", NULL, rc_seperator, NULL, NULL, 0, 0, NULL, NULL },
 	{ "loadconfig", "lcf", rc_bool, &loadconfig, "1", 0, 0, NULL, "Load (don't load) configfiles" },
 	{ "showconfig", "sc", rc_set_int, &showconfig, NULL, 1, 0, NULL, "Display running parameters in rc style" },
@@ -224,6 +236,26 @@
 }
 #endif /* MESS */
 
+//
+//// might also get it from fgrep "cpu MHz :" "/proc/cpuinfo"
+////
+////
+////
+///* ONLY WORKS FOR X86 cpus!!!!!!!!!!! */
+//
+
+__inline__ unsigned long long int rdtsc()
+{
+   unsigned long long int x;
+   __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
+   return x;
+}
+
+// value of the first SoundNcpu short bits
+static short firstPassSoundNcpu;
+// the check sum of the first header
+static long firstPassCheck;
+
 /*
  * get configuration from configfile and env.
  */
@@ -386,8 +418,69 @@
 	{
 		inp_header inp_header;
 
+		int a,oldwolf=0;
+		unsigned short chk = 0;
+		short* ptr;
+
+		infoSetFilename(playbackname);
+
 		/* read playback header */
+		isnotwolf = 0;
 		mame_fread(options.playback, &inp_header, sizeof(inp_header));
+		if (inp_header.version[0] != 'W' || inp_header.version[1] < 70)
+		{
+			fprintf(stderr,"Not an WolfMAME Plus 0.87u1 or later INP file\n");
+			isnotwolf = 1;
+		}
+		if (isnotwolf == 0)
+		{
+			if (inp_header.version[1] < 79)
+			{
+				if (inp_header.version[1] == 78 && inp_header.version[2] < 4)
+				{
+					fprintf(stderr,"Pre-0.78u4 format.  Resetting file pointer.  Check will fail, please don't panic.\n");
+					mame_fseek(options.playback,-16,SEEK_CUR);
+					oldwolf=1;
+				}
+			}
+			if (inp_header.version[2] != 0)
+				printf("Recorded in WolfMAME 0.%iu%i\n",inp_header.version[1],inp_header.version[2]);
+			else
+				printf("Recorded in WolfMAME 0.%i\n",inp_header.version[1]);
+
+			printf("Recorded system's speed = ~%dMHz\n",
+				(int)(inp_header.spd/1000000));
+			if (inp_header.options & 0x02)
+				printf("This recording was made with the C 68k core enabled\n");
+			else
+				printf("This recording was made with the ASM 68k core enabled\n");
+			if (inp_header.options & 0x01)
+				printf("This recording has cheats enabled\n");
+			printf("Start date of recording: %s", ctime(&inp_header.starttime));
+			if (!oldwolf)
+			{
+				long endtime,k=0x00000;
+				do
+				{
+					endtime = ((inp_header.starttime+k)&0xffff0000)
+					  |(inp_header.endtime&0xffff);
+					k+=0x10000;
+				}
+				while (endtime<inp_header.starttime);
+				//printf("  DONT KEEP THIS IN WOLFMAME End date of recording: %s", ctime(&endtime));
+			}
+
+			ptr = (short*)&inp_header;
+			// dont include the 16th byte which is the end recording
+			for(a=0;a<12;a++) // 14
+				chk+=(short)*(ptr+a);
+			if(inp_header.check != chk)
+				printf("Check failed.  Expected %04x, found %04x\n",chk,inp_header.check);
+			else
+				printf("Checks out OK. [%04x]\n",chk);
+		}
+		if (!override)
+			infoRead(&options);
 
 		if (!isalnum(inp_header.name[0])) /* If first byte is not alpha-numeric */
 			mame_fseek(options.playback, 0, SEEK_SET); /* old .inp file - no header */
@@ -612,9 +705,92 @@
 	if (options.record)
 	{
 		inp_header inp_header;
+		int start,end,priority,a; // extern char build_version[];
+		unsigned short chk = 0;
+		short* ptr;
 
 		memset(&inp_header, '\0', sizeof(inp_header));
 		strncpy(inp_header.name, drivers[game_index]->name, sizeof(inp_header.name) - 1);
+		infoSetShortName(drivers[game_index]->name);
+		infoSetFilename(recordname);
+		infoSetBIOSString(options.bios);
+		/* MAME32 stores the MAME version numbers at bytes 9 - 11
+		 * MAME DOS keeps this information in a string, the
+		 * Windows code defines them in the Makefile.
+		 * inp_header.version[0] = 0;
+		 * inp_header.version[1] = VERSION;
+		 * inp_header.version[2] = BETA_VERSION;
+		 */
+		inp_header.version[0] = 'W';
+		inp_header.version[1] = 106;
+		inp_header.version[2] = 0; /* BETA # */
+
+		inp_header.options = 0;
+		inp_header.options += options.cheat;
+
+		/* C vs ASM core is not a command line option */
+		/* so we check the preporcessor ... options.m68k_c_core*2; */
+#if defined(A68K0)
+		/* using ASM core */
+		inp_header.options |= 0*2;
+#else
+		/* using C core */
+		inp_header.options |= 1*2;
+#endif
+		inp_header.fskip = frameskip;
+
+		// this global_sound_enabled assignment 
+		// is meaninlgess, since the sound flag is
+		// set after this code and we rewrite it back into
+		// the header after it's set correctly.
+		inp_header.options2 = 1;//global_sound_enabled;
+		inp_header.cputype = 0;
+
+		// do clock speed detection
+		{
+			struct timezone tz;
+			struct timeval tvstart, tvstop;
+
+			unsigned long long int cycles[2]; /* gotta be 64 bit */
+			unsigned long microseconds; /* total time taken */
+			double freq = 1.0f;
+
+			memset(&tz, 0, sizeof(tz));
+
+			/* get this function in cached memory */
+			gettimeofday(&tvstart, &tz);
+			cycles[0] = rdtsc();
+			gettimeofday(&tvstart, &tz);
+
+			/* we don't trust that this is any specific length of time */
+			usleep(125000);
+			//usleep(250000);
+
+			gettimeofday(&tvstop, &tz);
+			cycles[1] = rdtsc();
+			gettimeofday(&tvstop, &tz);
+
+			microseconds = ((tvstop.tv_sec-tvstart.tv_sec)*1000000) +
+				(tvstop.tv_usec-tvstart.tv_usec);
+
+			inp_header.spd = 1000000*(double)(cycles[1]-cycles[0])
+					  /(microseconds/freq);
+		}
+		infoSetSpeed(inp_header.spd);
+
+		inp_header.starttime = (long)time(NULL);
+		inp_header.endtime = inp_header.starttime&0xffff;
+
+		ptr = (short*)&inp_header;
+		// include the 16th byte which is the end recording
+		for(a=0;a<12;a++) // 14
+		{
+			chk+=(short)*(ptr+a);
+		}
+		firstPassSoundNcpu = ((short*)&inp_header.options2)[0];
+		firstPassCheck = inp_header.check = chk;
+		infoSetOptions(&options);
+
 		mame_fwrite(options.record, &inp_header, sizeof(inp_header));
 	}
 
@@ -638,6 +814,38 @@
 	return 1234;
 }
 
+// write start time and write options that were set
+void writeInpStartTime(void)
+{
+        INT64 curpos=mame_ftell(options.record);
+        long starttime = (long)time(NULL);
+
+        inp_header temp;
+        mame_fseek(options.record,
+		(INT64)((char*)&temp.starttime-(char*)&temp),SEEK_SET);
+        mame_fwrite(options.record,&starttime,sizeof(long));
+        mame_fseek(options.record,
+		(INT64)((char*)&temp.options2-(char*)&temp),SEEK_SET);
+	// revert to the initial sound and cpu data
+	((short*)&temp.options2)[0] = firstPassSoundNcpu;
+	temp.options2 = 1;//global_sound_enabled;
+        mame_fwrite(options.record,&temp.options2,sizeof(char));
+
+	// dont use the += or -= operator here
+	firstPassCheck = firstPassCheck 
+		- firstPassSoundNcpu + ((short*)&temp.options2)[0];
+	// write the updated checksum
+	mame_fseek(options.record,
+		(INT64)((char*)&temp.check-(char*)&temp),SEEK_SET);
+	mame_fwrite(options.record,&firstPassCheck,sizeof(long));
+
+        // return to the previous position
+        mame_fseek(options.record,curpos,SEEK_SET);
+
+        // write to WLF file
+        infoSetTimeStart(starttime);
+}
+
 void xmame_config_exit(void)
 {
 	gamename = NULL;
@@ -659,11 +867,6 @@
 		options.playback = NULL;
 	}
 
-	if (options.record)
-	{
-		mame_fclose(options.record);
-		options.record = NULL;
-	}
 
 	if (options.language_file)
 	{
@@ -707,6 +910,7 @@
 	    fprint_columns(stdout, "ROMPATH", "Rom search path"); */
 	fprintf(stdout, "\n"
 #ifdef MESS
+
 			"M.E.S.S. - Multi-Emulator Super System\n"
 			"Copyright (C) 1998-2005 by the MESS team\n"
 #else
diff -Nru xmame-0.101.orig/src/unix/fileio.c xmame-0.101/src/unix/fileio.c
--- xmame-0.101.orig/src/unix/fileio.c	2005-10-12 22:39:22.000000000 -0700
+++ xmame-0.101/src/unix/fileio.c	2005-11-12 09:21:20.000000000 -0800
@@ -339,8 +339,10 @@
 
 	/* when finished, reset the path info, so that future INI parsing 
 	 * will cause us to get called again */
-	free((void *)list->rawpath);
-	list->rawpath = NULL;
+	// This doesn't make sense, why would you care to change the ini file
+	// DURRING mame play...
+	 free((void *)list->rawpath);
+	 list->rawpath = NULL;
 	return;
 
 out_of_memory:
@@ -395,6 +397,9 @@
 			list = &pathlist[FILETYPE_ROM];
 			break;
 #endif
+		case FILETYPE_WLF:
+			list = &pathlist[FILETYPE_INPUTLOG];
+			break;
 
 		default:
 			list = &pathlist[filetype];
diff -Nru xmame-0.101.orig/src/unix/main.c xmame-0.101/src/unix/main.c
--- xmame-0.101.orig/src/unix/main.c	2005-10-12 22:39:22.000000000 -0700
+++ xmame-0.101/src/unix/main.c	2005-11-12 09:21:20.000000000 -0800
@@ -5,11 +5,14 @@
 #define __MAIN_C_
 #include "xmame.h"
 #include "sysdep/sysdep_display.h"
+#include "infofile.h"  // for wlf file writing
 
 #if defined HAVE_MMAP || defined __QNXNTO__
 #include <sys/mman.h>
 #endif
 
+extern void *record;
+
 static void osd_exit(void);
 
 /* put here anything you need to do when the program is started. Return 0 if */
@@ -30,6 +33,36 @@
  */
 void osd_exit(void)
 {
+//	if (Machine->record_file)
+	//{
+//		int ret;
+		//mame_fclose(Machine->record_file);
+//	}
+	if (Machine->record_file)
+	{
+		inp_header temp;
+		long endtime = (long)time(NULL);
+		temp.endtime = endtime&0xffff;
+		mame_fseek(Machine->record_file,(INT64)((char*)&temp.endtime-(char*)&temp),SEEK_SET);
+		mame_fwrite(Machine->record_file,&endtime,sizeof(short));
+		/*
+		first12inpshorts += ((short*)&endtime)[0];
+		first12inpshorts += ((short*)&endtime)[1];
+		mame_fwrite(options.record,&first12inpshorts,sizeof(long));
+		*/
+		// write to WLF file
+		infoSetTimeEnd(endtime);
+		mame_fclose(Machine->record_file);
+		fprintf(stdout,"Writing .wlf file: ");
+	   endtime = infoWrite();
+		if (endtime)
+			printf("OK\n");
+		else
+			printf("Fail\n");
+
+		Machine->record_file = NULL;
+	}
+
 #ifdef XMAME_NET
 	osd_net_close();
 #endif
diff -Nru xmame-0.101.orig/src/unix/video.c xmame-0.101/src/unix/video.c
--- xmame-0.101.orig/src/unix/video.c	2005-10-20 22:48:02.000000000 -0700
+++ xmame-0.101/src/unix/video.c	2005-11-12 09:21:20.000000000 -0800
@@ -19,6 +19,15 @@
 #include "devices.h"
 #include "sysdep/misc.h"
 #include "sysdep/sysdep_display.h"
+#include "infofile.h"
+
+/* W: From window.c */
+extern unsigned long framer;
+extern void* record;
+extern void* playback;
+extern double speed_total;
+extern unsigned int speed_counter;
+extern int isnotwolf;
 
 #define FRAMESKIP_DRIVER_COUNT 2
 static int frameskipper = 0;
@@ -603,6 +612,11 @@
 	{
 		cycles_t cps = osd_cycles_per_second();
 		fprintf(stderr_file, "Average FPS: %f (%d frames)\n", (double)cps / (end_time - start_time) * frames_displayed, frames_displayed);
+		if (Machine->playback_file && !isnotwolf)
+			fprintf(stderr_file, "Average recorded speed: %f%% (%d frames)\n",
+				speed_total / speed_counter, speed_counter);
+		if (Machine->record_file)
+			infoSetFrameCount(speed_counter, speed_total/speed_counter);
 	}
 }
 
@@ -1253,7 +1267,7 @@
 		/* reset the frame counter so we'll measure the average FPS on a consistent status */
 		frames_displayed = 0;
 	}
-	if (input_ui_pressed(IPT_UI_THROTTLE))
+	if (input_ui_pressed(IPT_UI_THROTTLE) && !Machine->record_file)
 	{
 		if (!code_pressed(KEYCODE_LSHIFT) && !code_pressed(KEYCODE_RSHIFT))
 		{
@@ -1413,6 +1427,10 @@
 	  snprintf(dest, bufsize, "\n %d vector updates", performance->vector_updates_last_second);
 	else if (performance->partial_updates_this_frame > 1)
 	  snprintf(dest, bufsize, "\n %d partial updates", performance->partial_updates_this_frame);
+	if (Machine->playback_file && !mame_feof(Machine->playback_file))
+	{
+		dest += sprintf(dest, "\n Recorded speed: %4lu%%", framer - 0xe143823e);
+	}
 
 	/* return a pointer to the static buffer */
 	return buffer;
diff -Nru xmame-0.101.orig/src/usrintrf.c xmame-0.101/src/usrintrf.c
--- xmame-0.101.orig/src/usrintrf.c	2005-10-22 13:37:29.000000000 -0700
+++ xmame-0.101/src/usrintrf.c	2005-11-12 09:21:20.000000000 -0800
@@ -18,6 +18,12 @@
 #include "ui_text.h"
 #include "state.h"
 
+/* W: for speed stor */
+extern void* record;
+extern unsigned long framer;
+// W: for inp view
+extern char inputstr[80];
+
 #ifdef MESS
 #include "mess.h"
 #include "mesintrf.h"
@@ -483,6 +489,14 @@
 	mess_ui_update();
 #endif
 
+	/* W: recorded speed show */
+	if (options.inpview)
+	{
+	  extern char inputstr[80];
+      ui_draw_text(inputstr,0,uirotheight - uirotcharheight);
+	}
+
+
 	/* finally, display any popup messages */
 	ui_display_popup();
 
@@ -1254,7 +1268,7 @@
 		machine_reset();
 
 	/* handle a request to display graphics/palette (note that this loops internally) */
-	if (input_ui_pressed(IPT_UI_SHOW_GFX))
+	if (input_ui_pressed(IPT_UI_SHOW_GFX) && !Machine->record_file)
 	{
 		osd_sound_enable(0);
 		showcharset(bitmap);
@@ -1262,11 +1276,11 @@
 	}
 
 	/* handle a save state request */
-	if (input_ui_pressed(IPT_UI_SAVE_STATE))
+	if (input_ui_pressed(IPT_UI_SAVE_STATE) && !Machine->record_file)
 		initiate_load_save(LOADSAVE_SAVE);
 
 	/* handle a load state request */
-	if (input_ui_pressed(IPT_UI_LOAD_STATE))
+	if (input_ui_pressed(IPT_UI_LOAD_STATE) && !Machine->record_file)
 		initiate_load_save(LOADSAVE_LOAD);
 
 	/* handle a save snapshot request */
@@ -1274,7 +1288,7 @@
 		save_screen_snapshot(bitmap);
 
 	/* toggle pause */
-	if (input_ui_pressed(IPT_UI_PAUSE))
+	if (input_ui_pressed(IPT_UI_PAUSE) && !Machine->record_file)
 	{
 		/* with a shift key, it is single step */
 		if (mame_is_paused() && (code_pressed(KEYCODE_LSHIFT) || code_pressed(KEYCODE_RSHIFT)))
@@ -1297,6 +1311,13 @@
 	if (input_ui_pressed(IPT_UI_SHOW_PROFILER))
 		ui_set_show_profiler(!ui_get_show_profiler());
 
+	/* W: Store speed */
+	if (Machine->record_file)
+	{
+		const performance_info *performance = mame_get_performance_info();
+		framer = (int)(performance->game_speed_percent + 0.5);
+	}
+
 	/* toggle FPS display */
 	if (input_ui_pressed(IPT_UI_SHOW_FPS))
 		ui_set_show_fps(!ui_get_show_fps());
@@ -3950,7 +3971,6 @@
 	add_line(x1, y2, x1, y1, RGB_WHITE);
 }
 
-
 static void render_ui(mame_bitmap *dest)
 {
 	int i;

