home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / VDH / VDHMAIN.C < prev    next >
C/C++ Source or Header  |  1995-04-14  |  62KB  |  1,785 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT (C) Microsoft Corporation, 1989                                 */
  4. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  5. /*                                                                           */
  6. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  7. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  8. /*    drivers. You may use this code in accordance with the IBM License      */
  9. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  10. /*    Copyright statement may not be removed.                                */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13. /*****************************************************************************
  14.  *
  15.  * SOURCE FILE NAME = VDHMAIN.c
  16.  *
  17.  * DESCRIPTIVE NAME = Base video device handlers - Initialization,
  18.  *                                                 Save/Restore &
  19.  *                                                 Get/FreePhysBuf
  20.  *
  21.  *
  22.  * VERSION      V2.0
  23.  *
  24.  * DATE
  25.  *
  26.  * DESCRIPTION  This source is compiled conditionally to produce 5
  27.  *              distinct video device handlers ( dynalink libraries )
  28.  *              for support of either MPA, CGA, EGA, VGA/PS2 adapter, or
  29.  *              8514/A display adapters.  The video device handlers
  30.  *              each consist of hardware dependent functions, which are
  31.  *              invoked directly by the OS/2 base video subsystem.
  32.  *
  33.  *              To direct the compiler to build each video device handler,
  34.  *              a unique symbol must be defined via the '-D' compile
  35.  *              switch for each one.  These symbols are:
  36.  *              -DVDHMPA for the MPA video device handler (VDHMPA.DLL)
  37.  *              -DVDHCGA for the CGA video device handler (VDHCGA.DLL)
  38.  *              -DVDHEGA for the EGA video device handler (VDHEGA.DLL)
  39.  *              -DVDHVGA for the VGA and PS/2 adapter VDH (VDHVGA.DLL)
  40.  *              -DVDH8514A for the BGA video device handler (VDH8514A.DLL)
  41.  *
  42.  * FUNCTIONS    DevEnable
  43.  *              InitEnv, SaveEnv, RestoreEnv
  44.  *              RetConfigInfo
  45.  *              GetPhysBuf, FreePhysBuf
  46.  *
  47.  * NOTES        NONE
  48.  *
  49.  * STRUCTURES   NONE
  50.  *
  51.  * EXTERNAL REFERENCES
  52.  *              DosOpen,  DosGetHugeShift
  53.  *              DosAllocSeg, DosFreeSeg
  54.  *              SaveRegs, RestoreRegs
  55.  *              ExamineConfig, SetHWMode
  56.  *              SaveRestorePVB, SaveRestoreHW
  57.  *              PhysToUVirt, FreePhysToUVirt
  58.  *
  59.  * EXTERNAL FUNCTIONS
  60.  *
  61.  *              NONE
  62.  *
  63. */
  64.  
  65. /*
  66. **  Include files
  67. */
  68.  
  69. #define INCL_BASE               /* ALL of OS/2 Base                */
  70. #define INCL_DOSDEVICES         /* Device specific, ring 2 support */
  71. #define INCL_OS2STD             /* Needed for NULL definition in OS2STD.H */
  72. #include <os2.h>
  73.  
  74. #if DEBUG
  75. #define DEBUG_DATA              /* Put debug data in this module   */
  76. #endif  /* DEBUG */
  77.  
  78. #include "vdhctl.h"             /* Conditional compilation control */
  79. #include "vdh.h"                /* Type definitions                */
  80. #include "vdhdata.h"            /* Global data                     */
  81.  
  82. #if VDHVGA                                                         /*@MS00 */
  83.  
  84. /*
  85. **  Externally defined global variables
  86. */
  87.  
  88. extern CLUTDATA far ColorCLUT;
  89. extern CLUTDATA far MonoCLUT;
  90.  
  91. extern USHORT SVGAPresent;                                           /*@drw */
  92. extern USHORT PASCAL NEAR GetSVGAConfig(VOID);                       /*@drw */
  93.  
  94. #endif  /* VDHVGA                                                     @MS00 */
  95.  
  96. extern USHORT OEMFlags;         /* OEM specific features              @MS27 */
  97.  
  98. /*****************************************************************************
  99.  *
  100.  *  SUBROUTINE NAME: DevEnable
  101.  *
  102.  *  DESCRIPTIVE NAME: Initialize call vector table
  103.  *
  104.  *  FUNCTION: DevEnable is called via the Presentation Manager DDI
  105.  *            interface.  The entry points of all VDH routines are
  106.  *            appropriately entered into the call vector table.
  107.  *            In addition, display adapter configuration is verified.
  108.  *
  109.  *  ENTRY POINT: DevEnable
  110.  *    LINKAGE:   CALL FAR
  111.  *
  112.  *  INPUT: (Passed on stack)
  113.  *             FAR * Parameter2  ( far pointer to parameter 2 packet )
  114.  *                      FAR *Flags
  115.  *                      FAR *CallVectorTable
  116.  *             FAR * Parameter1  ( far pointer to parameter 1 packet )
  117.  *                      ULONG EngineVersion ( Graphics engine ver. )
  118.  *                      ULONG TableSize ( Length of call table )
  119.  *             ULONG Subfunction ( Enable subfunction )
  120.  *             FAR *CallVectorTable[] ( BVS's table of entry points )
  121.  *         (Referenced)
  122.  *             VDHEntryPoint[] (global data - table of entry points )
  123.  *             HugeShift (global data - huge shift value)
  124.  *             hScreenDD (global data - screen device driver handle)
  125.  *
  126.  *  EXIT-NORMAL: AX = 0
  127.  *               Entries in VDHEntryPoint table are copied to
  128.  *                  CallVectorTable
  129.  *
  130.  *  EXIT-ERROR: AX = ERROR_VIO_BAD_ADAPTER or
  131.  *                   DosGetHugeShift error or
  132.  *                   DosOpen error or
  133.  *                   PMERR_DEV_FUNC_NOT_INSTALLED
  134.  *
  135.  *  EFFECTS: Huge shift value is saved in HugeShift
  136.  *           Screen device driver handle is saved in hScreenDD
  137.  *
  138.  *  INTERNAL REFERENCES:
  139.  *    ROUTINES: NONE
  140.  *
  141.  *  EXTERNAL REFERENCES:
  142.  *    ROUTINES: DosGetHugeShift, DosOpen, ExamineConfig
  143.  *              SaveRegs, RestoreRegs
  144.  *    DATA:     hScreenDD       (Global nonshared): handle to SCREEN$
  145.  *              HugeShift       (Global shared): from DosGetHugeShift
  146.  *              VDHEntryPoint[] (Global shared): table of entry points
  147.  *
  148.  ****************************************************************************/
  149.  
  150. USHORT EXPENTRY DevEnable( Parm2, Parm1, Subfunction )
  151.  
  152. DEV_PARM2 far *Parm2;
  153. DEV_PARM1 far *Parm1;
  154. ULONG Subfunction;
  155.  
  156. {
  157. USHORT rc,
  158.        j,
  159.        One = 1,
  160.        ActionTaken;
  161. ULONG i;
  162.  
  163. #if DEBUG                                                          /* @MS07 */
  164.          DEBUG_OUT = 1;                                            /* @MS07 */
  165.         _DPRINTF((char far *)DEBUG_BVH_VERSION);                   /* @MS07 */
  166.         _DPRINTF((char far *)"DEVENABLE\x0A\x0D");                 /* @MS07 */
  167. #endif  /* DEBUG                                                      @MS07 */
  168.  
  169. rc = NO_ERROR;                          /* Initialize to successful */
  170.  
  171. if ((Subfunction != FnFillInitDevBlock) &&     /* @T15 */
  172.     (Subfunction != FnFillLogicalDevBlock) )
  173. {
  174.  
  175.       rc = PMERR_DEV_FUNC_NOT_INSTALLED;
  176.  
  177. }
  178.  
  179. else
  180. {
  181.  
  182. /*
  183. **  Get handle to SCREEN$ for later use of IOCtls cat 3, funcs 70 & 71
  184. */
  185.  
  186. #if !(VDH8514A)                         /*@S15,@MS00*/
  187.  
  188.         if (!(*hScreenDD))
  189.         {            /* SCREEN$ not yet open, @S15*/ /*@T52*/
  190.  
  191.             rc = DosOpen( SCREENDD_NAME, (PHFILE)hScreenDD,             /*@T52*/
  192.                 (PUSHORT)&ActionTaken, NO_SIZE, NO_ATTRIBUTES, OPEN_IF_EXISTS,
  193.                 NO_INHERIT+DENY_NONE+READ_WRITE, RESERVED_LONG ); /*@T5,@T15,@S15*/
  194.  
  195.         }                               /*@S15*/
  196. #endif  /* ! VDH8514A                   @S15,@MS00 */
  197.  
  198.     if (!rc && FIRST_INIT)
  199.     {            /*@T21,@S15*/
  200.  
  201.         FIRST_INIT = FALSE;             /*@T15*/
  202.  
  203. /*
  204. **  Get huge shift value for later use during save/rest of display buffer
  205. */
  206.  
  207.         if ( !(rc = DosGetHugeShift( (PUSHORT)&HugeShift )) )
  208.         {
  209.  
  210.             HugeShift = One << HugeShift;
  211.  
  212. /*
  213. **  Verify presence of adapter and record adapter configuration for
  214. **  later use by RetConfigInfo and RetROMFontInfo
  215. */
  216.  
  217. #if VDH8514A                                                     /*@MS00 */
  218.  
  219. /*
  220. **  We need the call vector to RetConfigInfo in the VGA VDH (if it's there)
  221. **  ( This vector must be accessible prior to the call to ExamineConfig() )
  222. */
  223.  
  224.                 (USHORT far *)ChainedCallVectorTable[FnChainedRetConfigInfo] =
  225.                                  Parm2->CallVectorTable[FnReturnConfigInfo];
  226.  
  227. #endif  /* VDH8514A                                               @MS00 */
  228.  
  229. #if VDHVGA
  230.  
  231.             SVGAPresent = GetSVGAConfig();
  232.  
  233. #endif
  234.  
  235.             if ( !( rc = ExamineConfig() ) )
  236.             {
  237.  
  238. /*
  239. **  Copy all VDH entry points that are supported for this adapter
  240. **  to BVS's call table for this adapter
  241. */
  242.  
  243.                 for ( i = FnTextBufferUpdate, j = FnChainedBufUpdate;
  244.                     (i <= LASTFUNCTION) && (i < Parm1->TableSize); i++, j++ )
  245.                     { /* @D811 */
  246.  
  247.                     if ( VDHEntryPoint[j] != UNSUPPORTED_FUNCTION )
  248.                     {
  249.  
  250. #if VDH8514A                                                  /*@MS00 */
  251.  
  252. /*
  253. **  Save a copy of the call vector table for chaining
  254. */
  255.  
  256.                             (USHORT far *)ChainedCallVectorTable[j] =
  257.                                 Parm2->CallVectorTable[i];
  258.  
  259. #endif  /* VDH8514A                                                 @MS00 */
  260.  
  261. /*
  262. **  Change the current entry in the call vector table
  263. */
  264.  
  265. #if DEBUG                                                           /*@MS07 */
  266.                         Parm2->CallVectorTable[i] = (USHORT far *)DebugTrace;
  267.  
  268. #else                                                               /*@MS07 */
  269.                         Parm2->CallVectorTable[i] = VDHEntryPoint[j];
  270.  
  271. #endif  /* DEBUG                                                    /*@MS07 */ */
  272.                     }
  273.                 }
  274.  
  275. #if FONT_SUPPORT                                                    /*@MS00 */
  276.  
  277.                     GetCodePage();      /*@C10*/
  278.  
  279. #endif  /* FONT_SUPPORT                                              @MS00 */
  280.  
  281.             }
  282.         }
  283.     }
  284.  
  285. #if FONT_SUPPORT                        /* @C10,@MS00 */
  286.  
  287.  
  288.         else                       /* get access to CodePage segments @C10 */
  289.         {                          /* @C10 */
  290.  
  291.             if ( CodePage_Support )     /* @C10 */
  292.  
  293.                 if ( !( rc = DosGetSeg ( (SEL) CodePage.p.Selector ) ) ) /* @C10 */
  294.                     rc = DosGetSeg ( (SEL) RomCP_tbl.p.Selector ); /* @C10 */
  295.         }                               /* @C10 */
  296.  
  297. #endif  /* FONT_SUPPORT                  @C10,@MS00  */
  298.  
  299. #if !(VDH8514A)                         /*@S15,@MS00*/
  300.  
  301.         if ( rc )
  302.         {
  303.             DosClose(*hScreenDD);       /* @T5 */ /*@T52*/
  304.             *hScreenDD = 0;             /*@T55*/
  305.         }
  306.  
  307. #endif  /* ! VDH8514A                   @S15,@MS00 */
  308.  
  309. }
  310.  
  311. return( rc );
  312. }
  313.  
  314. /*****************************************************************************
  315.  *
  316.  *  SUBROUTINE NAME: InitEnv
  317.  *
  318.  *  DESCRIPTIVE NAME: Initialize environment
  319.  *
  320.  *  FUNCTION: InitEnv is called by BVS to initialize the video
  321.  *            environment during the creation of a new session.  This
  322.  *            includes initializing the adapter hardware and/or the
  323.  *            environment buffer.
  324.  *
  325.  *  ENTRY POINT: InitEnv
  326.  *    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 257 )
  327.  *
  328.  *  INPUT: (Passed on stack)
  329.  *             FAR *Environment ( Environment buffer for the session )
  330.  *             FAR *ParmBlock
  331.  *                     USHORT Length = length of this packet
  332.  *                     USHORT Flags  = 0 - Environment buffer only
  333.  *                                     1 - Hardware also
  334.  *             ULONG Function ( Call vector table entry = 257 )
  335.  *         (Referenced)
  336.  *             Modes[] (global data - table of supported video modes )
  337.  *
  338.  *  EXIT-NORMAL: AX = 0
  339.  *               Environment buffer is initialized
  340.  *
  341.  *  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  342.  *
  343.  *  EFFECTS: If requested, display adapter hardware is initialized to
  344.  *           highest resolution mode supported.
  345.  *
  346.  *  INTERNAL REFERENCES:
  347.  *    ROUTINES: NONE
  348.  *
  349.  *  EXTERNAL REFERENCES:
  350.  *    ROUTINES: SetHWMode, SetEnvMode
  351.  *
  352.  ****************************************************************************/
  353.  
  354. USHORT EXPENTRY InitEnv( Environment, ParmBlock, Function )
  355.  
  356. ENVIRONMENT far *Environment;
  357. VDH_INITENV far *ParmBlock;
  358. ULONG Function;
  359.  
  360. {
  361.  
  362. USHORT rc, i, j;
  363.  
  364. #if VDHVGA                       /*@D1452*/
  365.  
  366. HFILE dev_handle;                /*@D1452*/
  367. SHORT ActionTaken;               /*@D1452*/
  368. SHORT XGA_RC;                    /*@D1452*/
  369.  
  370. #endif                           /*@D1452*/
  371.  
  372. #if FONT_SUPPORT                                                 /* @C10,@MS00 */
  373.  
  374.   ROMCP_TABLE *rcp_tbl_ptr;                                           /* @C10 */
  375.  
  376. #endif  /* FONT_SUPPORT                                           @C10,@MS00 */
  377.  
  378. rc = ERROR_VIO_INVALID_PARMS;                          /* Initialize to error */
  379.  
  380. if ( ( Function == FnInitializeEnvironment )        && /* Valid function request */
  381.      ( ParmBlock->Length >= sizeof( VDH_INITENV ) ) && /* Valid packet length */
  382.      ( ParmBlock->Flags  <= VALID_INITENV_FLAG )    && /* Valid flags         */
  383.      SEG( Environment ) )
  384.  
  385. {                            /* Environment passed  */
  386.  
  387.   rc = NO_ERROR;                                /* Initialize no error */
  388.  
  389.   Environment->EnvFlags = DEFAULT_ENVFLAGS;     /*@D198*/
  390.  
  391.   /*  ** Removing the DosError calls. If an application is registering
  392.   ** their own handler, we would have enabled the exception handling on the
  393.   ** first pop-up in that session, which is forcing the default action. We would
  394.   ** need to query the state of DosError enable/disable in order to restore it.
  395.   ** Until such an API becomes available, keep the state in tact. Nobody on
  396.   ** the team can remember what was the reason for putting the DosError in.
  397.   ** According to Dave Medina, while an exception for one process is being handled,
  398.   ** all other exceptions are delayed.
  399.   */
  400.  
  401. #if VDH8514A                                                            /*@MS00 */
  402.  
  403. /*
  404. **  If VDHVGA.DLL has been successfully installed, call InitEnv in VDHVGA.DLL
  405. **  Otherwise, initialize to an 8514/A graphics mode and hope for the best
  406. */
  407.  
  408.   Environment->NATIVE_MODE = TRUE;
  409.  
  410.   if ( VGA_PRESENT )
  411.   {
  412.  
  413.     Environment->NATIVE_MODE = FALSE;
  414.     if ( ParmBlock->Flags & UPDATE_HARDWARE )
  415.        LeaveNativeMode();
  416.  
  417.     rc = ChainedVDHInitEnv( (ENVIRONMENT far *)&Environment->VGAEnvironment,
  418.                              ParmBlock, Function );
  419.  
  420.   }
  421.  
  422.   else
  423.   {                              /*@S10*/
  424.  
  425. #endif  /* VDH8514A                     @S10,@MS00*/
  426.  
  427. /*
  428. **  Initialize 1st word in environment buf to point to VioSetMode structure
  429. **  ( This offset is relative to the begining of the environment buffer )
  430. */
  431.  
  432.   Environment->ModeDataOFF = OFFSET( Environment->ModeData ) -
  433.                              OFFSET( Environment->ModeDataOFF );
  434.  
  435. #if FONT_SUPPORT                                                    /*@MS00 */
  436.  
  437. /*
  438. **  Initialize active fonts to ROM fonts only
  439. */
  440.  
  441.   Environment->ActiveFontPTR = (UCHAR far *)ROM_FONT;
  442.  
  443. /*
  444. **  Initialize active code page to system first prepared
  445. **  if the codepage is in our table
  446. */
  447.  
  448.  
  449.   Environment->CodePageID = ROM_FONT;                                 /* @C10 */
  450.  
  451.   if (CodePage_Support)                                               /* @C10 */
  452.   {                                                                   /* @C10 */
  453.     DosGetCp( 0x2, (PUSHORT)&j, (PUSHORT)&i );                        /* @C10 */
  454.     rcp_tbl_ptr = RomCP_tbl.ptr;                                      /* @C10 */
  455.  
  456.     for ( i=0; i<ROMCP_NUM; i++ )                                     /* @C10 */
  457.  
  458.        if ( j == rcp_tbl_ptr->CodePageID )
  459.        {                          /* @C10 */
  460.           Environment->CodePageID = j;                                /* @C10 */
  461.           i = ROMCP_NUM;                                              /* @C10 */
  462.        }                                                              /* @C10 */
  463.  
  464.        else                                                           /* @C10 */
  465.           rcp_tbl_ptr++;                                              /* @C10 */
  466.   }                                                                   /* @C10 */
  467.  
  468. /*
  469. **  Initialize the USER font to NOT SELECTABLE ( Code page or ROM font only )
  470. */
  471.  
  472.   Environment->UserFont     = USER_FONT_NOT_SELECTABLE;
  473.   Environment->NumUSERFonts = 0;           /* Number of USER fonts in storage */
  474.  
  475. #endif         /* FONT_SUPPORT                                          @MS00 */
  476.  
  477.  
  478. /*
  479. **  Initialize video mode to highest resolution 80x25 color text supported
  480. */
  481.  
  482.   SetEnvMode( VideoHardware.popupMode, /* Initialize mode data structure  @T39*/
  483.               Environment, (ENVIRONMENT far *)NULL, 1 );                /*@T70*/
  484.  
  485. /*
  486. **  Shadow cursor attribute outside of register shadow - register contains
  487. **  one bit indicating hidden or visible.  Use this to retrieve exact non -1
  488. **  cursor attribute ( cursor attribute: -1 = hidden, other = non-hidden )
  489. */
  490.  
  491. #if !(VDH8514A)                         /*@S10,@MS00*/
  492.  
  493.   Environment->CursorAttribute = 0;                             /* Not hidden */
  494.  
  495. /*
  496. **  For VGA, the Screen Off bit (b5) of the Miscellaneous Output Register
  497. **  is used to enable/disable the video signal.  For all other adapters, the
  498. **  Attribute registers are used and a query references this shadow
  499. */
  500.  
  501. /*
  502. **   @C21  Use Attribute regs for all including VGA
  503. */
  504.   Environment->VideoEnable = 0;         /* Disabled, @S43*/
  505.  
  506. #endif  /* ! VDH8514A                   @S10,@MS00 */
  507.  
  508. #if VDHVGA
  509.   /*
  510.   **            Initialize SVDH related fields.
  511.   */
  512.   Environment->SVGAMode = 0;
  513.   Environment->PelRows = 0;
  514.   Environment->PelColumns = 0;
  515. #endif
  516. #if FONT_SUPPORT                                                  /*@C15,@MS00*/
  517.  
  518.   /*
  519.   ** call FindFont to setup Env for the appropriate font
  520.   */
  521.   FindFont ( Environment->ModeIndex, Environment->ModeData.row,        /*@C15*/
  522.              Environment );                                            /*@C15*/
  523.  
  524. #endif  /* FONT_SUPPORT */
  525.  
  526. /*
  527. **  Initialize mode to highest resolution 80x25 color text
  528. **  ( This includes the setting of the appropriate ROM font )
  529. **  If foreground, SetHWMode will set the hardware. By passing the
  530. **  environment, SetHWMode will shadow also shadow the registers.
  531. */
  532.  
  533.   if ( !(rc = SetHWMode( VideoHardware.popupMode,
  534.          ParmBlock->Flags, Environment ) ) )
  535.   {    /*@T39,@T53*/
  536.  
  537. /*
  538. **  Initialize the scrollable text region of the screen.                @P1
  539. **  Note that in all cases the entire screen is the scrollable region.  @P1
  540. */
  541.  
  542.      Environment->ScrollRect.Left = 0;                               /* @P1 */
  543.      Environment->ScrollRect.Top = 0;                                /* @P1 */
  544.      Environment->ScrollRect.Right = Environment->ModeData.col - 1;  /* @P1 */
  545.      Environment->ScrollRect.Bottom = Environment->ModeData.row - 1; /* @P1 */
  546.      Environment->AttrBufSize = 1;                                   /* @P1 */
  547.      Environment->AttrBuf[0] = DefaultAttribute[0];                  /* @P1 */
  548.      Environment->AttrBuf[1] = DefaultAttribute[1];                  /* @P1 */
  549.      Environment->AttrBuf[2] = DefaultAttribute[2];                  /* @P1 */
  550.  
  551.   }                                                                 /* @T53 */
  552.  
  553. #if VDH8514A                            /*@S10,@MS00*/
  554.  
  555.   } /* VGA not present */               /*@S10*/
  556.  
  557. #endif
  558.  
  559. #if VDHVGA                                                            /*@D1085*/
  560.                                                                       /*@D1085*/
  561.   Environment->Comp_Reg = 0;                                          /*@D1085*/
  562.                                                                       /*@D1085*/
  563. #endif                                                                /*@D1085*/
  564.  
  565.   }
  566.  
  567. #if VDHVGA                                                          /*@D1452*/
  568.                                                                     /*@D1452*/
  569. /*
  570. ** Device driver detection: if DosOpen fails, it's not there
  571. ** and we need to wait until later
  572. */
  573.  
  574.  
  575.    Environment->XGA_PRESENT = FALSE;                              /*@B720995*/
  576.  
  577.    if (!(DosOpen( "\\DEV\\$$AFVIO0",                                /*@D1452*/
  578.          (PHFILE)&dev_handle,                                       /*@D1452*/
  579.          (PUSHORT)&ActionTaken,                                     /*@D1452*/
  580.          NO_SIZE,                                                   /*@D1452*/
  581.          FILE_SYSTEM,                                               /*@D1452*/
  582.          OPEN_ACTION_OPEN_IF_EXISTS,                                /*@D1452*/
  583.               NO_INHERIT+                                          /*@D1452f*/
  584.               OPEN_SHARE_DENYNONE+                                  /*@D1452*/
  585.               OPEN_ACCESS_READWRITE,                                /*@D1452*/
  586.          RESERVED_LONG )) )                                         /*@D1452*/
  587.  
  588.    {                                                                /*@D1452*/
  589.       Environment->XGA_PRESENT = TRUE;                              /*@D1452*/
  590.       VideoHardware.Reg_132 = TRUE;          /*@B729652 */
  591.       DosClose(dev_handle);                                        /*@D1452f*/
  592.    }                                                                /*@D1452*/
  593.                                                                     /*@D1452*/
  594. #endif                                                              /*@D1452*/
  595.  
  596.   /*  ** Removing the DosError calls. See comments above.                        
  597.   */
  598.  
  599. return( rc );
  600.  
  601. }
  602.  
  603. /*****************************************************************************
  604.  *
  605.  *  SUBROUTINE NAME: SaveEnv
  606.  *
  607.  *  DESCRIPTIVE NAME: Save environment
  608.  *
  609.  *  FUNCTION: SaveEnv is called by BVS prior to a screen switch
  610.  *            in order to preserve the display adapter hardware state
  611.  *            and/or the full or partial display buffer.
  612.  *
  613.  *  ENTRY POINT: SaveEnv
  614.  *    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 258 )
  615.  *
  616.  *  INPUT: (Passed on stack)
  617.  *             FAR *Environment ( Environment buffer for the session )
  618.  *             FAR *ParmBlock
  619.  *                     USHORT Length = length of this packet
  620.  *                     USHORT Flags  = 2 - Hardware state
  621.  *                                     4 - Full display buffer
  622.  *                                     8 - Partial display buffer
  623.  *                     USHORT PVBHugeSEL = 1st huge selector for PVB
  624.  *             ULONG Function ( Call vector table entry = 258 )
  625.  *
  626.  *  EXIT-NORMAL: AX = 0
  627.  *               Hardware state and/or display buffer is saved in
  628.  *                 environment buffer
  629.  *
  630.  *  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  631.  *
  632.  *  EFFECTS: None                                               @T51
  633.  *                                                              @T51
  634.  *
  635.  *  INTERNAL REFERENCES:
  636.  *    ROUTINES: NONE
  637.  *
  638.  *  EXTERNAL REFERENCES:
  639.  *    ROUTINES: SaveRestorePVB, SaveRestoreHW                   @T51
  640.  *
  641.  ****************************************************************************/
  642.  
  643. USHORT EXPENTRY SaveEnv( Environment, ParmBlock, Function )
  644.  
  645. ENVIRONMENT far *Environment;
  646. VDH_SAVEREST far *ParmBlock;
  647. ULONG Function;
  648.  
  649. {
  650.  
  651. USHORT rc, EnvBufferPassed;
  652. REGDATA RegData;
  653. REGADDRESS RegAddress;
  654. ULONG BufSize;
  655.  
  656. UCHAR TempAddrRegs[6];                                                  /*@C39*/
  657. USHORT ColorMode;                                                       /*@C39*/
  658.  
  659. rc = ERROR_VIO_INVALID_PARMS;                            /*Initialize to error*/
  660. EnvBufferPassed = SEG( Environment );                    /*Non-zero = TRUE    */
  661.  
  662. if ( ( Function == FnSaveEnvironment )                && /*Valid funct request*/
  663.      ( ParmBlock->Length >= MinSLen_SaveRestoreEnv )  && /*Valid packet length*/
  664.        ParmBlock->Flags                               && /*An option specified*/
  665.     !( ParmBlock->Flags & ~VALID_SAVEREST_FLAG )      && /*No illegal options */
  666.     !( ( ParmBlock->Flags & SAVEREST_FULLPVB )        &&
  667.        ( ParmBlock->Flags & SAVEREST_PARTPVB ) )      && /*Not part and full  */
  668.     !( ( ParmBlock->Length < sizeof( VDH_SAVEREST ) ) && /*PVB and no selector*/
  669.        ( ParmBlock->Flags & (SAVEREST_FULLPVB+SAVEREST_PARTPVB) ) ) &&
  670.      EnvBufferPassed )
  671.  
  672. {
  673.  
  674.   rc = NO_ERROR;                                       /* Initialize no error */
  675.  
  676. #if VDH8514A                                                     /*@MS00 */
  677.  
  678. /*
  679. **  If the current mode is not an 8514/A native mode, call SaveEnv in
  680. **  VDHVGA.DLL.  Otherwise, do nothing.
  681. */
  682.  
  683.   if ( VGA_PRESENT && !Environment->NATIVE_MODE )
  684.     rc = ChainedVDHSaveEnv( (ENVIRONMENT far *)&Environment->VGAEnvironment,
  685.                             ParmBlock, Function              );
  686.  
  687. #else
  688.  
  689.   if ( ParmBlock->Flags & SAVEREST_HARDWARE )
  690.   {
  691.  
  692. /*
  693. **  If hardware is not write-only, read it and copy to the env buffer
  694. */
  695.  
  696. #if VDHVGA    /* Read/write hardware */                               /*@MS00 */
  697.  
  698.     if ( ParmBlock->Flags & SAVEREST_VDM )
  699.     {                            /*@C39*/
  700.        Environment->EnvFlags |= SAVEREST_VDM;    /*              VDM  Popup   */
  701.        ColorMode = HardwareColor();                                     /*@C39*/
  702.  
  703.        if ( ColorMode )                                                 /*@C39*/
  704.          RegAddress.DataPort    = CRTColorAddrPort;                     /*@C39*/
  705.  
  706.        else                                                             /*@C39*/
  707.          RegAddress.DataPort    = CRTAddressPort;                       /*@C39*/
  708.  
  709.        AccessRegister( &RegAddress, GET, &TempAddrRegs[0] );            /*@C39*/
  710.        RegAddress.DataPort    = AttAddressPort;                         /*@C39*/
  711.        AccessRegister( &RegAddress, GET, &TempAddrRegs[1] );            /*@C39*/
  712.        RegAddress.DataPort    = SeqAddressPort;                         /*@C39*/
  713.        AccessRegister( &RegAddress, GET, &TempAddrRegs[2] );            /*@C39*/
  714.        RegAddress.DataPort    = GraphAddressPort;                       /*@C39*/
  715.        AccessRegister( &RegAddress, GET, &TempAddrRegs[3] );            /*@C39*/
  716.        RegAddress.DataPort    = DACAddrPortWrite;                       /*@C39*/
  717.        AccessRegister( &RegAddress, GET, &TempAddrRegs[4] );            /*@C39*/
  718.        RegAddress.DataPort    = DACAddrPortRead;                        /*@C39*/
  719.        AccessRegister( &RegAddress, GET, &TempAddrRegs[5] );            /*@C39*/
  720.  
  721.     }                                                                   /*@C39*/
  722.  
  723. /*
  724. **  Read registers into environment buffer
  725. */
  726.  
  727.     SaveRestoreHW( Environment, GET );
  728.  
  729. #else
  730.  
  731. /*
  732. **  Cursor position is always readable
  733. */
  734.  
  735.    if ( !( ParmBlock->Flags & SAVEREST_VDM ) )
  736.    {                        /*@C39*/
  737.  
  738.      RegAddress.AddressPort = CRTAddressPort;
  739.      RegAddress.DataPort    = CRTDataPort;
  740.      RegAddress.ColorAdjust = ColorAdjustment;
  741.      RegAddress.Flags       = NONE;
  742.  
  743.      RegData.DataArea =
  744.              &Environment->Hardware.CRTCtlRegs.All[ RegData.FirstEntry = 0x0E ];
  745.  
  746.      RegData.NumEntries = 2;                         /* Just cursor position */
  747.  
  748.      AccessHardware( &RegAddress, BYTES,
  749.                      (USHORT)(Environment->ModeData.fbType & NOT_MONO),
  750.                      GET, &RegData );
  751.    }                                                                    /*@C39*/
  752.  
  753. #endif
  754.  
  755.   }
  756.  
  757. /*
  758. **  Save partial or full display buffer
  759. */
  760.  
  761.   if ( ParmBlock->Flags & (SAVEREST_FULLPVB+SAVEREST_PARTPVB) )
  762.   {
  763.  
  764.      if (!rc || rc==ERROR_ACCESS_DENIED)
  765.      {      /*STJ*/
  766.         rc = SaveRestorePVB( ParmBlock, SAVE, (UCHAR far *)NULL, Environment );
  767.      }
  768.   }
  769.  
  770.   if ( ParmBlock->Flags & SAVEREST_VDM )
  771.   {                             /*@C39*/
  772.  
  773. #if VDHVGA    /* Read/write hardware */                           /*@C39,@MS00*/
  774.  
  775.      if ( ColorMode )                                                  /*@C39*/
  776.        RegAddress.DataPort    = CRTColorAddrPort;                      /*@C39*/
  777.  
  778.      else                                                              /*@C39*/
  779.        RegAddress.DataPort    = CRTAddressPort;                        /*@C39*/
  780.  
  781.      AccessRegister( &RegAddress, SET, &TempAddrRegs[0] );             /*@C39*/
  782.      RegAddress.DataPort    = AttAddressPort;                          /*@C39*/
  783.      AccessRegister( &RegAddress, SET, &TempAddrRegs[1] );             /*@C39*/
  784.      RegAddress.DataPort    = SeqAddressPort;                          /*@C39*/
  785.      AccessRegister( &RegAddress, SET, &TempAddrRegs[2] );             /*@C39*/
  786.      RegAddress.DataPort    = GraphAddressPort;                        /*@C39*/
  787.      AccessRegister( &RegAddress, SET, &TempAddrRegs[3] );             /*@C39*/
  788.      RegAddress.DataPort    = DACAddrPortWrite;                        /*@C39*/
  789.      AccessRegister( &RegAddress, SET, &TempAddrRegs[4] );             /*@C39*/
  790.      RegAddress.DataPort    = DACAddrPortRead;                         /*@C39*/
  791.      AccessRegister( &RegAddress, SET, &TempAddrRegs[5] );             /*@C39*/
  792.  
  793. #else                                                                  /*@C39*/
  794.  
  795.      if ( !rc )                                                        /*@C39*/
  796.         rc = NOT_READABLE_HARDWARE;                                    /*@C39*/
  797.  
  798. #endif
  799.  
  800.   }                                                                    /*@C39*/
  801.  
  802.  
  803. #endif
  804.  
  805.   }
  806. return( rc );
  807. }
  808.  
  809. /*****************************************************************************
  810.  *
  811.  *  SUBROUTINE NAME: RestoreEnv
  812.  *
  813.  *  DESCRIPTIVE NAME: Restore environment
  814.  *
  815.  *  FUNCTION: RestoreEnv is called by BVS following a screen switch
  816.  *            in order to restore the display adapter hardware state
  817.  *            and/or the full or partial display buffer.
  818.  *
  819.  *  ENTRY POINT: RestoreEnv
  820.  *    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 259 )
  821.  *
  822.  *  INPUT: (Passed on stack)
  823.  *             FAR *Environment ( Environment buffer for the session )
  824.  *             FAR *ParmBlock
  825.  *                     USHORT Length = length of this packet
  826.  *                     USHORT Flags  = 2 - Hardware state
  827.  *                                     4 - Full display buffer
  828.  *                                     8 - Partial display buffer
  829.  *                     USHORT PVBHugeSEL = 1st huge selector for PVB
  830.  *             ULONG Function ( Call vector table entry = 259 )
  831.  *
  832.  *  EXIT-NORMAL: AX = 0
  833.  *               Hardware state and/or display buffer is restored
  834.  *                 using info from environment buffer.
  835.  *
  836.  *  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  837.  *
  838.  *  EFFECTS: None                                               @T51
  839.  *                                                              @T51
  840.  *
  841.  *  INTERNAL REFERENCES:
  842.  *    ROUTINES: NONE
  843.  *
  844.  *  EXTERNAL REFERENCES:
  845.  *    ROUTINES: SaveRestorePVB, SaveRestoreHW
  846.  *
  847.  ****************************************************************************/
  848.  
  849. USHORT EXPENTRY RestoreEnv( Environment, ParmBlock, Function )
  850.  
  851. ENVIRONMENT far *Environment;
  852. VDH_SAVEREST far *ParmBlock;
  853. ULONG Function;
  854.  
  855. {
  856.  
  857. USHORT rc,
  858.        VideoState,                                                      /*@C21*/
  859.        VideoOn,                                                         /*@C21*/
  860.        ColorMode,                                                       /*@C21*/
  861.        EnvBufferPassed;
  862.  
  863. rc = ERROR_VIO_INVALID_PARMS;                           /* Initialize to error*/
  864. EnvBufferPassed = SEG( Environment );                   /* Non-zero = TRUE    */
  865.  
  866. if ( ( Function == FnRestoreEnvironment )            && /* Valid funct request*/
  867.      ( ParmBlock->Length >= MinSLen_SaveRestoreEnv ) && /* Valid packet length*/
  868.        ParmBlock->Flags                              && /* An option specified*/
  869.     !( ParmBlock->Flags & ~VALID_SAVEREST_FLAG )     && /* No illegal options */
  870.     !( ( ParmBlock->Flags & SAVEREST_FULLPVB )       &&
  871.        ( ParmBlock->Flags & SAVEREST_PARTPVB ) )     && /* Not part and full  */
  872.     !( ( ParmBlock->Length < sizeof( VDH_SAVEREST )) && /* PVB and no selector*/
  873.        ( ParmBlock->Flags & (SAVEREST_FULLPVB+SAVEREST_PARTPVB) ) ) &&
  874.        EnvBufferPassed )
  875. {
  876.  
  877.   rc = NO_ERROR;                                       /* Initialize no error */
  878.  
  879. #if VDH8514A                                                  /*@MS00 */
  880.  
  881. /*
  882. **  If the mode being restored is not an 8514/A native mode, call RestoreEnv
  883. **  in VDHVGA.DLL.  Otherwise, restore the native mode.
  884. */
  885.  
  886.   if ( VGA_PRESENT && !Environment->NATIVE_MODE )
  887.   {
  888.     LeaveNativeMode();
  889.     rc = ChainedVDHRestoreEnv( (ENVIRONMENT far *)&Environment->VGAEnvironment,
  890.                                ParmBlock, Function );
  891.   }
  892.  
  893. #else
  894.  
  895. /*
  896. **  Turn off the Video Signal                                             @C2
  897. */
  898.  
  899.   VideoState = Environment->VideoEnable;                                /*@C21*/
  900.   Environment->VideoEnable = 0;                                         /*@C21*/
  901.  
  902. #if VDHVGA                                                         /*@C21,@MS00*/
  903.      ColorMode = HardwareColor();        /* color/mono mode               @C21*/
  904. #else                                                              /*@C21,@MS00*/
  905.      ColorMode = Environment->ModeData.fbType & NOT_MONO;               /*@C21*/
  906. #endif
  907.  
  908.   VideoOn = 0;                                                          /*@C21*/
  909.   AccessVideoEnable( ColorMode, SET, &VideoOn );                        /*@C21*/
  910.  
  911.   if ( ParmBlock->Flags & SAVEREST_HARDWARE )
  912.  
  913. /*
  914. **  Output environment buffer to registers
  915. */
  916.     SaveRestoreHW( Environment, SET );
  917.  
  918.   if ( ParmBlock->Flags & ( SAVEREST_FULLPVB | SAVEREST_PARTPVB ) )
  919.  
  920. /*
  921. **  Restore partial or full display buffer
  922. */
  923.  
  924.     rc = SaveRestorePVB( ParmBlock, RESTORE,
  925.  
  926. #if VDHEGA || VDHVGA                                           /*@MS00 */
  927.  
  928.                          (UCHAR far *)&Environment->Hardware.Sequencers.Regs.MapMask,
  929.  
  930. #else
  931.  
  932.                          (UCHAR far *)NULL,
  933.  
  934. #endif
  935.  
  936.                          Environment );
  937.  
  938. /*
  939. **  Turn the Video Signal ON if it was on previously                      @C2
  940. */
  941.  
  942. /*
  943. **  If current cols = 132 then ensure proper register setup for 132 cols
  944. **  on a restore.
  945. */
  946.  
  947. #if VDHVGA                                                        /*@D1085,@MS00*/
  948.                                                                        /*@D1085*/
  949.   if(Environment->ModeData.col == 132)
  950.   {                               /*@D1085*/
  951.  
  952.     if ((SVGAPresent == IBM_ADAPTER) || !SVGAPresent)           /*            */
  953.      if(Environment->XGA_PRESENT == FALSE)                      /*@D1452*/
  954.        SET132(Environment->Comp_Reg,1);                         /*@D1085*/
  955.   }
  956.  
  957.   else
  958.   {                                                             /*@D1085*/
  959.  
  960.      if (Environment->Comp_Reg != 0)
  961.      {                                 /*@D1085*/
  962.  
  963.         if ((SVGAPresent == IBM_ADAPTER) || !SVGAPresent)       /*            */
  964.           if (Environment->XGA_PRESENT == FALSE)
  965.             SET132(Environment->Comp_Reg,0);                    /*@D1085*/
  966.      } /* endif */                                              /*@D1085*/
  967.   } /* endif */                                                 /*@D1085*/
  968.                                                                 /*@D1085*/
  969. #endif
  970.  
  971.   if ( VideoState )
  972.   {                                                   /*@C21*/
  973.  
  974.      AccessVideoEnable( ColorMode, SET, &VideoState );                  /*@C21*/
  975.      Environment->VideoEnable = 1;                                      /*@C21*/
  976.   }                                                                     /*@C21*/
  977.  
  978. #endif
  979.  
  980.   }
  981. return( rc );
  982.  
  983. }
  984.  
  985. /*****************************************************************************
  986.  *
  987.  *  SUBROUTINE NAME: RetConfigInfo
  988.  *
  989.  *  DESCRIPTIVE NAME: Return video adapter configuration information
  990.  *
  991.  *  FUNCTION: RetConfigInfo is called by BVS to identify the current
  992.  *            display adapter.
  993.  *
  994.  *  ENTRY POINT: RetConfigInfo
  995.  *    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 260 )
  996.  *
  997.  *  INPUT: (Passed on stack)
  998.  *             FAR *Environment ( Environment buffer for the session )
  999.  *             FAR *ParmBlock
  1000.  *                     USHORT Length = length of this packet
  1001.  *                     USHORT Flags  = 0 ( reserved )
  1002.  *                     FAR *ConfigData = VioGetConfig structure
  1003.  *             ULONG Function ( Call vector table entry = 260 )
  1004.  *         (Referenced)
  1005.  *
  1006.  *
  1007.  *  EXIT-NORMAL: AX = 0
  1008.  *               Configuration data is returned to caller
  1009.  *
  1010.  *  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  1011.  *
  1012.  *  EFFECTS: If the length of ConfigData does not exactly fit a
  1013.  *           parameter, the length is adjusted and returned.
  1014.  *
  1015.  *  INTERNAL REFERENCES:
  1016.  *    ROUTINES: NONE
  1017.  *
  1018.  *  EXTERNAL REFERENCES:
  1019.  *    ROUTINES: NONE
  1020.  *
  1021.  ****************************************************************************/
  1022.  
  1023. USHORT EXPENTRY RetConfigInfo( Environment, ParmBlock, Function )
  1024.  
  1025. ENVIRONMENT far *Environment;
  1026. VDH_CONFIG far *ParmBlock;
  1027. ULONG Function;
  1028.  
  1029. {
  1030.  
  1031. USHORT rc,workvar;
  1032.  
  1033. VDHCONFIGINFO far *pReqConfig;          /* Reduce level of indirection, @S8 */
  1034. unsigned register ReqConfigLen;         /* Eliminate segment loading, @S8 */
  1035.  
  1036. rc = ERROR_VIO_INVALID_PARMS;                         /* Initialize to error    */
  1037.  
  1038. if ( ( Function == FnReturnConfigInfo )            && /* Valid function request */
  1039.      ( ParmBlock->Length >= sizeof( VDH_CONFIG ) ) && /* Valid packet length    */
  1040.      ( !ParmBlock->Flags ) )
  1041. {                        /* Valid flags            */
  1042.  
  1043.   rc = NO_ERROR;                                       /* Initialize no error */
  1044.  
  1045.   ReqConfigLen = (pReqConfig = ParmBlock->ConfigDataPTR)->cb; /*@S8*/
  1046.  
  1047.   if ( ReqConfigLen > sizeof(VDHCONFIGINFO) )
  1048.   { /*@S25*/
  1049.  
  1050.      ReqConfigLen = MinDLen_Config_Memory;      /*@S25*/
  1051.   }                                             /*@S25*/
  1052.  
  1053.   if ( ( ReqConfigLen < MinDLen_Config_Adapter ) &&  /* @@A */
  1054.        ( ReqConfigLen != Config_Return_Length ) )    /* @@A */
  1055.      rc = ERROR_VIO_INVALID_LENGTH;                                  /* @@A */
  1056.  
  1057. /*
  1058. **  Structure length of 2 means set structure length and return
  1059. */
  1060.  
  1061.   else if ( ReqConfigLen == Config_Return_Length )
  1062.     ReqConfigLen = sizeof( VDHCONFIGINFO );
  1063.  
  1064.   else
  1065.   {
  1066.  
  1067. /*
  1068. **  Adapter types:
  1069. **                 0 - MPA                   4 - IBM Japan G
  1070. **                 1 - CGA                   5 - IBM Japan H
  1071. **                 2 - EGA                   6 - IBM Japan ST
  1072. **                 3 - VGA or PS/2 adapter   7 - 8514/A
  1073. */
  1074.  
  1075.  
  1076. #if VDHCGA                                                            /*@MS00 */
  1077.  
  1078.     pReqConfig->adapter  = TYPE_CGA;
  1079.  
  1080. #elif VDHEGA                                                          /*@MS00 */
  1081.  
  1082.     pReqConfig->adapter  = TYPE_EGA;
  1083.  
  1084. #elif VDHVGA                                                          /*@MS00 */
  1085.  
  1086.     pReqConfig->adapter  = TYPE_VGA;
  1087.  
  1088. #elif VDH8514A                                                        /*@MS00 */
  1089.  
  1090.     pReqConfig->adapter  = TYPE_8514A;
  1091.  
  1092. #elif VDHMPA                                                          /*@MS00 */
  1093.  
  1094.     pReqConfig->adapter  = TYPE_MPA;
  1095.  
  1096. #endif  /* VDHCGA                                                       @MS00 */
  1097.  
  1098.     if ( ReqConfigLen < MinDLen_Config_Display )
  1099.       ReqConfigLen = MinDLen_Config_Adapter;
  1100.  
  1101.     else
  1102.     {
  1103. /*
  1104. **  Display types:
  1105. **                 0 - 5151 mono             5 - IBM Japan 5550 mono
  1106. **                 1 - 5153 color            6 - IBM Japan 5550 color
  1107. **                 2 - 5154 enhanced         7 - IBM Japan 5570 color
  1108. **                 3 - 8503 mono             8 - IBM Japan 5570 full page
  1109. **                 4 - 8512/8513 color       9 - 8514 color
  1110. */
  1111.  
  1112.       pReqConfig->display = VideoHardware.display;                      /*@T39*/
  1113.  
  1114.       if ( ReqConfigLen < MinDLen_Config_Memory )
  1115.         ReqConfigLen = MinDLen_Config_Display;
  1116.  
  1117.       else
  1118.       {
  1119. /*
  1120. **  Video memory size:
  1121. **    VGA or PS/2 adapter:  256k
  1122. **    EGA:                  64k, 128k, 192k, 256k
  1123. **    CGA:                  64k
  1124. **    MPA:                  4k
  1125. **    8514/A:               512k, 1MB
  1126. */
  1127.  
  1128.         pReqConfig->cbMemory = VideoHardware.memory;                    /*@T39*/
  1129.  
  1130.         if ( ReqConfigLen < MinDLen_Config_ConfigNum )
  1131.           ReqConfigLen = MinDLen_Config_Memory;
  1132.  
  1133.         else
  1134.         {
  1135.  
  1136. /*
  1137. **  Configuration number: always return unknown
  1138. */
  1139.  
  1140.           pReqConfig->Configuration = UNKNOWN;
  1141.  
  1142.           if ( ReqConfigLen < MinDLen_Config_Version )
  1143.             ReqConfigLen = MinDLen_Config_ConfigNum;
  1144.  
  1145.           else
  1146.           {
  1147.  
  1148. /*
  1149. **  Video device driver version number
  1150. */
  1151.  
  1152.             pReqConfig->DeviceDriver = DeviceDriver;
  1153.  
  1154.             if ( ReqConfigLen < MinDLen_Config_Flag )
  1155.               ReqConfigLen = MinDLen_Config_Version;
  1156.  
  1157.             else
  1158.             {
  1159.  
  1160. /*
  1161. **  Configuration flag: xxxxxxxb  1 = Power-up display
  1162. */
  1163.  
  1164.               pReqConfig->Flags = ConfigFlag;
  1165.  
  1166.               if ( ReqConfigLen < MinDLen_Config_HWBufLen )
  1167.                 ReqConfigLen = MinDLen_Config_Flag;
  1168.  
  1169.               else
  1170.               {
  1171.  
  1172. /*
  1173. **  Size of hardware state buffer
  1174. */
  1175.  
  1176.                 pReqConfig->HWBufferSize = sizeof( ENVIRONMENT );
  1177.  
  1178. #if VDH8514A                                                         /* @MS00 */
  1179.  
  1180.  
  1181. /*
  1182. **  If the VDHVGA is there, allocate enough room to tack its environment
  1183. **  buffer onto the end of the VDH8514A environment buffer.
  1184. */
  1185.  
  1186.                 if ( VGA_PRESENT )
  1187.                   pReqConfig->HWBufferSize +=
  1188.                                                 VGAConfigData.HWBufferSize;
  1189.  
  1190. #endif
  1191.  
  1192.                 if ( ReqConfigLen < MinDLen_Config_FullSaveSz )
  1193.                   ReqConfigLen = MinDLen_Config_HWBufLen;
  1194.  
  1195.                 else
  1196.                 {
  1197.  
  1198. /*
  1199. **  Size of entire physical display buffer for the current mode (page 0 only)
  1200. */
  1201.  
  1202. #if VDHVGA                                                            /*@MS00 */
  1203.  
  1204.         if (OEMFlags & STARDUST_VGA)
  1205.                   pReqConfig->FullSaveSize = 640L*480L;   /* VGC mode 2E */
  1206.  
  1207.         else
  1208.                   pReqConfig->FullSaveSize =  38400L * 4L;   /* VGA mode 12 */
  1209.  
  1210. #elif VDHEGA                                                         /*@MS00 */
  1211.  
  1212.                   pReqConfig->FullSaveSize =  28400L * 4L;   /* EGA mode 10 */
  1213.  
  1214. #elif VDHCGA                                                          /*@MS00 */
  1215.  
  1216.                   pReqConfig->FullSaveSize =   8000L * 2L; /* CGA modes 4,5,6 */
  1217.  
  1218. #elif VDHMPA                                                          /*@MS00 */
  1219.  
  1220.                   pReqConfig->FullSaveSize =   (ULONG)(80 * 25 * 2); /* MPA 7 */
  1221.  
  1222. #elif VDH8514A                                                        /*@MS00 */
  1223.  
  1224.                   pReqConfig->FullSaveSize =
  1225.                            VGA_PRESENT ? VGAConfigData.FullSaveSize : UNKNOWN;
  1226.  
  1227. #endif  /* VDHVGA                                                       @MS00 */
  1228.  
  1229.                   if ( ReqConfigLen < MinDLen_Config_PartSaveSz )
  1230.                     ReqConfigLen = MinDLen_Config_FullSaveSz;
  1231.  
  1232.                   else
  1233.                   {
  1234.  
  1235. /*
  1236. **  Size of entire physical display buffer for the popup mode (page 0 only)
  1237. */
  1238.  
  1239.                     pReqConfig->PartSaveSize = PartialSaveSize;
  1240.  
  1241.                     if ( ReqConfigLen < MinDLen_Config_EMAdapter )
  1242.                       ReqConfigLen = MinDLen_Config_PartSaveSz;
  1243.  
  1244.                     else
  1245.                     {
  1246.  
  1247. /*
  1248. **  Emulated adapter type and offset its offset in ConfigData structure
  1249. */
  1250.  
  1251.                       pReqConfig->EMAdaptersOFF =
  1252.                               OFFSET( pReqConfig->LEMAdapterdata ) -    /*@C33*/
  1253.                               OFFSET( pReqConfig->cb );
  1254.  
  1255.                                        /* length of Emulated adapter data @C33*/
  1256.                       pReqConfig->LEMAdapterdata = 1;                   /*@C33*/
  1257.  
  1258. /*
  1259. **  Emulated adapter types:
  1260. **              b0 - MPA adapter         b3 - VGA or PS/2 adapter
  1261. **              b1 - CGA adapter         b7 - 8514/A adapter
  1262. **              b2 - EGA adapter
  1263. */
  1264.  
  1265. #if VDHMPA                                                            /*@MS00 */
  1266.  
  1267.                       pReqConfig->EMAdapters = EMULATE_TYPE_MPA;
  1268.  
  1269. #elif VDHCGA                                                          /*@MS00 */
  1270.  
  1271.                       pReqConfig->EMAdapters = EMULATE_TYPE_CGA;
  1272.  
  1273. #elif VDHEGA                                                          /*@MS00 */
  1274.  
  1275.                       pReqConfig->EMAdapters =
  1276.                              ( VideoHardware.display == Mono5151 ) ?    /*@T39*/
  1277.                                  EMULATE_TYPE_MPA + EMULATE_TYPE_EGA : /*@D184*/
  1278.                                  EMULATE_TYPE_CGA + EMULATE_TYPE_EGA;  /*@D184*/
  1279.  
  1280. #elif VDHVGA
  1281.                                                                        /*@MS00 */
  1282.                       pReqConfig->EMAdapters =
  1283.                                  EMULATE_TYPE_MPA + EMULATE_TYPE_CGA +
  1284.                                  EMULATE_TYPE_EGA + EMULATE_TYPE_VGA;
  1285.  
  1286. #elif VDH8514A                                                          /*@MS00 */
  1287.  
  1288.                       pReqConfig->EMAdapters = EMULATE_TYPE_8514A
  1289.                              + ( !VGA_PRESENT ? 0 :
  1290.                                  EMULATE_TYPE_MPA + EMULATE_TYPE_CGA +
  1291.                                  EMULATE_TYPE_EGA + EMULATE_TYPE_VGA );
  1292.  
  1293. #endif  /* VDHMPA                                                    @MS00 */
  1294.  
  1295.                       if ( ReqConfigLen < MinDLen_Config_EMDisplay )
  1296.                         ReqConfigLen = MinDLen_Config_EMAdapter;
  1297.  
  1298.                       else
  1299.                       {
  1300.  
  1301. /*
  1302. **  Emulated display type and offset its offset in ConfigData structure
  1303. */
  1304.  
  1305.                         pReqConfig->EMDisplaysOFF =
  1306.                                      OFFSET( pReqConfig->LEMDisplaydata ) -
  1307.                                      OFFSET( pReqConfig->cb );
  1308.  
  1309.                                        /* length of Emulated display data @C33*/
  1310.                         pReqConfig->LEMDisplaydata = 1;                 /*@C33*/
  1311.  
  1312. /*
  1313. **  Emulated display types:
  1314. **                b0 - 5151 mono            b3 - 8503 mono
  1315. **                b1 - 5153 color           b4 - 8512/8513 color
  1316. **                b2 - 5154 enhanced        b9 - 8514 color
  1317. */
  1318.                         pReqConfig->EMDisplays =
  1319.                           pReqConfig->EMAdapters & EMULATE_TYPE_MPA
  1320.                           ? EmDisp_MPA : 0; /*@D184*/
  1321.  
  1322. #if !(VDHMPA)                                                         /*@MS00 */
  1323.  
  1324.                         pReqConfig->EMDisplays |=
  1325.                           pReqConfig->EMAdapters & EMULATE_TYPE_CGA
  1326.                           ? EmDisp_CGA : 0; /*@D184*/
  1327.  
  1328. #if !(VDHCGA)                                                         /*@MS00 */
  1329.  
  1330.                         pReqConfig->EMDisplays |=
  1331.                           (VideoHardware.display == EnColor5154)        /*@T39*/
  1332.                           ? EmDisp_EGA : 0; /*@D184*/
  1333.  
  1334. #if !(VDHEGA)                                                         /*@MS00 */
  1335.  
  1336.                         pReqConfig->EMDisplays |=
  1337.                           pReqConfig->EMAdapters & EMULATE_TYPE_VGA
  1338.                           ? EmDisp_VGA + EmDisp_EGA : 0; /*@D184*/
  1339.  
  1340. #if VDH8514A                                                          /*@MS00 */
  1341.  
  1342.                         pReqConfig->EMDisplays |=
  1343.                            (VideoHardware.display==Color8512_8513      /*@T39*/
  1344.                                  || VideoHardware.display==Mono8503)
  1345.                            ? EmDisp_8514L : EmDisp_8514A; /*@D184*/
  1346.  
  1347. #endif  /* VDH8514A                                              @MS00 */
  1348. #endif  /* ! VDHEGA                                              @MS00 */
  1349. #endif  /* ! VDHCGA                                              @MS00 */
  1350. #endif  /* ! VDHMPA                                              @MS00 */
  1351.  
  1352.                         ReqConfigLen = MinDLen_Config_EMDisplay;
  1353.                         }
  1354.                       }
  1355.                     }
  1356.                   }
  1357.                 }
  1358.               }
  1359.             }
  1360.           }
  1361.         }
  1362.       }
  1363.  
  1364.     }
  1365.   }
  1366.  
  1367. if (!rc)
  1368. {                              /*@S8*/
  1369.     pReqConfig->cb = ReqConfigLen;      /*@S8*/
  1370. }                                       /*@S8*/
  1371.  
  1372. return( rc );
  1373. }
  1374.  
  1375. #if !(VDH8514A)                                                  /*@MS00 */
  1376.  
  1377. /*****************************************************************************
  1378.  *
  1379.  *  SUBROUTINE NAME: GetPhysBuf
  1380.  *
  1381.  *  DESCRIPTIVE NAME: Get LDT selector to physical display buffer
  1382.  *
  1383.  *  FUNCTION: GetPhysBuf is called by BVS in order to obtain an LDT
  1384.  *            selector by which to address the display buffer
  1385.  *            corresponding to the current mode or the mode specified.
  1386.  *
  1387.  *  ENTRY POINT: GetPhysBuf
  1388.  *    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 275 )
  1389.  *
  1390.  *  INPUT: (Passed on stack)
  1391.  *             FAR *Environment ( Environment buffer for the session )
  1392.  *             FAR *ParmBlock
  1393.  *                     USHORT Length = length of this packet
  1394.  *                     USHORT Flags
  1395.  *                     FAR *PhysBufData = VioGetPhysBuf structure
  1396.  *             ULONG Function ( Call vector table entry = 275 )
  1397.  *         (Referenced)
  1398.  *             MemoryMaps[] (Table of memory map info for each mode)
  1399.  *
  1400.  *  EXIT-NORMAL: AX = 0
  1401.  *               An LDT selector to the PVB is returned to caller
  1402.  *
  1403.  *  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  1404.  *
  1405.  *  EFFECTS: NONE
  1406.  *
  1407.  *  INTERNAL REFERENCES:
  1408.  *    ROUTINES: NONE
  1409.  *
  1410.  *  EXTERNAL REFERENCES:
  1411.  *    ROUTINES: PhysToUVirt
  1412.  *
  1413.  ****************************************************************************/
  1414.  
  1415. USHORT EXPENTRY GetPhysBuf( Environment, ParmBlock, Function )
  1416.  
  1417. ENVIRONMENT far *Environment;
  1418. VDH_GETPVB far *ParmBlock;
  1419. ULONG Function;
  1420.  
  1421. {
  1422.  
  1423. USHORT rc,
  1424.        i,
  1425.        Mode,
  1426.        AmountAllocated,
  1427.        EnvBufferPassed;
  1428. ULONG  PVB_TOP, PVB_BOTTOM,
  1429.        PVBLen, NOT_ALLOCATED;
  1430. FarAddress PVB, Temp;                                                   /*@T30*/
  1431. ENVIRONMENT far *TempEnv;
  1432. SEL Selector;
  1433. USHORT far *ReturnDataArea;
  1434.  
  1435. USHORT return_alt_selectors;                                            /*@B29*/
  1436. USHORT use_ALT_VIOPHYSBUF;                                              /*@B29*/
  1437.  
  1438. return_alt_selectors = FALSE;                                           /*@B29*/
  1439.  
  1440. rc = ERROR_VIO_PTR;                                 /* LDTSelector not passed */
  1441.  
  1442. if ( ( Function == FnGetPhysBuf )                  && /*Valid function request*/
  1443.      ( ParmBlock->Length >= sizeof( VDH_GETPVB ) ) && /*Valid structure length*/
  1444.      ( ParmBlock->Flags <= 1 ) ) {                    /*Valid flags           */
  1445.  
  1446.   EnvBufferPassed = SEG( Environment );               /*Non-zero = TRUE       */
  1447.  
  1448.   if ( ParmBlock->PVBDataPTR->cb == 0L && ParmBlock->PVBDataPTR->pBuf != 0L )
  1449.   {
  1450. /*
  1451. **  Length = 0, use address and length corresponding to the current mode
  1452. **  on this adapter:
  1453. **    VGA: mono text      - Address: 0xB0000, Length: 4000
  1454. **         color text     - Address: 0xB8000, Length: 4000
  1455. **         lores graphics - Address: 0xB8000, Length: 8000  ( 1st page )
  1456. **         lores graphics - Address: 0xBA000, Length: 8000  ( 2nd page )
  1457. **         other graphics - Address: 0xA0000, Length: 64000
  1458. **    EGA: mono text      - Address: 0xB0000, Length: 4000
  1459. **         color text     - Address: 0xB8000, Length: 4000
  1460. **         lores graphics - Address: 0xB8000, Length: 8000  ( 1st page )
  1461. **         lores graphics - Address: 0xBA000, Length: 8000  ( 2nd page )
  1462. **         other graphics - Address: 0xA0000, Length: 28000
  1463. **    CGA: mono text      - Address: 0xB0000, Length: 4000
  1464. **         color text     - Address: 0xB8000, Length: 4000
  1465. **         lores graphics - Address: 0xB8000, Length: 8000  ( 1st page )
  1466. **         lores graphics - Address: 0xBA000, Length: 8000  ( 2nd page )
  1467. **    MPA: mono text      - Address: 0xB0000, Length: 4000
  1468. */
  1469.  
  1470.     if ( (ParmBlock->Flags & UPDATE_HARDWARE) && READABLE )
  1471.     {
  1472.  
  1473. #if VDHVGA    /* Read/write hardware */                             /*@MS00 */
  1474.  
  1475. /*
  1476. **  Allocate temporary storage to temporary environment buffer
  1477. */
  1478.  
  1479.        if ( !(rc = DosAllocSeg( sizeof( ENVIRONMENT ), (PSEL)&Selector, 0 )) )
  1480.        {
  1481.  
  1482.          TempEnv = (ENVIRONMENT far *)MakeFarPTR( Selector, 0 );
  1483.  
  1484. /*
  1485. **  If "foreground", get the mode directly from the hardware
  1486. */
  1487.  
  1488.          TempEnv->VideoEnable = 1;              /* Assume video ON */   /*@T34*/
  1489.          SaveRestoreHW( TempEnv, GET );                 /* Read hardware      */
  1490.  
  1491.          Mode = GetModeIndex( TempEnv );                /* Get mode index + 1 */
  1492.  
  1493.          rc = ( !Mode-- ) ? ERROR_VIO_MODE : NO_ERROR;
  1494.  
  1495. /*
  1496. **  Deallocate temporary storage to temporary environment buffer
  1497. */
  1498.  
  1499.          DosFreeSeg( Selector );
  1500.  
  1501.          }
  1502.  
  1503. #endif
  1504.  
  1505.        }
  1506.  
  1507.        else
  1508.  
  1509. /*
  1510. **  If "background", get the mode from the environment buffer
  1511. */
  1512.  
  1513.       if ( EnvBufferPassed )
  1514.       {
  1515.         Mode = Environment->ModeIndex;
  1516.         rc   = NO_ERROR;
  1517.  
  1518.         }
  1519.  
  1520.     if ( !rc )
  1521.     {
  1522.       PVB.FullAddress = MemoryMaps[Modes[Mode].MemMap].Start.FullAddress;
  1523.  
  1524.       if (Environment->ModeData.fbType & GRAPHICS )
  1525.       {                /*@B70*/
  1526.  
  1527.          if (!(PVBLen = (ULONG)MemoryMaps[Modes[Mode].MemMap].PageLength))
  1528.             PVBLen = 0x10000;
  1529.       }
  1530.  
  1531.       else                                                           /*@B70*/
  1532.          PVBLen = (Environment->ModeData.row                         /*@B70*/
  1533.                      * Environment->ModeData.col * 2);               /*@B70*/
  1534.  
  1535. /*
  1536. **  Return selector list in the alternate data structure
  1537. */
  1538.  
  1539.       if(((ALT_VIOPHYSBUF far *)(ParmBlock->PVBDataPTR->pBuf))->cb != 2)/*@B29*/
  1540.          return_alt_selectors = TRUE;                                   /*@B29*/
  1541.  
  1542.       ReturnDataArea = (USHORT far *)&(((ALT_VIOPHYSBUF far *)
  1543.                        (ParmBlock->PVBDataPTR->pBuf))->asel[0]);
  1544.       }
  1545.     }
  1546.  
  1547.   else
  1548.   {
  1549.  
  1550.     if ( ParmBlock->PVBDataPTR->cb != 0L )
  1551.     {
  1552.       PVBLen = ParmBlock->PVBDataPTR->cb;
  1553.       PVB_BOTTOM = (ULONG)(PVB.FullAddress = ParmBlock->PVBDataPTR->pBuf);
  1554.       PVB_TOP    = PVB_BOTTOM + PVBLen - 1L;
  1555.  
  1556.       if ( ( (PVB_BOTTOM >= MIN_PVB_BOTTOM)  && (PVB_TOP <= MAX_PVB_TOP)))
  1557.            rc = NO_ERROR; /* This passes the A0000 to BFFFF text, say it's OK */
  1558.  
  1559.       else                                   /*@B68*/
  1560.           rc = ERROR_VIO_INVALID_PARMS;      /*@B68*/
  1561.  
  1562. /*
  1563. **  Return selector list in the passed PhysBuf data structure
  1564. */
  1565.  
  1566.       ReturnDataArea = (USHORT far *)&ParmBlock->PVBDataPTR->asel[0];
  1567.  
  1568.       }
  1569.     }
  1570.  
  1571.   use_ALT_VIOPHYSBUF = FALSE;                                           /*@B29*/
  1572.  
  1573.   if (ReturnDataArea == (USHORT far *)&(((ALT_VIOPHYSBUF far *)
  1574.                         (ParmBlock->PVBDataPTR->pBuf))->asel[0])){ /*@B29*/
  1575.     use_ALT_VIOPHYSBUF = TRUE;                                          /*@B29*/
  1576.  
  1577.     }
  1578.  
  1579.   if ( !rc )
  1580.  
  1581.     for ( i = 0, NOT_ALLOCATED = PVBLen; NOT_ALLOCATED; i++ ) {
  1582.  
  1583.       if ( NOT_ALLOCATED > 0xFFFFL+1L )
  1584.       {
  1585.         AmountAllocated = 0;                      /* Allocate maximum ( 64K ) */
  1586.         NOT_ALLOCATED -= 64L * 1024L;
  1587.         rc = PhysToUVirt( PVB, &Temp, AmountAllocated );        /*@B31*/
  1588.         PVB.part.Selector += 1;                                 /*@B31*/
  1589.       }
  1590.  
  1591.       else
  1592.       {
  1593.         AmountAllocated = (USHORT)NOT_ALLOCATED;         /* Allocate the rest */
  1594.         NOT_ALLOCATED = 0L;
  1595.         rc = PhysToUVirt( PVB, &Temp, AmountAllocated );        /*@B31*/
  1596.        }
  1597.  
  1598.       if ( !rc )
  1599.       {                                                 /*@T30,@T53*/
  1600.  
  1601.         if (use_ALT_VIOPHYSBUF == TRUE)
  1602.         {                                /*@B29*/
  1603.           ((ALT_VIOPHYSBUF far *)(ParmBlock->PVBDataPTR->pBuf))->cb =
  1604.                                 ((2*(i+1))+2); /*@B28*/
  1605.           if (return_alt_selectors == TRUE)                             /*@B29*/
  1606.              ReturnDataArea[i] = Temp.part.Selector;                    /*@B29*/
  1607.         }                                                               /*@B29*/
  1608.  
  1609.         else
  1610.           ReturnDataArea[i] = Temp.part.Selector;                       /*@T30*/
  1611.       }                                                                 /*@T53*/
  1612.     }
  1613.   }
  1614.  
  1615. return( rc );
  1616.  
  1617. }
  1618.  
  1619. /*****************************************************************************
  1620.  *
  1621.  *  SUBROUTINE NAME: FreePhysBuf
  1622.  *
  1623.  *  DESCRIPTIVE NAME: Deallocate LDT selector
  1624.  *
  1625.  *  FUNCTION: FreePhysBufe is called by BVS in order to deallocate an
  1626.  *            LDT selector which was previously used to address the
  1627.  *            physical display buffer.
  1628.  *
  1629.  *  ENTRY POINT: FreePhysBuf
  1630.  *    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 276 )
  1631.  *
  1632.  *  INPUT: (Passed on stack)
  1633.  *             FAR *Environment ( Environment buffer for the session )
  1634.  *             FAR *ParmBlock
  1635.  *                     USHORT Length = length of this packet
  1636.  *                     USHORT Flags  = 0 ( reserved )
  1637.  *                     USHORT LDTSelector = selector to deallocate
  1638.  *             ULONG Function ( Call vector table entry = 276 )
  1639.  *
  1640.  *  EXIT-NORMAL: AX = 0
  1641.  *               An LDT selector to the PVB is deallocated
  1642.  *
  1643.  *  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  1644.  *
  1645.  *  EFFECTS: NONE
  1646.  *
  1647.  *  INTERNAL REFERENCES:
  1648.  *    ROUTINES: NONE
  1649.  *
  1650.  *  EXTERNAL REFERENCES:
  1651.  *    ROUTINES: FreePhysToUVirt
  1652.  *
  1653.  ****************************************************************************/
  1654.  
  1655. USHORT EXPENTRY FreePhysBuf( Environment, ParmBlock, Function )
  1656.  
  1657. ENVIRONMENT far *Environment;
  1658. VDH_FREEPVB far *ParmBlock;
  1659. ULONG Function;
  1660.  
  1661. {
  1662.  
  1663. USHORT rc;
  1664.  
  1665. if ( ( Function == FnFreePhysBuf )                  && /* Valid function request */
  1666.      ( ParmBlock->Length >= sizeof( VDH_FREEPVB ) ) && /* Valid structure length */
  1667.       !ParmBlock->Flags )
  1668.  
  1669. {                            /* Valid flags            */
  1670.   FreePhysToUVirt( ParmBlock->LDTSelector );
  1671.   rc = NO_ERROR;                                       /* Signal no error        */
  1672. }
  1673.  
  1674. else
  1675.   rc = ERROR_VIO_INVALID_PARMS;                        /* LDTSelector not passed */
  1676.  
  1677. return( rc );
  1678. }
  1679.  
  1680. #else
  1681.  
  1682. /*****************************************************************************
  1683.  *
  1684.  *  SUBROUTINE NAME: ChainRouter
  1685.  *
  1686.  *  DESCRIPTIVE NAME: Call default entry in call vector table
  1687.  *
  1688.  *  FUNCTION: During VDH chaining, the environment buffer of the
  1689.  *            previous call table entry is tacked on to the end of the
  1690.  *            current VDH environment buffer.  If a particular VDH
  1691.  *            service is not supported, the VDH has to call the
  1692.  *            previous entry with its environment.
  1693.  *
  1694.  *  ENTRY POINT: UnsupportedService
  1695.  *    LINKAGE:   CALL FAR
  1696.  *
  1697.  *  INPUT: (Passed on stack)
  1698.  *             FAR *Environment ( Environment buffer for the session )
  1699.  *             FAR *ParmBlock
  1700.  *             ULONG Function ( Call vector table entry )
  1701.  *
  1702.  *  EXIT:      AX = return code from call table vector routine
  1703.  *
  1704.  *  EFFECTS: NONE
  1705.  *
  1706.  *  INTERNAL REFERENCES:
  1707.  *    ROUTINES: NONE
  1708.  *
  1709.  *  EXTERNAL REFERENCES:
  1710.  *    ROUTINES: NONE
  1711.  *
  1712.  ****************************************************************************/
  1713.  
  1714. USHORT EXPENTRY ChainRouter( Environment, ParmBlock, Function )
  1715.  
  1716. ENVIRONMENT far *Environment;
  1717. char far *ParmBlock;
  1718. ULONG Function;
  1719.  
  1720. {
  1721.  
  1722. USHORT rc;
  1723.  
  1724. rc = (*ChainedCallVectorTable[ Function - FnTextBufferUpdate ])
  1725.              ((char far *)&Environment->VGAEnvironment, ParmBlock, Function );
  1726.  
  1727. return( rc );
  1728.  
  1729. }
  1730.  
  1731. #endif
  1732.  
  1733. #if DEBUG                                               /*@MS07 - BEGIN */
  1734.  
  1735. /*****************************************************************************
  1736.  *
  1737.  *  SUBROUTINE NAME: DEBUG_TRACE
  1738.  *
  1739.  *  DESCRIPTIVE NAME: Print Debug Trace
  1740.  *
  1741.  *  FUNCTION: Print debug trace
  1742.  *              then call the entry in call vector table
  1743.  *
  1744.  *  ENTRY POINT: UnsupportedService
  1745.  *    LINKAGE:   CALL FAR
  1746.  *
  1747.  *  INPUT: (Passed on stack)
  1748.  *             FAR *Environment ( Environment buffer for the session )
  1749.  *             FAR *ParmBlock
  1750.  *             ULONG Function ( Call vector table entry )
  1751.  *
  1752.  *  EXIT:      AX = return code from call table vector routine
  1753.  *
  1754.  *  EFFECTS: NONE
  1755.  *
  1756.  *  INTERNAL REFERENCES:
  1757.  *    ROUTINES: NONE
  1758.  *
  1759.  *  EXTERNAL REFERENCES:
  1760.  *    ROUTINES: NONE
  1761.  *
  1762.  ****************************************************************************/
  1763.  
  1764. USHORT EXPENTRY DEBUG_TRACE( Environment, ParmBlock, Function )
  1765.  
  1766. ENVIRONMENT far *Environment;
  1767. char far *ParmBlock;
  1768. ULONG Function;
  1769.  
  1770. {
  1771.  
  1772. USHORT rc;
  1773.  
  1774.    FNDEBUG(Function);
  1775.  
  1776.    (USHORT far *)DebugTrace = VDHEntryPoint[ Function - FnTextBufferUpdate ];
  1777.  
  1778.    rc = (DebugTrace)(Environment, ParmBlock, Function );
  1779.  
  1780.    return( rc );
  1781. }
  1782.  
  1783. #endif  /* DEBUG                                               @MS07 - END */
  1784.  
  1785.