source: trunk/src/ddraw/os2fsdd.cpp@ 21916

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

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