ReactOS 0.4.15-dev-7942-gd23573b
screen.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS VGA display driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/drivers/displays/vga/objects/screen.c
5 * PURPOSE:
6 * PROGRAMMERS:
7 */
8
9#include <vgaddi.h>
10
11static WORD PaletteBuffer[] = {
12 16, 0, // 16 entries, start with 0
13 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
14};
15
16static BYTE ColorBuffer[] = {
17 16, // 16 entries
18 0, 0,
19 0, // start with 0
20 0x00, 0x00, 0x00, 0x00, // black
21 0x2A, 0x00, 0x15, 0x00, // red
22 0x00, 0x2A, 0x15, 0x00, // green
23 0x2A, 0x2A, 0x15, 0x00, // brown
24 0x00, 0x00, 0x2A, 0x00, // blue
25 0x2A, 0x15, 0x2A, 0x00, // magenta
26 0x15, 0x2A, 0x2A, 0x00, // cyan
27 0x21, 0x22, 0x23, 0x00, // dark gray
28 0x30, 0x31, 0x32, 0x00, // light gray
29 0x3F, 0x00, 0x00, 0x00, // bright red
30 0x00, 0x3F, 0x00, 0x00, // bright green
31 0x3F, 0x3F, 0x00, 0x00, // bright yellow
32 0x00, 0x00, 0x3F, 0x00, // bright blue
33 0x3F, 0x00, 0x3F, 0x00, // bright magenta
34 0x00, 0x3F, 0x3F, 0x00, // bright cyan
35 0x3F, 0x3F, 0x3F, 0x00 // bright white
36};
37
40 OUT PVIDEO_MODE_INFORMATION *modeInformation,
41 OUT DWORD *ModeSize)
42{
43 ULONG Temp;
44 VIDEO_NUM_MODES modes;
46
47 /* get number of modes supported */
48 if (EngDeviceIoControl(Driver,
50 NULL,
51 0,
52 &modes,
53 sizeof(VIDEO_NUM_MODES),
54 &Temp))
55 {
56 /* get modes failed */
57 return 0;
58 }
59
60 *ModeSize = modes.ModeInformationLength;
61
62 /* allocate buffer for the mini-port to write the modes in */
63 *modeInformation = (PVIDEO_MODE_INFORMATION)
64 EngAllocMem(0, modes.NumModes *
66
67 if (*modeInformation == NULL)
68 {
69 /* couldn't allocate buffer */
70 return 0;
71 }
72
73 /* Ask the mini-port to fill in the available modes. */
74 if (EngDeviceIoControl(Driver,
76 NULL,
77 0,
78 *modeInformation,
79 modes.NumModes * modes.ModeInformationLength,
80 &Temp))
81 {
82 /* failed to query modes */
83 EngFreeMem(*modeInformation);
84 *modeInformation = NULL;
85
86 return 0;
87 }
88
89 /* Which modes supported by miniport driver are also suppoted by us, the
90 * display driver */
91
92 Temp = modes.NumModes;
93 VideoTemp = *modeInformation;
94
95 /* Reject mode if it's not 4 planes or not graphic or not 1 bits per pel */
96 while (Temp--)
97 {
98 if ((VideoTemp->NumberOfPlanes != 4 ) ||
99 !(VideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
100 (VideoTemp->BitsPerPlane != 1) ||
101 BROKEN_RASTERS(VideoTemp->ScreenStride, VideoTemp->VisScreenHeight))
102 {
103 VideoTemp->Length = 0;
104 }
105
106 VideoTemp = (PVIDEO_MODE_INFORMATION)(((PUCHAR)VideoTemp) + modes.ModeInformationLength);
107 }
108
109 return modes.NumModes;
110}
111
113{
114 VIDEO_MEMORY VideoMemory;
115 ULONG ReturnedDataLength;
116
117 VideoMemory.RequestedVirtualAddress = (PVOID)ppdev->fbScreen;
118
119 if (EngDeviceIoControl(ppdev->KMDriver,
121 (PVOID)&VideoMemory,
122 sizeof(VIDEO_MEMORY),
123 NULL,
124 0,
125 &ReturnedDataLength))
126 {
127 DPRINT1("Failed to unmap video memory.\n");
129 return FALSE;
130 }
131 return TRUE;
132}
133
134BOOL InitVGA(PPDEV ppdev, BOOL bFirst)
135{
136 ULONG ReturnedDataLength;
137 VIDEO_MEMORY VideoMemory;
138 VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
139
140 ppdev->sizeSurf.cx = 640;
141 ppdev->sizeSurf.cy = 480;
142 ppdev->ModeNum = 2;
143
144 /* Set the mode that was requested */
145 if (EngDeviceIoControl(ppdev->KMDriver,
147 &ppdev->ModeNum,
148 sizeof(VIDEO_MODE),
149 NULL,
150 0,
151 &ReturnedDataLength))
152 {
153 return FALSE;
154 }
155
156 /* set up internal palette */
157 if (EngDeviceIoControl(ppdev->KMDriver,
161 NULL,
162 0,
163 &ReturnedDataLength))
164 {
165 return FALSE;
166 }
167
168 /* set up the DAC */
169 if (EngDeviceIoControl(ppdev->KMDriver,
173 NULL,
174 0,
175 &ReturnedDataLength))
176 {
177 return FALSE;
178 }
179
180 if (bFirst)
181 {
182 /* map video memory into virtual memory */
183 VideoMemory.RequestedVirtualAddress = NULL;
184
185 if (EngDeviceIoControl(ppdev->KMDriver,
187 (PVOID) &VideoMemory,
189 (PVOID) &VideoMemoryInfo,
190 sizeof (VideoMemoryInfo),
191 &ReturnedDataLength))
192 {
193 /* Failed to map to virtual memory */
194 return FALSE;
195 }
196
197 ppdev->fbScreen = VideoMemoryInfo.FrameBufferBase;
198 vidmem = (PUCHAR)ppdev->fbScreen;
199 }
200
201 return TRUE;
202}
#define DPRINT1
Definition: precomp.h:8
#define ALLOC_TAG
Definition: btrfs_drv.h:87
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
if(dx< 0)
Definition: linetemp.h:194
#define IOCTL_VIDEO_MAP_VIDEO_MEMORY
Definition: ntddvdeo.h:173
#define VIDEO_MODE_GRAPHICS
Definition: ntddvdeo.h:364
#define IOCTL_VIDEO_SET_PALETTE_REGISTERS
Definition: ntddvdeo.h:230
#define IOCTL_VIDEO_UNMAP_VIDEO_MEMORY
Definition: ntddvdeo.h:248
struct _VIDEO_MODE_INFORMATION * PVIDEO_MODE_INFORMATION
#define IOCTL_VIDEO_SET_CURRENT_MODE
Definition: ntddvdeo.h:221
#define IOCTL_VIDEO_SET_COLOR_REGISTERS
Definition: ntddvdeo.h:218
#define IOCTL_VIDEO_QUERY_AVAIL_MODES
Definition: ntddvdeo.h:176
#define IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES
Definition: ntddvdeo.h:191
#define EngFreeMem
Definition: polytest.cpp:56
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
Definition: framebuf.h:34
SIZEL sizeSurf
Definition: vgaddi.h:136
PBYTE fbScreen
Definition: vgaddi.h:137
ULONG ModeNum
Definition: vgaddi.h:134
HANDLE KMDriver
Definition: vgaddi.h:108
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
PVOID RequestedVirtualAddress
Definition: ntddvdeo.h:344
ULONG ModeInformationLength
Definition: ntddvdeo.h:398
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define BROKEN_RASTERS(stride, cy)
Definition: vgaddi.h:72
PBYTE vidmem
Definition: vgavideo.c:18
_Must_inspect_result_ _In_ WDFDRIVER Driver
Definition: wdfcontrol.h:83
DWORD getAvailableModes(IN HANDLE Driver, OUT PVIDEO_MODE_INFORMATION *modeInformation, OUT DWORD *ModeSize)
Definition: screen.c:38
static WORD PaletteBuffer[]
Definition: screen.c:11
static BYTE ColorBuffer[]
Definition: screen.c:16
BOOL InitVGA(PPDEV ppdev, BOOL bFirst)
Definition: screen.c:134
BOOL DeinitVGA(PPDEV ppdev)
Definition: screen.c:112
_Analysis_noreturn_ ENGAPI VOID APIENTRY EngDebugBreak(VOID)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
unsigned char BYTE
Definition: xxhash.c:193