src/cdrom/os2/SDL_syscdrom.c
author Sam Lantinga
Mon, 06 Feb 2006 08:28:51 +0000
changeset 1330 450721ad5436
parent 1312 c9b51268668f
child 1336 3692456e7b0f
permissions -rw-r--r--
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
icculus@1190
     1
/*
icculus@1190
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
icculus@1190
     4
icculus@1190
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
icculus@1190
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
icculus@1190
     9
icculus@1190
    10
    This library is distributed in the hope that it will be useful,
icculus@1190
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
icculus@1190
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
icculus@1190
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
icculus@1190
    18
icculus@1190
    19
    Sam Lantinga
icculus@1190
    20
    slouken@libsdl.org
icculus@1190
    21
*/
icculus@1190
    22
icculus@1190
    23
/* Functions for system-level CD-ROM audio control */
icculus@1190
    24
icculus@1190
    25
#define INCL_MCIOS2
icculus@1190
    26
#include <os2.h>
icculus@1190
    27
#include <os2me.h>
icculus@1190
    28
#include <stdio.h>
icculus@1190
    29
#include <stdlib.h>
icculus@1190
    30
#include <string.h>
icculus@1190
    31
icculus@1190
    32
#include "SDL_error.h"
icculus@1190
    33
#include "SDL_cdrom.h"
icculus@1190
    34
#include "SDL_syscdrom.h"
icculus@1190
    35
icculus@1190
    36
/* Size of MCI result buffer (in bytes) */
icculus@1190
    37
#define MCI_CMDRETBUFSIZE	128
icculus@1190
    38
icculus@1190
    39
/* The maximum number of CD-ROM drives we'll detect */
icculus@1190
    40
#define MAX_DRIVES	16	
icculus@1190
    41
icculus@1190
    42
/* A list of available CD-ROM drives */
icculus@1190
    43
static char *SDL_cdlist[MAX_DRIVES];
icculus@1190
    44
//static dev_t SDL_cdmode[MAX_DRIVES];
icculus@1190
    45
icculus@1190
    46
/* The system-dependent CD control functions */
icculus@1190
    47
static const char *SDL_SYS_CDName(int drive);
icculus@1190
    48
static int SDL_SYS_CDOpen(int drive);
icculus@1190
    49
static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
icculus@1190
    50
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
icculus@1190
    51
static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
icculus@1190
    52
static int SDL_SYS_CDPause(SDL_CD *cdrom);
icculus@1190
    53
static int SDL_SYS_CDResume(SDL_CD *cdrom);
icculus@1190
    54
static int SDL_SYS_CDStop(SDL_CD *cdrom);
icculus@1190
    55
static int SDL_SYS_CDEject(SDL_CD *cdrom);
icculus@1190
    56
static void SDL_SYS_CDClose(SDL_CD *cdrom);
icculus@1190
    57
icculus@1190
    58
/* MCI Timing Functions */
icculus@1190
    59
#define	MCI_MMTIMEPERSECOND		3000
icculus@1190
    60
#define	FRAMESFROMMM(mmtime)		(((mmtime)*CD_FPS)/MCI_MMTIMEPERSECOND)
icculus@1190
    61
icculus@1190
    62
icculus@1190
    63
/* Ready for MCI CDAudio Devices */
icculus@1190
    64
int  SDL_SYS_CDInit(void)
icculus@1190
    65
{
icculus@1190
    66
int i; /* generig counter */
icculus@1190
    67
MCI_SYSINFO_PARMS		msp;	/* Structure to MCI SysInfo parameters */
icculus@1190
    68
CHAR 						SysInfoRet[MCI_CMDRETBUFSIZE];	/* Buffer for MCI Command result */
icculus@1190
    69
icculus@1190
    70
/* Fill in our driver capabilities */
icculus@1190
    71
SDL_CDcaps.Name = SDL_SYS_CDName;
icculus@1190
    72
SDL_CDcaps.Open = SDL_SYS_CDOpen;
icculus@1190
    73
SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
icculus@1190
    74
SDL_CDcaps.Status = SDL_SYS_CDStatus;
icculus@1190
    75
SDL_CDcaps.Play = SDL_SYS_CDPlay;
icculus@1190
    76
SDL_CDcaps.Pause = SDL_SYS_CDPause;
icculus@1190
    77
SDL_CDcaps.Resume = SDL_SYS_CDResume;
icculus@1190
    78
SDL_CDcaps.Stop = SDL_SYS_CDStop;
icculus@1190
    79
SDL_CDcaps.Eject = SDL_SYS_CDEject;
icculus@1190
    80
SDL_CDcaps.Close = SDL_SYS_CDClose;
icculus@1190
    81
icculus@1190
    82
/* Get the number of CD ROMs in the System */
icculus@1190
    83
/* Clean SysInfo structure */
icculus@1190
    84
memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS));
icculus@1190
    85
