Email
GameRoom Articles
GameRoom Web Store
RetroBlast Reviews
RetroBlast Articles
Game Room Links
File Downloads
Site and Contact Information

A Lazy Man's Cheat Sheet

Quick Jump:

How to configure and tweak Windows MAME for the best video timing

One of the really great things about Windows MAME is that it is pretty easy to get running because you don’t need any specific hardware or drivers. If your system runs Windows just fine, then you should be able to run Windows MAME also. It might be easy to get running, but after a little playing around, you will find that getting perfect video is anything but easy.

The reason for this is that Windows MAME is unable to control the video card directly; it must go through Windows. Windows does a pretty good job of handling everything related to video except one thing, the refresh rate. Precise refresh rates are not available although you usually have a few limited ones per resolution such as 60 hertz (Hz), 70 Hz, or 85 Hz.

 

For those who are not familiar with the term hertz, it simply means the number of times per second. You will see it used in many ways, but for our purposes it describes the number of times a monitor is updated each second. So a 60 Hz refresh rate means that the display is refreshed (or drawn) 60 times per second.

 

In MAME, game speed is referred to as frames per second (fps), but don’t let this confuse you as it is the same thing as hertz (60 fps = 60 Hz). In fact, a game in MAME with a 53 fps game speed is set that way because the actual arcade game ran at 53 Hz. Actual arcade games run in perfect video timing with their monitors because they actually generate the signal the monitor is displaying. Here is a depiction of how this would look:

 

 

In a game at 53 fps, there would be exactly 53 of these frames for every one second.  Our goal with MAME is to reproduce this as closely as possible, but this becomes a problem because the closest available refresh rate in Windows is 60 Hz.  The real issue here is that there are two timers constantly out of sync with each other.  MAME has a timer it uses to keep the game at the correct game speed (fps), and the monitor has a timer (its refresh rate) that it uses to display frames one after another.  Even when you think these timers should be in sync (60 fps game and 60 Hz monitor) they will not be because most likely your monitor is actually running 59.992321 Hz or 60.103341 Hz.  To complicate this even further, MAME has games ranging from 30 fps to 69 fps

There are 3 techniques that can be used to address the issue.  Here is a description of each technique along with its advantages and disadvantages.  You can use MAME's timer only, you can use the monitor's timer only, or you can use them both at the same time.

 

Technique 1:  Use MAME's timer only

This technique is actually default behavior for Windows MAME.  It updates the frame when its timer indicates it should and it does not care if the monitor is in the middle of drawing the last frame.  So, the monitor could be somewhere in the middle of drawing frame 1 when MAME updates to frame 2 and the monitor would never finish drawing frame 1.  Here is what this looks like:

 

 

The two advantages of this technique are perfect game speed and best video performance.  Perfect game speed means you will be playing the game at exactly the same speed it ran on the original arcade hardware.  Best video performance means that if your CPU is barely able to keep up with a game, then this technique will yield the fastest frame rate.

The disadvantage of this technique is that is looks terrible.  When a frame is changed and the monitor is currently drawing the previous one, this often results in a retrace line (see the example above).  Scrolling games look especially bad as the retrace line can actually slowly move up or down the display; this is called tearing.  Flashing sequences also look terrible because the original arcade game may have meant the monitor to flash solid red and then solid green, but instead you will get frames that are partially red and partially green.  I consider this technique so bad visually that I don't use it unless I have to.

 

 Technique 2:  Use the monitor's timer only

To enable this technique you must enable the syncrefresh option (I will underline all MAME options in this article).  I also suggest that you enable the triplebuffer option as well.  You can specify these options on the command line or put them in your MAME.INI.  This will disable MAME's internal timer and run the game speed at the monitor's refresh rate.

 If you don't enable triplebuffer with syncrefresh, MAME will enable waitvsync whether you have it enabled or not.  So, with syncrefresh you have a choice of waitvsync or triplebuffer depending on whether you enable triplebuffer or not.  What is the difference between waitvsync and triplebuffer?  They both seem to do the same thing, waiting for the monitor to be in the middle of the vertical blank before updating the frame.  The difference is that waitvsync uses code in MAME to wait for the vertical blank and triplebuffer actually puts that task on the DirectDraw/D3D subsystem.  I find that triplebuffer works better on a wider variety of hardware so I prefer it. 

The advantage is that you have the closest thing to our first example of perfect video.  You can't see any retrace lines, scrolling games look perfect, and any flashing frames will look exactly as they did in the arcade:

 

 

The primary disadvantage is that you may not be playing the game at the same speed it ran in the arcade.  This is why I recommend using this technique for games that are very close to your monitor's refresh rate.  For example, a game that runs at 60.60606 fps (think about a round yellow character eating dots!) would be 1% slower if run at 60 fps.  This small decrease in speed would not be very noticeable, but if would certainly be noticeable if you sped up a game that normally runs at 53 fps to 60 fps (13% faster).

