source: cmedia/trunk/Drv16/apmcalls.cpp

Last change on this file was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 4.4 KB
Line 
1//----------------------------------------------------------------------//
2// //
3// APMCALLS.CPP //
4// //
5// (c) S&T Systemtechnik GmbH //
6// R. Ihle 11/01 //
7// //
8//----------------------------------------------------------------------//
9
10extern "C" {
11 #define INCL_16
12 #include <os2.h>
13}
14
15#include <string.h>
16#include <include.h>
17#include <devhelp.h>
18#include <apmioctl.h>
19
20#include <apmcalls.h>
21
22
23//----------------------------------------------------------------------//
24// //
25//----------------------------------------------------------------------//
26
27typedef struct
28{
29 USHORT usFunction;
30 union {
31 APMIDC_REGISTER_PKT Register; // Func 0: APMIDC_Register
32 APMIDC_DEREGISTER_PKT Deregister; // Func 1: APMIDC_Deregister
33 APMIDC_SENDEVENT_PKT SendEvent; // Func 2: APMIDC_SendEvent
34 APMIDC_QSTATUS_PKT QueryStatus; // Func 3: APMIDC_QueryStatus
35 APMIDC_QINFO_PKT QueryInfo; // Func 4: APMIDC_QueryInfo
36 // Func 5: APMIDC_QueryDaemon
37 APMIDC_QSTATE_PKT QueryPwrState; // Func 6: APMIDC_QueryState
38 APMIDC_OEMFUNC_PKT OEMFunction; // Func 7: APMIDC_OEMFunction
39 };
40} APM_IDC_PARAM, FAR *PAPM_IDC_PARAM;
41
42
43
44//----------------------------------------------------------------------//
45// //
46//----------------------------------------------------------------------//
47
48static IDCTABLE APMIDCTable;
49
50
51
52//----------------------------------------------------------------------//
53// internal function to call APM IDC interface //
54//----------------------------------------------------------------------//
55
56static USHORT CallAPM(PAPM_IDC_PARAM pParam)
57{
58 __asm {
59 mov bx, word ptr [APMIDCTable + 6]
60 mov ax, -1
61 or bx, word ptr [APMIDCTable + 6 + 2]
62 jz l1
63
64 push ds
65 push es
66 les bx, [pParam]
67 call dword ptr [APMIDCTable + 6] ; IDCTable.ProtIDCEntry
68 pop es
69 pop ds
70
71 l1:
72 }
73
74 return _AX();
75}
76
77
78
79//----------------------------------------------------------------------//
80// Attach to APM device driver //
81//----------------------------------------------------------------------//
82
83BOOL APMAttach(VOID)
84{
85 return DevHelp_AttachDD((NPSZ)"APM$ ", (NPBYTE)&APMIDCTable) == 0 &&
86 APMIDCTable.ProtIDCEntry != NULL;
87}
88
89
90
91//----------------------------------------------------------------------//
92// Register APM client //
93//----------------------------------------------------------------------//
94
95HAPM APMRegister(PFNAPMEVENT pfnAPMEvent, ULONG ulEventMask, USHORT usDeviceID)
96{
97 APM_IDC_PARAM Param;
98
99 Param.usFunction = APMIDC_Register;
100 Param.Register.hClient = 0;
101 Param.Register.EventHandler = (PFN)pfnAPMEvent;
102 Param.Register.NotifyMask = ulEventMask;
103 Param.Register.ClientDS = _DS();
104 Param.Register.DeviceId = usDeviceID;
105
106 return ( CallAPM(&Param) == 0 ) ? (HAPM)Param.Register.hClient : (HAPM)0;
107}
108
109
110
111//----------------------------------------------------------------------//
112// Deregister APM client //
113//----------------------------------------------------------------------//
114
115BOOL APMDeregister(HAPM hClient)
116{
117 APM_IDC_PARAM Param;
118
119 Param.usFunction = APMIDC_Deregister;
120 Param.Deregister.hClient = hClient;
121
122 return CallAPM(&Param) == 0;
123}
124
125
126#if 0
127
128//----------------------------------------------------------------------//
129// Query power status //
130//----------------------------------------------------------------------//
131
132BOOL APMQueryPwrStatus(struct _APMIDC_QSTATUS_PKT FAR *pStatus)
133{
134 APM_IDC_PARAM Param;
135 USHORT usResult;
136
137 _fmemset(&Param, 0, sizeof(Param));
138 Param.usFunction = APMIDC_QueryStatus;
139 Param.QueryStatus.ParmLength = sizeof(Param.QueryStatus);
140
141 usResult = CallAPM(&Param);
142 _fmemcpy(pStatus, &Param.QueryStatus, sizeof(APMIDC_QSTATUS_PKT));
143
144 return usResult == 0;
145}
146
147
148
149//----------------------------------------------------------------------//
150// Query power status //
151//----------------------------------------------------------------------//
152
153BOOL APMSendPowerEvent(USHORT usSubID, USHORT usDeviceID, USHORT usPwrState)
154{
155 APM_IDC_PARAM Param;
156
157 Param.usFunction = APMIDC_SendEvent;
158 Param.SendEvent.SubId = usSubID;
159 Param.SendEvent.reserved = 0;
160 Param.SendEvent.DevId = usDeviceID;
161 Param.SendEvent.PwrState = usPwrState;
162
163 return CallAPM(&Param) == 0;
164}
165
166
167#endif
168
169
170
Note: See TracBrowser for help on using the repository browser.