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
27 extern HWND mainwindow;
31 void CDAudio_SysEject(void)
35 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD)NULL)))
36 Con_DPrintf("MCI_SET_DOOR_OPEN failed (%i)\n", dwReturn);
40 void CDAudio_SysCloseDoor(void)
44 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD)NULL)))
45 Con_DPrintf("MCI_SET_DOOR_CLOSED failed (%i)\n", dwReturn);
48 int CDAudio_SysGetAudioDiskInfo(void)
51 MCI_STATUS_PARMS mciStatusParms;
53 mciStatusParms.dwItem = MCI_STATUS_READY;
54 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
57 Con_DPrintf("CDAudio: drive ready test - get status failed\n");
60 if (!mciStatusParms.dwReturn)
62 Con_DPrintf("CDAudio: drive not ready\n");
66 mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
67 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
70 Con_DPrintf("CDAudio: get tracks - status failed\n");
73 if (mciStatusParms.dwReturn < 1)
75 Con_DPrintf("CDAudio: no music tracks\n");
79 return mciStatusParms.dwReturn;
83 int CDAudio_SysPlay (qbyte track)
86 MCI_PLAY_PARMS mciPlayParms;
87 MCI_STATUS_PARMS mciStatusParms;
89 // don't try to play a non-audio track
90 mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
91 mciStatusParms.dwTrack = track;
92 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
95 Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
98 if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO)
100 Con_Printf("CDAudio: track %i is not audio\n", track);
107 // get the length of the track to be played
108 mciStatusParms.dwItem = MCI_STATUS_LENGTH;
109 mciStatusParms.dwTrack = track;
110 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
113 Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
117 mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0);
118 mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
119 mciPlayParms.dwCallback = (DWORD)mainwindow;
120 dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID) &mciPlayParms);
123 Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
131 int CDAudio_SysStop (void)
135 if ((dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD)NULL)))
137 Con_DPrintf("MCI_STOP failed (%i)", dwReturn);
143 int CDAudio_SysPause (void)
146 MCI_GENERIC_PARMS mciGenericParms;
148 mciGenericParms.dwCallback = (DWORD)mainwindow;
149 if ((dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD)(LPVOID) &mciGenericParms)))
151 Con_DPrintf("MCI_PAUSE failed (%i)", dwReturn);
158 int CDAudio_SysResume (void)
161 MCI_PLAY_PARMS mciPlayParms;
163 mciPlayParms.dwFrom = MCI_MAKE_TMSF(cdPlayTrack, 0, 0, 0);
164 mciPlayParms.dwTo = MCI_MAKE_TMSF(cdPlayTrack + 1, 0, 0, 0);
165 mciPlayParms.dwCallback = (DWORD)mainwindow;
166 dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms);
169 Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
175 LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
177 if (lParam != (LPARAM)wDeviceID)
182 case MCI_NOTIFY_SUCCESSFUL:
187 CDAudio_Play(cdPlayTrack, true);
191 case MCI_NOTIFY_ABORTED:
192 case MCI_NOTIFY_SUPERSEDED:
195 case MCI_NOTIFY_FAILURE:
196 Con_DPrintf("MCI_NOTIFY_FAILURE\n");
202 Con_DPrintf("Unexpected MM_MCINOTIFY type (%i)\n", wParam);
210 int CDAudio_SysUpdate (void)
215 void CDAudio_SysInit (void)
219 int CDAudio_SysStartup (void)
222 MCI_OPEN_PARMS mciOpenParms;
223 MCI_SET_PARMS mciSetParms;
225 mciOpenParms.lpstrDeviceType = "cdaudio";
226 if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD) (LPVOID) &mciOpenParms)))
228 Con_Printf("CDAudio_Init: MCI_OPEN failed (%i)\n", dwReturn);
231 wDeviceID = mciOpenParms.wDeviceID;
233 // Set the time format to track/minute/second/frame (TMSF).
234 mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
235 if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms)))
237 Con_Printf("MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn);
238 mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD)NULL);
245 void CDAudio_SysShutdown (void)
247 if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD)NULL))
248 Con_DPrintf("CDAudio_Shutdown: MCI_CLOSE failed\n");