annotate vidix/sysdep/libdha_win32.c @ 36900:ecf965eee74d

Remove casts. Make use of implicit arithmetic conversion and increase precision at that.
author ib
date Wed, 12 Mar 2014 12:01:40 +0000
parents d9cf7500b0d8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
1 /*
30419
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
2 * MAPDEV.h - include file for VxD MAPDEV
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
3 * Copyright (c) 1996 Vireo Software, Inc.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
4 * Modified for libdha by Nick Kurshev.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
5 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
6 * This file is part of MPlayer.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
7 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
9 * it under the terms of the GNU General Public License as published by
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
11 * (at your option) any later version.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
12 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
16 * GNU General Public License for more details.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
17 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
18 * You should have received a copy of the GNU General Public License along
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
21 */
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
22
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
23 #include <windows.h>
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
24 #include <ddk/ntddk.h>
26994
4eb30f58ea41 Fix dhahelper.h #include paths.
diego
parents: 26900
diff changeset
25 #include "vidix/dhahelperwin/dhahelper.h"
33627
d9cf7500b0d8 vidix: Replace IsWinNT() forward declaration by a proper header.
diego
parents: 33623
diff changeset
26 #include "libdha_win32.h"
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
27
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
28 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
29 This is the request structure that applications use
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
30 to request services from the MAPDEV VxD.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
31 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
32
25607
9d0b189ce1b2 Fix illegal identifiers: Names starting with __ or _ and uppercase are reserved
diego
parents: 22900
diff changeset
33 typedef struct MapDevRequest
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
34 {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
35 DWORD mdr_ServiceID; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
36 LPVOID mdr_PhysicalAddress; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
37 DWORD mdr_SizeInBytes; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
38 LPVOID mdr_LinearAddress; /* returned by VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
39 WORD mdr_Selector; /* returned if 16-bit caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
40 WORD mdr_Status; /* MDR_xxxx code below */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
41 } MAPDEVREQUEST, *PMAPDEVREQUEST;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
42
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
43 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
44 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
45
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
46 #define MDR_STATUS_SUCCESS 1
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
47 #define MDR_STATUS_ERROR 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
48 /*#include "winioctl.h"*/
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
49 #define FILE_DEVICE_UNKNOWN 0x00000022
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
50 #define METHOD_NEITHER 3
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
51
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
52
28232
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27721
diff changeset
53 int IsWinNT(void) {
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
54 OSVERSIONINFO OSVersionInfo;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
55 OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
56 GetVersionEx(&OSVersionInfo);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
57 return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
58 }
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
59
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
60 static HANDLE hDriver = INVALID_HANDLE_VALUE;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
61
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
62
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
63 /* Memory Map a piece of Real Memory */
10980
e687fa1d55c6 port libdha to mingw
faust3
parents: 4164
diff changeset
64 void *map_phys_mem(unsigned long base, unsigned long size) {
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
65 if(!IsWinNT()){
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
66 HANDLE hDevice ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
67 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
68 DWORD cbBytesReturned ; /* count of bytes returned from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
69 MAPDEVREQUEST req ; /* map device request structure */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
70 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
71 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
72
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
73 hDevice = CreateFile(VxDName, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
74 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
75 if (hDevice == INVALID_HANDLE_VALUE)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
76 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
77 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
78 if (hDevice == INVALID_HANDLE_VALUE) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
79 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
80 exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
81
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
82 req.mdr_ServiceID = MDR_SERVICE_MAP ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
83 req.mdr_PhysicalAddress = (PVOID)base ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
84 req.mdr_SizeInBytes = size ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
85 inBuf[0] = &req ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
86
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
87 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
88 NULL, 0, &cbBytesReturned, NULL) ) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
89 fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
90
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
91 return (void*)req.mdr_LinearAddress ;
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
92 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
93 else{
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
94 dhahelper_t dhahelper_priv;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
95 DWORD dwBytesReturned;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
96 dhahelper_priv.size = size;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
97 dhahelper_priv.base = base;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
98 if(hDriver==INVALID_HANDLE_VALUE)hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
99 if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL)){
17971
fd0d4b94b5ec Change some printf calls to fprintf.
diego
parents: 12056
diff changeset
100 fprintf(stderr,"Unable to map the requested memory region.\n");
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
101 return NULL;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
102 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
103 else return dhahelper_priv.ptr;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
104 }
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
105 }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
106
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
107 void unmap_phys_mem(void *ptr, unsigned long size) {
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
108 if(IsWinNT()){
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
109 dhahelper_t dhahelper_priv;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
110 DWORD dwBytesReturned;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
111 dhahelper_priv.ptr = ptr;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
112 DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
113 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
114 }