r/howdidtheycodeit • u/_rokk_ • Aug 20 '23
Answered How did they code gameboy emulators' fast forward function?
In most of the gameboy emulators out there, there's a dedicated button to fast-forward the games. This means instead of moving at a normal gameboy speed you're going like 10x faster.
- Is it a quirk of emulating such old/weak hardware?
- Extra credit: How could one go about implementing that in a modern engine/software?
22
Upvotes
33
u/khedoros Aug 20 '23
Running at full speed, the Game Boy outputs 60 frames per second, so 17-ish milliseconds per frame. If it takes 1 millisecond for the computer to emulate a frame's worth of Game Boy instructions, you usually have the process sleep for the rest of the time.
Activate "turbo", and the emulator can just sleep for less time per frame (and also probably skip outputting every frame).
9
u/Joey-172 Aug 20 '23
The Gameboys processor ran at about 4 MHz, whereas modern CPU's run around 2 ~ 4 GHz, which is about 500 to 1000 times faster. Because of this, emulators have to artificially cap the speed that they process the games at. So to add a fast forward feature all you would have to do is remove or reduce that cap.
How you would implement a fast forward in a modern game engine depends on the specific engine you're working with and how their game loop is programmed (whether it's using fixed length vs variable length time steps). For fixed length time steps you could typically you could just reduce the amount of sleep time between each frame (i.e, increase frame rate). For variable length time step engine I imagine you could just multiply the delta time by a factor to accomplish a fast-forward effect but that might get whacky for some engines, especially if there's physics is involved
4
u/Waffalz Aug 20 '23
Video games run on a clock, be it one of software or hardware. This means that they have an internal loop where the game processes changes and other calculations. These loop iterations ("frames", or "ticks") generally happen at a set frequency, thus there is a relatively predictable amount of time between each tick that the game relies on to make temporal calculations (e.g. speed and time). For older games like Gameboy ones, this timing is a hard-coded constant (the game assumes the same amount of time has passed between each tick), so you can effectively manipulate the speed of time by adjusting the amount of actual time between each tick. This means increased frequency (less real time between ticks) makes the game run faster, while decreased frequency makes time pass slower.
2
u/ZoomLong Aug 20 '23
Possibly by adjusting the frame rate