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 typedef DWORD DWORD_PTR;
32 extern HWND mainwindow;
36 void CDAudio_SysEject(void)
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);
45 void CDAudio_SysCloseDoor(void)
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);
53 int CDAudio_SysGetAudioDiskInfo(void)
56 MCI_STATUS_PARMS mciStatusParms;
58 mciStatusParms.dwItem = MCI_STATUS_READY;
59 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
62 Con_Print("CDAudio_SysGetAudioDiskInfo: drive ready test - get status failed\n");
65 if (!mciStatusParms.dwReturn)
67 Con_Print("CDAudio_SysGetAudioDiskInfo: drive not ready\n");
71 mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
72 dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR) (LPVOID) &mciStatusParms);
75 Con_Print("CDAudio_SysGetAudioDiskInfo: get tracks - status failed\n");
78 if (mciStatusParms.dwReturn < 1)
80 Con_Print("CDAudio_SysGetAudioDiskInfo: no music tracks\n");
84 return mciStatusParms.dwReturn;
88 float CDAudio_SysGetVolume (void)
95 void CDAudio_SysSetVolume (float volume)
101 int CDAudio_SysPlay (qbyte track)
104 MCI_PLAY_PARMS mciPlayParms;
105 MCI_STATUS_PARMS mciStatusParms;
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);
113 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%i)\n", dwReturn);
116 if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO)
118 Con_Printf("CDAudio_SysPlay: track %i is not audio\n", track);
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);
131 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%i)\n", dwReturn);
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);
141 Con_Printf("CDAudio_SysPlay: MCI_PLAY failed (%i)\n", dwReturn);
149 int CDAudio_SysStop (void)
153 if ((dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD_PTR)NULL)))
155 Con_Printf("MCI_STOP failed (%i)\n", dwReturn);
161 int CDAudio_SysPause (void)
164 MCI_GENERIC_PARMS mciGenericParms;
166 mciGenericParms.dwCallback = (DWORD_PTR)mainwindow;
167 if ((dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD_PTR)(LPVOID) &mciGenericParms)))
169 Con_Printf("MCI_PAUSE failed (%i)\n", dwReturn);
176 int CDAudio_SysResume (void)
179 MCI_PLAY_PARMS mciPlayParms;
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);
187 Con_Printf("CDAudio_SysResume: MCI_PLAY failed (%i)\n", dwReturn);
193 LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
195 if (lParam != (LPARAM)wDeviceID)
200 case MCI_NOTIFY_SUCCESSFUL:
205 CDAudio_Play(cdPlayTrack, true);
209 case MCI_NOTIFY_ABORTED:
210 case MCI_NOTIFY_SUPERSEDED:
213 case MCI_NOTIFY_FAILURE:
214 Con_Print("MCI_NOTIFY_FAILURE\n");
220 Con_Printf("Unexpected MM_MCINOTIFY type (%i)\n", wParam);
228 int CDAudio_SysUpdate (void)
233 void CDAudio_SysInit (void)
237 int CDAudio_SysStartup (void)
240 MCI_OPEN_PARMS mciOpenParms;
241 MCI_SET_PARMS mciSetParms;
243 mciOpenParms.lpstrDeviceType = "cdaudio";
244 if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD_PTR) (LPVOID) &mciOpenParms)))
246 Con_Printf("CDAudio_SysStartup: MCI_OPEN failed (%i)\n", dwReturn);
249 wDeviceID = mciOpenParms.wDeviceID;
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)))
255 Con_Printf("CDAudio_SysStartup: MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn);
256 mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD_PTR)NULL);
263 void CDAudio_SysShutdown (void)
265 if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD_PTR)NULL))
266 Con_Print("CDAudio_SysShutdown: MCI_CLOSE failed\n");