Locked



Post subject: Adding Recording to PCSX emulator
Joined: 2/9/2007
Posts: 22
I'm currently looking at the source code for PCSX and wondering how to accomplish this. If someone could point me to source code where this has already been done on another emulator, preferrably with comments for each section edited/added, that would help immsensely. Currently, 70% of my programming experience lies in web developement. PHP, MySQL, HTML, CSS, and some javascript are what I'm most well versed in. Besides these, I have some previous experience in C++(mostly editing code, I haven't programmed anything myself yet), so I can make some sense of what I'm seeing. I have MS Visual Studio 2003, so I have a capable editor/compiler to work with. My current goal is simple: Add a way to record button presses and automatically play them back. This means no savestates will be incorporated yet or anything of the sort. I am only focused on recording the input and playing it back, and savestates/other things can come later. After implementing recording/playback, I will ensure that playback doesn't desync because of loading times or other things that may vary wildly from user to user. After implementing the above, I will work on savestates and other features. The more help I get with this, the faster it will get done.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye
Former player
Joined: 10/1/2006
Posts: 1102
Location: boot_camp
Borg Collective wrote:
Negotiation is irrelevant. Self-determination is irrelevant. You will be assimilated.
Player (71)
Joined: 8/24/2004
Posts: 2562
Location: Sweden
This sounds awesome. I wish you good luck, Valarnin.
Skilled player (1098)
Joined: 8/26/2006
Posts: 1139
Location: United Kingdom
Excellent. There are so many issues with how PSX TASing that I am skeptical as to whether or not this will work out. I really hope you succeed. Also, dibs on Metal Gear Solid :)
Active player (411)
Joined: 3/16/2004
Posts: 2623
Location: America, Québec
Imo, psx emulator is a better choice.
JXQ
Experienced player (761)
Joined: 5/6/2005
Posts: 3132
Mukki wrote:
dibs on Metal Gear Solid :)
Dibs? Lol, I bet that really flies around here.
<Swordless> Go hug a tree, you vegetarian (I bet you really are one)
adelikat
He/Him
Emulator Coder, Site Developer, Site Owner, Expert player (3571)
Joined: 11/3/2004
Posts: 4754
Location: Tennessee
Hell yes, good luck on this :D
It's hard to look this good. My TAS projects
N._Harmonik
She/Her
Joined: 8/27/2006
Posts: 502
Location: Canada
Woohoo! Crash Bandicoot, Resident Evil and Tomb Raider runs, here we come!
Why, oh, why do I even <i>try</i> to understand my own species?
ventuz
He/Him
Player (125)
Joined: 10/4/2004
Posts: 940
Very cool, but I'm not sure how are you planning to keep movie in sync (problem falls in making iso, playing from CD or iso, etc..) If you could manage to get working playback in sync. I'll try do Parasite Eve and Parasite Eve 2 :)
Former player
Joined: 10/1/2006
Posts: 1102
Location: boot_camp
Is it possible to have fmv skipping as an option? If so, I wonder how low FF7 could go ...
Borg Collective wrote:
Negotiation is irrelevant. Self-determination is irrelevant. You will be assimilated.
Joined: 2/9/2007
Posts: 22
OK, let's talk movie file structure. How should the movie file be arranged?
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 :[
You should first find out what type of input are you going to record, will it be frame-based (less likely) or, like mupen64's (what's the word for it~), how many controllers and other devices are you going to record, how are you going to manage multidisk games etc... Another problems that game ISOs may differ pretty much, unlike roms. It can affect replayability... Ugh, after all I don't think recording movies on ps using only input is possible, sorry~ But good luck, It should be interesting to try to do it =)
Joined: 2/9/2007
Posts: 22
If I let the already-coded plugins system handle everything else and just take over input while it's playing back... I could include the SLES/SLUS/whatever ID in the movie file's header. This will allow different image files to work, because after all the data is the same, the container just changes. Maybe the header should contain controller amount, frames recorded, and other things needed. The amount of controllers would tell the emu how to process the movie file. My question is how should I record that input to the file? For multi-disk movies, the movie file will have a flag that tells the emulator to prompt for the next disk.
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 a flag or check in the PSX to tell wether a cutscene is playing or a title screen is showing? If so you could probably add some of that info for desync messages while playing right?
Joined: 4/11/2006
Posts: 487
Location: North of Russia :[
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...
Joined: 2/9/2007
Posts: 22
Really all I'm working on now is recording itself. I figure 512 bytes should be good for the header, considering it's just some simple text and stuff. I have no experience actually writing to file though. I could make a file manually in a hex editor, I could parse it with PHP and handle it properly, but I've never had to do this in C++ before. Anyone here have some experience with this that wants to contribute some code? A simple function to create the header of the movie file would be great. -----EDIT----- Here's a sample header file. The actual file should be padded with 00's instead of 2D's(-). I padded it with 2D's to show exactly how long each part should be.
00000000  74 65 73 74 20 66 69 6c 65 2d 2d 2d 2d 2d 2d 2d  test file-------         Title of Run
00000010  2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00000020  56 61 6c 61 72 6e 69 6e 2d 2d 2d 2d 2d 2d 2d 2d  Valarnin--------         Runner's Name
00000030  2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00000040  53 4c 45 53 5f 31 30 30 31 2d 2d 2d 2d 2d 2d 2d  SLES_1001-------         Disk ID
00000050  53 6f 6d 65 46 69 6c 65 2e 49 53 4f 2d 2d 2d 2d  SomeFile.ISO----         Original File Name
00000060  2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00000070  31 00 31 00 34 35 33 34 35 36 39 33 38 37 32 31  1.1.453456938721
00000080  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000a0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000b0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000d0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000e0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000f0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100  53 68 6f 72 74 20 63 6f 6d 6d 65 6e 74 73 20 66  Short comments f
00000110  72 6f 6d 20 61 75 74 68 6f 72 20 74 6f 20 64 65  rom author to de
00000120  73 63 72 69 62 65 20 74 68 65 20 72 75 6e 2e 20  scribe the run. 
00000130  54 68 69 73 20 63 6f 75 6c 64 20 62 65 20 75 70  This could be up
00000140  20 74 6f 20 62 79 74 65 20 35 31 32 2e 20 49 6d   to byte 512. Im
00000150  6d 65 64 69 61 74 6c 79 20 61 66 74 65 72 20 62  mediatly after b
00000160  79 74 65 20 35 31 32 20 74 68 65 20 76 69 64 65  yte 512 the vide
00000170  6f 20 72 65 63 6f 72 64 69 6e 67 20 77 69 6c 6c  o recording will
00000180  20 73 74 61 72 74 2e 20 53 75 63 68 20 61 20 6c   start. Such a l
00000190  6f 6e 67 20 73 70 61 63 65 20 69 73 20 72 65 73  ong space is res
000001a0  65 72 76 65 64 20 73 6f 20 77 65 20 63 61 6e 20  erved so we can 
000001b0  6d 6f 76 65 20 63 6f 6d 6d 65 6e 74 73 20 75 70  move comments up
000001c0  20 6c 61 74 65 72 20 61 6e 64 20 68 61 76 65 20   later and have 
000001d0  72 6f 6f 6d 20 66 6f 72 20 6e 65 77 20 66 6c 61  room for new fla
000001e0  67 73 2e 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  gs.-------------
000001f0  2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
-----EDIT2----- OK, I've coded a function to read the header of the file. I also modified the code above to reflect the changed test movie file. Any input on the read code?
int PlayMovie(char moviefile[256]) {
	char RunName[32], RunnerName[32], RunCDID[16], RunCDName[32], RunComments[256];
	char Controllers[1], DiskAmount[1], RunLength[12];
	FILE * movptr;
	movptr = fopen(moviefile, "r");
	fgets(RunName, 32, movptr);
	fseek(movptr, 32, SEEK_SET);
	fgets(RunnerName, 32, movptr);
	fseek(movptr, 64, SEEK_SET);
	fgets(RunCDID, 16, movptr);
	fseek(movptr, 80, SEEK_SET);
	fgets(RunCDName, 32, movptr);
	fseek(movptr, 112, SEEK_SET);
	fgets(Controllers, 1, movptr);
	fseek(movptr, 114, SEEK_SET);
	fgets(DiskAmount, 1, movptr);
	fseek(movptr, 116, SEEK_SET);
	fgets(RunLength, 12, movptr);
	fseek(movptr, 256, SEEK_SET);
	fgets(RunComments, 256, 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
Joined: 4/11/2006
Posts: 487
Location: North of Russia :[
I think you should start with 4-byte header(PSX\$1A), then address of data start or header length and only then start data. Don't forget to include: number of rerecords length of movie in inputs length of movie in time version of emulator (You'll need it for backwards compatibility) ALL settings that may affect playback and FREE SPACE to add something later (like things from previous point that you might have forgotten)=) ...and please, don't store numbers as strings, or I'll kill you :E sorry )
Emulator Coder, Site Developer, Former player
Joined: 11/6/2004
Posts: 833
I must agree. I should be able to write a short script that spews out information about the run (rerecord information and all that) or state that the file is not a valid movie for this emulator. The format you've described does not meet that requirement. Site rules state that parsing the full file must not be required to determine the length of the movie. It is acceptable to have the file's size as part of the calculation (FMV movies are filesize - 144 bytes, for example). This post may be relevant, though it is slightly N64 centric. It still shows what the guidelines are. 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.
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
Original File Name - Um why? Is this even relavent? Is it always possible?
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Emulator Coder, Site Developer, Former player
Joined: 11/6/2004
Posts: 833
If the author uses the "GoodNES" style filenames, it can be a benefit in locating the right ROM. Failing that, it's not much use, I agree.. As for its application to PSX, I leave that to someone who knows what they're talking about.
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
Right ROM? I'm running my games off of an original CD.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Active player (411)
Joined: 3/16/2004
Posts: 2623
Location: America, Québec
Well, I remember some database to help identify PS games. If it's SLUS-555 for example, then it tells you the full name.
Joined: 2/9/2007
Posts: 22
DeHackEd wrote:
Site rules state that parsing the full file must not be required to determine the length of the movie. It is acceptable to have the file's size as part of the calculation (FMV movies are filesize - 144 bytes, for example).
One of the variables(RunLength[12]) is supposed to be the Run's length in frames. The focus right now is getting it to read from/write to a file.
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. Don't forget to include: number of rerecords length of movie in inputs length of movie in time version of emulator (You'll need it for backwards compatibility) ALL settings that may affect playback and FREE SPACE to add something later (like things from previous point that you might have forgotten)=) ...and please, don't store numbers as strings, or I'll kill you :E sorry )
I'm not quite sure what you mean by the 4-byte header. The header length with information about the run was to be a set size(512 bytes). Input was to start after that. I'm not familiar enough with the emulator's code yet to do much. Just code that read header info from the file and assigned it to variables like I posted would be great. The code to create the files would be even better. This is the first time I've had to read and write from files like this, so I'm still a bit out of my depth. I originally created the header file from scratch using a hex editor. I don't have code to create the file when it isn't present.
Phil wrote:
Well, I remember some database to help identify PS games. If it's SLUS-555 for example, then it tells you the full name.
The S***-##### CDID is included in the header. The Original file name was included for convenience. The CD-ID is stored in the game's exe file on the disk/image. This will allow us to tell different versions. Googling for a second brought up this big list of discs and their IDs. The first part(SLES/SLUS/SCES/whatever) show the region of the game, and the second part shows the game ID.[/url]
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 :[
Try reading this: http://tasvideos.org/FCM.html http://tasvideos.org/FMV.html http://tasvideos.org/M64.html http://tasvideos.org/VBM.html http://tasvideos.org/SMV.html http://tasvideos.org/GMV.html Especially header description. Each and every one starts with 4-byte signature, and none keeps numbers as strings. You should define structure for your header(Struch header {char[4] sig; long length; long rerec; ... (etc) } and write it using not fputs, but... i don't remember that function's name =\ If it was delphi, it would be blockwrite -_- Well, feel free to dtry to do it the way you try and can, but I'm groing more and more sceptical about it...
Joined: 2/9/2007
Posts: 22
zefiris wrote:
Try reading this: http://tasvideos.org/FCM.html http://tasvideos.org/FMV.html http://tasvideos.org/M64.html http://tasvideos.org/VBM.html http://tasvideos.org/SMV.html http://tasvideos.org/GMV.html Especially header description. Each and every one starts with 4-byte signature, and none keeps numbers as strings. You should define structure for your header(Struch header {char[4] sig; long length; long rerec; ... (etc) } and write it using not fputs, but... i don't remember that function's name =\ If it was delphi, it would be blockwrite -_- Well, feel free to dtry to do it the way you try and can, but I'm groing more and more sceptical about it...
OK, I understand the sig thing now, and can define a structure for the header. Is this the function you were talking about? I also see I'm going to have to take note of the plugins and stuff. If I can find a way to md5sum the PSX executable from within the code, I could also use that along with CDID and omit the orig file name. The MD5sum would be of the playstation executable file on the disk's image, and not the image itself, once again getting around the different format/container problem.
BoltR : I'm not bothering with no fairy demons BoltR : I'm going right for time itself BoltR : Right in the eye

Locked