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

Last change on this file since 6496 was 5330, checked in by mike, 24 years ago

Forgot to add these files yesterday...

File size: 10.0 KB
Line 
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 */
21typedef 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
35char PMIFILE[256] = "\\os2\\svgadata.pmi";
36
37/*
38 * Adapter instance.
39 */
40VIDEO_ADAPTER AdapterInstance;
41
42/*
43 * Entry point to videopmi
44 */
45PFNVIDEOPMIREQUEST __pfnPMIRequest;
46
47//
48// mode table. It is an array of VIDEOMODEINFOs.
49//
50static PVIDEOMODEINFO ModeTable;
51
52static ULONG ulTotalModes;
53
54static bIsInFS = FALSE;
55
56/*
57 * PMI request wrapper
58 */
59inline 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
78ULONG 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 ************************************************************/
140ULONG 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
173ULONG 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
195ULONG 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
265 return rc;
266}
267
268//******************************************************************************
269//******************************************************************************
270ULONG SetSVGAPalette (PVOID pal) {
271 PALETTEENTRY *pDirectXPal = (PALETTEENTRY *)pal;
272 struct {
273 CLUTDATA clData;
274 SVGARGB svgaRGB[255];
275 } clutData;
276
277 ULONG i, rc;
278
279 dprintf(("DDRAW-OS2FSDD: Setting physical palette\n"));
280
281 /* We have to clamp down the values - physical palette only goes to 64 */
282 /* on standard VGA */
283 for(i = 0; i < 256; i++) {
284 clutData.clData.aRGB[i].bR = pDirectXPal[i].peRed >> 2;
285 clutData.clData.aRGB[i].bG = pDirectXPal[i].peGreen >> 2;
286 clutData.clData.aRGB[i].bB = pDirectXPal[i].peBlue >> 2;
287 clutData.clData.aRGB[i].bUnused = 0;
288 }
289 clutData.clData.ulRGBCount = 256;
290 clutData.clData.ulRGBStart = 0;
291
292 rc = PMI_Request (&AdapterInstance,
293 PMIREQUEST_SETCLUT,
294 &clutData,
295 NULL);
296 return rc;
297}
298
299//******************************************************************************
300//******************************************************************************
301VOID KillPM(VOID)
302{
303 HAB hab;
304 HWND hwnd;
305 HDC hdc;
306 ULONG rc;
307 USHORT sel = RestoreOS2FS();
308
309 hab = WinQueryAnchorBlock(HWND_DESKTOP);
310
311 hwnd = WinQueryDesktopWindow(hab, NULL);
312
313 // Grab the handle to the Desktop DC
314 hdc = WinOpenWindowDC(hwnd);
315
316 dprintf(("*** Killing the PM screen ***"));
317
318 // Call GreDeath
319 rc=GreDeath(hdc);
320
321 SetFS(sel);
322
323 // Set a flag so that a subsequent restore works
324 bIsInFS = TRUE;
325
326 dprintf(("GreDeath() rc= %x",rc));
327}
328
329//******************************************************************************
330//******************************************************************************
331VOID RestorePM(VOID)
332{
333 HAB hab;
334 HWND hwnd;
335 HDC hdc;
336 ULONG rc;
337 USHORT sel = RestoreOS2FS();
338
339 // Bail out if we aren't in FS mode
340 if (!bIsInFS) {
341 SetFS(sel);
342 return;
343 }
344
345 // Get the anchor block
346 hab = WinQueryAnchorBlock(HWND_DESKTOP);
347
348 // Get the window handle to the Desktop
349 hwnd = WinQueryDesktopWindow(hab, NULL);
350
351 // Grab the handle to the Desktop DC
352 hdc = WinQueryWindowDC(hwnd);
353
354 dprintf(("*** Restore the PM screen ***"));
355
356 rc=GreResurrection(hdc, 0L, NULL);
357
358 // Repaint the desktop
359 WinInvalidateRect(hwnd, NULL, TRUE);
360
361 // Set a flag so that we know we're back in PM
362 bIsInFS = FALSE;
363
364 SetFS(sel);
365 dprintf(("GreResurrection() rc=%x",rc));
366}
367
368//******************************************************************************
369//******************************************************************************
370BOOL ModeInSVGAModeTable(ULONG resX,ULONG resY, ULONG bpp)
371{
372 int i;
373 for (i=0;i<ulTotalModes;i++)
374 {
375 if ((ModeTable[i].usXResolution==resX) &&
376 (ModeTable[i].usYResolution==resY) &&
377 (ModeTable[i].bBitsPerPixel==bpp)) return TRUE;
378 }
379 return FALSE;
380}
Note: See TracBrowser for help on using the repository browser.