/* Prepare structure to Ask Numer of Audio CDs */
icculus@1190
    86
msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;	/* CD Audio Type */
icculus@1190
    87
msp.pszReturn = (PSZ)&SysInfoRet; 	/* Return Structure */
icculus@1190
    88
msp.ulRetSize = MCI_CMDRETBUFSIZE; 	/* Size of ret struct */
icculus@1190
    89
if (LOUSHORT(mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID)&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR);
icculus@1190
    90
SDL_numcds = atoi(SysInfoRet);
icculus@1190
    91
if (SDL_numcds > MAX_DRIVES) SDL_numcds = MAX_DRIVES; /* Limit maximum CD number */
icculus@1190
    92
icculus@1190
    93
/* Get and Add their system name to the SDL_cdlist */
icculus@1190
    94
msp.pszReturn = (PSZ)&SysInfoRet; 				/* Return Structure */
icculus@1190
    95
msp.ulRetSize = MCI_CMDRETBUFSIZE; 			/* Size of ret struct */
icculus@1190
    96
msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;		/* CD Audio Type */
icculus@1190
    97
for (i=0; i<SDL_numcds; i++)
icculus@1190
    98
	{
icculus@1190
    99
	msp.ulNumber = i+1;
icculus@1190
   100
	mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT,&msp, 0);
icculus@1190
   101
	SDL_cdlist[i] = (char *)malloc(strlen(SysInfoRet)+1);
icculus@1190
   102
	if ( SDL_cdlist[i] == NULL )
icculus@1190
   103
		{
icculus@1190
   104
		SDL_OutOfMemory();
icculus@1190
   105
		return(-1);
icculus@1190
   106
		}
icculus@1190
   107
	strcpy(SDL_cdlist[i], SysInfoRet);
icculus@1190
   108
	}
icculus@1190
   109
return(0);
icculus@1190
   110
}
icculus@1190
   111
icculus@1190
   112
/* Return CDAudio System Dependent Device Name - Ready for MCI*/
icculus@1190
   113
static const char *SDL_SYS_CDName(int drive)
icculus@1190
   114
{
icculus@1190
   115
return(SDL_cdlist[drive]);
icculus@1190
   116
}
icculus@1190
   117
icculus@1190
   118
/* Open CDAudio Device - Ready for MCI */
icculus@1190
   119
