forked from REDPOWAR/glDoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
i_cd.c
238 lines (207 loc) · 7.04 KB
/
i_cd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Global define needed for calling these functions
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include "doomtype.h"
#include "i_cd.h"
#include "gconsole.h"
// Local define needed only for error message capture and display
#define MCIMSGLEN 256
char CDmsg[MCIMSGLEN+32];
void lfprintf(char *message, ... );
dboolean CDOpen(HWND hWnd, CD_Data_t *cdd)
{
MCI_OPEN_PARMS open;
MCIERROR MCI_Error;
open.dwCallback = (DWORD)hWnd;
open.lpstrDeviceType = "cdaudio";
MCI_Error = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD)&open);
cdd->CDError = 0;
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\n");
//MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
con_printf("Unable to open CD-ROM device...\n");
lfprintf(CDmsg);
if (MCI_Error == MCIERR_MUST_USE_SHAREABLE)
{
lfprintf("The \"shareable\" parameter was specified.\nThe program that has the CD device open will not share it.\n");
}
cdd->CDError = MCI_Error;
return(false);
}
cdd->CDDevice = open.wDeviceID;
return(true);
}
dboolean CDCheck(HWND hWnd, CD_Data_t *cdd)
{
MCI_STATUS_PARMS status;
MCIERROR MCI_Error;
status.dwCallback = (DWORD)hWnd;
status.dwItem = MCI_STATUS_MEDIA_PRESENT;
cdd->CDError = 0;
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)&status);
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\nCheckCD");
MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
cdd->CDError = MCI_Error;
return(false);
}
cdd->CDMedia = status.dwReturn;
return(true);
}
dboolean CDMediaIdentity(HWND hWnd, CD_Data_t *cdd, char *szIdent)
{
MCI_INFO_PARMS info;
MCIERROR MCI_Error;
info.dwCallback = (DWORD)hWnd;
info.lpstrReturn = szIdent;
info.dwRetSize = 30;
cdd->CDError = 0;
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_INFO, MCI_INFO_MEDIA_IDENTITY, (DWORD)&info);
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\nMediaIdentityCD");
MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
cdd->CDError = MCI_Error;
return(false);
}
return(true);
}
dboolean CDTrackCount(HWND hWnd, CD_Data_t *cdd)
{
MCI_STATUS_PARMS status;
MCIERROR MCI_Error;
status.dwCallback = (DWORD)hWnd;
status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
cdd->CDError = 0;
cdd->CDTrackCount = 0;
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)&status);
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\nCDTracks");
MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
cdd->CDError = MCI_Error;
return(false);
}
cdd->CDTrackCount = status.dwReturn;
return(true);
}
dboolean CDTrackType(HWND hWnd, CD_Data_t *cdd)
{
MCI_STATUS_PARMS status;
MCIERROR MCI_Error;
status.dwCallback = (DWORD)hWnd;
status.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
status.dwTrack = cdd->CDTrack+1;
cdd->CDError = 0;
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK, (DWORD)&status);
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\nCDTrackType");
MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
cdd->CDError = MCI_Error;
return(false);
}
cdd->CDTrackList[cdd->CDTrack] = status.dwReturn;
return(true);
}
dboolean CDTrackPlay(HWND hWnd, CD_Data_t *cdd)
{
MCI_PLAY_PARMS play;
MCI_SET_PARMS set;
MCIERROR MCI_Error;
char tstr[16];
cdd->CDError = 0;
set.dwTimeFormat = MCI_FORMAT_TMSF;
mciSendCommand(cdd->CDDevice, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &set);
play.dwCallback = (DWORD)hWnd;
play.dwTo = 0L;
play.dwFrom = MCI_MAKE_TMSF(cdd->CDTrack+1, 0, 0, 0);
if (cdd->CDTrack == (cdd->CDTrackCount-1))
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_PLAY, MCI_NOTIFY | MCI_FROM, (DWORD)(LPVOID)&play);
else
{
play.dwTo = MCI_MAKE_TMSF(cdd->CDTrack+2, 0, 0, 0);
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID)&play);
}
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\nCDTrackPlay - ");
sprintf(tstr, "No: %d", cdd->CDTrack);
strcat(CDmsg, tstr);
MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
cdd->CDError = MCI_Error;
return(false);
}
cdd->CDStatus = cd_play;
return(true);
}
dboolean CDPause(HWND hWnd, CD_Data_t *cdd)
{
MCI_SET_PARMS set;
MCI_STATUS_PARMS status;
MCIERROR MCI_Error;
cdd->CDError = 0;
set.dwTimeFormat = MCI_FORMAT_TMSF;
mciSendCommand(cdd->CDDevice, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID)&set);
status.dwCallback = (DWORD)hWnd;
status.dwItem = MCI_STATUS_POSITION;
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)&status);
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\nCDPause");
MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
cdd->CDError = MCI_Error;
return(false);
}
cdd->CDPosition = status.dwReturn;
cdd->CDTrack = MCI_TMSF_TRACK(cdd->CDPosition);
mciSendCommand(cdd->CDDevice, MCI_STOP, 0, (DWORD)NULL);
return(true);
}
dboolean CDResume(HWND hWnd, CD_Data_t *cdd)
{
MCI_SET_PARMS set;
MCI_PLAY_PARMS play;
MCIERROR MCI_Error;
cdd->CDError = 0;
set.dwTimeFormat = MCI_FORMAT_TMSF;
mciSendCommand(cdd->CDDevice, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &set);
play.dwCallback = (DWORD)hWnd;
play.dwTo = 0;
play.dwFrom = cdd->CDPosition;
if (cdd->CDTrack == (cdd->CDTrackCount-1))
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_PLAY, MCI_NOTIFY | MCI_FROM, (DWORD)(LPVOID)&play);
else
{
play.dwTo = MCI_MAKE_TMSF(MCI_TMSF_TRACK(cdd->CDPosition)+1, 0, 0, 0);
MCI_Error = mciSendCommand(cdd->CDDevice, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID)&play);
}
if (MCI_Error)
{
mciGetErrorString(MCI_Error, CDmsg, MCIMSGLEN);
strcat(CDmsg, "\nCDResume");
MessageBox(hWnd, CDmsg, NULL, MB_ICONSTOP | MB_OK);
cdd->CDError = MCI_Error;
return(false);
}
return(true);
}
void CDStop(CD_Data_t *cdd)
{
mciSendCommand(cdd->CDDevice, MCI_STOP, 0, (DWORD)NULL);
cdd->CDStatus = cd_stop;
}
void CDClose(CD_Data_t *cdd)
{
mciSendCommand(cdd->CDDevice, MCI_CLOSE, 0, (DWORD)NULL);
}