I use this technique on games from 58.5 to 61.5 fps which includes 87% of all MAME games.  Fortunately, 70% of these are 60 fps games so they run at the correct speed (unless you video adapter is too far off of 60.000000 Hz).  The other 17% of games I run using this technique will be made faster or slower by 0.1 - 2.1%.  There are emulation purists who would say that any game speed change however small is not acceptable, but I think a couple of percent difference in game speed on 17% of the games is an acceptable trade for perfect video.  I'll bet the variations in electronics from the same arcade game to another were probably off by a percent or so anyway.

 A second disadvantage of this technique is that your CPU must be fast enough to prepare the next frame before the monitor needs it.  If it isn't fast enough, then it will miss its opportunity to update the monitor when it is in between frames and have to wait for the next refresh cycle.  If this happens, you should go back to technique 1 because it will run faster if not synchronized to the monitor.

To use this technique, make sure you are running MAME 0.103u2 or later.  Versoins before that had a couple of bugs regarding the syncrefresh, waitvsync, and triplebuffer options.  If you want to stick with an older version and you compile your own, please email me as I can send you a patch that corrects the bugs for older versions.

 

Technique 3:  Use both timers

To enable this technique you must enable either the triplebuffer or waitvsync options with syncrefresh disabled.  This will make MAME use its internal timer as well as wait for the monitor to be in the vertical blank before updating the frame.

The advantages are that this will eliminate the retrace line just like technique 2, and at the same time keep the original game speed.  This causes a problem because frames will be displayed twice when MAME's timer (the game speed) is unable to keep up with the monitor (refresh rate).

 

 

Here is an example the worst possible case:  What if you have a game that is 59 fps and you run it on a 60 Hz monitor.  This means that for every 1 second the game is 1 frame short.  What will happen is that MAME will keep the game at the slower 59 fps rate and one frame of the 59 will have to be displayed twice as in the above example.  So, think about a game that displays a frame twice every second, on the second.  If you playing a scrolling game of any type, this would mean the scrolling would stop every second on the second.  Most arcade games are all about action so the action would stop every second on the second.  Needless to say this would be very obnoxious and would make it unplayable.

When using both timers, you can't eliminate that frames will be displayed twice, but what you can do is try to make them less noticeable.  One per second is very noticeable.  Also, if you are running a 60 fps game and your monitor is actually running 60.1 Hz, then every ten seconds this 0.1 Hz difference will add up and become a displayed twice frame.  So it is games that are near the refresh rate that look horrible this technique.

To make this technique look better you want there to be as many displayed twice frames as possible and as randomly as possible.  I have found that once you approach 8 or more displayed twice frames per second that they become less noticeable.  So a 53 fps game running on a 60 Hz monitor would look much better than our 59 fps example above.  A better solution is to simply increase the refresh rate to something higher, such as 85 Hz.  Windows may not allow you to specify 57 Hz, but you usually have a few refresh rates to choose from besides 60 Hz.  Now, the 59 fps game at 85 Hz has 26 displayed twice frames all mixed in with the 59 active frames.  This will look much better.


Summary and Tweaks:

You might be asking yourself, why not just use technique 3 all the time?  The reason is that 70% of the games in MAME will have virtually no game speed difference using technique 2 and look 100% perfect using it.  Another 17% will have their game speed changed very little in order to look 100% perfect.  This leaves 13% of games which I recommend using technique 3 for.  While technique 3 looks very good, it does not look perfect like technique 2. 

I certainly did not want to configure each game so that it would run technique 2 or 3 as this would take a huge amount of time.  Instead I created two new options in MAME that would automatically determine which technique to use based on the game speed being emulated.  Here are they are from MAME -showusage:

 

-[no]autosyncrefresh /         enables automatic sync refresh                 

-[no]asr                                                                      