static int SDL_SYS_CDOpen(int drive)
icculus@1190
   120
{
icculus@1190
   121
MCI_OPEN_PARMS	mop;
icculus@1190
   122
MCI_SET_PARMS msp;
icculus@1190
   123
MCI_GENERIC_PARMS mgp;
icculus@1190
   124
icculus@1190
   125
/* Open the device */
icculus@1190
   126
mop.hwndCallback = (HWND)NULL;		// None
icculus@1190
   127
mop.usDeviceID = (USHORT)NULL;		// Will be returned.
icculus@1190
   128
mop.pszDeviceType = (PSZ)SDL_cdlist[drive];		// CDAudio Device
icculus@1190
   129
if (LOUSHORT(mciSendCommand(0,MCI_OPEN,MCI_WAIT,&mop, 0)) != MCIERR_SUCCESS) return(CD_ERROR);
icculus@1190
   130
/* Set time format */
icculus@1190
   131
msp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   132
msp.ulTimeFormat = MCI_FORMAT_MSF;	// Minute : Second : Frame structure
icculus@1190
   133
msp.ulSpeedFormat = (ULONG)NULL;		// No change
icculus@1190
   134
msp.ulAudio = (ULONG)NULL;				// No Channel
icculus@1190
   135
msp.ulLevel = (ULONG)NULL;				// No Volume
icculus@1190
   136
msp.ulOver = (ULONG)NULL;				// No Delay
icculus@1190
   137
msp.ulItem = (ULONG)NULL;				// No item
icculus@1190
   138
msp.ulValue = (ULONG)NULL;				// No value for item flag
icculus@1190
   139
if (LOUSHORT(mciSendCommand(mop.usDeviceID,MCI_SET,MCI_WAIT | MCI_SET_TIME_FORMAT,&msp, 0)) == MCIERR_SUCCESS) return (mop.usDeviceID);
icculus@1190
   140
/* Error setting time format? - Close opened device */
icculus@1190
   141
mgp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   142
mciSendCommand(mop.usDeviceID,MCI_CLOSE,MCI_WAIT,&mgp, 0);
icculus@1190
   143
return(CD_ERROR);
icculus@1190
   144
}
icculus@1190
   145
icculus@1190
   146
/* Get CD Table Of Contents - Ready for MCI */
icculus@1190
   147
static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
icculus@1190
   148
{
icculus@1190
   149
MCI_TOC_PARMS mtp;
icculus@1190
   150
MCI_STATUS_PARMS msp;
icculus@1190
   151
MCI_TOC_REC * mtr;
icculus@1190
   152
INT i;
icculus@1190
   153
icculus@1190
   154
/* Correction because MCI cannot read TOC while CD is playing (it'll stop!) */
icculus@1190
   155
if (cdrom->status == CD_PLAYING || cdrom->status == CD_PAUSED) return 0;
icculus@1190
   156
icculus@1190
   157
/* Get Number of Tracks */
icculus@1190
   158
msp.hwndCallback = (HWND)NULL; /* None */
icculus@1190
   159
msp.ulReturn = (ULONG)NULL; /* We want this information */
icculus@1190
   160
msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS;
icculus@1190
   161
msp.ulValue = (ULONG)NULL; /* No additional information */
icculus@1190
   162
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR);
icculus@1190
   163
cdrom->numtracks = msp.ulReturn;
icculus@1190
   164
if ( cdrom->numtracks > SDL_MAX_TRACKS )
icculus@1190
   165
	{
icculus@1190
   166
	cdrom->numtracks = SDL_MAX_TRACKS;
icculus@1190
   167
	}
icculus@1190
   168
/* Alocate space for TOC data */
icculus@1190
   169
mtr = (MCI_TOC_REC *)malloc(cdrom->numtracks*sizeof(MCI_TOC_REC));
icculus@1190
   170
if ( mtr == NULL )
icculus@1190
   171
	{
icculus@1190
   172
	SDL_OutOfMemory();
icculus@1190
   173
	return(-1);
icculus@1190
   174
	}
icculus@1190
   175
/* Get TOC from CD */
icculus@1190
   176
mtp.pBuf = mtr;
icculus@1190
   177
mtp.ulBufSize = cdrom->numtracks*sizeof(MCI_TOC_REC);
icculus@1190
   178
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_GETTOC,MCI_WAIT,&mtp, 0)) != MCIERR_SUCCESS)
icculus@1190
   179
	{
icculus@1190
   180
	SDL_OutOfMemory();
icculus@1190
   181
	free(mtr);
icculus@1190
   182
	return(CD_ERROR);
icculus@1190
   183
	}
icculus@1190
   184
/* Fill SDL Tracks Structure */
icculus@1190
   185
