![[Toc]](../../toc.gif)
![[Index]](/idx.gif)
Code Sample
The following code sample shows how to load the .PMI file, set up the mode
table, and set the graphics mode.
#include <os2.h>
#include <svgadefs.h>
#define DLLNAME "videopmi"
#define REQUEST_ENTRYPOINT "VIDEOPMI32Request"
#define FAIL_LENGTH 256
#define PMIFILE "svgadata.pmi"
/*
* Adapter instance.
*/
VIDEO_ADAPTER AdapterInstance;
/*
* Entry point to videopmi
*/
PFNVIDEOPMIREQUEST pfnPMIRequest;
/*
* mode table. It is an array of VIDEOMODEINFOs.
*/
PVIDEOMODEINFO ModeTable;
ULONG ulTotalModes;
/************************************************************
* Load the .PMI file, get the hardware information about the
* adapter and the entry point to videopmi.
*
* Returns 0 if successful; DOS error token, otherwise.
************************************************************/
APIRET LoadPMIService (VOID)
{
APIRET rc;
char sFail[FAIL_LENGTH] = {0};
HMODULE hmodVIDEOPMI;
/************************************************************
* Load videopmi.dll
************************************************************/
if (!(rc = DosLoadModule (sFail, FAIL_LENGTH, DLLNAME,
&hmodVIDEOPMI)))
{
/************************************************************
* Get PMIREQUEST entry point
************************************************************/
if (!(rc = DosQueryProcAddr (hmodVIDEOPMI,
0,
REQUEST_ENTRYPOINT,
&pfnPMIRequest)))
/*
* Load PMI file.
* If PMI file is successfully loaded,
* adapter in AdapterInstance will be filled with the
* information in .PMI file.
*
* Remember to set up the size information for ADAPTERINFO
* and VIDEOMODEINFO.
*/
AdapterInstance.AdapterInfo_cb = sizeof (ADAPTERINFO);
AdapterInstance.VideoModeInfo_cb = sizeof (VIDEOMODEINFO);
rc = pfnPMIRequest (&AdapterInstance,
PMIREQUEST_LOADPMIFILE,
PMIFILE,
NULL);
if (rc)
DosFreeModule (hmodVIDEOPMI);
}
return rc;
}
/************************************************************
*
* This function sets up the mode table.
*
* Copy the mode table from videopmi. It is an arrary of modes.
* All the information in [ModeInfo] and
* [MonitorModeInfo], if any, is included.
*
* Returns 0 if successful; DOS error token, otherwise.
************************************************************/
APIRET SetUpModeTable (VOID)
{
APIRET rc;
/*
* Get the total number of modes
*/
if (!(rc = pfnPMIRequest (&AdapterInstance,
PMIREQUEST_QUERYMAXMODEENTRIES,
NULL,
&ulTotalModes)))
/*
* Allocate memory for mode table
*/
if (!(rc = DosAllocSharedMem ((PPVOID)&ModeTable,
NULL,
ulTotalModes *
sizeof (VIDEOMODEINFO),
OBJ_GETTABLE | PAG_COMMIT |
PAG_WRITE)))
/*
* Copy mode table.
* Please check svgadefs.h for the fields in VIDEOMODEINFO.
*/
rc = pfnPMIRequest (&AdapterInstance,
PMIREQUEST_QUERYMODEINFODATA,
NULL,
ModeTable);
return rc;
}
/************************************************************
*
* This function sets the graphic mode.
*
* You can select the mode based on any information in the VIDEOMODEINFO
* structure. The following is only an example to set the graphics mode
* based on resolution and refresh rate.
* PM driver should not call videopmi to set the mode directly.
* It should call BVH to set the mode as before, such that
* the mode can be set based on the current monitor capability
* handled by BVH.
*
* Returns 0 if successful; DOS error token, otherwise.
************************************************************/
APIRET SETSVGAMODE (ULONG ulHorRes,
ULONG ulVerRes,
ULONG ulColors,
ULONG ulVerRefr,
PULONG pulModeInd,
PCLUTDATA pCLUTData)
{
APIRET rc=0xFFFF;
ULONG i;
/* Search mode */
if (ulVerRefr >= 0xFFL) /* pick the first mode of the resolution */
{
for(i=0; i < ulTotalModes; i++)
if ((ModeTable[i].usXResolution == (USHORT) ulHorRes) &&
(ModeTable[i].usYResolution == (USHORT) ulVerRes) &&
(ModeTable[i].bBitsPerPixel == (BYTE) ulColors))
*pulModeInd = i;
}
else /* verify all including the refresh parameter */
{
for(i=0; i < ulTotalModes; i++)
if ((ModeTable[i].usXResolution == (USHORT )ulHorRes) &&
(ModeTable[i].usYResolution == (USHORT) ulVerRes) &&
(ModeTable[i].bBitsPerPixel == (BYTE) ulColors) &&
((ModeTable[i].bVrtRefresh == 0xFF) ||
(ModeTable[i]bVrtRefresh == (BYTE) ulVerRefr)))
*pulModeInd= i;
}
if (i == ulTotalModes)
return rc; /* mode not found */
/* Unlock first */
/*
* Copy VIDEOMODEINFO of the selected mode to AdapterInstance.
* Depending on the .PMI file, this information may be needed.
*/
AdapterInstance.ModeInfo = ModeTable[*pulModeInd];
/*
* Call videopmi to set the mode.
*/
rc = pfnPMIRequest (&AdapterInstance,
PMIREQUEST_SETMODE,
&ModeTable[*pulModeInd].miModeId,
NULL);
if (rc)
return rc;
else
/* Load Color Lookup Table */
if (ModeTable[*pulModeInd].bBitsPerPixel <= 8)
rc = pfnPMIRequest (&AdapterInstance,
PMIREQUEST_SETCLUT,
pCLUTData,
NULL);
return rc;
}
Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs