annotate libdha/sysdep/libdha_win32.c @ 4656:04880518728d

add initial mPNG support
author pontscho
date Mon, 11 Feb 2002 09:15:59 +0000
parents 2e3262002acb
children e687fa1d55c6
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 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
2 MAPDEV.h - include file for VxD MAPDEV
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
3 Copyright (c) 1996 Vireo Software, Inc.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
4 Modified for libdha by Nick Kurshev.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
5 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
6
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
7 #include <windows.h>
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
8
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
9 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
10 This is the request structure that applications use
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
11 to request services from the MAPDEV VxD.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
12 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
13
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
14 typedef struct _MapDevRequest
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
15 {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
16 DWORD mdr_ServiceID; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
17 LPVOID mdr_PhysicalAddress; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
18 DWORD mdr_SizeInBytes; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
19 LPVOID mdr_LinearAddress; /* returned by VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
20 WORD mdr_Selector; /* returned if 16-bit caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
21 WORD mdr_Status; /* MDR_xxxx code below */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
22 } MAPDEVREQUEST, *PMAPDEVREQUEST;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
23
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
24 #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
25 #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
26
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
27 #define MDR_STATUS_SUCCESS 1
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
28 #define MDR_STATUS_ERROR 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
29 /*#include "winioctl.h"*/
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
30 #define FILE_DEVICE_UNKNOWN 0x00000022
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
31 #define METHOD_NEITHER 3
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
32 #define FILE_ANY_ACCESS 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
33 #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
34 ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) )
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
35
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
36 /* Memory Map a piece of Real Memory */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
37 void *map_phys_mem(unsigned base, unsigned size) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
38
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
39 HANDLE hDevice ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
40 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
41 DWORD RetInfo[2] ; /* buffer to receive data from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
42 DWORD cbBytesReturned ; /* count of bytes returned from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
43 MAPDEVREQUEST req ; /* map device request structure */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
44 DWORD *pNicstar, Status, Time ; int i ; char *endptr ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
45 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
46 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
47
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
48 hDevice = CreateFile(VxDName, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
49 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
50 if (hDevice == INVALID_HANDLE_VALUE)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
51 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
52 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
53 if (hDevice == INVALID_HANDLE_VALUE) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
54 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
55 exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
56
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
57 req.mdr_ServiceID = MDR_SERVICE_MAP ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
58 req.mdr_PhysicalAddress = (PVOID)base ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
59 req.mdr_SizeInBytes = size ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
60 inBuf[0] = &req ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
61
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
62 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
63 NULL, 0, &cbBytesReturned, NULL) ) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
64 fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
65
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
66 return (void*)req.mdr_LinearAddress ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
67 }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
68
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
69 void unmap_phys_mem(void *ptr, unsigned size) { }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
70