for (i=0; i<cdrom->numtracks; i++)
icculus@1190
   186
	{
icculus@1190
   187
	/* Set Track ID */
icculus@1190
   188
	cdrom->track[i].id = (mtr+i)->TrackNum;
icculus@1190
   189
	/* Set Track Type */
icculus@1190
   190
	msp.hwndCallback = (HWND)NULL; /* None */
icculus@1190
   191
	msp.ulReturn = (ULONG)NULL; /* We want this information */
icculus@1190
   192
	msp.ulItem = MCI_CD_STATUS_TRACK_TYPE;
icculus@1190
   193
	msp.ulValue = (ULONG)((mtr+i)->TrackNum); /* Track Number? */
icculus@1190
   194
	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS)
icculus@1190
   195
		{
icculus@1190
   196
		free(mtr);
icculus@1190
   197
		return (CD_ERROR);
icculus@1190
   198
		}
icculus@1190
   199
	if (msp.ulReturn==MCI_CD_TRACK_AUDIO) cdrom->track[i].type = SDL_AUDIO_TRACK;
icculus@1190
   200
	else cdrom->track[i].type = SDL_DATA_TRACK;
icculus@1190
   201
	/* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */
icculus@1190
   202
	cdrom->track[i].length = FRAMESFROMMM((mtr+i)->ulEndAddr - (mtr+i)->ulStartAddr);
icculus@1190
   203
	/* Set Track Offset */
icculus@1190
   204
	cdrom->track[i].offset = FRAMESFROMMM((mtr+i)->ulStartAddr);
icculus@1190
   205
	}
icculus@1190
   206
free(mtr);
icculus@1190
   207
return(0);
icculus@1190
   208
}
icculus@1190
   209
icculus@1190
   210
icculus@1190
   211
/* Get CD-ROM status - Ready for MCI */
icculus@1190
   212
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
icculus@1190
   213
{
icculus@1190
   214
CDstatus status;
icculus@1190
   215
MCI_STATUS_PARMS msp;
icculus@1190
   216
icculus@1190
   217
/* Get Status from MCI */
icculus@1190
   218
msp.hwndCallback = (HWND)NULL; /* None */
icculus@1190
   219
msp.ulReturn = (ULONG)NULL; /* We want this information */
icculus@1190
   220
msp.ulItem = MCI_STATUS_MODE;
icculus@1190
   221
msp.ulValue = (ULONG)NULL; /* No additional information */
icculus@1190
   222
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) status = CD_ERROR;
icculus@1190
   223
else
icculus@1190
   224
	{
icculus@1190
   225
	switch(msp.ulReturn)
icculus@1190
   226
		{
icculus@1190
   227
		case	MCI_MODE_NOT_READY:
icculus@1190
   228
			status = CD_TRAYEMPTY;
icculus@1190
   229
			break;
icculus@1190
   230
		case	MCI_MODE_PAUSE:
icculus@1190
   231
			status = CD_PAUSED;
icculus@1190
   232
			break;
icculus@1190
   233
		case	MCI_MODE_PLAY:
icculus@1190
   234
			status = CD_PLAYING;
icculus@1190
   235
			break;
icculus@1190
   236
		case	MCI_MODE_STOP:
icculus@1190
   237
			status = CD_STOPPED;
icculus@1190
   238
			break;
icculus@1190
   239
		/* These cases should not occour */
icculus@1190
   240
		case	MCI_MODE_RECORD:
icculus@1190
   241
		case	MCI_MODE_SEEK:
icculus@1190
   242
		default:
icculus@1190
   243
			status = CD_ERROR;
icculus@1190
   244
			break;
icculus@1190
   245
		}
icculus@1190
   246
	}
icculus@1190
   247
icculus@1190
   248
/* Determine position */
icculus@1190
   249
if (position != NULL) /* The SDL $&$&%# CDROM call sends NULL pointer here! */
icculus@1190
   250
	{
icculus@1190
   251
		if ((status == CD_PLAYING) || (status == CD_PAUSED))
icculus@1190
   252
		{
icculus@1190
   253
		/* Get Position */
icculus@1190
   254
		msp.hwndCallback = (HWND)NULL; /* None */
icculus@1190
   255
		msp.ulReturn = (ULONG)NULL; /* We want this information */
icculus@1190
   256
		msp.ulItem = MCI_STATUS_POSITION;
icculus@1190
   257
		msp.ulValue = (ULONG)NULL; /* No additiona info */
icculus@1190
   258
		if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return (CD_ERROR);
icculus@1190
   259
		/* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */
icculus@1190
   260
		*position = MSF_TO_FRAMES(MSF_MINUTE(msp.ulReturn),MSF_SECOND(msp.ulReturn),MSF_FRAME(msp.ulReturn));
icculus@1190
   261
		}
icculus@1190
   262
	else *position = 0;
icculus@1190
   263
	}
