]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cd_win.c
fix VC 6 not supporting DWORD_PTR.
[xonotic/darkplaces.git] / cd_win.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
21 // rights reserved.
22
23 #include <windows.h>
24
25 #include "quakedef.h"
26 #include "cdaudio.h"
27
28 #if _MSC_VER < 1300
29 typedef DWORD DWORD_PTR;
30 #endif
31
32 extern  HWND    mainwindow;
33
34 UINT    wDeviceID;
35
36 void CDAudio_SysEject(void)
37 {
38         DWORD   dwReturn;
39
40         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD_PTR)NULL)))
41                 Con_Printf("MCI_SET_DOOR_OPEN failed (%i)\n", dwReturn);
42 }
43
44
45 void CDAudio_SysCloseDoor(void)
46 {
47         DWORD   dwReturn;
48
49         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD_PTR)NULL)))
50                 Con_Printf("MCI_SET_DOOR_CLOSED failed (%i)\n", dwReturn);
51 }
52
53 int CDAudio_SysGetAudioDiskInfo(void)
54 {
55         DWORD                           dwReturn;
56         MCI_STATUS_PARMS        mciStatusParms;
57
58         mciStatusParms.dwItem = MCI_STATUS_READY;
59         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
60         if (dwReturn)
61         {
62                 Con_Print("CDAudio_SysGetAudioDiskInfo: drive ready test - get status failed\n");
63                 return -1;
64         }
65         if (!mciStatusParms.dwReturn)
66         {
67                 Con_Print("CDAudio_SysGetAudioDiskInfo: drive not ready\n");
68                 return -1;
69         }
70
71         mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
72         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
73         if (dwReturn)
74         {
75                 Con_Print("CDAudio_SysGetAudioDiskInfo: get tracks - status failed\n");
76                 return -1;
77         }
78         if (mciStatusParms.dwReturn < 1)
79         {
80                 Con_Print("CDAudio_SysGetAudioDiskInfo: no music tracks\n");
81                 return -1;
82         }
83
84         return mciStatusParms.dwReturn;
85 }
86
87
88 float CDAudio_SysGetVolume (void)
89 {
90         // IMPLEMENTME
91         return -1.0f;
92 }
93
94
95 void CDAudio_SysSetVolume (float volume)
96 {
97         // IMPLEMENTME
98 }
99
100
101 int CDAudio_SysPlay (qbyte track)
102 {
103         DWORD                           dwReturn;
104         MCI_PLAY_PARMS          mciPlayParms;
105         MCI_STATUS_PARMS        mciStatusParms;
106
107         // don't try to play a non-audio track
108         mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
109         mciStatusParms.dwTrack = track;
110         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
111         if (dwReturn)
112         {
113                 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%i)\n", dwReturn);
114                 return -1;
115         }
116         if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO)
117         {
118                 Con_Printf("CDAudio_SysPlay: track %i is not audio\n", track);
119                 return -1;
120         }
121
122         if (cdPlaying)
123                 CDAudio_Stop();
124
125         // get the length of the track to be played
126         mciStatusParms.dwItem = MCI_STATUS_LENGTH;
127         mciStatusParms.dwTrack = track;
128         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
129         if (dwReturn)
130         {
131                 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%i)\n", dwReturn);
132                 return -1;
133         }
134
135         mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0);
136         mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
137         mciPlayParms.dwCallback = (DWORD_PTR)mainwindow;
138         dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD_PTR)(LPVOID) &mciPlayParms);
139         if (dwReturn)
140         {
141                 Con_Printf("CDAudio_SysPlay: MCI_PLAY failed (%i)\n", dwReturn);
142                 return -1;
143         }
144
145         return 0;
146 }
147
148
149 int CDAudio_SysStop (void)
150 {
151         DWORD   dwReturn;
152
153         if ((dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD_PTR)NULL)))
154         {
155                 Con_Printf("MCI_STOP failed (%i)\n", dwReturn);
156                 return -1;
157         }
158         return 0;
159 }
160
161 int CDAudio_SysPause (void)
162 {
163         DWORD                           dwReturn;
164         MCI_GENERIC_PARMS       mciGenericParms;
165
166         mciGenericParms.dwCallback = (DWORD_PTR)mainwindow;
167         if ((dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD_PTR)(LPVOID) &mciGenericParms)))
168         {
169                 Con_Printf("MCI_PAUSE failed (%i)\n", dwReturn);
170                 return -1;
171         }
172         return 0;
173 }
174
175
176 int CDAudio_SysResume (void)
177 {
178         DWORD                   dwReturn;
179         MCI_PLAY_PARMS  mciPlayParms;
180
181         mciPlayParms.dwFrom = MCI_MAKE_TMSF(cdPlayTrack, 0, 0, 0);
182         mciPlayParms.dwTo = MCI_MAKE_TMSF(cdPlayTrack + 1, 0, 0, 0);
183         mciPlayParms.dwCallback = (DWORD_PTR)mainwindow;
184         dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD_PTR)(LPVOID) &mciPlayParms);
185         if (dwReturn)
186         {
187                 Con_Printf("CDAudio_SysResume: MCI_PLAY failed (%i)\n", dwReturn);
188                 return -1;
189         }
190         return 0;       
191 }
192
193 LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
194 {
195         if (lParam != (LPARAM)wDeviceID)
196                 return 1;
197
198         switch (wParam)
199         {
200                 case MCI_NOTIFY_SUCCESSFUL:
201                         if (cdPlaying)
202                         {
203                                 cdPlaying = false;
204                                 if (cdPlayLooping)
205                                         CDAudio_Play(cdPlayTrack, true);
206                         }
207                         break;
208
209                 case MCI_NOTIFY_ABORTED:
210                 case MCI_NOTIFY_SUPERSEDED:
211                         break;
212
213                 case MCI_NOTIFY_FAILURE:
214                         Con_Print("MCI_NOTIFY_FAILURE\n");
215                         CDAudio_Stop ();
216                         cdValid = false;
217                         break;
218
219                 default:
220                         Con_Printf("Unexpected MM_MCINOTIFY type (%i)\n", wParam);
221                         return 1;
222         }
223
224         return 0;
225 }
226
227
228 int CDAudio_SysUpdate (void)
229 {
230         return 0;
231 }
232
233 void CDAudio_SysInit (void)
234 {
235 }
236
237 int CDAudio_SysStartup (void)
238 {
239         DWORD   dwReturn;
240         MCI_OPEN_PARMS  mciOpenParms;
241         MCI_SET_PARMS   mciSetParms;
242
243         mciOpenParms.lpstrDeviceType = "cdaudio";
244         if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD_PTR) (LPVOID) &mciOpenParms)))
245         {
246                 Con_Printf("CDAudio_SysStartup: MCI_OPEN failed (%i)\n", dwReturn);
247                 return -1;
248         }
249         wDeviceID = mciOpenParms.wDeviceID;
250
251         // Set the time format to track/minute/second/frame (TMSF).
252         mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
253         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)(LPVOID) &mciSetParms)))
254         {
255                 Con_Printf("CDAudio_SysStartup: MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn);
256                 mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD_PTR)NULL);
257                 return -1;
258         }
259
260         return 0;
261 }
262
263 void CDAudio_SysShutdown (void)
264 {
265         if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD_PTR)NULL))
266                 Con_Print("CDAudio_SysShutdown: MCI_CLOSE failed\n");
267 }