Post subject: Real-time reverse replay feature
Emulator Coder
Joined: 6/8/2005
Posts: 14
There has been recent discussion and development over at Nesdev of an algorithm for immediate backwards replay at any point, without using much more processing than for normal forwards emulation. In my very experimental NES emulator I made it so if you hit the reverse key, video and audio slow down to a crawl, then smoothly speed up in reverse, similar to the opening scene in The Matrix. Then as it plays backwards, at any point you can pick up playing (or hit the reverse key and replay back to the point where you reversed). It's quite cool. I'm posting this so that any programmers who want to open-source emulators might add this feature, and so that anyone interested can request this in their favorite emulator. I've refined the core algorithm and written a commented C implementation, with callbacks to the emulator, so it shouldn't be hard to integrate (it's only a hundred or so lines long). I'll also provide any assistance with understanding or implementing it. I posted an mp3 from my emulator (I don't have any easy way to make a video, sorry) to the nesdev thread mentioned above and I'd appreciate someone mirroring it and posting the URL here.
nesrocks
He/Him
Player (247)
Joined: 5/1/2004
Posts: 4096
Location: Rio, Brazil
I think i got it how it works, and its really cool to have a button on the joystick to do rewind that way. Now i want to dl the emulator to test it :) but i'm guessing you dont have it compiled and ready for users to dl do you
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
This is interesting. As I understand it, it creates savestates at a regular interval, and for seeking to a precise moment (such as current frame - 1), it loads the nearest savestate before that moment and quietly(?) emulates the required number of frames. Is this right? Edit:
void emu_save_state( int n );     // save to snapshot n
void emu_restore_state( int n );  // restore snapshot n
What is the range of "n" for these functions?
Emulator Coder
Joined: 6/8/2005
Posts: 14
The algorithm summarized: - Make a save state every second, record controller input, and keep the last 60 save states. This allows immediate seeking to any second in the last minute. - To play one second in reverse, restore previous second of save state, generate all frames into an image/sound buffer that has 60 slots, then display the frames in reverse order. - To play continuously in reverse, fill the frame buffer with one second of material. Then, as you display each frame, be filling the buffer with the previous second. Once all 60 frames have been displayed, the buffer is now filled with the previous second. Do the same for each previous second. Note that after setup, CPU usage is not much more than for forward emulation. - A further optimization is to keep the buffer filled at all times with the most recent 60 frames, so that switching to reverse doesn't require immediate generation of 60 frames. When using the example code, set aside however many save states you want to use. Also make a buffer of frames (60 in this example, i.e. one second) and call re_init( 60 ). Implement the emu_ functions in your emulator. Then use re_next_frame() and re_prev_frame() to go forward/backward, using the return value as an index into your buffer of frames to choose which one to display/play the audio of. In most cases, each requested frame results in emulation of only one frame. Currently the code doesn't have a way to specify how far back the save states go; the indicies passed to the save state functions go from 0 to however many seconds (assuming re_init( 60 )) you've emulated since initializing. You could just take the modulo of the save state index, i.e. save_states [n % 60] (note that this 60 isn't the same one as used for re_init() and the number of frames in the buffer). Sorry for the lack of clear writing; I've been up too long.
Editor, Reviewer, Experienced player (980)
Joined: 4/17/2004
Posts: 3109
Location: Sweden
For us, from a movie-making perspective, I can see this as perhaps being useful when noticing you have quicksaved at a too late point to undo something. This is salvageable by replaying the movie of course, but that can be bothersome. Then a frame reverse button would surely come in handy. Probably the biggest gain would be in movie reviewing. I don't know how many times I wanted a go-back-10 seconds button (by just a simple auto-savestate at regular intervals really) when I saw something interesting or improvable in a movie. I remember some SNES emulator having that function, but I don't remember which one.
nesrocks
He/Him
Player (247)
Joined: 5/1/2004
Posts: 4096
Location: Rio, Brazil
Zsnes has rewind, but it skips to savestates, it doesnt do the rewind animation. Yes, for the tool-assisted time attack community, the biggest gain would be in movie watching.