11 #include "../vgavideo/vgavideo.h"
14 #define DBG_PREFIX "VGADDI: "
16 static BOOL VGAInitialized = FALSE;
20 /* Required Display driver fuctions */
21 {INDEX_DrvAssertMode, (PFN) DrvAssertMode},
22 {INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV},
23 {INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV},
24 {INDEX_DrvDisableSurface, (PFN) DrvDisableSurface},
25 {INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV},
26 {INDEX_DrvEnableSurface, (PFN) DrvEnableSurface},
27 {INDEX_DrvGetModes, (PFN) DrvGetModes},
28 {INDEX_DrvLineTo, (PFN) DrvLineTo},
29 {INDEX_DrvPaint, (PFN) DrvPaint},
30 {INDEX_DrvBitBlt, (PFN) DrvBitBlt},
31 {INDEX_DrvTransparentBlt, (PFN) DrvTransparentBlt},
32 {INDEX_DrvMovePointer, (PFN) DrvMovePointer},
33 {INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape},
36 /* Optional Display driver functions */
38 {INDEX_DescribePixelFormat, (PFN) VGADDIDescribePixelFormat},
39 {INDEX_DrvDitherColor, (PFN) VGADDIDitherColor},
40 {INDEX_DrvFillPath, (PFN) VGADDIFillPath},
41 {INDEX_DrvGetTrueTypeFile, (PFN) VGADDIGetTrueTypeFile},
42 {INDEX_DrvLoadFontFile, (PFN) VGADDILoadFontFile},
43 {INDEX_DrvQueryFont, (PFN) VGADDIQueryFont},
44 {INDEX_DrvQueryFontCaps, (PFN) VGADDIQueryFontCaps},
45 {INDEX_DrvQueryFontData, (PFN) VGADDIQueryFontData},
46 {INDEX_DrvQueryFontFile, (PFN) VGADDIQueryFontFile},
47 {INDEX_DrvQueryFontTree, (PFN) VGADDIQueryFontTree},
48 {INDEX_DrvQueryTrueTypeOutline, (PFN) VGADDIQueryTrueTypeOutline},
49 {INDEX_DrvQueryTrueTypeTable, (PFN) VGADDIQueryTrueTypeTable},
50 {INDEX_DrvRealizeBrush, (PFN) VGADDIRealizeBrush},
51 {INDEX_DrvResetPDEV, (PFN) VGADDIResetPDEV},
52 {INDEX_DrvSetPalette, (PFN) VGADDISetPalette},
53 {INDEX_DrvSetPixelFormat, (PFN) VGADDISetPixelFormat},
54 {INDEX_DrvStretchBlt, (PFN) VGADDIStretchBlt},
55 {INDEX_DrvStrokePath, (PFN) VGADDIStrokePath},
56 {INDEX_DrvSwapBuffers, (PFN) VGADDISwapBuffers},
57 {INDEX_DrvTextOut, (PFN) VGADDITextOut},
58 {INDEX_DrvUnloadFontFile, (PFN) VGADDIUnloadFontFile},
64 DrvEnableDriver(IN ULONG EngineVersion,
66 OUT PDRVENABLEDATA DriveEnableData)
68 EngDebugPrint("VGADDI", "DrvEnableDriver called...\n", 0);
72 // FIXME: Use Vidport to map the memory properly
73 vidmem = (char *)(0xd0000000 + 0xa0000);
75 VGADDI_InitializeOffScreenMem((640 * 480) >> 3, 65536 - ((640 * 480) >> 3));
77 DriveEnableData->pdrvfn = FuncList;
78 DriveEnableData->c = sizeof(FuncList) / sizeof(DRVFN);
79 DriveEnableData->iDriverVersion = DDI_DRIVER_VERSION;
86 // This function is called by the KMGDI at exit. It should cleanup.
93 DrvDisableDriver(VOID)
98 // ----------------------------------------------- Driver Implementation
103 // This function is called after DrvEnableDriver to get information
104 // about the mode that is to be used. This function just returns
105 // information, and should not yet initialize the mode.
107 // IN DEVMODEW * DM Describes the mode requested
108 // IN LPWSTR LogAddress
109 // IN ULONG PatternCount number of patterns expected
110 // OUT HSURF * SurfPatterns array to contain pattern handles
111 // IN ULONG CapsSize the size of the DevCaps object passed in
112 // OUT ULONG * DevCaps Device Capabilities object
113 // IN ULONG DevInfoSize the size of the DevInfo object passed in
114 // OUT DEVINFO * DI Device Info object
115 // IN LPWSTR DevDataFile ignore
116 // IN LPWSTR DeviceName Device name
117 // IN HANDLE Driver handle to KM driver
119 // DHPDEV a handle to a DPev object
122 DrvEnablePDEV(IN DEVMODEW *DM,
123 IN LPWSTR LogAddress,
124 IN ULONG PatternCount,
125 OUT HSURF *SurfPatterns,
128 IN ULONG DevInfoSize,
130 IN LPWSTR DevDataFile,
131 IN LPWSTR DeviceName,
136 PDev = EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
139 EngDebugPrint(DBG_PREFIX, "EngAllocMem failed for PDEV\n", 0);
142 PDev->KMDriver = Driver;
143 DPRINT( "PDev: %x, Driver: %x\n", PDev, PDev->KMDriver );
144 PDev->xyCursor.x = 320;
145 PDev->xyCursor.y = 240;
146 PDev->ptlExtent.x = 0;
147 PDev->ptlExtent.y = 0;
149 PDev->flCursor = CURSOR_DOWN;
150 // FIXME: fill out DevCaps
151 // FIXME: full out DevInfo
153 devinfoVGA.hpalDefault = EngCreatePalette(PAL_INDEXED, 16, (PULONG *)VGApalette.PaletteEntry, 0, 0, 0);
154 DPRINT("Palette from Driver: %u\n", devinfoVGA.hpalDefault);
156 DPRINT("Palette from Driver 2: %u and DI is %08x\n", DI->hpalDefault, DI);
164 // Called after initialization of PDEV is complete. Supplies
165 // a reference to the GDI handle for the PDEV.
168 DrvCompletePDEV(IN DHPDEV PDev,
171 ((PPDEV) PDev)->GDIDevHandle = Dev; // Handle to the DC
176 DrvAssertMode(IN DHPDEV DPev,
179 PPDEV ppdev = (PPDEV)DPev;
180 ULONG returnedDataLength;
184 // Reenable our graphics mode
186 if (!InitPointer(ppdev))
188 // Failed to set pointer
194 if (!InitVGA(ppdev, FALSE))
196 // Failed to initialize the VGA
199 VGAInitialized = TRUE;
202 // Go back to last known mode
203 DPRINT( "ppdev: %x, KMDriver: %x", ppdev, ppdev->KMDriver );
204 if (EngDeviceIoControl(ppdev->KMDriver, IOCTL_VIDEO_RESET_DEVICE, NULL, 0, NULL, 0, &returnedDataLength))
206 // Failed to go back to mode
209 VGAInitialized = FALSE;
216 DrvDisablePDEV(IN DHPDEV PDev)
218 PPDEV ppdev = (PPDEV)PDev;
\r
220 // EngDeletePalette(devinfoVGA.hpalDefault);
221 if (ppdev->pjPreallocSSBBuffer != NULL)
223 EngFreeMem(ppdev->pjPreallocSSBBuffer);
226 if (ppdev->pucDIB4ToVGAConvBuffer != NULL)
228 EngFreeMem(ppdev->pucDIB4ToVGAConvBuffer);
230 DPRINT( "Freeing PDEV\n" );
236 DrvDisableSurface(IN DHPDEV PDev)
238 PPDEV ppdev = (PPDEV)PDev;
239 PDEVSURF pdsurf = ppdev->AssociatedSurf;
240 PSAVED_SCREEN_BITS pSSB, pSSBNext;
242 DPRINT( "KMDriver: %x\n", ppdev->KMDriver );
243 // EngFreeMem(pdsurf->BankSelectInfo);
245 if (pdsurf->BankInfo != NULL) {
246 EngFreeMem(pdsurf->BankInfo);
249 if (pdsurf->BankInfo2RW != NULL) {
250 EngFreeMem(pdsurf->BankInfo2RW);
253 if (pdsurf->BankBufferPlane0 != NULL) {
254 EngFreeMem(pdsurf->BankBufferPlane0);
257 if (ppdev->pPointerAttributes != NULL) {
258 EngFreeMem(ppdev->pPointerAttributes);
261 // free any pending saved screen bit blocks
263 pSSB = pdsurf->ssbList;
264 while (pSSB != (PSAVED_SCREEN_BITS) NULL) {
266 // Point to the next saved screen bits block
267 pSSBNext = (PSAVED_SCREEN_BITS) pSSB->pvNextSSB;
269 // Free the current block
274 EngDeleteSurface((HSURF) ppdev->SurfHandle);
275 // EngFreeMem(pdsurf); // free the surface
280 InitSavedBits(PPDEV ppdev)
282 if (!(ppdev->fl & DRIVER_OFFSCREEN_REFRESHED))
287 // set up rect to right of visible screen
288 ppdev->SavedBitsRight.left = ppdev->sizeSurf.cx;
289 ppdev->SavedBitsRight.top = 0;
290 ppdev->SavedBitsRight.right = ppdev->sizeMem.cx-PLANAR_PELS_PER_CPU_ADDRESS;
291 ppdev->SavedBitsRight.bottom = ppdev->sizeSurf.cy;
293 if ((ppdev->SavedBitsRight.right <= ppdev->SavedBitsRight.left) ||
294 (ppdev->SavedBitsRight.bottom <= ppdev->SavedBitsRight.top))
296 ppdev->SavedBitsRight.left = 0;
297 ppdev->SavedBitsRight.top = 0;
298 ppdev->SavedBitsRight.right = 0;
299 ppdev->SavedBitsRight.bottom = 0;
302 // set up rect below visible screen
303 ppdev->SavedBitsBottom.left = 0;
304 ppdev->SavedBitsBottom.top = ppdev->sizeSurf.cy;
305 ppdev->SavedBitsBottom.right = ppdev->sizeMem.cx-PLANAR_PELS_PER_CPU_ADDRESS;
306 ppdev->SavedBitsBottom.bottom = ppdev->sizeMem.cy - ppdev->NumScansUsedByPointer;
308 if ((ppdev->SavedBitsBottom.right <= ppdev->SavedBitsBottom.left) ||
309 (ppdev->SavedBitsBottom.bottom <= ppdev->SavedBitsBottom.top))
311 ppdev->SavedBitsBottom.left = 0;
312 ppdev->SavedBitsBottom.top = 0;
313 ppdev->SavedBitsBottom.right = 0;
314 ppdev->SavedBitsBottom.bottom = 0;
317 ppdev->BitsSaved = FALSE;
324 DrvEnableSurface(IN DHPDEV PDev)
326 PPDEV ppdev = (PPDEV)PDev;
331 DPRINT1("DrvEnableSurface() called\n");
333 // Initialize the VGA
336 if (!InitVGA(ppdev, TRUE))
340 VGAInitialized = TRUE;
344 // dhsurf is of type DEVSURF, which is the drivers specialized surface type
345 dhsurf = (DHSURF)EngAllocMem(0, sizeof(DEVSURF), ALLOC_TAG);
346 if (dhsurf == (DHSURF) 0)
351 pdsurf = (PDEVSURF) dhsurf;
352 pdsurf->ident = DEVSURF_IDENT;
354 pdsurf->Format = BMF_PHYSDEVICE;
355 pdsurf->jReserved1 = 0;
356 pdsurf->jReserved2 = 0;
357 pdsurf->ppdev = ppdev;
358 pdsurf->sizeSurf.cx = ppdev->sizeSurf.cx;
359 pdsurf->sizeSurf.cy = ppdev->sizeSurf.cy;
360 pdsurf->NextPlane = 0;
361 pdsurf->Scan0 = ppdev->fbScreen;
362 pdsurf->BitmapStart = ppdev->fbScreen;
363 pdsurf->StartBmp = ppdev->fbScreen;
365 /* pdsurf->Conv = &ConvertBuffer[0]; */
367 if (!InitPointer(ppdev)) {
368 DbgPrint("DrvEnablePDEV failed bInitPointer\n");
372 /* if (!SetUpBanking(pdsurf, ppdev)) {
373 DISPDBG((0, "DrvEnablePDEV failed SetUpBanking\n"));
375 } BANKING CODE UNIMPLEMENTED */
377 if ((hsurf = EngCreateDeviceSurface(dhsurf, ppdev->sizeSurf, BMF_4BPP)) ==
380 // Call to EngCreateDeviceSurface failed
381 EngDebugPrint("VGADDI:", "EngCreateDeviceSurface call failed\n", 0);
385 InitSavedBits(ppdev);
387 if (EngAssociateSurface(hsurf, ppdev->GDIDevHandle, HOOK_BITBLT | HOOK_PAINT | HOOK_LINETO | HOOK_COPYBITS |
388 HOOK_TRANSPARENTBLT))
390 EngDebugPrint("VGADDI:", "Successfully associated surface\n", 0);
391 ppdev->SurfHandle = hsurf;
392 ppdev->AssociatedSurf = pdsurf;
394 // Set up an empty saved screen block list
395 pdsurf->ssbList = NULL;
399 DPRINT( "EngAssociateSurface() failed\n" );
400 EngDeleteSurface(hsurf);
411 DrvGetModes(IN HANDLE Driver,
418 DWORD OutputModes = DataSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
419 PVIDEO_MODE_INFORMATION VideoModeInformation, VideoTemp;
421 NumModes = getAvailableModes(Driver,
422 (PVIDEO_MODE_INFORMATION *) &VideoModeInformation,
432 OutputSize = NumModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
436 VideoTemp = VideoModeInformation;
440 if (VideoTemp->Length != 0)
442 if (OutputModes == 0)
447 memset(DM, 0, sizeof(DEVMODEW));
448 memcpy(DM->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
450 DM->dmSpecVersion = DM_SPECVERSION;
451 DM->dmDriverVersion = DM_SPECVERSION;
452 DM->dmSize = sizeof(DEVMODEW);
453 DM->dmDriverExtra = DRIVER_EXTRA_SIZE;
454 DM->dmBitsPerPel = VideoTemp->NumberOfPlanes *
455 VideoTemp->BitsPerPlane;
456 DM->dmPelsWidth = VideoTemp->VisScreenWidth;
457 DM->dmPelsHeight = VideoTemp->VisScreenHeight;
458 DM->dmDisplayFrequency = VideoTemp->Frequency;
459 DM->dmDisplayFlags = 0;
461 DM->dmFields = DM_BITSPERPEL |
464 DM_DISPLAYFREQUENCY |
467 // next DEVMODE entry
470 DM = (PDEVMODEW) ( ((ULONG)DM) + sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
472 OutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
475 VideoTemp = (PVIDEO_MODE_INFORMATION)(((PUCHAR)VideoTemp) + ModeSize);
477 } while (--NumModes);