2nd time lucky - MPU401 driver. Sorry about the previous breakage of blue :(
[reactos.git] / reactos / drivers / dd / blue / dll / mpu401.c
1 /*
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/dd/mpu401/dll/mpu401.c
6 * PURPOSE: MPU-401 MIDI driver WINMM interface
7 * PROGRAMMER: Andrew Greenwood
8 * UPDATE HISTORY:
9 * Sept 28, 2003: Created
10 */
11
12 #include <windows.h>
13 typedef UINT *LPUINT;
14 #include <mmsystem.h>
15 #include "messages.h"
16
17
18 #define DBG printf
19
20
21 // Erm... This is in mmsystem i think:
22 LONG APIENTRY DefDriverProc(DWORD dwDriverIdentifier,
23 HANDLE hDriver,
24 UINT message, // Bug in ptypes32.h
25 LONG lParam1,
26 LONG lParam2);
27
28
29
30
31 STATIC int MessageLength(BYTE b)
32 {
33 if (b > 0xf8) return 1;
34
35 switch(b)
36 {
37 case 0xf0 : case 0xf4 : case 0xf5 : case 0xf6 : case 0xf7 :
38 return 1;
39 case 0xf1 : case 0xf3 :
40 return 2;
41 case 0xf2 :
42 return 3;
43 }
44
45 switch(b & 0xf0)
46 {
47 case 0x80 : case 0x90 : case 0xa0 : case 0xb0 : case 0xe0 :
48 return 2;
49 }
50
51 return 0; // must be a status byte
52 }
53
54
55 DWORD APIENTRY modMessage(DWORD id, DWORD msg, DWORD dwUser,
56 DWORD dwParam1, DWORD dwParam2)
57 {
58 switch(msg)
59 {
60 case MODM_GETNUMDEVS :
61 DBG("MODM_GETNUMDEVS\n");
62 break;
63
64 case MODM_GETDEVCAPS :
65 DBG("MODM_GETDEVCAPS\n");
66 break;
67
68 case MODM_OPEN :
69 DBG("MODM_OPEN\n");
70 break;
71
72 case MODM_CLOSE :
73 DBG("MODM_CLOSE\n");
74 break;
75
76 case MODM_DATA :
77 /*
78 MODM_DATA requests that the driver process a short MIDI message.
79
80 PARAMETERS
81 id : ?
82 dwUser : ?
83 dwParam1 : MIDI message packed into a 32-bit number
84 dwParam2 : ?
85
86 RETURN VALUES
87 ???
88 */
89 {
90 int i;
91 BYTE b[4];
92 DBG("MODM_DATA\n");
93 for (i = 0; i < 4; i ++)
94 {
95 b[i] = (BYTE)(dwParam1 % 256);
96 dwParam1 /= 256;
97 }
98 // midiOutWrite(data, length, client?)
99 // somehow we need to keep track of running status
100 // return midiOutWrite(b, modMIDIlength((PMIDIALLOC)dwUser, b[0]),
101 // (PMIDIALLOC)dwUser);
102 }
103
104 case MODM_LONGDATA :
105 DBG("MODM_LONGDATA\n");
106 break;
107
108 case MODM_RESET :
109 DBG("MODM_RESET\n");
110 break;
111
112 case MODM_SETVOLUME :
113 DBG("MODM_SETVOLUME\n");
114 break;
115
116 case MODM_GETVOLUME :
117 DBG("MODM_GETVOLUME\n");
118 break;
119
120 case MODM_CACHEPATCHES :
121 DBG("MODM_CACHEPATCHES\n");
122 break;
123
124 case MODM_CACHEDRUMPATCHES :
125 DBG("MODM_CACHEDRUMPATCHES\n");
126 break;
127 }
128
129 // return MMSYSERR_NOT_SUPPORTED;
130 }
131
132
133
134 LRESULT DriverProc(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage,
135 LPARAM lParam1, LPARAM lParam2)
136 /*
137 ROUTINE
138 DriverProc
139
140 PURPOSE
141 Process driver messages
142
143 PARAMETERS
144 dwDriverID : Identifier of installable driver
145 hDriver : Handle of the installable driver instance
146 uiMessage : Which operation to perform
147 lParam1 : Message-dependent
148 lParam2 : Message-dependent
149
150 NOTES
151 For parameters that aren't listed in the messages, they are not
152 used.
153
154 Loading and unloading messages occur in this order:
155 DRV_LOAD - DRV_ENABLE - DRV_OPEN
156 DRV_CLOSE - DRV_DISABLE - DRV_FREE
157 */
158 {
159 switch(uiMessage)
160 {
161 case DRV_LOAD :
162 /*
163 DRV_LOAD notifies the driver that it has been loaded. It should
164 then make sure it can function properly.
165
166 PARAMETERS
167 (No Parameters)
168
169 RETURN VALUES
170 Non-zero if successful
171 Zero if not
172 */
173 DBG("DRV_LOAD\n");
174 break;
175
176 case DRV_FREE :
177 /*
178 DRV_FREE notifies the driver that it is being unloaded. It
179 should make sure it releases any memory or other resources.
180
181 PARAMETERS
182 hDriver : Hande of the installable driver instance
183
184 RETURN VALUES
185 Nothing
186 */
187 DBG("DRV_FREE\n");
188 break;
189
190 case DRV_OPEN :
191 /*
192 DRV_OPEN directs the driver to open a new instance.
193
194 PARAMETERS
195 dwDriverID : Identifier of the installable driver
196 hDriver : Handle of the installable driver instance
197 lParam1 : Wide string specifying configuration
198 information, or this can be NULL
199 lParam2 : 32-bit driver-specific data
200
201 RETURN VALUES
202 Non-zero if successful
203 Zero if not
204 */
205 DBG("DRV_OPEN\n");
206 break;
207
208 case DRV_CLOSE :
209 /*
210 DRV_CLOSE directs the driver to close the specified instance.
211
212 PARAMETERS
213 dwDriverID : Identifier of the installable driver
214 hDriver : Handle of the installable driver instance
215 lParam1 : 32-bit value passed from DriverClose()
216 lParam2 : 32-bit value passed from DriverClose()
217
218 RETURN VALUES
219 Non-zero if successful
220 Zero if not
221 */
222 DBG("DRV_CLOSE\n");
223 break;
224
225 case DRV_ENABLE :
226 /*
227 DRV_ENABLE enables the driver (as if you didn't see THAT one
228 coming!)
229
230 PARAMETERS
231 hDriver : Handle of the installable driver instance
232
233 RETURN VALUES
234 Nothing
235 */
236 DBG("DRV_ENABLE\n");
237 break;
238
239 case DRV_DISABLE :
240 /*
241 DRV_DISABLE disables the driver - see above comment ;) This
242 message comes before DRV_FREE.
243
244 PARAMETERS
245 hDriver : Handle of the installable driver instance
246
247 RETURN VALUES
248 Nothing
249 */
250 DBG("DRV_DISABLE\n");
251 break;
252
253 case DRV_QUERYCONFIGURE :
254 /*
255 DRV_QUERYCONFIGURE asks the driver if it supports custom
256 configuration.
257
258 PARAMETERS
259 dwDriverID : Identifier of the installable driver
260 hDriver : Handle of the installable driver instance
261
262 RETURN VALUES
263 Non-zero to indicate the driver can display a config dialog
264 Zero if not
265 */
266 DBG("DRV_QUERYCONFIGURE\n");
267 break;
268
269 case DRV_CONFIGURE :
270 /*
271 DRV_CONFIGURE requests the driver to display a configuration
272 dialog box.
273
274 PARAMETERS
275 dwDriverID : Identified of the installable driver
276 hDriver : Handle of the installable driver instance
277 lParam1 : Handle of the parent window of the dialog
278 lParam2 : Address of a DRVCONFIGINFO, or NULL
279
280 RETURN VALUES
281 DRVCNF_OK The configuration was successful
282 DRVCNF_CANCEL The user cancelled the dialog box
283 DRVCNF_RESTART The configuration requires a reboot
284 */
285 DBG("DRV_CONFIGURE\n");
286 break;
287
288 case DRV_INSTALL :
289 /*
290 DRV_INSTALL notifies the driver that it is being installed.
291
292 PARAMETERS
293 dwDriverID : Identifier of the installable driver
294 hDriver : Handle of the installable driver instance
295 lParam2 : Address of a DEVCONFIGINFO, or NULL
296
297 RETURN VALUES
298 DRVCNF_OK The configuration was successful
299 DRVCNF_CANCEL The user cancelled the dialog box
300 DRVCNF_RESTART The configuration requires a reboot
301 */
302 DBG("DRV_INSTALL\n");
303 break;
304
305 case DRV_REMOVE :
306 /*
307 DRV_REMOVE notifies the driver that it is being removed from the
308 system.
309
310 PARAMETERS
311 dwDriverID : Identifier of the installable driver
312 hDriver : Handle of the installable driver instance
313
314 RETURN VALUES
315 Nothing
316 */
317 DBG("DRV_REMOVE\n");
318 break;
319
320 case DRV_POWER :
321 /*
322 DRV_POWER notifies the driver that power is being turned on/off.
323
324 PARAMETERS
325 dwDriverID : Identifier of the installable driver
326 hDriver : Handle of the installable driver instance
327
328 RETURN VALUES
329 Nothing
330 */
331 DBG("DRV_POWER\n");
332
333 case DRV_EXITSESSION :
334 /*
335 DRV_EXITSESSION notifies the driver that Windows is shutting down.
336
337 PARAMETERS
338 dwDriverID : Identifier of the installable driver
339 hDriver : Handle of the installable driver instance
340
341 RETURN VALUES
342 Nothing
343 */
344
345 // case DRV_PNPINSTALL : break;
346 default :
347 return DefDriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
348 }
349
350 return DefDriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
351 }
352
353
354 BOOL CALLBACK DProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
355 {
356 // if (uMsg == WM_INITDIALOG)
357 // return -1;
358
359 return 0;
360 }
361
362
363 void Test()
364 {
365 // HWND Dlg = CreateDialog(GetModuleHandle(NULL), "Config", NULL, DProc);
366 HWND Z = CreateWindow("Static", "", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 20, 20, NULL, NULL, GetModuleHandle(NULL), NULL);
367 if (DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(1001), Z, DProc) == -1)
368 MessageBox(NULL, "Error", "Error", MB_OK | MB_TASKMODAL);
369 }