2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
29 #if defined(_MSC_VER) && (_MSC_VER < 1300)
30 typedef DWORD DWORD_PTR;
33 extern HWND mainwindow;
37 void CDAudio_SysEject(void)
41 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD_PTR)NULL)))
42 Con_Printf("MCI_SET_DOOR_OPEN failed (%x)\n", (unsigned)dwReturn);
46 void CDAudio_SysCloseDoor(void)
50 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD_PTR)NULL)))
51 Con_Printf("MCI_SET_DOOR_CLOSED failed (%x)\n", (unsigned)dwReturn);
54 int CDAudio_SysGetAudioDiskInfo(void)
57 MCI_STATUS_PARMS mciStatusParms;
59 mciStatusParms.dwItem = MCI_STATUS_READY;
60 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
63 Con_Print("CDAudio_SysGetAudioDiskInfo: drive ready test - get status failed\n");
66 if (!mciStatusParms.dwReturn)
68 Con_Print("CDAudio_SysGetAudioDiskInfo: drive not ready\n");
72 mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
73 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
76 Con_Print("CDAudio_SysGetAudioDiskInfo: get tracks - status failed\n");
79 if (mciStatusParms.dwReturn < 1)
81 Con_Print("CDAudio_SysGetAudioDiskInfo: no music tracks\n");
85 return mciStatusParms.dwReturn;
89 float CDAudio_SysGetVolume (void)
96 void CDAudio_SysSetVolume (float volume)
102 int CDAudio_SysPlay (int track)
105 MCI_PLAY_PARMS mciPlayParms;
106 MCI_STATUS_PARMS mciStatusParms;
108 // don't try to play a non-audio track
109 mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
110 mciStatusParms.dwTrack = track;
111 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
114 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%x)\n", (unsigned)dwReturn);
117 if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO)
119 Con_Printf("CDAudio_SysPlay: track %i is not audio\n", track);
126 // get the length of the track to be played
127 mciStatusParms.dwItem = MCI_STATUS_LENGTH;
128 mciStatusParms.dwTrack = track;
129 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
132 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%x)\n", (unsigned)dwReturn);
136 mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0);
137 mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
138 mciPlayParms.dwCallback = (DWORD_PTR)mainwindow;
139 dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD_PTR)(LPVOID) &mciPlayParms);
142 Con_Printf("CDAudio_SysPlay: MCI_PLAY failed (%x)\n", (unsigned)dwReturn);
150 int CDAudio_SysStop (void)
154 if ((dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD_PTR)NULL)))
156 Con_Printf("MCI_STOP failed (%x)\n", (unsigned)dwReturn);
162 int CDAudio_SysPause (void)
165 MCI_GENERIC_PARMS mciGenericParms;
167 mciGenericParms.dwCallback = (DWORD_PTR)mainwindow;
168 if ((dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD_PTR)(LPVOID) &mciGenericParms)))
170 Con_Printf("MCI_PAUSE failed (%x)\n", (unsigned)dwReturn);
177 int CDAudio_SysResume (void)
180 MCI_PLAY_PARMS mciPlayParms;
182 mciPlayParms.dwFrom = MCI_MAKE_TMSF(cdPlayTrack, 0, 0, 0);
183 mciPlayParms.dwTo = MCI_MAKE_TMSF(cdPlayTrack + 1, 0, 0, 0);
184 mciPlayParms.dwCallback = (DWORD_PTR)mainwindow;
185 dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD_PTR)(LPVOID) &mciPlayParms);
188 Con_Printf("CDAudio_SysResume: MCI_PLAY failed (%x)\n", (unsigned)dwReturn);
194 LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
196 if (lParam != (LPARAM)wDeviceID)
201 case MCI_NOTIFY_SUCCESSFUL:
206 CDAudio_Play(cdPlayTrack, true);
210 case MCI_NOTIFY_ABORTED:
211 case MCI_NOTIFY_SUPERSEDED:
214 case MCI_NOTIFY_FAILURE:
215 Con_Print("MCI_NOTIFY_FAILURE\n");
221 Con_Printf("Unexpected MM_MCINOTIFY type (%i)\n", (int)wParam);
229 int CDAudio_SysUpdate (void)
234 void CDAudio_SysInit (void)
238 int CDAudio_SysStartup (void)
241 MCI_OPEN_PARMS mciOpenParms;
242 MCI_SET_PARMS mciSetParms;
244 mciOpenParms.lpstrDeviceType = "cdaudio";
245 if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD_PTR) (LPVOID) &mciOpenParms)))
247 Con_Printf("CDAudio_SysStartup: MCI_OPEN failed (%x)\n", (unsigned)dwReturn);
250 wDeviceID = mciOpenParms.wDeviceID;
252 // Set the time format to track/minute/second/frame (TMSF).
253 mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
254 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)(LPVOID) &mciSetParms)))
256 Con_Printf("CDAudio_SysStartup: MCI_SET_TIME_FORMAT failed (%x)\n", (unsigned)dwReturn);
257 mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD_PTR)NULL);
264 void CDAudio_SysShutdown (void)
266 if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD_PTR)NULL))
267 Con_Print("CDAudio_SysShutdown: MCI_CLOSE failed\n");