Post subject: New libgambatte frame timing
Skilled player (1040)
Joined: 7/24/2013
Posts: 175
As this came up in my recent submission (#4376: MrWint's GB Pokémon: Red Version "Gotta Catch 'Em All!" in 1:54:56.62), I feel the need to discuss this a bit more: As of version 1.7.0, the frame timing has changed, forcing all frames to have the same length. Since these frames determine when you can do your inputs, this changes the input timing (and is therefore incompatible with input sequences recorded on the old timing). The pre-1.7 timing allowed individual frames to be shorter and tried to end the frame at VBlank (this is where the new frame gets drawn). This way the input frames always stayed in sync with the video frames of the game, at the cost of having very few single shorter frames to sync them up again when e.g. the LCD was turned off by the game. The new timing ignores video frames, so that the input frame boundary and the video frame boundary get out of sync. Let me illustrate the different behavior with a graphic (note that this is a simplification): http://pastebin.com/sjETYLAW The problem I have with this new frame timing is this desync of input frames and video frames. The game I was working on, and I assume many other games, fetch their input at VBlank. With the old frame timing, this was ideal, since you had an input frame on every VBlank, so you can literally do all inputs that are possible on a real Gameboy, which was great. Moreover, if you want to do an action in frame X, you know exactly that the corresponding input frame where you need to make your inputs is also X. With the new timing, this doesn't work anymore. If you e.g. want to close a textbox, and the game tests this during input frame 7, you can't be sure when you need to do the inputs: If it's after the VBlank that occurs somewhere during frame 7, you need to input it at frame 7, but if it's before the VBlank you already need to press the buttons in frame 6. This is highly confusing, and can (in rare cases) even lead to inputs not being possible at all, if multiple VBlanks occur quickly after another. To put it in other words: You set a breakpoint where the inputs are used, and run the game until it stops at the breakpoint. Now you want to know when you need to press the joypad to set the inputs at that breakpoint. In the old frame timing, this was easy, just go back to the last frame boundary and press the buttons there (this is how I created aforementioned run btw). With the new frame timing, it's not that easy: It may be the last frame, or the frame before that, or even no frame at all. It's a mess. I assume you were trying to fix timing accuracy issues with this, since you determine the movie length by multiplying the frames with the frame rate, and some individual frames were shorter than the rest, resulting in a slightly too-high total time. The main problem here lies in the assumption that the frame rate is constant, because it just isn't. Well, it is under normal circumstances, which is 99.9% of the runtime, but not always. It may be better to measure the time in terms of CPU cycles, which are in fact constant, and accept that some video (and therefore input) individual frames are shorter. Forcing all frames to be the same length causes issues as described above, and at least for me makes the way I create TASes impossible. I hope there is a chance to rethink this change, or I'm probably forever stuck with BizHawk version 1.6.1 for GB games... Note that I had this discussion (with a slightly different focus) before for lsnes (Thread #14274: lsnes (libgambatte core): Frames don't end on VBlank), which does the same thing. I'm running out of usable emulators it seems...
adelikat
He/Him
Emulator Coder, Site Developer, Site Owner, Expert player (3575)
Joined: 11/3/2004
Posts: 4754
Location: Tennessee
BizHawk does this, because lsnes did it. And people were using lsnes because their movies were looking faster because it was less frames. There's advantages to the system though. Movies times are now accurate (whereas bizHawk movies in 1.6x or before are off by some seconds potentially). I hope this will spur some debate though. I reluctantly did this to BizHawk due to demand. Adding some kind of option in the core is potentially doable. (Certainly feasible enough that it isn't the reason whey we don't have the option)
It's hard to look this good. My TAS projects
Warepire
He/Him
Editor
Joined: 3/2/2010
Posts: 2178
Location: A little to the left of nowhere (Sweden)
I vote for frame-timing á la 1.6.x I'm not sure if one can really count the CPU cycles either, if I remember correctly the CPU fully and entirely stops during the HALT (or STOP?) instruction. Though if I am wrong here, that would be the ultimate solution. (Number of cycle counter roll-overs + cycles passed since last roll-over) I don't think there is any fully accurate way to track time in the gameboy without running into issues where time might not be represented 100% accurately. I do however not see this as a major issue, compared to the issue that it might not be possible to provide input during certain situations. What is the purpose of more accurate emulators if we botch the timing? That is potentially as bad as using emulators of less accuracy.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
imho, theres no solution to this which will please everyone. Until what I think is the long term solution (allow user to independently control options which affect when frames are displayed, what frame-advance hotkey does, and when input is consumed from input log) is in place, chasing a theoretical dragon will only bring grief.
Skilled player (1040)
Joined: 7/24/2013
Posts: 175
zeromus wrote:
imho, theres no solution to this which will please everyone. Until what I think is the long term solution (allow user to independently control options which affect when frames are displayed, what frame-advance hotkey does, and when input is consumed from input log) is in place, chasing a theoretical dragon will only bring grief.
You're right, there's no frame-based timing that will fit all games, since GB games can use joypad interrupts (well you could make inputs accurate to the CPU cycle, but that's not practical). But the old timing was fitting some if not most of the games, and my point is that the slight timing accuracy gain is not worth making the frame timing fit literally none of the games, especially when the accuracy could be achievd in a different way that doesn't have this drawback. I don't want to force some immediate changes here, I'm happy to continue using BizHawk 1.6.1, and as long as this is seen as an issue and there's a solution to it planned in the future, everything is good. All I want is to point out that the new frame timing is not strictly better than the old one, infact it has major drawbacks which may cause players to continue using the old timing, and that's probably fine, there are no emulation accuracy differences involved, it's strictly about timing. And even the timing can be compensated for by actually counting the CPU cycles in a run, which makes both frame timings comparable in terms of total time. Of course this raises the question why you would want to bother with the new frame timing in the first place, but I guess it's too late now, it's released and runs created on it must be dealt with. Reverting the timing change won't do much about this.
Editor, Emulator Coder, Site Developer
Joined: 5/11/2011
Posts: 1108
Location: Murka
Warepire wrote:
I vote for frame-timing á la 1.6.x I'm not sure if one can really count the CPU cycles either, if I remember correctly the CPU fully and entirely stops during the HALT (or STOP?) instruction. Though if I am wrong here, that would be the ultimate solution. (Number of cycle counter roll-overs + cycles passed since last roll-over) I don't think there is any fully accurate way to track time in the gameboy without running into issues where time might not be represented 100% accurately. I do however not see this as a major issue, compared to the issue that it might not be possible to provide input during certain situations. What is the purpose of more accurate emulators if we botch the timing? That is potentially as bad as using emulators of less accuracy.
One can count ticks of a reference clock, which continues ticking at a constant rate even when the cpu is HLT/STP. Although Bizhawk doesn't do so now, it could easily be modified to show the exact number of refclocks elapsed at any particular frame end, and so the exact correct time elapsed could always be known regardless of frame end choice.
MrWint wrote:
You're right, there's no frame-based timing that will fit all games, since GB games can use joypad interrupts (well you could make inputs accurate to the CPU cycle, but that's not practical). But the old timing was fitting some if not most of the games, and my point is that the slight timing accuracy gain is not worth making the frame timing fit literally none of the games, especially when the accuracy could be achievd in a different way that doesn't have this drawback.
Joypad interrupts are not a problem; it was such a useless feature that the CGB doesn't even support them, and games didn't use them. Mid-frame power off could be useful, though. That would be moving all the way to arbitrary timed input which Bizhawk does not do. Point to consider: Every single NES emulator (FCEUX, Bizhawk, others) uses the same timing scheme as old GBHawk, where variable length frames are used with the frame end being consistent relative to NMI, but not consistent in total time length. The magnitude of error is much smaller in NES, though.
Joined: 3/11/2014
Posts: 46
Well, this explains a thing or 2. I could not understand why, randomly, my inputs were sometimes delayed by one frame after certain screen transitions or menuing (both of which disable the LCD temporarily). When this happens, it also tends to break some of my scripts which do certain inputs for me (mostly text mashing). I can work around this, but I would probably revert to bizhawk 1.6 for my next TASing project.
Skilled player (1742)
Joined: 9/17/2009
Posts: 4986
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
If it matters, it desyncs on the stuart little TAS published a while back. While trying to sync it up, I noticed that rather than a fixed pattern of <input><lag><lag>, it seems somewhat random, but oddly gets to the next screen/transition at the same amount of time.
Skilled player (1742)
Joined: 9/17/2009
Posts: 4986
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
zeromus wrote:
imho, theres no solution to this which will please everyone. Until what I think is the long term solution (allow user to independently control options which affect when frames are displayed, what frame-advance hotkey does, and when input is consumed from input log) is in place, chasing a theoretical dragon will only bring grief.
Sorry for double posting, but how about making a poll to see which option is preferred?
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
That's a question that would best be addressed to someone who wondered which option people preferred, instead of a person who said it was ideal to have all options.
Editor, Emulator Coder, Site Developer
Joined: 5/11/2011
Posts: 1108
Location: Murka
As of r7519, you can have both options; that way no one is happy. This will be in the next release; which probably won't happen anytime soon.
Skilled player (1040)
Joined: 7/24/2013
Posts: 175
natt wrote:
As of r7519, you can have both options; that way no one is happy. This will be in the next release; which probably won't happen anytime soon.
That's awesome. So basically you also have backwards compatibility to pre-1.7 movies again (except for those who use the RTC, but hey). I feel kinda obligated to use this and create more GB movies now that my whining about the frame timing was successful...
Editor, Emulator Coder, Site Developer
Joined: 5/11/2011
Posts: 1108
Location: Murka
MrWint wrote:
natt wrote:
As of r7519, you can have both options; that way no one is happy. This will be in the next release; which probably won't happen anytime soon.
That's awesome. So basically you also have backwards compatibility to pre-1.7 movies again (except for those who use the RTC, but hey). I feel kinda obligated to use this and create more GB movies now that my whining about the frame timing was successful...
I haven't put it through its paces yet, but pre-1.7 movies will require some minor manual header adjustments to work.
Skilled player (1040)
Joined: 7/24/2013
Posts: 175
I just noticed that Ilari added an option to the lsnes a couple of months ago to support BizHawk's (old) GB timing (with a totally appropriate flag name: http://repo.or.cz/w/lsnes.git/commit/b14bc7a3a71214ce8e7fb0a8326a5753743ccd9a). Now lsnes is imitating BizHawk, while BizHawk imitates lsnes. I wonder if the two are compatible in both frame timings now...
Editor, Emulator Coder, Site Developer
Joined: 5/11/2011
Posts: 1108
Location: Murka
MrWint wrote:
(with a totally appropriate flag name: http://repo.or.cz/w/lsnes.git/commit/b14bc7a3a71214ce8e7fb0a8326a5753743ccd9a)
Ilari has the leisure of not having to care if anyone ever uses his software.