Matrox MGA Mystique/Mystique 220
Graphics Clock (GCLK) and Memory Clock (MCLK) Programmer
Release Notes for Version 0.30 Beta Release.
All Rights Reserved.  Sept 23, 1997


Disclaimer
~~~~~~~~~~
Use the software at your own risk. I'm not responsible for any damage that
may have inflicted to your Mystique.


History
~~~~~~~
Version 0.1  Alpha Release 1 (Sept 14, 1997)
- "READ-ONLY" version of MYSTCLK.
- limited distribution.

Version 0.1  Alpha Release 2 (Sept 16, 1997)
- added ability to modify system PLL registers.
- first internet-available for testing purposes.

Version 0.11 Beta Release (Sept 19, 1997)
- added ability to modify Clock Divider.
- discovered "WRITE-ONLY" bug that SGRAM Timings parameters cannot
  be displayed. (...but can be modify...;)
- added ability to modify SGRAM Timings registers. (..Here it is !)
- added error checking for out-of-range value.
- added on-line help.
- bundled with system PLL Clock matcher to find the best
  M, N and P value to achieve the nearest desired freq.

Version 0.12 Beta Release (Sept 23, 1997)
- fixed bugs in SGRAM optimization code.
- fixed bugs in RAM refresh counter code.

Version 0.20 Beta Release (Oct 2, 1997)
- limited distribution.
- only release to beta testers who own a Asustek motherboard (TX97 or T2P4)
  for testing purposes.
- new coding implemented to access PCI Configuration Space through PCI
  Configuration Mechanism 1.
- specially for solving incompatibility between MystCLK and Asustek
  motherboard.

Version 0.30 Beta Release ( Oct 3, 1997)
- combined version 0.20 Beta Release with original MystCLK into single
  executable which support both Intel PCI BIOS and PCI Configuration
  Mechanism 1.
- added MYSTCLK.INI to configure MystCLK for PCI Configuration Space
  accessing method.
- added 2 new tips.
- minor cosmatic changes.
- solved imcompatibility between MystCLK and Asustek motherboards through
  the implementation of PCI Configuration Mechanism 1.
  (...Now, Asustek MB owners should be happy to hear this...) ^_^



Introduction
~~~~~~~~~~~~
The Mystique GCLK/MCLK programmer is able to display and modify the content
of all Mystique internal timings registers. Its features include:

     *1. Full control over Mystique SGRAM timings registers like
         a) CAS Latency
         b) RAS-to-CAS Delay
         c) RAS Minimum Active Time

      2. Memory Clock and Graphics Clock Divider

      3. System PLL Clock

      4. RAM Refresh counter

* - modify-only, refer to "Tips on using MystCLK" for extra information.



Using Mystique GCLK/MCLK Programmer ( MYSTCLK.COM )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Syntax:    MYSTCLK.COM [options]

If options field is omitted, MYSTCLK will show
the content of Mystique timings registers.

Available options:- 

  /1 m n p - change the content of M, N and P registers 
             of system PLL to the value specified by m,n,p. 

  /2 a b c - a - CAS Latency      ( 0 = 2 MCLK, 1 = 3 MCLK) 
             b - RAS-to-CAS Delay ( 0 = 2 MCLK, 1 = 3 MCLK) 
             c - RAS Minimum Active Time   ( 0 = 4 MCLK      
                                             1 = 5 MCLK  
                                             2 = 6 MCLK  
                                             3 = 7 MCLK  )

  /3 G M - Graphic Clock Divider and Memory Clock Devider 
               Graphics clock, G ( 0 = /3, 1 = /1 ) 
               Memory   clock, M ( 0 = /2, 1 = /1 ) 

  /4 x y - RAM Refresh Counter. Setting x and y to 0 halts memory refresh.
           RAM Refresh period = (( x * 256 ) + ( y * 64 ) + 1) MCLK
           where 0 <= x <= 7 and 0 <= y <= 1.


MystCLK is default to use Intel PCI BIOS to access PCI Configuration Space.
If your motherboard is incompatible with this method (...like Asustek MB.),
then you can modify the MYSTCLK.INI by changing the line:

        PCIBios=1
to:
        PCIBios=0

Then, MystCLK will use PCI Configuration Mechanism 1 to access PCI
Configuration Space.



Known Limitation
~~~~~~~~~~~~~~~~
- does not work under Windows NT.

