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
28 extern HWND mainwindow;
32 void CDAudio_SysEject(void)
36 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD)NULL)))
37 Con_DPrintf("MCI_SET_DOOR_OPEN failed (%i)\n", dwReturn);
41 void CDAudio_SysCloseDoor(void)
45 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD)NULL)))
46 Con_DPrintf("MCI_SET_DOOR_CLOSED failed (%i)\n", dwReturn);
49 int CDAudio_SysGetAudioDiskInfo(void)
52 MCI_STATUS_PARMS mciStatusParms;
54 mciStatusParms.dwItem = MCI_STATUS_READY;
55 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
58 Con_DPrint("CDAudio: drive ready test - get status failed\n");
61 if (!mciStatusParms.dwReturn)
63 Con_DPrint("CDAudio: drive not ready\n");
67 mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
68 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
71 Con_DPrint("CDAudio: get tracks - status failed\n");
74 if (mciStatusParms.dwReturn < 1)
76 Con_DPrint("CDAudio: no music tracks\n");
80 return mciStatusParms.dwReturn;
84 int CDAudio_SysPlay (qbyte track)
87 MCI_PLAY_PARMS mciPlayParms;
88 MCI_STATUS_PARMS mciStatusParms;
90 // don't try to play a non-audio track
91 mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
92 mciStatusParms.dwTrack = track;
93 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
96 Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
99 if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO)
101 Con_Printf("CDAudio: track %i is not audio\n", track);
108 // get the length of the track to be played
109 mciStatusParms.dwItem = MCI_STATUS_LENGTH;
110 mciStatusParms.dwTrack = track;
111 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
114 Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
118 mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0);
119 mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
120 mciPlayParms.dwCallback = (DWORD)mainwindow;
121 dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID) &mciPlayParms);
124 Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
132 int CDAudio_SysStop (void)
136 if ((dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD)NULL)))
138 Con_DPrintf("MCI_STOP failed (%i)\n", dwReturn);
144 int CDAudio_SysPause (void)
147 MCI_GENERIC_PARMS mciGenericParms;
149 mciGenericParms.dwCallback = (DWORD)mainwindow;
150 if ((dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD)(LPVOID) &mciGenericParms)))
152 Con_DPrintf("MCI_PAUSE failed (%i)\n", dwReturn);
159 int CDAudio_SysResume (void)
162 MCI_PLAY_PARMS mciPlayParms;
164 mciPlayParms.dwFrom = MCI_MAKE_TMSF(cdPlayTrack, 0, 0, 0);
165 mciPlayParms.dwTo = MCI_MAKE_TMSF(cdPlayTrack + 1, 0, 0, 0);
166 mciPlayParms.dwCallback = (DWORD)mainwindow;
167 dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms);
170 Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
176 LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
178 if (lParam != (LPARAM)wDeviceID)
183 case MCI_NOTIFY_SUCCESSFUL:
188 CDAudio_Play(cdPlayTrack, true);
192 case MCI_NOTIFY_ABORTED:
193 case MCI_NOTIFY_SUPERSEDED:
196 case MCI_NOTIFY_FAILURE:
197 Con_DPrint("MCI_NOTIFY_FAILURE\n");
203 Con_DPrintf("Unexpected MM_MCINOTIFY type (%i)\n", wParam);
211 int CDAudio_SysUpdate (void)
216 void CDAudio_SysInit (void)
220 int CDAudio_SysStartup (void)
223 MCI_OPEN_PARMS mciOpenParms;
224 MCI_SET_PARMS mciSetParms;
226 mciOpenParms.lpstrDeviceType = "cdaudio";
227 if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD) (LPVOID) &mciOpenParms)))
229 Con_Printf("CDAudio_Init: MCI_OPEN failed (%i)\n", dwReturn);
232 wDeviceID = mciOpenParms.wDeviceID;
234 // Set the time format to track/minute/second/frame (TMSF).
235 mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
236 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms)))
238 Con_Printf("MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn);
239 mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD)NULL);
246 void CDAudio_SysShutdown (void)
248 if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD)NULL))
249 Con_DPrint("CDAudio_Shutdown: MCI_CLOSE failed\n");