-autosyncrefresh_range / -asrr specifies automatic sync refresh range (games  

<float>                        60Hz +/- this value are included in automatic sync refresh

 

If autosyncrefresh is enabled, the game speed (fps) will be looked at when MAME starts.  If the game speed is within the range of 60 +/- the value specified in autosyncrefresh_range, then syncrefresh with be enabled and the refresh will be set to 60.  It is important to note that both of these will be changed because when a game is within the range.  If a game is outside of the range specified, then they will not be changed and MAME will use your default syncrefresh and refresh settings.

 

Here are the settings I change from the defaults:

 

triplebuffer 1

resolution 1024x768x16

refresh 85

autosyncrefresh 1

autosyncrefresh_range 1.500000

syncrefresh 0

 

If I load a game that is 60.60606 fps, then it will be within the range of 60 fps +/- 1.5 (58.5 - 61.5 fps) and autosyncrefresh will enable syncrefresh and change the refresh to 60 which enables technique 2.

If I load a game that is 53 fps, then it will be outside the range and autosyncrefresh will do nothing.  This will leave syncrefresh off and refresh at 85 Hz which are perfect for technique 3.

So there you have it, automatic selection of two techniques that deal with the video timing problems of Windows MAME.  If you force all the games to conform to a single resolution (something that Windows is excellent at), you can now display all the games in MAME with only two video modes (1024x768x60 Hz and 1024x768x85 Hz in my example).  You can adjust your monitor for both of these modes, center and size them appropriately and every game in MAME will look great.

If you use different resolutions for different games, then you can decide per game which technique you want to use and then simply enable it in a game specific INI, you don't actually need my autosyncrefresh tweak although you will still need MAME 0.103u2 or later for the bug fixes that come with it.


Other options I haven't already mentioned that you might also tweak in MAME:

 

autoframeskip 

 

-[no]autoframeskip / -[no]afs  skip frames to speed up emulation              

 I always disable autoframeskip as it is useless for modern processors.  The games that are unable to run full speed these days can't be helped by the technique of frame skipping.  It looks terrible anyway and I think they should remove this option from MAME because it no longer has any value.

 

waitvsync

 

-[no]waitvsync                 wait for vertical sync (reduces tearing)       

 

 There is really no good reason to use waitvsync because triplebuffer does it better, unless you aren't using full screen mode.

 

triplebuffer

 

-[no]triplebuffer / -[no]tb    triple buffering (only if fullscreen)    

      

 This is the preferred technique of waiting for the vertical blank to draw the next frame.

 

direct3d

 

-[no]direct3d / -[no]d3d       use Direct3D for rendering                 

 

 I enable direct3d only for vector games because they appear brighter in direct3d mode.  I prefer the way raster games look on directdraw so I usually don't use direct3d for them.

 

resolution and refresh

 

-resolution / -r <string>      set resolution                                 

-refresh <int>                 set specific monitor refresh rate

 

 I always define a specific resolution and refresh rate because I don't want MAME guessing for each game what to do.

 

effect

 

-effect <string>               specify the blitting effect    

 

 I use a high resolution PC monitor and if you leave this at none you will get a blurry stretch that looks more like a lower arcade resolution monitor, not perfect but not bad.  I usually use sharp on this option because I prefer the retro looking crispness that comes with sharpening.

  

screen_aspect

 

-screen_aspect <string>        specify an alternate monitor aspect ratio  

    

 If you have a horizontal mounted monitor this should probably be 4:3, on a vertical setup it is usually 3:4.  But keep in mind that you can use this to alter the width to height ratio of games.  My monitor is mounted vertically and the result is that horizontal games have black bars at the top and bottom.  I use this option in a horizontal.ini file (parsing of horizontal.ini is added by one of my other tweaks) that affects only horizontal games to stretch them a little bit vertically.  This makes horizontal games look bigger and if you only stretch them a little it is subtle.

 

sleep

 

-[no]sleep          allow MAME to give back time to the system when it's not needed     

                         

 I don't ever want MAME to sleep or volunteer CPU cycles back to the operating system so I disable this.  Don't confuse this with the sleepafterframe option below which gives control back to the operating system at the end of each frame.  I recommend the sleepafterframe option because it will bring synchronization to when MAME will be preempted.

 

rdtsc

 

-[no]rdtsc                     prefer RDTSC over QueryPerformanceCounter for  timing     

 

 You can only use this on certain processors (mostly desktop ones).  Any machine with power saving capability will likely be unable to handle RDTSC.  My suggestion is to start with this disabled and get everything working great.  Then try to enable it and if everything still works ok, then keep it because it has less overhead than the alternative method.  My notebook can't handle it at all and it makes game play extremely erratic. 

 

high_priority

 

-[no]high_priority             increase thread priority      

                  

I always enable this so MAME gets the most CPU time possible.


Other options I haven't already mentioned that are added by my Autosyncrefresh Tweak: 

 

sleepafterframe

 

-[no]sleepafterframe /         releases the current timeslice after each frame

-[no]saf    

                                                                  

 The sleepafterframe option causes MAME to issue a Sleep(0) command which sleeps for 0 milliseconds after each frame.  In reality this causes MAME to give up its current CPU time slice to the operating system right after a frame has been displayed.  Hopefully when MAME gets the processor back it will get an uninterrupted time slice to perform its processing and be ready to display the next frame before the monitor needs it.  I suggest using this because it creates a known place where MAME will be preempted instead of just leaving the when it will be preempted up to chance.

 

override_fps

 

-override_fps / -of <float>    overrides the default game fps                  

 

The -override_fps command is a handy command if you want to force a game to run faster or slower.  This is also useful for someone who is impaired or a young child wants to play a game, by slowing it down a bit, you can make it more playable for them.


SA Dev's MAME Tweaks:

My tweaks include many more added options than the ones I've included above.  You can download them here.  To use these tweaks you must know how to compile MAME and modify the source code using them before compiling.  I will also be writing an article soon on how to compile MAME step by step, so you might refer to that when it is available, otherwise there are other guides and forums available on how to do this.  If you already know how to compile MAME, here is a how to integrate my tweaks. 

1.       Extract the zip file into the directory with the makefile.  SRC should be a subdirectory of this directory. 

2.       Run applyscr.bat and it will apply all the scripts one by one as you hit Y for yes. 

3.       Then compile MAME.  Once you have MAME with these tweaks compiled in, just run a "mame -cc" and it will update your mame.ini to contain the new options.  You can use them from the command line as well.

Well, I hope this article will help you to have the best video quality possible from your Windows MAME setup!

 


 

Next >