- unable to show the content of SGRAM Timings registers.
  (...Not my fault, it's the chip design....sigh.. :-( )

- when changing SGRAM Timings parameters under Win95 DOS Box,
  the DOS screen may mesh up. A "CLS" will clear the mesh and
  everything should work fine. This is due to the nature of Mystique
  that the SGRAM has to be reset and re-initialized after changing
  CAS Latency.

- strange color sometimes appear if using PCI Configuration Mechanism 1 to
  change SGRAM settings.




Tips on using MystCLK
~~~~~~~~~~~~~~~~~~~~~

- Try not to use P Value other than 0. I have experience reduced
  performance. Play with N and M Value instead to obtain desired freq.

- Several workable freq: (...on my system...)

  P=0, N=25, M=1   ( 186.16MHz )
  P=0, N=78, M=5   ( 188.55MHz )

  * not yet been tested for long hours. *

- Freq after 190MHz, some times work. But often crash when playing VCD
  using XingMPEG V3.12.

- Mystique Win95 Powerdesk Drivers 3.70 reset system clock to factory
  settings on every boot-up. So, placing MYSTCLK.COM in AUTOEXEC.BAT has
  no effect on Win95 apps. You must place it in Win95 StartUp Folder if
  you wish to see its effect under Windows95. You can also manually set
  the desired freq in Windows95 MS-DOS Prompt, both full-screened and
  windowed.

  ( MYSTCLK.COM is fully developed under Windows 95 MS-DOS prompt, so its
    code is very reliable and environment independent. )

- I found that XingMPEG benefits the most from overclocking. On my P133, now
  I can playback VCD at 30fps in 1024 x 768 16bit colors easily by clocking
  my Mystique at 186.16Mhz. Without overclocking, not even a P166 can do
  that. Higher resolution seems to get better results.

  In XingMPEG Video Diagnostis Performance,

  800x600 16bit color without overclocking,
  Rate Control Off, Full-screen                   37 fps

                                                  39.5-40.5 (Overclocking)

  1024x768 16bit color without overclocking,
  Rate Control Off, Full-screen                   28fps

                                                  34.5 (Overclocking)

- Overclocking doesn't affect much on benchmark scores, except the obsolute
  ZD WinBench 3.11. ( 165M -> 206M )
  Tested benchmark ( Win: Winbench 96, Wintune97, Speedy
                     DOS: VSPEED.EXE, PROFILE.EXE )

- 3D apps and games are getting good results too, minimum 1-2fps improvement.
  According to MS D3DTest, overclocking increases fillrate and intersection,
  and yielding a more stable polygons throughput figure.

- I find that the RAM Refresh Counter didn't do anything special in 
  performance improvement. I just leave it there for experimentation.
  If you know its benefits, please tell me.



                    ***** SGRAM OPTIMIZATION *****

- Experiment with a few combination between SGRAM timings parameters and
  system PLL clock. Certain applications seem to benefit more on either
  way. From my experience, VESA-compliant DOS-based software like optimum
  SGRAM timings settings and Windows apps like higher clock rate. Some may
  benefit from both way. Microsft D3DTest shows that Fillrate had jumped
  up 30% from the original settings while D3DTunnel test shows 20%
  improvement.  Here's the approx. figures:

  180MHz clock (no SGRAM optimization, /1 6 87 0 )
  Fillrate      = 10.90
  Polygon       = 175.58
  Intersection  = 2.13
  Tunnel        = 60-62fps

  176MHZ clock (full SGRAM optimization, /1 6 85 0 /2 0 0 0 )
  Fillrate      = 11.49
  Polygon       = 175.58
  Intersection  = 2.15
  Tunnel        = 69-72fps

  188MHz clock (partial SGRAM optimization, /1 6 91 0 /2 1 0 0 )
  Fillrate      = 11.96
  Polygon       = 175.58
  Intersection  = 2.24
  Tunnel        = 72-75fps

  Base-line comparison (150MHz, no SGRAM optimization -- without MystCLK)
  Fillrate      = 8.76
  Polygon       = 176.58
  Intersection  = 1.80
  Tunnel        = 56-58fps

  ( D3DTest is performed in 640x400 16bit color, using Gourand Shading,
    Perspective Correct, Point Filtering, Z-buffer, Texture, Front-to-Back,
    RGB. Each test performs separately.

    Tunnel is performed in 640x400 16bit color, using Gourand Shading,
    Perspective Correct, Point Filtering, Texture 555, Specular light.

    All tests performed using Intel Pentium 133Mhz, 32MB EDO RAM 60ns,
    512KB L2 Pipelined Burst Cache, Mystique 4MB, Powerdesk 3.70, BIOS 1.5
    SB AWE32, Diamond Monster3D (disabled using Tweak!),
    Quantum Sirocco 1.7G, Intel Bus Mastering Driver 3.01,
    Biostar 8500TUC HX-based motherboard, Sony CDU311 8X CDROM, external
    US Robotics Sportster Voice X2 56k faxmodem. )


- SGRAM optimization will be lost if you switch from text mode to graphic
  mode in Win95 ONLY. One example is after running full-screen DOS apps. You'll
  have to re-run MystCLK with SGRAM optimization after each fullscreen DOS
  session. This also implys that SGRAM optimization must be done in
  windowed Win95 DOS Box only. So as RAM Refresh Counter, will be set to 
  factory value during text-to-graphics mode switching in Win95. 
  Graphics-to-graphics and graphics-to-text switching have no effect on
  SGRAM optimization and RAM Refresh Counter.

- Try not to change the setting of CAS Latency. Although changing CAS Latency
  to less MCLK can yield better performance, you'll have to lower the system
  PLL clock to have a stable screen. Full SGRAM optimization cannot work with
  high system PLL clock. Thus, using partial SGRAM optimization with high
  system PLL clock produces the best performance.

- Avoid using SGRAM optimization in 32bit color mode, cause abnormal
  appearance in Win95 desktop.

- your screen will mesh up if you full SGRAM Optimization with high system
  PLL clock. *new*

- if your system is compatible with Intel PCI BIOS method, then you should
  use Intel PCI BIOS to access PCI Configuration Space. This is a better
  way to tweak Mystique, since Intel PCI BIOS is more flexible.



Inside Mystique
~~~~~~~~~~~~~~~
Matrox Mystique is a low-cost solution for all-in-one 2D, 3D and multimedia
accelerator. Its acceleration engine is based on the award-winning MGA-2064W.
The Mystique chip MGA-1064SG is unique in the way that it has its frame
buffer and graphics engine clocked at different frequency. The memory
clock is 1.5 times faster than that of graphics engine.  The memory clock
is using a divider factor of 2, while the graphics clock is using a divider
factor of 3. Mystique GCLK/MCLK Programmer is able to change such default
behaviour by using a divider factor of 1 for both clock.

       !!!!!!!! CAUTION WHEN CHANGING DIVIDER FACTOR !!!!!!!!!

       Be sure to reduce the system PLL clock before switching
       the devider factor to 1. Failing to do so, may cause
       damage to your display card, by torturing your Mystique
       with a freq more than 100MHz !!!!

       You can use the follow example to experiment with clock
       divider of 1.

                MYSTCLK /1 1 6 0  /3 1 1  [Enter]

       This will reduce the system PLL clock to 50MHz then
       switch the divider factor to 1. Then slowly increase
       the system PLL clock until the limit of Mystique graphic
       engines is reached. ( approx. 70MHz for my case...)

       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

The chip has two built-in PLL, one is for pixel clock while the
other for system clock. The pixel clock is the frequency that drives the
refresh rate of monitor's screen. The system clock produces the memory clock
and graphics clock. The documented frequency of system clock is 133MHz, hence
yielding 66MHz memory clock (133/2) and  44MHz graphics clock (133/3).

There are 3 registers that control the frequency of system clock, they are
M Value, N Value and P Value. The system clock can be derived using the
formula:



                                    ( N + 1 )
       System Clock (Fo)   =  --------------------- * 14.31818MHz
                              ( M + 1 ) * ( P + 1 )


       1 <= M <=  31     ( input divider )
       1 <= N <= 127    ( feedback divider )
       P = 0,1,3,7      ( Post Divider )


**  According to Mystique datasheet, the N value must be at least 100. **
**  But I found it to be wrong. Both M and N value can even take a 0.  **
**  However, doing that will crash the system immediately.             **
   


The Native Language of MYSTCLK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Mystique GCLK/MCLK Programer is fully programmed using Microsoft Macro
Assembler Version 6.11, to ensure direct accessing of hardware, small
executable size and superb performance and reliability. The source code
will be published with the final release of Mystique GCLK/MCLK
Programmer.

I did't really take a formal course in IBM PC Assembly Language and
C/C++ until I proceeded to tertiary studies. Well, my U teached MC68000
Assembly Languge instead. I have been learning IBM PC Assembly Language
all by myself long before I went into university. However, my initial
Assembly code was quite in a mesh and hard to manage. Only after I have
learned C/C++ and the spirit of modular design, structure and object-
oriented programming, then I apply those rules to my Assembly code as
well. It seems to me that Assembly Language can be as fun to program as
C/C++ when good programming practice is adhered to, yet providing much
more power to the programmers to reach to the very low-level of system.



About The Author
~~~~~~~~~~~~~~~~
I'm an undergradute in University of Technology Malaysia (UTM), taking
Computer Engineering. A casual programmer and a hobbyist hacker, too.
  
I can be contacted through the following means:

Mail address   :  Mr. Liew Khong Jye
                  14, Jalan Mas,
                  Green Lane,
                  11600 Penang,
                  Malaysia.             Tel: (60) 04-6571689

Campus address :  Mr. Liew Khong Jye
                  57, Jalan Timah 7,
                  Taman Sri Putri,
                  81300 Johor Bahru,
                  Johor Darul Takzim.   Tel: (60) 07-5576428

Internet e-mail:  kjliew@pop.jaring.my

ICQ UIN        :  3185960


I'm pleased to make all my software freely available at no cost. However,
I do appreciate contribution in the form of peripharals or
databook/datasheet to enable me to expand my support for other graphics
controllers other than Mystique. If you like my software, I would love to
receive postcards which show the beauty of your nation.


Future Plan
~~~~~~~~~~~
- a TweakBIOS-equivalent utility, with all its features including
  those that are only available in registered version like
  "save and restore" of chipsets settings.

- FOC as well !!!!


Acknowledgement
~~~~~~~~~~~~~~~
Special thanks to :

- Royce Liao, the author of MCLK Video Card Overclocking
  Utility, for providing me chip information of Mystique.

- All beta-testers that have been very helpful by providing
  comments and suggestion to improve my software.
