src/video/windx5/SDL_dx5video.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1661 281d3f4870e5
child 1668 4da1ee79c9af
     1.1 --- a/src/video/windx5/SDL_dx5video.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/video/windx5/SDL_dx5video.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -56,14 +56,17 @@
     1.4  
     1.5  
     1.6  /* DirectX function pointers for video and events */
     1.7 -HRESULT (WINAPI *DDrawCreate)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter );
     1.8 -HRESULT (WINAPI *DInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT *ppDI, LPUNKNOWN punkOuter);
     1.9 +HRESULT (WINAPI * DDrawCreate) (GUID FAR * lpGUID, LPDIRECTDRAW FAR * lplpDD,
    1.10 +                                IUnknown FAR * pUnkOuter);
    1.11 +HRESULT (WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
    1.12 +                                 LPDIRECTINPUT * ppDI, LPUNKNOWN punkOuter);
    1.13  
    1.14  /* This is the rect EnumModes2 uses */
    1.15 -struct DX5EnumRect {
    1.16 -	SDL_Rect r;
    1.17 -	int refreshRate;
    1.18 -	struct DX5EnumRect* next;
    1.19 +struct DX5EnumRect
    1.20 +{
    1.21 +    SDL_Rect r;
    1.22 +    int refreshRate;
    1.23 +    struct DX5EnumRect *next;
    1.24  };
    1.25  static struct DX5EnumRect *enumlists[NUM_MODELISTS];
    1.26  
    1.27 @@ -74,262 +77,262 @@
    1.28  /* Keyboard */
    1.29  
    1.30  static DIOBJECTDATAFORMAT KBD_fmt[] = {
    1.31 -	{ &GUID_Key, 0, 0x8000000C, 0x00000000 },
    1.32 -	{ &GUID_Key, 1, 0x8000010C, 0x00000000 },
    1.33 -	{ &GUID_Key, 2, 0x8000020C, 0x00000000 },
    1.34 -	{ &GUID_Key, 3, 0x8000030C, 0x00000000 },
    1.35 -	{ &GUID_Key, 4, 0x8000040C, 0x00000000 },
    1.36 -	{ &GUID_Key, 5, 0x8000050C, 0x00000000 },
    1.37 -	{ &GUID_Key, 6, 0x8000060C, 0x00000000 },
    1.38 -	{ &GUID_Key, 7, 0x8000070C, 0x00000000 },
    1.39 -	{ &GUID_Key, 8, 0x8000080C, 0x00000000 },
    1.40 -	{ &GUID_Key, 9, 0x8000090C, 0x00000000 },
    1.41 -	{ &GUID_Key, 10, 0x80000A0C, 0x00000000 },
    1.42 -	{ &GUID_Key, 11, 0x80000B0C, 0x00000000 },
    1.43 -	{ &GUID_Key, 12, 0x80000C0C, 0x00000000 },
    1.44 -	{ &GUID_Key, 13, 0x80000D0C, 0x00000000 },
    1.45 -	{ &GUID_Key, 14, 0x80000E0C, 0x00000000 },
    1.46 -	{ &GUID_Key, 15, 0x80000F0C, 0x00000000 },
    1.47 -	{ &GUID_Key, 16, 0x8000100C, 0x00000000 },
    1.48 -	{ &GUID_Key, 17, 0x8000110C, 0x00000000 },
    1.49 -	{ &GUID_Key, 18, 0x8000120C, 0x00000000 },
    1.50 -	{ &GUID_Key, 19, 0x8000130C, 0x00000000 },
    1.51 -	{ &GUID_Key, 20, 0x8000140C, 0x00000000 },
    1.52 -	{ &GUID_Key, 21, 0x8000150C, 0x00000000 },
    1.53 -	{ &GUID_Key, 22, 0x8000160C, 0x00000000 },
    1.54 -	{ &GUID_Key, 23, 0x8000170C, 0x00000000 },
    1.55 -	{ &GUID_Key, 24, 0x8000180C, 0x00000000 },
    1.56 -	{ &GUID_Key, 25, 0x8000190C, 0x00000000 },
    1.57 -	{ &GUID_Key, 26, 0x80001A0C, 0x00000000 },
    1.58 -	{ &GUID_Key, 27, 0x80001B0C, 0x00000000 },
    1.59 -	{ &GUID_Key, 28, 0x80001C0C, 0x00000000 },
    1.60 -	{ &GUID_Key, 29, 0x80001D0C, 0x00000000 },
    1.61 -	{ &GUID_Key, 30, 0x80001E0C, 0x00000000 },
    1.62 -	{ &GUID_Key, 31, 0x80001F0C, 0x00000000 },
    1.63 -	{ &GUID_Key, 32, 0x8000200C, 0x00000000 },
    1.64 -	{ &GUID_Key, 33, 0x8000210C, 0x00000000 },
    1.65 -	{ &GUID_Key, 34, 0x8000220C, 0x00000000 },
    1.66 -	{ &GUID_Key, 35, 0x8000230C, 0x00000000 },
    1.67 -	{ &GUID_Key, 36, 0x8000240C, 0x00000000 },
    1.68 -	{ &GUID_Key, 37, 0x8000250C, 0x00000000 },
    1.69 -	{ &GUID_Key, 38, 0x8000260C, 0x00000000 },
    1.70 -	{ &GUID_Key, 39, 0x8000270C, 0x00000000 },
    1.71 -	{ &GUID_Key, 40, 0x8000280C, 0x00000000 },
    1.72 -	{ &GUID_Key, 41, 0x8000290C, 0x00000000 },
    1.73 -	{ &GUID_Key, 42, 0x80002A0C, 0x00000000 },
    1.74 -	{ &GUID_Key, 43, 0x80002B0C, 0x00000000 },
    1.75 -	{ &GUID_Key, 44, 0x80002C0C, 0x00000000 },
    1.76 -	{ &GUID_Key, 45, 0x80002D0C, 0x00000000 },
    1.77 -	{ &GUID_Key, 46, 0x80002E0C, 0x00000000 },
    1.78 -	{ &GUID_Key, 47, 0x80002F0C, 0x00000000 },
    1.79 -	{ &GUID_Key, 48, 0x8000300C, 0x00000000 },
    1.80 -	{ &GUID_Key, 49, 0x8000310C, 0x00000000 },
    1.81 -	{ &GUID_Key, 50, 0x8000320C, 0x00000000 },
    1.82 -	{ &GUID_Key, 51, 0x8000330C, 0x00000000 },
    1.83 -	{ &GUID_Key, 52, 0x8000340C, 0x00000000 },
    1.84 -	{ &GUID_Key, 53, 0x8000350C, 0x00000000 },
    1.85 -	{ &GUID_Key, 54, 0x8000360C, 0x00000000 },
    1.86 -	{ &GUID_Key, 55, 0x8000370C, 0x00000000 },
    1.87 -	{ &GUID_Key, 56, 0x8000380C, 0x00000000 },
    1.88 -	{ &GUID_Key, 57, 0x8000390C, 0x00000000 },
    1.89 -	{ &GUID_Key, 58, 0x80003A0C, 0x00000000 },
    1.90 -	{ &GUID_Key, 59, 0x80003B0C, 0x00000000 },
    1.91 -	{ &GUID_Key, 60, 0x80003C0C, 0x00000000 },
    1.92 -	{ &GUID_Key, 61, 0x80003D0C, 0x00000000 },
    1.93 -	{ &GUID_Key, 62, 0x80003E0C, 0x00000000 },
    1.94 -	{ &GUID_Key, 63, 0x80003F0C, 0x00000000 },
    1.95 -	{ &GUID_Key, 64, 0x8000400C, 0x00000000 },
    1.96 -	{ &GUID_Key, 65, 0x8000410C, 0x00000000 },
    1.97 -	{ &GUID_Key, 66, 0x8000420C, 0x00000000 },
    1.98 -	{ &GUID_Key, 67, 0x8000430C, 0x00000000 },
    1.99 -	{ &GUID_Key, 68, 0x8000440C, 0x00000000 },
   1.100 -	{ &GUID_Key, 69, 0x8000450C, 0x00000000 },
   1.101 -	{ &GUID_Key, 70, 0x8000460C, 0x00000000 },
   1.102 -	{ &GUID_Key, 71, 0x8000470C, 0x00000000 },
   1.103 -	{ &GUID_Key, 72, 0x8000480C, 0x00000000 },
   1.104 -	{ &GUID_Key, 73, 0x8000490C, 0x00000000 },
   1.105 -	{ &GUID_Key, 74, 0x80004A0C, 0x00000000 },
   1.106 -	{ &GUID_Key, 75, 0x80004B0C, 0x00000000 },
   1.107 -	{ &GUID_Key, 76, 0x80004C0C, 0x00000000 },
   1.108 -	{ &GUID_Key, 77, 0x80004D0C, 0x00000000 },
   1.109 -	{ &GUID_Key, 78, 0x80004E0C, 0x00000000 },
   1.110 -	{ &GUID_Key, 79, 0x80004F0C, 0x00000000 },
   1.111 -	{ &GUID_Key, 80, 0x8000500C, 0x00000000 },
   1.112 -	{ &GUID_Key, 81, 0x8000510C, 0x00000000 },
   1.113 -	{ &GUID_Key, 82, 0x8000520C, 0x00000000 },
   1.114 -	{ &GUID_Key, 83, 0x8000530C, 0x00000000 },
   1.115 -	{ &GUID_Key, 84, 0x8000540C, 0x00000000 },
   1.116 -	{ &GUID_Key, 85, 0x8000550C, 0x00000000 },
   1.117 -	{ &GUID_Key, 86, 0x8000560C, 0x00000000 },
   1.118 -	{ &GUID_Key, 87, 0x8000570C, 0x00000000 },
   1.119 -	{ &GUID_Key, 88, 0x8000580C, 0x00000000 },
   1.120 -	{ &GUID_Key, 89, 0x8000590C, 0x00000000 },
   1.121 -	{ &GUID_Key, 90, 0x80005A0C, 0x00000000 },
   1.122 -	{ &GUID_Key, 91, 0x80005B0C, 0x00000000 },
   1.123 -	{ &GUID_Key, 92, 0x80005C0C, 0x00000000 },
   1.124 -	{ &GUID_Key, 93, 0x80005D0C, 0x00000000 },
   1.125 -	{ &GUID_Key, 94, 0x80005E0C, 0x00000000 },
   1.126 -	{ &GUID_Key, 95, 0x80005F0C, 0x00000000 },
   1.127 -	{ &GUID_Key, 96, 0x8000600C, 0x00000000 },
   1.128 -	{ &GUID_Key, 97, 0x8000610C, 0x00000000 },
   1.129 -	{ &GUID_Key, 98, 0x8000620C, 0x00000000 },
   1.130 -	{ &GUID_Key, 99, 0x8000630C, 0x00000000 },
   1.131 -	{ &GUID_Key, 100, 0x8000640C, 0x00000000 },
   1.132 -	{ &GUID_Key, 101, 0x8000650C, 0x00000000 },
   1.133 -	{ &GUID_Key, 102, 0x8000660C, 0x00000000 },
   1.134 -	{ &GUID_Key, 103, 0x8000670C, 0x00000000 },
   1.135 -	{ &GUID_Key, 104, 0x8000680C, 0x00000000 },
   1.136 -	{ &GUID_Key, 105, 0x8000690C, 0x00000000 },
   1.137 -	{ &GUID_Key, 106, 0x80006A0C, 0x00000000 },
   1.138 -	{ &GUID_Key, 107, 0x80006B0C, 0x00000000 },
   1.139 -	{ &GUID_Key, 108, 0x80006C0C, 0x00000000 },
   1.140 -	{ &GUID_Key, 109, 0x80006D0C, 0x00000000 },
   1.141 -	{ &GUID_Key, 110, 0x80006E0C, 0x00000000 },
   1.142 -	{ &GUID_Key, 111, 0x80006F0C, 0x00000000 },
   1.143 -	{ &GUID_Key, 112, 0x8000700C, 0x00000000 },
   1.144 -	{ &GUID_Key, 113, 0x8000710C, 0x00000000 },
   1.145 -	{ &GUID_Key, 114, 0x8000720C, 0x00000000 },
   1.146 -	{ &GUID_Key, 115, 0x8000730C, 0x00000000 },
   1.147 -	{ &GUID_Key, 116, 0x8000740C, 0x00000000 },
   1.148 -	{ &GUID_Key, 117, 0x8000750C, 0x00000000 },
   1.149 -	{ &GUID_Key, 118, 0x8000760C, 0x00000000 },
   1.150 -	{ &GUID_Key, 119, 0x8000770C, 0x00000000 },
   1.151 -	{ &GUID_Key, 120, 0x8000780C, 0x00000000 },
   1.152 -	{ &GUID_Key, 121, 0x8000790C, 0x00000000 },
   1.153 -	{ &GUID_Key, 122, 0x80007A0C, 0x00000000 },
   1.154 -	{ &GUID_Key, 123, 0x80007B0C, 0x00000000 },
   1.155 -	{ &GUID_Key, 124, 0x80007C0C, 0x00000000 },
   1.156 -	{ &GUID_Key, 125, 0x80007D0C, 0x00000000 },
   1.157 -	{ &GUID_Key, 126, 0x80007E0C, 0x00000000 },
   1.158 -	{ &GUID_Key, 127, 0x80007F0C, 0x00000000 },
   1.159 -	{ &GUID_Key, 128, 0x8000800C, 0x00000000 },
   1.160 -	{ &GUID_Key, 129, 0x8000810C, 0x00000000 },
   1.161 -	{ &GUID_Key, 130, 0x8000820C, 0x00000000 },
   1.162 -	{ &GUID_Key, 131, 0x8000830C, 0x00000000 },
   1.163 -	{ &GUID_Key, 132, 0x8000840C, 0x00000000 },
   1.164 -	{ &GUID_Key, 133, 0x8000850C, 0x00000000 },
   1.165 -	{ &GUID_Key, 134, 0x8000860C, 0x00000000 },
   1.166 -	{ &GUID_Key, 135, 0x8000870C, 0x00000000 },
   1.167 -	{ &GUID_Key, 136, 0x8000880C, 0x00000000 },
   1.168 -	{ &GUID_Key, 137, 0x8000890C, 0x00000000 },
   1.169 -	{ &GUID_Key, 138, 0x80008A0C, 0x00000000 },
   1.170 -	{ &GUID_Key, 139, 0x80008B0C, 0x00000000 },
   1.171 -	{ &GUID_Key, 140, 0x80008C0C, 0x00000000 },
   1.172 -	{ &GUID_Key, 141, 0x80008D0C, 0x00000000 },
   1.173 -	{ &GUID_Key, 142, 0x80008E0C, 0x00000000 },
   1.174 -	{ &GUID_Key, 143, 0x80008F0C, 0x00000000 },
   1.175 -	{ &GUID_Key, 144, 0x8000900C, 0x00000000 },
   1.176 -	{ &GUID_Key, 145, 0x8000910C, 0x00000000 },
   1.177 -	{ &GUID_Key, 146, 0x8000920C, 0x00000000 },
   1.178 -	{ &GUID_Key, 147, 0x8000930C, 0x00000000 },
   1.179 -	{ &GUID_Key, 148, 0x8000940C, 0x00000000 },
   1.180 -	{ &GUID_Key, 149, 0x8000950C, 0x00000000 },
   1.181 -	{ &GUID_Key, 150, 0x8000960C, 0x00000000 },
   1.182 -	{ &GUID_Key, 151, 0x8000970C, 0x00000000 },
   1.183 -	{ &GUID_Key, 152, 0x8000980C, 0x00000000 },
   1.184 -	{ &GUID_Key, 153, 0x8000990C, 0x00000000 },
   1.185 -	{ &GUID_Key, 154, 0x80009A0C, 0x00000000 },
   1.186 -	{ &GUID_Key, 155, 0x80009B0C, 0x00000000 },
   1.187 -	{ &GUID_Key, 156, 0x80009C0C, 0x00000000 },
   1.188 -	{ &GUID_Key, 157, 0x80009D0C, 0x00000000 },
   1.189 -	{ &GUID_Key, 158, 0x80009E0C, 0x00000000 },
   1.190 -	{ &GUID_Key, 159, 0x80009F0C, 0x00000000 },
   1.191 -	{ &GUID_Key, 160, 0x8000A00C, 0x00000000 },
   1.192 -	{ &GUID_Key, 161, 0x8000A10C, 0x00000000 },
   1.193 -	{ &GUID_Key, 162, 0x8000A20C, 0x00000000 },
   1.194 -	{ &GUID_Key, 163, 0x8000A30C, 0x00000000 },
   1.195 -	{ &GUID_Key, 164, 0x8000A40C, 0x00000000 },
   1.196 -	{ &GUID_Key, 165, 0x8000A50C, 0x00000000 },
   1.197 -	{ &GUID_Key, 166, 0x8000A60C, 0x00000000 },
   1.198 -	{ &GUID_Key, 167, 0x8000A70C, 0x00000000 },
   1.199 -	{ &GUID_Key, 168, 0x8000A80C, 0x00000000 },
   1.200 -	{ &GUID_Key, 169, 0x8000A90C, 0x00000000 },
   1.201 -	{ &GUID_Key, 170, 0x8000AA0C, 0x00000000 },
   1.202 -	{ &GUID_Key, 171, 0x8000AB0C, 0x00000000 },
   1.203 -	{ &GUID_Key, 172, 0x8000AC0C, 0x00000000 },
   1.204 -	{ &GUID_Key, 173, 0x8000AD0C, 0x00000000 },
   1.205 -	{ &GUID_Key, 174, 0x8000AE0C, 0x00000000 },
   1.206 -	{ &GUID_Key, 175, 0x8000AF0C, 0x00000000 },
   1.207 -	{ &GUID_Key, 176, 0x8000B00C, 0x00000000 },
   1.208 -	{ &GUID_Key, 177, 0x8000B10C, 0x00000000 },
   1.209 -	{ &GUID_Key, 178, 0x8000B20C, 0x00000000 },
   1.210 -	{ &GUID_Key, 179, 0x8000B30C, 0x00000000 },
   1.211 -	{ &GUID_Key, 180, 0x8000B40C, 0x00000000 },
   1.212 -	{ &GUID_Key, 181, 0x8000B50C, 0x00000000 },
   1.213 -	{ &GUID_Key, 182, 0x8000B60C, 0x00000000 },
   1.214 -	{ &GUID_Key, 183, 0x8000B70C, 0x00000000 },
   1.215 -	{ &GUID_Key, 184, 0x8000B80C, 0x00000000 },
   1.216 -	{ &GUID_Key, 185, 0x8000B90C, 0x00000000 },
   1.217 -	{ &GUID_Key, 186, 0x8000BA0C, 0x00000000 },
   1.218 -	{ &GUID_Key, 187, 0x8000BB0C, 0x00000000 },
   1.219 -	{ &GUID_Key, 188, 0x8000BC0C, 0x00000000 },
   1.220 -	{ &GUID_Key, 189, 0x8000BD0C, 0x00000000 },
   1.221 -	{ &GUID_Key, 190, 0x8000BE0C, 0x00000000 },
   1.222 -	{ &GUID_Key, 191, 0x8000BF0C, 0x00000000 },
   1.223 -	{ &GUID_Key, 192, 0x8000C00C, 0x00000000 },
   1.224 -	{ &GUID_Key, 193, 0x8000C10C, 0x00000000 },
   1.225 -	{ &GUID_Key, 194, 0x8000C20C, 0x00000000 },
   1.226 -	{ &GUID_Key, 195, 0x8000C30C, 0x00000000 },
   1.227 -	{ &GUID_Key, 196, 0x8000C40C, 0x00000000 },
   1.228 -	{ &GUID_Key, 197, 0x8000C50C, 0x00000000 },
   1.229 -	{ &GUID_Key, 198, 0x8000C60C, 0x00000000 },
   1.230 -	{ &GUID_Key, 199, 0x8000C70C, 0x00000000 },
   1.231 -	{ &GUID_Key, 200, 0x8000C80C, 0x00000000 },
   1.232 -	{ &GUID_Key, 201, 0x8000C90C, 0x00000000 },
   1.233 -	{ &GUID_Key, 202, 0x8000CA0C, 0x00000000 },
   1.234 -	{ &GUID_Key, 203, 0x8000CB0C, 0x00000000 },
   1.235 -	{ &GUID_Key, 204, 0x8000CC0C, 0x00000000 },
   1.236 -	{ &GUID_Key, 205, 0x8000CD0C, 0x00000000 },
   1.237 -	{ &GUID_Key, 206, 0x8000CE0C, 0x00000000 },
   1.238 -	{ &GUID_Key, 207, 0x8000CF0C, 0x00000000 },
   1.239 -	{ &GUID_Key, 208, 0x8000D00C, 0x00000000 },
   1.240 -	{ &GUID_Key, 209, 0x8000D10C, 0x00000000 },
   1.241 -	{ &GUID_Key, 210, 0x8000D20C, 0x00000000 },
   1.242 -	{ &GUID_Key, 211, 0x8000D30C, 0x00000000 },
   1.243 -	{ &GUID_Key, 212, 0x8000D40C, 0x00000000 },
   1.244 -	{ &GUID_Key, 213, 0x8000D50C, 0x00000000 },
   1.245 -	{ &GUID_Key, 214, 0x8000D60C, 0x00000000 },
   1.246 -	{ &GUID_Key, 215, 0x8000D70C, 0x00000000 },
   1.247 -	{ &GUID_Key, 216, 0x8000D80C, 0x00000000 },
   1.248 -	{ &GUID_Key, 217, 0x8000D90C, 0x00000000 },
   1.249 -	{ &GUID_Key, 218, 0x8000DA0C, 0x00000000 },
   1.250 -	{ &GUID_Key, 219, 0x8000DB0C, 0x00000000 },
   1.251 -	{ &GUID_Key, 220, 0x8000DC0C, 0x00000000 },
   1.252 -	{ &GUID_Key, 221, 0x8000DD0C, 0x00000000 },
   1.253 -	{ &GUID_Key, 222, 0x8000DE0C, 0x00000000 },
   1.254 -	{ &GUID_Key, 223, 0x8000DF0C, 0x00000000 },
   1.255 -	{ &GUID_Key, 224, 0x8000E00C, 0x00000000 },
   1.256 -	{ &GUID_Key, 225, 0x8000E10C, 0x00000000 },
   1.257 -	{ &GUID_Key, 226, 0x8000E20C, 0x00000000 },
   1.258 -	{ &GUID_Key, 227, 0x8000E30C, 0x00000000 },
   1.259 -	{ &GUID_Key, 228, 0x8000E40C, 0x00000000 },
   1.260 -	{ &GUID_Key, 229, 0x8000E50C, 0x00000000 },
   1.261 -	{ &GUID_Key, 230, 0x8000E60C, 0x00000000 },
   1.262 -	{ &GUID_Key, 231, 0x8000E70C, 0x00000000 },
   1.263 -	{ &GUID_Key, 232, 0x8000E80C, 0x00000000 },
   1.264 -	{ &GUID_Key, 233, 0x8000E90C, 0x00000000 },
   1.265 -	{ &GUID_Key, 234, 0x8000EA0C, 0x00000000 },
   1.266 -	{ &GUID_Key, 235, 0x8000EB0C, 0x00000000 },
   1.267 -	{ &GUID_Key, 236, 0x8000EC0C, 0x00000000 },
   1.268 -	{ &GUID_Key, 237, 0x8000ED0C, 0x00000000 },
   1.269 -	{ &GUID_Key, 238, 0x8000EE0C, 0x00000000 },
   1.270 -	{ &GUID_Key, 239, 0x8000EF0C, 0x00000000 },
   1.271 -	{ &GUID_Key, 240, 0x8000F00C, 0x00000000 },
   1.272 -	{ &GUID_Key, 241, 0x8000F10C, 0x00000000 },
   1.273 -	{ &GUID_Key, 242, 0x8000F20C, 0x00000000 },
   1.274 -	{ &GUID_Key, 243, 0x8000F30C, 0x00000000 },
   1.275 -	{ &GUID_Key, 244, 0x8000F40C, 0x00000000 },
   1.276 -	{ &GUID_Key, 245, 0x8000F50C, 0x00000000 },
   1.277 -	{ &GUID_Key, 246, 0x8000F60C, 0x00000000 },
   1.278 -	{ &GUID_Key, 247, 0x8000F70C, 0x00000000 },
   1.279 -	{ &GUID_Key, 248, 0x8000F80C, 0x00000000 },
   1.280 -	{ &GUID_Key, 249, 0x8000F90C, 0x00000000 },
   1.281 -	{ &GUID_Key, 250, 0x8000FA0C, 0x00000000 },
   1.282 -	{ &GUID_Key, 251, 0x8000FB0C, 0x00000000 },
   1.283 -	{ &GUID_Key, 252, 0x8000FC0C, 0x00000000 },
   1.284 -	{ &GUID_Key, 253, 0x8000FD0C, 0x00000000 },
   1.285 -	{ &GUID_Key, 254, 0x8000FE0C, 0x00000000 },
   1.286 -	{ &GUID_Key, 255, 0x8000FF0C, 0x00000000 },
   1.287 +    {&GUID_Key, 0, 0x8000000C, 0x00000000},
   1.288 +    {&GUID_Key, 1, 0x8000010C, 0x00000000},
   1.289 +    {&GUID_Key, 2, 0x8000020C, 0x00000000},
   1.290 +    {&GUID_Key, 3, 0x8000030C, 0x00000000},
   1.291 +    {&GUID_Key, 4, 0x8000040C, 0x00000000},
   1.292 +    {&GUID_Key, 5, 0x8000050C, 0x00000000},
   1.293 +    {&GUID_Key, 6, 0x8000060C, 0x00000000},
   1.294 +    {&GUID_Key, 7, 0x8000070C, 0x00000000},
   1.295 +    {&GUID_Key, 8, 0x8000080C, 0x00000000},
   1.296 +    {&GUID_Key, 9, 0x8000090C, 0x00000000},
   1.297 +    {&GUID_Key, 10, 0x80000A0C, 0x00000000},
   1.298 +    {&GUID_Key, 11, 0x80000B0C, 0x00000000},
   1.299 +    {&GUID_Key, 12, 0x80000C0C, 0x00000000},
   1.300 +    {&GUID_Key, 13, 0x80000D0C, 0x00000000},
   1.301 +    {&GUID_Key, 14, 0x80000E0C, 0x00000000},
   1.302 +    {&GUID_Key, 15, 0x80000F0C, 0x00000000},
   1.303 +    {&GUID_Key, 16, 0x8000100C, 0x00000000},
   1.304 +    {&GUID_Key, 17, 0x8000110C, 0x00000000},
   1.305 +    {&GUID_Key, 18, 0x8000120C, 0x00000000},
   1.306 +    {&GUID_Key, 19, 0x8000130C, 0x00000000},
   1.307 +    {&GUID_Key, 20, 0x8000140C, 0x00000000},
   1.308 +    {&GUID_Key, 21, 0x8000150C, 0x00000000},
   1.309 +    {&GUID_Key, 22, 0x8000160C, 0x00000000},
   1.310 +    {&GUID_Key, 23, 0x8000170C, 0x00000000},
   1.311 +    {&GUID_Key, 24, 0x8000180C, 0x00000000},
   1.312 +    {&GUID_Key, 25, 0x8000190C, 0x00000000},
   1.313 +    {&GUID_Key, 26, 0x80001A0C, 0x00000000},
   1.314 +    {&GUID_Key, 27, 0x80001B0C, 0x00000000},
   1.315 +    {&GUID_Key, 28, 0x80001C0C, 0x00000000},
   1.316 +    {&GUID_Key, 29, 0x80001D0C, 0x00000000},
   1.317 +    {&GUID_Key, 30, 0x80001E0C, 0x00000000},
   1.318 +    {&GUID_Key, 31, 0x80001F0C, 0x00000000},
   1.319 +    {&GUID_Key, 32, 0x8000200C, 0x00000000},
   1.320 +    {&GUID_Key, 33, 0x8000210C, 0x00000000},
   1.321 +    {&GUID_Key, 34, 0x8000220C, 0x00000000},
   1.322 +    {&GUID_Key, 35, 0x8000230C, 0x00000000},
   1.323 +    {&GUID_Key, 36, 0x8000240C, 0x00000000},
   1.324 +    {&GUID_Key, 37, 0x8000250C, 0x00000000},
   1.325 +    {&GUID_Key, 38, 0x8000260C, 0x00000000},
   1.326 +    {&GUID_Key, 39, 0x8000270C, 0x00000000},
   1.327 +    {&GUID_Key, 40, 0x8000280C, 0x00000000},
   1.328 +    {&GUID_Key, 41, 0x8000290C, 0x00000000},
   1.329 +    {&GUID_Key, 42, 0x80002A0C, 0x00000000},
   1.330 +    {&GUID_Key, 43, 0x80002B0C, 0x00000000},
   1.331 +    {&GUID_Key, 44, 0x80002C0C, 0x00000000},
   1.332 +    {&GUID_Key, 45, 0x80002D0C, 0x00000000},
   1.333 +    {&GUID_Key, 46, 0x80002E0C, 0x00000000},
   1.334 +    {&GUID_Key, 47, 0x80002F0C, 0x00000000},
   1.335 +    {&GUID_Key, 48, 0x8000300C, 0x00000000},
   1.336 +    {&GUID_Key, 49, 0x8000310C, 0x00000000},
   1.337 +    {&GUID_Key, 50, 0x8000320C, 0x00000000},
   1.338 +    {&GUID_Key, 51, 0x8000330C, 0x00000000},
   1.339 +    {&GUID_Key, 52, 0x8000340C, 0x00000000},
   1.340 +    {&GUID_Key, 53, 0x8000350C, 0x00000000},
   1.341 +    {&GUID_Key, 54, 0x8000360C, 0x00000000},
   1.342 +    {&GUID_Key, 55, 0x8000370C, 0x00000000},
   1.343 +    {&GUID_Key, 56, 0x8000380C, 0x00000000},
   1.344 +    {&GUID_Key, 57, 0x8000390C, 0x00000000},
   1.345 +    {&GUID_Key, 58, 0x80003A0C, 0x00000000},
   1.346 +    {&GUID_Key, 59, 0x80003B0C, 0x00000000},
   1.347 +    {&GUID_Key, 60, 0x80003C0C, 0x00000000},
   1.348 +    {&GUID_Key, 61, 0x80003D0C, 0x00000000},
   1.349 +    {&GUID_Key, 62, 0x80003E0C, 0x00000000},
   1.350 +    {&GUID_Key, 63, 0x80003F0C, 0x00000000},
   1.351 +    {&GUID_Key, 64, 0x8000400C, 0x00000000},
   1.352 +    {&GUID_Key, 65, 0x8000410C, 0x00000000},
   1.353 +    {&GUID_Key, 66, 0x8000420C, 0x00000000},
   1.354 +    {&GUID_Key, 67, 0x8000430C, 0x00000000},
   1.355 +    {&GUID_Key, 68, 0x8000440C, 0x00000000},
   1.356 +    {&GUID_Key, 69, 0x8000450C, 0x00000000},
   1.357 +    {&GUID_Key, 70, 0x8000460C, 0x00000000},
   1.358 +    {&GUID_Key, 71, 0x8000470C, 0x00000000},
   1.359 +    {&GUID_Key, 72, 0x8000480C, 0x00000000},
   1.360 +    {&GUID_Key, 73, 0x8000490C, 0x00000000},
   1.361 +    {&GUID_Key, 74, 0x80004A0C, 0x00000000},
   1.362 +    {&GUID_Key, 75, 0x80004B0C, 0x00000000},
   1.363 +    {&GUID_Key, 76, 0x80004C0C, 0x00000000},
   1.364 +    {&GUID_Key, 77, 0x80004D0C, 0x00000000},
   1.365 +    {&GUID_Key, 78, 0x80004E0C, 0x00000000},
   1.366 +    {&GUID_Key, 79, 0x80004F0C, 0x00000000},
   1.367 +    {&GUID_Key, 80, 0x8000500C, 0x00000000},
   1.368 +    {&GUID_Key, 81, 0x8000510C, 0x00000000},
   1.369 +    {&GUID_Key, 82, 0x8000520C, 0x00000000},
   1.370 +    {&GUID_Key, 83, 0x8000530C, 0x00000000},
   1.371 +    {&GUID_Key, 84, 0x8000540C, 0x00000000},
   1.372 +    {&GUID_Key, 85, 0x8000550C, 0x00000000},
   1.373 +    {&GUID_Key, 86, 0x8000560C, 0x00000000},
   1.374 +    {&GUID_Key, 87, 0x8000570C, 0x00000000},
   1.375 +    {&GUID_Key, 88, 0x8000580C, 0x00000000},
   1.376 +    {&GUID_Key, 89, 0x8000590C, 0x00000000},
   1.377 +    {&GUID_Key, 90, 0x80005A0C, 0x00000000},
   1.378 +    {&GUID_Key, 91, 0x80005B0C, 0x00000000},
   1.379 +    {&GUID_Key, 92, 0x80005C0C, 0x00000000},
   1.380 +    {&GUID_Key, 93, 0x80005D0C, 0x00000000},
   1.381 +    {&GUID_Key, 94, 0x80005E0C, 0x00000000},
   1.382 +    {&GUID_Key, 95, 0x80005F0C, 0x00000000},
   1.383 +    {&GUID_Key, 96, 0x8000600C, 0x00000000},
   1.384 +    {&GUID_Key, 97, 0x8000610C, 0x00000000},
   1.385 +    {&GUID_Key, 98, 0x8000620C, 0x00000000},
   1.386 +    {&GUID_Key, 99, 0x8000630C, 0x00000000},
   1.387 +    {&GUID_Key, 100, 0x8000640C, 0x00000000},
   1.388 +    {&GUID_Key, 101, 0x8000650C, 0x00000000},
   1.389 +    {&GUID_Key, 102, 0x8000660C, 0x00000000},
   1.390 +    {&GUID_Key, 103, 0x8000670C, 0x00000000},
   1.391 +    {&GUID_Key, 104, 0x8000680C, 0x00000000},
   1.392 +    {&GUID_Key, 105, 0x8000690C, 0x00000000},
   1.393 +    {&GUID_Key, 106, 0x80006A0C, 0x00000000},
   1.394 +    {&GUID_Key, 107, 0x80006B0C, 0x00000000},
   1.395 +    {&GUID_Key, 108, 0x80006C0C, 0x00000000},
   1.396 +    {&GUID_Key, 109, 0x80006D0C, 0x00000000},
   1.397 +    {&GUID_Key, 110, 0x80006E0C, 0x00000000},
   1.398 +    {&GUID_Key, 111, 0x80006F0C, 0x00000000},
   1.399 +    {&GUID_Key, 112, 0x8000700C, 0x00000000},
   1.400 +    {&GUID_Key, 113, 0x8000710C, 0x00000000},
   1.401 +    {&GUID_Key, 114, 0x8000720C, 0x00000000},
   1.402 +    {&GUID_Key, 115, 0x8000730C, 0x00000000},
   1.403 +    {&GUID_Key, 116, 0x8000740C, 0x00000000},
   1.404 +    {&GUID_Key, 117, 0x8000750C, 0x00000000},
   1.405 +    {&GUID_Key, 118, 0x8000760C, 0x00000000},
   1.406 +    {&GUID_Key, 119, 0x8000770C, 0x00000000},
   1.407 +    {&GUID_Key, 120, 0x8000780C, 0x00000000},
   1.408 +    {&GUID_Key, 121, 0x8000790C, 0x00000000},
   1.409 +    {&GUID_Key, 122, 0x80007A0C, 0x00000000},
   1.410 +    {&GUID_Key, 123, 0x80007B0C, 0x00000000},
   1.411 +    {&GUID_Key, 124, 0x80007C0C, 0x00000000},
   1.412 +    {&GUID_Key, 125, 0x80007D0C, 0x00000000},
   1.413 +    {&GUID_Key, 126, 0x80007E0C, 0x00000000},
   1.414 +    {&GUID_Key, 127, 0x80007F0C, 0x00000000},
   1.415 +    {&GUID_Key, 128, 0x8000800C, 0x00000000},
   1.416 +    {&GUID_Key, 129, 0x8000810C, 0x00000000},
   1.417 +    {&GUID_Key, 130, 0x8000820C, 0x00000000},
   1.418 +    {&GUID_Key, 131, 0x8000830C, 0x00000000},
   1.419 +    {&GUID_Key, 132, 0x8000840C, 0x00000000},
   1.420 +    {&GUID_Key, 133, 0x8000850C, 0x00000000},
   1.421 +    {&GUID_Key, 134, 0x8000860C, 0x00000000},
   1.422 +    {&GUID_Key, 135, 0x8000870C, 0x00000000},
   1.423 +    {&GUID_Key, 136, 0x8000880C, 0x00000000},
   1.424 +    {&GUID_Key, 137, 0x8000890C, 0x00000000},
   1.425 +    {&GUID_Key, 138, 0x80008A0C, 0x00000000},
   1.426 +    {&GUID_Key, 139, 0x80008B0C, 0x00000000},
   1.427 +    {&GUID_Key, 140, 0x80008C0C, 0x00000000},
   1.428 +    {&GUID_Key, 141, 0x80008D0C, 0x00000000},
   1.429 +    {&GUID_Key, 142, 0x80008E0C, 0x00000000},
   1.430 +    {&GUID_Key, 143, 0x80008F0C, 0x00000000},
   1.431 +    {&GUID_Key, 144, 0x8000900C, 0x00000000},
   1.432 +    {&GUID_Key, 145, 0x8000910C, 0x00000000},
   1.433 +    {&GUID_Key, 146, 0x8000920C, 0x00000000},
   1.434 +    {&GUID_Key, 147, 0x8000930C, 0x00000000},
   1.435 +    {&GUID_Key, 148, 0x8000940C, 0x00000000},
   1.436 +    {&GUID_Key, 149, 0x8000950C, 0x00000000},
   1.437 +    {&GUID_Key, 150, 0x8000960C, 0x00000000},
   1.438 +    {&GUID_Key, 151, 0x8000970C, 0x00000000},
   1.439 +    {&GUID_Key, 152, 0x8000980C, 0x00000000},
   1.440 +    {&GUID_Key, 153, 0x8000990C, 0x00000000},
   1.441 +    {&GUID_Key, 154, 0x80009A0C, 0x00000000},
   1.442 +    {&GUID_Key, 155, 0x80009B0C, 0x00000000},
   1.443 +    {&GUID_Key, 156, 0x80009C0C, 0x00000000},
   1.444 +    {&GUID_Key, 157, 0x80009D0C, 0x00000000},
   1.445 +    {&GUID_Key, 158, 0x80009E0C, 0x00000000},
   1.446 +    {&GUID_Key, 159, 0x80009F0C, 0x00000000},
   1.447 +    {&GUID_Key, 160, 0x8000A00C, 0x00000000},
   1.448 +    {&GUID_Key, 161, 0x8000A10C, 0x00000000},
   1.449 +    {&GUID_Key, 162, 0x8000A20C, 0x00000000},
   1.450 +    {&GUID_Key, 163, 0x8000A30C, 0x00000000},
   1.451 +    {&GUID_Key, 164, 0x8000A40C, 0x00000000},
   1.452 +    {&GUID_Key, 165, 0x8000A50C, 0x00000000},
   1.453 +    {&GUID_Key, 166, 0x8000A60C, 0x00000000},
   1.454 +    {&GUID_Key, 167, 0x8000A70C, 0x00000000},
   1.455 +    {&GUID_Key, 168, 0x8000A80C, 0x00000000},
   1.456 +    {&GUID_Key, 169, 0x8000A90C, 0x00000000},
   1.457 +    {&GUID_Key, 170, 0x8000AA0C, 0x00000000},
   1.458 +    {&GUID_Key, 171, 0x8000AB0C, 0x00000000},
   1.459 +    {&GUID_Key, 172, 0x8000AC0C, 0x00000000},
   1.460 +    {&GUID_Key, 173, 0x8000AD0C, 0x00000000},
   1.461 +    {&GUID_Key, 174, 0x8000AE0C, 0x00000000},
   1.462 +    {&GUID_Key, 175, 0x8000AF0C, 0x00000000},
   1.463 +    {&GUID_Key, 176, 0x8000B00C, 0x00000000},
   1.464 +    {&GUID_Key, 177, 0x8000B10C, 0x00000000},
   1.465 +    {&GUID_Key, 178, 0x8000B20C, 0x00000000},
   1.466 +    {&GUID_Key, 179, 0x8000B30C, 0x00000000},
   1.467 +    {&GUID_Key, 180, 0x8000B40C, 0x00000000},
   1.468 +    {&GUID_Key, 181, 0x8000B50C, 0x00000000},
   1.469 +    {&GUID_Key, 182, 0x8000B60C, 0x00000000},
   1.470 +    {&GUID_Key, 183, 0x8000B70C, 0x00000000},
   1.471 +    {&GUID_Key, 184, 0x8000B80C, 0x00000000},
   1.472 +    {&GUID_Key, 185, 0x8000B90C, 0x00000000},
   1.473 +    {&GUID_Key, 186, 0x8000BA0C, 0x00000000},
   1.474 +    {&GUID_Key, 187, 0x8000BB0C, 0x00000000},
   1.475 +    {&GUID_Key, 188, 0x8000BC0C, 0x00000000},
   1.476 +    {&GUID_Key, 189, 0x8000BD0C, 0x00000000},
   1.477 +    {&GUID_Key, 190, 0x8000BE0C, 0x00000000},
   1.478 +    {&GUID_Key, 191, 0x8000BF0C, 0x00000000},
   1.479 +    {&GUID_Key, 192, 0x8000C00C, 0x00000000},
   1.480 +    {&GUID_Key, 193, 0x8000C10C, 0x00000000},
   1.481 +    {&GUID_Key, 194, 0x8000C20C, 0x00000000},
   1.482 +    {&GUID_Key, 195, 0x8000C30C, 0x00000000},
   1.483 +    {&GUID_Key, 196, 0x8000C40C, 0x00000000},
   1.484 +    {&GUID_Key, 197, 0x8000C50C, 0x00000000},
   1.485 +    {&GUID_Key, 198, 0x8000C60C, 0x00000000},
   1.486 +    {&GUID_Key, 199, 0x8000C70C, 0x00000000},
   1.487 +    {&GUID_Key, 200, 0x8000C80C, 0x00000000},
   1.488 +    {&GUID_Key, 201, 0x8000C90C, 0x00000000},
   1.489 +    {&GUID_Key, 202, 0x8000CA0C, 0x00000000},
   1.490 +    {&GUID_Key, 203, 0x8000CB0C, 0x00000000},
   1.491 +    {&GUID_Key, 204, 0x8000CC0C, 0x00000000},
   1.492 +    {&GUID_Key, 205, 0x8000CD0C, 0x00000000},
   1.493 +    {&GUID_Key, 206, 0x8000CE0C, 0x00000000},
   1.494 +    {&GUID_Key, 207, 0x8000CF0C, 0x00000000},
   1.495 +    {&GUID_Key, 208, 0x8000D00C, 0x00000000},
   1.496 +    {&GUID_Key, 209, 0x8000D10C, 0x00000000},
   1.497 +    {&GUID_Key, 210, 0x8000D20C, 0x00000000},
   1.498 +    {&GUID_Key, 211, 0x8000D30C, 0x00000000},
   1.499 +    {&GUID_Key, 212, 0x8000D40C, 0x00000000},
   1.500 +    {&GUID_Key, 213, 0x8000D50C, 0x00000000},
   1.501 +    {&GUID_Key, 214, 0x8000D60C, 0x00000000},
   1.502 +    {&GUID_Key, 215, 0x8000D70C, 0x00000000},
   1.503 +    {&GUID_Key, 216, 0x8000D80C, 0x00000000},
   1.504 +    {&GUID_Key, 217, 0x8000D90C, 0x00000000},
   1.505 +    {&GUID_Key, 218, 0x8000DA0C, 0x00000000},
   1.506 +    {&GUID_Key, 219, 0x8000DB0C, 0x00000000},
   1.507 +    {&GUID_Key, 220, 0x8000DC0C, 0x00000000},
   1.508 +    {&GUID_Key, 221, 0x8000DD0C, 0x00000000},
   1.509 +    {&GUID_Key, 222, 0x8000DE0C, 0x00000000},
   1.510 +    {&GUID_Key, 223, 0x8000DF0C, 0x00000000},
   1.511 +    {&GUID_Key, 224, 0x8000E00C, 0x00000000},
   1.512 +    {&GUID_Key, 225, 0x8000E10C, 0x00000000},
   1.513 +    {&GUID_Key, 226, 0x8000E20C, 0x00000000},
   1.514 +    {&GUID_Key, 227, 0x8000E30C, 0x00000000},
   1.515 +    {&GUID_Key, 228, 0x8000E40C, 0x00000000},
   1.516 +    {&GUID_Key, 229, 0x8000E50C, 0x00000000},
   1.517 +    {&GUID_Key, 230, 0x8000E60C, 0x00000000},
   1.518 +    {&GUID_Key, 231, 0x8000E70C, 0x00000000},
   1.519 +    {&GUID_Key, 232, 0x8000E80C, 0x00000000},
   1.520 +    {&GUID_Key, 233, 0x8000E90C, 0x00000000},
   1.521 +    {&GUID_Key, 234, 0x8000EA0C, 0x00000000},
   1.522 +    {&GUID_Key, 235, 0x8000EB0C, 0x00000000},
   1.523 +    {&GUID_Key, 236, 0x8000EC0C, 0x00000000},
   1.524 +    {&GUID_Key, 237, 0x8000ED0C, 0x00000000},
   1.525 +    {&GUID_Key, 238, 0x8000EE0C, 0x00000000},
   1.526 +    {&GUID_Key, 239, 0x8000EF0C, 0x00000000},
   1.527 +    {&GUID_Key, 240, 0x8000F00C, 0x00000000},
   1.528 +    {&GUID_Key, 241, 0x8000F10C, 0x00000000},
   1.529 +    {&GUID_Key, 242, 0x8000F20C, 0x00000000},
   1.530 +    {&GUID_Key, 243, 0x8000F30C, 0x00000000},
   1.531 +    {&GUID_Key, 244, 0x8000F40C, 0x00000000},
   1.532 +    {&GUID_Key, 245, 0x8000F50C, 0x00000000},
   1.533 +    {&GUID_Key, 246, 0x8000F60C, 0x00000000},
   1.534 +    {&GUID_Key, 247, 0x8000F70C, 0x00000000},
   1.535 +    {&GUID_Key, 248, 0x8000F80C, 0x00000000},
   1.536 +    {&GUID_Key, 249, 0x8000F90C, 0x00000000},
   1.537 +    {&GUID_Key, 250, 0x8000FA0C, 0x00000000},
   1.538 +    {&GUID_Key, 251, 0x8000FB0C, 0x00000000},
   1.539 +    {&GUID_Key, 252, 0x8000FC0C, 0x00000000},
   1.540 +    {&GUID_Key, 253, 0x8000FD0C, 0x00000000},
   1.541 +    {&GUID_Key, 254, 0x8000FE0C, 0x00000000},
   1.542 +    {&GUID_Key, 255, 0x8000FF0C, 0x00000000},
   1.543  };
   1.544  
   1.545  const DIDATAFORMAT c_dfDIKeyboard = { 24, 16, 0x00000002, 256, 256, KBD_fmt };
   1.546 @@ -338,13 +341,13 @@
   1.547  /* Mouse */
   1.548  
   1.549  static DIOBJECTDATAFORMAT PTR_fmt[] = {
   1.550 -	{ &GUID_XAxis, 0, 0x00FFFF03, 0x00000000 },
   1.551 -	{ &GUID_YAxis, 4, 0x00FFFF03, 0x00000000 },
   1.552 -	{ &GUID_ZAxis, 8, 0x80FFFF03, 0x00000000 },
   1.553 -	{ NULL, 12, 0x00FFFF0C, 0x00000000 },
   1.554 -	{ NULL, 13, 0x00FFFF0C, 0x00000000 },
   1.555 -	{ NULL, 14, 0x80FFFF0C, 0x00000000 },
   1.556 -	{ NULL, 15, 0x80FFFF0C, 0x00000000 },
   1.557 +    {&GUID_XAxis, 0, 0x00FFFF03, 0x00000000},
   1.558 +    {&GUID_YAxis, 4, 0x00FFFF03, 0x00000000},
   1.559 +    {&GUID_ZAxis, 8, 0x80FFFF03, 0x00000000},
   1.560 +    {NULL, 12, 0x00FFFF0C, 0x00000000},
   1.561 +    {NULL, 13, 0x00FFFF0C, 0x00000000},
   1.562 +    {NULL, 14, 0x80FFFF0C, 0x00000000},
   1.563 +    {NULL, 15, 0x80FFFF0C, 0x00000000},
   1.564  };
   1.565  
   1.566  const DIDATAFORMAT c_dfDIMouse = { 24, 16, 0x00000002, 16, 7, PTR_fmt };
   1.567 @@ -353,1785 +356,1854 @@
   1.568  /* Joystick */
   1.569  
   1.570  static DIOBJECTDATAFORMAT JOY_fmt[] = {
   1.571 -	{ &GUID_XAxis, 0, 0x80FFFF03, 0x00000100 },
   1.572 -	{ &GUID_YAxis, 4, 0x80FFFF03, 0x00000100 },
   1.573 -	{ &GUID_ZAxis, 8, 0x80FFFF03, 0x00000100 },
   1.574 -	{ &GUID_RxAxis, 12, 0x80FFFF03, 0x00000100 },
   1.575 -	{ &GUID_RyAxis, 16, 0x80FFFF03, 0x00000100 },
   1.576 -	{ &GUID_RzAxis, 20, 0x80FFFF03, 0x00000100 },
   1.577 -	{ &GUID_Slider, 24, 0x80FFFF03, 0x00000100 },
   1.578 -	{ &GUID_Slider, 28, 0x80FFFF03, 0x00000100 },
   1.579 -	{ &GUID_POV, 32, 0x80FFFF10, 0x00000000 },
   1.580 -	{ &GUID_POV, 36, 0x80FFFF10, 0x00000000 },
   1.581 -	{ &GUID_POV, 40, 0x80FFFF10, 0x00000000 },
   1.582 -	{ &GUID_POV, 44, 0x80FFFF10, 0x00000000 },
   1.583 -	{ NULL, 48, 0x80FFFF0C, 0x00000000 },
   1.584 -	{ NULL, 49, 0x80FFFF0C, 0x00000000 },
   1.585 -	{ NULL, 50, 0x80FFFF0C, 0x00000000 },
   1.586 -	{ NULL, 51, 0x80FFFF0C, 0x00000000 },
   1.587 -	{ NULL, 52, 0x80FFFF0C, 0x00000000 },
   1.588 -	{ NULL, 53, 0x80FFFF0C, 0x00000000 },
   1.589 -	{ NULL, 54, 0x80FFFF0C, 0x00000000 },
   1.590 -	{ NULL, 55, 0x80FFFF0C, 0x00000000 },
   1.591 -	{ NULL, 56, 0x80FFFF0C, 0x00000000 },
   1.592 -	{ NULL, 57, 0x80FFFF0C, 0x00000000 },
   1.593 -	{ NULL, 58, 0x80FFFF0C, 0x00000000 },
   1.594 -	{ NULL, 59, 0x80FFFF0C, 0x00000000 },
   1.595 -	{ NULL, 60, 0x80FFFF0C, 0x00000000 },
   1.596 -	{ NULL, 61, 0x80FFFF0C, 0x00000000 },
   1.597 -	{ NULL, 62, 0x80FFFF0C, 0x00000000 },
   1.598 -	{ NULL, 63, 0x80FFFF0C, 0x00000000 },
   1.599 -	{ NULL, 64, 0x80FFFF0C, 0x00000000 },
   1.600 -	{ NULL, 65, 0x80FFFF0C, 0x00000000 },
   1.601 -	{ NULL, 66, 0x80FFFF0C, 0x00000000 },
   1.602 -	{ NULL, 67, 0x80FFFF0C, 0x00000000 },
   1.603 -	{ NULL, 68, 0x80FFFF0C, 0x00000000 },
   1.604 -	{ NULL, 69, 0x80FFFF0C, 0x00000000 },
   1.605 -	{ NULL, 70, 0x80FFFF0C, 0x00000000 },
   1.606 -	{ NULL, 71, 0x80FFFF0C, 0x00000000 },
   1.607 -	{ NULL, 72, 0x80FFFF0C, 0x00000000 },
   1.608 -	{ NULL, 73, 0x80FFFF0C, 0x00000000 },
   1.609 -	{ NULL, 74, 0x80FFFF0C, 0x00000000 },
   1.610 -	{ NULL, 75, 0x80FFFF0C, 0x00000000 },
   1.611 -	{ NULL, 76, 0x80FFFF0C, 0x00000000 },
   1.612 -	{ NULL, 77, 0x80FFFF0C, 0x00000000 },
   1.613 -	{ NULL, 78, 0x80FFFF0C, 0x00000000 },
   1.614 -	{ NULL, 79, 0x80FFFF0C, 0x00000000 },
   1.615 +    {&GUID_XAxis, 0, 0x80FFFF03, 0x00000100},
   1.616 +    {&GUID_YAxis, 4, 0x80FFFF03, 0x00000100},
   1.617 +    {&GUID_ZAxis, 8, 0x80FFFF03, 0x00000100},
   1.618 +    {&GUID_RxAxis, 12, 0x80FFFF03, 0x00000100},
   1.619 +    {&GUID_RyAxis, 16, 0x80FFFF03, 0x00000100},
   1.620 +    {&GUID_RzAxis, 20, 0x80FFFF03, 0x00000100},
   1.621 +    {&GUID_Slider, 24, 0x80FFFF03, 0x00000100},
   1.622 +    {&GUID_Slider, 28, 0x80FFFF03, 0x00000100},
   1.623 +    {&GUID_POV, 32, 0x80FFFF10, 0x00000000},
   1.624 +    {&GUID_POV, 36, 0x80FFFF10, 0x00000000},
   1.625 +    {&GUID_POV, 40, 0x80FFFF10, 0x00000000},
   1.626 +    {&GUID_POV, 44, 0x80FFFF10, 0x00000000},
   1.627 +    {NULL, 48, 0x80FFFF0C, 0x00000000},
   1.628 +    {NULL, 49, 0x80FFFF0C, 0x00000000},
   1.629 +    {NULL, 50, 0x80FFFF0C, 0x00000000},
   1.630 +    {NULL, 51, 0x80FFFF0C, 0x00000000},
   1.631 +    {NULL, 52, 0x80FFFF0C, 0x00000000},
   1.632 +    {NULL, 53, 0x80FFFF0C, 0x00000000},
   1.633 +    {NULL, 54, 0x80FFFF0C, 0x00000000},
   1.634 +    {NULL, 55, 0x80FFFF0C, 0x00000000},
   1.635 +    {NULL, 56, 0x80FFFF0C, 0x00000000},
   1.636 +    {NULL, 57, 0x80FFFF0C, 0x00000000},
   1.637 +    {NULL, 58, 0x80FFFF0C, 0x00000000},
   1.638 +    {NULL, 59, 0x80FFFF0C, 0x00000000},
   1.639 +    {NULL, 60, 0x80FFFF0C, 0x00000000},
   1.640 +    {NULL, 61, 0x80FFFF0C, 0x00000000},
   1.641 +    {NULL, 62, 0x80FFFF0C, 0x00000000},
   1.642 +    {NULL, 63, 0x80FFFF0C, 0x00000000},
   1.643 +    {NULL, 64, 0x80FFFF0C, 0x00000000},
   1.644 +    {NULL, 65, 0x80FFFF0C, 0x00000000},
   1.645 +    {NULL, 66, 0x80FFFF0C, 0x00000000},
   1.646 +    {NULL, 67, 0x80FFFF0C, 0x00000000},
   1.647 +    {NULL, 68, 0x80FFFF0C, 0x00000000},
   1.648 +    {NULL, 69, 0x80FFFF0C, 0x00000000},
   1.649 +    {NULL, 70, 0x80FFFF0C, 0x00000000},
   1.650 +    {NULL, 71, 0x80FFFF0C, 0x00000000},
   1.651 +    {NULL, 72, 0x80FFFF0C, 0x00000000},
   1.652 +    {NULL, 73, 0x80FFFF0C, 0x00000000},
   1.653 +    {NULL, 74, 0x80FFFF0C, 0x00000000},
   1.654 +    {NULL, 75, 0x80FFFF0C, 0x00000000},
   1.655 +    {NULL, 76, 0x80FFFF0C, 0x00000000},
   1.656 +    {NULL, 77, 0x80FFFF0C, 0x00000000},
   1.657 +    {NULL, 78, 0x80FFFF0C, 0x00000000},
   1.658 +    {NULL, 79, 0x80FFFF0C, 0x00000000},
   1.659  };
   1.660  
   1.661  const DIDATAFORMAT c_dfDIJoystick = { 24, 16, 0x00000001, 80, 44, JOY_fmt };
   1.662  
   1.663  
   1.664  /* Initialization/Query functions */
   1.665 -static int DX5_VideoInit(_THIS, SDL_PixelFormat *vformat);
   1.666 -static SDL_Rect **DX5_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   1.667 -static SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   1.668 -static int DX5_SetColors(_THIS, int firstcolor, int ncolors,
   1.669 -			 SDL_Color *colors);
   1.670 -static int DX5_SetGammaRamp(_THIS, Uint16 *ramp);
   1.671 -static int DX5_GetGammaRamp(_THIS, Uint16 *ramp);
   1.672 -static void DX5_VideoQuit(_THIS);
   1.673 +static int DX5_VideoInit (_THIS, SDL_PixelFormat * vformat);
   1.674 +static SDL_Rect **DX5_ListModes (_THIS, SDL_PixelFormat * format,
   1.675 +                                 Uint32 flags);
   1.676 +static SDL_Surface *DX5_SetVideoMode (_THIS, SDL_Surface * current, int width,
   1.677 +                                      int height, int bpp, Uint32 flags);
   1.678 +static int DX5_SetColors (_THIS, int firstcolor, int ncolors,
   1.679 +                          SDL_Color * colors);
   1.680 +static int DX5_SetGammaRamp (_THIS, Uint16 * ramp);
   1.681 +static int DX5_GetGammaRamp (_THIS, Uint16 * ramp);
   1.682 +static void DX5_VideoQuit (_THIS);
   1.683  
   1.684  /* Hardware surface functions */
   1.685 -static int DX5_AllocHWSurface(_THIS, SDL_Surface *surface);
   1.686 -static int DX5_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst);
   1.687 -static int DX5_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
   1.688 -static int DX5_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key);
   1.689 -static int DX5_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha);
   1.690 -static int DX5_LockHWSurface(_THIS, SDL_Surface *surface);
   1.691 -static void DX5_UnlockHWSurface(_THIS, SDL_Surface *surface);
   1.692 -static int DX5_FlipHWSurface(_THIS, SDL_Surface *surface);
   1.693 -static void DX5_FreeHWSurface(_THIS, SDL_Surface *surface);
   1.694 +static int DX5_AllocHWSurface (_THIS, SDL_Surface * surface);
   1.695 +static int DX5_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst);
   1.696 +static int DX5_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect,
   1.697 +                           Uint32 color);
   1.698 +static int DX5_SetHWColorKey (_THIS, SDL_Surface * surface, Uint32 key);
   1.699 +static int DX5_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha);
   1.700 +static int DX5_LockHWSurface (_THIS, SDL_Surface * surface);
   1.701 +static void DX5_UnlockHWSurface (_THIS, SDL_Surface * surface);
   1.702 +static int DX5_FlipHWSurface (_THIS, SDL_Surface * surface);
   1.703 +static void DX5_FreeHWSurface (_THIS, SDL_Surface * surface);
   1.704  
   1.705 -static int DX5_AllocDDSurface(_THIS, SDL_Surface *surface, 
   1.706 -				LPDIRECTDRAWSURFACE3 requested, Uint32 flag);
   1.707 +static int DX5_AllocDDSurface (_THIS, SDL_Surface * surface,
   1.708 +                               LPDIRECTDRAWSURFACE3 requested, Uint32 flag);
   1.709  
   1.710  /* Windows message handling functions */
   1.711 -static void DX5_RealizePalette(_THIS);
   1.712 -static void DX5_PaletteChanged(_THIS, HWND window);
   1.713 -static void DX5_WinPAINT(_THIS, HDC hdc);
   1.714 +static void DX5_RealizePalette (_THIS);
   1.715 +static void DX5_PaletteChanged (_THIS, HWND window);
   1.716 +static void DX5_WinPAINT (_THIS, HDC hdc);
   1.717  
   1.718  /* WinDIB driver functions for manipulating gamma ramps */
   1.719 -extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
   1.720 -extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
   1.721 -extern void DIB_QuitGamma(_THIS);
   1.722 +extern int DIB_SetGammaRamp (_THIS, Uint16 * ramp);
   1.723 +extern int DIB_GetGammaRamp (_THIS, Uint16 * ramp);
   1.724 +extern void DIB_QuitGamma (_THIS);
   1.725  
   1.726  /* Functions for loading the DirectX functions dynamically */
   1.727  static int DX5_loaded = 0;
   1.728  static HINSTANCE DDrawDLL = NULL;
   1.729  static HINSTANCE DInputDLL = NULL;
   1.730  
   1.731 -void DX5_Unload(void)
   1.732 +void
   1.733 +DX5_Unload (void)
   1.734  {
   1.735 -	if ( --DX5_loaded == 0 ) {
   1.736 -		if ( DDrawDLL != NULL ) {
   1.737 -			FreeLibrary(DDrawDLL);
   1.738 -			DDrawCreate = NULL;
   1.739 -			DDrawDLL = NULL;
   1.740 -		}
   1.741 -		if ( DInputDLL != NULL ) {
   1.742 -			FreeLibrary(DInputDLL);
   1.743 -			DInputCreate = NULL;
   1.744 -			DInputDLL = NULL;
   1.745 -		}
   1.746 -	}
   1.747 +    if (--DX5_loaded == 0) {
   1.748 +        if (DDrawDLL != NULL) {
   1.749 +            FreeLibrary (DDrawDLL);
   1.750 +            DDrawCreate = NULL;
   1.751 +            DDrawDLL = NULL;
   1.752 +        }
   1.753 +        if (DInputDLL != NULL) {
   1.754 +            FreeLibrary (DInputDLL);
   1.755 +            DInputCreate = NULL;
   1.756 +            DInputDLL = NULL;
   1.757 +        }
   1.758 +    }
   1.759  }
   1.760 -int DX5_Load(void)
   1.761 +int
   1.762 +DX5_Load (void)
   1.763  {
   1.764 -	int status = 0;
   1.765 +    int status = 0;
   1.766  
   1.767 -	if ( ++DX5_loaded == 1 ) {
   1.768 -		DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
   1.769 -		if ( DDrawDLL != NULL ) {
   1.770 -			DDrawCreate = (void *)GetProcAddress(DDrawDLL,
   1.771 -						TEXT("DirectDrawCreate"));
   1.772 -		}
   1.773 -		DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
   1.774 -		if ( DInputDLL != NULL ) {
   1.775 -			DInputCreate = (void *)GetProcAddress(DInputDLL,
   1.776 -						TEXT("DirectInputCreateA"));
   1.777 -		}
   1.778 -		if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
   1.779 -			status = 0;
   1.780 -		} else {
   1.781 -			DX5_Unload();
   1.782 -			status = -1;
   1.783 -		}
   1.784 -	}
   1.785 -	return status;
   1.786 +    if (++DX5_loaded == 1) {
   1.787 +        DDrawDLL = LoadLibrary (TEXT ("DDRAW.DLL"));
   1.788 +        if (DDrawDLL != NULL) {
   1.789 +            DDrawCreate = (void *) GetProcAddress (DDrawDLL,
   1.790 +                                                   TEXT ("DirectDrawCreate"));
   1.791 +        }
   1.792 +        DInputDLL = LoadLibrary (TEXT ("DINPUT.DLL"));
   1.793 +        if (DInputDLL != NULL) {
   1.794 +            DInputCreate = (void *) GetProcAddress (DInputDLL,
   1.795 +                                                    TEXT
   1.796 +                                                    ("DirectInputCreateA"));
   1.797 +        }
   1.798 +        if (DDrawDLL && DDrawCreate && DInputDLL && DInputCreate) {
   1.799 +            status = 0;
   1.800 +        } else {
   1.801 +            DX5_Unload ();
   1.802 +            status = -1;
   1.803 +        }
   1.804 +    }
   1.805 +    return status;
   1.806  }
   1.807  
   1.808  /* DX5 driver bootstrap functions */
   1.809  
   1.810 -static int DX5_Available(void)
   1.811 +static int
   1.812 +DX5_Available (void)
   1.813  {
   1.814 -	int ddraw_ok = 0;
   1.815 -	HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
   1.816 -	LPDIRECTDRAW DDraw;
   1.817 +    int ddraw_ok = 0;
   1.818 +    HRESULT (WINAPI * DDrawCreate) (GUID *, LPDIRECTDRAW *, IUnknown *);
   1.819 +    LPDIRECTDRAW DDraw;
   1.820  
   1.821 -	/* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
   1.822 -	if ( DX5_Load() < 0 ) {
   1.823 -		return -1;
   1.824 -	}
   1.825 +    /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
   1.826 +    if (DX5_Load () < 0) {
   1.827 +        return -1;
   1.828 +    }
   1.829  
   1.830 -	/* Try to create a valid DirectDraw object */
   1.831 -	DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
   1.832 -	if ( (DDrawCreate != NULL)
   1.833 -			&& !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
   1.834 -	  if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
   1.835 -							NULL, DDSCL_NORMAL)) ) {
   1.836 -	    DDSURFACEDESC desc;
   1.837 -	    LPDIRECTDRAWSURFACE  DDrawSurf;
   1.838 -	    LPDIRECTDRAWSURFACE3 DDrawSurf3;
   1.839 +    /* Try to create a valid DirectDraw object */
   1.840 +    DDrawCreate =
   1.841 +        (void *) GetProcAddress (DDrawDLL, TEXT ("DirectDrawCreate"));
   1.842 +    if ((DDrawCreate != NULL) && !FAILED (DDrawCreate (NULL, &DDraw, NULL))) {
   1.843 +        if (!FAILED (IDirectDraw_SetCooperativeLevel (DDraw,
   1.844 +                                                      NULL, DDSCL_NORMAL))) {
   1.845 +            DDSURFACEDESC desc;
   1.846 +            LPDIRECTDRAWSURFACE DDrawSurf;
   1.847 +            LPDIRECTDRAWSURFACE3 DDrawSurf3;
   1.848  
   1.849 -	    /* Try to create a DirectDrawSurface3 object */
   1.850 -	    SDL_memset(&desc, 0, sizeof(desc));
   1.851 -	    desc.dwSize = sizeof(desc);
   1.852 -	    desc.dwFlags = DDSD_CAPS;
   1.853 -	    desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
   1.854 -	    if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
   1.855 -							&DDrawSurf, NULL)) ) {
   1.856 -	      if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
   1.857 -			&IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) {
   1.858 -	        /* Yay! */
   1.859 -		ddraw_ok = 1;
   1.860 +            /* Try to create a DirectDrawSurface3 object */
   1.861 +            SDL_memset (&desc, 0, sizeof (desc));
   1.862 +            desc.dwSize = sizeof (desc);
   1.863 +            desc.dwFlags = DDSD_CAPS;
   1.864 +            desc.ddsCaps.dwCaps =
   1.865 +                DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY;
   1.866 +            if (!FAILED
   1.867 +                (IDirectDraw_CreateSurface
   1.868 +                 (DDraw, &desc, &DDrawSurf, NULL))) {
   1.869 +                if (!FAILED
   1.870 +                    (IDirectDrawSurface_QueryInterface
   1.871 +                     (DDrawSurf, &IID_IDirectDrawSurface3,
   1.872 +                      (LPVOID *) & DDrawSurf3))) {
   1.873 +                    /* Yay! */
   1.874 +                    ddraw_ok = 1;
   1.875  
   1.876 -	        /* Clean up.. */
   1.877 -	        IDirectDrawSurface3_Release(DDrawSurf3);
   1.878 -	      }
   1.879 -	      IDirectDrawSurface_Release(DDrawSurf);
   1.880 -	    }
   1.881 -	  }
   1.882 -	  IDirectDraw_Release(DDraw);
   1.883 -	}
   1.884 +                    /* Clean up.. */
   1.885 +                    IDirectDrawSurface3_Release (DDrawSurf3);
   1.886 +                }
   1.887 +                IDirectDrawSurface_Release (DDrawSurf);
   1.888 +            }
   1.889 +        }
   1.890 +        IDirectDraw_Release (DDraw);
   1.891 +    }
   1.892  
   1.893 -	DX5_Unload();
   1.894 +    DX5_Unload ();
   1.895  
   1.896 -	return ddraw_ok;
   1.897 +    return ddraw_ok;
   1.898  }
   1.899  
   1.900 -static void DX5_DeleteDevice(SDL_VideoDevice *this)
   1.901 +static void
   1.902 +DX5_DeleteDevice (SDL_VideoDevice * this)
   1.903  {
   1.904 -	/* Free DirectDraw object */
   1.905 -	if ( ddraw2 != NULL ) {
   1.906 -		IDirectDraw2_Release(ddraw2);
   1.907 -	}
   1.908 -	DX5_Unload();
   1.909 +    /* Free DirectDraw object */
   1.910 +    if (ddraw2 != NULL) {
   1.911 +        IDirectDraw2_Release (ddraw2);
   1.912 +    }
   1.913 +    DX5_Unload ();
   1.914  
   1.915 -	if ( this ) {
   1.916 -		if ( this->hidden ) {
   1.917 -			SDL_free(this->hidden);
   1.918 -		}
   1.919 -		if ( this->gl_data ) {
   1.920 -			SDL_free(this->gl_data);
   1.921 -		}
   1.922 -		SDL_free(this);
   1.923 -	}
   1.924 +    if (this) {
   1.925 +        if (this->hidden) {
   1.926 +            SDL_free (this->hidden);
   1.927 +        }
   1.928 +        if (this->gl_data) {
   1.929 +            SDL_free (this->gl_data);
   1.930 +        }
   1.931 +        SDL_free (this);
   1.932 +    }
   1.933  }
   1.934  
   1.935 -static SDL_VideoDevice *DX5_CreateDevice(int devindex)
   1.936 +static SDL_VideoDevice *
   1.937 +DX5_CreateDevice (int devindex)
   1.938  {
   1.939 -	SDL_VideoDevice *device;
   1.940 +    SDL_VideoDevice *device;
   1.941  
   1.942 -	/* Load DirectX */
   1.943 -	if ( DX5_Load() < 0 ) {
   1.944 -		return(NULL);
   1.945 -	}
   1.946 +    /* Load DirectX */
   1.947 +    if (DX5_Load () < 0) {
   1.948 +        return (NULL);
   1.949 +    }
   1.950  
   1.951 -	/* Initialize all variables that we clean on shutdown */
   1.952 -	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
   1.953 -	if ( device ) {
   1.954 -		SDL_memset(device, 0, (sizeof *device));
   1.955 -		device->hidden = (struct SDL_PrivateVideoData *)
   1.956 -				SDL_malloc((sizeof *device->hidden));
   1.957 -		device->gl_data = (struct SDL_PrivateGLData *)
   1.958 -				SDL_malloc((sizeof *device->gl_data));
   1.959 -	}
   1.960 -	if ( (device == NULL) || (device->hidden == NULL) ||
   1.961 -		                 (device->gl_data == NULL) ) {
   1.962 -		SDL_OutOfMemory();
   1.963 -		DX5_DeleteDevice(device);
   1.964 -		return(NULL);
   1.965 -	}
   1.966 -	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
   1.967 -	SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
   1.968 +    /* Initialize all variables that we clean on shutdown */
   1.969 +    device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
   1.970 +    if (device) {
   1.971 +        SDL_memset (device, 0, (sizeof *device));
   1.972 +        device->hidden = (struct SDL_PrivateVideoData *)
   1.973 +            SDL_malloc ((sizeof *device->hidden));
   1.974 +        device->gl_data = (struct SDL_PrivateGLData *)
   1.975 +            SDL_malloc ((sizeof *device->gl_data));
   1.976 +    }
   1.977 +    if ((device == NULL) || (device->hidden == NULL) ||
   1.978 +        (device->gl_data == NULL)) {
   1.979 +        SDL_OutOfMemory ();
   1.980 +        DX5_DeleteDevice (device);
   1.981 +        return (NULL);
   1.982 +    }
   1.983 +    SDL_memset (device->hidden, 0, (sizeof *device->hidden));
   1.984 +    SDL_memset (device->gl_data, 0, (sizeof *device->gl_data));
   1.985  
   1.986 -	/* Set the function pointers */
   1.987 -	device->VideoInit = DX5_VideoInit;
   1.988 -	device->ListModes = DX5_ListModes;
   1.989 -	device->SetVideoMode = DX5_SetVideoMode;
   1.990 -	device->UpdateMouse = WIN_UpdateMouse;
   1.991 -	device->CreateYUVOverlay = DX5_CreateYUVOverlay;
   1.992 -	device->SetColors = DX5_SetColors;
   1.993 -	device->UpdateRects = NULL;
   1.994 -	device->VideoQuit = DX5_VideoQuit;
   1.995 -	device->AllocHWSurface = DX5_AllocHWSurface;
   1.996 -	device->CheckHWBlit = DX5_CheckHWBlit;
   1.997 -	device->FillHWRect = DX5_FillHWRect;
   1.998 -	device->SetHWColorKey = DX5_SetHWColorKey;
   1.999 -	device->SetHWAlpha = DX5_SetHWAlpha;
  1.1000 -	device->LockHWSurface = DX5_LockHWSurface;
  1.1001 -	device->UnlockHWSurface = DX5_UnlockHWSurface;
  1.1002 -	device->FlipHWSurface = DX5_FlipHWSurface;
  1.1003 -	device->FreeHWSurface = DX5_FreeHWSurface;
  1.1004 -	device->SetGammaRamp = DX5_SetGammaRamp;
  1.1005 -	device->GetGammaRamp = DX5_GetGammaRamp;
  1.1006 +    /* Set the function pointers */
  1.1007 +    device->VideoInit = DX5_VideoInit;
  1.1008 +    device->ListModes = DX5_ListModes;
  1.1009 +    device->SetVideoMode = DX5_SetVideoMode;
  1.1010 +    device->UpdateMouse = WIN_UpdateMouse;
  1.1011 +    device->CreateYUVOverlay = DX5_CreateYUVOverlay;
  1.1012 +    device->SetColors = DX5_SetColors;
  1.1013 +    device->UpdateRects = NULL;
  1.1014 +    device->VideoQuit = DX5_VideoQuit;
  1.1015 +    device->AllocHWSurface = DX5_AllocHWSurface;
  1.1016 +    device->CheckHWBlit = DX5_CheckHWBlit;
  1.1017 +    device->FillHWRect = DX5_FillHWRect;
  1.1018 +    device->SetHWColorKey = DX5_SetHWColorKey;
  1.1019 +    device->SetHWAlpha = DX5_SetHWAlpha;
  1.1020 +    device->LockHWSurface = DX5_LockHWSurface;
  1.1021 +    device->UnlockHWSurface = DX5_UnlockHWSurface;
  1.1022 +    device->FlipHWSurface = DX5_FlipHWSurface;
  1.1023 +    device->FreeHWSurface = DX5_FreeHWSurface;
  1.1024 +    device->SetGammaRamp = DX5_SetGammaRamp;
  1.1025 +    device->GetGammaRamp = DX5_GetGammaRamp;
  1.1026  #if SDL_VIDEO_OPENGL
  1.1027 -	device->GL_LoadLibrary = WIN_GL_LoadLibrary;
  1.1028 -	device->GL_GetProcAddress = WIN_GL_GetProcAddress;
  1.1029 -	device->GL_GetAttribute = WIN_GL_GetAttribute;
  1.1030 -	device->GL_MakeCurrent = WIN_GL_MakeCurrent;
  1.1031 -	device->GL_SwapBuffers = WIN_GL_SwapBuffers;
  1.1032 +    device->GL_LoadLibrary = WIN_GL_LoadLibrary;
  1.1033 +    device->GL_GetProcAddress = WIN_GL_GetProcAddress;
  1.1034 +    device->GL_GetAttribute = WIN_GL_GetAttribute;
  1.1035 +    device->GL_MakeCurrent = WIN_GL_MakeCurrent;
  1.1036 +    device->GL_SwapBuffers = WIN_GL_SwapBuffers;
  1.1037  #endif
  1.1038 -	device->SetCaption = WIN_SetWMCaption;
  1.1039 -	device->SetIcon = WIN_SetWMIcon;
  1.1040 -	device->IconifyWindow = WIN_IconifyWindow;
  1.1041 -	device->GrabInput = WIN_GrabInput;
  1.1042 -	device->GetWMInfo = WIN_GetWMInfo;
  1.1043 -	device->FreeWMCursor = WIN_FreeWMCursor;
  1.1044 -	device->CreateWMCursor = WIN_CreateWMCursor;
  1.1045 -	device->ShowWMCursor = WIN_ShowWMCursor;
  1.1046 -	device->WarpWMCursor = WIN_WarpWMCursor;
  1.1047 -	device->CheckMouseMode = WIN_CheckMouseMode;
  1.1048 -	device->InitOSKeymap = DX5_InitOSKeymap;
  1.1049 -	device->PumpEvents = DX5_PumpEvents;
  1.1050 +    device->SetCaption = WIN_SetWMCaption;
  1.1051 +    device->SetIcon = WIN_SetWMIcon;
  1.1052 +    device->IconifyWindow = WIN_IconifyWindow;
  1.1053 +    device->GrabInput = WIN_GrabInput;
  1.1054 +    device->GetWMInfo = WIN_GetWMInfo;
  1.1055 +    device->FreeWMCursor = WIN_FreeWMCursor;
  1.1056 +    device->CreateWMCursor = WIN_CreateWMCursor;
  1.1057 +    device->ShowWMCursor = WIN_ShowWMCursor;
  1.1058 +    device->WarpWMCursor = WIN_WarpWMCursor;
  1.1059 +    device->CheckMouseMode = WIN_CheckMouseMode;
  1.1060 +    device->InitOSKeymap = DX5_InitOSKeymap;
  1.1061 +    device->PumpEvents = DX5_PumpEvents;
  1.1062  
  1.1063 -	/* Set up the windows message handling functions */
  1.1064 -	WIN_RealizePalette = DX5_RealizePalette;
  1.1065 -	WIN_PaletteChanged = DX5_PaletteChanged;
  1.1066 -	WIN_WinPAINT = DX5_WinPAINT;
  1.1067 -	HandleMessage = DX5_HandleMessage;
  1.1068 +    /* Set up the windows message handling functions */
  1.1069 +    WIN_RealizePalette = DX5_RealizePalette;
  1.1070 +    WIN_PaletteChanged = DX5_PaletteChanged;
  1.1071 +    WIN_WinPAINT = DX5_WinPAINT;
  1.1072 +    HandleMessage = DX5_HandleMessage;
  1.1073  
  1.1074 -	device->free = DX5_DeleteDevice;
  1.1075 +    device->free = DX5_DeleteDevice;
  1.1076  
  1.1077 -	/* We're finally ready */
  1.1078 -	return device;
  1.1079 +    /* We're finally ready */
  1.1080 +    return device;
  1.1081  }
  1.1082  
  1.1083  VideoBootStrap DIRECTX_bootstrap = {
  1.1084 -	"directx", "Win95/98/2000 DirectX",
  1.1085 -	DX5_Available, DX5_CreateDevice
  1.1086 +    "directx", "Win95/98/2000 DirectX",
  1.1087 +    DX5_Available, DX5_CreateDevice
  1.1088  };
  1.1089  
  1.1090 -static int cmpmodes(const void *va, const void *vb)
  1.1091 +static int
  1.1092 +cmpmodes (const void *va, const void *vb)
  1.1093  {
  1.1094 -    SDL_Rect *a = *(SDL_Rect **)va;
  1.1095 -    SDL_Rect *b = *(SDL_Rect **)vb;
  1.1096 -    if ( a->w == b->w )
  1.1097 +    SDL_Rect *a = *(SDL_Rect **) va;
  1.1098 +    SDL_Rect *b = *(SDL_Rect **) vb;
  1.1099 +    if (a->w == b->w)
  1.1100          return b->h - a->h;
  1.1101      else
  1.1102          return b->w - a->w;
  1.1103  }
  1.1104  
  1.1105 -static HRESULT WINAPI EnumModes2(DDSURFACEDESC *desc, VOID *udata)
  1.1106 +static HRESULT WINAPI
  1.1107 +EnumModes2 (DDSURFACEDESC * desc, VOID * udata)
  1.1108  {
  1.1109 -	SDL_VideoDevice *this = (SDL_VideoDevice *)udata;
  1.1110 -	struct DX5EnumRect *enumrect;
  1.1111 +    SDL_VideoDevice *this = (SDL_VideoDevice *) udata;
  1.1112 +    struct DX5EnumRect *enumrect;
  1.1113  #if defined(NONAMELESSUNION)
  1.1114 -	int bpp = desc->ddpfPixelFormat.u1.dwRGBBitCount;
  1.1115 -	int refreshRate = desc->u2.dwRefreshRate;
  1.1116 +    int bpp = desc->ddpfPixelFormat.u1.dwRGBBitCount;
  1.1117 +    int refreshRate = desc->u2.dwRefreshRate;
  1.1118  #else
  1.1119 -	int bpp = desc->ddpfPixelFormat.dwRGBBitCount;
  1.1120 -	int refreshRate = desc->dwRefreshRate;
  1.1121 +    int bpp = desc->ddpfPixelFormat.dwRGBBitCount;
  1.1122 +    int refreshRate = desc->dwRefreshRate;
  1.1123  #endif
  1.1124 -	int maxRefreshRate;
  1.1125 +    int maxRefreshRate;
  1.1126  
  1.1127 -	if ( desc->dwWidth <= SDL_desktop_mode.dmPelsWidth &&
  1.1128 -	     desc->dwHeight <= SDL_desktop_mode.dmPelsHeight ) {
  1.1129 -		maxRefreshRate = SDL_desktop_mode.dmDisplayFrequency;
  1.1130 -	} else {
  1.1131 -		maxRefreshRate = 85;	/* safe value? */
  1.1132 -	}
  1.1133 +    if (desc->dwWidth <= SDL_desktop_mode.dmPelsWidth &&
  1.1134 +        desc->dwHeight <= SDL_desktop_mode.dmPelsHeight) {
  1.1135 +        maxRefreshRate = SDL_desktop_mode.dmDisplayFrequency;
  1.1136 +    } else {
  1.1137 +        maxRefreshRate = 85;    /* safe value? */
  1.1138 +    }
  1.1139  
  1.1140 -	switch (bpp)  {
  1.1141 -		case 8:
  1.1142 -		case 16:
  1.1143 -		case 24:
  1.1144 -		case 32:
  1.1145 -			bpp /= 8; --bpp;
  1.1146 -			if ( enumlists[bpp] &&
  1.1147 -			     enumlists[bpp]->r.w == (Uint16)desc->dwWidth &&
  1.1148 -			     enumlists[bpp]->r.h == (Uint16)desc->dwHeight ) {
  1.1149 -				if ( refreshRate > enumlists[bpp]->refreshRate &&
  1.1150 -				     refreshRate <= maxRefreshRate ) {
  1.1151 -					enumlists[bpp]->refreshRate = refreshRate;
  1.1152 +    switch (bpp) {
  1.1153 +    case 8:
  1.1154 +    case 16:
  1.1155 +    case 24:
  1.1156 +    case 32:
  1.1157 +        bpp /= 8;
  1.1158 +        --bpp;
  1.1159 +        if (enumlists[bpp] &&
  1.1160 +            enumlists[bpp]->r.w == (Uint16) desc->dwWidth &&
  1.1161 +            enumlists[bpp]->r.h == (Uint16) desc->dwHeight) {
  1.1162 +            if (refreshRate > enumlists[bpp]->refreshRate &&
  1.1163 +                refreshRate <= maxRefreshRate) {
  1.1164 +                enumlists[bpp]->refreshRate = refreshRate;
  1.1165  #ifdef DDRAW_DEBUG
  1.1166 - fprintf(stderr, "New refresh rate for %d bpp: %dx%d at %d Hz\n", (bpp+1)*8, (int)desc->dwWidth, (int)desc->dwHeight, refreshRate);
  1.1167 +                fprintf (stderr,
  1.1168 +                         "New refresh rate for %d bpp: %dx%d at %d Hz\n",
  1.1169 +                         (bpp + 1) * 8, (int) desc->dwWidth,
  1.1170 +                         (int) desc->dwHeight, refreshRate);
  1.1171  #endif
  1.1172 -				}
  1.1173 -				break;
  1.1174 -			}
  1.1175 -			++SDL_nummodes[bpp];
  1.1176 -			enumrect = (struct DX5EnumRect*)SDL_malloc(sizeof(struct DX5EnumRect));
  1.1177 -			if ( !enumrect ) {
  1.1178 -				SDL_OutOfMemory();
  1.1179 -				return(DDENUMRET_CANCEL);
  1.1180 -			}
  1.1181 -			enumrect->refreshRate = refreshRate;
  1.1182 -			enumrect->r.x = 0;
  1.1183 -			enumrect->r.y = 0;
  1.1184 -			enumrect->r.w = (Uint16)desc->dwWidth;
  1.1185 -			enumrect->r.h = (Uint16)desc->dwHeight;
  1.1186 -			enumrect->next = enumlists[bpp];
  1.1187 -			enumlists[bpp] = enumrect;
  1.1188 +            }
  1.1189 +            break;
  1.1190 +        }
  1.1191 +        ++SDL_nummodes[bpp];
  1.1192 +        enumrect =
  1.1193 +            (struct DX5EnumRect *) SDL_malloc (sizeof (struct DX5EnumRect));
  1.1194 +        if (!enumrect) {
  1.1195 +            SDL_OutOfMemory ();
  1.1196 +            return (DDENUMRET_CANCEL);
  1.1197 +        }
  1.1198 +        enumrect->refreshRate = refreshRate;
  1.1199 +        enumrect->r.x = 0;
  1.1200 +        enumrect->r.y = 0;
  1.1201 +        enumrect->r.w = (Uint16) desc->dwWidth;
  1.1202 +        enumrect->r.h = (Uint16) desc->dwHeight;
  1.1203 +        enumrect->next = enumlists[bpp];
  1.1204 +        enumlists[bpp] = enumrect;
  1.1205  #ifdef DDRAW_DEBUG
  1.1206 - fprintf(stderr, "New mode for %d bpp: %dx%d at %d Hz\n", (bpp+1)*8, (int)desc->dwWidth, (int)desc->dwHeight, refreshRate);
  1.1207 +        fprintf (stderr, "New mode for %d bpp: %dx%d at %d Hz\n",
  1.1208 +                 (bpp + 1) * 8, (int) desc->dwWidth, (int) desc->dwHeight,
  1.1209 +                 refreshRate);
  1.1210  #endif
  1.1211 -			break;
  1.1212 -	}
  1.1213 +        break;
  1.1214 +    }
  1.1215  
  1.1216 -	return(DDENUMRET_OK);
  1.1217 +    return (DDENUMRET_OK);
  1.1218  }
  1.1219  
  1.1220 -void SetDDerror(const char *function, int code)
  1.1221 +void
  1.1222 +SetDDerror (const char *function, int code)
  1.1223  {
  1.1224 -	static char *error;
  1.1225 -	static char  errbuf[1024];
  1.1226 +    static char *error;
  1.1227 +    static char errbuf[1024];
  1.1228  
  1.1229 -	errbuf[0] = 0;
  1.1230 -	switch (code) {
  1.1231 -		case DDERR_GENERIC:
  1.1232 -			error = "Undefined error!";
  1.1233 -			break;
  1.1234 -		case DDERR_EXCEPTION:
  1.1235 -			error = "Exception encountered";
  1.1236 -			break;
  1.1237 -		case DDERR_INVALIDOBJECT:
  1.1238 -			error = "Invalid object";
  1.1239 -			break;
  1.1240 -		case DDERR_INVALIDPARAMS:
  1.1241 -			error = "Invalid parameters";
  1.1242 -			break;
  1.1243 -		case DDERR_NOTFOUND:
  1.1244 -			error = "Object not found";
  1.1245 -			break;
  1.1246 -		case DDERR_INVALIDRECT:
  1.1247 -			error = "Invalid rectangle";
  1.1248 -			break;
  1.1249 -		case DDERR_INVALIDCAPS:
  1.1250 -			error = "Invalid caps member";
  1.1251 -			break;
  1.1252 -		case DDERR_INVALIDPIXELFORMAT:
  1.1253 -			error = "Invalid pixel format";
  1.1254 -			break;
  1.1255 -		case DDERR_OUTOFMEMORY:
  1.1256 -			error = "Out of memory";
  1.1257 -			break;
  1.1258 -		case DDERR_OUTOFVIDEOMEMORY:
  1.1259 -			error = "Out of video memory";
  1.1260 -			break;
  1.1261 -		case DDERR_SURFACEBUSY:
  1.1262 -			error = "Surface busy";
  1.1263 -			break;
  1.1264 -		case DDERR_SURFACELOST:
  1.1265 -			error = "Surface was lost";
  1.1266 -			break;
  1.1267 -		case DDERR_WASSTILLDRAWING:
  1.1268 -			error = "DirectDraw is still drawing";
  1.1269 -			break;
  1.1270 -		case DDERR_INVALIDSURFACETYPE:
  1.1271 -			error = "Invalid surface type";
  1.1272 -			break;
  1.1273 -		case DDERR_NOEXCLUSIVEMODE:
  1.1274 -			error = "Not in exclusive access mode";
  1.1275 -			break;
  1.1276 -		case DDERR_NOPALETTEATTACHED:
  1.1277 -			error = "No palette attached";
  1.1278 -			break;
  1.1279 -		case DDERR_NOPALETTEHW:
  1.1280 -			error = "No palette hardware";
  1.1281 -			break;
  1.1282 -		case DDERR_NOT8BITCOLOR:
  1.1283 -			error = "Not 8-bit color";
  1.1284 -			break;
  1.1285 -		case DDERR_EXCLUSIVEMODEALREADYSET:
  1.1286 -			error = "Exclusive mode was already set";
  1.1287 -			break;
  1.1288 -		case DDERR_HWNDALREADYSET:
  1.1289 -			error = "Window handle already set";
  1.1290 -			break;
  1.1291 -		case DDERR_HWNDSUBCLASSED:
  1.1292 -			error = "Window handle is subclassed";
  1.1293 -			break;
  1.1294 -		case DDERR_NOBLTHW:
  1.1295 -			error = "No blit hardware";
  1.1296 -			break;
  1.1297 -		case DDERR_IMPLICITLYCREATED:
  1.1298 -			error = "Surface was implicitly created";
  1.1299 -			break;
  1.1300 -		case DDERR_INCOMPATIBLEPRIMARY:
  1.1301 -			error = "Incompatible primary surface";
  1.1302 -			break;
  1.1303 -		case DDERR_NOCOOPERATIVELEVELSET:
  1.1304 -			error = "No cooperative level set";
  1.1305 -			break;
  1.1306 -		case DDERR_NODIRECTDRAWHW:
  1.1307 -			error = "No DirectDraw hardware";
  1.1308 -			break;
  1.1309 -		case DDERR_NOEMULATION:
  1.1310 -			error = "No emulation available";
  1.1311 -			break;
  1.1312 -		case DDERR_NOFLIPHW:
  1.1313 -			error = "No flip hardware";
  1.1314 -			break;
  1.1315 -		case DDERR_NOTFLIPPABLE:
  1.1316 -			error = "Surface not flippable";
  1.1317 -			break;
  1.1318 -		case DDERR_PRIMARYSURFACEALREADYEXISTS:
  1.1319 -			error = "Primary surface already exists";
  1.1320 -			break;
  1.1321 -		case DDERR_UNSUPPORTEDMODE:
  1.1322 -			error = "Unsupported mode";
  1.1323 -			break;
  1.1324 -		case DDERR_WRONGMODE:
  1.1325 -			error = "Surface created in different mode";
  1.1326 -			break;
  1.1327 -		case DDERR_UNSUPPORTED:
  1.1328 -			error = "Operation not supported";
  1.1329 -			break;
  1.1330 -		case E_NOINTERFACE:
  1.1331 -			error = "Interface not present";
  1.1332 -			break;
  1.1333 -		default:
  1.1334 -			SDL_snprintf(errbuf, SDL_arraysize(errbuf),
  1.1335 -			         "%s: Unknown DirectDraw error: 0x%x",
  1.1336 -								function, code);
  1.1337 -			break;
  1.1338 -	}
  1.1339 -	if ( ! errbuf[0] ) {
  1.1340 -		SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
  1.1341 -	}
  1.1342 -	SDL_SetError("%s", errbuf);
  1.1343 -	return;
  1.1344 +    errbuf[0] = 0;
  1.1345 +    switch (code) {
  1.1346 +    case DDERR_GENERIC:
  1.1347 +        error = "Undefined error!";
  1.1348 +        break;
  1.1349 +    case DDERR_EXCEPTION:
  1.1350 +        error = "Exception encountered";
  1.1351 +        break;
  1.1352 +    case DDERR_INVALIDOBJECT:
  1.1353 +        error = "Invalid object";
  1.1354 +        break;
  1.1355 +    case DDERR_INVALIDPARAMS:
  1.1356 +        error = "Invalid parameters";
  1.1357 +        break;
  1.1358 +    case DDERR_NOTFOUND:
  1.1359 +        error = "Object not found";
  1.1360 +        break;
  1.1361 +    case DDERR_INVALIDRECT:
  1.1362 +        error = "Invalid rectangle";
  1.1363 +        break;
  1.1364 +    case DDERR_INVALIDCAPS:
  1.1365 +        error = "Invalid caps member";
  1.1366 +        break;
  1.1367 +    case DDERR_INVALIDPIXELFORMAT:
  1.1368 +        error = "Invalid pixel format";
  1.1369 +        break;
  1.1370 +    case DDERR_OUTOFMEMORY:
  1.1371 +        error = "Out of memory";
  1.1372 +        break;
  1.1373 +    case DDERR_OUTOFVIDEOMEMORY:
  1.1374 +        error = "Out of video memory";
  1.1375 +        break;
  1.1376 +    case DDERR_SURFACEBUSY:
  1.1377 +        error = "Surface busy";
  1.1378 +        break;
  1.1379 +    case DDERR_SURFACELOST:
  1.1380 +        error = "Surface was lost";
  1.1381 +        break;
  1.1382 +    case DDERR_WASSTILLDRAWING:
  1.1383 +        error = "DirectDraw is still drawing";
  1.1384 +        break;
  1.1385 +    case DDERR_INVALIDSURFACETYPE:
  1.1386 +        error = "Invalid surface type";
  1.1387 +        break;
  1.1388 +    case DDERR_NOEXCLUSIVEMODE:
  1.1389 +        error = "Not in exclusive access mode";
  1.1390 +        break;
  1.1391 +    case DDERR_NOPALETTEATTACHED:
  1.1392 +        error = "No palette attached";
  1.1393 +        break;
  1.1394 +    case DDERR_NOPALETTEHW:
  1.1395 +        error = "No palette hardware";
  1.1396 +        break;
  1.1397 +    case DDERR_NOT8BITCOLOR:
  1.1398 +        error = "Not 8-bit color";
  1.1399 +        break;
  1.1400 +    case DDERR_EXCLUSIVEMODEALREADYSET:
  1.1401 +        error = "Exclusive mode was already set";
  1.1402 +        break;
  1.1403 +    case DDERR_HWNDALREADYSET:
  1.1404 +        error = "Window handle already set";
  1.1405 +        break;
  1.1406 +    case DDERR_HWNDSUBCLASSED:
  1.1407 +        error = "Window handle is subclassed";
  1.1408 +        break;
  1.1409 +    case DDERR_NOBLTHW:
  1.1410 +        error = "No blit hardware";
  1.1411 +        break;
  1.1412 +    case DDERR_IMPLICITLYCREATED:
  1.1413 +        error = "Surface was implicitly created";
  1.1414 +        break;
  1.1415 +    case DDERR_INCOMPATIBLEPRIMARY:
  1.1416 +        error = "Incompatible primary surface";
  1.1417 +        break;
  1.1418 +    case DDERR_NOCOOPERATIVELEVELSET:
  1.1419 +        error = "No cooperative level set";
  1.1420 +        break;
  1.1421 +    case DDERR_NODIRECTDRAWHW:
  1.1422 +        error = "No DirectDraw hardware";
  1.1423 +        break;
  1.1424 +    case DDERR_NOEMULATION:
  1.1425 +        error = "No emulation available";
  1.1426 +        break;
  1.1427 +    case DDERR_NOFLIPHW:
  1.1428 +        error = "No flip hardware";
  1.1429 +        break;
  1.1430 +    case DDERR_NOTFLIPPABLE:
  1.1431 +        error = "Surface not flippable";
  1.1432 +        break;
  1.1433 +    case DDERR_PRIMARYSURFACEALREADYEXISTS:
  1.1434 +        error = "Primary surface already exists";
  1.1435 +        break;
  1.1436 +    case DDERR_UNSUPPORTEDMODE:
  1.1437 +        error = "Unsupported mode";
  1.1438 +        break;
  1.1439 +    case DDERR_WRONGMODE:
  1.1440 +        error = "Surface created in different mode";
  1.1441 +        break;
  1.1442 +    case DDERR_UNSUPPORTED:
  1.1443 +        error = "Operation not supported";
  1.1444 +        break;
  1.1445 +    case E_NOINTERFACE:
  1.1446 +        error = "Interface not present";
  1.1447 +        break;
  1.1448 +    default:
  1.1449 +        SDL_snprintf (errbuf, SDL_arraysize (errbuf),
  1.1450 +                      "%s: Unknown DirectDraw error: 0x%x", function, code);
  1.1451 +        break;
  1.1452 +    }
  1.1453 +    if (!errbuf[0]) {
  1.1454 +        SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: %s", function,
  1.1455 +                      error);
  1.1456 +    }
  1.1457 +    SDL_SetError ("%s", errbuf);
  1.1458 +    return;
  1.1459  }
  1.1460  
  1.1461  
  1.1462 -static int DX5_UpdateVideoInfo(_THIS)
  1.1463 +static int
  1.1464 +DX5_UpdateVideoInfo (_THIS)
  1.1465  {
  1.1466 -	/* This needs to be DDCAPS_DX5 for the DirectDraw2 interface */
  1.1467 +    /* This needs to be DDCAPS_DX5 for the DirectDraw2 interface */
  1.1468  #if DIRECTDRAW_VERSION <= 0x300
  1.1469  #error Your version of DirectX must be greater than or equal to 5.0
  1.1470  #endif
  1.1471  #ifndef IDirectDrawGammaControl_SetGammaRamp
  1.1472 -	/*if gamma is undefined then we really have directx <= 0x500*/
  1.1473 -	DDCAPS DDCaps;
  1.1474 +    /*if gamma is undefined then we really have directx <= 0x500 */
  1.1475 +    DDCAPS DDCaps;
  1.1476  #else
  1.1477 -	DDCAPS_DX5 DDCaps;
  1.1478 +    DDCAPS_DX5 DDCaps;
  1.1479  #endif
  1.1480 -	HRESULT result;
  1.1481 +    HRESULT result;
  1.1482  
  1.1483 -	/* Fill in our hardware acceleration capabilities */
  1.1484 -	SDL_memset(&DDCaps, 0, sizeof(DDCaps));
  1.1485 -	DDCaps.dwSize = sizeof(DDCaps);
  1.1486 -	result = IDirectDraw2_GetCaps(ddraw2, (DDCAPS *)&DDCaps, NULL);
  1.1487 -	if ( result != DD_OK ) {
  1.1488 -		SetDDerror("DirectDraw2::GetCaps", result);
  1.1489 -		return(-1);
  1.1490 -	}
  1.1491 -	this->info.hw_available = 1;
  1.1492 -	if ( (DDCaps.dwCaps & DDCAPS_BLT) == DDCAPS_BLT ) {
  1.1493 -		this->info.blit_hw = 1;
  1.1494 -	}
  1.1495 -	if ( ((DDCaps.dwCaps & DDCAPS_COLORKEY) == DDCAPS_COLORKEY) &&
  1.1496 -	     ((DDCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT) == DDCKEYCAPS_SRCBLT) ) {
  1.1497 -		this->info.blit_hw_CC = 1;
  1.1498 -	}
  1.1499 -	if ( (DDCaps.dwCaps & DDCAPS_ALPHA) == DDCAPS_ALPHA ) {
  1.1500 -		/* This is only for alpha channel, and DirectX 6
  1.1501 -		   doesn't support 2D alpha blits yet, so set it 0
  1.1502 -		 */
  1.1503 -		this->info.blit_hw_A = 0;
  1.1504 -	}
  1.1505 -	if ( (DDCaps.dwCaps & DDCAPS_CANBLTSYSMEM) == DDCAPS_CANBLTSYSMEM ) {
  1.1506 -		this->info.blit_sw = 1;
  1.1507 -		/* This isn't necessarily true, but the HEL will cover us */
  1.1508 -		this->info.blit_sw_CC = this->info.blit_hw_CC;
  1.1509 -		this->info.blit_sw_A = this->info.blit_hw_A;
  1.1510 -	}
  1.1511 -	if ( (DDCaps.dwCaps & DDCAPS_BLTCOLORFILL) == DDCAPS_BLTCOLORFILL ) {
  1.1512 -		this->info.blit_fill = 1;
  1.1513 -	}
  1.1514 +    /* Fill in our hardware acceleration capabilities */
  1.1515 +    SDL_memset (&DDCaps, 0, sizeof (DDCaps));
  1.1516 +    DDCaps.dwSize = sizeof (DDCaps);
  1.1517 +    result = IDirectDraw2_GetCaps (ddraw2, (DDCAPS *) & DDCaps, NULL);
  1.1518 +    if (result != DD_OK) {
  1.1519 +        SetDDerror ("DirectDraw2::GetCaps", result);
  1.1520 +        return (-1);
  1.1521 +    }
  1.1522 +    this->info.hw_available = 1;
  1.1523 +    if ((DDCaps.dwCaps & DDCAPS_BLT) == DDCAPS_BLT) {
  1.1524 +        this->info.blit_hw = 1;
  1.1525 +    }
  1.1526 +    if (((DDCaps.dwCaps & DDCAPS_COLORKEY) == DDCAPS_COLORKEY) &&
  1.1527 +        ((DDCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT) == DDCKEYCAPS_SRCBLT)) {
  1.1528 +        this->info.blit_hw_CC = 1;
  1.1529 +    }
  1.1530 +    if ((DDCaps.dwCaps & DDCAPS_ALPHA) == DDCAPS_ALPHA) {
  1.1531 +        /* This is only for alpha channel, and DirectX 6
  1.1532 +           doesn't support 2D alpha blits yet, so set it 0
  1.1533 +         */
  1.1534 +        this->info.blit_hw_A = 0;
  1.1535 +    }
  1.1536 +    if ((DDCaps.dwCaps & DDCAPS_CANBLTSYSMEM) == DDCAPS_CANBLTSYSMEM) {
  1.1537 +        this->info.blit_sw = 1;
  1.1538 +        /* This isn't necessarily true, but the HEL will cover us */
  1.1539 +        this->info.blit_sw_CC = this->info.blit_hw_CC;
  1.1540 +        this->info.blit_sw_A = this->info.blit_hw_A;
  1.1541 +    }
  1.1542 +    if ((DDCaps.dwCaps & DDCAPS_BLTCOLORFILL) == DDCAPS_BLTCOLORFILL) {
  1.1543 +        this->info.blit_fill = 1;
  1.1544 +    }
  1.1545  
  1.1546 -	/* Find out how much video memory is available */
  1.1547 -	{ DDSCAPS ddsCaps;
  1.1548 -	  DWORD total_mem;
  1.1549 -		ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
  1.1550 -		result = IDirectDraw2_GetAvailableVidMem(ddraw2,
  1.1551 -						&ddsCaps, &total_mem, NULL);
  1.1552 -		if ( result != DD_OK ) {
  1.1553 -			total_mem = DDCaps.dwVidMemTotal; 
  1.1554 -		}
  1.1555 -		this->info.video_mem = total_mem/1024;
  1.1556 -	}
  1.1557 -	return(0);
  1.1558 +    /* Find out how much video memory is available */
  1.1559 +    {
  1.1560 +        DDSCAPS ddsCaps;
  1.1561 +        DWORD total_mem;
  1.1562 +        ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
  1.1563 +        result = IDirectDraw2_GetAvailableVidMem (ddraw2,
  1.1564 +                                                  &ddsCaps, &total_mem, NULL);
  1.1565 +        if (result != DD_OK) {
  1.1566 +            total_mem = DDCaps.dwVidMemTotal;
  1.1567 +        }
  1.1568 +        this->info.video_mem = total_mem / 1024;
  1.1569 +    }
  1.1570 +    return (0);
  1.1571  }
  1.1572  
  1.1573 -int DX5_VideoInit(_THIS, SDL_PixelFormat *vformat)
  1.1574 +int
  1.1575 +DX5_VideoInit (_THIS, SDL_PixelFormat * vformat)
  1.1576  {
  1.1577 -	HRESULT result;
  1.1578 -	LPDIRECTDRAW ddraw;
  1.1579 -	int i, j;
  1.1580 -	HDC hdc;
  1.1581 +    HRESULT result;
  1.1582 +    LPDIRECTDRAW ddraw;
  1.1583 +    int i, j;
  1.1584 +    HDC hdc;
  1.1585  
  1.1586 -	/* Intialize everything */
  1.1587 -	ddraw2 = NULL;
  1.1588 -	SDL_primary = NULL;
  1.1589 -	SDL_clipper = NULL;
  1.1590 -	SDL_palette = NULL;
  1.1591 -	for ( i=0; i<NUM_MODELISTS; ++i ) {
  1.1592 -		SDL_nummodes[i] = 0;
  1.1593 -		SDL_modelist[i] = NULL;
  1.1594 -		SDL_modeindex[i] = 0;
  1.1595 -	}
  1.1596 -	colorchange_expected = 0;
  1.1597 +    /* Intialize everything */
  1.1598 +    ddraw2 = NULL;
  1.1599 +    SDL_primary = NULL;
  1.1600 +    SDL_clipper = NULL;
  1.1601 +    SDL_palette = NULL;
  1.1602 +    for (i = 0; i < NUM_MODELISTS; ++i) {
  1.1603 +        SDL_nummodes[i] = 0;
  1.1604 +        SDL_modelist[i] = NULL;
  1.1605 +        SDL_modeindex[i] = 0;
  1.1606 +    }
  1.1607 +    colorchange_expected = 0;
  1.1608  
  1.1609 -	/* Create the window */
  1.1610 -	if ( DX5_CreateWindow(this) < 0 ) {
  1.1611 -		return(-1);
  1.1612 -	}
  1.1613 -
  1.1614 +    /* Create the window */
  1.1615 +    if (DX5_CreateWindow (this) < 0) {
  1.1616 +        return (-1);
  1.1617 +    }
  1.1618  #if !SDL_AUDIO_DISABLED
  1.1619 -	DX5_SoundFocus(SDL_Window);
  1.1620 +    DX5_SoundFocus (SDL_Window);
  1.1621  #endif
  1.1622  
  1.1623 -	/* Create the DirectDraw object */
  1.1624 -	result = DDrawCreate(NULL, &ddraw, NULL);
  1.1625 -	if ( result != DD_OK ) {
  1.1626 -		SetDDerror("DirectDrawCreate", result);
  1.1627 -		return(-1);
  1.1628 -	}
  1.1629 -	result = IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw2,
  1.1630 -							(LPVOID *)&ddraw2);
  1.1631 -	IDirectDraw_Release(ddraw);
  1.1632 -	if ( result != DD_OK ) {
  1.1633 -		SetDDerror("DirectDraw::QueryInterface", result);
  1.1634 -		return(-1);
  1.1635 -	}
  1.1636 +    /* Create the DirectDraw object */
  1.1637 +    result = DDrawCreate (NULL, &ddraw, NULL);
  1.1638 +    if (result != DD_OK) {
  1.1639 +        SetDDerror ("DirectDrawCreate", result);
  1.1640 +        return (-1);
  1.1641 +    }
  1.1642 +    result = IDirectDraw_QueryInterface (ddraw, &IID_IDirectDraw2,
  1.1643 +                                         (LPVOID *) & ddraw2);
  1.1644 +    IDirectDraw_Release (ddraw);
  1.1645 +    if (result != DD_OK) {
  1.1646 +        SetDDerror ("DirectDraw::QueryInterface", result);
  1.1647 +        return (-1);
  1.1648 +    }
  1.1649  
  1.1650 -	/* Determine the screen depth */
  1.1651 -	hdc = GetDC(SDL_Window);
  1.1652 -	vformat->BitsPerPixel = GetDeviceCaps(hdc,PLANES) *
  1.1653 -					GetDeviceCaps(hdc,BITSPIXEL);
  1.1654 -	ReleaseDC(SDL_Window, hdc);
  1.1655 +    /* Determine the screen depth */
  1.1656 +    hdc = GetDC (SDL_Window);
  1.1657 +    vformat->BitsPerPixel = GetDeviceCaps (hdc, PLANES) *
  1.1658 +        GetDeviceCaps (hdc, BITSPIXEL);
  1.1659 +    ReleaseDC (SDL_Window, hdc);
  1.1660  
  1.1661  #ifndef NO_CHANGEDISPLAYSETTINGS
  1.1662 -	/* Query for the desktop resolution */
  1.1663 -	EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
  1.1664 -	this->info.current_w = SDL_desktop_mode.dmPelsWidth;
  1.1665 -	this->info.current_h = SDL_desktop_mode.dmPelsHeight;
  1.1666 +    /* Query for the desktop resolution */
  1.1667 +    EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
  1.1668 +    this->info.current_w = SDL_desktop_mode.dmPelsWidth;
  1.1669 +    this->info.current_h = SDL_desktop_mode.dmPelsHeight;
  1.1670  #endif
  1.1671  
  1.1672 -	/* Enumerate the available fullscreen modes */
  1.1673 -	for ( i=0; i<NUM_MODELISTS; ++i )
  1.1674 -		enumlists[i] = NULL;
  1.1675 +    /* Enumerate the available fullscreen modes */
  1.1676 +    for (i = 0; i < NUM_MODELISTS; ++i)
  1.1677 +        enumlists[i] = NULL;
  1.1678  
  1.1679 -	result = IDirectDraw2_EnumDisplayModes(ddraw2,DDEDM_REFRESHRATES,NULL,this,EnumModes2);
  1.1680 -	if ( result != DD_OK ) {
  1.1681 -		SetDDerror("DirectDraw2::EnumDisplayModes", result);
  1.1682 -		return(-1);
  1.1683 -	}
  1.1684 -	for ( i=0; i<NUM_MODELISTS; ++i ) {
  1.1685 -		struct DX5EnumRect *rect;
  1.1686 -		SDL_modelist[i] = (SDL_Rect **)
  1.1687 -				SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
  1.1688 -		if ( SDL_modelist[i] == NULL ) {
  1.1689 -			SDL_OutOfMemory();
  1.1690 -			return(-1);
  1.1691 -		}
  1.1692 -		for ( j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next ) {
  1.1693 -			SDL_modelist[i][j] = &rect->r;
  1.1694 -		}
  1.1695 -		SDL_modelist[i][j] = NULL;
  1.1696 +    result =
  1.1697 +        IDirectDraw2_EnumDisplayModes (ddraw2, DDEDM_REFRESHRATES, NULL, this,
  1.1698 +                                       EnumModes2);
  1.1699 +    if (result != DD_OK) {
  1.1700 +        SetDDerror ("DirectDraw2::EnumDisplayModes", result);
  1.1701 +        return (-1);
  1.1702 +    }
  1.1703 +    for (i = 0; i < NUM_MODELISTS; ++i) {
  1.1704 +        struct DX5EnumRect *rect;
  1.1705 +        SDL_modelist[i] = (SDL_Rect **)
  1.1706 +            SDL_malloc ((SDL_nummodes[i] + 1) * sizeof (SDL_Rect *));
  1.1707 +        if (SDL_modelist[i] == NULL) {
  1.1708 +            SDL_OutOfMemory ();
  1.1709 +            return (-1);
  1.1710 +        }
  1.1711 +        for (j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next) {
  1.1712 +            SDL_modelist[i][j] = &rect->r;
  1.1713 +        }
  1.1714 +        SDL_modelist[i][j] = NULL;
  1.1715  
  1.1716 -		if ( SDL_nummodes[i] > 0 ) {
  1.1717 -			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
  1.1718 -		}
  1.1719 -	}
  1.1720 -	
  1.1721 -	/* Fill in some window manager capabilities */
  1.1722 -	this->info.wm_available = 1;
  1.1723 +        if (SDL_nummodes[i] > 0) {
  1.1724 +            SDL_qsort (SDL_modelist[i], SDL_nummodes[i],
  1.1725 +                       sizeof *SDL_modelist[i], cmpmodes);
  1.1726 +        }
  1.1727 +    }
  1.1728  
  1.1729 -	/* Fill in the video hardware capabilities */
  1.1730 -	DX5_UpdateVideoInfo(this);
  1.1731 +    /* Fill in some window manager capabilities */
  1.1732 +    this->info.wm_available = 1;
  1.1733  
  1.1734 -	return(0);
  1.1735 +    /* Fill in the video hardware capabilities */
  1.1736 +    DX5_UpdateVideoInfo (this);
  1.1737 +
  1.1738 +    return (0);
  1.1739  }
  1.1740  
  1.1741 -SDL_Rect **DX5_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  1.1742 +SDL_Rect **
  1.1743 +DX5_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
  1.1744  {
  1.1745 -	int bpp;
  1.1746 +    int bpp;
  1.1747  
  1.1748 -	bpp = format->BitsPerPixel;
  1.1749 -	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.1750 -		/* FIXME:  No support for 1 bpp or 4 bpp formats */
  1.1751 -		switch (bpp) {  /* Does windows support other BPP? */
  1.1752 -			case 8:
  1.1753 -			case 16:
  1.1754 -			case 24:
  1.1755 -			case 32:
  1.1756 -				bpp = (bpp/8)-1;
  1.1757 -				if ( SDL_nummodes[bpp] > 0 )
  1.1758 -					return(SDL_modelist[bpp]);
  1.1759 -				/* Fall through */
  1.1760 -			default:
  1.1761 -				return((SDL_Rect **)0);
  1.1762 -		}
  1.1763 -	} else {
  1.1764 -		if ( this->screen->format->BitsPerPixel == bpp ) {
  1.1765 -			return((SDL_Rect **)-1);
  1.1766 -		} else {
  1.1767 -			return((SDL_Rect **)0);
  1.1768 -		}
  1.1769 -	}
  1.1770 +    bpp = format->BitsPerPixel;
  1.1771 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.1772 +        /* FIXME:  No support for 1 bpp or 4 bpp formats */
  1.1773 +        switch (bpp) {          /* Does windows support other BPP? */
  1.1774 +        case 8:
  1.1775 +        case 16:
  1.1776 +        case 24:
  1.1777 +        case 32:
  1.1778 +            bpp = (bpp / 8) - 1;
  1.1779 +            if (SDL_nummodes[bpp] > 0)
  1.1780 +                return (SDL_modelist[bpp]);
  1.1781 +            /* Fall through */
  1.1782 +        default:
  1.1783 +            return ((SDL_Rect **) 0);
  1.1784 +        }
  1.1785 +    } else {
  1.1786 +        if (this->screen->format->BitsPerPixel == bpp) {
  1.1787 +            return ((SDL_Rect **) - 1);
  1.1788 +        } else {
  1.1789 +            return ((SDL_Rect **) 0);
  1.1790 +        }
  1.1791 +    }
  1.1792  }
  1.1793  
  1.1794  /* Various screen update functions available */
  1.1795 -static void DX5_WindowUpdate(_THIS, int numrects, SDL_Rect *rects);
  1.1796 -static void DX5_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
  1.1797 +static void DX5_WindowUpdate (_THIS, int numrects, SDL_Rect * rects);
  1.1798 +static void DX5_DirectUpdate (_THIS, int numrects, SDL_Rect * rects);
  1.1799  
  1.1800 -SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current,
  1.1801 -				int width, int height, int bpp, Uint32 flags)
  1.1802 +SDL_Surface *
  1.1803 +DX5_SetVideoMode (_THIS, SDL_Surface * current,
  1.1804 +                  int width, int height, int bpp, Uint32 flags)
  1.1805  {
  1.1806 -	SDL_Surface *video;
  1.1807 -	HRESULT result;
  1.1808 -	DWORD sharemode;
  1.1809 -	DWORD style;
  1.1810 -	const DWORD directstyle =
  1.1811 -			(WS_POPUP);
  1.1812 -	const DWORD windowstyle = 
  1.1813 -			(WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX);
  1.1814 -	const DWORD resizestyle =
  1.1815 -			(WS_THICKFRAME|WS_MAXIMIZEBOX);
  1.1816 -	DDSURFACEDESC ddsd;
  1.1817 -	LPDIRECTDRAWSURFACE  dd_surface1;
  1.1818 -	LPDIRECTDRAWSURFACE3 dd_surface3;
  1.1819 +    SDL_Surface *video;
  1.1820 +    HRESULT result;
  1.1821 +    DWORD sharemode;
  1.1822 +    DWORD style;
  1.1823 +    const DWORD directstyle = (WS_POPUP);
  1.1824 +    const DWORD windowstyle =
  1.1825 +        (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
  1.1826 +    const DWORD resizestyle = (WS_THICKFRAME | WS_MAXIMIZEBOX);
  1.1827 +    DDSURFACEDESC ddsd;
  1.1828 +    LPDIRECTDRAWSURFACE dd_surface1;
  1.1829 +    LPDIRECTDRAWSURFACE3 dd_surface3;
  1.1830  
  1.1831 -	SDL_resizing = 1;
  1.1832 +    SDL_resizing = 1;
  1.1833  #ifdef DDRAW_DEBUG
  1.1834 - fprintf(stderr, "Setting %dx%dx%d video mode\n", width, height, bpp);
  1.1835 +    fprintf (stderr, "Setting %dx%dx%d video mode\n", width, height, bpp);
  1.1836  #endif
  1.1837 -	/* Clean up any previous DirectDraw surfaces */
  1.1838 -	if ( current->hwdata ) {
  1.1839 -		this->FreeHWSurface(this, current);
  1.1840 -		current->hwdata = NULL;
  1.1841 -	}
  1.1842 -	if ( SDL_primary != NULL ) {
  1.1843 -		IDirectDrawSurface3_Release(SDL_primary);
  1.1844 -		SDL_primary = NULL;
  1.1845 -	}
  1.1846 -
  1.1847 +    /* Clean up any previous DirectDraw surfaces */
  1.1848 +    if (current->hwdata) {
  1.1849 +        this->FreeHWSurface (this, current);
  1.1850 +        current->hwdata = NULL;
  1.1851 +    }
  1.1852 +    if (SDL_primary != NULL) {
  1.1853 +        IDirectDrawSurface3_Release (SDL_primary);
  1.1854 +        SDL_primary = NULL;
  1.1855 +    }
  1.1856  #ifndef NO_CHANGEDISPLAYSETTINGS
  1.1857 -	/* Unset any previous OpenGL fullscreen mode */
  1.1858 -	if ( (current->flags & (SDL_INTERNALOPENGL|SDL_FULLSCREEN)) ==
  1.1859 -	                       (SDL_INTERNALOPENGL|SDL_FULLSCREEN) ) {
  1.1860 -		ChangeDisplaySettings(NULL, 0);
  1.1861 -	}
  1.1862 +    /* Unset any previous OpenGL fullscreen mode */
  1.1863 +    if ((current->flags & (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) ==
  1.1864 +        (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) {
  1.1865 +        ChangeDisplaySettings (NULL, 0);
  1.1866 +    }
  1.1867  #endif
  1.1868  
  1.1869 -	/* Clean up any GL context that may be hanging around */
  1.1870 -	if ( current->flags & SDL_INTERNALOPENGL ) {
  1.1871 -		WIN_GL_ShutDown(this);
  1.1872 -	}
  1.1873 +    /* Clean up any GL context that may be hanging around */
  1.1874 +    if (current->flags & SDL_INTERNALOPENGL) {
  1.1875 +        WIN_GL_ShutDown (this);
  1.1876 +    }
  1.1877  
  1.1878 -	/* If we are setting a GL mode, use GDI, not DirectX (yuck) */
  1.1879 -	if ( flags & SDL_INTERNALOPENGL ) {
  1.1880 -		Uint32 Rmask, Gmask, Bmask;
  1.1881 +    /* If we are setting a GL mode, use GDI, not DirectX (yuck) */
  1.1882 +    if (flags & SDL_INTERNALOPENGL) {
  1.1883 +        Uint32 Rmask, Gmask, Bmask;
  1.1884  
  1.1885 -		/* Recalculate the bitmasks if necessary */
  1.1886 -		if ( bpp == current->format->BitsPerPixel ) {
  1.1887 -			video = current;
  1.1888 -		} else {
  1.1889 -			switch (bpp) {
  1.1890 -			    case 15:
  1.1891 -			    case 16:
  1.1892 -				if ( 0 /*DIB_SussScreenDepth() == 15*/ ) {
  1.1893 -					/* 5-5-5 */
  1.1894 -					Rmask = 0x00007c00;
  1.1895 -					Gmask = 0x000003e0;
  1.1896 -					Bmask = 0x0000001f;
  1.1897 -				} else {
  1.1898 -					/* 5-6-5 */
  1.1899 -					Rmask = 0x0000f800;
  1.1900 -					Gmask = 0x000007e0;
  1.1901 -					Bmask = 0x0000001f;
  1.1902 -				}
  1.1903 -				break;
  1.1904 -			    case 24:
  1.1905 -			    case 32:
  1.1906 -				/* GDI defined as 8-8-8 */
  1.1907 -				Rmask = 0x00ff0000;
  1.1908 -				Gmask = 0x0000ff00;
  1.1909 -				Bmask = 0x000000ff;
  1.1910 -				break;
  1.1911 -			    default:
  1.1912 -				Rmask = 0x00000000;
  1.1913 -				Gmask = 0x00000000;
  1.1914 -				Bmask = 0x00000000;
  1.1915 -				break;
  1.1916 -			}
  1.1917 -			video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp,
  1.1918 -			                             Rmask, Gmask, Bmask, 0);
  1.1919 -			if ( video == NULL ) {
  1.1920 -				SDL_OutOfMemory();
  1.1921 -				return(NULL);
  1.1922 -			}
  1.1923 -		}
  1.1924 +        /* Recalculate the bitmasks if necessary */
  1.1925 +        if (bpp == current->format->BitsPerPixel) {
  1.1926 +            video = current;
  1.1927 +        } else {
  1.1928 +            switch (bpp) {
  1.1929 +            case 15:
  1.1930 +            case 16:
  1.1931 +                if (0 /*DIB_SussScreenDepth() == 15 */ ) {
  1.1932 +                    /* 5-5-5 */
  1.1933 +                    Rmask = 0x00007c00;
  1.1934 +                    Gmask = 0x000003e0;
  1.1935 +                    Bmask = 0x0000001f;
  1.1936 +                } else {
  1.1937 +                    /* 5-6-5 */
  1.1938 +                    Rmask = 0x0000f800;
  1.1939 +                    Gmask = 0x000007e0;
  1.1940 +                    Bmask = 0x0000001f;
  1.1941 +                }
  1.1942 +                break;
  1.1943 +            case 24:
  1.1944 +            case 32:
  1.1945 +                /* GDI defined as 8-8-8 */
  1.1946 +                Rmask = 0x00ff0000;
  1.1947 +                Gmask = 0x0000ff00;
  1.1948 +                Bmask = 0x000000ff;
  1.1949 +                break;
  1.1950 +            default:
  1.1951 +                Rmask = 0x00000000;
  1.1952 +                Gmask = 0x00000000;
  1.1953 +                Bmask = 0x00000000;
  1.1954 +                break;
  1.1955 +            }
  1.1956 +            video = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0, bpp,
  1.1957 +                                          Rmask, Gmask, Bmask, 0);
  1.1958 +            if (video == NULL) {
  1.1959 +                SDL_OutOfMemory ();
  1.1960 +                return (NULL);
  1.1961 +            }
  1.1962 +        }
  1.1963  
  1.1964 -		/* Fill in part of the video surface */
  1.1965 -		video->flags = 0;	/* Clear flags */
  1.1966 -		video->w = width;
  1.1967 -		video->h = height;
  1.1968 -		video->pitch = SDL_CalculatePitch(video);
  1.1969 +        /* Fill in part of the video surface */
  1.1970 +        video->flags = 0;       /* Clear flags */
  1.1971 +        video->w = width;
  1.1972 +        video->h = height;
  1.1973 +        video->pitch = SDL_CalculatePitch (video);
  1.1974  
  1.1975  #ifndef NO_CHANGEDISPLAYSETTINGS
  1.1976 -		/* Set fullscreen mode if appropriate.
  1.1977 -		   Ugh, since our list of valid video modes comes from
  1.1978 -		   the DirectX driver, we may not actually be able to
  1.1979 -		   change to the desired resolution here.
  1.1980 -		   FIXME: Should we do a closest match?
  1.1981 -		 */
  1.1982 -		if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.1983 -			DEVMODE settings;
  1.1984 -			BOOL changed;
  1.1985 +        /* Set fullscreen mode if appropriate.
  1.1986 +           Ugh, since our list of valid video modes comes from
  1.1987 +           the DirectX driver, we may not actually be able to
  1.1988 +           change to the desired resolution here.
  1.1989 +           FIXME: Should we do a closest match?
  1.1990 +         */
  1.1991 +        if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.1992 +            DEVMODE settings;
  1.1993 +            BOOL changed;
  1.1994  
  1.1995 -			SDL_memset(&settings, 0, sizeof(DEVMODE));
  1.1996 -			settings.dmSize = sizeof(DEVMODE);
  1.1997 -			settings.dmBitsPerPel = video->format->BitsPerPixel;
  1.1998 -			settings.dmPelsWidth = width;
  1.1999 -			settings.dmPelsHeight = height;
  1.2000 -			settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
  1.2001 -			if ( width <= (int)SDL_desktop_mode.dmPelsWidth &&
  1.2002 -			     height <= (int)SDL_desktop_mode.dmPelsHeight ) {
  1.2003 -				settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
  1.2004 -				settings.dmFields |= DM_DISPLAYFREQUENCY;
  1.2005 -			}
  1.2006 -			changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
  1.2007 -			if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) {
  1.2008 -				settings.dmFields &= ~DM_DISPLAYFREQUENCY;
  1.2009 -				changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
  1.2010 -			}
  1.2011 -			if ( changed ) {
  1.2012 -				video->flags |= SDL_FULLSCREEN;
  1.2013 -				SDL_fullscreen_mode = settings;
  1.2014 -			}
  1.2015 -		}
  1.2016 +            SDL_memset (&settings, 0, sizeof (DEVMODE));
  1.2017 +            settings.dmSize = sizeof (DEVMODE);
  1.2018 +            settings.dmBitsPerPel = video->format->BitsPerPixel;
  1.2019 +            settings.dmPelsWidth = width;
  1.2020 +            settings.dmPelsHeight = height;
  1.2021 +            settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
  1.2022 +            if (width <= (int) SDL_desktop_mode.dmPelsWidth
  1.2023 +                && height <= (int) SDL_desktop_mode.dmPelsHeight) {
  1.2024 +                settings.dmDisplayFrequency =
  1.2025 +                    SDL_desktop_mode.dmDisplayFrequency;
  1.2026 +                settings.dmFields |= DM_DISPLAYFREQUENCY;
  1.2027 +            }
  1.2028 +            changed =
  1.2029 +                (ChangeDisplaySettings (&settings, CDS_FULLSCREEN) ==
  1.2030 +                 DISP_CHANGE_SUCCESSFUL);
  1.2031 +            if (!changed && (settings.dmFields & DM_DISPLAYFREQUENCY)) {
  1.2032 +                settings.dmFields &= ~DM_DISPLAYFREQUENCY;
  1.2033 +                changed = (ChangeDisplaySettings (&settings, CDS_FULLSCREEN)
  1.2034 +                           == DISP_CHANGE_SUCCESSFUL);
  1.2035 +            }
  1.2036 +            if (changed) {
  1.2037 +                video->flags |= SDL_FULLSCREEN;
  1.2038 +                SDL_fullscreen_mode = settings;
  1.2039 +            }
  1.2040 +        }
  1.2041  #endif /* !NO_CHANGEDISPLAYSETTINGS */
  1.2042  
  1.2043 -		style = GetWindowLong(SDL_Window, GWL_STYLE);
  1.2044 -		style &= ~(resizestyle|WS_MAXIMIZE);
  1.2045 -		if ( video->flags & SDL_FULLSCREEN ) {
  1.2046 -			style &= ~windowstyle;
  1.2047 -			style |= directstyle;
  1.2048 -		} else {
  1.2049 -			if ( flags & SDL_NOFRAME ) {
  1.2050 -				style &= ~windowstyle;
  1.2051 -				style |= directstyle;
  1.2052 -				video->flags |= SDL_NOFRAME;
  1.2053 -			} else {
  1.2054 -				style &= ~directstyle;
  1.2055 -				style |= windowstyle;
  1.2056 -				if ( flags & SDL_RESIZABLE ) {
  1.2057 -					style |= resizestyle;
  1.2058 -					video->flags |= SDL_RESIZABLE;
  1.2059 -				}
  1.2060 -			}
  1.2061 +        style = GetWindowLong (SDL_Window, GWL_STYLE);
  1.2062 +        style &= ~(resizestyle | WS_MAXIMIZE);
  1.2063 +        if (video->flags & SDL_FULLSCREEN) {
  1.2064 +            style &= ~windowstyle;
  1.2065 +            style |= directstyle;
  1.2066 +        } else {
  1.2067 +            if (flags & SDL_NOFRAME) {
  1.2068 +                style &= ~windowstyle;
  1.2069 +                style |= directstyle;
  1.2070 +                video->flags |= SDL_NOFRAME;
  1.2071 +            } else {
  1.2072 +                style &= ~directstyle;
  1.2073 +                style |= windowstyle;
  1.2074 +                if (flags & SDL_RESIZABLE) {
  1.2075 +                    style |= resizestyle;
  1.2076 +                    video->flags |= SDL_RESIZABLE;
  1.2077 +                }
  1.2078 +            }
  1.2079  #if WS_MAXIMIZE
  1.2080 -			if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
  1.2081 +            if (IsZoomed (SDL_Window))
  1.2082 +                style |= WS_MAXIMIZE;
  1.2083  #endif
  1.2084 -		}
  1.2085 +        }
  1.2086  
  1.2087 -		/* DJM: Don't piss of anyone who has setup his own window */
  1.2088 -		if ( !SDL_windowid )
  1.2089 -			SetWindowLong(SDL_Window, GWL_STYLE, style);
  1.2090 +        /* DJM: Don't piss of anyone who has setup his own window */
  1.2091 +        if (!SDL_windowid)
  1.2092 +            SetWindowLong (SDL_Window, GWL_STYLE, style);
  1.2093  
  1.2094 -		/* Resize the window (copied from SDL WinDIB driver) */
  1.2095 -		if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
  1.2096 -			RECT bounds;
  1.2097 -			int x, y;
  1.2098 -			HWND top;
  1.2099 -			UINT swp_flags;
  1.2100 -			const char *window = NULL;
  1.2101 -			const char *center = NULL;
  1.2102 +        /* Resize the window (copied from SDL WinDIB driver) */
  1.2103 +        if (!SDL_windowid && !IsZoomed (SDL_Window)) {
  1.2104 +            RECT bounds;
  1.2105 +            int x, y;
  1.2106 +            HWND top;
  1.2107 +            UINT swp_flags;
  1.2108 +            const char *window = NULL;
  1.2109 +            const char *center = NULL;
  1.2110  
  1.2111 -			if ( !SDL_windowX && !SDL_windowY ) {
  1.2112 -				window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
  1.2113 -				center = SDL_getenv("SDL_VIDEO_CENTERED");
  1.2114 -				if ( window ) {
  1.2115 -					if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) {
  1.2116 -						SDL_windowX = x;
  1.2117 -						SDL_windowY = y;
  1.2118 -					}
  1.2119 -					if ( SDL_strcmp(window, "center") == 0 ) {
  1.2120 -						center = window;
  1.2121 -					}
  1.2122 -				}
  1.2123 -			}
  1.2124 -			swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
  1.2125 +            if (!SDL_windowX && !SDL_windowY) {
  1.2126 +                window = SDL_getenv ("SDL_VIDEO_WINDOW_POS");
  1.2127 +                center = SDL_getenv ("SDL_VIDEO_CENTERED");
  1.2128 +                if (window) {
  1.2129 +                    if (SDL_sscanf (window, "%d,%d", &x, &y) == 2) {
  1.2130 +                        SDL_windowX = x;
  1.2131 +                        SDL_windowY = y;
  1.2132 +                    }
  1.2133 +                    if (SDL_strcmp (window, "center") == 0) {
  1.2134 +                        center = window;
  1.2135 +                    }
  1.2136 +                }
  1.2137 +            }
  1.2138 +            swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
  1.2139  
  1.2140 -			bounds.left = SDL_windowX;
  1.2141 -			bounds.top = SDL_windowY;
  1.2142 -			bounds.right = SDL_windowX+video->w;
  1.2143 -			bounds.bottom = SDL_windowY+video->h;
  1.2144 -			AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
  1.2145 -			width = bounds.right-bounds.left;
  1.2146 -			height = bounds.bottom-bounds.top;
  1.2147 -			if ( (flags & SDL_FULLSCREEN) ) {
  1.2148 -				x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
  1.2149 -				y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
  1.2150 -			} else if ( center ) {
  1.2151 -				x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
  1.2152 -				y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
  1.2153 -			} else if ( SDL_windowX || SDL_windowY || window ) {
  1.2154 -				x = bounds.left;
  1.2155 -				y = bounds.top;
  1.2156 -			} else {
  1.2157 -				x = y = -1;
  1.2158 -				swp_flags |= SWP_NOMOVE;
  1.2159 -			}
  1.2160 -			if ( flags & SDL_FULLSCREEN ) {
  1.2161 -				top = HWND_TOPMOST;
  1.2162 -			} else {
  1.2163 -				top = HWND_NOTOPMOST;
  1.2164 -			}
  1.2165 -			SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);
  1.2166 -			if ( !(flags & SDL_FULLSCREEN) ) {
  1.2167 -				SDL_windowX = SDL_bounds.left;
  1.2168 -				SDL_windowY = SDL_bounds.top;
  1.2169 -			}
  1.2170 -			SetForegroundWindow(SDL_Window);
  1.2171 -		}
  1.2172 -		SDL_resizing = 0;
  1.2173 +            bounds.left = SDL_windowX;
  1.2174 +            bounds.top = SDL_windowY;
  1.2175 +            bounds.right = SDL_windowX + video->w;
  1.2176 +            bounds.bottom = SDL_windowY + video->h;
  1.2177 +            AdjustWindowRectEx (&bounds,
  1.2178 +                                GetWindowLong (SDL_Window, GWL_STYLE),
  1.2179 +                                FALSE, 0);
  1.2180 +            width = bounds.right - bounds.left;
  1.2181 +            height = bounds.bottom - bounds.top;
  1.2182 +            if ((flags & SDL_FULLSCREEN)) {
  1.2183 +                x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2;
  1.2184 +                y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2;
  1.2185 +            } else if (center) {
  1.2186 +                x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2;
  1.2187 +                y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2;
  1.2188 +            } else if (SDL_windowX || SDL_windowY || window) {
  1.2189 +                x = bounds.left;
  1.2190 +                y = bounds.top;
  1.2191 +            } else {
  1.2192 +                x = y = -1;
  1.2193 +                swp_flags |= SWP_NOMOVE;
  1.2194 +            }
  1.2195 +            if (flags & SDL_FULLSCREEN) {
  1.2196 +                top = HWND_TOPMOST;
  1.2197 +            } else {
  1.2198 +                top = HWND_NOTOPMOST;
  1.2199 +            }
  1.2200 +            SetWindowPos (SDL_Window, top, x, y, width, height, swp_flags);
  1.2201 +            if (!(flags & SDL_FULLSCREEN)) {
  1.2202 +                SDL_windowX = SDL_bounds.left;
  1.2203 +                SDL_windowY = SDL_bounds.top;
  1.2204 +            }
  1.2205 +            SetForegroundWindow (SDL_Window);
  1.2206 +        }
  1.2207 +        SDL_resizing = 0;
  1.2208  
  1.2209 -		/* Set up for OpenGL */
  1.2210 -		if ( WIN_GL_SetupWindow(this) < 0 ) {
  1.2211 -			return(NULL);
  1.2212 -		}
  1.2213 -		video->flags |= SDL_INTERNALOPENGL;
  1.2214 -		return(video);
  1.2215 -	}
  1.2216 +        /* Set up for OpenGL */
  1.2217 +        if (WIN_GL_SetupWindow (this) < 0) {
  1.2218 +            return (NULL);
  1.2219 +        }
  1.2220 +        video->flags |= SDL_INTERNALOPENGL;
  1.2221 +        return (video);
  1.2222 +    }
  1.2223  
  1.2224 -	/* Set the appropriate window style */
  1.2225 -	style = GetWindowLong(SDL_Window, GWL_STYLE);
  1.2226 -	style &= ~(resizestyle|WS_MAXIMIZE);
  1.2227 -	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.2228 -		style &= ~windowstyle;
  1.2229 -		style |= directstyle;
  1.2230 -	} else {
  1.2231 -		if ( flags & SDL_NOFRAME ) {
  1.2232 -			style &= ~windowstyle;
  1.2233 -			style |= directstyle;
  1.2234 -		} else {
  1.2235 -			style &= ~directstyle;
  1.2236 -			style |= windowstyle;
  1.2237 -			if ( flags & SDL_RESIZABLE ) {
  1.2238 -				style |= resizestyle;
  1.2239 -			}
  1.2240 -		}
  1.2241 +    /* Set the appropriate window style */
  1.2242 +    style = GetWindowLong (SDL_Window, GWL_STYLE);
  1.2243 +    style &= ~(resizestyle | WS_MAXIMIZE);
  1.2244 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.2245 +        style &= ~windowstyle;
  1.2246 +        style |= directstyle;
  1.2247 +    } else {
  1.2248 +        if (flags & SDL_NOFRAME) {
  1.2249 +            style &= ~windowstyle;
  1.2250 +            style |= directstyle;
  1.2251 +        } else {
  1.2252 +            style &= ~directstyle;
  1.2253 +            style |= windowstyle;
  1.2254 +            if (flags & SDL_RESIZABLE) {
  1.2255 +                style |= resizestyle;
  1.2256 +            }
  1.2257 +        }
  1.2258  #if WS_MAXIMIZE
  1.2259 -		if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
  1.2260 +        if (IsZoomed (SDL_Window))
  1.2261 +            style |= WS_MAXIMIZE;
  1.2262  #endif
  1.2263 -	}
  1.2264 -	/* DJM: Don't piss of anyone who has setup his own window */
  1.2265 -	if ( !SDL_windowid )
  1.2266 -		SetWindowLong(SDL_Window, GWL_STYLE, style);
  1.2267 +    }
  1.2268 +    /* DJM: Don't piss of anyone who has setup his own window */
  1.2269 +    if (!SDL_windowid)
  1.2270 +        SetWindowLong (SDL_Window, GWL_STYLE, style);
  1.2271  
  1.2272 -	/* Set DirectDraw sharing mode.. exclusive when fullscreen */
  1.2273 -	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.2274 -		sharemode = DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE|DDSCL_ALLOWREBOOT;
  1.2275 -	} else {
  1.2276 -		sharemode = DDSCL_NORMAL;
  1.2277 -	}
  1.2278 -	result = IDirectDraw2_SetCooperativeLevel(ddraw2,SDL_Window,sharemode);
  1.2279 -	if ( result != DD_OK ) {
  1.2280 -		SetDDerror("DirectDraw2::SetCooperativeLevel", result);
  1.2281 -		return(NULL);
  1.2282 -	}
  1.2283 +    /* Set DirectDraw sharing mode.. exclusive when fullscreen */
  1.2284 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.2285 +        sharemode = DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT;
  1.2286 +    } else {
  1.2287 +        sharemode = DDSCL_NORMAL;
  1.2288 +    }
  1.2289 +    result = IDirectDraw2_SetCooperativeLevel (ddraw2, SDL_Window, sharemode);
  1.2290 +    if (result != DD_OK) {
  1.2291 +        SetDDerror ("DirectDraw2::SetCooperativeLevel", result);
  1.2292 +        return (NULL);
  1.2293 +    }
  1.2294  
  1.2295 -	/* Set the display mode, if we are in fullscreen mode */
  1.2296 -	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.2297 -		RECT bounds;
  1.2298 -		struct DX5EnumRect *rect;
  1.2299 -		int maxRefreshRate;
  1.2300 +    /* Set the display mode, if we are in fullscreen mode */
  1.2301 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.2302 +        RECT bounds;
  1.2303 +        struct DX5EnumRect *rect;
  1.2304 +        int maxRefreshRate;
  1.2305  
  1.2306 -		/* Cover up desktop during mode change */
  1.2307 -		bounds.left = 0;
  1.2308 -		bounds.top = 0;
  1.2309 -		bounds.right = GetSystemMetrics(SM_CXSCREEN);
  1.2310 -		bounds.bottom = GetSystemMetrics(SM_CYSCREEN);
  1.2311 -		AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
  1.2312 -		SetWindowPos(SDL_Window, HWND_TOPMOST,
  1.2313 -			bounds.left, bounds.top, 
  1.2314 -			bounds.right - bounds.left,
  1.2315 -			bounds.bottom - bounds.top, SWP_NOCOPYBITS);
  1.2316 -		ShowWindow(SDL_Window, SW_SHOW);
  1.2317 -		while ( GetForegroundWindow() != SDL_Window ) {
  1.2318 -			SetForegroundWindow(SDL_Window);
  1.2319 -			SDL_Delay(100);
  1.2320 -		}
  1.2321 +        /* Cover up desktop during mode change */
  1.2322 +        bounds.left = 0;
  1.2323 +        bounds.top = 0;
  1.2324 +        bounds.right = GetSystemMetrics (SM_CXSCREEN);
  1.2325 +        bounds.bottom = GetSystemMetrics (SM_CYSCREEN);
  1.2326 +        AdjustWindowRectEx (&bounds, GetWindowLong (SDL_Window, GWL_STYLE),
  1.2327 +                            FALSE, 0);
  1.2328 +        SetWindowPos (SDL_Window, HWND_TOPMOST, bounds.left, bounds.top,
  1.2329 +                      bounds.right - bounds.left,
  1.2330 +                      bounds.bottom - bounds.top, SWP_NOCOPYBITS);
  1.2331 +        ShowWindow (SDL_Window, SW_SHOW);
  1.2332 +        while (GetForegroundWindow () != SDL_Window) {
  1.2333 +            SetForegroundWindow (SDL_Window);
  1.2334 +            SDL_Delay (100);
  1.2335 +        }
  1.2336  
  1.2337 -		/* find maximum monitor refresh rate for this resolution */
  1.2338 -		/* Dmitry Yakimov ftech@tula.net */
  1.2339 -		maxRefreshRate = 0; /* system default */
  1.2340 -		for ( rect = enumlists[bpp / 8 - 1]; rect; rect = rect->next ) {
  1.2341 -			if ( (width == rect->r.w) && (height == rect->r.h) ) {
  1.2342 -				maxRefreshRate = rect->refreshRate;
  1.2343 -				break;
  1.2344 -			}
  1.2345 -		}
  1.2346 +        /* find maximum monitor refresh rate for this resolution */
  1.2347 +        /* Dmitry Yakimov ftech@tula.net */
  1.2348 +        maxRefreshRate = 0;     /* system default */
  1.2349 +        for (rect = enumlists[bpp / 8 - 1]; rect; rect = rect->next) {
  1.2350 +            if ((width == rect->r.w) && (height == rect->r.h)) {
  1.2351 +                maxRefreshRate = rect->refreshRate;
  1.2352 +                break;
  1.2353 +            }
  1.2354 +        }
  1.2355  #ifdef DDRAW_DEBUG
  1.2356 - fprintf(stderr, "refresh rate = %d Hz\n", maxRefreshRate);
  1.2357 +        fprintf (stderr, "refresh rate = %d Hz\n", maxRefreshRate);
  1.2358  #endif
  1.2359  
  1.2360 -		result = IDirectDraw2_SetDisplayMode(ddraw2, width, height, bpp, maxRefreshRate, 0);
  1.2361 -		if ( result != DD_OK ) {
  1.2362 -			result = IDirectDraw2_SetDisplayMode(ddraw2, width, height, bpp, 0, 0);
  1.2363 -			if ( result != DD_OK ) {
  1.2364 -				/* We couldn't set fullscreen mode, try window */
  1.2365 -				return(DX5_SetVideoMode(this, current, width, height, bpp, flags & ~SDL_FULLSCREEN)); 
  1.2366 -			}
  1.2367 -		}
  1.2368 -		DX5_DInputReset(this, 1);
  1.2369 -	} else {
  1.2370 -		DX5_DInputReset(this, 0);
  1.2371 -	}
  1.2372 -	DX5_UpdateVideoInfo(this);
  1.2373 +        result =
  1.2374 +            IDirectDraw2_SetDisplayMode (ddraw2, width, height, bpp,
  1.2375 +                                         maxRefreshRate, 0);
  1.2376 +        if (result != DD_OK) {
  1.2377 +            result =
  1.2378 +                IDirectDraw2_SetDisplayMode (ddraw2, width, height, bpp,
  1.2379 +                                             0, 0);
  1.2380 +            if (result != DD_OK) {
  1.2381 +                /* We couldn't set fullscreen mode, try window */
  1.2382 +                return (DX5_SetVideoMode
  1.2383 +                        (this, current, width, height, bpp,
  1.2384 +                         flags & ~SDL_FULLSCREEN));
  1.2385 +            }
  1.2386 +        }
  1.2387 +        DX5_DInputReset (this, 1);
  1.2388 +    } else {
  1.2389 +        DX5_DInputReset (this, 0);
  1.2390 +    }
  1.2391 +    DX5_UpdateVideoInfo (this);
  1.2392  
  1.2393 -	/* Create a primary DirectDraw surface */
  1.2394 -	SDL_memset(&ddsd, 0, sizeof(ddsd));
  1.2395 -	ddsd.dwSize = sizeof(ddsd);
  1.2396 -	ddsd.dwFlags = DDSD_CAPS;
  1.2397 -	ddsd.ddsCaps.dwCaps = (DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY);
  1.2398 -	if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
  1.2399 -		/* There's no windowed double-buffering */
  1.2400 -		flags &= ~SDL_DOUBLEBUF;
  1.2401 -	}
  1.2402 -	if ( (flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
  1.2403 -		ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
  1.2404 -		ddsd.ddsCaps.dwCaps |= (DDSCAPS_COMPLEX|DDSCAPS_FLIP);
  1.2405 -		ddsd.dwBackBufferCount = 1;
  1.2406 -	}
  1.2407 -	result = IDirectDraw2_CreateSurface(ddraw2, &ddsd, &dd_surface1, NULL); 
  1.2408 -	if ( (result != DD_OK) && ((flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) ) {
  1.2409 -		ddsd.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
  1.2410 -		ddsd.ddsCaps.dwCaps &= ~(DDSCAPS_COMPLEX|DDSCAPS_FLIP);
  1.2411 -		ddsd.dwBackBufferCount = 0;
  1.2412 -		result = IDirectDraw2_CreateSurface(ddraw2,
  1.2413 -						&ddsd, &dd_surface1, NULL); 
  1.2414 -	}
  1.2415 -	if ( result != DD_OK ) {
  1.2416 -		SetDDerror("DirectDraw2::CreateSurface(PRIMARY)", result);
  1.2417 -		return(NULL);
  1.2418 -	}
  1.2419 -	result = IDirectDrawSurface_QueryInterface(dd_surface1,
  1.2420 -			&IID_IDirectDrawSurface3, (LPVOID *)&SDL_primary);
  1.2421 -	if ( result != DD_OK ) {
  1.2422 -		SetDDerror("DirectDrawSurface::QueryInterface", result);
  1.2423 -		return(NULL);
  1.2424 -	}
  1.2425 -	IDirectDrawSurface_Release(dd_surface1);
  1.2426 +    /* Create a primary DirectDraw surface */
  1.2427 +    SDL_memset (&ddsd, 0, sizeof (ddsd));
  1.2428 +    ddsd.dwSize = sizeof (ddsd);
  1.2429 +    ddsd.dwFlags = DDSD_CAPS;
  1.2430 +    ddsd.ddsCaps.dwCaps = (DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY);
  1.2431 +    if ((flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) {
  1.2432 +        /* There's no windowed double-buffering */
  1.2433 +        flags &= ~SDL_DOUBLEBUF;
  1.2434 +    }
  1.2435 +    if ((flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
  1.2436 +        ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
  1.2437 +        ddsd.ddsCaps.dwCaps |= (DDSCAPS_COMPLEX | DDSCAPS_FLIP);
  1.2438 +        ddsd.dwBackBufferCount = 1;
  1.2439 +    }
  1.2440 +    result = IDirectDraw2_CreateSurface (ddraw2, &ddsd, &dd_surface1, NULL);
  1.2441 +    if ((result != DD_OK) && ((flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)) {
  1.2442 +        ddsd.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
  1.2443 +        ddsd.ddsCaps.dwCaps &= ~(DDSCAPS_COMPLEX | DDSCAPS_FLIP);
  1.2444 +        ddsd.dwBackBufferCount = 0;
  1.2445 +        result = IDirectDraw2_CreateSurface (ddraw2,
  1.2446 +                                             &ddsd, &dd_surface1, NULL);
  1.2447 +    }
  1.2448 +    if (result != DD_OK) {
  1.2449 +        SetDDerror ("DirectDraw2::CreateSurface(PRIMARY)", result);
  1.2450 +        return (NULL);
  1.2451 +    }
  1.2452 +    result = IDirectDrawSurface_QueryInterface (dd_surface1,
  1.2453 +                                                &IID_IDirectDrawSurface3,
  1.2454 +                                                (LPVOID *) & SDL_primary);
  1.2455 +    if (result != DD_OK) {
  1.2456 +        SetDDerror ("DirectDrawSurface::QueryInterface", result);
  1.2457 +        return (NULL);
  1.2458 +    }
  1.2459 +    IDirectDrawSurface_Release (dd_surface1);
  1.2460  
  1.2461 -	/* Get the format of the primary DirectDraw surface */
  1.2462 -	SDL_memset(&ddsd, 0, sizeof(ddsd));
  1.2463 -	ddsd.dwSize = sizeof(ddsd);
  1.2464 -	ddsd.dwFlags = DDSD_PIXELFORMAT|DDSD_CAPS;
  1.2465 -	result = IDirectDrawSurface3_GetSurfaceDesc(SDL_primary, &ddsd);
  1.2466 -	if ( result != DD_OK ) {
  1.2467 -		SetDDerror("DirectDrawSurface::GetSurfaceDesc", result);
  1.2468 -		return(NULL);
  1.2469 -	}
  1.2470 -	if ( ! (ddsd.ddpfPixelFormat.dwFlags&DDPF_RGB) ) {
  1.2471 -		SDL_SetError("Primary DDRAW surface is not RGB format");
  1.2472 -		return(NULL);
  1.2473 -	}
  1.2474 -
  1.2475 -	/* Free old palette and create a new one if we're in 8-bit mode */
  1.2476 -	if ( SDL_palette != NULL ) {
  1.2477 -		IDirectDrawPalette_Release(SDL_palette);
  1.2478 -		SDL_palette = NULL;
  1.2479 -	}
  1.2480 -#if defined(NONAMELESSUNION)
  1.2481 -	if ( ddsd.ddpfPixelFormat.u1.dwRGBBitCount == 8 ) {
  1.2482 -#else
  1.2483 -	if ( ddsd.ddpfPixelFormat.dwRGBBitCount == 8 ) {
  1.2484 -#endif
  1.2485 -		int i;
  1.2486 +    /* Get the format of the primary DirectDraw surface */
  1.2487 +    SDL_memset (&ddsd, 0, sizeof (ddsd));
  1.2488 +    ddsd.dwSize = sizeof (ddsd);
  1.2489 +    ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  1.2490 +    result = IDirectDrawSurface3_GetSurfaceDesc (SDL_primary, &ddsd);
  1.2491 +    if (result != DD_OK) {
  1.2492 +        SetDDerror ("DirectDrawSurface::GetSurfaceDesc", result);
  1.2493 +        return (NULL);
  1.2494 +    }
  1.2495 +    if (!(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)) {
  1.2496 +        SDL_SetError ("Primary DDRAW surface is not RGB format");
  1.2497 +        return (NULL);
  1.2498 +    }
  1.2499  
  1.2500 -		if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.2501 -			/* We have access to the entire palette */
  1.2502 -			for ( i=0; i<256; ++i ) {
  1.2503 -				SDL_colors[i].peFlags =
  1.2504 -						(PC_NOCOLLAPSE|PC_RESERVED);
  1.2505 -				SDL_colors[i].peRed = 0;
  1.2506 -				SDL_colors[i].peGreen = 0;
  1.2507 -				SDL_colors[i].peBlue = 0;
  1.2508 -			}
  1.2509 -		} else {
  1.2510 -			/* First 10 colors are reserved by Windows */
  1.2511 -			for ( i=0; i<10; ++i ) {
  1.2512 -				SDL_colors[i].peFlags = PC_EXPLICIT;
  1.2513 -				SDL_colors[i].peRed = i;
  1.2514 -				SDL_colors[i].peGreen = 0;
  1.2515 -				SDL_colors[i].peBlue = 0;
  1.2516 -			}
  1.2517 -			for ( i=10; i<(10+236); ++i ) {
  1.2518 -				SDL_colors[i].peFlags = PC_NOCOLLAPSE;
  1.2519 -				SDL_colors[i].peRed = 0;
  1.2520 -				SDL_colors[i].peGreen = 0;
  1.2521 -				SDL_colors[i].peBlue = 0;
  1.2522 -			}
  1.2523 -			/* Last 10 colors are reserved by Windows */
  1.2524 -			for ( i=246; i<256; ++i ) {
  1.2525 -				SDL_colors[i].peFlags = PC_EXPLICIT;
  1.2526 -				SDL_colors[i].peRed = i;
  1.2527 -				SDL_colors[i].peGreen = 0;
  1.2528 -				SDL_colors[i].peBlue = 0;
  1.2529 -			}
  1.2530 -		}
  1.2531 -		result = IDirectDraw2_CreatePalette(ddraw2,
  1.2532 -		     			(DDPCAPS_8BIT|DDPCAPS_ALLOW256),
  1.2533 -						SDL_colors, &SDL_palette, NULL);
  1.2534 -		if ( result != DD_OK ) {
  1.2535 -			SetDDerror("DirectDraw2::CreatePalette", result);
  1.2536 -			return(NULL);
  1.2537 -		}
  1.2538 -		result = IDirectDrawSurface3_SetPalette(SDL_primary,
  1.2539 -								SDL_palette);
  1.2540 -		if ( result != DD_OK ) {
  1.2541 -			SetDDerror("DirectDrawSurface3::SetPalette", result);
  1.2542 -			return(NULL);
  1.2543 -		}
  1.2544 -	}
  1.2545 +    /* Free old palette and create a new one if we're in 8-bit mode */
  1.2546 +    if (SDL_palette != NULL) {
  1.2547 +        IDirectDrawPalette_Release (SDL_palette);
  1.2548 +        SDL_palette = NULL;
  1.2549 +    }
  1.2550 +#if defined(NONAMELESSUNION)
  1.2551 +    if (ddsd.ddpfPixelFormat.u1.dwRGBBitCount == 8) {
  1.2552 +#else
  1.2553 +    if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8) {
  1.2554 +#endif
  1.2555 +        int i;
  1.2556  
  1.2557 -	/* Create our video surface using the same pixel format */
  1.2558 -	video = current;
  1.2559 -	if ( (width != video->w) || (height != video->h)
  1.2560 -			|| (video->format->BitsPerPixel != 
  1.2561 -#if defined(NONAMELESSUNION)
  1.2562 -				ddsd.ddpfPixelFormat.u1.dwRGBBitCount) ) {
  1.2563 -#else
  1.2564 -				ddsd.ddpfPixelFormat.dwRGBBitCount) ) {
  1.2565 -#endif
  1.2566 -		SDL_FreeSurface(video);
  1.2567 -		video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0,
  1.2568 +        if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.2569 +            /* We have access to the entire palette */
  1.2570 +            for (i = 0; i < 256; ++i) {
  1.2571 +                SDL_colors[i].peFlags = (PC_NOCOLLAPSE | PC_RESERVED);
  1.2572 +                SDL_colors[i].peRed = 0;
  1.2573 +                SDL_colors[i].peGreen = 0;
  1.2574 +                SDL_colors[i].peBlue = 0;
  1.2575 +            }
  1.2576 +        } else {
  1.2577 +            /* First 10 colors are reserved by Windows */
  1.2578 +            for (i = 0; i < 10; ++i) {
  1.2579 +                SDL_colors[i].peFlags = PC_EXPLICIT;
  1.2580 +                SDL_colors[i].peRed = i;
  1.2581 +                SDL_colors[i].peGreen = 0;
  1.2582 +                SDL_colors[i].peBlue = 0;
  1.2583 +            }
  1.2584 +            for (i = 10; i < (10 + 236); ++i) {
  1.2585 +                SDL_colors[i].peFlags = PC_NOCOLLAPSE;
  1.2586 +                SDL_colors[i].peRed = 0;
  1.2587 +                SDL_colors[i].peGreen = 0;
  1.2588 +                SDL_colors[i].peBlue = 0;
  1.2589 +            }
  1.2590 +            /* Last 10 colors are reserved by Windows */
  1.2591 +            for (i = 246; i < 256; ++i) {
  1.2592 +                SDL_colors[i].peFlags = PC_EXPLICIT;
  1.2593 +                SDL_colors[i].peRed = i;
  1.2594 +                SDL_colors[i].peGreen = 0;
  1.2595 +                SDL_colors[i].peBlue = 0;
  1.2596 +            }
  1.2597 +        }
  1.2598 +        result = IDirectDraw2_CreatePalette (ddraw2,
  1.2599 +                                             (DDPCAPS_8BIT |
  1.2600 +                                              DDPCAPS_ALLOW256), SDL_colors,
  1.2601 +                                             &SDL_palette, NULL);
  1.2602 +        if (result != DD_OK) {
  1.2603 +            SetDDerror ("DirectDraw2::CreatePalette", result);
  1.2604 +            return (NULL);
  1.2605 +        }
  1.2606 +        result = IDirectDrawSurface3_SetPalette (SDL_primary, SDL_palette);
  1.2607 +        if (result != DD_OK) {
  1.2608 +            SetDDerror ("DirectDrawSurface3::SetPalette", result);
  1.2609 +            return (NULL);
  1.2610 +        }
  1.2611 +    }
  1.2612 +
  1.2613 +    /* Create our video surface using the same pixel format */
  1.2614 +    video = current;
  1.2615 +    if ((width != video->w) || (height != video->h)
  1.2616 +        || (video->format->BitsPerPixel !=
  1.2617  #if defined(NONAMELESSUNION)
  1.2618 -				ddsd.ddpfPixelFormat.u1.dwRGBBitCount,
  1.2619 -					ddsd.ddpfPixelFormat.u2.dwRBitMask,
  1.2620 -					ddsd.ddpfPixelFormat.u3.dwGBitMask,
  1.2621 -					ddsd.ddpfPixelFormat.u4.dwBBitMask,
  1.2622 +            ddsd.ddpfPixelFormat.u1.dwRGBBitCount)) {
  1.2623  #else
  1.2624 -				ddsd.ddpfPixelFormat.dwRGBBitCount,
  1.2625 -					ddsd.ddpfPixelFormat.dwRBitMask,
  1.2626 -					ddsd.ddpfPixelFormat.dwGBitMask,
  1.2627 -					ddsd.ddpfPixelFormat.dwBBitMask,
  1.2628 +            ddsd.ddpfPixelFormat.dwRGBBitCount)) {
  1.2629  #endif
  1.2630 -								0);
  1.2631 -		if ( video == NULL ) {
  1.2632 -			SDL_OutOfMemory();
  1.2633 -			return(NULL);
  1.2634 -		}
  1.2635 -		video->w = width;
  1.2636 -		video->h = height;
  1.2637 -		video->pitch = 0;
  1.2638 -	}
  1.2639 -	video->flags = 0;	/* Clear flags */
  1.2640 +        SDL_FreeSurface (video);
  1.2641 +        video = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0,
  1.2642 +#if defined(NONAMELESSUNION)
  1.2643 +                                      ddsd.ddpfPixelFormat.u1.dwRGBBitCount,
  1.2644 +                                      ddsd.ddpfPixelFormat.u2.dwRBitMask,
  1.2645 +                                      ddsd.ddpfPixelFormat.u3.dwGBitMask,
  1.2646 +                                      ddsd.ddpfPixelFormat.u4.dwBBitMask,
  1.2647 +#else
  1.2648 +                                      ddsd.ddpfPixelFormat.dwRGBBitCount,
  1.2649 +                                      ddsd.ddpfPixelFormat.dwRBitMask,
  1.2650 +                                      ddsd.ddpfPixelFormat.dwGBitMask,
  1.2651 +                                      ddsd.ddpfPixelFormat.dwBBitMask,
  1.2652 +#endif
  1.2653 +                                      0);
  1.2654 +        if (video == NULL) {
  1.2655 +            SDL_OutOfMemory ();
  1.2656 +            return (NULL);
  1.2657 +        }
  1.2658 +        video->w = width;
  1.2659 +        video->h = height;
  1.2660 +        video->pitch = 0;
  1.2661 +    }
  1.2662 +    video->flags = 0;           /* Clear flags */
  1.2663  
  1.2664 -	/* If not fullscreen, locking is possible, but it doesn't do what 
  1.2665 -	   the caller really expects -- if the locked surface is written to,
  1.2666 -	   the appropriate portion of the entire screen is modified, not 
  1.2667 -	   the application window, as we would like.
  1.2668 -	   Note that it is still possible to write directly to display
  1.2669 -	   memory, but the application must respect the clip list of
  1.2670 -	   the surface.  There might be some odd timing interactions
  1.2671 -	   involving clip list updates and background refreshing as
  1.2672 -	   Windows moves other windows across our window.
  1.2673 -	   We currently don't support this, even though it might be a
  1.2674 -	   good idea since BeOS has an implementation of BDirectWindow
  1.2675 -	   that does the same thing.  This would be most useful for
  1.2676 -	   applications that do complete screen updates every frame.
  1.2677 -	    -- Fixme?
  1.2678 -	*/
  1.2679 -	if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
  1.2680 -		/* Necessary if we're going from fullscreen to window */
  1.2681 -		if ( video->pixels == NULL ) {
  1.2682 -			video->pitch = (width*video->format->BytesPerPixel);
  1.2683 -			/* Pitch needs to be QWORD (8-byte) aligned */
  1.2684 -			video->pitch = (video->pitch + 7) & ~7;
  1.2685 -			video->pixels = (void *)SDL_malloc(video->h*video->pitch);
  1.2686 -			if ( video->pixels == NULL ) {
  1.2687 -				if ( video != current ) {
  1.2688 -					SDL_FreeSurface(video);
  1.2689 -				}
  1.2690 -				SDL_OutOfMemory();
  1.2691 -				return(NULL);
  1.2692 -			}
  1.2693 -		}
  1.2694 -		dd_surface3 = NULL;
  1.2695 -#if 0 /* FIXME: enable this when SDL consistently reports lost surfaces */
  1.2696 -		if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
  1.2697 -			video->flags |= SDL_HWSURFACE;
  1.2698 -		} else {
  1.2699 -			video->flags |= SDL_SWSURFACE;
  1.2700 -		}
  1.2701 +    /* If not fullscreen, locking is possible, but it doesn't do what 
  1.2702 +       the caller really expects -- if the locked surface is written to,
  1.2703 +       the appropriate portion of the entire screen is modified, not 
  1.2704 +       the application window, as we would like.
  1.2705 +       Note that it is still possible to write directly to display
  1.2706 +       memory, but the application must respect the clip list of
  1.2707 +       the surface.  There might be some odd timing interactions
  1.2708 +       involving clip list updates and background refreshing as
  1.2709 +       Windows moves other windows across our window.
  1.2710 +       We currently don't support this, even though it might be a
  1.2711 +       good idea since BeOS has an implementation of BDirectWindow
  1.2712 +       that does the same thing.  This would be most useful for
  1.2713 +       applications that do complete screen updates every frame.
  1.2714 +       -- Fixme?
  1.2715 +     */
  1.2716 +    if ((flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) {
  1.2717 +        /* Necessary if we're going from fullscreen to window */
  1.2718 +        if (video->pixels == NULL) {
  1.2719 +            video->pitch = (width * video->format->BytesPerPixel);
  1.2720 +            /* Pitch needs to be QWORD (8-byte) aligned */
  1.2721 +            video->pitch = (video->pitch + 7) & ~7;
  1.2722 +            video->pixels = (void *) SDL_malloc (video->h * video->pitch);
  1.2723 +            if (video->pixels == NULL) {
  1.2724 +                if (video != current) {
  1.2725 +                    SDL_FreeSurface (video);
  1.2726 +                }
  1.2727 +                SDL_OutOfMemory ();
  1.2728 +                return (NULL);
  1.2729 +            }
  1.2730 +        }
  1.2731 +        dd_surface3 = NULL;
  1.2732 +#if 0                           /* FIXME: enable this when SDL consistently reports lost surfaces */
  1.2733 +        if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
  1.2734 +            video->flags |= SDL_HWSURFACE;
  1.2735 +        } else {
  1.2736 +            video->flags |= SDL_SWSURFACE;
  1.2737 +        }
  1.2738  #else
  1.2739 -		video->flags |= SDL_SWSURFACE;
  1.2740 +        video->flags |= SDL_SWSURFACE;
  1.2741  #endif
  1.2742 -		if ( (flags & SDL_RESIZABLE) && !(flags & SDL_NOFRAME) ) {
  1.2743 -			video->flags |= SDL_RESIZABLE;
  1.2744 -		}
  1.2745 -		if ( flags & SDL_NOFRAME ) {
  1.2746 -			video->flags |= SDL_NOFRAME;
  1.2747 -		}
  1.2748 -	} else {
  1.2749 -		/* Necessary if we're going from window to fullscreen */
  1.2750 -		if ( video->pixels != NULL ) {
  1.2751 -			SDL_free(video->pixels);
  1.2752 -			video->pixels = NULL;
  1.2753 -		}
  1.2754 -		dd_surface3 = SDL_primary;
  1.2755 -		video->flags |= SDL_HWSURFACE;
  1.2756 -	}
  1.2757 +        if ((flags & SDL_RESIZABLE) && !(flags & SDL_NOFRAME)) {
  1.2758 +            video->flags |= SDL_RESIZABLE;
  1.2759 +        }
  1.2760 +        if (flags & SDL_NOFRAME) {
  1.2761 +            video->flags |= SDL_NOFRAME;
  1.2762 +        }
  1.2763 +    } else {
  1.2764 +        /* Necessary if we're going from window to fullscreen */
  1.2765 +        if (video->pixels != NULL) {
  1.2766 +            SDL_free (video->pixels);
  1.2767 +            video->pixels = NULL;
  1.2768 +        }
  1.2769 +        dd_surface3 = SDL_primary;
  1.2770 +        video->flags |= SDL_HWSURFACE;
  1.2771 +    }
  1.2772  
  1.2773 -	/* See if the primary surface has double-buffering enabled */
  1.2774 -	if ( (ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP) == DDSCAPS_FLIP ) {
  1.2775 -		video->flags |= SDL_DOUBLEBUF;
  1.2776 -	}
  1.2777 +    /* See if the primary surface has double-buffering enabled */
  1.2778 +    if ((ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP) == DDSCAPS_FLIP) {
  1.2779 +        video->flags |= SDL_DOUBLEBUF;
  1.2780 +    }
  1.2781  
  1.2782 -	/* Allocate the SDL surface associated with the primary surface */
  1.2783 -	if ( DX5_AllocDDSurface(this, video, dd_surface3,
  1.2784 -	                        video->flags&SDL_HWSURFACE) < 0 ) {
  1.2785 -		if ( video != current ) {
  1.2786 -			SDL_FreeSurface(video);
  1.2787 -		}
  1.2788 -		return(NULL);
  1.2789 -	}
  1.2790 +    /* Allocate the SDL surface associated with the primary surface */
  1.2791 +    if (DX5_AllocDDSurface (this, video, dd_surface3,
  1.2792 +                            video->flags & SDL_HWSURFACE) < 0) {
  1.2793 +        if (video != current) {
  1.2794 +            SDL_FreeSurface (video);
  1.2795 +        }
  1.2796 +        return (NULL);
  1.2797 +    }
  1.2798  
  1.2799 -	/* Use the appropriate blitting function */
  1.2800 -	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.2801 -		video->flags |= SDL_FULLSCREEN;
  1.2802 -		if ( video->format->palette != NULL ) {
  1.2803 -			video->flags |= SDL_HWPALETTE;
  1.2804 -		}
  1.2805 -		this->UpdateRects = DX5_DirectUpdate;
  1.2806 -	} else {
  1.2807 -		this->UpdateRects = DX5_WindowUpdate;
  1.2808 -	}
  1.2809 +    /* Use the appropriate blitting function */
  1.2810 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.2811 +        video->flags |= SDL_FULLSCREEN;
  1.2812 +        if (video->format->palette != NULL) {
  1.2813 +            video->flags |= SDL_HWPALETTE;
  1.2814 +        }
  1.2815 +        this->UpdateRects = DX5_DirectUpdate;
  1.2816 +    } else {
  1.2817 +        this->UpdateRects = DX5_WindowUpdate;
  1.2818 +    }
  1.2819  
  1.2820 -	/* Make our window the proper size, set the clipper, then show it */
  1.2821 -	if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
  1.2822 -		/* Create and set a clipper on our primary surface */
  1.2823 -		if ( SDL_clipper == NULL ) {
  1.2824 -			result = IDirectDraw2_CreateClipper(ddraw2,
  1.2825 -							0, &SDL_clipper, NULL);
  1.2826 -			if ( result != DD_OK ) {
  1.2827 -				if ( video != current ) {
  1.2828 -					SDL_FreeSurface(video);
  1.2829 -				}
  1.2830 -				SetDDerror("DirectDraw2::CreateClipper",result);
  1.2831 -				return(NULL);
  1.2832 -			}
  1.2833 -		}
  1.2834 -		result = IDirectDrawClipper_SetHWnd(SDL_clipper, 0, SDL_Window);
  1.2835 -		if ( result != DD_OK ) {
  1.2836 -			if ( video != current ) {
  1.2837 -				SDL_FreeSurface(video);
  1.2838 -			}
  1.2839 -			SetDDerror("DirectDrawClipper::SetHWnd", result);
  1.2840 -			return(NULL);
  1.2841 -		}
  1.2842 -		result = IDirectDrawSurface3_SetClipper(SDL_primary,
  1.2843 -								SDL_clipper);
  1.2844 -		if ( result != DD_OK ) {
  1.2845 -			if ( video != current ) {
  1.2846 -				SDL_FreeSurface(video);
  1.2847 -			}
  1.2848 -			SetDDerror("DirectDrawSurface3::SetClipper", result);
  1.2849 -			return(NULL);
  1.2850 -		}
  1.2851 +    /* Make our window the proper size, set the clipper, then show it */
  1.2852 +    if ((flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) {
  1.2853 +        /* Create and set a clipper on our primary surface */
  1.2854 +        if (SDL_clipper == NULL) {
  1.2855 +            result = IDirectDraw2_CreateClipper (ddraw2,
  1.2856 +                                                 0, &SDL_clipper, NULL);
  1.2857 +            if (result != DD_OK) {
  1.2858 +                if (video != current) {
  1.2859 +                    SDL_FreeSurface (video);
  1.2860 +                }
  1.2861 +                SetDDerror ("DirectDraw2::CreateClipper", result);
  1.2862 +                return (NULL);
  1.2863 +            }
  1.2864 +        }
  1.2865 +        result = IDirectDrawClipper_SetHWnd (SDL_clipper, 0, SDL_Window);
  1.2866 +        if (result != DD_OK) {
  1.2867 +            if (video != current) {
  1.2868 +                SDL_FreeSurface (video);
  1.2869 +            }
  1.2870 +            SetDDerror ("DirectDrawClipper::SetHWnd", result);
  1.2871 +            return (NULL);
  1.2872 +        }
  1.2873 +        result = IDirectDrawSurface3_SetClipper (SDL_primary, SDL_clipper);
  1.2874 +        if (result != DD_OK) {
  1.2875 +            if (video != current) {
  1.2876 +                SDL_FreeSurface (video);
  1.2877 +            }
  1.2878 +            SetDDerror ("DirectDrawSurface3::SetClipper", result);
  1.2879 +            return (NULL);
  1.2880 +        }
  1.2881  
  1.2882 -		/* Resize the window (copied from SDL WinDIB driver) */
  1.2883 -		if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
  1.2884 -			RECT bounds;
  1.2885 -			int  x, y;
  1.2886 -			UINT swp_flags;
  1.2887 -			const char *window = NULL;
  1.2888 -			const char *center = NULL;
  1.2889 +        /* Resize the window (copied from SDL WinDIB driver) */
  1.2890 +        if (!SDL_windowid && !IsZoomed (SDL_Window)) {
  1.2891 +            RECT bounds;
  1.2892 +            int x, y;
  1.2893 +            UINT swp_flags;
  1.2894 +            const char *window = NULL;
  1.2895 +            const char *center = NULL;
  1.2896  
  1.2897 -			if ( !SDL_windowX && !SDL_windowY ) {
  1.2898 -				window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
  1.2899 -				center = SDL_getenv("SDL_VIDEO_CENTERED");
  1.2900 -				if ( window ) {
  1.2901 -					if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) {
  1.2902 -						SDL_windowX = x;
  1.2903 -						SDL_windowY = y;
  1.2904 -					}
  1.2905 -					if ( SDL_strcmp(window, "center") == 0 ) {
  1.2906 -						center = window;
  1.2907 -					}
  1.2908 -				}
  1.2909 -			}
  1.2910 -			swp_flags = SWP_NOCOPYBITS;
  1.2911 +            if (!SDL_windowX && !SDL_windowY) {
  1.2912 +                window = SDL_getenv ("SDL_VIDEO_WINDOW_POS");
  1.2913 +                center = SDL_getenv ("SDL_VIDEO_CENTERED");
  1.2914 +                if (window) {
  1.2915 +                    if (SDL_sscanf (window, "%d,%d", &x, &y) == 2) {
  1.2916 +                        SDL_windowX = x;
  1.2917 +                        SDL_windowY = y;
  1.2918 +                    }
  1.2919 +                    if (SDL_strcmp (window, "center") == 0) {
  1.2920 +                        center = window;
  1.2921 +                    }
  1.2922 +                }
  1.2923 +            }
  1.2924 +            swp_flags = SWP_NOCOPYBITS;
  1.2925  
  1.2926 -			bounds.left = SDL_windowX;
  1.2927 -			bounds.top = SDL_windowY;
  1.2928 -			bounds.right = SDL_windowX+video->w;
  1.2929 -			bounds.bottom = SDL_windowY+video->h;
  1.2930 -			AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
  1.2931 -			width = bounds.right-bounds.left;
  1.2932 -			height = bounds.bottom-bounds.top;
  1.2933 -			if ( center ) {
  1.2934 -				x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
  1.2935 -				y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
  1.2936 -			} else if ( SDL_windowX || SDL_windowY || window ) {
  1.2937 -				x = bounds.left;
  1.2938 -				y = bounds.top;
  1.2939 -			} else {
  1.2940 -				x = y = -1;
  1.2941 -				swp_flags |= SWP_NOMOVE;
  1.2942 -			}
  1.2943 -			SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags);
  1.2944 -			SDL_windowX = SDL_bounds.left;
  1.2945 -			SDL_windowY = SDL_bounds.top;
  1.2946 -		}
  1.2947 +            bounds.left = SDL_windowX;
  1.2948 +            bounds.top = SDL_windowY;
  1.2949 +            bounds.right = SDL_windowX + video->w;
  1.2950 +            bounds.bottom = SDL_windowY + video->h;
  1.2951 +            AdjustWindowRectEx (&bounds,
  1.2952 +                                GetWindowLong (SDL_Window, GWL_STYLE),
  1.2953 +                                FALSE, 0);
  1.2954 +            width = bounds.right - bounds.left;
  1.2955 +            height = bounds.bottom - bounds.top;
  1.2956 +            if (center) {
  1.2957 +                x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2;
  1.2958 +                y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2;
  1.2959 +            } else if (SDL_windowX || SDL_windowY || window) {
  1.2960 +                x = bounds.left;
  1.2961 +                y = bounds.top;
  1.2962 +            } else {
  1.2963 +                x = y = -1;
  1.2964 +                swp_flags |= SWP_NOMOVE;
  1.2965 +            }
  1.2966 +            SetWindowPos (SDL_Window, HWND_NOTOPMOST, x, y, width, height,
  1.2967 +                          swp_flags);
  1.2968 +            SDL_windowX = SDL_bounds.left;
  1.2969 +            SDL_windowY = SDL_bounds.top;
  1.2970 +        }
  1.2971  
  1.2972 -	}
  1.2973 -	ShowWindow(SDL_Window, SW_SHOW);
  1.2974 -	SetForegroundWindow(SDL_Window);
  1.2975 -	SDL_resizing = 0;
  1.2976 +    }
  1.2977 +    ShowWindow (SDL_Window, SW_SHOW);
  1.2978 +    SetForegroundWindow (SDL_Window);
  1.2979 +    SDL_resizing = 0;
  1.2980  
  1.2981 -	/* JC 14 Mar 2006
  1.2982 -		Flush the message loop or this can cause big problems later
  1.2983 -		Especially if the user decides to use dialog boxes or assert()!
  1.2984 -	*/
  1.2985 -	WIN_FlushMessageQueue();
  1.2986 +    /* JC 14 Mar 2006
  1.2987 +       Flush the message loop or this can cause big problems later
  1.2988 +       Especially if the user decides to use dialog boxes or assert()!
  1.2989 +     */
  1.2990 +    WIN_FlushMessageQueue ();
  1.2991  
  1.2992 -	/* We're live! */
  1.2993 -	return(video);
  1.2994 +    /* We're live! */
  1.2995 +    return (video);
  1.2996  }
  1.2997  
  1.2998 -struct private_hwdata {
  1.2999 -	LPDIRECTDRAWSURFACE3 dd_surface;
  1.3000 -	LPDIRECTDRAWSURFACE3 dd_writebuf;
  1.3001 +struct private_hwdata
  1.3002 +{
  1.3003 +    LPDIRECTDRAWSURFACE3 dd_surface;
  1.3004 +    LPDIRECTDRAWSURFACE3 dd_writebuf;
  1.3005  };
  1.3006  
  1.3007 -static int DX5_AllocDDSurface(_THIS, SDL_Surface *surface, 
  1.3008 -				LPDIRECTDRAWSURFACE3 requested, Uint32 flag)
  1.3009 +static int
  1.3010 +DX5_AllocDDSurface (_THIS, SDL_Surface * surface,
  1.3011 +                    LPDIRECTDRAWSURFACE3 requested, Uint32 flag)
  1.3012  {
  1.3013 -	LPDIRECTDRAWSURFACE  dd_surface1;
  1.3014 -	LPDIRECTDRAWSURFACE3 dd_surface3;
  1.3015 -	DDSURFACEDESC ddsd;
  1.3016 -	HRESULT result;
  1.3017 +    LPDIRECTDRAWSURFACE dd_surface1;
  1.3018 +    LPDIRECTDRAWSURFACE3 dd_surface3;
  1.3019 +    DDSURFACEDESC ddsd;
  1.3020 +    HRESULT result;
  1.3021  
  1.3022 -	/* Clear the hardware flag, in case we fail */
  1.3023 -	surface->flags &= ~flag;
  1.3024 +    /* Clear the hardware flag, in case we fail */
  1.3025 +    surface->flags &= ~flag;
  1.3026  
  1.3027 -	/* Allocate the hardware acceleration data */
  1.3028 -	surface->hwdata = (struct private_hwdata *)
  1.3029 -					SDL_malloc(sizeof(*surface->hwdata));
  1.3030 -	if ( surface->hwdata == NULL ) {
  1.3031 -		SDL_OutOfMemory();
  1.3032 -		return(-1);
  1.3033 -	}
  1.3034 -	dd_surface3 = NULL;
  1.3035 +    /* Allocate the hardware acceleration data */
  1.3036 +    surface->hwdata = (struct private_hwdata *)
  1.3037 +        SDL_malloc (sizeof (*surface->hwdata));
  1.3038 +    if (surface->hwdata == NULL) {
  1.3039 +        SDL_OutOfMemory ();
  1.3040 +        return (-1);
  1.3041 +    }
  1.3042 +    dd_surface3 = NULL;
  1.3043  
  1.3044 -	/* Set up the surface description */
  1.3045 -	SDL_memset(&ddsd, 0, sizeof(ddsd));
  1.3046 -	ddsd.dwSize = sizeof(ddsd);
  1.3047 -	ddsd.dwFlags = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|
  1.3048 -					DDSD_PITCH|DDSD_PIXELFORMAT);
  1.3049 -	ddsd.dwWidth = surface->w;
  1.3050 -	ddsd.dwHeight= surface->h;
  1.3051 +    /* Set up the surface description */
  1.3052 +    SDL_memset (&ddsd, 0, sizeof (ddsd));
  1.3053 +    ddsd.dwSize = sizeof (ddsd);
  1.3054 +    ddsd.dwFlags = (DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS |
  1.3055 +                    DDSD_PITCH | DDSD_PIXELFORMAT);
  1.3056 +    ddsd.dwWidth = surface->w;
  1.3057 +    ddsd.dwHeight = surface->h;
  1.3058  #if defined(NONAMELESSUNION)
  1.3059 -	ddsd.u1.lPitch = surface->pitch;
  1.3060 +    ddsd.u1.lPitch = surface->pitch;
  1.3061  #else
  1.3062 -	ddsd.lPitch = surface->pitch;
  1.3063 +    ddsd.lPitch = surface->pitch;
  1.3064  #endif
  1.3065 -	if ( (flag & SDL_HWSURFACE) == SDL_HWSURFACE ) {
  1.3066 -		ddsd.ddsCaps.dwCaps =
  1.3067 -				(DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY);
  1.3068 -	} else {
  1.3069 -		ddsd.ddsCaps.dwCaps =
  1.3070 -				(DDSCAPS_OFFSCREENPLAIN|DDSCAPS_SYSTEMMEMORY);
  1.3071 -	}
  1.3072 -	ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
  1.3073 -	ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
  1.3074 -	if ( surface->format->palette ) {
  1.3075 -		ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
  1.3076 -	}
  1.3077 +    if ((flag & SDL_HWSURFACE) == SDL_HWSURFACE) {
  1.3078 +        ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY);
  1.3079 +    } else {
  1.3080 +        ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY);
  1.3081 +    }
  1.3082 +    ddsd.ddpfPixelFormat.dwSize = sizeof (ddsd.ddpfPixelFormat);
  1.3083 +    ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
  1.3084 +    if (surface->format->palette) {
  1.3085 +        ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
  1.3086 +    }
  1.3087  #if defined(NONAMELESSUNION)
  1.3088 -	ddsd.ddpfPixelFormat.u1.dwRGBBitCount = surface->format->BitsPerPixel;
  1.3089 -	ddsd.ddpfPixelFormat.u2.dwRBitMask = surface->format->Rmask;
  1.3090 -	ddsd.ddpfPixelFormat.u3.dwGBitMask = surface->format->Gmask;
  1.3091 -	ddsd.ddpfPixelFormat.u4.dwBBitMask = surface->format->Bmask;
  1.3092 +    ddsd.ddpfPixelFormat.u1.dwRGBBitCount = surface->format->BitsPerPixel;
  1.3093 +    ddsd.ddpfPixelFormat.u2.dwRBitMask = surface->format->Rmask;
  1.3094 +    ddsd.ddpfPixelFormat.u3.dwGBitMask = surface->format->Gmask;
  1.3095 +    ddsd.ddpfPixelFormat.u4.dwBBitMask = surface->format->Bmask;
  1.3096  #else
  1.3097 -	ddsd.ddpfPixelFormat.dwRGBBitCount = surface->format->BitsPerPixel;
  1.3098 -	ddsd.ddpfPixelFormat.dwRBitMask = surface->format->Rmask;
  1.3099 -	ddsd.ddpfPixelFormat.dwGBitMask = surface->format->Gmask;
  1.3100 -	ddsd.ddpfPixelFormat.dwBBitMask = surface->format->Bmask;
  1.3101 +    ddsd.ddpfPixelFormat.dwRGBBitCount = surface->format->BitsPerPixel;
  1.3102 +    ddsd.ddpfPixelFormat.dwRBitMask = surface->format->Rmask;
  1.3103 +    ddsd.ddpfPixelFormat.dwGBitMask = surface->format->Gmask;
  1.3104 +    ddsd.ddpfPixelFormat.dwBBitMask = surface->format->Bmask;
  1.3105  #endif
  1.3106  
  1.3107 -	/* Create the DirectDraw video surface */
  1.3108 -	if ( requested != NULL ) {
  1.3109 -		dd_surface3 = requested;
  1.3110 -	} else {
  1.3111 -		result = IDirectDraw2_CreateSurface(ddraw2,
  1.3112 -						&ddsd, &dd_surface1, NULL); 
  1.3113 -		if ( result != DD_OK ) {
  1.3114 -			SetDDerror("DirectDraw2::CreateSurface", result);
  1.3115 -			goto error_end;
  1.3116 -		}
  1.3117 -		result = IDirectDrawSurface_QueryInterface(dd_surface1,
  1.3118 -			&IID_IDirectDrawSurface3, (LPVOID *)&dd_surface3);
  1.3119 -		IDirectDrawSurface_Release(dd_surface1);
  1.3120 -		if ( result != DD_OK ) {
  1.3121 -			SetDDerror("DirectDrawSurface::QueryInterface", result);
  1.3122 -			goto error_end;
  1.3123 -		}
  1.3124 -	}
  1.3125 +    /* Create the DirectDraw video surface */
  1.3126 +    if (requested != NULL) {
  1.3127 +        dd_surface3 = requested;
  1.3128 +    } else {
  1.3129 +        result = IDirectDraw2_CreateSurface (ddraw2,
  1.3130 +                                             &ddsd, &dd_surface1, NULL);
  1.3131 +        if (result != DD_OK) {
  1.3132 +            SetDDerror ("DirectDraw2::CreateSurface", result);
  1.3133 +            goto error_end;
  1.3134 +        }
  1.3135 +        result = IDirectDrawSurface_QueryInterface (dd_surface1,
  1.3136 +                                                    &IID_IDirectDrawSurface3,
  1.3137 +                                                    (LPVOID *) & dd_surface3);
  1.3138 +        IDirectDrawSurface_Release (dd_surface1);
  1.3139 +        if (result != DD_OK) {
  1.3140 +            SetDDerror ("DirectDrawSurface::QueryInterface", result);
  1.3141 +            goto error_end;
  1.3142 +        }
  1.3143 +    }
  1.3144  
  1.3145 -	if ( (flag & SDL_HWSURFACE) == SDL_HWSURFACE ) {
  1.3146 -		/* Check to see whether the surface actually ended up
  1.3147 -		   in video memory, and fail if not.  We expect the
  1.3148 -		   surfaces we create here to actually be in hardware!
  1.3149 -		*/
  1.3150 -		result = IDirectDrawSurface3_GetCaps(dd_surface3,&ddsd.ddsCaps);
  1.3151 -		if ( result != DD_OK ) {
  1.3152 -			SetDDerror("DirectDrawSurface3::GetCaps", result);
  1.3153 -			goto error_end;
  1.3154 -		}
  1.3155 -		if ( (ddsd.ddsCaps.dwCaps&DDSCAPS_VIDEOMEMORY) !=
  1.3156 -							DDSCAPS_VIDEOMEMORY ) {
  1.3157 -			SDL_SetError("No room in video memory");
  1.3158 -			goto error_end;
  1.3159 -		}
  1.3160 -	} else {
  1.3161 -		/* Try to hook our surface memory */
  1.3162 -		ddsd.dwFlags = DDSD_LPSURFACE;
  1.3163 -		ddsd.lpSurface = surface->pixels;
  1.3164 -		result = IDirectDrawSurface3_SetSurfaceDesc(dd_surface3,
  1.3165 -								&ddsd, 0);
  1.3166 -		if ( result != DD_OK ) {
  1.3167 -			SetDDerror("DirectDraw2::SetSurfaceDesc", result);
  1.3168 -			goto error_end;
  1.3169 -		}
  1.3170 -	
  1.3171 -	}
  1.3172 +    if ((flag & SDL_HWSURFACE) == SDL_HWSURFACE) {
  1.3173 +        /* Check to see whether the surface actually ended up
  1.3174 +           in video memory, and fail if not.  We expect the
  1.3175 +           surfaces we create here to actually be in hardware!
  1.3176 +         */
  1.3177 +        result = IDirectDrawSurface3_GetCaps (dd_surface3, &ddsd.ddsCaps);
  1.3178 +        if (result != DD_OK) {
  1.3179 +            SetDDerror ("DirectDrawSurface3::GetCaps", result);
  1.3180 +            goto error_end;
  1.3181 +        }
  1.3182 +        if ((ddsd.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) !=
  1.3183 +            DDSCAPS_VIDEOMEMORY) {
  1.3184 +            SDL_SetError ("No room in video memory");
  1.3185 +            goto error_end;
  1.3186 +        }
  1.3187 +    } else {
  1.3188 +        /* Try to hook our surface memory */
  1.3189 +        ddsd.dwFlags = DDSD_LPSURFACE;
  1.3190 +        ddsd.lpSurface = surface->pixels;
  1.3191 +        result = IDirectDrawSurface3_SetSurfaceDesc (dd_surface3, &ddsd, 0);
  1.3192 +        if (result != DD_OK) {
  1.3193 +            SetDDerror ("DirectDraw2::SetSurfaceDesc", result);
  1.3194 +            goto error_end;
  1.3195 +        }
  1.3196  
  1.3197 -	/* Make sure the surface format was set properly */
  1.3198 -	SDL_memset(&ddsd, 0, sizeof(ddsd));
  1.3199 -	ddsd.dwSize = sizeof(ddsd);
  1.3200 -	result = IDirectDrawSurface3_Lock(dd_surface3, NULL,
  1.3201 -		&ddsd, (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
  1.3202 -	if ( result != DD_OK ) {
  1.3203 -		SetDDerror("DirectDrawSurface3::Lock", result);
  1.3204 -		goto error_end;
  1.3205 -	}
  1.3206 -	IDirectDrawSurface3_Unlock(dd_surface3, NULL);
  1.3207 +    }
  1.3208  
  1.3209 -	if ( (flag & SDL_HWSURFACE) == SDL_SWSURFACE ) {
  1.3210 -		if ( ddsd.lpSurface != surface->pixels ) {
  1.3211 -			SDL_SetError("DDraw didn't use SDL surface memory");
  1.3212 -			goto error_end;
  1.3213 -		}
  1.3214 -		if (
  1.3215 +    /* Make sure the surface format was set properly */
  1.3216 +    SDL_memset (&ddsd, 0, sizeof (ddsd));
  1.3217 +    ddsd.dwSize = sizeof (ddsd);
  1.3218 +    result = IDirectDrawSurface3_Lock (dd_surface3, NULL,
  1.3219 +                                       &ddsd,
  1.3220 +                                       (DDLOCK_NOSYSLOCK | DDLOCK_WAIT),
  1.3221 +                                       NULL);
  1.3222 +    if (result != DD_OK) {
  1.3223 +        SetDDerror ("DirectDrawSurface3::Lock", result);
  1.3224 +        goto error_end;
  1.3225 +    }
  1.3226 +    IDirectDrawSurface3_Unlock (dd_surface3, NULL);
  1.3227 +
  1.3228 +    if ((flag & SDL_HWSURFACE) == SDL_SWSURFACE) {
  1.3229 +        if (ddsd.lpSurface != surface->pixels) {
  1.3230 +            SDL_SetError ("DDraw didn't use SDL surface memory");
  1.3231 +            goto error_end;
  1.3232 +        }
  1.3233 +        if (
  1.3234  #if defined(NONAMELESSUNION)
  1.3235 -			ddsd.u1.lPitch
  1.3236 +               ddsd.u1.lPitch
  1.3237  #else
  1.3238 -			ddsd.lPitch
  1.3239 +               ddsd.lPitch
  1.3240  #endif
  1.3241 -				 != (LONG)surface->pitch ) {
  1.3242 -			SDL_SetError("DDraw created surface with wrong pitch");
  1.3243 -			goto error_end;
  1.3244 -		}
  1.3245 -	} else {
  1.3246 +               != (LONG) surface->pitch) {
  1.3247 +            SDL_SetError ("DDraw created surface with wrong pitch");
  1.3248 +            goto error_end;
  1.3249 +        }
  1.3250 +    } else {
  1.3251  #if defined(NONAMELESSUNION)
  1.3252 -		surface->pitch = (Uint16)ddsd.u1.lPitch;
  1.3253 +        surface->pitch = (Uint16) ddsd.u1.lPitch;
  1.3254  #else
  1.3255 -		surface->pitch = (Uint16)ddsd.lPitch;
  1.3256 +        surface->pitch = (Uint16) ddsd.lPitch;
  1.3257  #endif
  1.3258 -	}
  1.3259 +    }
  1.3260  #if defined(NONAMELESSUNION)
  1.3261 -	if ( (ddsd.ddpfPixelFormat.u1.dwRGBBitCount != 
  1.3262 -					surface->format->BitsPerPixel) ||
  1.3263 -	     (ddsd.ddpfPixelFormat.u2.dwRBitMask != surface->format->Rmask) ||
  1.3264 -	     (ddsd.ddpfPixelFormat.u3.dwGBitMask != surface->format->Gmask) ||
  1.3265 -	     (ddsd.ddpfPixelFormat.u4.dwBBitMask != surface->format->Bmask) ){
  1.3266 +    if ((ddsd.ddpfPixelFormat.u1.dwRGBBitCount !=
  1.3267 +         surface->format->BitsPerPixel) ||
  1.3268 +        (ddsd.ddpfPixelFormat.u2.dwRBitMask != surface->format->Rmask) ||
  1.3269 +        (ddsd.ddpfPixelFormat.u3.dwGBitMask != surface->format->Gmask) ||
  1.3270 +        (ddsd.ddpfPixelFormat.u4.dwBBitMask != surface->format->Bmask)) {
  1.3271  #else
  1.3272 -	if ( (ddsd.ddpfPixelFormat.dwRGBBitCount != 
  1.3273 -					surface->format->BitsPerPixel) ||
  1.3274 -	     (ddsd.ddpfPixelFormat.dwRBitMask != surface->format->Rmask) ||
  1.3275 -	     (ddsd.ddpfPixelFormat.dwGBitMask != surface->format->Gmask) ||
  1.3276 -	     (ddsd.ddpfPixelFormat.dwBBitMask != surface->format->Bmask) ){
  1.3277 +    if ((ddsd.ddpfPixelFormat.dwRGBBitCount !=
  1.3278 +         surface->format->BitsPerPixel) ||
  1.3279 +        (ddsd.ddpfPixelFormat.dwRBitMask != surface->format->Rmask) ||
  1.3280 +        (ddsd.ddpfPixelFormat.dwGBitMask != surface->format->Gmask) ||
  1.3281 +        (ddsd.ddpfPixelFormat.dwBBitMask != surface->format->Bmask)) {
  1.3282  #endif
  1.3283 -		SDL_SetError("DDraw didn't use SDL surface description");
  1.3284 -		goto error_end;
  1.3285 -	}
  1.3286 -	if ( (ddsd.dwWidth != (DWORD)surface->w) ||
  1.3287 -		(ddsd.dwHeight != (DWORD)surface->h) ) {
  1.3288 -		SDL_SetError("DDraw created surface with wrong size");
  1.3289 -		goto error_end;
  1.3290 -	}
  1.3291 +        SDL_SetError ("DDraw didn't use SDL surface description");
  1.3292 +        goto error_end;
  1.3293 +    }
  1.3294 +    if ((ddsd.dwWidth != (DWORD) surface->w) ||
  1.3295 +        (ddsd.dwHeight != (DWORD) surface->h)) {
  1.3296 +        SDL_SetError ("DDraw created surface with wrong size");
  1.3297 +        goto error_end;
  1.3298 +    }
  1.3299  
  1.3300 -	/* Set the surface private data */
  1.3301 -	surface->flags |= flag;
  1.3302 -	surface->hwdata->dd_surface = dd_surface3;
  1.3303 -	if ( (surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
  1.3304 -		LPDIRECTDRAWSURFACE3 dd_writebuf;
  1.3305 +    /* Set the surface private data */
  1.3306 +    surface->flags |= flag;
  1.3307 +    surface->hwdata->dd_surface = dd_surface3;
  1.3308 +    if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
  1.3309 +        LPDIRECTDRAWSURFACE3 dd_writebuf;
  1.3310  
  1.3311 -		ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
  1.3312 -		result = IDirectDrawSurface3_GetAttachedSurface(dd_surface3,
  1.3313 -						&ddsd.ddsCaps, &dd_writebuf);
  1.3314 -		if ( result != DD_OK ) {
  1.3315 -			SetDDerror("DirectDrawSurface3::GetAttachedSurface",
  1.3316 -								result);
  1.3317 -		} else {
  1.3318 -			dd_surface3 = dd_writebuf;
  1.3319 -		}
  1.3320 -	}
  1.3321 -	surface->hwdata->dd_writebuf = dd_surface3;
  1.3322 +        ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
  1.3323 +        result = IDirectDrawSurface3_GetAttachedSurface (dd_surface3,
  1.3324 +                                                         &ddsd.ddsCaps,
  1.3325 +                                                         &dd_writebuf);
  1.3326 +        if (result != DD_OK) {
  1.3327 +            SetDDerror ("DirectDrawSurface3::GetAttachedSurface", result);
  1.3328 +        } else {
  1.3329 +            dd_surface3 = dd_writebuf;
  1.3330 +        }
  1.3331 +    }
  1.3332 +    surface->hwdata->dd_writebuf = dd_surface3;
  1.3333  
  1.3334 -	/* We're ready to go! */
  1.3335 -	return(0);
  1.3336 +    /* We're ready to go! */
  1.3337 +    return (0);
  1.3338  
  1.3339 -	/* Okay, so goto's are cheesy, but there are so many possible
  1.3340 -	   errors in this function, and the cleanup is the same in 
  1.3341 -	   every single case.  Is there a better way, other than deeply
  1.3342 -	   nesting the code?
  1.3343 -	*/
  1.3344 -error_end:
  1.3345 -	if ( (dd_surface3 != NULL) && (dd_surface3 != requested) ) {
  1.3346 -		IDirectDrawSurface_Release(dd_surface3);
  1.3347 -	}
  1.3348 -	SDL_free(surface->hwdata);
  1.3349 -	surface->hwdata = NULL;
  1.3350 -	return(-1);
  1.3351 +    /* Okay, so goto's are cheesy, but there are so many possible
  1.3352 +       errors in this function, and the cleanup is the same in 
  1.3353 +       every single case.  Is there a better way, other than deeply
  1.3354 +       nesting the code?
  1.3355 +     */
  1.3356 +  error_end:
  1.3357 +    if ((dd_surface3 != NULL) && (dd_surface3 != requested)) {
  1.3358 +        IDirectDrawSurface_Release (dd_surface3);
  1.3359 +    }
  1.3360 +    SDL_free (surface->hwdata);
  1.3361 +    surface->hwdata = NULL;
  1.3362 +    return (-1);
  1.3363  }
  1.3364  
  1.3365 -static int DX5_AllocHWSurface(_THIS, SDL_Surface *surface)
  1.3366 +static int
  1.3367 +DX5_AllocHWSurface (_THIS, SDL_Surface * surface)
  1.3368  {
  1.3369 -	/* DDraw limitation -- you need to set cooperative level first */
  1.3370 -	if ( SDL_primary == NULL ) {
  1.3371 -		SDL_SetError("You must set a non-GL video mode first");
  1.3372 -		return(-1);
  1.3373 -	}
  1.3374 -	return(DX5_AllocDDSurface(this, surface, NULL, SDL_HWSURFACE));
  1.3375 +    /* DDraw limitation -- you need to set cooperative level first */
  1.3376 +    if (SDL_primary == NULL) {
  1.3377 +        SDL_SetError ("You must set a non-GL video mode first");
  1.3378 +        return (-1);
  1.3379 +    }
  1.3380 +    return (DX5_AllocDDSurface (this, surface, NULL, SDL_HWSURFACE));
  1.3381  }
  1.3382  
  1.3383  #ifdef DDRAW_DEBUG
  1.3384 -void PrintSurface(char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags)
  1.3385 +void
  1.3386 +PrintSurface (char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags)
  1.3387  {
  1.3388 -	DDSURFACEDESC ddsd;
  1.3389 +    DDSURFACEDESC ddsd;
  1.3390 +
  1.3391 +    /* Lock and load! */
  1.3392 +    SDL_memset (&ddsd, 0, sizeof (ddsd));
  1.3393 +    ddsd.dwSize = sizeof (ddsd);
  1.3394 +    if (IDirectDrawSurface3_Lock (surface, NULL, &ddsd,
  1.3395 +                                  (DDLOCK_NOSYSLOCK | DDLOCK_WAIT),
  1.3396 +                                  NULL) != DD_OK) {
  1.3397 +        return;
  1.3398 +    }
  1.3399 +    IDirectDrawSurface3_Unlock (surface, NULL);
  1.3400  
  1.3401 -	/* Lock and load! */
  1.3402 -	SDL_memset(&ddsd, 0, sizeof(ddsd));
  1.3403 -	ddsd.dwSize = sizeof(ddsd);
  1.3404 -	if ( IDirectDrawSurface3_Lock(surface, NULL, &ddsd,
  1.3405 -			(DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL) != DD_OK ) {
  1.3406 -		return;
  1.3407 -	}
  1.3408 -	IDirectDrawSurface3_Unlock(surface, NULL);
  1.3409 -	
  1.3410 -	fprintf(stderr, "%s:\n", title);
  1.3411 -	fprintf(stderr, "\tSize: %dx%d in %s at %ld bpp (pitch = %ld)\n",
  1.3412 -		ddsd.dwWidth, ddsd.dwHeight,
  1.3413 -		(flags & SDL_HWSURFACE) ? "hardware" : "software",
  1.3414 +    fprintf (stderr, "%s:\n", title);
  1.3415 +    fprintf (stderr, "\tSize: %dx%d in %s at %ld bpp (pitch = %ld)\n",
  1.3416 +             ddsd.dwWidth, ddsd.dwHeight,
  1.3417 +             (flags & SDL_HWSURFACE) ? "hardware" : "software",
  1.3418  #if defined(NONAMELESSUNION)
  1.3419 -		ddsd.ddpfPixelFormat.u1.dwRGBBitCount, ddsd.u1.lPitch);
  1.3420 +             ddsd.ddpfPixelFormat.u1.dwRGBBitCount, ddsd.u1.lPitch);
  1.3421  #else
  1.3422 -		ddsd.ddpfPixelFormat.dwRGBBitCount, ddsd.lPitch);
  1.3423 +             ddsd.ddpfPixelFormat.dwRGBBitCount, ddsd.lPitch);
  1.3424  #endif
  1.3425 -	fprintf(stderr, "\tR = 0x%X, G = 0x%X, B = 0x%X\n", 
  1.3426 +    fprintf (stderr, "\tR = 0x%X, G = 0x%X, B = 0x%X\n",
  1.3427  #if defined(NONAMELESSUNION)
  1.3428 -	     		ddsd.ddpfPixelFormat.u2.dwRBitMask,
  1.3429 -	     		ddsd.ddpfPixelFormat.u3.dwGBitMask,
  1.3430 -	     		ddsd.ddpfPixelFormat.u4.dwBBitMask);
  1.3431 +             ddsd.ddpfPixelFormat.u2.dwRBitMask,
  1.3432 +             ddsd.ddpfPixelFormat.u3.dwGBitMask,
  1.3433 +             ddsd.ddpfPixelFormat.u4.dwBBitMask);
  1.3434  #else
  1.3435 -	     		ddsd.ddpfPixelFormat.dwRBitMask,
  1.3436 -	     		ddsd.ddpfPixelFormat.dwGBitMask,
  1.3437 -	     		ddsd.ddpfPixelFormat.dwBBitMask);
  1.3438 +             ddsd.ddpfPixelFormat.dwRBitMask,
  1.3439 +             ddsd.ddpfPixelFormat.dwGBitMask,
  1.3440 +             ddsd.ddpfPixelFormat.dwBBitMask);
  1.3441  #endif
  1.3442  }
  1.3443  #endif /* DDRAW_DEBUG */
  1.3444  
  1.3445 -static int DX5_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
  1.3446 -					SDL_Surface *dst, SDL_Rect *dstrect)
  1.3447 +static int
  1.3448 +DX5_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect,
  1.3449 +                 SDL_Surface * dst, SDL_Rect * dstrect)
  1.3450  {
  1.3451 -	LPDIRECTDRAWSURFACE3 src_surface;
  1.3452 -	LPDIRECTDRAWSURFACE3 dst_surface;
  1.3453 -	DWORD flags;
  1.3454 -	RECT rect;
  1.3455 -	HRESULT result;
  1.3456 +    LPDIRECTDRAWSURFACE3 src_surface;
  1.3457 +    LPDIRECTDRAWSURFACE3 dst_surface;
  1.3458 +    DWORD flags;
  1.3459 +    RECT rect;
  1.3460 +    HRESULT result;
  1.3461  
  1.3462 -	/* Set it up.. the desination must have a DDRAW surface */
  1.3463 -	src_surface = src->hwdata->dd_writebuf;
  1.3464 -	dst_surface = dst->hwdata->dd_writebuf;
  1.3465 -	rect.top    = (LONG)srcrect->y;
  1.3466 -	rect.bottom = (LONG)srcrect->y+srcrect->h;
  1.3467 -	rect.left   = (LONG)srcrect->x;
  1.3468 -	rect.right  = (LONG)srcrect->x+srcrect->w;
  1.3469 -	if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY )
  1.3470 -		flags = DDBLTFAST_SRCCOLORKEY;
  1.3471 -	else
  1.3472 -		flags = DDBLTFAST_NOCOLORKEY;
  1.3473 -	/* FIXME:  We can remove this flag for _really_ fast blit queuing,
  1.3474 -	           but it will affect the return values of locks and flips.
  1.3475 -	 */
  1.3476 -	flags |= DDBLTFAST_WAIT;
  1.3477 +    /* Set it up.. the desination must have a DDRAW surface */
  1.3478 +    src_surface = src->hwdata->dd_writebuf;
  1.3479 +    dst_surface = dst->hwdata->dd_writebuf;
  1.3480 +    rect.top = (LONG) srcrect->y;
  1.3481 +    rect.bottom = (LONG) srcrect->y + srcrect->h;
  1.3482 +    rect.left = (LONG) srcrect->x;
  1.3483 +    rect.right = (LONG) srcrect->x + srcrect->w;
  1.3484 +    if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
  1.3485 +        flags = DDBLTFAST_SRCCOLORKEY;
  1.3486 +    else
  1.3487 +        flags = DDBLTFAST_NOCOLORKEY;
  1.3488 +    /* FIXME:  We can remove this flag for _really_ fast blit queuing,
  1.3489 +       but it will affect the return values of locks and flips.
  1.3490 +     */
  1.3491 +    flags |= DDBLTFAST_WAIT;
  1.3492  
  1.3493 -	/* Do the blit! */
  1.3494 -	result = IDirectDrawSurface3_BltFast(dst_surface,
  1.3495 -			dstrect->x, dstrect->y, src_surface, &rect, flags);
  1.3496 -	if ( result != DD_OK ) {
  1.3497 -		if ( result == DDERR_SURFACELOST ) {
  1.3498 -			result = IDirectDrawSurface3_Restore(src_surface);
  1.3499 -			result = IDirectDrawSurface3_Restore(dst_surface);
  1.3500 -			/* The surfaces need to be reloaded with artwork */
  1.3501 -			SDL_SetError("Blit surfaces were lost, reload them");
  1.3502 -			return(-2);
  1.3503 -		}
  1.3504 -		SetDDerror("IDirectDrawSurface3::BltFast", result);
  1.3505 +    /* Do the blit! */
  1.3506 +    result = IDirectDrawSurface3_BltFast (dst_surface,
  1.3507 +                                          dstrect->x, dstrect->y, src_surface,
  1.3508 +                                          &rect, flags);
  1.3509 +    if (result != DD_OK) {
  1.3510 +        if (result == DDERR_SURFACELOST) {
  1.3511 +            result = IDirectDrawSurface3_Restore (src_surface);
  1.3512 +            result = IDirectDrawSurface3_Restore (dst_surface);
  1.3513 +            /* The surfaces need to be reloaded with artwork */
  1.3514 +            SDL_SetError ("Blit surfaces were lost, reload them");
  1.3515 +            return (-2);
  1.3516 +        }
  1.3517 +        SetDDerror ("IDirectDrawSurface3::BltFast", result);
  1.3518  #ifdef DDRAW_DEBUG
  1.3519 - fprintf(stderr, "Original dest rect: %dx%d at %d,%d\n", dstrect->w, dstrect->h, dstrect->x, dstrect->y);
  1.3520 - fprintf(stderr, "HW accelerated %sblit to from 0x%p to 0x%p at (%d,%d)\n",
  1.3521 -		(src->flags & SDL_SRCCOLORKEY) ? "colorkey " : "", src, dst,
  1.3522 -					dstrect->x, dstrect->y);
  1.3523 -  PrintSurface("SRC", src_surface, src->flags);
  1.3524 -  PrintSurface("DST", dst_surface, dst->flags);
  1.3525 - fprintf(stderr, "Source rectangle: (%d,%d) - (%d,%d)\n",
  1.3526 -		rect.left, rect.top, rect.right, rect.bottom);
  1.3527 +        fprintf (stderr, "Original dest rect: %dx%d at %d,%d\n", dstrect->w,
  1.3528 +                 dstrect->h, dstrect->x, dstrect->y);
  1.3529 +        fprintf (stderr,
  1.3530 +                 "HW accelerated %sblit to from 0x%p to 0x%p at (%d,%d)\n",
  1.3531 +                 (src->flags & SDL_SRCCOLORKEY) ? "colorkey " : "", src,
  1.3532 +                 dst, dstrect->x, dstrect->y);
  1.3533 +        PrintSurface ("SRC", src_surface, src->flags);
  1.3534 +        PrintSurface ("DST", dst_surface, dst->flags);
  1.3535 +        fprintf (stderr, "Source rectangle: (%d,%d) - (%d,%d)\n",
  1.3536 +                 rect.left, rect.top, rect.right, rect.bottom);
  1.3537  #endif
  1.3538 -		/* Unexpected error, fall back to software blit */
  1.3539 -		return(src->map->sw_blit(src, srcrect, dst, dstrect));
  1.3540 -	}
  1.3541 -	return(0);
  1.3542 +        /* Unexpected error, fall back to software blit */
  1.3543 +        return (src->map->sw_blit (src, srcrect, dst, dstrect));
  1.3544 +    }
  1.3545 +    return (0);
  1.3546  }
  1.3547  
  1.3548 -static int DX5_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
  1.3549 +static int
  1.3550 +DX5_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst)
  1.3551  {
  1.3552 -	int accelerated;
  1.3553 +    int accelerated;
  1.3554  
  1.3555 -	/* We need to have a DDraw surface for HW blits */
  1.3556 -	if ( (src->flags & SDL_HWSURFACE) == SDL_SWSURFACE ) {
  1.3557 -		/* Allocate a DDraw surface for the blit */
  1.3558 -		if ( src->hwdata == NULL ) {
  1.3559 -			DX5_AllocDDSurface(this, src, NULL, SDL_SWSURFACE);
  1.3560 -		}
  1.3561 -	}
  1.3562 -	if ( src->hwdata == NULL ) {
  1.3563 -		return(0);
  1.3564 -	}
  1.3565 +    /* We need to have a DDraw surface for HW blits */
  1.3566 +    if ((src->flags & SDL_HWSURFACE) == SDL_SWSURFACE) {
  1.3567 +        /* Allocate a DDraw surface for the blit */
  1.3568 +        if (src->hwdata == NULL) {
  1.3569 +            DX5_AllocDDSurface (this, src, NULL, SDL_SWSURFACE);
  1.3570 +        }
  1.3571 +    }
  1.3572 +    if (src->hwdata == NULL) {
  1.3573 +        return (0);
  1.3574 +    }
  1.3575  
  1.3576 -	/* Set initial acceleration on */
  1.3577 -	src->flags |= SDL_HWACCEL;
  1.3578 +    /* Set initial acceleration on */
  1.3579 +    src->flags |= SDL_HWACCEL;
  1.3580  
  1.3581 -	/* Set the surface attributes */
  1.3582 -	if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
  1.3583 -		if ( DX5_SetHWColorKey(this, src, src->format->colorkey) < 0 ) {
  1.3584 -			src->flags &= ~SDL_HWACCEL;
  1.3585 -		}
  1.3586 -	}
  1.3587 -	if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
  1.3588 -		if ( DX5_SetHWAlpha(this, src, src->format->alpha) < 0 ) {
  1.3589 -			src->flags &= ~SDL_HWACCEL;
  1.3590 -		}
  1.3591 -	}
  1.3592 +    /* Set the surface attributes */
  1.3593 +    if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  1.3594 +        if (DX5_SetHWColorKey (this, src, src->format->colorkey) < 0) {
  1.3595 +            src->flags &= ~SDL_HWACCEL;
  1.3596 +        }
  1.3597 +    }
  1.3598 +    if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
  1.3599 +        if (DX5_SetHWAlpha (this, src, src->format->alpha) < 0) {
  1.3600 +            src->flags &= ~SDL_HWACCEL;
  1.3601 +        }
  1.3602 +    }
  1.3603  
  1.3604 -	/* Check to see if final surface blit is accelerated */
  1.3605 -	accelerated = !!(src->flags & SDL_HWACCEL);
  1.3606 -	if ( accelerated ) {
  1.3607 +    /* Check to see if final surface blit is accelerated */
  1.3608 +    accelerated = !!(src->flags & SDL_HWACCEL);
  1.3609 +    if (accelerated) {
  1.3610  #ifdef DDRAW_DEBUG
  1.3611 -  fprintf(stderr, "Setting accelerated blit on 0x%p\n", src);
  1.3612 +        fprintf (stderr, "Setting accelerated blit on 0x%p\n", src);
  1.3613  #endif
  1.3614 -		src->map->hw_blit = DX5_HWAccelBlit;
  1.3615 -	}
  1.3616 -	return(accelerated);
  1.3617 +        src->map->hw_blit = DX5_HWAccelBlit;
  1.3618 +    }
  1.3619 +    return (accelerated);
  1.3620  }
  1.3621  
  1.3622 -static int DX5_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
  1.3623 +static int
  1.3624 +DX5_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
  1.3625  {
  1.3626 -	LPDIRECTDRAWSURFACE3 dst_surface;
  1.3627 -	RECT area;
  1.3628 -	DDBLTFX bltfx;
  1.3629 -	HRESULT result;
  1.3630 +    LPDIRECTDRAWSURFACE3 dst_surface;
  1.3631 +    RECT area;
  1.3632 +    DDBLTFX bltfx;
  1.3633 +    HRESULT result;
  1.3634  
  1.3635  #ifdef DDRAW_DEBUG
  1.3636 - fprintf(stderr, "HW accelerated fill at (%d,%d)\n", dstrect->x, dstrect->y);
  1.3637 +    fprintf (stderr, "HW accelerated fill at (%d,%d)\n", dstrect->x,
  1.3638 +             dstrect->y);
  1.3639  #endif
  1.3640 -	dst_surface = dst->hwdata->dd_writebuf;
  1.3641 -	area.top    = (LONG)dstrect->y;
  1.3642 -	area.bottom = (LONG)dstrect->y+dstrect->h;
  1.3643 -	area.left   = (LONG)dstrect->x;
  1.3644 -	area.right  = (LONG)dstrect->x+dstrect->w;
  1.3645 -	bltfx.dwSize = sizeof(bltfx);
  1.3646 +    dst_surface = dst->hwdata->dd_writebuf;
  1.3647 +    area.top = (LONG) dstrect->y;
  1.3648 +    area.bottom = (LONG) dstrect->y + dstrect->h;
  1.3649 +    area.left = (LONG) dstrect->x;
  1.3650 +    area.right = (LONG) dstrect->x + dstrect->w;
  1.3651 +    bltfx.dwSize = sizeof (bltfx);
  1.3652  #if defined(NONAMELESSUNION)
  1.3653 -	bltfx.u5.dwFillColor = color;
  1.3654 +    bltfx.u5.dwFillColor = color;
  1.3655  #else
  1.3656 -	bltfx.dwFillColor = color;
  1.3657 +    bltfx.dwFillColor = color;
  1.3658  #endif
  1.3659 -	result = IDirectDrawSurface3_Blt(dst_surface,
  1.3660 -			&area, NULL, NULL, DDBLT_COLORFILL|DDBLT_WAIT, &bltfx);
  1.3661 -	if ( result == DDERR_SURFACELOST ) {
  1.3662 -		IDirectDrawSurface3_Restore(dst_surface);
  1.3663 -		result = IDirectDrawSurface3_Blt(dst_surface,
  1.3664 -			&area, NULL, NULL, DDBLT_COLORFILL|DDBLT_WAIT, &bltfx);
  1.3665 -	}
  1.3666 -	if ( result != DD_OK ) {
  1.3667 -		SetDDerror("IDirectDrawSurface3::Blt", result);
  1.3668 -		return(-1);
  1.3669 -	}
  1.3670 -	return(0);
  1.3671 +    result = IDirectDrawSurface3_Blt (dst_surface,
  1.3672 +                                      &area, NULL, NULL,
  1.3673 +                                      DDBLT_COLORFILL | DDBLT_WAIT, &bltfx);
  1.3674 +    if (result == DDERR_SURFACELOST) {
  1.3675 +        IDirectDrawSurface3_Restore (dst_surface);
  1.3676 +        result = IDirectDrawSurface3_Blt (dst_surface,
  1.3677 +                                          &area, NULL, NULL,
  1.3678 +                                          DDBLT_COLORFILL | DDBLT_WAIT,
  1.3679 +                                          &bltfx);
  1.3680 +    }
  1.3681 +    if (result != DD_OK) {
  1.3682 +        SetDDerror ("IDirectDrawSurface3::Blt", result);
  1.3683 +        return (-1);
  1.3684 +    }
  1.3685 +    return (0);
  1.3686  }
  1.3687  
  1.3688 -static int DX5_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
  1.3689 +static int
  1.3690 +DX5_SetHWColorKey (_THIS, SDL_Surface * surface, Uint32 key)
  1.3691  {
  1.3692 -	DDCOLORKEY colorkey;
  1.3693 -	HRESULT result;
  1.3694 +    DDCOLORKEY colorkey;
  1.3695 +    HRESULT result;
  1.3696  
  1.3697 -	/* Set the surface colorkey */
  1.3698 -	colorkey.dwColorSpaceLowValue = key;
  1.3699 -	colorkey.dwColorSpaceHighValue = key;
  1.3700 -	result = IDirectDrawSurface3_SetColorKey(
  1.3701 -			surface->hwdata->dd_surface, DDCKEY_SRCBLT, &colorkey);
  1.3702 -	if ( result != DD_OK ) {
  1.3703 -		SetDDerror("IDirectDrawSurface3::SetColorKey", result);
  1.3704 -		return(-1);
  1.3705 -	}
  1.3706 -	return(0);
  1.3707 +    /* Set the surface colorkey */
  1.3708 +    colorkey.dwColorSpaceLowValue = key;
  1.3709 +    colorkey.dwColorSpaceHighValue = key;
  1.3710 +    result =
  1.3711 +        IDirectDrawSurface3_SetColorKey (surface->hwdata->dd_surface,
  1.3712 +                                         DDCKEY_SRCBLT, &colorkey);
  1.3713 +    if (result != DD_OK) {
  1.3714 +        SetDDerror ("IDirectDrawSurface3::SetColorKey", result);
  1.3715 +        return (-1);
  1.3716 +    }
  1.3717 +    return (0);
  1.3718  }
  1.3719 -static int DX5_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha)
  1.3720 +static int
  1.3721 +DX5_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha)
  1.3722  {
  1.3723 -	return(-1);
  1.3724 +    return (-1);
  1.3725  }
  1.3726  
  1.3727 -static int DX5_LockHWSurface(_THIS, SDL_Surface *surface)
  1.3728 +static int
  1.3729 +DX5_LockHWSurface (_THIS, SDL_Surface * surface)
  1.3730  {
  1.3731 -	HRESULT result;
  1.3732 -	LPDIRECTDRAWSURFACE3 dd_surface;
  1.3733 -	DDSURFACEDESC ddsd;
  1.3734 +    HRESULT result;
  1.3735 +    LPDIRECTDRAWSURFACE3 dd_surface;
  1.3736 +    DDSURFACEDESC ddsd;
  1.3737  
  1.3738 -	/* Lock and load! */
  1.3739 -	dd_surface = surface->hwdata->dd_writebuf;
  1.3740 -	SDL_memset(&ddsd, 0, sizeof(ddsd));
  1.3741 -	ddsd.dwSize = sizeof(ddsd);
  1.3742 -	result = IDirectDrawSurface3_Lock(dd_surface, NULL, &ddsd,
  1.3743 -					(DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
  1.3744 -	if ( result == DDERR_SURFACELOST ) {
  1.3745 -		result = IDirectDrawSurface3_Restore(
  1.3746 -						surface->hwdata->dd_surface);
  1.3747 -		result = IDirectDrawSurface3_Lock(dd_surface, NULL, &ddsd, 
  1.3748 -					(DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
  1.3749 -	}
  1.3750 -	if ( result != DD_OK ) {
  1.3751 -		SetDDerror("DirectDrawSurface3::Lock", result);
  1.3752 -		return(-1);
  1.3753 -	}
  1.3754 -	/* Pitch might have changed -- recalculate pitch and offset */
  1.3755 +    /* Lock and load! */
  1.3756 +    dd_surface = surface->hwdata->dd_writebuf;
  1.3757 +    SDL_memset (&ddsd, 0, sizeof (ddsd));
  1.3758 +    ddsd.dwSize = sizeof (ddsd);
  1.3759 +    result = IDirectDrawSurface3_Lock (dd_surface, NULL, &ddsd,
  1.3760 +                                       (DDLOCK_NOSYSLOCK | DDLOCK_WAIT),
  1.3761 +                                       NULL);
  1.3762 +    if (result == DDERR_SURFACELOST) {
  1.3763 +        result = IDirectDrawSurface3_Restore (surface->hwdata->dd_surface);
  1.3764 +        result = IDirectDrawSurface3_Lock (dd_surface, NULL, &ddsd,
  1.3765 +                                           (DDLOCK_NOSYSLOCK | DDLOCK_WAIT),
  1.3766 +                                           NULL);
  1.3767 +    }
  1.3768 +    if (result != DD_OK) {
  1.3769 +        SetDDerror ("DirectDrawSurface3::Lock", result);
  1.3770 +        return (-1);
  1.3771 +    }
  1.3772 +    /* Pitch might have changed -- recalculate pitch and offset */
  1.3773  #if defined(NONAMELESSUNION)
  1.3774 -	if ( surface->pitch != ddsd.u1.lPitch ) {
  1.3775 -		surface->pitch = ddsd.u1.lPitch;
  1.3776 +    if (surface->pitch != ddsd.u1.lPitch) {
  1.3777 +        surface->pitch = ddsd.u1.lPitch;
  1.3778  #else
  1.3779 -	if ( surface->pitch != ddsd.lPitch ) {
  1.3780 -		surface->pitch = (Uint16)ddsd.lPitch;
  1.3781 +    if (surface->pitch != ddsd.lPitch) {
  1.3782 +        surface->pitch = (Uint16) ddsd.lPitch;
  1.3783  #endif
  1.3784 -		surface->offset =
  1.3785 -			((ddsd.dwHeight-surface->h)/2)*surface->pitch +
  1.3786 -			((ddsd.dwWidth-surface->w)/2)*
  1.3787 -					surface->format->BytesPerPixel;
  1.3788 -	}
  1.3789 -	surface->pixels = ddsd.lpSurface;
  1.3790 -	return(0);
  1.3791 -}
  1.3792 -
  1.3793 -static void DX5_UnlockHWSurface(_THIS, SDL_Surface *surface)
  1.3794 -{
  1.3795 -	IDirectDrawSurface3_Unlock(surface->hwdata->dd_writebuf, NULL);
  1.3796 -	surface->pixels = NULL;
  1.3797 +        surface->offset =
  1.3798 +            ((ddsd.dwHeight - surface->h) / 2) * surface->pitch +
  1.3799 +            ((ddsd.dwWidth - surface->w) / 2) *
  1.3800 +            surface->format->BytesPerPixel;
  1.3801 +    }
  1.3802 +    surface->pixels = ddsd.lpSurface;
  1.3803 +    return (0);
  1.3804  }
  1.3805  
  1.3806 -static int DX5_FlipHWSurface(_THIS, SDL_Surface *surface)
  1.3807 +static void
  1.3808 +DX5_UnlockHWSurface (_THIS, SDL_Surface * surface)
  1.3809  {
  1.3810 -	HRESULT result;
  1.3811 -	LPDIRECTDRAWSURFACE3 dd_surface;
  1.3812 +    IDirectDrawSurface3_Unlock (surface->hwdata->dd_writebuf, NULL);
  1.3813 +    surface->pixels = NULL;
  1.3814 +}
  1.3815  
  1.3816 -	dd_surface = surface->hwdata->dd_surface;
  1.3817 +static int
  1.3818 +DX5_FlipHWSurface (_THIS, SDL_Surface * surface)
  1.3819 +{
  1.3820 +    HRESULT result;
  1.3821 +    LPDIRECTDRAWSURFACE3 dd_surface;
  1.3822  
  1.3823 -	/* to prevent big slowdown on fast computers, wait here instead of driver ring 0 code */
  1.3824 -	/* Dmitry Yakimov (ftech@tula.net) */
  1.3825 -	while(IDirectDrawSurface3_GetFlipStatus(dd_surface, DDGBS_ISBLTDONE) == DDERR_WASSTILLDRAWING);
  1.3826 +    dd_surface = surface->hwdata->dd_surface;
  1.3827  
  1.3828 -	result = IDirectDrawSurface3_Flip(dd_surface, NULL, DDFLIP_WAIT);
  1.3829 -	if ( result == DDERR_SURFACELOST ) {
  1.3830 -		result = IDirectDrawSurface3_Restore(
  1.3831 -						surface->hwdata->dd_surface);
  1.3832 -		while(IDirectDrawSurface3_GetFlipStatus(dd_surface, DDGBS_ISBLTDONE) == DDERR_WASSTILLDRAWING);
  1.3833 -		result = IDirectDrawSurface3_Flip(dd_surface, NULL, DDFLIP_WAIT);
  1.3834 -	}
  1.3835 -	if ( result != DD_OK ) {
  1.3836 -		SetDDerror("DirectDrawSurface3::Flip", result);
  1.3837 -		return(-1);
  1.3838 -	}
  1.3839 -	return(0);
  1.3840 +    /* to prevent big slowdown on fast computers, wait here instead of driver ring 0 code */
  1.3841 +    /* Dmitry Yakimov (ftech@tula.net) */
  1.3842 +    while (IDirectDrawSurface3_GetFlipStatus (dd_surface, DDGBS_ISBLTDONE) ==
  1.3843 +           DDERR_WASSTILLDRAWING);
  1.3844 +
  1.3845 +    result = IDirectDrawSurface3_Flip (dd_surface, NULL, DDFLIP_WAIT);
  1.3846 +    if (result == DDERR_SURFACELOST) {
  1.3847 +        result = IDirectDrawSurface3_Restore (surface->hwdata->dd_surface);
  1.3848 +        while (IDirectDrawSurface3_GetFlipStatus
  1.3849 +               (dd_surface, DDGBS_ISBLTDONE) == DDERR_WASSTILLDRAWING);
  1.3850 +        result = IDirectDrawSurface3_Flip (dd_surface, NULL, DDFLIP_WAIT);
  1.3851 +    }
  1.3852 +    if (result != DD_OK) {
  1.3853 +        SetDDerror ("DirectDrawSurface3::Flip", result);
  1.3854 +        return (-1);
  1.3855 +    }
  1.3856 +    return (0);
  1.3857  }
  1.3858  
  1.3859 -static void DX5_FreeHWSurface(_THIS, SDL_Surface *surface)
  1.3860 +static void
  1.3861 +DX5_FreeHWSurface (_THIS, SDL_Surface * surface)
  1.3862  {
  1.3863 -	if ( surface->hwdata ) {
  1.3864 -		if ( surface->hwdata->dd_surface != SDL_primary ) {
  1.3865 -			IDirectDrawSurface3_Release(surface->hwdata->dd_surface);
  1.3866 -		}
  1.3867 -		SDL_free(surface->hwdata);
  1.3868 -		surface->hwdata = NULL;
  1.3869 -	}
  1.3870 +    if (surface->hwdata) {
  1.3871 +        if (surface->hwdata->dd_surface != SDL_primary) {
  1.3872 +            IDirectDrawSurface3_Release (surface->hwdata->dd_surface);
  1.3873 +        }
  1.3874 +        SDL_free (surface->hwdata);
  1.3875 +        surface->hwdata = NULL;
  1.3876 +    }
  1.3877  }
  1.3878  
  1.3879 -void DX5_WindowUpdate(_THIS, int numrects, SDL_Rect *rects)
  1.3880 +void
  1.3881 +DX5_WindowUpdate (_THIS, int numrects, SDL_Rect * rects)
  1.3882  {
  1.3883 -	HRESULT result;
  1.3884 -	int i;
  1.3885 -	RECT src, dst;
  1.3886 +    HRESULT result;
  1.3887 +    int i;
  1.3888 +    RECT src, dst;
  1.3889  
  1.3890 -	for ( i=0; i<numrects; ++i ) {
  1.3891 -		src.top    = (LONG)rects[i].y;
  1.3892 -		src.bottom = (LONG)rects[i].y+rects[i].h;
  1.3893 -		src.left   = (LONG)rects[i].x;
  1.3894 -		src.right  = (LONG)rects[i].x+rects[i].w;
  1.3895 -		dst.top    = SDL_bounds.top+src.top;
  1.3896 -		dst.left   = SDL_bounds.left+src.left;
  1.3897 -		dst.bottom = SDL_bounds.top+src.bottom;
  1.3898 -		dst.right  = SDL_bounds.left+src.right;
  1.3899 -		result = IDirectDrawSurface3_Blt(SDL_primary, &dst, 
  1.3900 -					this->screen->hwdata->dd_surface, &src,
  1.3901 -							DDBLT_WAIT, NULL);
  1.3902 -		/* Doh!  Check for lost surface and restore it */
  1.3903 -		if ( result == DDERR_SURFACELOST ) {
  1.3904 -			IDirectDrawSurface3_Restore(SDL_primary);
  1.3905 -			IDirectDrawSurface3_Blt(SDL_primary, &dst, 
  1.3906 -					this->screen->hwdata->dd_surface, &src,
  1.3907 -							DDBLT_WAIT, NULL);
  1.3908 -		}
  1.3909 -	}
  1.3910 +    for (i = 0; i < numrects; ++i) {
  1.3911 +        src.top = (LONG) rects[i].y;
  1.3912 +        src.bottom = (LONG) rects[i].y + rects[i].h;
  1.3913 +        src.left = (LONG) rects[i].x;
  1.3914 +        src.right = (LONG) rects[i].x + rects[i].w;
  1.3915 +        dst.top = SDL_bounds.top + src.top;
  1.3916 +        dst.left = SDL_bounds.left + src.left;
  1.3917 +        dst.bottom = SDL_bounds.top + src.bottom;
  1.3918 +        dst.right = SDL_bounds.left + src.right;
  1.3919 +        result = IDirectDrawSurface3_Blt (SDL_primary, &dst,
  1.3920 +                                          this->screen->hwdata->dd_surface,
  1.3921 +                                          &src, DDBLT_WAIT, NULL);
  1.3922 +        /* Doh!  Check for lost surface and restore it */
  1.3923 +        if (result == DDERR_SURFACELOST) {
  1.3924 +            IDirectDrawSurface3_Restore (SDL_primary);
  1.3925 +            IDirectDrawSurface3_Blt (SDL_primary, &dst,
  1.3926 +                                     this->screen->hwdata->dd_surface,
  1.3927 +                                     &src, DDBLT_WAIT, NULL);
  1.3928 +        }
  1.3929 +    }
  1.3930  }
  1.3931  
  1.3932 -void DX5_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
  1.3933 +void
  1.3934 +DX5_DirectUpdate (_THIS, int numrects, SDL_Rect * rects)
  1.3935  {
  1.3936  }
  1.3937  
  1.3938 @@ -2161,345 +2233,356 @@
  1.3939  	int b = (A.b - B.b);						\
  1.3940  	(r*r + g*g + b*b);						\
  1.3941  })
  1.3942 -static void DX5_CompressPalette(_THIS, SDL_Color *colors, int ncolors, int maxcolors)
  1.3943 +static void
  1.3944 +DX5_CompressPalette (_THIS, SDL_Color * colors, int ncolors, int maxcolors)
  1.3945  {
  1.3946  #ifdef SIMPLE_COMPRESSION
  1.3947 -	int i, j;
  1.3948 +    int i, j;
  1.3949  #else
  1.3950 -	static SDL_Color zero = { 0, 0, 0, 0 };
  1.3951 -	int i, j;
  1.3952 -	int max, dist;
  1.3953 -	int prev, next;
  1.3954 -	int *pool;
  1.3955 -	int *seen, *order;
  1.3956 +    static SDL_Color zero = { 0, 0, 0, 0 };
  1.3957 +    int i, j;
  1.3958 +    int max, dist;
  1.3959 +    int prev, next;
  1.3960 +    int *pool;
  1.3961 +    int *seen, *order;
  1.3962  #endif
  1.3963  
  1.3964 -	/* Does this happen? */
  1.3965 -	if ( maxcolors > ncolors ) {
  1.3966 -		maxcolors = ncolors;
  1.3967 -	}
  1.3968 -
  1.3969 +    /* Does this happen? */
  1.3970 +    if (maxcolors > ncolors) {
  1.3971 +        maxcolors = ncolors;
  1.3972 +    }
  1.3973  #ifdef SIMPLE_COMPRESSION
  1.3974 -	/* Just copy the first "maxcolors" colors */
  1.3975 -	for ( j=10, i=0; i<maxcolors; ++i, ++j ) {
  1.3976 -		SDL_colors[j].peRed = colors[i].r;
  1.3977 -		SDL_colors[j].peGreen = colors[i].g;
  1.3978 -		SDL_colors[j].peBlue = colors[i].b;
  1.3979 -	}
  1.3980 +    /* Just copy the first "maxcolors" colors */
  1.3981 +    for (j = 10, i = 0; i < maxcolors; ++i, ++j) {
  1.3982 +        SDL_colors[j].peRed = colors[i].r;
  1.3983 +        SDL_colors[j].peGreen = colors[i].g;
  1.3984 +        SDL_colors[j].peBlue = colors[i].b;
  1.3985 +    }
  1.3986  #else
  1.3987 -	/* Allocate memory for the arrays we use */
  1.3988 -	pool = SDL_stack_alloc(int, 2*ncolors);
  1.3989 -	if ( pool == NULL ) {
  1.3990 -		/* No worries, just return */;
  1.3991 -		return;
  1.3992 -	}
  1.3993 -	seen = pool;
  1.3994 -	SDL_memset(seen, 0, ncolors*sizeof(int));
  1.3995 -	order = pool+ncolors;
  1.3996 +    /* Allocate memory for the arrays we use */
  1.3997 +    pool = SDL_stack_alloc (int, 2 * ncolors);
  1.3998 +    if (pool == NULL) {
  1.3999 +        /* No worries, just return */ ;
  1.4000 +        return;
  1.4001 +    }
  1.4002 +    seen = pool;
  1.4003 +    SDL_memset (seen, 0, ncolors * sizeof (int));
  1.4004 +    order = pool + ncolors;
  1.4005  
  1.4006 -	/* Start with the brightest color */
  1.4007 -	max = 0;
  1.4008 -	for ( i=0; i<ncolors; ++i ) {
  1.4009 -		dist = CS_CS_DIST(zero, colors[i]);
  1.4010 -		if ( dist >= max ) {
  1.4011 -			max = dist;
  1.4012 -			next = i;
  1.4013 -		}
  1.4014 -	}
  1.4015 -	j = 0;
  1.4016 -	order[j++] = next;
  1.4017 -	seen[next] = 1;
  1.4018 -	prev = next;
  1.4019 +    /* Start with the brightest color */
  1.4020 +    max = 0;
  1.4021 +    for (i = 0; i < ncolors; ++i) {
  1.4022 +        dist = CS_CS_DIST (zero, colors[i]);
  1.4023 +        if (dist >= max) {
  1.4024 +            max = dist;
  1.4025 +            next = i;
  1.4026 +        }
  1.4027 +    }
  1.4028 +    j = 0;
  1.4029 +    order[j++] = next;
  1.4030 +    seen[next] = 1;
  1.4031 +    prev = next;
  1.4032  
  1.4033 -	/* Keep going through all the colors */
  1.4034 -	while ( j < maxcolors ) {
  1.4035 -		max = 0;
  1.4036 -		for ( i=0; i<ncolors; ++i ) {
  1.4037 -			if ( seen[i] ) {
  1.4038 -				continue;
  1.4039 -			}
  1.4040 -			dist = CS_CS_DIST(colors[i], colors[prev]);
  1.4041 -			if ( dist >= max ) {
  1.4042 -				max = dist;
  1.4043 -				next = i;
  1.4044 -			}
  1.4045 -		}
  1.4046 -		order[j++] = next;
  1.4047 -		seen[next] = 1;
  1.4048 -		prev = next;
  1.4049 -	}
  1.4050 +    /* Keep going through all the colors */
  1.4051 +    while (j < maxcolors) {
  1.4052 +        max = 0;
  1.4053 +        for (i = 0; i < ncolors; ++i) {
  1.4054 +            if (seen[i]) {
  1.4055 +                continue;
  1.4056 +            }
  1.4057 +            dist = CS_CS_DIST (colors[i], colors[prev]);
  1.4058 +            if (dist >= max) {
  1.4059 +                max = dist;
  1.4060 +                next = i;
  1.4061 +            }
  1.4062 +        }
  1.4063 +        order[j++] = next;
  1.4064 +        seen[next] = 1;
  1.4065 +        prev = next;
  1.4066 +    }
  1.4067  
  1.4068 -	/* Compress the colors to the palette */
  1.4069 -	for ( j=10, i=0; i<maxcolors; ++i, ++j ) {
  1.4070 -		SDL_colors[j].peRed = colors[order[i]].r;
  1.4071 -		SDL_colors[j].peGreen = colors[order[i]].g;
  1.4072 -		SDL_colors[j].peBlue = colors[order[i]].b;
  1.4073 -	}
  1.4074 -	SDL_stack_free(pool);
  1.4075 +    /* Compress the colors to the palette */
  1.4076 +    for (j = 10, i = 0; i < maxcolors; ++i, ++j) {
  1.4077 +        SDL_colors[j].peRed = colors[order[i]].r;
  1.4078 +        SDL_colors[j].peGreen = colors[order[i]].g;
  1.4079 +        SDL_colors[j].peBlue = colors[order[i]].b;
  1.4080 +    }
  1.4081 +    SDL_stack_free (pool);
  1.4082  #endif /* SIMPLE_COMPRESSION */
  1.4083  }
  1.4084  
  1.4085  /* Set the system colormap in both fullscreen and windowed modes */
  1.4086 -int DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  1.4087 +int
  1.4088 +DX5_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
  1.4089  {
  1.4090 -	int i;
  1.4091 -	int alloct_all;
  1.4092 +    int i;
  1.4093 +    int alloct_all;
  1.4094  
  1.4095 -	/* Copy palette colors into display palette */
  1.4096 -	alloct_all = 0;
  1.4097 -	if ( SDL_palette != NULL ) {
  1.4098 -		if ( (this->screen->flags&SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.4099 -			/* We can set all entries explicitly */
  1.4100 -			for ( i=0; i< ncolors; ++i ) {
  1.4101 -			        int j = firstcolor + i;
  1.4102 -				SDL_colors[j].peRed = colors[i].r;
  1.4103 -				SDL_colors[j].peGreen = colors[i].g;
  1.4104 -				SDL_colors[j].peBlue = colors[i].b;
  1.4105 -			}
  1.4106 -			IDirectDrawPalette_SetEntries(SDL_palette, 0,
  1.4107 -				firstcolor, ncolors, &SDL_colors[firstcolor]);
  1.4108 -			alloct_all = 1;
  1.4109 -		} else {
  1.4110 -			/* Grab the 236 most diverse colors in the palette */
  1.4111 -			DX5_CompressPalette(this, colors, ncolors, 236);
  1.4112 -			/* This sends an WM_PALETTECHANGED message to us */
  1.4113 -			colorchange_expected = 1;
  1.4114 -			IDirectDrawPalette_SetEntries(SDL_palette, 0,
  1.4115 -							0, 256, SDL_colors);
  1.4116 -		}
  1.4117 -	}
  1.4118 -	return(alloct_all);
  1.4119 +    /* Copy palette colors into display palette */
  1.4120 +    alloct_all = 0;
  1.4121 +    if (SDL_palette != NULL) {
  1.4122 +        if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.4123 +            /* We can set all entries explicitly */
  1.4124 +            for (i = 0; i < ncolors; ++i) {
  1.4125 +                int j = firstcolor + i;
  1.4126 +                SDL_colors[j].peRed = colors[i].r;
  1.4127 +                SDL_colors[j].peGreen = colors[i].g;
  1.4128 +                SDL_colors[j].peBlue = colors[i].b;
  1.4129 +            }
  1.4130 +            IDirectDrawPalette_SetEntries (SDL_palette, 0,
  1.4131 +                                           firstcolor, ncolors,
  1.4132 +                                           &SDL_colors[firstcolor]);
  1.4133 +            alloct_all = 1;
  1.4134 +        } else {
  1.4135 +            /* Grab the 236 most diverse colors in the palette */
  1.4136 +            DX5_CompressPalette (this, colors, ncolors, 236);
  1.4137 +            /* This sends an WM_PALETTECHANGED message to us */
  1.4138 +            colorchange_expected = 1;
  1.4139 +            IDirectDrawPalette_SetEntries (SDL_palette, 0,
  1.4140 +                                           0, 256, SDL_colors);
  1.4141 +        }
  1.4142 +    }
  1.4143 +    return (alloct_all);
  1.4144  }
  1.4145  
  1.4146  /* Gamma code is only available on DirectX 7 and newer */
  1.4147 -static int DX5_SetGammaRamp(_THIS, Uint16 *ramp)
  1.4148 +static int
  1.4149 +DX5_SetGammaRamp (_THIS, Uint16 * ramp)
  1.4150  {
  1.4151  #ifdef IDirectDrawGammaControl_SetGammaRamp
  1.4152 -	LPDIRECTDRAWGAMMACONTROL gamma;
  1.4153 -	DDGAMMARAMP gamma_ramp;
  1.4154 -	HRESULT result;
  1.4155 +    LPDIRECTDRAWGAMMACONTROL gamma;
  1.4156 +    DDGAMMARAMP gamma_ramp;
  1.4157 +    HRESULT result;
  1.4158  #endif
  1.4159  
  1.4160 -	/* In windowed or OpenGL mode, use windib gamma code */
  1.4161 -	if ( ! DDRAW_FULLSCREEN() ) {
  1.4162 -		return DIB_SetGammaRamp(this, ramp);
  1.4163 -	}
  1.4164 -
  1.4165 +    /* In windowed or OpenGL mode, use windib gamma code */
  1.4166 +    if (!DDRAW_FULLSCREEN ()) {
  1.4167 +        return DIB_SetGammaRamp (this, ramp);
  1.4168 +    }
  1.4169  #ifndef IDirectDrawGammaControl_SetGammaRamp
  1.4170 -	SDL_SetError("SDL compiled without DirectX gamma ramp support");
  1.4171 -	return -1;
  1.4172 +    SDL_SetError ("SDL compiled without DirectX gamma ramp support");
  1.4173 +    return -1;
  1.4174  #else
  1.4175 -	/* Check for a video mode! */
  1.4176 -	if ( ! SDL_primary ) {
  1.4177 -		SDL_SetError("A video mode must be set for gamma correction");
  1.4178 -		return(-1);
  1.4179 -	}
  1.4180 +    /* Check for a video mode! */
  1.4181 +    if (!SDL_primary) {
  1.4182 +        SDL_SetError ("A video mode must be set for gamma correction");
  1.4183 +        return (-1);
  1.4184 +    }
  1.4185  
  1.4186 -	/* Get the gamma control object */
  1.4187 -	result = IDirectDrawSurface3_QueryInterface(SDL_primary,
  1.4188 -			&IID_IDirectDrawGammaControl, (LPVOID *)&gamma);
  1.4189 -	if ( result != DD_OK ) {
  1.4190 -		SetDDerror("DirectDrawSurface3::QueryInterface(GAMMA)", result);
  1.4191 -		return(-1);
  1.4192 -	}
  1.4193 +    /* Get the gamma control object */
  1.4194 +    result = IDirectDrawSurface3_QueryInterface (SDL_primary,
  1.4195 +                                                 &IID_IDirectDrawGammaControl,
  1.4196 +                                                 (LPVOID *) & gamma);
  1.4197 +    if (result != DD_OK) {
  1.4198 +        SetDDerror ("DirectDrawSurface3::QueryInterface(GAMMA)", result);
  1.4199 +        return (-1);
  1.4200 +    }
  1.4201  
  1.4202 -	/* Set up the gamma ramp */
  1.4203 -	SDL_memcpy(gamma_ramp.red, &ramp[0*256], 256*sizeof(*ramp));
  1.4204 -	SDL_memcpy(gamma_ramp.green, &ramp[1*256], 256*sizeof(*ramp));
  1.4205 -	SDL_memcpy(gamma_ramp.blue, &ramp[2*256], 256*sizeof(*ramp));
  1.4206 -	result = IDirectDrawGammaControl_SetGammaRamp(gamma, 0, &gamma_ramp);
  1.4207 -	if ( result != DD_OK ) {
  1.4208 -		SetDDerror("DirectDrawGammaControl::SetGammaRamp()", result);
  1.4209 -	}
  1.4210 +    /* Set up the gamma ramp */
  1.4211 +    SDL_memcpy (gamma_ramp.red, &ramp[0 * 256], 256 * sizeof (*ramp));
  1.4212 +    SDL_memcpy (gamma_ramp.green, &ramp[1 * 256], 256 * sizeof (*ramp));
  1.4213 +    SDL_memcpy (gamma_ramp.blue, &ramp[2 * 256], 256 * sizeof (*ramp));
  1.4214 +    result = IDirectDrawGammaControl_SetGammaRamp (gamma, 0, &gamma_ramp);
  1.4215 +    if (result != DD_OK) {
  1.4216 +        SetDDerror ("DirectDrawGammaControl::SetGammaRamp()", result);
  1.4217 +    }
  1.4218  
  1.4219 -	/* Release the interface and return */
  1.4220 -	IDirectDrawGammaControl_Release(gamma);
  1.4221 -	return (result == DD_OK) ? 0 : -1;
  1.4222 +    /* Release the interface and return */
  1.4223 +    IDirectDrawGammaControl_Release (gamma);
  1.4224 +    return (result == DD_OK) ? 0 : -1;
  1.4225  #endif /* !IDirectDrawGammaControl_SetGammaRamp */
  1.4226  }
  1.4227  
  1.4228 -static int DX5_GetGammaRamp(_THIS, Uint16 *ramp)
  1.4229 +static int
  1.4230 +DX5_GetGammaRamp (_THIS, Uint16 * ramp)
  1.4231  {
  1.4232  #ifdef IDirectDrawGammaControl_SetGammaRamp
  1.4233 -	LPDIRECTDRAWGAMMACONTROL gamma;
  1.4234 -	DDGAMMARAMP gamma_ramp;
  1.4235 -	HRESULT result;
  1.4236 +    LPDIRECTDRAWGAMMACONTROL gamma;
  1.4237 +    DDGAMMARAMP gamma_ramp;
  1.4238 +    HRESULT result;
  1.4239  #endif
  1.4240  
  1.4241 -	/* In windowed or OpenGL mode, use windib gamma code */
  1.4242 -	if ( ! DDRAW_FULLSCREEN() ) {
  1.4243 -		return DIB_GetGammaRamp(this, ramp);
  1.4244 -	}
  1.4245 -
  1.4246 +    /* In windowed or OpenGL mode, use windib gamma code */
  1.4247 +    if (!DDRAW_FULLSCREEN ()) {
  1.4248 +        return DIB_GetGammaRamp (this, ramp);
  1.4249 +    }
  1.4250  #ifndef IDirectDrawGammaControl_SetGammaRamp
  1.4251 -	SDL_SetError("SDL compiled without DirectX gamma ramp support");
  1.4252 -	return -1;
  1.4253 +    SDL_SetError ("SDL compiled without DirectX gamma ramp support");
  1.4254 +    return -1;
  1.4255  #else
  1.4256 -	/* Check for a video mode! */
  1.4257 -	if ( ! SDL_primary ) {
  1.4258 -		SDL_SetError("A video mode must be set for gamma correction");
  1.4259 -		return(-1);
  1.4260 -	}
  1.4261 +    /* Check for a video mode! */
  1.4262 +    if (!SDL_primary) {
  1.4263 +        SDL_SetError ("A video mode must be set for gamma correction");
  1.4264 +        return (-1);
  1.4265 +    }
  1.4266  
  1.4267 -	/* Get the gamma control object */
  1.4268 -	result = IDirectDrawSurface3_QueryInterface(SDL_primary,
  1.4269 -			&IID_IDirectDrawGammaControl, (LPVOID *)&gamma);
  1.4270 -	if ( result != DD_OK ) {
  1.4271 -		SetDDerror("DirectDrawSurface3::QueryInterface(GAMMA)", result);
  1.4272 -		return(-1);
  1.4273 -	}
  1.4274 +    /* Get the gamma control object */
  1.4275 +    result = IDirectDrawSurface3_QueryInterface (SDL_primary,
  1.4276 +                                                 &IID_IDirectDrawGammaControl,
  1.4277 +                                                 (LPVOID *) & gamma);
  1.4278 +    if (result != DD_OK) {
  1.4279 +        SetDDerror ("DirectDrawSurface3::QueryInterface(GAMMA)", result);
  1.4280 +        return (-1);
  1.4281 +    }
  1.4282  
  1.4283 -	/* Set up the gamma ramp */
  1.4284 -	result = IDirectDrawGammaControl_GetGammaRamp(gamma, 0, &gamma_ramp);
  1.4285 -	if ( result == DD_OK ) {
  1.4286 -		SDL_memcpy(&ramp[0*256], gamma_ramp.red, 256*sizeof(*ramp));
  1.4287 -		SDL_memcpy(&ramp[1*256], gamma_ramp.green, 256*sizeof(*ramp));
  1.4288 -		SDL_memcpy(&ramp[2*256], gamma_ramp.blue, 256*sizeof(*ramp));
  1.4289 -	} else {
  1.4290 -		SetDDerror("DirectDrawGammaControl::GetGammaRamp()", result);
  1.4291 -	}
  1.4292 +    /* Set up the gamma ramp */
  1.4293 +    result = IDirectDrawGammaControl_GetGammaRamp (gamma, 0, &gamma_ramp);
  1.4294 +    if (result == DD_OK) {
  1.4295 +        SDL_memcpy (&ramp[0 * 256], gamma_ramp.red, 256 * sizeof (*ramp));
  1.4296 +        SDL_memcpy (&ramp[1 * 256], gamma_ramp.green, 256 * sizeof (*ramp));
  1.4297 +        SDL_memcpy (&ramp[2 * 256], gamma_ramp.blue, 256 * sizeof (*ramp));
  1.4298 +    } else {
  1.4299 +        SetDDerror ("DirectDrawGammaControl::GetGammaRamp()", result);
  1.4300 +    }
  1.4301  
  1.4302 -	/* Release the interface and return */
  1.4303 -	IDirectDrawGammaControl_Release(gamma);
  1.4304 -	return (result == DD_OK) ? 0 : -1;
  1.4305 +    /* Release the interface and return */
  1.4306 +    IDirectDrawGammaControl_Release (gamma);
  1.4307 +    return (result == DD_OK) ? 0 : -1;
  1.4308  #endif /* !IDirectDrawGammaControl_SetGammaRamp */
  1.4309  }
  1.4310  
  1.4311 -void DX5_VideoQuit(_THIS)
  1.4312 +void
  1.4313 +DX5_VideoQuit (_THIS)
  1.4314  {
  1.4315 -	int i, j;
  1.4316 +    int i, j;
  1.4317  
  1.4318 -	/* If we're fullscreen GL, we need to reset the display */
  1.4319 -	if ( this->screen != NULL ) {
  1.4320 +    /* If we're fullscreen GL, we need to reset the display */
  1.4321 +    if (this->screen != NULL) {
  1.4322  #ifndef NO_CHANGEDISPLAYSETTINGS
  1.4323 -		if ( (this->screen->flags & (SDL_INTERNALOPENGL|SDL_FULLSCREEN)) ==
  1.4324 -		                            (SDL_INTERNALOPENGL|SDL_FULLSCREEN) ) {
  1.4325 -			ChangeDisplaySettings(NULL, 0);
  1.4326 -			ShowWindow(SDL_Window, SW_HIDE);
  1.4327 -		}
  1.4328 +        if ((this->screen->flags & (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) ==
  1.4329 +            (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) {
  1.4330 +            ChangeDisplaySettings (NULL, 0);
  1.4331 +            ShowWindow (SDL_Window, SW_HIDE);
  1.4332 +        }
  1.4333  #endif
  1.4334 -		if ( this->screen->flags & SDL_INTERNALOPENGL ) {
  1.4335 -			WIN_GL_ShutDown(this);
  1.4336 -		}
  1.4337 -	}
  1.4338 +        if (this->screen->flags & SDL_INTERNALOPENGL) {
  1.4339 +            WIN_GL_ShutDown (this);
  1.4340 +        }
  1.4341 +    }
  1.4342  
  1.4343 -	/* Free any palettes we used */
  1.4344 -	if ( SDL_palette != NULL ) {
  1.4345 -		IDirectDrawPalette_Release(SDL_palette);
  1.4346 -		SDL_palette = NULL;
  1.4347 -	}
  1.4348 +    /* Free any palettes we used */
  1.4349 +    if (SDL_palette != NULL) {
  1.4350 +        IDirectDrawPalette_Release (SDL_palette);
  1.4351 +        SDL_palette = NULL;
  1.4352 +    }
  1.4353  
  1.4354 -	/* Allow the primary surface to be freed */
  1.4355 -	if ( SDL_primary != NULL ) {
  1.4356 -		SDL_primary = NULL;
  1.4357 -	}
  1.4358 +    /* Allow the primary surface to be freed */
  1.4359 +    if (SDL_primary != NULL) {
  1.4360 +        SDL_primary = NULL;
  1.4361 +    }
  1.4362  
  1.4363 -	/* Free video mode lists */
  1.4364 -	for ( i=0; i<NUM_MODELISTS; ++i ) {
  1.4365 -		if ( SDL_modelist[i] != NULL ) {
  1.4366 -			for ( j=0; SDL_modelist[i][j]; ++j )
  1.4367 -				SDL_free(SDL_modelist[i][j]);
  1.4368 -			SDL_free(SDL_modelist[i]);
  1.4369 -			SDL_modelist[i] = NULL;
  1.4370 -		}
  1.4371 -	}
  1.4372 +    /* Free video mode lists */
  1.4373 +    for (i = 0; i < NUM_MODELISTS; ++i) {
  1.4374 +        if (SDL_modelist[i] != NULL) {
  1.4375 +            for (j = 0; SDL_modelist[i][j]; ++j)
  1.4376 +                SDL_free (SDL_modelist[i][j]);
  1.4377 +            SDL_free (SDL_modelist[i]);
  1.4378 +            SDL_modelist[i] = NULL;
  1.4379 +        }
  1.4380 +    }
  1.4381  
  1.4382 -	/* Free the window */
  1.4383 -	DIB_QuitGamma(this);
  1.4384 -	if ( SDL_Window ) {
  1.4385 -		DX5_DestroyWindow(this);
  1.4386 -	}
  1.4387 +    /* Free the window */
  1.4388 +    DIB_QuitGamma (this);
  1.4389 +    if (SDL_Window) {
  1.4390 +        DX5_DestroyWindow (this);
  1.4391 +    }
  1.4392  
  1.4393 -	/* Free our window icon */
  1.4394 -	if ( screen_icn ) {
  1.4395 -		DestroyIcon(screen_icn);
  1.4396 -		screen_icn = NULL;
  1.4397 -	}
  1.4398 +    /* Free our window icon */
  1.4399 +    if (screen_icn) {
  1.4400 +        DestroyIcon (screen_icn);
  1.4401 +        screen_icn = NULL;
  1.4402 +    }
  1.4403  }
  1.4404  
  1.4405  /* Exported for the windows message loop only */
  1.4406 -void DX5_RealizePalette(_THIS)
  1.4407 +void
  1.4408 +DX5_RealizePalette (_THIS)
  1.4409  {
  1.4410 -	if ( SDL_palette ) {
  1.4411 -		IDirectDrawSurface3_SetPalette(SDL_primary, SDL_palette);
  1.4412 -	}
  1.4413 +    if (SDL_palette) {
  1.4414 +        IDirectDrawSurface3_SetPalette (SDL_primary, SDL_palette);
  1.4415 +    }
  1.4416  }
  1.4417 -static void DX5_Recolor8Bit(_THIS, SDL_Surface *surface, Uint8 *mapping)
  1.4418 +static void
  1.4419 +DX5_Recolor8Bit (_THIS, SDL_Surface * surface, Uint8 * mapping)
  1.4420  {
  1.4421 -	int row, col;
  1.4422 -	Uint8 *pixels;
  1.4423 +    int row, col;
  1.4424 +    Uint8 *pixels;
  1.4425  
  1.4426 -	if ( surface->w && surface->h ) {
  1.4427 -		if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
  1.4428 -			if ( this->LockHWSurface(this, surface) < 0 ) {
  1.4429 -				return;
  1.4430 -			}
  1.4431 -		}
  1.4432 -		for ( row=0; row<surface->h; ++row ) {
  1.4433 -			pixels = (Uint8 *)surface->pixels+row*surface->pitch;
  1.4434 -			for ( col=0; col<surface->w; ++col, ++pixels ) {
  1.4435 -				*pixels = mapping[*pixels];
  1.4436 -			}
  1.4437 -		}
  1.4438 -		if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
  1.4439 -			this->UnlockHWSurface(this, surface);
  1.4440 -		}
  1.4441 -		SDL_UpdateRect(surface, 0, 0, 0, 0);
  1.4442 -	}
  1.4443 +    if (surface->w && surface->h) {
  1.4444 +        if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
  1.4445 +            if (this->LockHWSurface (this, surface) < 0) {
  1.4446 +                return;
  1.4447 +            }
  1.4448 +        }
  1.4449 +        for (row = 0; row < surface->h; ++row) {
  1.4450 +            pixels = (Uint8 *) surface->pixels + row * surface->pitch;
  1.4451 +            for (col = 0; col < surface->w; ++col, ++pixels) {
  1.4452 +                *pixels = mapping[*pixels];
  1.4453 +            }
  1.4454 +        }
  1.4455 +        if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
  1.4456 +            this->UnlockHWSurface (this, surface);
  1.4457 +        }
  1.4458 +        SDL_UpdateRect (surface, 0, 0, 0, 0);
  1.4459 +    }
  1.4460  }
  1.4461 -void DX5_PaletteChanged(_THIS, HWND window)
  1.4462 +void
  1.4463 +DX5_PaletteChanged (_THIS, HWND window)
  1.4464  {
  1.4465 -	SDL_Palette *palette;
  1.4466 -	SDL_Color *saved = NULL;
  1.4467 -	HDC hdc;
  1.4468 -	int i;
  1.4469 -	PALETTEENTRY *entries;
  1.4470 +    SDL_Palette *palette;
  1.4471 +    SDL_Color *saved = NULL;
  1.4472 +    HDC hdc;
  1.4473 +    int i;
  1.4474 +    PALETTEENTRY *entries;
  1.4475  
  1.4476 -	/* This is true when the window is closing */
  1.4477 -	if ( (SDL_primary == NULL) || (SDL_VideoSurface == NULL) )
  1.4478 -		return;
  1.4479 +    /* This is true when the window is closing */
  1.4480 +    if ((SDL_primary == NULL) || (SDL_VideoSurface == NULL))
  1.4481 +        return;
  1.4482  
  1.4483 -	/* We need to get the colors as they were set */
  1.4484 -	palette = this->physpal;
  1.4485 -	if(!palette)
  1.4486 -	        palette = SDL_VideoSurface->format->palette;
  1.4487 -	if ( palette == NULL ) { /* Sometimes we don't have a palette */
  1.4488 -		return;
  1.4489 -	}
  1.4490 -	entries = SDL_stack_alloc(PALETTEENTRY, palette->ncolors);
  1.4491 -	hdc = GetDC(window);
  1.4492 -	GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries);
  1.4493 -	ReleaseDC(window, hdc);
  1.4494 -	if ( ! colorchange_expected ) {
  1.4495 -		saved = SDL_stack_alloc(SDL_Color, palette->ncolors);
  1.4496 -		SDL_memcpy(saved, palette->colors, 
  1.4497 -					palette->ncolors*sizeof(SDL_Color));
  1.4498 -	}
  1.4499 -	for ( i=0; i<palette->ncolors; ++i ) {
  1.4500 -		palette->colors[i].r = entries[i].peRed;
  1.4501 -		palette->colors[i].g = entries[i].peGreen;
  1.4502 -		palette->colors[i].b = entries[i].peBlue;
  1.4503 -	}
  1.4504 -	SDL_stack_free(entries);
  1.4505 -	if ( ! colorchange_expected ) {
  1.4506 -		Uint8 mapping[256];
  1.4507 +    /* We need to get the colors as they were set */
  1.4508 +    palette = this->physpal;
  1.4509 +    if (!palette)
  1.4510 +        palette = SDL_VideoSurface->format->palette;
  1.4511 +    if (palette == NULL) {      /* Sometimes we don't have a palette */
  1.4512 +        return;
  1.4513 +    }
  1.4514 +    entries = SDL_stack_alloc (PALETTEENTRY, palette->ncolors);
  1.4515 +    hdc = GetDC (window);
  1.4516 +    GetSystemPaletteEntries (hdc, 0, palette->ncolors, entries);
  1.4517 +    ReleaseDC (window, hdc);
  1.4518 +    if (!colorchange_expected) {
  1.4519 +        saved = SDL_stack_alloc (SDL_Color, palette->ncolors);
  1.4520 +        SDL_memcpy (saved, palette->colors,
  1.4521 +                    palette->ncolors * sizeof (SDL_Color));
  1.4522 +    }
  1.4523 +    for (i = 0; i < palette->ncolors; ++i) {
  1.4524 +        palette->colors[i].r = entries[i].peRed;
  1.4525 +        palette->colors[i].g = entries[i].peGreen;
  1.4526 +        palette->colors[i].b = entries[i].peBlue;
  1.4527 +    }
  1.4528 +    SDL_stack_free (entries);
  1.4529 +    if (!colorchange_expected) {
  1.4530 +        Uint8 mapping[256];
  1.4531  
  1.4532 -		SDL_memset(mapping, 0, sizeof(mapping));
  1.4533 -		for ( i=0; i<palette->ncolors; ++i ) {
  1.4534 -			mapping[i] = SDL_FindColor(palette,
  1.4535 -					saved[i].r, saved[i].g, saved[i].b);
  1.4536 -		}
  1.4537 -		DX5_Recolor8Bit(this, SDL_VideoSurface, mapping);
  1.4538 -		SDL_stack_free(saved);
  1.4539 -	}
  1.4540 -	colorchange_expected = 0;
  1.4541 +        SDL_memset (mapping, 0, sizeof (mapping));
  1.4542 +        for (i = 0; i < palette->ncolors; ++i) {
  1.4543 +            mapping[i] = SDL_FindColor (palette,
  1.4544 +                                        saved[i].r, saved[i].g, saved[i].b);
  1.4545 +        }
  1.4546 +        DX5_Recolor8Bit (this, SDL_VideoSurface, mapping);
  1.4547 +        SDL_stack_free (saved);
  1.4548 +    }
  1.4549 +    colorchange_expected = 0;
  1.4550  
  1.4551 -	/* Notify all mapped surfaces of the change */
  1.4552 -	SDL_FormatChanged(SDL_VideoSurface);
  1.4553 +    /* Notify all mapped surfaces of the change */
  1.4554 +    SDL_FormatChanged (SDL_VideoSurface);
  1.4555  }
  1.4556  
  1.4557  /* Exported for the windows message loop only */
  1.4558 -void DX5_WinPAINT(_THIS, HDC hdc)
  1.4559 +void
  1.4560 +DX5_WinPAINT (_THIS, HDC hdc)
  1.4561  {
  1.4562 -	SDL_UpdateRect(SDL_PublicSurface, 0, 0, 0, 0);
  1.4563 +    SDL_UpdateRect (SDL_PublicSurface, 0, 0, 0, 0);
  1.4564  }
  1.4565 +
  1.4566 +/* vi: set ts=4 sw=4 expandtab: */