1 #ifndef _VGADDI_PCH_ 2 #define _VGADDI_PCH_ 3 4 #define _WINBASE_ 5 #define _WINDOWS_H 6 #include <stdarg.h> 7 #include <windef.h> 8 #include <wingdi.h> 9 #include <winddi.h> 10 #include <winioctl.h> 11 #include <ntddvdeo.h> 12 #include <ioaccess.h> 13 14 #include "vgavideo/vgavideo.h" 15 16 #ifndef NDEBUG 17 #define DPRINT DbgPrint 18 #else 19 #define DPRINT 20 #endif 21 #define DPRINT1 DbgPrint 22 23 /* FIXME - what a headers mess.... */ 24 25 #define DDKFASTAPI __fastcall 26 #define FASTCALL __fastcall 27 28 ULONG DbgPrint(PCCH Format,...); 29 30 static __inline BOOLEAN 31 RemoveEntryList( 32 IN PLIST_ENTRY Entry) 33 { 34 PLIST_ENTRY OldFlink; 35 PLIST_ENTRY OldBlink; 36 37 OldFlink = Entry->Flink; 38 OldBlink = Entry->Blink; 39 OldFlink->Blink = OldBlink; 40 OldBlink->Flink = OldFlink; 41 return (OldFlink == OldBlink); 42 } 43 44 static __inline VOID 45 InsertHeadList( 46 IN PLIST_ENTRY ListHead, 47 IN PLIST_ENTRY Entry) 48 { 49 PLIST_ENTRY OldFlink; 50 OldFlink = ListHead->Flink; 51 Entry->Flink = OldFlink; 52 Entry->Blink = ListHead; 53 OldFlink->Blink = Entry; 54 ListHead->Flink = Entry; 55 } 56 57 static __inline VOID 58 InitializeListHead( 59 IN PLIST_ENTRY ListHead) 60 { 61 ListHead->Flink = ListHead->Blink = ListHead; 62 } 63 64 /***********************************************************/ 65 66 #define DS_SOLIDBRUSH 0x00000001 67 #define DS_GREYBRUSH 0x00000002 68 #define DS_BRUSH 0x00000004 69 #define DS_DIB 0x00000008 70 71 #define POW2(stride) (!((stride) & ((stride)-1))) // TRUE if stride is power of 2 72 #define BROKEN_RASTERS(stride,cy) ((!(POW2(stride))) && ((stride*cy) > 0x10000)) 73 74 #define ENUM_RECT_LIMIT 50 75 76 typedef struct _RECT_ENUM 77 { 78 ULONG c; 79 RECTL arcl[ENUM_RECT_LIMIT]; 80 } RECT_ENUM; 81 82 // Cursor coordinates 83 typedef struct _XYPAIR 84 { 85 USHORT x; 86 USHORT y; 87 } XYPAIR; 88 89 typedef struct _SAVED_SCREEN_BITS 90 { 91 BOOL Free; 92 DWORD Offset; 93 ULONG Size; 94 LIST_ENTRY ListEntry; 95 } SAVED_SCREEN_BITS, *PSAVED_SCREEN_BITS; 96 97 // Cursor states 98 #define CURSOR_COLOR 0x00000004 99 #define CURSOR_HW 0x00000010 100 #define CURSOR_HW_ACTIVE 0x00000020 101 #define CURSOR_ANIMATE 0x00000040 102 103 typedef struct _PDEV 104 { 105 ULONG fl; // driver flags 106 107 // Handles 108 HANDLE KMDriver; 109 HDEV GDIDevHandle; // engine's handle to PDEV 110 HSURF SurfHandle; // engine's handle to surface 111 PVOID AssociatedSurf; // associated surface 112 113 // Cursor 114 XYPAIR xyHotSpot; // cursor hotspot 115 116 // Pointer 117 PVIDEO_POINTER_ATTRIBUTES pPointerAttributes; // HW Pointer Attributes 118 PSAVED_SCREEN_BITS ImageBehindCursor; 119 ULONG XorMaskStartOffset; // Start offset of hardware pointer 120 // XOR mask relative to AND mask for 121 // passing to HW pointer 122 DWORD PointerAttributes; // Size of buffer allocated 123 DWORD flPreallocSSBBufferInUse; // True if preallocated saved screen 124 // bits buffer is in use 125 PUCHAR pjPreallocSSBBuffer; // Pointer to preallocated saved screen 126 // bits buffer, if there is one 127 ULONG ulPreallocSSBSize; // Size of preallocated saved screen 128 // bits buffer 129 VIDEO_POINTER_CAPABILITIES PointerCapabilities; // HW pointer abilities 130 PUCHAR pucDIB4ToVGAConvBuffer; // DIB4->VGA conversion table buffer 131 PUCHAR pucDIB4ToVGAConvTables; // Pointer to DIB4->VGA conversion 132 133 // Misc 134 ULONG ModeNum; // mode index for current VGA mode 135 136 SIZEL sizeSurf; // displayed size of the surface 137 PBYTE fbScreen; // pointer to the frame buffer 138 RECTL SavedBitsRight; // invisible part right of screen 139 RECTL SavedBitsBottom; // invisible part at the bottom of the screen 140 BOOL BitsSaved; // TRUE if bits are currently saved 141 SIZEL sizeMem; // actual size (in pixels) of video memory 142 LONG NumScansUsedByPointer; // # scans of offscreen memory used by 143 144 } PDEV, *PPDEV; 145 146 typedef struct { 147 RECTL BankBounds; // Pixels addressable in this bank 148 ULONG BankOffset; // Offset of bank start from bitmap start if linearly addressable 149 } BANK_INFO, *PBANK_INFO; 150 151 typedef enum { 152 JustifyTop = 0, 153 JustifyBottom, 154 } BANK_JUST; 155 156 // bank control function vector 157 //typedef VOID (*PFN_BankControl)(PDEVSURF, ULONG, BANK_JUST); 158 typedef VOID (*PFN_BankControl)(PVOID, ULONG, BANK_JUST); 159 160 // DEVSURF -- definition of a surface as seen and used by the various VGA 161 // drivers 162 163 typedef struct _DEVSURF 164 { 165 IDENT ident; // Identifier for debugging ease 166 ULONG flSurf; // DS_ flags as defined below 167 BYTE Color; // Solid color surface if DS_SOLIDBRUSH 168 169 // If DS_SOLIDBRUSH, the following fields are undefined and not guaranteed to 170 // have been allocated! 171 172 BYTE Format; // BMF_*, BMF_PHYSDEVICE 173 BYTE jReserved1; // Reserved 174 BYTE jReserved2; // Reserved 175 PPDEV ppdev; // Pointer to associated PDEV 176 SIZEL sizeSurf; // Size of the surface 177 ULONG NextScan; // Offset from scan "n" to "n+1" 178 ULONG NextPlane; // Offset from plane "n" to "n+1" 179 PVOID Scan0; // Pointer to scan 0 of bitmap 180 // (actual address of start of bank, for banked VGA surface) 181 PVOID StartBmp; // Pointer to start of bitmap 182 PVOID Conv; // Pointer to DIB/Planer conversion buffer 183 184 // Banking variables; used only for banked VGA surfaces 185 186 PVIDEO_BANK_SELECT BankSelectInfo; 187 ULONG Bank2RWSkip; // Offset from one bank index to next to make two 32K banks appear to be 188 // one seamless 64K bank 189 PFN pfnBankSwitchCode; 190 VIDEO_BANK_TYPE BankingType; 191 ULONG BitmapSize; // Length of bitmap if there were no banking, in CPU addressable bytes 192 ULONG PtrBankScan; // Last scan line in pointer work bank 193 RECTL WindowClip1; // Single-window banking clip rect 194 RECTL WindowClip2[2]; // Double-window banking clip rects for 195 // windows 0 & 1 196 ULONG WindowBank[2]; // Current banks mapped into windows 197 // 0 & 1 (used in 2 window mode only) 198 PBANK_INFO BankInfo; // Pointer to array of bank clip info 199 ULONG BankInfoLength; // Length of pbiBankInfo, in entries 200 PBANK_INFO BankInfo2RW; // Same as above, but for 2RW window 201 ULONG BankInfo2RWLength; // case 202 PFN_BankControl pfnBankControl; // Pointer to bank control function 203 PFN_BankControl pfnBankControl2Window; // Pointer to double-window bank 204 // control function 205 PVOID BitmapStart; // Single-window bitmap start pointer (adjusted as 206 // necessary to make window map in at proper offset) 207 PVOID BitmapStart2Window[2]; // Double-window window 0 and 1 bitmap start 208 PVOID BankBufferPlane0; // Pointer to temp buffer capable of 209 // storing one full bank for plane 0 for 1 210 // R/W case; capable of storing one full 211 // bank height of edge bytes for all four 212 // planes for the 1R/1W case. Also used to 213 // point to text building buffer in all 214 // cases. This is the pointer used to 215 // dealloc bank working storage for all 216 // four planes 217 218 // The following 3 pointers used by 1 R/W banked devices 219 PVOID BankBufferPlane1; // Like above, but for plane 1 220 PVOID BankBufferPlane2; // Like above, but for plane 2 221 PVOID BankBufferPlane3; // Like above, but for plane 3 222 ULONG TempBufferSize; // Full size of temp buffer pointed to 223 // by pvBankBufferPlane0 224 225 ULONG ajBits[1]; // Bits will start here for device bitmaps 226 PSAVED_SCREEN_BITS ssbList; // Pointer to start of linked list of 227 // saved screen bit blocks 228 } DEVSURF, *PDEVSURF; 229 230 typedef VOID (*PFN_ScreenToScreenBlt)(PDEVSURF, PRECTL, PPOINTL, INT); 231 232 // BMF_PHYSDEVICE format type 233 234 #define BMF_PHYSDEVICE 0xFF 235 #define BMF_DFB 0xFE 236 237 // Identifiers used in debugging (DEVSURF.ident) 238 239 #define PDEV_IDENT ('V' + ('P' << 8) + ('D' << 16) + ('V' << 24)) 240 #define DEVSURF_IDENT ('V' + ('S' << 8) + ('R' << 16) + ('F' << 24)) 241 242 BOOL InitVGA(PPDEV ppdev, BOOL bFirst); // screen.c: initialize VGA mode 243 BOOL DeinitVGA(PPDEV ppdev); // screen.c: Free resources allocated in InitVGA 244 245 #define DRIVER_EXTRA_SIZE 0 246 #define ALLOC_TAG 'agvD' // Dvga tag 247 #define DLL_NAME L"vga" // DLL name in Unicode 248 249 #define MAX_SCAN_WIDTH 2048 // pixels 250 #define DRIVER_OFFSCREEN_REFRESHED 0x04L // if not set, don't use offscreen memory 251 #define PLANAR_PELS_PER_CPU_ADDRESS 8 252 #define PACKED_PELS_PER_CPU_ADDRESS 2 253 254 BOOL VGAtoGDI( 255 SURFOBJ *Dest, SURFOBJ *Source, SURFOBJ *Mask, XLATEOBJ *ColorTranslation, 256 RECTL *DestRect, POINTL *SourcePoint); 257 258 VOID 259 VGADDI_BltFromSavedScreenBits(ULONG DestX, 260 ULONG DestY, 261 PSAVED_SCREEN_BITS Src, 262 ULONG SizeX, 263 ULONG SizeY); 264 VOID 265 VGADDI_BltToSavedScreenBits(PSAVED_SCREEN_BITS Dest, 266 ULONG SourceX, 267 ULONG SourceY, 268 ULONG SizeX, 269 ULONG SizeY); 270 VOID 271 VGADDI_FreeSavedScreenBits(PSAVED_SCREEN_BITS SavedBits); 272 PSAVED_SCREEN_BITS 273 VGADDI_AllocSavedScreenBits(ULONG Size); 274 VOID 275 VGADDI_InitializeOffScreenMem(ULONG Start, ULONG Length); 276 277 BOOL InitPointer(PPDEV ppdev); 278 DWORD getAvailableModes(HANDLE Driver, 279 PVIDEO_MODE_INFORMATION *modeInformation, 280 DWORD *ModeSize); 281 282 VOID FASTCALL 283 vgaReadScan(int x, int y, int w, void *b); 284 285 VOID FASTCALL 286 vgaWriteScan(int x, int y, int w, void *b); 287 288 #endif /* _VGADDI_PCH_ */ 289