Locked



Joined: 4/11/2006
Posts: 487
Location: North of Russia :[
Yes, if was fwrite :) Now it does not look that hopeless ^^ You understood everything correctly and writing crc of executable file is a good idea... Sorry if I say discouraging or cruel things, I just want it to be done really well ) And if you keep getting better this way you can succeed~ ^^
Joined: 2/9/2007
Posts: 22
How's this look for the header?
struct MovieHeader {
	char Sig[4];
	char Ver[4];
	long InputCount[4];
	long FrameCount[4];
	char DiskID[14];
	long Controllers[1];
	long Disks[1];
	char RunName[16];
	char RunnerName[16];
	char GfxPlugin[32];
	char SndPlugin[32];
	char CDPlugin[32];
	char BIOS[32];
	char Pad1Plugin[32];
	char Pad2Plugin[32];
	char RunComments[256];
	char ReservedSpace[512];
};
-----EDIT----- Forgot the rest of the post ;) The header totals 1024 Bytes. The movie file's input should start immediatly afterward for this and all versions until recording from a savestate is implimented.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Player (71)
Joined: 8/24/2004
Posts: 2562
Location: Sweden
Is there any way to force a dump of a game to match another dump?
Emulator Coder, Site Developer, Former player
Joined: 11/6/2004
Posts: 833
Valarnin wrote:
struct MovieHeader {
	char Sig[4];
	char Ver[4];
	long InputCount[4];
	long FrameCount[4];
	char DiskID[14];
	long Controllers[1];
	long Disks[1];
	char RunName[16];
	char RunnerName[16];
	char GfxPlugin[32];
	char SndPlugin[32];
	char CDPlugin[32];
	char BIOS[32];
	char Pad1Plugin[32];
	char Pad2Plugin[32];
	char RunComments[256];
	char ReservedSpace[512];
};
You know "long" is 4 bytes (8 on x86_64). Why are you using an array of size 4 for these? Do you need the frame counter to have a range from 0 to 340282366920938463463374607431768211456?
Joined: 2/9/2007
Posts: 22
DeHackEd wrote:
Valarnin wrote:
struct MovieHeader {
	char Sig[4];
	char Ver[4];
	long InputCount[4];
	long FrameCount[4];
	char DiskID[14];
	long Controllers[1];
	long Disks[1];
	char RunName[16];
	char RunnerName[16];
	char GfxPlugin[32];
	char SndPlugin[32];
	char CDPlugin[32];
	char BIOS[32];
	char Pad1Plugin[32];
	char Pad2Plugin[32];
	char RunComments[256];
	char ReservedSpace[512];
};
You know "long" is 4 bytes (8 on x86_64). Why are you using an array of size 4 for these? Do you need the frame counter to have a range from 0 to 340282366920938463463374607431768211456?
So should I change the longs to ints or drop the [4]? Do I need both input count and frame count? -----EDIT----- Like this?
struct MovieHeader {
	char Sig[4];				//4
	char Ver[4];				//8
	long FrameCount;			//16
	char DiskID[14];			//30
	int Controllers[1];			//31
	int Disks[1];				//32
	char RunName[16];			//48
	char RunnerName[16];		//64
	char GfxPlugin[32];			//96
	char SndPlugin[32];			//128
	char CDPlugin[32];			//160
	char BIOS[32];				//192
	char Pad1Plugin[32];		//224
	char Pad2Plugin[32];		//256
	char RunComments[256];		//512
	char ReservedSpace[512];	//1024
};
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Joined: 4/11/2006
Posts: 487
Location: North of Russia :[
drop [4]. If frame count cannot be calculated while loading file from input count without analysing the whole movie then it's needed.
Joined: 2/9/2007
Posts: 22
I've tried these two functions. The first one doesn't load the data at all, and the second one crashes at the last line(because it's loading from file as string instead of long).
MovieHeader hdr;

int LoadMovie(char moviefile[256]) {
	FILE * movptr;
	movptr = fopen(moviefile, "r");
	fread (hdr,1024,1,movptr);      //also tried (hdr, 1, 1024, movptr)
MovieHeader hdr;

int LoadMovie(char moviefile[256]) {
	FILE * movptr;
	movptr = fopen(moviefile, "r");
	fgets(hdr.Sig, 5, movptr);
	fseek(movptr, 4, SEEK_SET);
	fgets(hdr.Ver, 5, movptr);
	fseek(movptr, 8, SEEK_SET);
	fgets(hdr.FrameCount, 9, movptr);
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Emulator Coder, Site Developer, Former player
Joined: 11/6/2004
Posts: 833
Doing it that way is considered bad form. sizeof(long)==4 on 32 bit systems, sizeof(long)==8 on 64 bit systems. If you want to call fread() to bulk read the structure, here's what you should do. First, use sizeof(MovieHeader) rather than assuming the size of the structure. Second, if you're using GCC to compile this, make sure you use __attribute__ ((packed)) to prevent dead space from being added. Finally, use the various uint32_t style fields to ensure fields remain the same size. Or even better, read fields individually and use ntohs and ntohl class functions to regulate byte ordering. Not all hardware orders bytes the same way. This is the little/big endian system problem. Pentium and compatible hardware are little endian, and that's the major platform, but that might not be true for everybody.
Joined: 2/9/2007
Posts: 22
DeHackEd wrote:
Doing it that way is considered bad form. sizeof(long)==4 on 32 bit systems, sizeof(long)==8 on 64 bit systems. If you want to call fread() to bulk read the structure, here's what you should do. First, use sizeof(MovieHeader) rather than assuming the size of the structure. Second, if you're using GCC to compile this, make sure you use __attribute__ ((packed)) to prevent dead space from being added. Finally, use the various uint32_t style fields to ensure fields remain the same size. Or even better, read fields individually and use ntohs and ntohl class functions to regulate byte ordering. Not all hardware orders bytes the same way. This is the little/big endian system problem. Pentium and compatible hardware are little endian, and that's the major platform, but that might not be true for everybody.
I only understood about 50% of what you just said O.o Using the following sample file and file read code I can get what's in the screenshot.
00000000  50 53 58 1a 30 2e 30 31 05 00 00 00 00 00 00 00  PSX.0.01........
00000010  53 4c 55 53 5f 30 30 30 30 31 00 00 00 00 01 01  SLUS_00001......
00000020  54 65 73 74 20 46 69 6c 65 00 00 00 00 00 00 00  Test File.......
00000030  56 61 6c 61 72 6e 69 6e 00 00 00 00 00 00 00 00  Valarnin........
00000040  53 6f 6d 65 20 47 46 58 20 50 6c 75 67 69 6e 00  Some GFX Plugin.
00000050  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060  53 6f 6d 65 20 53 6f 75 6e 64 20 50 6c 75 67 69  Some Sound Plugi
00000070  6e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  n...............
00000080  53 6f 6d 65 20 43 44 20 50 6c 75 67 69 6e 00 00  Some CD Plugin..
00000090  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0  53 6f 6d 65 20 42 49 4f 53 00 00 00 00 00 00 00  Some BIOS.......
000000b0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0  46 69 72 73 74 20 50 61 64 20 50 6c 75 67 69 6e  First Pad Plugin
000000d0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0  53 65 63 6f 6e 64 20 50 61 64 20 50 6c 75 67 69  Second Pad Plugi
000000f0  6e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  n...............
00000100  43 6f 6d 6d 65 6e 74 73 20 67 6f 20 68 65 72 65  Comments go here
00000110  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000120  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000130  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000160  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000170  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000180  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000190  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001a0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001b0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001c0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001d0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001e0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001f0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000200  54 68 65 20 72 65 73 74 20 69 73 20 72 65 73 65  The rest is rese
00000210  72 76 65 64 20 73 70 61 63 65 20 66 6f 72 20 66  rved space for f
00000220  75 74 75 72 65 20 65 78 70 61 6e 73 69 6f 6e 2e  uture expansion.
00000230  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000240  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000250  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000260  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000270  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000280  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000290  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000002a0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000002b0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000002c0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000002d0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000002e0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000002f0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000300  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000310  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000320  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000330  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000340  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000350  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000360  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000370  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000380  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000390  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000003a0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000003b0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000003c0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000003d0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000003e0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000003f0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
int LoadMovie(char moviefile[256]) {
	FILE * movptr;
	movptr = fopen(moviefile, "r");
	if (movptr == NULL) exit(0);
	fgets(hdr.Sig, 5, movptr);
	fseek(movptr, 4, SEEK_SET);
	fgets(hdr.Ver, 5, movptr);
	//fseek(movptr, 8, SEEK_SET);
	//fgets(hdr.FrameCount, 9, movptr);
	fseek(movptr, 16, SEEK_SET);
	fgets(hdr.DiskID, 15, movptr);
	//fseek(movptr, 30, SEEK_SET);
	//fgets(hdr.Controllers, 2, movptr);
	//fseek(movptr, 31, SEEK_SET);
	//fgets(hdr.Disks, 2, movptr);
	fseek(movptr, 32, SEEK_SET);
	fgets(hdr.RunName, 17, movptr);
	fseek(movptr, 48, SEEK_SET);
	fgets(hdr.RunnerName, 17, movptr);
	fseek(movptr, 64, SEEK_SET);
	fgets(hdr.GfxPlugin, 33, movptr);
	fseek(movptr, 96, SEEK_SET);
	fgets(hdr.SndPlugin, 33, movptr);
	fseek(movptr, 128, SEEK_SET);
	fgets(hdr.CDPlugin, 33, movptr);
	fseek(movptr, 160, SEEK_SET);
	fgets(hdr.BIOS, 33, movptr);
	fseek(movptr, 192, SEEK_SET);
	fgets(hdr.Pad1Plugin, 33, movptr);
	fseek(movptr, 224, SEEK_SET);
	fgets(hdr.Pad2Plugin, 33, movptr);
	fseek(movptr, 256, SEEK_SET);
	fgets(hdr.RunComments, 257, movptr);
	fseek(movptr, 512, SEEK_SET);
	fgets(hdr.ReservedSpace, 513, movptr);
	fclose(movptr);
	return 1;
}
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
ventuz
He/Him
Player (126)
Joined: 10/4/2004
Posts: 940
Hmm, is it possible for you to make movie file to remember what plugin's config are?
Joined: 2/9/2007
Posts: 22
ventuz wrote:
Hmm, is it possible for you to make movie file to remember what plugin's config are?
I can't see the point, the GFX plugin settings only really determine how it looks, not how it emulates. Besides that, the config is loaded by the plugin itself and not the emulator, so it's out of my reach.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Joined: 3/16/2006
Posts: 289
A little on a little off topic question here. Are there any games that don't emulate right? I remember playing through FFIX on EpcxE (or something) and it froze at a certain cut scene. Only an older version worked. Are there any like that in this emu?
I am just a silhouette, a silhouette of a memory of a solitary night .. nothing more.
Joined: 2/9/2007
Posts: 22
Right now, I'm not really concerned with that. I can debug things like that later and try to track down errors. The entire point of this is to impliment recording that works. On that note, I'm looking into how the emulator handles input, so I can see how to properly record it. I still can't read the long value properly, because fgets is for strings and doesn't return hex or anything else, which I could use. If anyone can find the function to read hex from a file, that would be great.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Joined: 4/11/2006
Posts: 487
Location: North of Russia :[
I can't see the point, the GFX plugin settings only really determine how it looks, not how it emulates
OBJECTION! ^__^ it may affect timing of events at very least. EDIT: I would be more concerned with SFX plugin settings. I believe sometimes game waits until some sound is over, and it's affected by spu...
Joined: 2/9/2007
Posts: 22
If my assessment of the source code is right, the emulator just dumps the raw data on the plugin, and leaves the decoding and rendering of the data to it. Graphics are one-way, while sound, pad, CD, and BIOS are all two-way exchanges. The point is though, that most options in the plugins themselves don't effect the emulation process. Only the Special Game Fixes effect it, the rest just determine how the decoded data is sent to the computer's hardware(IE DirectX or OpenGL, resolution, or in the case of sound, output quality). Any options in the plugin that effect emulation are for that plugin only, and not in all plugins. Besides this, there is no way to get plugin settings from within the emulator. When the emulator gets settings, it consults the DLL on-the-fly to open it's configure screen. The configure screen isn't in the emulator, it's in the DLL.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Player (35)
Joined: 12/18/2005
Posts: 250
zefiris wrote:
OBJECTION! ^__^ it may affect timing of events at very least.
OBJECTION!!!!!11 :)
我々を待ち受けなさい。
Joined: 2/9/2007
Posts: 22
This struct looks promising for recording and playing...
typedef struct
{
	// controler type - fill it withe predefined values above
	unsigned char controllerType;
	
	// status of buttons - every controller fills this field
	unsigned short buttonStatus;
	
	// for analog pad fill those next 4 bytes
	// values are analog in range 0-255 where 128 is center position
	unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY;

	// for mouse fill those next 2 bytes
	// values are in range -128 - 127
	unsigned char moveX, moveY;

	unsigned char reserved[91];

} PadDataS;
Also, here's what it looks like so far.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
ventuz
He/Him
Player (126)
Joined: 10/4/2004
Posts: 940
Is that "Movie - You" going to stay like that? I think I much rather see "Movie's Setting - Your Setting" The disks thing, I just came up thought. I haven't tried this emu before, can you possible make emu prepares multiple ISO before running movie? Like load in FF7 disc 1 (as #1), FF7 disc 2 (as #2), FF7 disc 3 (as #3), then record movie and it records open tray, close tray, changed iso to other #.
Joined: 2/9/2007
Posts: 22
I don't think I can. The emulator emulates everything properly. There's only one function to read a file from a CD, and no real way to prepare a disk ahead of time without re-writing the entire disk read functions. What will happen is when recording, when you change disks with the emu, it will write a flag to the movie file instead of input that frame. When the playback gets to that point, it will pause the emu and ask for the next disk. The info window is ever changing. The "Movie You" thing wasn't even there until I wanted to take the screenshot. I'm working more on the code than the looks right now. On that note, I'm looking into the actual recording aspect now. After I get it to record and replay some input, I'll compile the exe and post a link to the exe and source.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Emulator Coder, Site Developer, Former player
Joined: 11/6/2004
Posts: 833
It's already been stated, but I hope the plugins don't have any say in emulation. eg. the sound output driver should merely be an OS interface, and not actually do SPU work. The video CD-ROM plugin shouldn't get to decide (directly or otherwise) how long seeking takes. And will there be Linux support? I might be able to assist with that, if you keep the Windows specific stuff separate from the generic backend. Last person to add rerecording to emulators made it for Windows and f**ked up all the rest of the operating systems.
Player (206)
Joined: 5/29/2004
Posts: 5712
Isn't plugins assisting with the emulation what makes it high-level and thereby fast? Or am I greatly wrong here?
put yourself in my rocketpack if that poochie is one outrageous dude
Joined: 2/16/2005
Posts: 462
   char RunName[16];         //48
   char RunnerName[16];      //64 
These seem really small when you consider that people can have names in unicode. I recommend around 256 bytes like in .m64
This signature is much better than its previous version.
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
Phil wrote:
Imo, psx emulator is a better choice.
Isn't that closed source?
Valarnin wrote:
OK, let's talk movie file structure. How should the movie file be arranged?
Two paths to go: fixed offsets or variable-length blocks. Fixed offsets are easier for hex-editing, but not flexible. I'd suggest that in any case the header has either a length field that describes its size, or a field that stores the offset of the input data.
zefiris wrote:
also if I remember right there's such thing as internal clock in ps, so you should set movie starting internal time and record it and always fix during playback as I am pretty sure that random number generator relies on it heavily...
Definitely.
zefiris wrote:
I think you should start with 4-byte header(PSX\$1A), then address of data start or header length and only then start data.
Why 4 bytes? It can be of any length, preferably the name of the movie file format.
zefiris wrote:
...and please, don't store numbers as strings
It doesn't really matter. ;)
Valarnin wrote:
I've tried these two functions. The first one doesn't load the data at all, and the second one crashes at the last line(because it's loading from file as string instead of long).
MovieHeader hdr;

int LoadMovie(char moviefile[256]) {
        FILE * movptr;
        movptr = fopen(moviefile, "r");
        fread (hdr,1024,1,movptr);      //also tried (hdr, 1, 1024, movptr)
MovieHeader hdr;

int LoadMovie(char moviefile[256]) {
        FILE * movptr;
        movptr = fopen(moviefile, "r");
        fgets(hdr.Sig, 5, movptr);
        fseek(movptr, 4, SEEK_SET);
        fgets(hdr.Ver, 5, movptr);
        fseek(movptr, 8, SEEK_SET);
        fgets(hdr.FrameCount, 9, movptr);
Use fopen(moviefile, "rb") for binary mode. (Not related to the crash.) You shouldn't need any calls to fseek.
Valarnin wrote:
If anyone can find the function to read hex from a file, that would be great.
Don't look for built-in mega-functions. ;) Read the raw data and convert it internally with library functions. You could write your own functions though that do the converting.
Valarnin wrote:
This struct looks promising for recording and playing...
typedef struct
{
        // controler type - fill it withe predefined values above
        unsigned char controllerType;
        
        // status of buttons - every controller fills this field
        unsigned short buttonStatus;
        
        // for analog pad fill those next 4 bytes
        // values are analog in range 0-255 where 128 is center position
        unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY;

        // for mouse fill those next 2 bytes
        // values are in range -128 - 127
        unsigned char moveX, moveY;

        unsigned char reserved[91];

} PadDataS;
How about this?
typedef struct tPadData  {
        uint32_t  ControllerType;       // controler type - fill it withe predefined values above
        uint32_t  ButtonStatus;         // status of buttons - every controller fills this field
        uint32_t  JoyL_X, JoyL_Y;       // analog values of 0 to 255, 128 = center
        uint32_t  JoyR_X, JoyR_Y;
         int32_t  MouseMove_X;          // values = -128 to 127
         int32_t  MouseMove_Y;
        uint8_t  reserved[91];
};

tPadData  PadData
I also suggest using structs for Joystick L and R, and for the mouse.
Joined: 2/9/2007
Posts: 22
Nononono, that struct is already in the emu. I mean I can get the button status and stuff with it. But anyways, progress is halted until I can find the function that gets button status from the plugin...
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Joined: 2/12/2006
Posts: 432
DeHackEd wrote:
Edit: and if the avatar isn't a dead giveaway, Linux support with all these movie and savestate features would be nice. It only has to be enough to boot up and play/record movies correctly, doesn't need an overly fancy GUI. AVI support I will be adding/modding myself.
how about linux support for 3d acceleration? until that comes, i won't be able to do much with any of this. though, i'll greatly enjoy seeing psx runs.

Locked