Phoinix, the free Gameboy emulator for PalmOS

by Bodo Wenzel
Sitemap:
Home (downloads)
F. A. Q.
Compatibility of...
  free cartridges
  commercial cartridges
How to...
  use the emulator
  convert cartridges
  make cartridges run
  get in touch
About...
  the history
  the future
  the playability testing
  skipping frames ==>
  some accessories
  limits and extensions
Thank you for the cookies

This site is kindly hosted by SourceForge Logo

About skipping frames

Because the request for frame skipping comes often I sat down some hours and reflected on it. Here are my thoughts, and HJ is investigating Liberty in more detail. Additionally there is a quick'n'dirty test version of Phoinix which was only distributed via the mailing list for developers, so get your subscription ;-)

On this page: - Some theory - Some real life values


Some theory:

OK, let's start. There's a lot of mathematics in here, but nothing more than the four basic arithmetical operations and solving equations. If you can't follow, write it down yourself and try to fill in the missing steps. Here are the symbols used:

Symbol Meaning
f frame skip factor ("every fth frame")
Ttotal(f) total time for an actual run with frame skip factor f
n number of frames in Ttotal
Temulate time to emulate the machine code of one frame
Trender time to render and show one frame
e
Trender
emulation ratio = 
Temulate
a(f)
Ttotal(1)
acceleration ratio = 
Ttotal(f)
r(f)
a(f)
frame rate ratio = 
f

We can surely assume that the time to emulate the machine code a Gameboy executes in one frame Temulate is fixed, independent of rendering and showing the frame. Similarly, the time needed to render and show the frame Trender is fixed, too. The values both vary with the game used, depending on the actual machine code, but while running it is assumed to be nearly constant. So the total time for an actual run Ttotal is:

n
Ttotal(f) = n * Temulate + 
 * Trender
f

The first thing we see is that even if we set the frame skip to infinite, we can't be faster than:

n
Ttotal(infinite)  = n * Temulate + 
 * Trender
infinite
 
= n * Temulate +  0  * Trender
 
= n * Temulate

Secondly, after inserting the transformed formula of the ratio e we have:

n
Ttotal(f)  = n * Temulate + 
 * Temulate * e
f
 
e
= n * Temulate * (1 + 
)
f

We calculate the ratio of accelaration a(f) for a frame skip factor f compared to the non-skipping run by:

Ttotal(1)
a(f) 
Ttotal(f)
 
e
n * Temulate * (1 + 
)
1

e
n * Temulate * (1 + 
)
f
 
1 + e

e
1 + 
f

Now let's see how fast we can be with some theoretical values for the frame skip factor f and the emulation ratio e. As the formula clearly shows, there is no proportional relationship between the frame skip factor and the emulation acceleration:

frame skip factorf 1234 51020infinite
e = 10 (incredibly fast emulation)
accelerationa 1.001.832.543.14 3.675.507.3311.00
frame rater 1.000.920.850.79 0.730.550.370.00
e = 2 (fast emulation)
accelerationa 1.001.501.802.00 2.142.502.733.00
frame rater 1.000.750.600.50 0.430.250.140.00
e = 1 (assumed average ratio)
accelerationa 1.001.331.501.60 1.671.821.902.00
frame rater 1.000.670.500.40 0.330.180.100.00
e = 0.5 (fast rendering)
accelerationa 1.001.201.291.33 1.361.431.461.50
frame rater 1.000.600.430.33 0.270.140.070.00
e = 0.1 (incredibly fast rendering)
accelerationa 1.001.051.061.07 1.081.091.091.10
frame rater 1.000.530.350.27 0.220.110.050.00

If we transform the equation for the accelaration ratio a(f), we can calculate the emulation ratio e if a(f) is given:

1 + e
a(f)  = 
e
1 + 
f
 
a(f)
a(f) + e * 
 =  1 + e
f
 
a(f)
a(f) - 1  =  e * (1 - 
)
f
 
a(f) - 1
e  = 
a(f)
1 - 
f

Some real life values:

Now that we know how to calculate things, let's take a look at some real life values. All times are taken on my old Palm III with no overclocking, comparable to 12 MHz due to its wait states.

Phoinix v.1.1fs (special test version), measured Ttotal(1) and Ttotal(2):
Game Ttotal(1) Ttotal(2) a(2) e a(infinite) r(2) emulation speed gain frame rate loss
Dr.Mario 4:042:57 1.391.222.280.69 39%31%
R-Type II 9:308:40 1.100.211.220.55 10%45%
SQRXZ 13:2011:53 1.120.281.280.56 12%44%
StarFisher 3:352:54 1.240.621.640.62 24%38%
Tetris 4:132:59 1.411.412.470.71 41%29%

Hm, the competitor shouldn't stand aside :-D

Liberty v.1.3b2, measured Ttotal(1) and Ttotal(2):
Game Ttotal(1) Ttotal(2) a(2) e a(infinite) r(2) emulation speed gain frame rate loss
Dr.Mario 5:223:57 1.361.122.060.68 36%32%
R-Type II 10:587:55 1.231.252.230.69 23%31%
SQRXZ 12:1910:43 1.140.351.350.57 14%43%
StarFisher 2:472:16 1.230.591.580.61 23%39%
Tetris 5:173:52 1.371.162.130.68 37%32%

So my assumptions about realistic emulation ratios e were quite right: depending on the machine code to execute it's a 0.2 to 1.5 range. With these values, I made some curves and their asymptotes at a(infinite):

Diagram a(f) by e.

How do you read this diagram? OK, let's assume the game has an emulation rate e = 0.7, meaning that Trender is 70% of Temulate. This is the dark green curve. First you're careful and choose a frame skip factor of f = 2. Put your finger on the "2" at the horizontal axis and move up to the dark green curve. Then you go left to the vertical axis and find... a = 1.25! This says that the game will be accelerated to 125%, 25% more than before. The frame rate is getting down a bit, calculated by 125% / 2 = 63%, quite acceptable. Now you plan to accelerate a lot, and you choose a frame skip factor of f = 5. This time you'll find a = 1.50! The game will be accelerated to 150%, 50% more than without frame skipping. But the frame rate is getting down much more, despite the acceleration. Just calculate 150% / 5 = 30%: only three tenth of the non-skipping frame rate! The decision is yours ;-)

palm.gb_emu@gmx.de