icculus@1190
   264
return(status);
icculus@1190
   265
}
icculus@1190
   266
icculus@1190
   267
/* Start play - Ready for MCI */
icculus@1190
   268
static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
icculus@1190
   269
{
icculus@1190
   270
MCI_GENERIC_PARMS mgp;
icculus@1190
   271
MCI_STATUS_PARMS msp;
icculus@1190
   272
MCI_PLAY_PARMS	mpp;
icculus@1190
   273
ULONG min,sec,frm;
icculus@1190
   274
icculus@1190
   275
/* Start MSF */
icculus@1190
   276
FRAMES_TO_MSF(start, &min, &sec, &frm);
icculus@1190
   277
MSF_MINUTE(mpp.ulFrom) = min;
icculus@1190
   278
MSF_SECOND(mpp.ulFrom) = sec;
icculus@1190
   279
MSF_FRAME(mpp.ulFrom) = frm;
icculus@1190
   280
/* End MSF */
icculus@1190
   281
FRAMES_TO_MSF(start+length, &min, &sec, &frm);
icculus@1190
   282
MSF_MINUTE(mpp.ulTo) = min;
icculus@1190
   283
MSF_SECOND(mpp.ulTo) = sec;
icculus@1190
   284
MSF_FRAME(mpp.ulTo) = frm;
icculus@1190
   285
#ifdef DEBUG_CDROM
icculus@1190
   286
	fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
icculus@1190
   287
	playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
icculus@1190
   288
	playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
icculus@1190
   289
#endif
icculus@1190
   290
/* Verifies if it is paused first... and if it is, unpause before stopping it. */
icculus@1190
   291
msp.hwndCallback = (HWND)NULL; /* None */
icculus@1190
   292
msp.ulReturn = (ULONG)NULL; /* We want this information */
icculus@1190
   293
msp.ulItem = MCI_STATUS_MODE;
icculus@1190
   294
msp.ulValue = (ULONG)NULL; /* No additional information */
icculus@1190
   295
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS)
icculus@1190
   296
	{
icculus@1190
   297
	if (msp.ulReturn == MCI_MODE_PAUSE)
icculus@1190
   298
		{
icculus@1190
   299
		mgp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   300
		mciSendCommand(cdrom->id,MCI_RESUME,NULL,&mgp, 0);
icculus@1190
   301
		}
icculus@1190
   302
	}
icculus@1190
   303
/* Now play it. */
icculus@1190
   304
mpp.hwndCallback = (HWND)NULL;		// We do not want the info. temp
icculus@1190
   305
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PLAY,MCI_FROM | MCI_TO,&mpp, 0)) == MCIERR_SUCCESS) return 0;
icculus@1190
   306
return (CD_ERROR);
icculus@1190
   307
}
icculus@1190
   308
icculus@1190
   309
/* Pause play - Ready for MCI */
icculus@1190
   310
static int SDL_SYS_CDPause(SDL_CD *cdrom)
icculus@1190
   311
{
icculus@1190
   312
MCI_GENERIC_PARMS mgp;
icculus@1190
   313
icculus@1190
   314
mgp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   315
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PAUSE,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0;
icculus@1190
   316
return(CD_ERROR);
icculus@1190
   317
}
icculus@1190
   318
icculus@1190
   319
/* Resume play - Ready for MCI */
icculus@1190
   320
static int SDL_SYS_CDResume(SDL_CD *cdrom)
icculus@1190
   321
{
icculus@1190
   322
MCI_GENERIC_PARMS mgp;
icculus@1190
   323
icculus@1190
   324
mgp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   325
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_RESUME,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0;
icculus@1190
   326
return(CD_ERROR);
icculus@1190
   327
}
icculus@1190
   328
