home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tvision / gravis / common / gr.doc < prev    next >
Encoding:
Text File  |  1994-05-23  |  16.5 KB  |  449 lines

  1. Gr        The commonly used graphics protocol of the MyMouse software
  2. ver 1.21    package, the Graphics Vision library, and MetaGraph.
  3.         Copyright (c) 1993 by Matthias Köppe.
  4.  
  5. -----------------------------------------------------------------------------
  6.  
  7. Gr is a Turbo Pascal unit that manages the VGA memory, provides information
  8. about the graphics mode and handles commonly used graphic data structures.
  9. Further, it is the central unit of the pointer/quality conception for
  10. graphical modularization and the notification chain conception.
  11.  
  12. Version 1.21 supports DPMI; and it provides the 7.0 procedures NewCache,
  13. DispoceCache, and GetShiftState for 6.0.
  14.  
  15. P r o c e d u r e s
  16.  
  17.  
  18. procedure SetGrMode(Mode: Word);
  19.  
  20.   SetGrMode sets the parameters of a graphics mode but does not initialize it.
  21.   The Mode parameter is one of the following grXXXX constants. They identify
  22.   - independently from the computer system - the graphics modes.
  23.  
  24.     grVgaLoStd        * 640 x 200, 2 pages, normal arrangement
  25.     grVgaLoPak          640 x 200, 2 pages, packed arrangement
  26.  
  27.     grVgaMedStd        * 640 x 350, 2 pages, normal arrangement
  28.     grVgaMedOne        * 640 x 350, 1 page
  29.     grVgaMedPak          640 x 350, 2 pages, packed arrangement
  30.  
  31.     grVgaHiStd        * 640 x 480, 1 page
  32.  
  33.     grSvgaStd          800 x 600, 1 page
  34.  
  35.     grVga256Std          320 x 200, 1 page, 256 colors
  36.  
  37.     grVgaWdMedStd      720 x 350, 2 pages, normal arrangement
  38.     grVgaWdMedOne      720 x 350, 1 page
  39.     grVgaWdMedPak      720 x 350, 2 pages, packed arrangement
  40.     grVgaWdHiStd      720 x 480, 1 page
  41.  
  42.   NOTE: Only the modes marked with an asterix (*) are standard modes, i.e.
  43.     they are supported by the BGI.
  44.   There are several so-called modifications of a graphics mode. The page
  45.   arrangement differs from modification to modification. Normal arrangement
  46.   is necessary for applications using BGI. Packed arrangement is useful
  47.   for applications using the VGA rest memory with the VgaMem unit. One-page
  48.   modes are useful if you need a very large rest memory.
  49.  
  50.   In chapter Methods 1, you will find information about graphics mode
  51.   initialization.
  52.  
  53. procedure SetActivePage(Page: Word);
  54.  
  55.   This procedure sets the screen page that shall be modified. The parameter
  56.   is assigned to the ActivePage variable. The ActiveSeg variable is set
  57.   to the appropriate real mode memory segment selector.
  58.   Further, SetActivepage calls ActivePageProc for notifying e.g. the BGI.
  59.  
  60. procedure SetVisualPage(Page: Word);
  61.  
  62.   This procedure sets the screen page that shall appear on screen. Always
  63.   use this procedure, never Graph.SetVisualPage.
  64.  
  65.  
  66. Following routines should be called instead of direct assignments to the
  67. respective data structures.
  68.  
  69. procedure SetDrawOrigin(x, y: Integer);
  70.  
  71.   This procedure sets the drawing origin to the given co-ordinates and
  72.   informs other modules by a ClipNotifyProc(gcnUpdOrigin) call.
  73.  
  74. procedure SetDrawOriginP(var P: TPoint);
  75.  
  76.   This procedure sets the drawing origin to the given point and informs other
  77.   modules by a ClipNotifyProc(gcnUpdOrigin) call.
  78.  
  79. procedure SetClipRect(x1, y1, x2, y2: Integer);
  80.  
  81.   This procedure sets the clipping rectangle to the given co-ordinates and
  82.   informs other modules by a ClipNotifyProc(gcnUpdAll) call.
  83.   NOTE: Turbo Vision notation is used, i.e. x2, y2 are just outside the
  84.     drawing region.
  85.  
  86. procedure SetClipRectR(var R: TRect);
  87.  
  88.   This procedure sets the clipping rectangle to the given rectangle and
  89.   informs other modules by a ClipNotifyProc(gcnUpdAll) call.
  90.  
  91.  
  92. Following procedures are needed for direct VGA memory allocation.
  93.  
  94. function PageSeg(Page: Word): Word;
  95.  
  96.   This function returns the real mode segment selector of a screen page.
  97.  
  98. function ReserveSegs(Size: Integer): LongInt;
  99.  
  100.   This procedure reserves Size paragraphs (16 bytes) of free VGA memory. The
  101.   starting segment is returned in the lower word. If Size is set -1,
  102.   the largest available memory block is reserved. The actually reserved
  103.   block size in paragraphs is returned in the higher word.
  104.  
  105.  
  106. Following routines provide an interface to the VGA BIOS.
  107.  
  108. procedure SetBiosMode(Mode: Byte);
  109.  
  110.   This procedure initializes a screen mode by a VGA BIOS function call. The
  111.   Mode values are partly device-dependent. Choose
  112.  
  113.   $0E    for 640 x 200 x 16
  114.   $10    for 640 x 350 x 16
  115.   $12    for 640 x 480 x 16
  116.   $13    for 320 x 200 x 256
  117.  
  118. procedure RestoreTextMode;
  119.  
  120.   This procedure switches back to the text mode active before the first
  121.   SetBiosMode call.
  122.  
  123. procedure Extend;
  124.  
  125.   This procedure modifies an initialized graphics mode of 640 coloumns
  126.   width such that it provides 720 coloumns. For initializing the grVgaWdHiStd
  127.   mode, call SetBiosMode($12) and Extend.
  128.  
  129. procedure InitBiosGraph;        * InitGraphProc, quality 10
  130.  
  131.   This procedure determines the appropriate standard VGA BIOS mode from
  132.   the Gr mode and calls SetBiosMode. If necessary, it also calls Extend.
  133.   NOTE:  SuperVGA modes are device-dependent and cannot be initialized by
  134.      InitBiosGraph. If you wish such a graphics mode by InitGraphProc,
  135.   write a procedure of higher "quality". (See pointer/quality conception)
  136.  
  137. procedure CloseBiosGraph;        * CloseGraphProc, Qualität 10
  138.  
  139.   This procedure calls RestoreTextMode, so that graphics is de-initialized.
  140.  
  141.  
  142. The other routines are semi-internal ones and are therefore not documented.
  143.  
  144.  
  145. V a r i a b l e s
  146.  
  147.  
  148. * Parameters of the graphics mode (set by SetGrMode)
  149.  
  150.   GrMode    Word    Gr mode (grXXXX, parameter of SetGrMode)
  151.   SavedTextMode    Byte    BIOS number of the previous text mode
  152.  
  153.   SizeX        Word    Horizontal pixel count (e.g. 640)
  154.   SizeY        Word    Vertical piexl count (e.g. 480)
  155.  
  156.   Page0Seg    Word    Segment address of page 0
  157.   Free0Seg    Word    Segment address of free block 0
  158.   Page1Seg    Word    Segment address of page 1
  159.   Free1Seg    Word    Segment address of free block 1
  160.   EndSeg    Word    Segment address of graphics memory end
  161.  
  162.   GrFlags    Word    0 for 16 colors        1 for 256 colors
  163.   ScreenF    Word    Aspect factor * 10000
  164.   RealBytesPerLine    Number of bytes in one pixel row
  165.         Word
  166.  
  167. * Current graphics parameters
  168.  
  169.   ActivePage    Word    Number of active screen page (0 or 1)
  170.   ActiveSeg    Word    Active screen page segment address
  171.   BytesPerLine    Word    Number of bytes in one pixel row
  172.  
  173. * Shared additional parameters
  174.  
  175.   DrawOrigin    TPoint    Drawing origin of higher graphical routines
  176.   ClipRect    TRect    Clipping rectangle for graphical routines
  177.  
  178. * MetaGraph support
  179.  
  180.   MetaState    Word    Drawing and/or recording of graphics
  181.   MetaClipRect    TRect    Global clipping rectangle during meta output
  182.   MetaOrigin    TRect    Global draw origin during meta output
  183.  
  184. * Pointer/quality conception
  185.  
  186.   UserXX    pointer    Freely available pointers, intended for commonly
  187.             used graphical routines.
  188.   QualityXX    Byte    Quality-indicating bytes of the respective pointers.
  189.  
  190. * Segment selectors for version 6.0
  191.  
  192.   Seg0040    Word    Contains the value $0040.
  193.   SegA000    Word    Contains the value $A000.
  194.   SegB000    Word    Contains the value $B000.
  195.   SegB800    Word    Contains the value $B800.
  196.  
  197. * Storage of VGA registers
  198.  
  199.   UserRegArea    array    Data area for register storage
  200.         of Byte
  201.  
  202.  
  203. M e t h o d s
  204.  
  205. 1 Graphics Mode Initialization
  206.  
  207.   After setting a graphics mode by Gr.SetGrMode, you have several
  208.   possibilities to initialize the adaptor. We recommend method (f).
  209.  
  210.   (a) Graph.InitGraph    Call this procedure if you want to use the Graph unit
  211.             for graphical output. Pay attention to using the
  212.             appropriate drive/mode values.
  213.   (b) BGI.InitBgiGraph    This procedure calls Graph.InitGraph and automatically
  214.             uses the right value, which is determined from the
  215.             set Gr mode.
  216.   (c) Gr.SetBiosMode    Call this procedure if you want to initialize a
  217.             graphics mode that is supported by your VGA BIOS.
  218.             The required parameter is dependent from your
  219.             adaptor card (non-standard modes).
  220.   (d) Gr.InitBiosGraph    This procedure calls Gr.SetBiosMode and automatically
  221.             uses the appropriate parameter if a standard mode
  222.             is set.
  223.   (e) Direct access    Use system-dependent direct access to your adaptor
  224.             card to initialize graphics modes which are not
  225.             supported from the adaptor's BIOS.
  226.   (f) UserParams(0);    Use these instructions for initialization the
  227.       InitGraphProc;    graphics appropriately to the requirements of the
  228.             installed software modules.
  229.             (See pointer/quality conception.)
  230.  
  231. 2 Switching Back to Text Mode.
  232.  
  233.   You should use the same method as applied at initialization.
  234.  
  235.   (a) Graph.CloseGraph
  236.   (b) BGI.CloseBgiGraph
  237.   (c) Gr.RestoreTextMode
  238.   (d) Gr.CloseBiosGraph
  239.   (e) Again direct access
  240.   (f) UserParams(0); CloseGraphProc;
  241.  
  242.  
  243. P o i n t e r / Q u a l i t y   C o n c e p t i o n
  244.  
  245. The Gr unit provides a certain number of freely available pointers, which
  246. are to store addresses of far-coded routines, so that program modules can
  247. make use of certain services without knowing the module that provides these
  248. services.
  249.  
  250. Most of these pointers are still unused, so that Gr does not know the
  251. calling scheme of the respective routines. Gr's initialization part puts
  252. a dummy routine, which takes the routine's parameters from the stack, in
  253. all UserXX pointers. Therefore, the number of parameter words must be given
  254. in the AX register when calling. If you want to call a user routine from
  255. Pascal, use the macro UserParams(Count: Word).
  256.  
  257. Gr's got a mechanism with which it is possible for multiple module to
  258. provide routines for the same purpose, from which only the "best" is
  259. installed, independently from the order in the uses-unit list.
  260.  
  261. Each pointer UserXX has got a quality-indicating byte QualityXX. If the
  262. initialization parts of the modules want to install their routines, they are
  263. to check whether they have got a higher quality than these previously
  264. installed.
  265.  
  266. Some of the pointers are already reserved. In Gr, alias identifiers
  267. (var ... absolute UserXX) are defined, often as procedural variables, so that
  268. you can easily access them from pascal programming level.
  269.  
  270. UserXX    Alias           Service                    Supporter
  271. ------    --------------  --------------------------------------  -----------
  272. User00    ExtSave         MetaGraph - Recording [external]    MetaGr
  273. User01    LineProc        Exported Line Drawing Routine        MetaGr, BGI
  274. User02    ClipNotifyProc    Clipping Notification            BGI
  275. User03    InitGraphProc    Initialize Graphics by GrMode        BGI, Gr
  276. User04    CloseGraphProc    De-initialize Graphics            BGI, Gr
  277. User05    ActivePageProc    Set active page by ActivePage        BGI
  278. User06  ChParamsProc    Change Graphics Parameters        MetaGr, BGI
  279. User07    GrNotifyProc    Graphics Notification Chain        --
  280.  
  281. The "Supporter" column shows the units which install this service in the
  282. descending order of the qualities.
  283.  
  284. Example
  285.  
  286.   Let's assume you are using a graphical user interface, which uses the
  287.   MetaGraph unit for maximal performance instead of the Graph unit, for
  288.   your applications. Of course, Graph is not initialized then.
  289.   Now you insert an element which requires the Graph unit into the GUI.
  290.   You will just have to insert the BGI unit in a USES list (this unit links
  291.   the Graph unit routines with the Gr unit conventions).
  292.   BGI's Init- and CloseGraphProc have a higher quality than Gr's ones, so
  293.   that - without any code modifications - the graphics is now initialized
  294.   by a BGI call rather than a VGA BIOS call, and you can use your BGI
  295.   element.
  296.  
  297. Pointer Services Documentation
  298.  
  299. User00    ExtSave         MetaGraph - Recording [external]    MetaGr
  300.  
  301.   This routine is used for recording graphics parameters for the metafile
  302.   conception. It must be called within assembler routines and has got a
  303.   very special calling scheme.
  304.   This routine is described in detail in the MetaGraph documentation.
  305.  
  306. User01    LineProc        Exported Line Drawing Routine        MetaGr, BGI
  307.  
  308.   This routine is used for drawing a line. It is used by MyFonts for
  309.   drawing scalable fonts.
  310.   The BGI unit provides such a line routines. We recommend the use of the
  311.   MetaGraph unit.
  312.  
  313. User02    ClipNotifyProc    Clipping Notification            BGI
  314.  
  315.   This routine is used for informing other modules, that the clipping
  316.   rectangle or the drawing origin has changed, and for changing the
  317.   clipping mode of such modules.
  318.   ClipNotifyProc has got one parameter. Use the following gcnXXXX constants
  319.   for that.
  320.  
  321.   Commands
  322.     gcnUpdAll      Adapts the module's clipping to the new parameters.
  323.     gcnUpdOrigin  Adapts the module's clipping to the new drawing origin.
  324.  
  325.   Changing the Clipping Mode
  326.     gcnStopUpd      Stops the automatical adaption.
  327.     gcnContUpd      Continues the automatical adaption.
  328.     gcnHaltUpd      Halts the automatical adaption.
  329.     gcnStartUpd      Begins the automatical adaption.
  330.     gcnUpdOnReq      Sets a special mode, in which the commands directly
  331.           adapt the module's clipping.
  332.  
  333.   The BGI unit uses the clipping notification, so that it doesn't need to
  334.   adapt Graph's clipping mechanism to the parameters at every graphical
  335.   operation, which takes too much time.
  336.  
  337.   ClipNotifyProc is called by the routines SetDrawOrigin, SetDrawOriginP,
  338.   SetClipRect, and SetClipRectR.
  339.  
  340. User03    InitGraphProc    Initialize Graphics by GrMode        BGI, Gr
  341.  
  342.   This routine is used for graphics initialization, after the Gr mode has
  343.   been set. It returns true if it was successful.
  344.  
  345. User04    CloseGraphProc    De-initialize Graphics            BGI, Gr
  346.  
  347.   This routine is used to de-initialize graphics mode and to return to
  348.   text mode.
  349.  
  350. User05    ActivePageProc    Set active page by ActivePage        BGI
  351.  
  352.   This routine is used to set the active screen page of another module to
  353.   the value of the ActivePage variable.
  354.  
  355. User06  ChParamsProc    Change Graphics Parameters        MetaGr, BGI
  356.  
  357.   This routine is used to change graphics parameters module-independently.
  358.   The first parameter specifies the parameter and the actionto be performed,
  359.   and the second one specifies a buffer. The function returns the buffer size
  360.   required.
  361.  
  362.   Value        Parameter/Action                Type
  363.   ------------    ----------------------------------------------    ----
  364.   gcpColor    Current color                    Word
  365.   gcpLineStyle    Current line style (dependent from module)    ???
  366.   gcpSolidThLn  Sets a solid line of a certain thickness    Word
  367.  
  368.   gcpGetSize    Determines the buffer size.
  369.   gcpGetParams  Puts the parameter in the buffer.
  370.   gcpSetParams    Reads the parameter from the buffer.
  371.  
  372. User07    GrNotifyProc    Graphics Notification Chain        --
  373.  
  374.   This routine is an instance of the notification chain conception.
  375.   Do read the following section.
  376.  
  377.  
  378. N o t i f i c a t i o n   C h a i n   C o n c e p t i o n
  379.  
  380.  
  381. The notification chain conception is used for notify modules of graphic
  382. actions.
  383.  
  384. A notification chain is a chain of notification functions of type
  385. TNotifyProc. You will implement such a function if a module has to react
  386. to a certain notice. With Gr.InstallNotifyProc, you can install a function
  387. to a chain; with Gr.UninstallProc, you can remove it from the chain. The
  388. function is inserted into the chain according to its quality.
  389.  
  390. The default behaviour of a notification function is provided by
  391. Gr.DefaultNotify. A notification function must handle the notices it needs
  392. to and then call DefaultNotify. Following are the parameters.
  393.  
  394. Notice        The notice specified in the function call.
  395. Info        Additional information specified in the funtion call.
  396. ThisProc    The notification function.
  397. NextProc    A global variable of TNotifyProc type, which belongs to
  398.         the notification function.
  399. Quality        The quality of the notification function.
  400.  
  401.  
  402. D e t a i l s
  403.  
  404.  
  405. 1  Difference between BytesPerLine and RealBytesPerLine
  406.  
  407.    Certain programs allocate VGA rest memory and draw any graphics into
  408.    that screen buffer. Therefore, they change the ActiveSeg and BytesPerLine
  409.    variables. So, graphical routines will use BytesPerLine and not
  410.    RealBytesPerLine.
  411.    A mouse cursor may not be drawn into that buffer but still appear on
  412.    the real screen. A mouse driver will use RealBytesPerLine and not
  413.    BytesPerLine.
  414.  
  415. 2  Exotic graphics modes
  416.  
  417.    If your graphics adapter supports some exotic graphic modes that are not
  418.    provided by SetGrMode, you can set the Gr parameters manually.
  419.    NOTE: The maximal supported graphics memory is 256 KB.
  420.  
  421. 3. If your adaptor card supports the grSvgaStd mode (800 x 600 x 16) and
  422.    you wish to initialize graphics by an InitGraphProc call, use a unit
  423.    like the following:
  424.  
  425.      unit MySvga;
  426.  
  427.      interface
  428.      implementation
  429.  
  430.      uses Gr;
  431.  
  432.      const
  433.        qInitSvgaGraph = 20;        { <-- quality, more than 10 }
  434.  
  435.      procedure InitSvgaGraph; far;
  436.      begin
  437.        If GrMode = grSvgaStd
  438.      then SetBiosMode($52)        { <-- BIOS mode number }
  439.      else InitBiosGraph
  440.      end;
  441.  
  442.      begin
  443.        if qInitSvgaGraph > qInitGraphProc then Begin
  444.      qInitGraphProc := qInitSvgaGraph;
  445.       InitGraphProc :=  InitSvgaGraph
  446.        End
  447.      end.
  448.  
  449.