home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / VDH / VDHXCONF.C < prev    next >
C/C++ Source or Header  |  1995-04-14  |  41KB  |  1,049 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 = vdhxconf.c
  16.  *
  17.  * DESCRIPTIVE NAME = video adapter detection routines
  18.  *
  19.  *
  20.  * VERSION = V2.0
  21.  *
  22.  * DATE
  23.  *
  24.  * DESCRIPTION    getVideoType, videoIoctl
  25.  *
  26.  * FUNCTIONS
  27.  *
  28.  * NOTES
  29.  *
  30.  * STRUCTURES
  31.  *
  32.  * EXTERNAL REFERENCES  DosOpen,  DosDevConfig, DosDevIoctl,
  33.  *                      PhysToUVirt, FreePhysToUvirt
  34.  *
  35.  * EXTERNAL FUNCTIONS
  36.  *
  37. */
  38.  
  39. #define  INCL_BASE                     /* ALL of OS/2 Base                  */
  40. #define  INCL_DOSDEVICES               /* Device specific, ring 2 support   */
  41. #define  INCL_OS2STD                   /* Needed for NULL definition in     */
  42.                                        /* OS2STD.H                          */
  43. #include <os2.h>
  44. #include "vdhctl.h"                    /* Conditional compilation control   */
  45. #include "vdh.h"                       /* Type definitions                  */
  46.  
  47. #if      !(VDH8514A)                   /* @MS00                             */
  48. extern USHORT *hScreenDD;              /* SCREEM$ handle for DosDevIOCtl    */
  49.  
  50.   #if      VDHEGA                      /* @S40f,MS00                        */
  51. extern MEMORYMAPS MemoryMaps[];        /* See VDHDATA.H for detail     @S40F*/
  52.  #endif                                /* VDHEGA                            */
  53.                                        /* @S40F,MS00                        */
  54. #endif                                 /* !(VDH8514A)                       */
  55. extern VIDEOHARDWARE VideoHardware;    /* Installed video hardware          */
  56.                                        /* structure                         */
  57.  
  58. #if      VDHINIT                       /*                               @ISO*/
  59. extern DMQSDATA *pDMQSdata;            /*                               @ISO*/
  60. extern USHORT machinetype;             /* used by QueryXGA              @RAD*/
  61. BIOSINFO biosinfo;                     /* to read in BIOS info          @RAD*/
  62. #endif                                 /*                               @ISO*/
  63.  
  64. extern USHORT OEMFlags;                /* OEM specific features             */
  65. void DetectOEM(void);                  /* OEM hardware detection            */
  66.  
  67. #ifdef   VDHVGA                        /* LCD                               */
  68. extern USHORT SVGAPresent;             /* LCD                               */
  69. #endif                                 /* LCD                               */
  70.  
  71. /*****************************************************************************
  72.  *
  73.  * SUBROUTINE NAME: getVideoType
  74.  *
  75.  * DESCRIPTIVE NAME: return the video hardware configuration
  76.  *
  77.  * FUNCTION: Determine adapters and monitors installed on target machine
  78.  *  this function is called from both IDH and BVHs each of which use
  79.  *  hardware configuration in different ways.  Thus, the video hardware
  80.  *  configuration is returned differently when called from a BVH than
  81.  *  when its called from the IDH.
  82.  *
  83.  *  IDHs only use the values filled in the
  84.  *  videohardware data structure so no globals are filled for them
  85.  *
  86.  *  ENTRY POINT: getVideoType
  87.  *    LINKAGE:   CALL FAR
  88.  *
  89.  *  INPUT: None
  90.  *
  91.  *  EXIT: return:  0 if video cannot be determined
  92.  *
  93.  * The global structure VideoHardware has fVideoType filled with:
  94.  *
  95.  *    MPA_BIT           1       bit 0, MPA adapter with MONO monitor
  96.  *    CGA_BIT           2       bit 1, CGA adapter with COLOR monitor
  97.  *    EGM_BIT           4       bit 2, EGA adapter with MONO monitor
  98.  *    EGC_BIT           8       bit 3, EGA adapter with COLOR monitor
  99.  *    EGA_BIT           0x10    bit 4, EGA adapter w/ ENH COLOR monitor
  100.  *    VGP_BIT           0x20    bit 5, VGA plasma display
  101.  *    VGM_BIT           0x40    bit 6, VGA adapter with MONO monitor
  102.  *    VGC_BIT           0x80    bit 7, VGA adapter with COLOR monitor
  103.  *    A8514M_BIT        0x100   bit 8, 8514A with 8507 monitor
  104.  *    A8514C_BIT        0x200   bit 9, 8514A with 8512/3 monitor
  105.  *    A8514A_BIT        0x400   bit 10, 8514A with 8514 monitor
  106.  *    A8514_15_BIT      0x800   bit 11, 8514A with 8515 monitor
  107.  *    A8514_03_BIT      0x1000  bit 12, 8514A with 8503 monitor
  108.  *    NODISPLAY_BIT     0x2000  bit 13, no display present on VGA system
  109.  *
  110.  *    all bits off means adapter type could not be determined
  111.  *
  112.  * The filled memory gets:
  113.  *     bits 0 and 1 reflect memory configuation for EGA or 8514A
  114.  *          bit  0 1   - means
  115.  *               ---------------
  116.  *               0 0    - minimum memory, EGA = 64K, 8514A = .5M
  117.  *               0 1    - EGA = 128K
  118.  *               1 0    - EGA = 192K
  119.  *               1 1    - maximum memory, EGA = 256K, 8514A = 1M
  120.  *   EGA64K_BIT     0x0000
  121.  *   EGA128K_BIT    0x0001
  122.  *   EGA192K_BIT    0x0002
  123.  *   EGA256K_BITS   0x0003
  124.  *   A85141MEG_BITS 0x0003
  125.  *
  126.  *  EFFECTS: NONE
  127.  *
  128.  *  INTERNAL REFERENCES:
  129.  *
  130.  *    ROUTINES: videoIoctl
  131.  *
  132.  *  EXTERNAL REFERENCES:
  133.  *
  134.  ****************************************************************************/
  135.  
  136. USHORT near getVideoType(void)
  137.  
  138. {
  139.  
  140. #if      VDH8514A      || VDHINIT      /* @T72,MS00                         */
  141.  
  142.   union
  143.   {                                    /* used to interpret 8514A           */
  144.                                        /* information                       */
  145.     USHORT Flags;
  146.     struct
  147.     {
  148.       UCHAR Display;
  149.       UCHAR Memory;
  150.     }
  151.     part;
  152.   }
  153.   A8514;
  154.  
  155. #endif                                 /* VDH8514A || VDHINIT               */
  156.                                        /* @T72,MS00                         */
  157.  
  158. #if      !(VDH8514A)                   /* MS00                              */
  159.   UCHAR videoType;                     /* possible VGA video type           */
  160.   EGABIOSINFO EGAInfo;                 /* EGA information from 40:87 & 88   */
  161.   UCHAR videoSW;                       /* EGA hardware switch settings      */
  162.  
  163.   #if      VDHEGA                      /* @S40f,MS00                        */
  164. MEMORYMAPS far *MemMapPtr;             /* Pointer to MemoryMaps[]           */
  165.  #endif                                /* VDHEGA                            */
  166.                                        /* @S40f,MS00                        */
  167.  
  168.   VideoHardware.fVideoType = VDHERROR_NO_ADAPTER;/* assume no adapter       */
  169.  
  170.   /*
  171.   ** Use the adapter information obtained from OEMHLP$ to determine
  172.   ** the default video memory and display configurations
  173.   */
  174.  
  175.   if (!videoIoctl(&videoType, NULL, OEMHLP_FUNCTION_ADAPTER))
  176.   {                                    /* @T74                              */
  177.  
  178.     if (videoType&MPA_DEVICE)
  179.     {                                  /* B0000 accessible?                 */
  180.  
  181.   #if      VDHMPA                      /* MS00                              */
  182.       VideoHardware.memory = 4L*1024L; /* Default to 4K                     */
  183.       VideoHardware.display = Mono5151;/* Default to MONO                   */
  184.       VideoHardware.popupMode = 0;
  185.  #endif                                /* VDHMPA                            */
  186.                                        /* @MS00                             */
  187.       VideoHardware.fVideoType |= MPA_BIT;/* mark MPA is present            */
  188.     }
  189.  
  190.     if (videoType&CGA_DEVICE)
  191.     {                                  /* B8000 accessible?                 */
  192.  
  193.   #if      VDHCGA                      /* MS00                              */
  194.       VideoHardware.memory = 16L*1024L;/* Default to 16K                    */
  195.       VideoHardware.display = Color5153;/* Default to Color                 */
  196.       VideoHardware.popupMode = ModeIndex_CGA3;/* hi-res 80x25 text         */
  197.  #endif                                /* VDHCGA                            */
  198.                                        /* MS00                              */
  199.       VideoHardware.fVideoType |= CGA_BIT;/* mark CGA is present            */
  200.     }
  201.  
  202.     if (videoType&EGA_DEVICE)
  203.     {                                  /* EGA present?                      */
  204.  
  205.       if (!getEGAinfo(&EGAInfo))
  206.       {                                /* determine/record EGA info         */
  207.  
  208.         /*
  209.         ** Form a 0 base value for the EGA switch settings
  210.         ** by removing the primary/secondary information
  211.         ** obtained from the BIOS data area
  212.         */
  213.  
  214.         if ((videoSW = EGAInfo.BIOS_info3&0x0F) >= 6)
  215.           videoSW -= 6;
  216.  
  217.                /* off = 1, sw1 = bit 0                                      */
  218.  
  219.         switch (videoSW)
  220.         {
  221.           case 0x0 :                   /* EGA in CGA 40x25 mode             */
  222.           case 0x1 :                   /* EGA in CGA 80x25 mode             */
  223.           case 0x2 :                   /* EGA in Enhanced display emulation */
  224.                                        /* mode                              */
  225.  
  226.   #if      VDHEGA                      /* MS00                              */
  227.             VideoHardware.display = Color5153;
  228.             VideoHardware.popupMode = ModeIndex_EGC3;
  229.  #endif                                /* VDHEGA                            */
  230.                                        /* MS00                              */
  231.  
  232.             /*
  233.             ** turn off CGA bit set by OEMHLP$ and turn on EGC bit
  234.             */
  235.  
  236.             VideoHardware.fVideoType ^= CGA_BIT|EGC_BIT;
  237.             break;
  238.  
  239.           case 0x3 :                   /* EGA in enhanced color modes       */
  240.  
  241.   #if      VDHEGA                      /* MS00                              */
  242.                VideoHardware.display = EnColor5154;
  243.             VideoHardware.popupMode = ModeIndex_EGA3;
  244.   #endif                               /* VDHEGA                            */
  245.  
  246.             /*
  247.             ** turn off CGA bit set by OEMHLP$ and turn on EGA bit
  248.             */
  249.  
  250.             VideoHardware.fVideoType ^= CGA_BIT|EGA_BIT;
  251.             break;
  252.  
  253.           case 0x4 :                   /* monochrome modes                  */
  254.           case 0x5 :
  255.  
  256.   #if      VDHEGA                      /* MS00                              */
  257.             VideoHardware.display = Mono5151;
  258.             VideoHardware.popupMode = ModeIndex_EGM7;
  259.   #endif                               /* VDHEGA                            */
  260.  
  261.                   /* turn off MPA bit set by OEMHLP$ and turn on EGM bit    */
  262.  
  263.             VideoHardware.fVideoType ^= MPA_BIT|EGM_BIT;
  264.             break;
  265.  
  266.         }                              /* end of switch ( videoSW )          */
  267.  
  268.   #if      VDHEGA        || VDHINIT    /* @B18,@C31,MS00                     */
  269.  
  270.     #if    VDHEGA                    /* @S40f,MS00                           */
  271.            MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_ModeD]; /* @S40f */
  272.     #endif                             /* VDHEGA                             */
  273.                                       /* @S40f,MS00                          */
  274.  
  275.         /*
  276.         ** Since ROM BIOS already examines the card, use the memory
  277.         ** size values found
  278.         **
  279.         ** BIOS_info BYTE:
  280.         **      B7: High bit of mode set, clear/not clear regen
  281.         **      B6: Memory  B6 B5 = 0 0 -  64k    0 1 - 128k
  282.         **      B5: Memory          1 0 - 192k    1 1 - 256k
  283.         **      B4: Reserved
  284.         **      B3: 1 - EGA active monitor, 0 - not active
  285.         **      B2: 1 - wait for display enable
  286.         **      B1: 1 - EGA has monochrome attatched
  287.         **      B0: 0 - set C_TYPE emulate active
  288.         */
  289.  
  290.         switch (EGAInfo.BIOS_info&0x60)
  291.  
  292.         {                              /* Use memory size bits              */
  293.           case 0x00 :
  294.             VideoHardware.memory = 64L*1024L;/* 64K VRAM                    */
  295.             break;
  296.  
  297.           case 0x20 :
  298.             VideoHardware.memory = 128L*1024L;/* 128K VRAM                  */
  299.  
  300.     #if      VDHEGA                    /* @S40f,MS00                        */
  301.             MemMapPtr->PageReal += 0x04000; /* @S40f                        */
  302.             MemMapPtr->TotalReal += 0x10000L; /* @S40f                      */
  303.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_ModeE]; /* @S40*/
  304.             MemMapPtr->PageReal += 0x04000; /* @S40f                        */
  305.             MemMapPtr->TotalReal += 0x10000L; /* @S40f                      */
  306.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_ModeF];/* @S40f*/
  307.             MemMapPtr->PageReal += 0x8000; /* @S40f                         */
  308.             MemMapPtr->TotalReal += 0x10000L; /* @S40f                      */
  309.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_Mode10];/*@S40f*/
  310.             MemMapPtr->TotalSize += 56000L; /* @S40f                        */
  311.             MemMapPtr->TotalReal += 0xE000L; /* @S40f                       */
  312.             MemMapPtr->BitPlanes += 10; /* @S40f                            */
  313.    #endif                              /* VDHEGA                            */
  314.                                        /* @S40f,MS00                        */
  315.             break;
  316.  
  317.           case 0x40 :
  318.             VideoHardware.memory = 192L*1024L;/* 192K VRAM                  */
  319.  
  320.     #if      VDHEGA                    /* @S40f,MS00                        */
  321.             MemMapPtr->PageReal += 0x08000; /* @S40f                        */
  322.             MemMapPtr->TotalReal += 0x20000L; /* @S40f                      */
  323.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_ModeE];/*@S40f */
  324.             MemMapPtr->PageReal += 0x08000; /* @S40f                        */
  325.             MemMapPtr->TotalReal += 0x20000L; /* @S40f                      */
  326.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_ModeF];/* @S40f*/
  327.             MemMapPtr->PageReal += 0x8000; /* @S40f                         */
  328.             MemMapPtr->TotalReal += 0x10000L; /* @S40f                      */
  329.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_Mode10];  /*40f*/
  330.             MemMapPtr->PageReal += 0x4000; /* @S40f                         */
  331.             MemMapPtr->TotalSize += 56000L; /* @S40f                        */
  332.             MemMapPtr->TotalReal += 0x1E000L; /* @S40f                      */
  333.             MemMapPtr->BitPlanes += 10; /* @S40f                            */
  334.    #endif                              /* VDHEGA                            */
  335.                                         /* @S40f,MS00                       */
  336.             break;
  337.  
  338.           case 0x60 :
  339.             VideoHardware.memory = 256L*1024L;/* 256K VRAM                  */
  340.  
  341.     #if      VDHEGA                    /* @S40f,MS00                        */
  342.             MemMapPtr->PageReal += 0x0C000; /* @S40f                        */
  343.             MemMapPtr->TotalReal += 0x30000L; /* @S40f                      */
  344.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_ModeE];/*@S40f */
  345.             MemMapPtr->PageReal += 0x0C000; /* @S40f                        */
  346.             MemMapPtr->TotalReal += 0x30000L; /* @S40f                      */
  347.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_ModeF];/*@S40f */
  348.             MemMapPtr->PageReal += 0x8000; /* @S40f                         */
  349.             MemMapPtr->TotalReal += 0x10000L; /* @S40f                      */
  350.             MemMapPtr = (MEMORYMAPS far *)&MemoryMaps[MemMap_Mode10];/*@S40f*/
  351.             MemMapPtr->PageReal += 0x8000; /* @S40f                         */
  352.             MemMapPtr->TotalSize += 56000L; /* @S40f                        */
  353.             MemMapPtr->TotalReal += 0x2E000L; /* @S40f                      */
  354.             MemMapPtr->BitPlanes += 10; /* @S40f                            */
  355.    #endif                               /* VDHEGA                           */
  356.                                         /* @S40f,MS00                       */
  357.             break;
  358.  
  359.         }                              /* end of switch ( EGAInfo.BIOS_info */
  360.                                        /* )                                 */
  361.  #endif                                /* VDHEGA || VDHINIT                 */
  362.                                        /* @B18,@C31,MS00                    */
  363.       }                                /* end of query EGA infor            */
  364.     }
  365.  
  366.     else
  367.  
  368.       if (videoType&VGA_DEVICE)
  369.    {                                   /* VGA present?                      */
  370.  
  371.         if (!(videoIoctl(&videoType, NULL, /* Get monitor type              */
  372.            OEMHLP_FUNCTION_VIDEO)))
  373.         {                              /* @T74                              */
  374.           VideoHardware.memory = 256L*1024L;/* Default to 256K              */
  375.  
  376.           switch (videoType)
  377.           {
  378.             case  VGA_NODISPLAY :      /* MS28 - BEGIN                      */
  379.  
  380.   #ifdef   BUGBUG                      /* work around INT 10h               */
  381.                                        /* incompatibility                   */
  382.  
  383.     #if      VDHVGA
  384.               VideoHardware.display = NoDisplay;
  385.               VideoHardware.popupMode = ModeIndex_VGA3p;
  386.     #endif                             /* VDHVGA                            */
  387.  
  388.               VideoHardware.fVideoType = NODISPLAY_BIT; /* @T41             */
  389.               break;
  390.  
  391.  #endif                                 /* BUGBUG                           */
  392.                                         /* MS28 - END                       */
  393.             case  VGA_COLOR :
  394.  
  395.   #if      VDHVGA                      /* MS00                              */
  396.               VideoHardware.display = Color8512_8513;
  397.               VideoHardware.popupMode = ModeIndex_VGA3p;
  398.  #endif                                 /* VDHVGA                           */
  399.                                         /* MS00                             */
  400.               VideoHardware.fVideoType ^= CGA_BIT|VGC_BIT; /* @T41          */
  401.               break;
  402.  
  403.             case  VGA_MONO :
  404.  
  405.               if (VideoHardware.fVideoType&MPA_BIT)
  406.               {                        /* @T41                              */
  407.  
  408.   #if      VDHVGA                      /* MS00                              */
  409.                 VideoHardware.display = Mono8503;
  410.                 VideoHardware.popupMode = ModeIndex_VGM7p;
  411.  #endif                                 /* VDHVGA                           */
  412.                                         /* MS00                             */
  413.                 VideoHardware.fVideoType ^= MPA_BIT|VGM_BIT; /* @T41        */
  414.               }
  415.  
  416.               else
  417.               {                        /* @T41                              */
  418.  
  419.   #if      VDHVGA                      /* @T41,MS00                         */
  420.                 VideoHardware.display = Color8512_8513; /* @T44             */
  421.                 VideoHardware.popupMode = ModeIndex_VGA3p; /* @T41          */
  422.  
  423.  #endif                                 /* VDHVGA                           */
  424.                                         /* @T41,MS00                        */
  425.                 VideoHardware.fVideoType ^= CGA_BIT|VGC_BIT; /* @T44        */
  426.               }                        /* @T41                              */
  427.               break;
  428.  
  429.           }                            /* end of switch ( videoType )       */
  430.  
  431.           /*
  432.           ** see if a plasma display is present
  433.           */
  434.  
  435.           if (!videoIoctl(&videoType, NULL, OEMHLP_FUNCTION_MISC))
  436.           {                            /* @T71                              */
  437.  
  438.             if (videoType&0x40)
  439.          {                             /* P70 video present?                */
  440.  
  441.   #if      VDHVGA                      /* MS00                              */
  442.               VideoHardware.display = PlasmaDisplay;
  443.  
  444.               if (VideoHardware.fVideoType&VGM_BIT)
  445.               {                        /* @T71                              */
  446.                 VideoHardware.popupMode = ModeIndex_VGP7p;
  447.               }
  448.  
  449.               else
  450.               {                        /* @T71                              */
  451.                 VideoHardware.popupMode = ModeIndex_VGC7p; /* @T71          */
  452.               }                        /* @T71                              */
  453.  #endif                                /* VDHVGA                            */
  454.                                        /* MS00                              */
  455.               VideoHardware.fVideoType |= VGP_BIT;
  456.             }                          /* end of P70 present check          */
  457.           }                            /* end of P70 query through OEMHLP$  */
  458.         }                              /* end of VGA monitor query through  */
  459.                                        /* OEMHLP$                           */
  460.       }                                /* end of EGA/VGA present check      */
  461.   }                                    /* end of video adapter query        */
  462.                                        /* through OEMHLP$                   */
  463. #endif                                 /* !(VDH8514A)                       */
  464.                                        /* MS00                              */
  465.  
  466. #if      VDHINIT                       /* @T72,MS00                         */
  467.     if (!videoIoctl(&biosinfo, NULL, OEMHLP_BIOSINFO))      /*          @RAD*/
  468.        machinetype = biosinfo.ABIOSPresent;                 /*          @RAD*/
  469.  
  470.     if ((A8514.Flags = QueryXGA()) != VDHERROR_NO_ADAPTER)
  471.     {                                  /* @T72                              */
  472.  
  473.       if ((A8514.part.Display) || (A8514.part.Memory&0x80) &&  /* B716255   */
  474.          (VideoHardware.display == PlasmaDisplay))
  475.       {                                /* B716255                           */
  476.         VideoHardware.fVideoType |= XGA_BIT; /* @T72                        */
  477.  
  478.         if (!videoIoctl(&pDMQSdata, NULL, OEMHLP_DMQS_INFO))/*          @ISO*/
  479.  
  480.           if (pDMQSdata)
  481.           {                            /*                               @ISO*/
  482.  
  483.             switch (pDMQSdata->monitor_id)
  484.             {                          /*                               @ISO*/
  485.                                        /*                               @ISO*/
  486.               case  COMP_ID_9515 :     /*                               @ISO*/
  487.                 A8514.part.Display = color9515;/*                       @ISO*/
  488.                 break;                 /*                               @ISO*/
  489.                                        /*                               @ISO*/
  490.               case  COMP_ID_9517 :     /*                               @ISO*/
  491.                 A8514.part.Display = color9517;/*                       @ISO*/
  492.                 break;                 /*                               @ISO*/
  493.                                        /*                               @ISO*/
  494.               case  COMP_ID_9518 :     /*                               @ISO*/
  495.                 A8514.part.Display = color9518;/*                       @ISO*/
  496.                 break;                 /*                               @ISO*/
  497.             }                          /*                               @ISO*/
  498.           }                            /*                               @ISO*/
  499.       }                                /* B716255                           */
  500.     }                                  /* @T72                              */
  501. #endif                                 /* VDHINIT                           */
  502.                                        /* @T72,MS00                         */
  503.  
  504. #if      VDH8514A      || VDHINIT      /* record possible 8514 information  */
  505.                                        /* MS00                              */
  506.  
  507. if ((VideoHardware.fVideoType&XGA_BIT) || /* XGA present?                   */
  508.      ((A8514.Flags = Query8514A()) != VDHERROR_NO_ADAPTER))
  509.   {                                    /* @T72                              */
  510.     VideoHardware.popupMode = 0;
  511.     VideoHardware.display = (USHORT)A8514.part.Display;
  512.  
  513.     switch (A8514.part.Display)
  514.     {
  515.       case  Mono8503 :
  516.         VideoHardware.fVideoType |= A8514_03_BIT;/* 8514/A with 8503        */
  517.         break;
  518.  
  519.       case  Color8514 :
  520.         VideoHardware.fVideoType |= A8514A_BIT;/* 8514/A with 8514          */
  521.         break;
  522.  
  523.       case  Color8515 :
  524.         VideoHardware.fVideoType |= A8514_15_BIT;/* 8514/A with 8515        */
  525.         break;
  526.  
  527.       case  Mono8507_8604 :
  528.         VideoHardware.fVideoType |= A8514M_BIT;/* 8514/A with 8507/8604     */
  529.         break;
  530.  
  531.       case  Color8512_8513 :
  532.         VideoHardware.fVideoType |= A8514C_BIT;/* 8514/A with 8512/13       */
  533.         break;
  534.     }                                  /* end of monitor attachment to      */
  535.                                        /* 8514A/XGA device                  */
  536.  
  537.     if (A8514.part.Memory == MEM_1MB)
  538.     {
  539.       VideoHardware.memory = 1024L*1024L;
  540.     }
  541.  
  542.     else
  543.     {
  544.       VideoHardware.memory = 512L*1024L;
  545.     }
  546.   }                                    /* end of XGA present check          */
  547. #endif                                 /* VDH8514A || VDHINIT               */
  548.                                        /* MS00                              */
  549.  
  550. #if      !(VDH8514A)                   /* B724243,MS27                      */
  551.     DetectOEM();                       /* MS27                              */
  552. #endif                                 /* !(VDH8514A)                       */
  553.                                        /* MS27                              */
  554.  
  555.   return (VideoHardware.fVideoType);
  556. }
  557.  
  558. #if      !(VDH8514A)                   /* MS00                              */
  559.  
  560. /*****************************************************************************
  561.  *
  562.  * SUBROUTINE NAME: getEGAInfo
  563.  *
  564.  * DESCRIPTIVE NAME: return EGA information from the BIOS at 40:86,87
  565.  *
  566.  * FUNCTION:  get access to 40: upon the first call and return the data
  567.  *            found at bytes 86h and 87h.
  568.  *
  569.  *  ENTRY POINT: getEGAInfo
  570.  *    LINKAGE:   CALL FAR
  571.  *
  572.  *  INPUT: address of egainfo structure
  573.  *
  574.  *  EXIT:  egainfo structure filled with necessary values
  575.  *
  576.  *  EFFECTS: NONE
  577.  *
  578.  *  INTERNAL REFERENCES:
  579.  *
  580.  *    ROUTINES: PhysToUVirt, FreePhysToVirt
  581.  *
  582.  *  EXTERNAL REFERENCES:
  583.  *
  584.  ****************************************************************************/
  585.  
  586. USHORT PASCAL near getEGAinfo(egainfo)
  587.  
  588.   EGABIOSINFO *egainfo;
  589.  
  590. {
  591.   FarAddress PhysAddress;              /* becomes virtual address of 40:    */
  592.   unsigned rc;                         /* return code                       */
  593.  
  594.  
  595.   /*
  596.   ** Obtain addressability to the BIOS data area
  597.   */
  598.  
  599.  
  600.   PhysAddress.part.Selector = 0x0000;
  601.   PhysAddress.part.Offset = 0x0400;
  602.  
  603.   if (!(rc = PhysToUVirt(PhysAddress, &PhysAddress, sizeof(VIDEO_BIOS))))
  604.   {                                    /* access to 40: successful, return  */
  605.                                        /* the parts for EGA type            */
  606.                                        /* determination                     */
  607.  
  608.     egainfo->BIOS_info = ((VIDEO_BIOS far *)PhysAddress.FullAddress)->
  609.                                             BIOS_info;
  610.  
  611.     egainfo->BIOS_info3 = ((VIDEO_BIOS far *)PhysAddress.FullAddress)->
  612.                                              BIOS_info3;
  613.     FreePhysToUVirt(PhysAddress.part.Selector);
  614.  
  615.   }
  616.  
  617.   return  rc;
  618. }
  619.  
  620. /*****************************************************************************
  621.  *
  622.  * SUBROUTINE NAME: videoIoctl
  623.  *
  624.  * DESCRIPTIVE NAME: perform requested IOCTL request
  625.  *
  626.  * FUNCTION:  Issue generic IOCTL, use strong error checking
  627.  *
  628.  *  ENTRY POINT: videoIoctl
  629.  *    LINKAGE:   CALL NEAR
  630.  *
  631.  *  INPUT: data - data from IOCTL request
  632.  *         parm - parameter to IOCTL request
  633.  *         function - function requested
  634.  *
  635.  *  EXIT:  error code from DosOpen or DosDevIoctl
  636.  *
  637.  *  EFFECTS: determined by request
  638.  *
  639.  *  INTERNAL REFERENCES:
  640.  *
  641.  *    ROUTINES: DosOpen, DosDevIoctl
  642.  *
  643.  *  EXTERNAL REFERENCES:
  644.  *
  645.  ****************************************************************************/
  646.  
  647. int PASCAL near videoIoctl(data,parm,function)
  648.  
  649.   UCHAR *data,*parm;
  650.   unsigned function;
  651.  
  652. {
  653.  
  654.   unsigned hOemhlp;                    /* handle of OEMHLP$ device driver   */
  655.   unsigned OpenAction;                 /* action taken to open device       */
  656.   unsigned rc;                         /* function return code              */
  657.  
  658.  
  659.   if (!(rc = DosOpen(OEMHLPDD_NAME, (PHFILE)&hOemhlp, (PUSHORT)&OpenAction,
  660.      NO_SIZE, NO_ATTRIBUTES, OPEN_IF_EXISTS, NO_INHERIT+DENY_NONE+READ_WRITE,
  661.      RESERVED_LONG)))
  662.  
  663.   {
  664.     rc = DosDevIOCtl(data,
  665.                      parm,
  666.                      function,
  667.                      OEMHLP_CATEGORY,
  668.                      (HFILE)hOemhlp);
  669.     DosClose(hOemhlp);
  670.   }
  671.  
  672.   return  rc;
  673.  
  674. }
  675.  
  676. #endif                                 /*        ! VDH8514A   @MS00         */
  677.  
  678. #if      !(VDH8514A)                   /* B724243 //MS27 - BEGIN            */
  679.  
  680. /***************************************************************************
  681.  *
  682.  * FUNCTION NAME = DetectOEM(void)
  683.  *
  684.  * DESCRIPTION   =
  685.  *
  686.  *     This routine detects OEM video hardware and features.
  687.  *     Some or all of the following variables are (re)set to reflect the
  688.  *     hardware detected:
  689.  *          OEMFlags
  690.  *          VideoHardware.display
  691.  *          VideoHardware.popupMode
  692.  *          VideoHardware.fVideoType
  693.  *
  694.  * INPUT         = NONE
  695.  * OUTPUT        = NONE
  696.  *
  697.  * RETURN-NORMAL = NONE
  698.  * RETURN-ERROR  = NONE
  699.  *
  700.  **************************************************************************/
  701.  
  702. void DetectOEM(void)
  703.  
  704. {
  705.  
  706.   REGADDRESS RegAddress;
  707.   REGDATA RegData;
  708.   UCHAR byt,sbyt;
  709.   USHORT i,j;
  710.   UCHAR *pchar;
  711.   USHORT *pword;
  712.   FarAddress PhysAddress;
  713.   extern VIDEOMODE Modes[];
  714.  
  715.   #if      !(VDHINIT)                  /* B724243                           */
  716.  
  717.     #if      VDHVGA
  718.  
  719.   if (VideoHardware.fVideoType & VGA_BITS)
  720.   {
  721.  
  722.     /*
  723.     **  Check C000, C800, E000, E800 for OEM video RO
  724.     */
  725.  
  726.     i = 0;
  727.     j = 0;
  728.  
  729.     do
  730.     {
  731.       PhysAddress.part.Selector = (i < 2)?0x0C:0x0E;
  732.       PhysAddress.part.Offset = (i&1)?0x8000:0x0000;
  733.  
  734.       if (!PhysToUVirt(PhysAddress, &PhysAddress, 0x0))
  735.       {
  736.         pword = (USHORT *)PhysAddress.FullAddress;
  737.                 /* Check for option ROM signature                           */
  738.  
  739.         if (*pword == 0xAA55)
  740.         {
  741.           pchar = (char *)pword;
  742.           j = *(pword+1);              /* Get length/512                    */
  743.           pchar += (j << 9)-0x16;      /* Calc Offset                       */
  744.                         /* Scan for OEM ID                                  */
  745.           j = 0;
  746.  
  747.           while ((j < 6) && (*(pchar+j) == "COMPAQ"[j]))
  748.             j++;
  749.         }
  750.  
  751.         FreePhysToUVirt(PhysAddress.part.Selector);
  752.       }
  753.       i++;
  754.     }
  755.  
  756.     while ((i < 4) && (j != 6));
  757.  
  758.     /*
  759.     ** If OEM video ROM present, detect and flag OEM VGA specific features.
  760.     */
  761.  
  762.     if (j == 6)
  763.     {
  764.       RegAddress.DataPort = 0x03BA;    /* Input Status 1 Port               */
  765.  
  766.       if (VideoHardware.popupMode != ModeIndex_VGM7p)
  767.           RegAddress.DataPort += ColorAdjustment;
  768.  
  769.       AccessRegister(&RegAddress, GET, &byt);
  770.  
  771.       if (byt & PARADISE_ID)
  772.       {
  773.         OEMFlags |= PARADISE_VGA;
  774.  
  775.         /*
  776.         ** Paradise     fix:
  777.         ** Search through mode table to find CRTCtlRegs_CMD with horizontal
  778.         ** blanking start/end data and decrement them by one row.
  779.         ** 0x2 -> start
  780.         */
  781.  
  782.         for (j = 0; j < NUM_MODES; j++)
  783.         {
  784.           i = 0;
  785.  
  786.           while ((Modes[j].ModeRegs[i].Command !=
  787.                   CRTCtlRegs_CMD) ||
  788.                   (Modes[j] .ModeRegs[i].RegData.NumEntries < 0x0C))
  789.              i++;
  790.              Modes[j].ModeRegs[i].RegData.DataArea[0x03]--;
  791.              Modes[j].ModeRegs[i].RegData.DataArea[0x02]--;
  792.         }
  793.       }
  794.  
  795.       else
  796.       {
  797.         RegAddress.AddressPort = GraphAddressPort;
  798.         RegAddress.DataPort = GraphDataPort;
  799.         RegAddress.Flags = NONE;
  800.         RegData.NumEntries = 1;
  801.         RegData.DataArea = &byt;
  802.                 /* Open access to extended VGA registers                    */
  803.  
  804.         RegData.FirstEntry = VGA_ENV_REG;
  805.         byt = VGA_UNLOCK;
  806.         AccessHardware(&RegAddress, BYTES, NONE, SET, &RegData);
  807.                 /* Read project/version byte                                */
  808.  
  809.         RegData.FirstEntry = VGA_VERSION_REG;
  810.         AccessHardware(&RegAddress, BYTES, NONE, GET, &RegData);
  811.         sbyt = byt;
  812.                 /* Close access to extended VGA registers                   */
  813.  
  814.         RegData.FirstEntry = VGA_ENV_REG;
  815.         byt = VGA_LOCK;
  816.         AccessHardware(&RegAddress, BYTES, NONE, SET, &RegData);
  817.  
  818.         if (sbyt == STARLIGHT132_ID)
  819.           OEMFlags |= STARLIGHT_VGA;
  820.  
  821.         else
  822.  
  823.           if ((sbyt & PROJECT_MASK) == STARDUST_ID)
  824.           {
  825.             OEMFlags |= STARDUST_VGA;
  826.             VideoHardware.memory = 512L*1024L;
  827.           }
  828.  
  829.           else
  830.           {
  831.             byt = ReadCMOS(CMOS_SYS_ID);
  832.  
  833.             /*
  834.             **  We need to add one more step to detecting the CRYSTAL VGA.
  835.             **  Specifically, we need to check if the LTE 386s/20 is plugged into
  836.             **  an expansion base and, if it is, check for a video card in the
  837.             **  base.  If a video card is detected, DON'T report back a CRYSTAL
  838.             **  VGA (the LTE internal VGA ASIC) because it is disabled whenever
  839.             **  a video card is present in the expansion base.  Also, for LCD
  840.             **  displays, use 640 pixel text modes for popups.
  841.             */
  842.  
  843.             if ((byt == TRIUMPH_ID) || (byt == TARGA_ID))
  844.             {
  845.               OEMFlags |= PRISM_VGA;
  846.               VideoHardware.popupMode = ModeIndex_VGP3p;
  847.             }
  848.  
  849.             else
  850.  
  851.               if (byt == CALYPSO_ID)
  852.               {
  853.                 /*
  854.                 ** Verify that CRYSTAL ASIC is active,
  855.                 ** instead of a card in the expansion
  856.                 ** base, by checking if the internal
  857.                 ** VGA is enabled (C67 bit 5 = 1).
  858.                 */
  859.                 RegAddress.DataPort = 0x0C67;
  860.                 AccessRegister(&RegAddress, GET, &byt);
  861.  
  862.                 if (byt&0x20)
  863.                 {
  864.                   OEMFlags |= CRYSTAL_VGA;
  865.                   VideoHardware.popupMode = ModeIndex_VGP3p;
  866.                 }
  867.               }
  868.           }
  869.       }
  870.     }
  871.  
  872.     else
  873.  
  874.       if (VideoHardware.Reg_132 = QUERY132())
  875.       {                                /* IBM VGA-E? //MS??                 */
  876.  
  877.         if (VideoHardware.display == PlasmaDisplay)
  878.         {                              /* LCD                               */
  879.           VideoHardware.Reg_132 = FALSE; /* LCD                             */
  880.           SVGAPresent = FALSE;         /* LCD                               */
  881.         }
  882.  
  883.         else
  884.         {                              /* LCD                               */
  885.           OEMFlags |= VGA_E;           /* 132 col. capable  @MS??           */
  886.         }                              /* LCD                               */
  887.       }
  888.   }
  889.     #endif                             /* VDHVGA                            */
  890.   #endif                  /*(VDHINIT)   B724243                             */
  891.  
  892.   #if      (VDHCGA       || VDHINIT)   /* B724243                           */
  893.  
  894.   if (VideoHardware.fVideoType&CGA_BIT)
  895.  
  896.   {
  897.     /*
  898.     ** Check for OEM system ROM.
  899.     */
  900.  
  901.     PhysAddress.part.Selector = 0xF;
  902.     PhysAddress.part.Offset = 0xFFEA;
  903.  
  904.     j = 0;
  905.  
  906.     if (!PhysToUVirt(PhysAddress, &PhysAddress, 6))
  907.     {
  908.       pchar = (UCHAR *)PhysAddress.FullAddress;
  909.  
  910.       while ((j < 6) && (*(pchar+j) == "COMPAQ"[j]))
  911.         j++;
  912.  
  913.       FreePhysToUVirt(PhysAddress.part.Selector);
  914.     }
  915.  
  916.     /*
  917.     ** If OEM system ROM present, detect and flag OEM CGA specific features.
  918.     */
  919.     if (j == 6)
  920.     {
  921.       RegAddress.DataPort = IDCEnvironReg;
  922.       AccessRegister(&RegAddress, GET, &byt);
  923.  
  924.       if (byt == IDC_SIGNATURE)
  925.       {
  926.         RegAddress.DataPort = IDCMasterModeReg;
  927.         AccessRegister(&RegAddress, GET, &byt);
  928.                 /* IDC in CGA (color) mode?                                 */
  929.  
  930.         if (!(byt & 0x07))
  931.         {
  932.  
  933.     #if      !(VDHINIT)                /* B724243                           */
  934.           OEMFlags |= IDC_CGA;
  935.     #endif
  936.  
  937.           /*
  938.           ** If internal plasma display enabled then check
  939.           */
  940.  
  941.           /*
  942.           ** display type thru the IDCDisplayType register
  943.           */
  944.  
  945.           if (byt & 0x08)
  946.           {                            /* B724243                           */
  947.             RegAddress.DataPort = IDCDisplayType; /* B724243                */
  948.             AccessRegister(&RegAddress, GET, &byt); /* B724243              */
  949.  
  950.             if (byt & 0x40)
  951.             {                          /* B724243                           */
  952.               VideoHardware.display = PlasmaDisplay; /* B724243             */
  953.             }                          /* B724243                           */
  954.           }                            /* B724243                           */
  955.  
  956.           /*
  957.           ** Read current attribute setting from extended mode
  958.           ** register.  (bits 5-7 = attribute).
  959.           */
  960.  
  961.           RegAddress.DataPort = IDCExtendedModeReg;
  962.           AccessRegister(&RegAddress, GET, &byt);
  963.  
  964.           /*
  965.           ** If attribute is alternate character set, use
  966.           ** half-intensity instead (preserve other bits).
  967.           */
  968.  
  969.           if ((byt & 0xE0) == 0x60)
  970.           {
  971.             byt ^= 0xE0;
  972.             AccessRegister(&RegAddress, SET, &byt);
  973.           }
  974.         }
  975.       }
  976.  
  977.     #if      !(VDHINIT)                /* B724243                           */
  978.  
  979.       else
  980.       {
  981.         byt = ReadCMOS(CMOS_VCFG);
  982.  
  983.         if (byt & VDU_VCFG)
  984.           OEMFlags |= VDU_CGA;
  985.  
  986.         if (byt & DSM_VCFG)
  987.         {
  988.           OEMFlags |= DSM_MONITOR;
  989.  
  990.           if (OEMFlags & VDU_CGA)
  991.             VideoHardware.popupMode = ModeIndex_VDUDSM3;
  992.         }
  993.       }
  994.     #endif        /*        !(VDHINIT)   B724243                            */
  995.     }
  996.   }
  997.   #endif          /*      (VDHCGA || VDHINIT), B724243  */
  998. }
  999.  
  1000. /*
  1001. ** @drw Add SVGA detection
  1002. */
  1003.  
  1004. /***************************************************************************
  1005.  *
  1006.  * FUNCTION NAME = GetSVGAConfig()
  1007.  *
  1008.  * DESCRIPTION   = detects whether SVGA is present
  1009.  *                 Note: SVGA support in OEMHLP$ is returned by function 8.
  1010.  *
  1011.  * INPUT         = NONE
  1012.  * OUTPUT        = TRUE  - SVGA Hardware present
  1013.  *                 FALSE - No SVGA Hardware.
  1014.  *
  1015.  * RETURN-NORMAL = NONE
  1016.  * RETURN-ERROR  = NONE
  1017.  *
  1018.  **************************************************************************/
  1019.  
  1020. USHORT PASCAL NEAR GetSVGAConfig(VOID)
  1021.  
  1022. {
  1023.   USHORT rc = FALSE;
  1024.   struct _OEMSVGAINFO
  1025.  
  1026.   {
  1027.     USHORT AdapterType;
  1028.     USHORT ChipType;
  1029.     ULONG Memory;
  1030.   }
  1031.  
  1032.   SVGAHardware;
  1033.  
  1034.  
  1035.   if (!videoIoctl((UCHAR *)&SVGAHardware, NULL, 8))
  1036.   {
  1037.     rc = SVGAHardware.AdapterType;     /* If we have SVGA installed         */
  1038.                                        /* return adapter type.              */
  1039.   }
  1040.  
  1041.   return (rc);
  1042. }
  1043.  
  1044. /*
  1045. ** @drw Add SVGA detection
  1046. */
  1047.  
  1048. #endif  /* !(VDH8514A)                           @MS27 - END B724243        */
  1049.