icculus@1190
   329
/* Stop play - Ready for MCI */
icculus@1190
   330
static int SDL_SYS_CDStop(SDL_CD *cdrom)
icculus@1190
   331
{
icculus@1190
   332
MCI_GENERIC_PARMS mgp;
icculus@1190
   333
MCI_STATUS_PARMS msp;
icculus@1190
   334
icculus@1190
   335
/* Verifies if it is paused first... and if it is, unpause before stopping it. */
icculus@1190
   336
msp.hwndCallback = (HWND)NULL; /* None */
icculus@1190
   337
msp.ulReturn = (ULONG)NULL; /* We want this information */
icculus@1190
   338
msp.ulItem = MCI_STATUS_MODE;
icculus@1190
   339
msp.ulValue = (ULONG)NULL; /* No additional information */
icculus@1190
   340
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS)
icculus@1190
   341
	{
icculus@1190
   342
	if (msp.ulReturn == MCI_MODE_PAUSE)
icculus@1190
   343
		{
icculus@1190
   344
		mgp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   345
		mciSendCommand(cdrom->id,MCI_RESUME,NULL,&mgp, 0);
icculus@1190
   346
		}
icculus@1190
   347
	}
icculus@1190
   348
/* Now stops the media */
icculus@1190
   349
mgp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   350
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STOP,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0;
icculus@1190
   351
return(CD_ERROR);
icculus@1190
   352
}
icculus@1190
   353
icculus@1190
   354
/* Eject the CD-ROM - Ready for MCI */
icculus@1190
   355
static int SDL_SYS_CDEject(SDL_CD *cdrom)
icculus@1190
   356
{
icculus@1190
   357
MCI_SET_PARMS msp;
icculus@1190
   358
icculus@1190
   359
msp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   360
msp.ulTimeFormat = (ULONG)NULL;		// No change
icculus@1190
   361
msp.ulSpeedFormat = (ULONG)NULL;		// No change
icculus@1190
   362
msp.ulAudio = (ULONG)NULL;				// No Channel
icculus@1190
   363
msp.ulLevel = (ULONG)NULL;				// No Volume
icculus@1190
   364
msp.ulOver = (ULONG)NULL;				// No Delay
icculus@1190
   365
msp.ulItem = (ULONG)NULL;					// No item
icculus@1190
   366
msp.ulValue = (ULONG)NULL;					// No value for item flag
icculus@1190
   367
if (LOUSHORT(mciSendCommand(cdrom->id,MCI_SET,MCI_WAIT | MCI_SET_DOOR_OPEN,&msp, 0)) == MCIERR_SUCCESS) return 0;
icculus@1190
   368
return(CD_ERROR);
icculus@1190
   369
}
icculus@1190
   370
icculus@1190
   371
/* Close the CD-ROM handle - Ready for MCI */
icculus@1190
   372
static void SDL_SYS_CDClose(SDL_CD *cdrom)
icculus@1190
   373
{
icculus@1190
   374
MCI_GENERIC_PARMS mgp;
icculus@1190
   375
icculus@1190
   376
mgp.hwndCallback = (HWND)NULL;		// None
icculus@1190
   377
mciSendCommand(cdrom->id,MCI_CLOSE,MCI_WAIT,&mgp, 0);
icculus@1190
   378
}
icculus@1190
   379
icculus@1190
   380
/* Finalize CDROM Subsystem - Ready for MCI */
icculus@1190
   381
void SDL_SYS_CDQuit(void)
icculus@1190
   382
{
icculus@1190
   383
int i;
icculus@1190
   384
icculus@1190
   385
if ( SDL_numcds > 0 )
icculus@1190
   386
	{
icculus@1190
   387
	for ( i=0; i<SDL_numcds; ++i )
icculus@1190
   388
		{
icculus@1190
   389
		free(SDL_cdlist[i]);
icculus@1190
   390
		}
icculus@1190
   391
	SDL_numcds = 0;
icculus@1190
   392
	}
icculus@1190
   393
}
icculus@1190
   394