home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / _SVGALIB.TAR / usr / doc / svgalib / README < prev    next >
Encoding:
Text File  |  1995-01-18  |  30.2 KB  |  788 lines

  1.  
  2. svgalib v1.22
  3.  
  4. 0.  Introduction
  5. 1.  Installation
  6. 2.  Overview of supported SVGA chipsets and modes
  7. 3.  Description of svgalib functions additional to VGAlib v1.2
  8. 4.  How to use svgalib
  9. 5.  Structure of chipset driver modules
  10. 6.  Changes (see file CHANGES)
  11. 7.  Known bugs
  12. 8.  Goals
  13. 9.  References (location of latest version, apps etc.)
  14.  
  15.  
  16.  
  17. 0.  Introduction
  18.  
  19. This is a low level graphics library for Linux, based on VGAlib 1.2 by
  20. Tommy Frandsen. VGAlib supported a number of standard VGA graphics modes, as
  21. well as Tseng ET4000 high resolution 256-color modes. I added support for my
  22. Cirrus 542x based card, including 15/16/24 bit color modes, and merged in the
  23. Trident code from Toomas Losin's tvgalib. It also provides ET4000
  24. hicolor/truecolor DAC support. There's also an alpha ATI mach32 driver
  25. by Michael Weller.
  26.  
  27. It supports transparent virtual console switching, that is, you can switch
  28. consoles to and from text and graphics mode consoles using alt-[function
  29. key]. Also, svgalib corrects most of VGAlib's textmode corruption behaviour
  30. by catching SIGSEGV, SIGFPE and SIGILL, and ensuring that a program is running
  31. in the currently visible virtual console before setting a graphics mode.
  32.  
  33. When the library is first used by a program at run-time, the chipset is
  34. detected and the appropriate driver is used. This means that a graphics
  35. program will work on any card that is supported by svgalib, if the mode it
  36. uses is supported by the chipset driver for that card. The library is
  37. upwardly compatible with VGAlib.
  38.  
  39. The set of drawing functions provided by svgalib itself is limited (unchanged
  40. from VGAlib) and unoptimized; you can however use vga_setpage and graph_mem
  41. (which points to the 64K VGA framebuffer) in a program or graphics library.
  42. A fast external framebuffer graphics library for linear and banked 1, 2, 3
  43. and 4 bytes per pixel modes is included (it also indirectly supports planar
  44. VGA modes). There's a README in the gl/ directory.
  45.  
  46. One obvious application of the library is a picture viewer. Several are
  47. available, along with animation viewers. See the references at the end of
  48. this document.
  49.  
  50. I have added a simple VGA textmode font restoration utility (restorefont) 
  51. which may help if you suffer from XFree86 textmode font corruption. It can
  52. also be used to change the textmode font. It's in the utils/ directory,
  53. along with a README and some other textmode utilities: restoretextmode (which
  54. saves/restores textmode registers), restorepalette, and the script textmode.
  55. If you run the savetextmode script to save textmode information to /tmp,
  56. you'll be able to restore textmode by running the textmode script.
  57.  
  58. If you have an ET4000 card, you should read the README in the et4000/
  59. directory. You will probably want to replace the ET4000 registers.
  60.  
  61. Directories:
  62. demos/        Demo and test programs.
  63. utils/        Textmode/font utilities.
  64. src/        Main library source.
  65. src/mouse/    Source for mouse interface.
  66. src/keyboard/    Source for keyboard interface.
  67. gl/        External framebuffer graphics library sources, and docs.
  68. support/    DOS-based utility for dumping VGA registers.
  69. et4000/        Notes, utilities and sample registers for ET4000.
  70. mach32/        Notes and a utility for the ATI mach32 driver.
  71. jump/        Configuration files for building DLL shared library.
  72. sharedlib/    Shared library image and stubs.
  73.  
  74. I welcome any questions, comments, suggestions, bug-reports, etc.
  75.  
  76. The source code is rather a mess, but there's hope. The new XFree86-style
  77. driver interface (used by the Cirrus driver) and kernel module graphics
  78. that some are experimenting with should provide some momentum.
  79.  
  80. Harm Hanemaayer
  81. hhanemaa@cs.ruu.nl
  82.  
  83.  
  84.  
  85. 1. Installation
  86.  
  87. Running 'make install' as root should take care of proper installation.
  88. Shared library stubs and images are included in the distribution. Edit the
  89. Makefile to change installation paths and to select the parts that should be
  90. installed, and edit libvga.config to set the monitor and mouse type.
  91.  
  92. If things go wrong, make sure that you have properly installed a recent libc 
  93.  (i.e. deleted /usr/lib/libgcc.(s)a), and that ld.so is up to date.
  94.  
  95. If you have an ET4000 card, read the et4000/README and copy the appropriate
  96. register file to et4000.regs. Remember to set the DAC type.
  97.  
  98. The default behaviour is the following:
  99.  
  100. Shared libraries are installed in /lib and /usr/local/lib, header files
  101. in /usr/local/include (any old header files in /usr/include are removed).
  102. In the Slackware distribution the linkable libraries are in /usr/lib, and the
  103. utilities in /usr/bin; these are now removed by make install. Until now
  104. just doing make install with Slackware may have produced duplicate binaries,
  105. but fortunately the newer version in usr/local/* would have taken precedence
  106. in use.
  107.  
  108. The et4000 registers (et4000.regs) are installed as
  109. /usr/local/lib/libvga.et4000, but only if this file does not exit yet.
  110. The same goes for the configuration file, libvga.config.
  111.  
  112. Textmode utilities are installed in /usr/local/bin. These are restorefont,
  113. runx, restorepalette, dumpreg, restoretextmode, textmode, savetextmode,
  114. and fix132x43.
  115.  
  116. If you change the Makefile to install the static libraries, static libraries
  117. are compiled, and installed in /usr/local/include. Note that you do not need
  118. to do this; the shared library is enough.
  119.  
  120. If you now run 'make', the demo programs are created in the demos/
  121. directory.
  122.  
  123. You can remove previously installed files (not the et4000 registers and
  124. config file) with 'make uninstall'.
  125.  
  126. Note that if you change and recompile the (static) library and install it
  127. (you can use 'make installstaticlib installheaders' for this), programs may
  128. still get linked to the (old) shared library version. Try temporarily
  129. removing the stubs in /usr/local/lib, or specifying libvga.a on the
  130. commandline instead of -lvga.
  131.  
  132.  
  133.  
  134. 2.  Overview of supported SVGA chipsets and modes
  135.  
  136. Supported chipsets:
  137.  
  138.     VGA and compatibles
  139.  
  140.         320x200x256, and the series of 16-color and non-standard
  141.         planar 256 color modes supported by VGAlib, as well as
  142.         720x348x2.
  143.  
  144.     Cirrus Logic GD542x/3x
  145.  
  146.         All the modes, including 256 color, 32K/64K color,
  147.         16M color (3 bytes per pixel) and 32-bit pixel 16M color
  148.         modes (5434). Some bitblt functions are supported.
  149.         The driver doesn't work with mode dumps, but uses a SVGA
  150.         abstraction with mode timings like the X drivers.
  151.  
  152.     Tseng ET4000/ET4000W32(i/p)
  153.  
  154.         Derived from VGAlib; not the same register values.
  155.         ET4000 register values are not compatible; see et4000/README.
  156.         Make sure the colors are right in hicolor mode; the vgatest
  157.         program should draw the same color bars for 256 and hicolor
  158.         modes (the DAC type is defined in et4000.regs or the dynamic
  159.         registers file).
  160.         ET4000/W32 based cards usually have an AT&T or Sierra 
  161.         15025/6 DAC. With recent W32p based cards, you might have
  162.         some luck with the AT&T DAC type.
  163.         If the high resolution modes don't work, you can try
  164.         dumping the registers in DOS using the program in the
  165.         et4000 directory and putting them in a file
  166.         (/usr/local/lib/libvga.et4000 is parsed at runtime if DYNAMIC
  167.         is defined in config.h).
  168.  
  169.         640x480x256, 800x600x256, 1024x768x256,
  170.         640x480x32K, 800x600x32K, 640x480x16M, etc.
  171.  
  172.         Reports of ET4000/W32i/p functionality are welcome.
  173.  
  174.         There may be a problem with the way the hicolor DAC register
  175.         is handled; dumped registers may use one of two timing
  176.         methods, with the value written to the register for a
  177.         particular DAC for a hicolor mode (in vgahico.c) being
  178.         correct for just one of the these methods. As a consequence
  179.         some dumped resolutions may work while others don't.
  180.  
  181.     Trident TVGA 8900C/9000 (and possibly also 8800CS/8900A/B)
  182.  
  183.         Derived from tvgalib by Toomas Losin.
  184.  
  185.         640x480x256, 800x600x256, 1024x768x256 (I and NI)
  186.         Might be useful to add 16-color modes (for those equipped
  187.         with a 512K TVGA9000).
  188.  
  189.     Oak Technologies OTI-037/67/77/87
  190.  
  191.         Driver by Christopher Wiles; includes 32K color modes
  192.         for OTI-087. See README.oak.
  193.  
  194.     ATI Mach32
  195.  
  196.         The alpha driver by Michael Weller supports all BIOS-defined
  197.         modes. However, non-Type 2 DAC's are untested. Check out
  198.         README.mach32 (and README.config). Do send feedback.
  199.  
  200.     S3
  201.  
  202.         The minimal S3 driver source present is a quick hack, and
  203.         does not work. It can be enabled by explicitly setting the
  204.         chipset to S3 in the configuration file, and defining
  205.         SVGALIB_TRY_S3 in the environment.
  206.         Several people have expressed interest and their willingness
  207.         to get something done. 
  208.         I would suggest to use the new driver interface used by
  209.         the cirrus driver (check out timing.*). The XFree86
  210.         S3 server source has it all, but it is very big/complicated
  211.         code.
  212.         [This has now been done, supporting the 864 + SDAC, but
  213.         it doesn't quite work yet]
  214.  
  215.  
  216.  
  217. 3.  Additional VGAlib functions
  218.  
  219.     For vgagl, see gl/README. The mouse and keyboard interfaces are
  220.     "documented" in their headerfiles. There is no automatic mouse
  221.     pointer support; handle it around mouse_(waitfor)update().
  222.  
  223.     vga_init()
  224.         Initialize library; detects chipset and gives up supervisor
  225.         rights. Recommended first line of any program that uses
  226.         svgalib; vga_setchipset can be used before it to avoid
  227.         detection.
  228.  
  229.     vga_modeinfo *vga_getmodeinfo( int mode )
  230.         Returns pointer to mode information structure for a mode.
  231.         width            Width of mode in pixels.
  232.         height            Height of mode.
  233.         bytesperpixel        Bytes per pixel (framebuffer-wise).
  234.                     This is 1, 2 or 3, and 0 for planar
  235.                     VGA modes.
  236.         linewidth        Logical scanline width in bytes.
  237.         colors            2, 16, 256, 32768, 65536 or 16M
  238.         maxlogicalwidth     Maximum logical scanline width (bytes).
  239.         startaddressrange     Mask of changeable bits of start
  240.                     address (in pixels).
  241.         maxpixels        Maximum number of pixels that will
  242.                     fit in a logical screen (depends on
  243.                     video memory).
  244.         haveblit        Indicates whether bitblit functions
  245.                     are available.
  246.                     Bit 0: Bitblit
  247.                     Bit 1: Fillblit
  248.                     Bit 2: Imageblit
  249.         flags            Miscellaneous flags.
  250.                     Bit 0: Setreadpage/setwritepage
  251.                            available.
  252.                     Bit 1: Mode is interlaced.
  253.                     Bit 2: Mode is mode-X like (planar
  254.                            256 colors).
  255.                     Bit 3: Dynamically loaded mode.
  256.                     Bit 4: Can set to linear addressing.
  257.                     Bit 5: Linear addressing enabled.
  258.                     Bit 6: The following fields in this
  259.                            information structure are set:
  260.  
  261.         chiptype        the chiptype that was detected/set.
  262.         memory            memory available on the card in KB
  263.         linewidth_unit        use only a multiple of this value for
  264.                     set_logicalwidth or set_displaystart
  265.                     to ensure graceful alignment of lines
  266.                     onto the vga memory in this mode.
  267.         linear_aperture        ptr to a mmaped secondary linear
  268.                     framebuffer (NULL if unavailable)
  269.         aperture_size        size of framebuffer in KB. 0 if
  270.                     unavailable.
  271.         set_aperture_page    a function taking an int as parameter
  272.                     to select a page in the framebuffer if
  273.                     aperture_size<memory.
  274.         extensions        pointer to additional info(contents of
  275.                     eeprom for mach32 driver.)
  276.  
  277.     int vga_getcurrentmode()
  278.         Returns the current mode.
  279.  
  280.     int vga_getdefaultmode()
  281.         Returns the default graphics mode number from the
  282.         GSVGAMODE environment variable; -1 if undefined. The
  283.         environment variable can either be a mode number or a mode
  284.         name.
  285.  
  286.     int vga_getcurrentchipset()
  287.         Returns the current SVGA chipset.
  288.  
  289.     void vga_setmousesupport( int stat )
  290.         Set mouse support; 0 disabled (default), 1 enabled. If
  291.         enabled, the mouse is set up for screen resolution after a
  292.         mode set. You can use the function to set up the mouse in
  293.         vgamouse.h instead for more flexibility.
  294.  
  295.     void vga_runinbackground( int stat )
  296.         Enable/disable background running of a graphics program
  297.         (1 = enable). Normally, the program is suspended while
  298.         not in the current virtual console. A program can only
  299.         safely run in the background if it doesn't do any video
  300.         access during this time.
  301.  
  302.     int vga_oktowrite()
  303.         Indicates whether the program is in the console currently
  304.         visible on the screen, that is, whether it is OK to write
  305.         to video memory (if running in the background has been allowed
  306.         with the function above). Note that this is not entirely
  307.         safe, since a console switch interrupt may occur during a
  308.         video operation. [best to avoid this function]
  309.  
  310.     int vga_getkey()
  311.         Read a character from the keyboard without waiting; returns
  312.         -1 if no key pressed.
  313.  
  314.     void vga_lockvc()
  315.         Disables virtual console switching for safety. Recommended
  316.         when doing register I/O or low-level device handling. Used
  317.         by mouse functions.
  318.  
  319.     void vga_unlockvc()
  320.         Re-enables virtual console switching.
  321.  
  322.     void vga_setpage( int page )
  323.         Set 64K SVGA page number.
  324.  
  325.     unsigned char *graph_mem;
  326.         Pointer to 64K VGA frame buffer window. Can be used by
  327.         graphics library on top of VGAlib.
  328.  
  329.     unsigned char *vga_getgraphmem()
  330.         Returns graph_mem.
  331.  
  332.     void vga_waitretrace();
  333.         Wait for vertical retrace. Use to synchronize animation with
  334.         monitor refresh.
  335.  
  336.     int vga_claimvideomemory( int m ) {
  337.         Declare the amount of video memory in bytes that is to
  338.         be saved when temporarily switching to textmode. Returns
  339.         nonzero if the amount is not available. Defaults to one
  340.         screen when a mode is set. Use this if you are using more
  341.         than one screen of video memory.
  342.  
  343.     void vga_setchipset( int chipset )
  344.         Force chipset (when chipset detection fails).
  345.         vga_setchipset(VGA) can be useful if the chipset specific
  346.         stuff or the SVGA detection stuff gives problems.
  347.  
  348.     void vga_setchipsetandfeatures( int chipset, int par1, int par2 )
  349.         Force chipset, and optional parameters like the exact
  350.         chipset type and the amount of video memory installed.
  351.         [Only for debugging.]
  352.  
  353.     void vga_setlogicalwidth( int l )
  354.         Set the logical scanline width to l bytes. Must be a
  355.         multiple of 8. Only changes the VGA register, drawing
  356.         functions don't take it into account.
  357.  
  358.     void vga_setdisplaystart( int a )
  359.         Set the display start address to a, where the address is the
  360.         number of pixels offset from the start of video memory,
  361.         except for hicolor/truecolor modes, which use a unit of
  362.         1 byte. Can be used for page-flipping and virtual desktop
  363.         scrolling. May not work properly for 16 color modes.
  364.  
  365.     void vga_setrgbcolor( int r, int g, int b )
  366.         Set the current color to RGB values r, g, and b, each in
  367.         the range 0-255. Does not make sense in 256-color modes.
  368.  
  369.     void vga_setmodeX()
  370.         Try to enable Mode X-like memory organization (only for
  371.         256 color modes using up to 256K of memory like 320x200x256
  372.         and 640x400x256; 320x240x256 etc. are Mode X-like by default).
  373.         This is not guaranteed to work. A new mode should be defined
  374.         for planar 320x200x256.
  375.  
  376.     void vga_copytoplanar256( unsigned char *virtual, int pitch,
  377.     int voffset, int vpitch, int w, int h )
  378.         Copy part of linear virtual screen in system memory to Mode
  379.         X video memory. pitch is the logical width of the virtual
  380.         screen; voffset is the address offset into video memory;
  381.         vpitch is the logical scanline length of the screen; (w, h)
  382.         is the size of the area to copy in pixels (width must be
  383.         multiple of 4).
  384.  
  385.     void vga_copytoplanar16( unsigned char *virtual, int pitch,
  386.     int voffset, int vpitch, int w, int h )
  387.         Similar function for 16 color modes (untested); assumes
  388.         pixels stored in consecutive bytes ranging from 0 to 15 in
  389.         the virtual screen.
  390.  
  391.     void vga_copytoplane( unsigned char *virtual, int pitch,
  392.     int voffset, int vpitch, int w, int h, int plane )
  393.         Similar to vga_copytoplanar16, but only copies one of the
  394.         four 16-color mode planes (plane should be in the range
  395.         0-15).
  396.  
  397.     int vga_getpixel( int x, int y )
  398.         Read a pixel value from the screen. Was missing for
  399.         planar modes (vgagl does it for packed-pixel modes).
  400.  
  401.     void vga_setlinearaddressing()
  402.         Switch to linear addressing mode. Only valid on Cirrus,
  403.         with less than 16Mb of memory (maps at 14Mb).
  404.         vga_getgraphmem returns the linear framebuffer address
  405.         (fixed at 0x40000000; letting the kernel give the address
  406.         wastes 2Mb). vga_ drawing functions are not supported;
  407.         vgagl does support it (gl_setcontextvga).
  408.  
  409.     int vga_ext_set(unsigned what, ...)
  410.         set several extended features. Defined are sofar:
  411.  
  412.         vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_SET)
  413.         returns an int with the i-th bit set if i is a valid "what"
  414.         parameter for vga_ext_set.
  415.  
  416.         vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL)
  417.         returns an int with the i-th bit set if i is a valid "what"
  418.         parameter for vga_accel.
  419.  
  420.         vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_FLAGS)
  421.         returns an int with bitflags. Bits that are set are supported
  422.         in the current mode.
  423.  
  424.         vga_ext_set(VGA_EXT_SET, int bitflags)
  425.         set all flags that are set in the int bitflags, do not touch
  426.         any other flags. Returns previous setting of all flags.
  427.         
  428.         vga_ext_set(VGA_EXT_CLEAR, int bitflags)
  429.         clear all flags that are set in the int bitflags, do not touch
  430.         any other flags. Returns previous setting of all flags.
  431.  
  432.         vga_ext_set(VGA_EXT_RESET, int bitflags)
  433.         set all flags to the corresponding bits of bitflags.
  434.         Returns previous setting of all flags.
  435.  
  436.         You can set flags, and their settings are remembered if not
  437.         supported in the current mode. This is to avoid problems when
  438.         switching VC's. The only flag sofar supported is VGA_CLUT8. Use:
  439.  
  440.         vga_ext_set(VGA_EXT_SET, VGA_CLUT8)
  441.  
  442.         to make the color lookup table for Mach32 cards with type 2 DAC's
  443.         8 bit per red, green, blue wide in all (even VGA) 256 color modes.
  444.  
  445.     int vga_accel(unsigned operation, ...)
  446.         interface to more complicated blitter functions. Not yet
  447.         implemented or even defined.
  448.         
  449.     void vga_safety_fork( void (*shutdown_routine(void))
  450.         Calling this at the start of a program results in a better
  451.         chance of textmode being restored in case of a crash.
  452.  
  453.     A note about vga_drawscansegment:
  454.     In hicolor/truecolor modes, the length must be given in bytes,
  455.     not pixels. Also, for planar modes (16/mode X), it must be a multiple
  456.     of 8.
  457.  
  458.     The following functions are only defined if the corresponding flag
  459.     in the haveblit field of the mode info structure is set. They are
  460.     not meant as graphics primitives, but more as an interface to the
  461.     blitter in the Cirrus 5426. Note: the maximum height is 1024 for
  462.     the Cirrus routines. They are available on the Mach32 in all non
  463.     VGA modes. The Mach32 expects the pitch to be a multiple of 8
  464.     PIXELS! The Mach32 works pixel oriented. It can mostly use x and y
  465.     Values from 0..1535 and width and heights from 0..2047. The driver
  466.     tries to move around the base address of the Accelerator to perform
  467.     your operations.
  468.  
  469.     void vga_bitblt( int srcaddr, int destaddr, int w, int h,
  470.     int pitch )
  471.         Bitblit (copy rectangular area in video memory), addresses
  472.         are offsets into video memory (up to 2M). The pitch is the
  473.         logical width of the screen. Height h is in Pixels, Width
  474.         w is in BYTES!
  475.  
  476.     void vga_fillblt( int destaddr, int w, int h, int pitch, int color )
  477.         Fill a rectangular area in video memory with a single color.
  478.         w and h are defined as above.
  479.  
  480.     void vga_imageblt( void *srcaddr, int destaddr, int w, int h, int
  481.     pitch )
  482.         Write a rectangular bitmap from system memory to video
  483.         memory.
  484.  
  485.     The following two are only supported for Mach32 currently:
  486.  
  487.     void vga_hlinelistblt( int ymin, int n, int *xmin, int *xmax,
  488.     int pitch, int c )
  489.         xmin and xmax are pointers to arrays of n integers.
  490.         There are n horizontal lines drawn, for i in 0..(n-1)
  491.         a horizontal line will be drawn from pixel (xmin[i],ymin+i)
  492.         to (xmax[i],ymin+i) using color c. Pixel (0,0) is considered
  493.         to be at the beginning of vga_memory.
  494.         (compare with vga_setdisplaystart(0))
  495.  
  496.     void vga_blitwait(void)
  497.         wait for any accelerator operation to finish. Though already
  498.         implemented not yet useful.
  499.  
  500.  
  501. 4.  How to use svgalib (and vgagl)
  502.  
  503. Do use vga_init as a first line. This will give up root priviledges right
  504. after initialization, making setuid-root binaries relatively safe.
  505.  
  506. The function vga_getdefaultmode() checks the environment variable GSVGAMODE
  507. for a default mode, and returns the corresponding mode number. The
  508. environment string can either be a mode number (compatible with (S)VGAlib
  509. Ghostscript), or a mode name as in (G640x480x2, G640x480x16, G640x480x256,
  510. G640x480x32K, G640x480x64K, G640x480x16M). As an example, to set the default
  511. graphics mode to 640x480, 256 colors, use: export GSVGAMODE=G640x480x256
  512. on the bash command line. If a program needs just a linear VGA/SVGA resolution
  513. (as required by vgagl), only modes where bytesperpixel in the vga_modeinfo
  514. structure is greater or equal to 1 should be accepted (this is 0 for tweaked
  515. planar 256-color VGA modes).
  516.  
  517. Use vga_setmode(graphicsmode) to set a graphics mode. Use vga_setmode(TEXT) to
  518. restore textmode before program exit.
  519.  
  520. Programs that use svgalib must include vga.h; if they also use the external
  521. graphics library vgagl, vgagl.h must also be included. Linking must be done
  522. with -lvga (and -lvgagl *before* -lvga, if vgagl is used). You can save binary
  523. space by removing the chipset drivers in config.h if you only use standard VGA
  524. (only for static binaries; better link with the shared library).
  525.  
  526. Functions in the vgagl library have the prefix "gl_". To initialize vgagl,
  527. the graphics context must be set. Example:
  528.  
  529.     vga_setmode(G320x200x256);
  530.     gl_setcontextvga(G320x200x256);
  531.  
  532. In this example, the context is set to the physical screen. The context can
  533. be saved (only the screen type, not the contents) into a variable, e.g.
  534.  
  535.     GraphicsContext physicalscreen;
  536.  
  537.     gl_getcontext(&physicalscreen).
  538.  
  539. To define a virtual screen in system memory, use gl_setcontextvgavirtual:
  540.  
  541.     gl_setcontextvgavirtual(G320x200x256)
  542.  
  543. which allocates space for a screen identical to 320x200x256 graphics mode,
  544. and makes this virtual screen the current graphics context.
  545.  
  546. The virtual screen can now be copied to the physical screen as follows:
  547.  
  548.     gl_copyscreen(&physicalscreen);
  549.  
  550. Note that with a virtual screen in system memory, it is possible to add
  551. fast X-Window support to a program, using MITSHM to copy the framebuffer
  552. to the screen window.
  553.  
  554.  
  555.  
  556. 5.  Structure of the chipset drivers
  557.  
  558.     The chipset specific registers saving function (saveregs) is only
  559.     used directly to save the textmode registers at initialization.
  560.  
  561.     The chipset specific registers restoring function (setregs) is only
  562.     used directly to return to textmode, and when setting a VGA mode
  563.     after an SVGA mode.
  564.  
  565.     The registers for each mode are stored like the ET4000 modes in
  566.     VGAlib 1.2, i.e. the extended registers at the end. The following
  567.     functions must be provided in a driver:
  568.  
  569.     saveregs( unsigned char regs[] )
  570.         Saves the chipset-specific registers in regs, starting at
  571.         array index EXT (after the VGA registers).
  572.  
  573.     setregs( unsigned char regs[] )
  574.         Sets the chipset-specific registers stored in regs from
  575.         index EXT.
  576.  
  577.     modeavailable( int mode )
  578.         Returns nonzero if mode is available (should check video
  579.         memory).
  580.  
  581.     getmodeinfo( vga_modeinfo *modeinfo )
  582.         Fills in chipset specific field of mode information
  583.         structure: maxlogicalwidth, startaddressrange (mask of
  584.         significant bits), and maxpixels (video memory divided by
  585.         the number of bytes per pixel). haveblit indicates whether
  586.         bitblt functions are available.
  587.         Note: providing extended info and an aperture with size
  588.         >= memory and setting bits 4 and 6 in flags will
  589.         automatically enable linear addressing support. 
  590.         
  591.  
  592.     setmode( int mode, int previous_mode )
  593.         Sets all registers for a mode; returns nonzero if mode not
  594.         available. __vga_setregs can be called to set the VGA
  595.         registers.
  596.  
  597.     unlock()
  598.         Unlocks chipset-specific registers.
  599.  
  600.     lock()
  601.         Lock (protect) chipset-specific registers. Currently not
  602.         called.
  603.  
  604.     test()
  605.         Identify chipset; initialize (check memory and type) and
  606.         return nonzero if detected.
  607.  
  608.     setpage( int page )
  609.         Set 64K page number to be mapped at 0xa0000.
  610.  
  611.     init( int force, int par1, ... )
  612.         Initialize memory and type; called by test. If force is 1,
  613.         the chiptype or the amount of memory can be forced (this
  614.         is pretty useless).
  615.  
  616.     The following functions provide for things like page flipping
  617.     and hardware scrolling virtual desktops.
  618.  
  619.     setdisplaystart( int addresss )
  620.         Sets the display start address in video memory in pixels.
  621.  
  622.     setlogicalwidth( int width )
  623.         Sets the logical scanline length in bytes. Usually a
  624.         multiple of 8.
  625.  
  626.     The function getchipset() in vga.c must call the test routine for
  627.     the chipset. The chipsetfunctionslist must be have a pointer
  628.     to the chipsetfunctions table for the chipset (which is the only
  629.     global symbol in a chipset driver). Also, vga.h contains a magic
  630.     number for each chipset. Also driver_names[] in vga.c has to
  631.     contain a name for each driver at the correct position.
  632.  
  633.  
  634.  
  635. 6.  Changes
  636.  
  637. See the file CHANGES.
  638.  
  639.  
  640.  
  641. 7.  Bugs
  642.  
  643.     Using a 132 column textmode may cause graphics modes to fail. Try
  644.     using something like 80x28.
  645.  
  646.     The console switching doesn't preserve some registers that may be
  647.     used to draw in planar VGA modes.
  648.  
  649.     Wild console switching can cause the text screen to be corrupted,
  650.     especially when switching between two graphics consoles.
  651.  
  652.     On ET4000, having run XFree86 may cause high resolution modes to
  653.     fail (this is more XFree86's fault).
  654.  
  655.     The Trident probing routine in the XFree86 server may cause standard
  656.     VGA modes to fail after exiting X on a Cirrus. Try putting a 'Chipset'
  657.     line in your Xconfig to avoid the Trident probe, or use the link kit
  658.     to build a server without the Trident driver. Saving and restoring
  659.     the textmode registers with savetextmode/textmode (restoretextmode)
  660.     should also work. [Note: svgalib now resets the particular extended
  661.     register, but only if the Cirrus driver is used (i.e. the chipset
  662.     is not forced to VGA)] [This is fixed in XFree86 v2.1]
  663.  
  664.     Some Paradise VGA cards may not work even in standard VGA modes. Can
  665.     anyone confirm this?
  666.  
  667.     Piping data into a graphics program has problems. I am not
  668.     sure why. A pity, since zcatting a 5Mb FLC file into flip on a 4Mb
  669.     machine would be fun.
  670.  
  671.     The tseng3 program doesn't recognize any modes on some ET4000 cards.
  672.     Also ET4000 cards with a Acumos/Cirrus DAC may only work correctly
  673.     in 64K color mode.
  674.  
  675.  
  676. 8.  Goals
  677.  
  678.     I think the ability to use a VGA/SVGA graphics resolution in one
  679.     virtual    console, and being able to switch to any other virtual console
  680.     and back makes a fairly useful implementation of graphics modes in
  681.     the Linux console.
  682.  
  683.     Programs that use svgalib must be setuid root. I don't know how
  684.     desirable it is to have this changed; direct port access can hardly
  685.     be done without. Root priviledges can now be given up right after
  686.     initialization. I noticed some unimplemented stuff in the kernel
  687.     header files that may be useful, although doing all register I/O via
  688.     the kernel would incur a significant context-switching overhead. An
  689.     alternative might be to have a pseudo /dev/vga device that yields
  690.     the required permissions when opened, the device being readable by
  691.     programs in group vga.
  692.  
  693.     It is important that textmode is restored properly and reliably; it
  694.     is fairly reliable at the moment, but fast console switching back
  695.     and forth between two consoles running graphics can give problems.
  696.     Wild virtual console switching also sometimes corrupts the contents
  697.     of the textmode screen buffer (not the textmode registers or font).
  698.     Also if a program crashes it may write into the area where the saved
  699.     textmode registers are stored, causing textmode not be restored
  700.     correctly. It would be a good idea to somehow store this information
  701.     in a 'safe' area (say a kernel buffer). Note that the safety_fork
  702.     thing has the same idea.
  703.  
  704.     Currently, programs that are in graphics mode are suspended while
  705.     not in the current virtual console. Would it be a good idea to let
  706.     them run in the background, virtualizing framebuffer actions (this
  707.     should not be too hard for linear banked SVGA modes)? It would be
  708.     nice to have, say, a raytracer with a real-time display run in the
  709.     background (although just using a seperate real-time viewing
  710.     program is much more elegant).
  711.  
  712.     Anyone wanting to rewrite it all in a cleaner way (something with
  713.     loadable kernel modules shouldn't hurt performance with linear
  714.     framebuffer/vgagl type applications) is encouraged.
  715.  
  716.     Also, if anyone feels really strongly about a low-resource and
  717.     truecolor supporting graphical window environment with cut-and-paste,
  718.     I believe it would be surprisingly little work to come up with a
  719.     simple but very useful client-server system with shmem, the most
  720.     useful applications being fairly trivial to write (e.g. shell
  721.     window,    bitmap viewer).    And many X apps would port trivially.
  722.  
  723.  
  724. 9.  References
  725.  
  726.     The latest version of svgalib can be found on sunsite.unc.edu and
  727.     mirrors    as svgalibXXX.tgz in the directory /pub/Linux/libs/graphics.
  728.  
  729.     The original VGAlib is on tsx-11.mit.edu,
  730.     pub/linux/sources/libs/vgalib12.tar.Z.
  731.     tvgalib-1.0.tar.Z is in the same directory.
  732.     SLS has long been distributing an old version of VGAlib.
  733.     Slackware keeps a fairly up-to-date version of svgalib, but it
  734.     may be installed in different directories from what svgalib likes
  735.     to do by default. The current svgalib install tries to remove most
  736.     of this. It also removes /usr/bin/setmclk and /usr/bin/convfont,
  737.     which is a security risk if setuid-root.
  738.     If you want to recompile the shared library, you will need the
  739.     DLL 'tools' package (found on tsx-11.mit.edu, GCC dir).
  740.  
  741.     Viewers (in /pub/Linux/apps/graphics/viewers on sunsite):
  742.  
  743.     spic        Picture viewer; JPG/PPM/GIF; truecolor; scrolling.
  744.     zgv        Full-featured viewer with nice file selector.
  745.     see-jpeg    Shows picture as it is being built up.
  746.     mpeg-linux      svgalib port of the Berkeley MPEG decoder
  747.             (mpeg_play); it also includes an X binary.
  748.     flip        FLI/FLC player (supports SVGA-resolution).
  749.  
  750.     Games (in /pub/Linux/games on sunsite):
  751.  
  752.     bdash        B*lderdash clone with sound.
  753.     sasteroids    Very smooth arcade asteroids game.
  754.     yatzy        Neat mouse controlled dice game.
  755.     vga_cardgames    Collection of graphical card games.
  756.     vga_gamespack    Connect4, othello and mines.
  757.     wt        Free state-of-the-art Doom-like engine.
  758.  
  759.     Docs
  760.  
  761.     In the vga directory of the SIMTEL MSDOS collection, there is a
  762.     package called vgadoc3 which is a collection of VGA/SVGA register
  763.     information.
  764.  
  765.     The XFree86 driver sources distributed with the link-kit may be
  766.     helpful.
  767.  
  768.     Miscellaneous
  769.  
  770.     There's an alternative RAW-mode keyboard library by Russell Marks for
  771.     use with svgalib on sunsite.
  772.  
  773.     LIBGRX, the extensive framebuffer library by Csaba Biegl distributed
  774.     with DJGPP, has been ported to Linux. Contact Hartmut Schirmer
  775.     (phc27@rz.uni-kiel.d400.de, subject prefix "HARTMUT:"). A more
  776.     up-to-date port by Daniel Jackson (djackson@icomp.intel.com) is
  777.     on sunsite.
  778.  
  779.     The vgalib ghostscript device driver sources can be found on
  780.     sunsite, /pub/Linux/apps/graphics.
  781.     Ghostscript patches from Slackware: ftp.cdrom.com, /pub/linux/misc.
  782.     gnuplot patches are on sunsite.
  783.  
  784.     Mitch D'Souza has written font functions that work in 16 color modes
  785.     and can use VGA textmode (codepage format) fonts; these can be found
  786.     in his g3fax package in sunsite. These functions may go into a later
  787.     version of svgalib.
  788.