| 1 | /*
|
|---|
| 2 | * Few routines for full-screen DirectDraw on OS/2
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 2000 Michal Necasek
|
|---|
| 5 | * Copyright 2000 Przemyslaw Dobrowolski
|
|---|
| 6 | *
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #define INCL_DOS
|
|---|
| 12 | #define INCL_WINWINDOWMGR
|
|---|
| 13 | #include <os2wrap.h>
|
|---|
| 14 | #include <misc.h>
|
|---|
| 15 |
|
|---|
| 16 | #include <svgadefs.h>
|
|---|
| 17 |
|
|---|
| 18 | #include "os2fsdd.h"
|
|---|
| 19 |
|
|---|
| 20 | /* DirectX palette entry */
|
|---|
| 21 | typedef struct tagPALETTEENTRY
|
|---|
| 22 | {
|
|---|
| 23 | BYTE peRed;
|
|---|
| 24 | BYTE peGreen;
|
|---|
| 25 | BYTE peBlue;
|
|---|
| 26 | BYTE peFlags;
|
|---|
| 27 | } PALETTEENTRY;
|
|---|
| 28 |
|
|---|
| 29 | #define DLLNAME "VIDEOPMI"
|
|---|
| 30 |
|
|---|
| 31 | #define REQUEST_ENTRYPOINT "VIDEOPMI32Request"
|
|---|
| 32 |
|
|---|
| 33 | #define FAIL_LENGTH 256
|
|---|
| 34 |
|
|---|
| 35 | char PMIFILE[256] = "\\os2\\svgadata.pmi";
|
|---|
| 36 |
|
|---|
| 37 | /*
|
|---|
| 38 | * Adapter instance.
|
|---|
| 39 | */
|
|---|
| 40 | VIDEO_ADAPTER AdapterInstance;
|
|---|
| 41 |
|
|---|
| 42 | /*
|
|---|
| 43 | * Entry point to videopmi
|
|---|
| 44 | */
|
|---|
| 45 | PFNVIDEOPMIREQUEST __pfnPMIRequest;
|
|---|
| 46 |
|
|---|
| 47 | //
|
|---|
| 48 | // mode table. It is an array of VIDEOMODEINFOs.
|
|---|
| 49 | //
|
|---|
| 50 | static PVIDEOMODEINFO ModeTable;
|
|---|
| 51 |
|
|---|
| 52 | static ULONG ulTotalModes;
|
|---|
| 53 |
|
|---|
| 54 | static bIsInFS = FALSE;
|
|---|
| 55 |
|
|---|
| 56 | /*
|
|---|
| 57 | * PMI request wrapper
|
|---|
| 58 | */
|
|---|
| 59 | inline ULONG PMI_Request(PVIDEO_ADAPTER a, ULONG b, PVOID c, PVOID d)
|
|---|
| 60 | {
|
|---|
| 61 | ULONG yyrc;
|
|---|
| 62 | USHORT sel = RestoreOS2FS();
|
|---|
| 63 |
|
|---|
| 64 | yyrc = __pfnPMIRequest(a, b, c, d);
|
|---|
| 65 | SetFS(sel);
|
|---|
| 66 |
|
|---|
| 67 | return yyrc;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | /************************************************************
|
|---|
| 72 | * Load the .PMI file, get the hardware information about the
|
|---|
| 73 | * adapter and the entry point to videopmi.
|
|---|
| 74 | *
|
|---|
| 75 | * Returns 0 if successful; DOS error token, otherwise.
|
|---|
| 76 | ************************************************************/
|
|---|
| 77 |
|
|---|
| 78 | ULONG LoadPMIService (VOID)
|
|---|
| 79 | {
|
|---|
| 80 | APIRET rc;
|
|---|
| 81 | char sFail[FAIL_LENGTH] = {0};
|
|---|
| 82 | HMODULE hmodVIDEOPMI;
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | /************************************************************
|
|---|
| 86 | * Load videopmi.dll
|
|---|
| 87 | ************************************************************/
|
|---|
| 88 |
|
|---|
| 89 | if (!(rc = DosLoadModule (sFail, FAIL_LENGTH, DLLNAME,
|
|---|
| 90 | &hmodVIDEOPMI)))
|
|---|
| 91 | {
|
|---|
| 92 |
|
|---|
| 93 | /************************************************************
|
|---|
| 94 | * Get PMIREQUEST entry point
|
|---|
| 95 | ************************************************************/
|
|---|
| 96 |
|
|---|
| 97 | rc = DosQueryProcAddr (hmodVIDEOPMI,
|
|---|
| 98 | 0,
|
|---|
| 99 | REQUEST_ENTRYPOINT,
|
|---|
| 100 | (PFN*)&__pfnPMIRequest);
|
|---|
| 101 |
|
|---|
| 102 | if (!rc)
|
|---|
| 103 |
|
|---|
| 104 | /*
|
|---|
| 105 | * Load PMI file.
|
|---|
| 106 | * If PMI file is successfully loaded,
|
|---|
| 107 | * adapter in AdapterInstance will be filled with the
|
|---|
| 108 | * information in .PMI file.
|
|---|
| 109 | *
|
|---|
| 110 | * Remember to set up the size information for ADAPTERINFO
|
|---|
| 111 | * and VIDEOMODEINFO.
|
|---|
| 112 | */
|
|---|
| 113 |
|
|---|
| 114 | // AdapterInstance.AdapterInfo.cb = sizeof (ADAPTERINFO);
|
|---|
| 115 | // AdapterInstance.VideoModeInfo.cb = sizeof (VIDEOMODEINFO);
|
|---|
| 116 |
|
|---|
| 117 | rc = PMI_Request (&AdapterInstance,
|
|---|
| 118 | PMIREQUEST_LOADPMIFILE,
|
|---|
| 119 | // PMIREQUEST_IDENTIFYADAPTER,
|
|---|
| 120 | PMIFILE,
|
|---|
| 121 | NULL);
|
|---|
| 122 | // if (rc)
|
|---|
| 123 | DosFreeModule (hmodVIDEOPMI);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | return rc;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 | /************************************************************
|
|---|
| 131 | *
|
|---|
| 132 | * This function sets up the mode table.
|
|---|
| 133 | *
|
|---|
| 134 | * Copy the mode table from videopmi. It is an arrary of modes.
|
|---|
| 135 | * All the information in [ModeInfo] and
|
|---|
| 136 | * [MonitorModeInfo], if any, is included.
|
|---|
| 137 | *
|
|---|
| 138 | * Returns 0 if successful; DOS error token, otherwise.
|
|---|
| 139 | ************************************************************/
|
|---|
| 140 | ULONG SetUpModeTable (VOID)
|
|---|
| 141 | {
|
|---|
| 142 | APIRET rc;
|
|---|
| 143 | /*
|
|---|
| 144 | * Get the total number of modes
|
|---|
| 145 | */
|
|---|
| 146 | if (!(rc = PMI_Request (&AdapterInstance,
|
|---|
| 147 | PMIREQUEST_QUERYMAXMODEENTRIES,
|
|---|
| 148 | NULL,
|
|---|
| 149 | &ulTotalModes)))
|
|---|
| 150 |
|
|---|
| 151 | /*
|
|---|
| 152 | * Allocate memory for mode table
|
|---|
| 153 | */
|
|---|
| 154 | if (!(rc = DosAllocSharedMem ((PPVOID)&ModeTable,
|
|---|
| 155 | NULL,
|
|---|
| 156 | ulTotalModes *
|
|---|
| 157 | sizeof (VIDEOMODEINFO),
|
|---|
| 158 | OBJ_GETTABLE | PAG_COMMIT |
|
|---|
| 159 | PAG_WRITE)))
|
|---|
| 160 |
|
|---|
| 161 | /*
|
|---|
| 162 | * Copy mode table.
|
|---|
| 163 | * Please check svgadefs.h for the fields in VIDEOMODEINFO.
|
|---|
| 164 | */
|
|---|
| 165 | rc = PMI_Request (&AdapterInstance,
|
|---|
| 166 | PMIREQUEST_QUERYMODEINFODATA,
|
|---|
| 167 | NULL,
|
|---|
| 168 | ModeTable);
|
|---|
| 169 |
|
|---|
| 170 | return rc;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | ULONG FreeModeTable (VOID)
|
|---|
| 174 | {
|
|---|
| 175 | DosFreeMem (ModeTable);
|
|---|
| 176 | return 0;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | /************************************************************
|
|---|
| 181 | *
|
|---|
| 182 | * This function sets the graphic mode.
|
|---|
| 183 | *
|
|---|
| 184 | * You can select the mode based on any information in the VIDEOMODEINFO
|
|---|
| 185 | * structure. The following is only an example to set the graphics mode
|
|---|
| 186 | * based on resolution and refresh rate.
|
|---|
| 187 | * PM driver should not call videopmi to set the mode directly.
|
|---|
| 188 | * It should call BVH to set the mode as before, such that
|
|---|
| 189 | * the mode can be set based on the current monitor capability
|
|---|
| 190 | * handled by BVH.
|
|---|
| 191 | *
|
|---|
| 192 | * Returns 0 if successful; DOS error token, otherwise.
|
|---|
| 193 | ************************************************************/
|
|---|
| 194 |
|
|---|
| 195 | ULONG SetSVGAMode (ULONG ulHorRes,
|
|---|
| 196 | ULONG ulVerRes,
|
|---|
| 197 | ULONG ulColors,
|
|---|
| 198 | ULONG ulVerRefr,
|
|---|
| 199 | PULONG pulModeInd,
|
|---|
| 200 | PVOID pCLUTData)
|
|---|
| 201 | {
|
|---|
| 202 | APIRET rc=0xFFFF;
|
|---|
| 203 | ULONG i;
|
|---|
| 204 |
|
|---|
| 205 | *pulModeInd = -1;
|
|---|
| 206 | /* Search mode */
|
|---|
| 207 | /* Assuming that the modes are sorted by refresh mode in ascending */
|
|---|
| 208 | /* order, we'll find the highest refresh mode */
|
|---|
| 209 | if (ulVerRefr >= 0xFFL)
|
|---|
| 210 | {
|
|---|
| 211 | for(i=0; i < ulTotalModes; i++)
|
|---|
| 212 | if ((ModeTable[i].usXResolution == (USHORT)ulHorRes) &&
|
|---|
| 213 | (ModeTable[i].usYResolution == (USHORT)ulVerRes) &&
|
|---|
| 214 | (ModeTable[i].bBitsPerPixel == (BYTE)ulColors)) {
|
|---|
| 215 | *pulModeInd = i;
|
|---|
| 216 | // break;
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | else /* verify all including the refresh parameter */
|
|---|
| 221 | {
|
|---|
| 222 | for(i=0; i < ulTotalModes; i++)
|
|---|
| 223 | if ((ModeTable[i].usXResolution == (USHORT) ulHorRes) &&
|
|---|
| 224 | (ModeTable[i].usYResolution == (USHORT) ulVerRes) &&
|
|---|
| 225 | (ModeTable[i].bBitsPerPixel == (BYTE) ulColors) &&
|
|---|
| 226 | ((ModeTable[i].bVrtRefresh == 0xFF) ||
|
|---|
| 227 | (ModeTable[i].bVrtRefresh == (BYTE) ulVerRefr)))
|
|---|
| 228 | *pulModeInd = i;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | if (*pulModeInd == -1)
|
|---|
| 232 | return rc; /* mode not found */
|
|---|
| 233 |
|
|---|
| 234 | /* Unlock first */
|
|---|
| 235 | rc = PMI_Request (&AdapterInstance,
|
|---|
| 236 | PMIREQUEST_UNLOCKREGISTERS,
|
|---|
| 237 | NULL,
|
|---|
| 238 | NULL);
|
|---|
| 239 |
|
|---|
| 240 | /*
|
|---|
| 241 | * Copy VIDEOMODEINFO of the selected mode to AdapterInstance.
|
|---|
| 242 | * Depending on the .PMI file, this information may be needed.
|
|---|
| 243 | */
|
|---|
| 244 | AdapterInstance.ModeInfo = ModeTable[*pulModeInd];
|
|---|
| 245 | /*
|
|---|
| 246 | * Call videopmi to set the mode.
|
|---|
| 247 | */
|
|---|
| 248 | rc = PMI_Request (&AdapterInstance,
|
|---|
| 249 | PMIREQUEST_SETMODE,
|
|---|
| 250 | &ModeTable[*pulModeInd].miModeId,
|
|---|
| 251 | NULL);
|
|---|
| 252 |
|
|---|
| 253 | if (rc)
|
|---|
| 254 | return rc;
|
|---|
| 255 |
|
|---|
| 256 | else
|
|---|
| 257 | /* Load Color Lookup Table */
|
|---|
| 258 | if (ModeTable[*pulModeInd].bBitsPerPixel <= 8 && pCLUTData != NULL)
|
|---|
| 259 | rc = PMI_Request (&AdapterInstance,
|
|---|
| 260 | PMIREQUEST_SETCLUT,
|
|---|
| 261 | pCLUTData,
|
|---|
| 262 | NULL);
|
|---|
| 263 |
|
|---|
| 264 | return rc;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | //******************************************************************************
|
|---|
| 268 | //******************************************************************************
|
|---|
| 269 | ULONG SetSVGAPalette (PVOID pal) {
|
|---|
| 270 | PALETTEENTRY *pDirectXPal = (PALETTEENTRY *)pal;
|
|---|
| 271 | struct {
|
|---|
| 272 | CLUTDATA clData;
|
|---|
| 273 | SVGARGB svgaRGB[255];
|
|---|
| 274 | } clutData;
|
|---|
| 275 |
|
|---|
| 276 | ULONG i, rc;
|
|---|
| 277 |
|
|---|
| 278 | dprintf(("DDRAW-OS2FSDD: Setting physical palette\n"));
|
|---|
| 279 |
|
|---|
| 280 | /* We have to clamp down the values - physical palette only goes to 64 */
|
|---|
| 281 | /* on standard VGA */
|
|---|
| 282 | for(i = 0; i < 256; i++) {
|
|---|
| 283 | clutData.clData.aRGB[i].bR = pDirectXPal[i].peRed >> 2;
|
|---|
| 284 | clutData.clData.aRGB[i].bG = pDirectXPal[i].peGreen >> 2;
|
|---|
| 285 | clutData.clData.aRGB[i].bB = pDirectXPal[i].peBlue >> 2;
|
|---|
| 286 | clutData.clData.aRGB[i].bUnused = 0;
|
|---|
| 287 | }
|
|---|
| 288 | clutData.clData.ulRGBCount = 256;
|
|---|
| 289 | clutData.clData.ulRGBStart = 0;
|
|---|
| 290 |
|
|---|
| 291 | rc = PMI_Request (&AdapterInstance,
|
|---|
| 292 | PMIREQUEST_SETCLUT,
|
|---|
| 293 | &clutData,
|
|---|
| 294 | NULL);
|
|---|
| 295 | return rc;
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | //******************************************************************************
|
|---|
| 299 | //******************************************************************************
|
|---|
| 300 | VOID KillPM(VOID)
|
|---|
| 301 | {
|
|---|
| 302 | HAB hab;
|
|---|
| 303 | HWND hwnd;
|
|---|
| 304 | HDC hdc;
|
|---|
| 305 | ULONG rc;
|
|---|
| 306 | USHORT sel = RestoreOS2FS();
|
|---|
| 307 |
|
|---|
| 308 | hab = WinQueryAnchorBlock(HWND_DESKTOP);
|
|---|
| 309 |
|
|---|
| 310 | hwnd = WinQueryDesktopWindow(hab, NULL);
|
|---|
| 311 |
|
|---|
| 312 | // Grab the handle to the Desktop DC
|
|---|
| 313 | hdc = WinOpenWindowDC(hwnd);
|
|---|
| 314 |
|
|---|
| 315 | dprintf(("*** Killing the PM screen ***"));
|
|---|
| 316 |
|
|---|
| 317 | // Call GreDeath
|
|---|
| 318 | rc=GreDeath(hdc);
|
|---|
| 319 |
|
|---|
| 320 | SetFS(sel);
|
|---|
| 321 |
|
|---|
| 322 | // Set a flag so that a subsequent restore works
|
|---|
| 323 | bIsInFS = TRUE;
|
|---|
| 324 |
|
|---|
| 325 | dprintf(("GreDeath() rc= %x",rc));
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | //******************************************************************************
|
|---|
| 329 | //******************************************************************************
|
|---|
| 330 | VOID RestorePM(VOID)
|
|---|
| 331 | {
|
|---|
| 332 | HAB hab;
|
|---|
| 333 | HWND hwnd;
|
|---|
| 334 | HDC hdc;
|
|---|
| 335 | ULONG rc;
|
|---|
| 336 | USHORT sel = RestoreOS2FS();
|
|---|
| 337 |
|
|---|
| 338 | // Bail out if we aren't in FS mode
|
|---|
| 339 | if (!bIsInFS) {
|
|---|
| 340 | SetFS(sel);
|
|---|
| 341 | return;
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | // Get the anchor block
|
|---|
| 345 | hab = WinQueryAnchorBlock(HWND_DESKTOP);
|
|---|
| 346 |
|
|---|
| 347 | // Get the window handle to the Desktop
|
|---|
| 348 | hwnd = WinQueryDesktopWindow(hab, NULL);
|
|---|
| 349 |
|
|---|
| 350 | // Grab the handle to the Desktop DC
|
|---|
| 351 | hdc = WinQueryWindowDC(hwnd);
|
|---|
| 352 |
|
|---|
| 353 | dprintf(("*** Restore the PM screen ***"));
|
|---|
| 354 |
|
|---|
| 355 | rc=GreResurrection(hdc, 0L, NULL);
|
|---|
| 356 |
|
|---|
| 357 | // Repaint the desktop
|
|---|
| 358 | WinInvalidateRect(hwnd, NULL, TRUE);
|
|---|
| 359 |
|
|---|
| 360 | // Set a flag so that we know we're back in PM
|
|---|
| 361 | bIsInFS = FALSE;
|
|---|
| 362 |
|
|---|
| 363 | SetFS(sel);
|
|---|
| 364 | dprintf(("GreResurrection() rc=%x",rc));
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | //******************************************************************************
|
|---|
| 368 | //******************************************************************************
|
|---|
| 369 | BOOL ModeInSVGAModeTable(ULONG resX,ULONG resY, ULONG bpp)
|
|---|
| 370 | {
|
|---|
| 371 | int i;
|
|---|
| 372 | for (i=0;i<ulTotalModes;i++)
|
|---|
| 373 | {
|
|---|
| 374 | if ((ModeTable[i].usXResolution==resX) &&
|
|---|
| 375 | (ModeTable[i].usYResolution==resY) &&
|
|---|
| 376 | (ModeTable[i].bBitsPerPixel==bpp)) return TRUE;
|
|---|
| 377 | }
|
|---|
| 378 | return FALSE;
|
|---|
| 379 | }
|
|---|