-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.c
172 lines (135 loc) · 6.05 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*****************************************************************************
Copyright (c) 2022 Michal Necasek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*****************************************************************************/
/* Display driver module initialization. */
#include "winhack.h"
#include <gdidefs.h>
#include <dibeng.h>
#include <minivdd.h>
#include "minidrv.h"
/* GlobalSmartPageLock is a semi-undocumented function. Not officially
* documented but described in KB Article Q180586. */
UINT WINAPI GlobalSmartPageLock( HGLOBAL hglb );
WORD wScrX = 640; /* Current X resolution. */
WORD wScrY = 480; /* Current Y resolution. */
WORD wDpi = 96; /* Current DPI setting. */
WORD wBpp = 8; /* Current BPP setting. */
WORD wPalettized = 0; /* Non-zero if palettized. */
WORD OurVMHandle = 0; /* The current VM's ID. */
DWORD VDDEntryPoint = 0; /* The VDD entry point. */
/* On Entry:
* EAX = Function code (VDD_GET_DISPLAY_CONFIG)
* EBX = This VM's handle
* ECX = Size of DISPLAYINFO structure
* EDX = Zero to tell VDD to try virtualizing
* ES:EDI = Pointer to DISPLAYINFO structure to be
* filled
*
* On Return:
* EAX = Return code (0 = succeess, -1 = failed)
*/
extern DWORD CallVDDGetDispConf( WORD Function, WORD wDInfSize, LPVOID pDInf );
#pragma aux CallVDDGetDispConf = \
".386" \
"movzx eax, ax" \
"movzx ecx, cx" \
"movzx ebx, OurVMHandle" \
"movzx edi, di" \
"call dword ptr VDDEntryPoint"\
"mov edx, eax" \
"shr edx, 16" \
parm [ax] [cx] [es di];
#pragma code_seg( _INIT )
/* Read the display settings from SYSTEM.INI or Registry.
*/
void ReadDisplayConfig( void )
{
WORD wX, wY;
UINT bIgnoreRegistry;
MODEDESC mode;
/* Get the DPI, default to 96. */
wDpi = GetPrivateProfileInt( "display", "dpi", 96, "system.ini" );
/* Get X and Y resolution. */
wX = GetPrivateProfileInt( "display", "x_resolution", 0, "system.ini" );
wY = GetPrivateProfileInt( "display", "y_resolution", 0, "system.ini" );
/* Get the bits per pixel. */
wBpp = GetPrivateProfileInt( "display", "bpp", 0, "system.ini" );
dbg_printf( "SYSTEM.INI: %ux%u %ubpp %udpi\n", wX, wY, wBpp, wDpi );
bIgnoreRegistry = GetPrivateProfileInt( "display", "IgnoreRegistry", 0, "system.ini" );
if( !bIgnoreRegistry ) {
DISPLAYINFO DispInfo;
DWORD dwRc;
dwRc = CallVDDGetDispConf( VDD_GET_DISPLAY_CONFIG, sizeof( DispInfo ), &DispInfo );
if( (dwRc != VDD_GET_DISPLAY_CONFIG) && !dwRc ) {
/* Call succeeded, use the data. */
wScrX = DispInfo.diXRes;
wScrY = DispInfo.diYRes;
wBpp = DispInfo.diBpp;
dbg_printf( "Registry: %ux%u %ubpp %udpi\n", DispInfo.diXRes, DispInfo.diYRes, DispInfo.diBpp, DispInfo.diDPI );
/* DPI might not be set, careful. */
if( DispInfo.diDPI )
wDpi = DispInfo.diDPI;
} else {
dbg_printf( "VDD_GET_DISPLAY_CONFIG failed, dwRc=%lX\n",dwRc );
}
}
mode.xRes = wScrX;
mode.yRes = wScrY;
mode.bpp = wBpp;
if( !FixModeInfo( &mode ) ) {
/* Values were changed. */
wScrX = mode.xRes;
wScrY = mode.yRes;
wBpp = mode.bpp;
}
/* For 8bpp, read the 'palettized' setting. Default to enabled. */
if( wBpp == 8 )
wPalettized = GetPrivateProfileInt( "display", "palettized", 1, "system.ini" );
else
wPalettized = 0;
}
#define VDD_ID 10 /* Virtual Display Driver ID. */
/* Get Device API Entry Point. */
void __far *int_2F_GetEP( unsigned ax, unsigned bx );
#pragma aux int_2F_GetEP = \
"int 2Fh" \
parm [ax] [bx] value [es di];
/* Get "magic number" (current Virtual Machine ID) for VDD calls. */
WORD int_2F_GetVMID( unsigned ax );
#pragma aux int_2F_GetVMID = \
"int 2Fh" \
parm [ax] value [bx];
/* Dummy pointer to get at the _TEXT segment. Is there any easier way? */
extern char __based( __segname( "_TEXT" ) ) *pText;
/* This is a standard DLL entry point. Note that DS is already set
* to point to this DLL's data segment on entry.
*/
#pragma aux DriverInit parm [cx] [di] [es si]
UINT FAR DriverInit( UINT cbHeap, UINT hModule, LPSTR lpCmdLine )
{
/* Lock the code segment. */
GlobalSmartPageLock( (__segment)pText );
/* Query the entry point of the Virtual Display Device. */
VDDEntryPoint = (DWORD)int_2F_GetEP( 0x1684, VDD_ID );
/* Obtain the "magic number" needed for VDD calls. */
OurVMHandle = int_2F_GetVMID( 0x1683 );
dbg_printf( "DriverInit: VDDEntryPoint=%WP, OurVMHandle=%x\n", VDDEntryPoint, OurVMHandle );
/* Read the display configuration before doing anything else. */
ReadDisplayConfig();
return( 1 ); /* Success. */
}