Scott's Timing Formula (STF) README WARNING! Misuse of this software can potentially damage your monitor. I assume no responsibility for any such damage and you use this software at your own risk. History ------- I own a Wells-Gardner U3000 arcade monitor, which is a fixed horizontal frequency monitor at 31.5 KHz. Unfortunately, MAME only has a few tweaked modes that work at this frequency. To be safe, only 640x480 can be used because some of the other tweaked modes run at higher or lower frequencies and there is no way to tell MAME not to use those modes. In 640x480 mode, a game that uses a resolution like 224x256 has a very small image centered in the middle of the screen. This is because the vertical resolution of 256 is too big for MAME to double (256 * 2 > 480) so MAME leaves it unscaled and just centers it in the available resolution. From my experience with programming VGA controllers, I knew there were monitor timings that would make most of these resolutions full screen on my monitor. I looked around on the 'net and found AdvanceMAME. AdvanceMAME has many features but the one that attracted me was its support for modelines. Modelines are sets of monitor timings that define a resolution. I tried it out and it worked pretty well. The problem was that 1) there are a lot of resolutions and it would take a long time to generate modelines for them all, 2) I wanted to use the main MAME source so I didn't have to worry about future support for AdvanceMAME, 3) AdvanceMAME does not do a good job picking the right resolution for a particular game, and 4) AdvanceMAME has a lot of features I would never use that would only slow MAME down. How It Works ------------ If you are not familiar with monitor timing, I would suggest taking a look at the XFree86 Video Timings HOWTO for a good tutorial. This can be found at http://www.linuxhq.com/ldp/howto/XFree86-Video-Timings-HOWTO.html STF basically works by automatically generating modeline parameters from a single set of generic timing definitions instead of having to uniquely define each resolution with its own specific modeline. This allows STF to generate any conceivable resolution by rewriting the CRTC registers in the VGA controller. This is the same way MAME sets the tweaked modes. The maximum and minimum horizontal and vertical scan rates of the monitor are specified in the configuration to ensure that the specifications of the monitor are not exceeded. STF will always try to use the maximum vertical refresh allowed. STF uses the VBE 3.0 (VESA 3.0) to set the pixel clock and to pick a standard resolution that is close to the one it is setting. If your video card does not support VESA 3.0, you will need a VESA extender such as SciTech Display Doctor. Also, STF may not work on all video cards due to the unpredictable way cards respond to having the CRTC registers written. I have tested it on a STB Velocity128 (Riva128) and a Matrox Mystique. The STB card works perfectly at all resolutions while the Matrox works perfectly except for vertical resolutions close to 500 (strange!). Your mileage will vary. STF Timing Diagram |<------------- total --------------->| |<- porch ->| |<- pulse ->| \ / \------------+ +--------------/ | | | | +-----------+ There are three parameters that define the horizontal interval in STF. The Total parameter defines the total size of the interval in terms of percentage of The total scanline. This defines the horizontal size of the image. The porch parameter defines the total size of the front porch which controls the left and right position of the image. The pulse parameter defines the width of the horizontal sync pulse and just needs to be wide enough for the monitor to recognize it. The vertical parameters work the same as the horizontal except that the porch parameter controls the up and down position and the total parameter controls the vertical size. The pulse parameter again just needs to be big enough for the monitor to recognize it. The polarities of the horizontal and vertical sync pulses need some explanation. VGA monitors use these to determine the vertical size of the image so that the monitor can expand or compress the vertical size. STF can automatically set the polarities depending on the requested resolution. This feature is enabled with the auto_polarity parameter in the configuration file. The following table summarizes the resolutions and polarity settings. Vertical Resolution H Sync V Sync ------------------- ------ ------ <= 350 + - <= 400 and > 350 - + > 400 - - STF can automatically control the aspect ratio for vertical and horizontal games. If a vertical game is display on a horizontal screen, STF still uses the exact resolution needed but compresses the image horizontally to maintain the 4:3 aspect ratio of the monitor. Vice versa, if a horizontal game is played on a vertical monitor, STF compress the image vertically to main the 4:3 aspect ratio. Unfortunately, STF can only mathematically compress and center the image when compensating for the aspect ratio. There is no way to predict how the monitor will actually display the image since the width of an unused pixel may not be the same as an used pixel. For example, the image is perfectly centered and sized on my PC monitor but my arcade monitor compresses the image too much and it is shifted right. In my experiences, this difference in pixel width is fairly constant on a given monitor so I included scaling parameters to compensate for it. The hcompress and hposition parameters scale the horizontal size and position to compensate for this problem. Increasing hcompress compresses the image and decreasing it expands the image. Increasing hposition shifts the image left and decreasing it shifts the image right. On my arcade monitor, these parameters are the inverse of each other - hposition is set to 1.2 and hcompress is set to 1/1.2 = 0.83. Installation ------------ Copy or unzip all of the files into the mame/src/msdos directory in the djgpp source tree. Run the command "patch < stf.diff" from this directory and recompile MAME. The patch command can be downloaded from one of the FTP sites listed at the DJGGP site http://www.delorie.com/djgpp/getting.html Download pat253b.zip from the /v2gnu directory and unzip its contents into the djgpp directory tree. Configuration Options --------------------- [config] use_stf = yes or no Enable the use of STF. Default is no. [stf] hfreq_min = n The minimum horizontal scanning frequency in KHz of the monitor. Default is 31.0. hfreq_max = n The maximum horizontal scanning frequency in KHz of the monitor. Default is 32.0. vfreq_min = n The minimum vertical refresh frequency in Hz of the monitor. Default is 60.0. vfreq_max= n The minimum vertical refresh frequency in Hz of the monitor. Default is 70.0. auto_polarity = yes or no If enabled, STF will set the horizontal and vertical sync polarities to match the vertical resolution. Most monitors will detect the polarities of these signals and will compress or expand the image vertically to match the vertical resolution. Default is no. hsync_porch = n The percentage of the horizontal scanline that is the front porch of the horizontal sync. Increasing this value will have the effect of shifting the image to the left and decreasing this value will shift the image to the left. This value plus hsync_pulse must be less than hsync_total. Default is 1.0 (1%). hsync_pulse = n The percentage of the horizontal scanline that is the horizontal sync pulse. This value should generally not be modified once the monitor is syncing horizontally. If the image tears, then this parameter might have to increased or decreased. Default is 10.0 (10%). hsync_total = n The percentage of the horizontal scanline that is the entire sync interval. Increasing this value will have the effect of compressing the image horizontally and decreasing this value will expand the image horizontally. This value must be larger than hsync_porch plus hsync_pulse. Default is 20.0 (20%). vsync_porch = n The percentage of horizontal scanlines that are the front porch of the vertical sync. Increasing this value will have the effect of shifting the image up and decreasing this value will shift the image down. This value plus vsync_pulse must be less than vsync_total. Default is 2.0 (2%). vsync_pulse = n The percentage of horizontal scanlines that are the vertical sync pulse. This value should generally not be modified once the monitor is syncing vertically. If the image rolls, then this parameter might have to increased or decreased. Default is 0.5 (0.5%). vsync_total = n The percentage of horizontal scanlines that are the entire sync interval. Increasing this value will have the effect of compressing the image vertically and decreasing this value will expand the image vertically. This value must be larger than vsync_porch plus vsync_pulse. Default is 5.0 (5%). hposition = n Amount to scale the horizontal position when STF is generating a video mode for a vertical game on a horizontal monitor or vice versa. Incresing this value moves the image left and decreasing this value moves the image right. Typical values are 0.5 to 1.5 with a value of 1.0 meaning that no scaling is done. Default is 1.0. hcompress = n Amount to scale the horizontal size when the STF is generating a a video mode for a vertical game on a horizontal monitor or vice versa. Increasing this value compresses the image and decreasing this value expands the image. Typical values are 0.5 to 1.5 with a value of 1.0 meaning that no scaling is done. Default is 1.0.