11 #include "../vgavideo/vgavideo.h"
15 #define DBG_PREFIX "VGADDI: "
17 static BOOL VGAInitialized = FALSE;
21 /* Required Display driver fuctions */
22 {INDEX_DrvAssertMode, (PFN) DrvAssertMode},
23 {INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV},
24 {INDEX_DrvCopyBits, (PFN) DrvCopyBits},
25 {INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV},
26 {INDEX_DrvDisableSurface, (PFN) DrvDisableSurface},
27 {INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV},
28 {INDEX_DrvEnableSurface, (PFN) DrvEnableSurface},
29 {INDEX_DrvGetModes, (PFN) DrvGetModes},
30 {INDEX_DrvLineTo, (PFN) DrvLineTo},
31 {INDEX_DrvPaint, (PFN) DrvPaint},
32 {INDEX_DrvBitBlt, (PFN) DrvBitBlt},
33 {INDEX_DrvTransparentBlt, (PFN) DrvTransparentBlt},
34 {INDEX_DrvMovePointer, (PFN) DrvMovePointer},
35 {INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape},
38 /* Optional Display driver functions */
40 {INDEX_DescribePixelFormat, (PFN) VGADDIDescribePixelFormat},
41 {INDEX_DrvDitherColor, (PFN) VGADDIDitherColor},
42 {INDEX_DrvFillPath, (PFN) VGADDIFillPath},
43 {INDEX_DrvGetTrueTypeFile, (PFN) VGADDIGetTrueTypeFile},
44 {INDEX_DrvLoadFontFile, (PFN) VGADDILoadFontFile},
45 {INDEX_DrvQueryFont, (PFN) VGADDIQueryFont},
46 {INDEX_DrvQueryFontCaps, (PFN) VGADDIQueryFontCaps},
47 {INDEX_DrvQueryFontData, (PFN) VGADDIQueryFontData},
48 {INDEX_DrvQueryFontFile, (PFN) VGADDIQueryFontFile},
49 {INDEX_DrvQueryFontTree, (PFN) VGADDIQueryFontTree},
50 {INDEX_DrvQueryTrueTypeOutline, (PFN) VGADDIQueryTrueTypeOutline},
51 {INDEX_DrvQueryTrueTypeTable, (PFN) VGADDIQueryTrueTypeTable},
52 {INDEX_DrvRealizeBrush, (PFN) VGADDIRealizeBrush},
53 {INDEX_DrvResetPDEV, (PFN) VGADDIResetPDEV},
54 {INDEX_DrvSetPalette, (PFN) VGADDISetPalette},
55 {INDEX_DrvSetPixelFormat, (PFN) VGADDISetPixelFormat},
56 {INDEX_DrvStretchBlt, (PFN) VGADDIStretchBlt},
57 {INDEX_DrvStrokePath, (PFN) VGADDIStrokePath},
58 {INDEX_DrvSwapBuffers, (PFN) VGADDISwapBuffers},
59 {INDEX_DrvTextOut, (PFN) VGADDITextOut},
60 {INDEX_DrvUnloadFontFile, (PFN) VGADDIUnloadFontFile},
66 DrvEnableDriver(IN ULONG EngineVersion,
68 OUT PDRVENABLEDATA DriveEnableData)
70 EngDebugPrint("VGADDI", "DrvEnableDriver called...\n", 0);
74 // FIXME: Use Vidport to map the memory properly
75 vidmem = (char *)(0xd0000000 + 0xa0000);
77 VGADDI_InitializeOffScreenMem((640 * 480) >> 3, 65536 - ((640 * 480) >> 3));
79 DriveEnableData->pdrvfn = FuncList;
80 DriveEnableData->c = sizeof(FuncList) / sizeof(DRVFN);
81 DriveEnableData->iDriverVersion = DDI_DRIVER_VERSION;
88 // This function is called by the KMGDI at exit. It should cleanup.
95 DrvDisableDriver(VOID)
100 // ----------------------------------------------- Driver Implementation
105 // This function is called after DrvEnableDriver to get information
106 // about the mode that is to be used. This function just returns
107 // information, and should not yet initialize the mode.
109 // IN DEVMODEW * DM Describes the mode requested
110 // IN LPWSTR LogAddress
111 // IN ULONG PatternCount number of patterns expected
112 // OUT HSURF * SurfPatterns array to contain pattern handles
113 // IN ULONG CapsSize the size of the DevCaps object passed in
114 // OUT ULONG * DevCaps Device Capabilities object
115 // IN ULONG DevInfoSize the size of the DevInfo object passed in
116 // OUT DEVINFO * DI Device Info object
117 // IN LPWSTR DevDataFile ignore
118 // IN LPWSTR DeviceName Device name
119 // IN HANDLE Driver handle to KM driver
121 // DHPDEV a handle to a DPev object
124 DrvEnablePDEV(IN DEVMODEW *DM,
125 IN LPWSTR LogAddress,
126 IN ULONG PatternCount,
127 OUT HSURF *SurfPatterns,
130 IN ULONG DevInfoSize,
132 IN LPWSTR DevDataFile,
133 IN LPWSTR DeviceName,
138 PDev = EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
141 EngDebugPrint(DBG_PREFIX, "EngAllocMem failed for PDEV\n", 0);
144 PDev->KMDriver = Driver;
145 DPRINT( "PDev: %x, Driver: %x\n", PDev, PDev->KMDriver );
146 PDev->xyCursor.x = 320;
147 PDev->xyCursor.y = 240;
148 PDev->ptlExtent.x = 0;
149 PDev->ptlExtent.y = 0;
151 PDev->flCursor = CURSOR_DOWN;
152 // FIXME: fill out DevCaps
153 // FIXME: full out DevInfo
155 devinfoVGA.hpalDefault = EngCreatePalette(PAL_INDEXED, 16, (PULONG *)VGApalette.PaletteEntry, 0, 0, 0);
156 DPRINT("Palette from Driver: %u\n", devinfoVGA.hpalDefault);
158 DPRINT("Palette from Driver 2: %u and DI is %08x\n", DI->hpalDefault, DI);
166 // Called after initialization of PDEV is complete. Supplies
167 // a reference to the GDI handle for the PDEV.
170 DrvCompletePDEV(IN DHPDEV PDev,
173 ((PPDEV) PDev)->GDIDevHandle = Dev; // Handle to the DC
178 DrvAssertMode(IN DHPDEV DPev,
181 PPDEV ppdev = (PPDEV)DPev;
182 ULONG returnedDataLength;
186 // Reenable our graphics mode
188 if (!InitPointer(ppdev))
190 // Failed to set pointer
196 if (!InitVGA(ppdev, FALSE))
198 // Failed to initialize the VGA
201 VGAInitialized = TRUE;
204 // Go back to last known mode
205 DPRINT( "ppdev: %x, KMDriver: %x", ppdev, ppdev->KMDriver );
206 if (EngDeviceIoControl(ppdev->KMDriver, IOCTL_VIDEO_RESET_DEVICE, NULL, 0, NULL, 0, &returnedDataLength))
208 // Failed to go back to mode
211 VGAInitialized = FALSE;
218 DrvDisablePDEV(IN DHPDEV PDev)
220 PPDEV ppdev = (PPDEV)PDev;
\r
222 // EngDeletePalette(devinfoVGA.hpalDefault);
223 if (ppdev->pjPreallocSSBBuffer != NULL)
225 EngFreeMem(ppdev->pjPreallocSSBBuffer);
228 if (ppdev->pucDIB4ToVGAConvBuffer != NULL)
230 EngFreeMem(ppdev->pucDIB4ToVGAConvBuffer);
232 DPRINT( "Freeing PDEV\n" );
238 DrvDisableSurface(IN DHPDEV PDev)
240 PPDEV ppdev = (PPDEV)PDev;
241 PDEVSURF pdsurf = ppdev->AssociatedSurf;
242 PSAVED_SCREEN_BITS pSSB, pSSBNext;
244 DPRINT( "KMDriver: %x\n", ppdev->KMDriver );
245 // EngFreeMem(pdsurf->BankSelectInfo);
247 if (pdsurf->BankInfo != NULL) {
248 EngFreeMem(pdsurf->BankInfo);
251 if (pdsurf->BankInfo2RW != NULL) {
252 EngFreeMem(pdsurf->BankInfo2RW);
255 if (pdsurf->BankBufferPlane0 != NULL) {
256 EngFreeMem(pdsurf->BankBufferPlane0);
259 if (ppdev->pPointerAttributes != NULL) {
260 EngFreeMem(ppdev->pPointerAttributes);
263 // free any pending saved screen bit blocks
265 pSSB = pdsurf->ssbList;
266 while (pSSB != (PSAVED_SCREEN_BITS) NULL) {
268 // Point to the next saved screen bits block
269 pSSBNext = (PSAVED_SCREEN_BITS) pSSB->pvNextSSB;
271 // Free the current block
276 EngDeleteSurface((HSURF) ppdev->SurfHandle);
277 // EngFreeMem(pdsurf); // free the surface
282 InitSavedBits(PPDEV ppdev)
284 if (!(ppdev->fl & DRIVER_OFFSCREEN_REFRESHED))
289 // set up rect to right of visible screen
290 ppdev->SavedBitsRight.left = ppdev->sizeSurf.cx;
291 ppdev->SavedBitsRight.top = 0;
292 ppdev->SavedBitsRight.right = ppdev->sizeMem.cx-PLANAR_PELS_PER_CPU_ADDRESS;
293 ppdev->SavedBitsRight.bottom = ppdev->sizeSurf.cy;
295 if ((ppdev->SavedBitsRight.right <= ppdev->SavedBitsRight.left) ||
296 (ppdev->SavedBitsRight.bottom <= ppdev->SavedBitsRight.top))
298 ppdev->SavedBitsRight.left = 0;
299 ppdev->SavedBitsRight.top = 0;
300 ppdev->SavedBitsRight.right = 0;
301 ppdev->SavedBitsRight.bottom = 0;
304 // set up rect below visible screen
305 ppdev->SavedBitsBottom.left = 0;
306 ppdev->SavedBitsBottom.top = ppdev->sizeSurf.cy;
307 ppdev->SavedBitsBottom.right = ppdev->sizeMem.cx-PLANAR_PELS_PER_CPU_ADDRESS;
308 ppdev->SavedBitsBottom.bottom = ppdev->sizeMem.cy - ppdev->NumScansUsedByPointer;
310 if ((ppdev->SavedBitsBottom.right <= ppdev->SavedBitsBottom.left) ||
311 (ppdev->SavedBitsBottom.bottom <= ppdev->SavedBitsBottom.top))
313 ppdev->SavedBitsBottom.left = 0;
314 ppdev->SavedBitsBottom.top = 0;
315 ppdev->SavedBitsBottom.right = 0;
316 ppdev->SavedBitsBottom.bottom = 0;
319 ppdev->BitsSaved = FALSE;
326 DrvEnableSurface(IN DHPDEV PDev)
328 PPDEV ppdev = (PPDEV)PDev;
333 DPRINT1("DrvEnableSurface() called\n");
335 // Initialize the VGA
338 if (!InitVGA(ppdev, TRUE))
342 VGAInitialized = TRUE;
346 // dhsurf is of type DEVSURF, which is the drivers specialized surface type
347 dhsurf = (DHSURF)EngAllocMem(0, sizeof(DEVSURF), ALLOC_TAG);
348 if (dhsurf == (DHSURF) 0)
353 pdsurf = (PDEVSURF) dhsurf;
354 pdsurf->ident = DEVSURF_IDENT;
356 pdsurf->Format = BMF_PHYSDEVICE;
357 pdsurf->jReserved1 = 0;
358 pdsurf->jReserved2 = 0;
359 pdsurf->ppdev = ppdev;
360 pdsurf->sizeSurf.cx = ppdev->sizeSurf.cx;
361 pdsurf->sizeSurf.cy = ppdev->sizeSurf.cy;
362 pdsurf->NextPlane = 0;
363 pdsurf->Scan0 = ppdev->fbScreen;
364 pdsurf->BitmapStart = ppdev->fbScreen;
365 pdsurf->StartBmp = ppdev->fbScreen;
367 /* pdsurf->Conv = &ConvertBuffer[0]; */
369 if (!InitPointer(ppdev)) {
370 DbgPrint("DrvEnablePDEV failed bInitPointer\n");
374 /* if (!SetUpBanking(pdsurf, ppdev)) {
375 DISPDBG((0, "DrvEnablePDEV failed SetUpBanking\n"));
377 } BANKING CODE UNIMPLEMENTED */
379 if ((hsurf = EngCreateDeviceSurface(dhsurf, ppdev->sizeSurf, BMF_4BPP)) ==
382 // Call to EngCreateDeviceSurface failed
383 EngDebugPrint("VGADDI:", "EngCreateDeviceSurface call failed\n", 0);
387 InitSavedBits(ppdev);
389 if (EngAssociateSurface(hsurf, ppdev->GDIDevHandle, HOOK_BITBLT | HOOK_PAINT | HOOK_LINETO | HOOK_COPYBITS |
390 HOOK_TRANSPARENTBLT))
392 EngDebugPrint("VGADDI:", "Successfully associated surface\n", 0);
393 ppdev->SurfHandle = hsurf;
394 ppdev->AssociatedSurf = pdsurf;
396 // Set up an empty saved screen block list
397 pdsurf->ssbList = NULL;
401 DPRINT( "EngAssociateSurface() failed\n" );
402 EngDeleteSurface(hsurf);
413 DrvGetModes(IN HANDLE Driver,
420 DWORD OutputModes = DataSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
421 PVIDEO_MODE_INFORMATION VideoModeInformation, VideoTemp;
423 NumModes = getAvailableModes(Driver,
424 (PVIDEO_MODE_INFORMATION *) &VideoModeInformation,
434 OutputSize = NumModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
438 VideoTemp = VideoModeInformation;
442 if (VideoTemp->Length != 0)
444 if (OutputModes == 0)
449 memset(DM, 0, sizeof(DEVMODEW));
450 memcpy(DM->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
452 DM->dmSpecVersion = DM_SPECVERSION;
453 DM->dmDriverVersion = DM_SPECVERSION;
454 DM->dmSize = sizeof(DEVMODEW);
455 DM->dmDriverExtra = DRIVER_EXTRA_SIZE;
456 DM->dmBitsPerPel = VideoTemp->NumberOfPlanes *
457 VideoTemp->BitsPerPlane;
458 DM->dmPelsWidth = VideoTemp->VisScreenWidth;
459 DM->dmPelsHeight = VideoTemp->VisScreenHeight;
460 DM->dmDisplayFrequency = VideoTemp->Frequency;
461 DM->dmDisplayFlags = 0;
463 DM->dmFields = DM_BITSPERPEL |
466 DM_DISPLAYFREQUENCY |
469 // next DEVMODE entry
472 DM = (PDEVMODEW) ( ((ULONG)DM) + sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
474 OutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
477 VideoTemp = (PVIDEO_MODE_INFORMATION)(((PUCHAR)VideoTemp) + ModeSize);
479 } while (--NumModes);