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