Post subject: Setting up a resync workflow
Player (66)
Joined: 4/21/2011
Posts: 232
I'm doing a little write-up to give some idea for what kind of dark art I'm performing to get famtasia movies running on fceux. So, starting with the .fmv, first you'll need a clean dump from famtasia (or a pre-made file you trust the frame-accuracy of). I run it through vdub to get it to lagarith. Then I start fceux, Open ROM..., Pause, Record Movie..., Stop Movie. This sets up the headers and I drag this file from the movie directory to my working directory. I add the frame data with this python/batch script. (nesmock should work too) Make sure the names of the .fmv and fm2 match. The underscore is to keep my utility stuff away from the other files. _py.bat
@ECHO OFF
IF NOT [%~nx1]==[%~n1.fmv] ECHO drag+drop .fmv & PAUSE & GOTO :EOF
IF NOT EXIST "%~n1.fm2" ECHO "%~n1.fm2" not found & PAUSE & GOTO :EOF

python _py.py %1 >> %~n1.fm2
_py.py
import sys

with open(sys.argv[1], "rb") as f:
    f.read(10)
    print("comment author ")
    print("comment original_rerecordCount",
          int.from_bytes(f.read(4), 'little') + 1)
    print("comment original_framecount ")
    f.read(2)
    print("comment original_emulator", str(f.read(64), "utf-8").strip('\0'))
    f.read(64)
    print("comment emulator_conversion nanogyth")

    while True:
        byte = f.read(1)
        if not byte:
            break
        byte = int.from_bytes(byte, 'little')
        list = ["RLUDBAST"[n] if byte & 1 << n else '.'\
            for n in [0,1,3,2,7,6,4,5]]
        print("|0|", ''.join(list), "|||", sep='')
Edit in the author and original framecount. Start the movie in fceux and open Tools/TAS Editor... Advance frames til the screen is black instead of grey. Make an avs to load your reference dump. dump.avs
avisource("dump.avi")
notes="
"
trim(0,0)
Load that in vdub and advance to the same point in the movie. Adjust your windows so you can see the frame number of each. Make note of the framenumbers then adjust the trim so that the frame numbers will match. Advance til something notable happens and see if they are still in sync (probably not). Add/delete frame from the fm2 til they do sync. Make note of which frame matched and what adjustments you made. Hopefully the only desyncs occur at lag frames. I use this lua script to jump to the next lag frame. _lag.lua
FCEU.speedmode("turbo");

repeat
    FCEU.frameadvance();
until FCEU.lagged();

FCEU.pause();
(is there a way to force an unpause in a lua script?) Look for a notable frame after the lag and check that fceux and the reference file are still in sync. If they're out of sync make note of it and maybe double check that they were really in sync the previous time. Adjust the trim in the .avs and reload to regain sync. Clone/delete an equal number of frames in TASEdit. Repeat until the end of movie, save the fm2 and fm3, close everything and check that the fm2 plays correctly. If you are doing a PAL resync things are much worse. Fceux didn't have any lag frames after the start for the one file I tried this with. And things desynced almost every time the screen went black (and there are a lot of scene changed in solstice).
AnS
Emulator Coder, Experienced player (727)
Joined: 2/23/2006
Posts: 682
nanogyth wrote:
(is there a way to force an unpause in a lua script?)
There's emu.unpause() See the full list in the FCEUX manual: http://www.fceux.com/web/help/fceux.html?LuaFunctionsList.html I think this can be further automated by finding a memory address that can serve as an indicator of sync, and then unleashing TAS Editor exhaustive search (adding/deleting frames when lag frame noticed) by writing custom lua bot. See the full list of Lua functions for auto-editing movie in the TAS Editor manual: http://shedevr.org.ru/temp/sound/taseditor/TASEditorManual.html?LuaAPI.html
Player (66)
Joined: 4/21/2011
Posts: 232
AnS wrote:
I think this can be further automated by finding a memory address that can serve as an indicator of sync,
But I'd need that data from Famtasia, right? Which would be tricky since its source is lost.
AnS
Emulator Coder, Experienced player (727)
Joined: 2/23/2006
Posts: 682
nanogyth wrote:
AnS wrote:
I think this can be further automated by finding a memory address that can serve as an indicator of sync,
But I'd need that data from Famtasia, right? Which would be tricky since its source is lost.
Yes, that's kinda non-trivial. You would need to dump the log of Famtasia values (likely using MHS, "Memory Hacking Software", I dunno). Yet the trickiest part would be writing the bot, I guess. And of course it's not obvious how to find actual memory addresses that can be reliable estimate of sync.
Player (66)
Joined: 4/21/2011
Posts: 232
My copy of fceux 2.1.6 is missing the "taseditor" subfolder of "luaScripts". Do you have a link to a build that includes it?
AnS
Emulator Coder, Experienced player (727)
Joined: 2/23/2006
Posts: 682
nanogyth wrote:
My copy of fceux 2.1.6 is missing the "taseditor" subfolder of "luaScripts". Do you have a link to a build that includes it?
FCEUX SVN: http://fceultra.svn.sourceforge.net/viewvc/fceultra/fceu/output/luaScripts/taseditor/ Also here some guys regularly compile sources of many open-source emulators: www.emucr.com/2012/05/fceux-svn-r2503.html
Player (66)
Joined: 4/21/2011
Posts: 232
I'd like to do something like this
function my_fun()
    repeat
        FCEU.frameadvance()
    until FCEU.lagged()
end

taseditor.registermanual(my_fun)
Is that possible?
AnS
Emulator Coder, Experienced player (727)
Joined: 2/23/2006
Posts: 682
Using emu.frameadvance is so last week, I suggest "register" methods.
stop_at_lag = false;

function my_fun()
	if emu.paused() then
		emu.unpause();
		emu.speedmode("turbo");
		stop_at_lag = true;
	end;
end;

function my_auto()
	if (stop_at_lag) and (not emu.paused()) and emu.lagged() then
		emu.pause();
		emu.speedmode("normal");
		stop_at_lag = false;
	end;
end;

taseditor.registermanual(my_fun);
emu.registerafter(my_auto);		-- or taseditor.registerauto(my_auto);
There was a error in FCEUX Lua implementation of emu.unpause(), I've just fixed it, so get latest SVN revision before running this script.
Player (66)
Joined: 4/21/2011
Posts: 232
Thank you