clean-up/tidy-up os2/SDL_syscdrom.c SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Wed, 31 Jul 2019 23:50:10 +0300
branchSDL-1.2
changeset 1297737d0eba8fa17
parent 12975 537cc728d28b
child 12980 32075e9e2135
clean-up/tidy-up os2/SDL_syscdrom.c
src/cdrom/os2/SDL_syscdrom.c
     1.1 --- a/src/cdrom/os2/SDL_syscdrom.c	Wed Jul 31 20:55:02 2019 +0300
     1.2 +++ b/src/cdrom/os2/SDL_syscdrom.c	Wed Jul 31 23:50:10 2019 +0300
     1.3 @@ -40,7 +40,7 @@
     1.4  
     1.5  /* A list of available CD-ROM drives */
     1.6  static char *SDL_cdlist[MAX_DRIVES];
     1.7 -//static dev_t SDL_cdmode[MAX_DRIVES];
     1.8 +/*static dev_t SDL_cdmode[MAX_DRIVES];*/
     1.9  
    1.10  /* The system-dependent CD control functions */
    1.11  static const char *SDL_SYS_CDName(int drive);
    1.12 @@ -62,166 +62,174 @@
    1.13  /* Ready for MCI CDAudio Devices */
    1.14  int  SDL_SYS_CDInit(void)
    1.15  {
    1.16 -int i; /* generig counter */
    1.17 -MCI_SYSINFO_PARMS		msp;	/* Structure to MCI SysInfo parameters */
    1.18 -CHAR 						SysInfoRet[MCI_CMDRETBUFSIZE];	/* Buffer for MCI Command result */
    1.19 +	int i; /* generig counter */
    1.20 +	MCI_SYSINFO_PARMS		msp;	/* Structure to MCI SysInfo parameters */
    1.21 +	CHAR	SysInfoRet[MCI_CMDRETBUFSIZE];	/* Buffer for MCI Command result */
    1.22  
    1.23 -/* Fill in our driver capabilities */
    1.24 -SDL_CDcaps.Name = SDL_SYS_CDName;
    1.25 -SDL_CDcaps.Open = SDL_SYS_CDOpen;
    1.26 -SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
    1.27 -SDL_CDcaps.Status = SDL_SYS_CDStatus;
    1.28 -SDL_CDcaps.Play = SDL_SYS_CDPlay;
    1.29 -SDL_CDcaps.Pause = SDL_SYS_CDPause;
    1.30 -SDL_CDcaps.Resume = SDL_SYS_CDResume;
    1.31 -SDL_CDcaps.Stop = SDL_SYS_CDStop;
    1.32 -SDL_CDcaps.Eject = SDL_SYS_CDEject;
    1.33 -SDL_CDcaps.Close = SDL_SYS_CDClose;
    1.34 +	/* Fill in our driver capabilities */
    1.35 +	SDL_CDcaps.Name = SDL_SYS_CDName;
    1.36 +	SDL_CDcaps.Open = SDL_SYS_CDOpen;
    1.37 +	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
    1.38 +	SDL_CDcaps.Status = SDL_SYS_CDStatus;
    1.39 +	SDL_CDcaps.Play = SDL_SYS_CDPlay;
    1.40 +	SDL_CDcaps.Pause = SDL_SYS_CDPause;
    1.41 +	SDL_CDcaps.Resume = SDL_SYS_CDResume;
    1.42 +	SDL_CDcaps.Stop = SDL_SYS_CDStop;
    1.43 +	SDL_CDcaps.Eject = SDL_SYS_CDEject;
    1.44 +	SDL_CDcaps.Close = SDL_SYS_CDClose;
    1.45  
    1.46 -/* Get the number of CD ROMs in the System */
    1.47 -/* Clean SysInfo structure */
    1.48 -SDL_memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS));
    1.49 -/* Prepare structure to Ask Numer of Audio CDs */
    1.50 -msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;	/* CD Audio Type */
    1.51 -msp.pszReturn = SysInfoRet;		/* Return Structure */
    1.52 -msp.ulRetSize = MCI_CMDRETBUFSIZE; 	/* Size of ret struct */
    1.53 -if (LOUSHORT(mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID)&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR);
    1.54 -SDL_numcds = atoi(SysInfoRet);
    1.55 -if (SDL_numcds > MAX_DRIVES) SDL_numcds = MAX_DRIVES; /* Limit maximum CD number */
    1.56 +	/* Get the number of CD ROMs in the System */
    1.57 +	/* Clean SysInfo structure */
    1.58 +	SDL_memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS));
    1.59 +	/* Prepare structure to Ask Numer of Audio CDs */
    1.60 +	msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;	/* CD Audio Type */
    1.61 +	msp.pszReturn = SysInfoRet;		/* Return Structure */
    1.62 +	msp.ulRetSize = MCI_CMDRETBUFSIZE; 	/* Size of ret struct */
    1.63 +	if (LOUSHORT(mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID)&msp, 0)) != MCIERR_SUCCESS) {
    1.64 +		return(CD_ERROR);
    1.65 +	}
    1.66 +	SDL_numcds = atoi(SysInfoRet);
    1.67 +	if (SDL_numcds > MAX_DRIVES) {
    1.68 +		SDL_numcds = MAX_DRIVES; /* Limit maximum CD number */
    1.69 +	}
    1.70  
    1.71 -/* Get and Add their system name to the SDL_cdlist */
    1.72 -msp.pszReturn = SysInfoRet;				/* Return Structure */
    1.73 -msp.ulRetSize = MCI_CMDRETBUFSIZE; 			/* Size of ret struct */
    1.74 -msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;		/* CD Audio Type */
    1.75 -for (i=0; i<SDL_numcds; i++)
    1.76 -	{
    1.77 -	msp.ulNumber = i+1;
    1.78 -	mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT,&msp, 0);
    1.79 -	SDL_cdlist[i] = SDL_strdup(SysInfoRet);
    1.80 -	if ( SDL_cdlist[i] == NULL )
    1.81 -		{
    1.82 -		SDL_OutOfMemory();
    1.83 -		return(-1);
    1.84 +	/* Get and Add their system name to the SDL_cdlist */
    1.85 +	msp.pszReturn = SysInfoRet;				/* Return Structure */
    1.86 +	msp.ulRetSize = MCI_CMDRETBUFSIZE; 			/* Size of ret struct */
    1.87 +	msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;		/* CD Audio Type */
    1.88 +	for (i = 0; i < SDL_numcds; i++) {
    1.89 +		msp.ulNumber = i+1;
    1.90 +		mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT,&msp, 0);
    1.91 +		SDL_cdlist[i] = SDL_strdup(SysInfoRet);
    1.92 +		if (SDL_cdlist[i] == NULL) {
    1.93 +			SDL_OutOfMemory();
    1.94 +			return(-1);
    1.95  		}
    1.96  	}
    1.97 -return(0);
    1.98 +	return(0);
    1.99  }
   1.100  
   1.101  /* Return CDAudio System Dependent Device Name - Ready for MCI*/
   1.102  static const char *SDL_SYS_CDName(int drive)
   1.103  {
   1.104 -return(SDL_cdlist[drive]);
   1.105 +	return(SDL_cdlist[drive]);
   1.106  }
   1.107  
   1.108  /* Open CDAudio Device - Ready for MCI */
   1.109  static int SDL_SYS_CDOpen(int drive)
   1.110  {
   1.111 -MCI_OPEN_PARMS	mop;
   1.112 -MCI_SET_PARMS msp;
   1.113 -MCI_GENERIC_PARMS mgp;
   1.114 +	MCI_OPEN_PARMS	mop;
   1.115 +	MCI_SET_PARMS msp;
   1.116 +	MCI_GENERIC_PARMS mgp;
   1.117  
   1.118 -/* Open the device */
   1.119 -mop.hwndCallback = (HWND)NULL;		// None
   1.120 -mop.usDeviceID = (USHORT)NULL;		// Will be returned.
   1.121 -mop.pszDeviceType = (PSZ)SDL_cdlist[drive];		// CDAudio Device
   1.122 -if (LOUSHORT(mciSendCommand(0,MCI_OPEN,MCI_WAIT,&mop, 0)) != MCIERR_SUCCESS) return(CD_ERROR);
   1.123 -/* Set time format */
   1.124 -msp.hwndCallback = (HWND)NULL;		// None
   1.125 -msp.ulTimeFormat = MCI_FORMAT_MSF;	// Minute : Second : Frame structure
   1.126 -msp.ulSpeedFormat = (ULONG)NULL;		// No change
   1.127 -msp.ulAudio = (ULONG)NULL;				// No Channel
   1.128 -msp.ulLevel = (ULONG)NULL;				// No Volume
   1.129 -msp.ulOver = (ULONG)NULL;				// No Delay
   1.130 -msp.ulItem = (ULONG)NULL;				// No item
   1.131 -msp.ulValue = (ULONG)NULL;				// No value for item flag
   1.132 -if (LOUSHORT(mciSendCommand(mop.usDeviceID,MCI_SET,MCI_WAIT | MCI_SET_TIME_FORMAT,&msp, 0)) == MCIERR_SUCCESS) return (mop.usDeviceID);
   1.133 -/* Error setting time format? - Close opened device */
   1.134 -mgp.hwndCallback = (HWND)NULL;		// None
   1.135 -mciSendCommand(mop.usDeviceID,MCI_CLOSE,MCI_WAIT,&mgp, 0);
   1.136 -return(CD_ERROR);
   1.137 +	/* Open the device */
   1.138 +	mop.hwndCallback = NULLHANDLE;	/* None */
   1.139 +	mop.usDeviceID = 0;		/* Will be returned. */
   1.140 +	mop.pszDeviceType = (PSZ)SDL_cdlist[drive];		/* CDAudio Device */
   1.141 +	if (LOUSHORT(mciSendCommand(0,MCI_OPEN,MCI_WAIT,&mop, 0)) != MCIERR_SUCCESS) {
   1.142 +		return(CD_ERROR);
   1.143 +	}
   1.144 +	/* Set time format */
   1.145 +	msp.hwndCallback = NULLHANDLE;		/* None */
   1.146 +	msp.ulTimeFormat = MCI_FORMAT_MSF;	/* Minute : Second : Frame structure */
   1.147 +	msp.ulSpeedFormat = 0;		/* No change */
   1.148 +	msp.ulAudio = 0;		/* No Channel */
   1.149 +	msp.ulLevel = 0;		/* No Volume */
   1.150 +	msp.ulOver = 0;			/* No Delay */
   1.151 +	msp.ulItem = 0;			/* No item */
   1.152 +	msp.ulValue = 0;		/* No value for item flag */
   1.153 +	if (LOUSHORT(mciSendCommand(mop.usDeviceID,MCI_SET,MCI_WAIT | MCI_SET_TIME_FORMAT,&msp, 0)) == MCIERR_SUCCESS) {
   1.154 +		return (mop.usDeviceID);
   1.155 +	}
   1.156 +	/* Error setting time format? - Close opened device */
   1.157 +	mgp.hwndCallback = NULLHANDLE;		/* None */
   1.158 +	mciSendCommand(mop.usDeviceID,MCI_CLOSE,MCI_WAIT,&mgp, 0);
   1.159 +	return(CD_ERROR);
   1.160  }
   1.161  
   1.162  /* Get CD Table Of Contents - Ready for MCI */
   1.163  static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   1.164  {
   1.165 -MCI_TOC_PARMS mtp;
   1.166 -MCI_STATUS_PARMS msp;
   1.167 -MCI_TOC_REC * mtr;
   1.168 -INT i;
   1.169 +	MCI_TOC_PARMS mtp;
   1.170 +	MCI_STATUS_PARMS msp;
   1.171 +	MCI_TOC_REC * mtr;
   1.172 +	INT i;
   1.173  
   1.174 -/* Correction because MCI cannot read TOC while CD is playing (it'll stop!) */
   1.175 -if (cdrom->status == CD_PLAYING || cdrom->status == CD_PAUSED) return 0;
   1.176 +	/* Correction because MCI cannot read TOC while CD is playing (it'll stop!) */
   1.177 +	if (cdrom->status == CD_PLAYING || cdrom->status == CD_PAUSED) {
   1.178 +		return 0;
   1.179 +	}
   1.180  
   1.181 -/* Get Number of Tracks */
   1.182 -msp.hwndCallback = (HWND)NULL; /* None */
   1.183 -msp.ulReturn = (ULONG)NULL; /* We want this information */
   1.184 -msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS;
   1.185 -msp.ulValue = (ULONG)NULL; /* No additional information */
   1.186 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR);
   1.187 -cdrom->numtracks = msp.ulReturn;
   1.188 -if ( cdrom->numtracks > SDL_MAX_TRACKS )
   1.189 -	{
   1.190 -	cdrom->numtracks = SDL_MAX_TRACKS;
   1.191 +	/* Get Number of Tracks */
   1.192 +	msp.hwndCallback = NULLHANDLE; /* None */
   1.193 +	msp.ulReturn = 0; /* We want this information */
   1.194 +	msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS;
   1.195 +	msp.ulValue = 0; /* No additional information */
   1.196 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) {
   1.197 +		return(CD_ERROR);
   1.198  	}
   1.199 -/* Alocate space for TOC data */
   1.200 -mtr = (MCI_TOC_REC *)SDL_malloc(cdrom->numtracks*sizeof(MCI_TOC_REC));
   1.201 -if ( mtr == NULL )
   1.202 -	{
   1.203 -	SDL_OutOfMemory();
   1.204 -	return(-1);
   1.205 +	cdrom->numtracks = msp.ulReturn;
   1.206 +	if (cdrom->numtracks > SDL_MAX_TRACKS) {
   1.207 +		cdrom->numtracks = SDL_MAX_TRACKS;
   1.208  	}
   1.209 -/* Get TOC from CD */
   1.210 -mtp.pBuf = mtr;
   1.211 -mtp.ulBufSize = cdrom->numtracks*sizeof(MCI_TOC_REC);
   1.212 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_GETTOC,MCI_WAIT,&mtp, 0)) != MCIERR_SUCCESS)
   1.213 -	{
   1.214 -	SDL_OutOfMemory();
   1.215 +	/* Alocate space for TOC data */
   1.216 +	mtr = (MCI_TOC_REC *)SDL_malloc(cdrom->numtracks*sizeof(MCI_TOC_REC));
   1.217 +	if (mtr == NULL) {
   1.218 +		SDL_OutOfMemory();
   1.219 +		return(-1);
   1.220 +	}
   1.221 +	/* Get TOC from CD */
   1.222 +	mtp.pBuf = mtr;
   1.223 +	mtp.ulBufSize = cdrom->numtracks*sizeof(MCI_TOC_REC);
   1.224 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_GETTOC,MCI_WAIT,&mtp, 0)) != MCIERR_SUCCESS) {
   1.225 +		SDL_OutOfMemory();
   1.226 +		SDL_free(mtr);
   1.227 +		return(CD_ERROR);
   1.228 +	}
   1.229 +	/* Fill SDL Tracks Structure */
   1.230 +	for (i=0; i<cdrom->numtracks; i++) {
   1.231 +		/* Set Track ID */
   1.232 +		cdrom->track[i].id = (mtr+i)->TrackNum;
   1.233 +		/* Set Track Type */
   1.234 +		msp.hwndCallback = NULLHANDLE; /* None */
   1.235 +		msp.ulReturn = 0; /* We want this information */
   1.236 +		msp.ulItem = MCI_CD_STATUS_TRACK_TYPE;
   1.237 +		msp.ulValue = (ULONG)((mtr+i)->TrackNum); /* Track Number? */
   1.238 +		if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) {
   1.239 +			SDL_free(mtr);
   1.240 +			return (CD_ERROR);
   1.241 +		}
   1.242 +		if (msp.ulReturn==MCI_CD_TRACK_AUDIO) {
   1.243 +			cdrom->track[i].type = SDL_AUDIO_TRACK;
   1.244 +		}
   1.245 +		else {
   1.246 +			cdrom->track[i].type = SDL_DATA_TRACK;
   1.247 +		}
   1.248 +		/* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */
   1.249 +		cdrom->track[i].length = FRAMESFROMMM((mtr+i)->ulEndAddr - (mtr+i)->ulStartAddr);
   1.250 +		/* Set Track Offset */
   1.251 +		cdrom->track[i].offset = FRAMESFROMMM((mtr+i)->ulStartAddr);
   1.252 +	}
   1.253  	SDL_free(mtr);
   1.254 -	return(CD_ERROR);
   1.255 -	}
   1.256 -/* Fill SDL Tracks Structure */
   1.257 -for (i=0; i<cdrom->numtracks; i++)
   1.258 -	{
   1.259 -	/* Set Track ID */
   1.260 -	cdrom->track[i].id = (mtr+i)->TrackNum;
   1.261 -	/* Set Track Type */
   1.262 -	msp.hwndCallback = (HWND)NULL; /* None */
   1.263 -	msp.ulReturn = (ULONG)NULL; /* We want this information */
   1.264 -	msp.ulItem = MCI_CD_STATUS_TRACK_TYPE;
   1.265 -	msp.ulValue = (ULONG)((mtr+i)->TrackNum); /* Track Number? */
   1.266 -	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS)
   1.267 -		{
   1.268 -		SDL_free(mtr);
   1.269 -		return (CD_ERROR);
   1.270 -		}
   1.271 -	if (msp.ulReturn==MCI_CD_TRACK_AUDIO) cdrom->track[i].type = SDL_AUDIO_TRACK;
   1.272 -	else cdrom->track[i].type = SDL_DATA_TRACK;
   1.273 -	/* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */
   1.274 -	cdrom->track[i].length = FRAMESFROMMM((mtr+i)->ulEndAddr - (mtr+i)->ulStartAddr);
   1.275 -	/* Set Track Offset */
   1.276 -	cdrom->track[i].offset = FRAMESFROMMM((mtr+i)->ulStartAddr);
   1.277 -	}
   1.278 -SDL_free(mtr);
   1.279 -return(0);
   1.280 +	return(0);
   1.281  }
   1.282  
   1.283 -
   1.284  /* Get CD-ROM status - Ready for MCI */
   1.285  static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
   1.286  {
   1.287 -CDstatus status;
   1.288 -MCI_STATUS_PARMS msp;
   1.289 +	CDstatus status;
   1.290 +	MCI_STATUS_PARMS msp;
   1.291  
   1.292 -/* Get Status from MCI */
   1.293 -msp.hwndCallback = (HWND)NULL; /* None */
   1.294 -msp.ulReturn = (ULONG)NULL; /* We want this information */
   1.295 -msp.ulItem = MCI_STATUS_MODE;
   1.296 -msp.ulValue = (ULONG)NULL; /* No additional information */
   1.297 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) status = CD_ERROR;
   1.298 -else
   1.299 -	{
   1.300 -	switch(msp.ulReturn)
   1.301 -		{
   1.302 +	/* Get Status from MCI */
   1.303 +	msp.hwndCallback = NULLHANDLE; /* None */
   1.304 +	msp.ulReturn = 0; /* We want this information */
   1.305 +	msp.ulItem = MCI_STATUS_MODE;
   1.306 +	msp.ulValue = 0; /* No additional information */
   1.307 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) {
   1.308 +		status = CD_ERROR;
   1.309 +	}
   1.310 +	else {
   1.311 +		switch(msp.ulReturn) {
   1.312  		case	MCI_MODE_NOT_READY:
   1.313  			status = CD_TRAYEMPTY;
   1.314  			break;
   1.315 @@ -243,150 +251,156 @@
   1.316  		}
   1.317  	}
   1.318  
   1.319 -/* Determine position */
   1.320 -if (position != NULL) /* The SDL $&$&%# CDROM call sends NULL pointer here! */
   1.321 -	{
   1.322 -		if ((status == CD_PLAYING) || (status == CD_PAUSED))
   1.323 -		{
   1.324 -		/* Get Position */
   1.325 -		msp.hwndCallback = (HWND)NULL; /* None */
   1.326 -		msp.ulReturn = (ULONG)NULL; /* We want this information */
   1.327 -		msp.ulItem = MCI_STATUS_POSITION;
   1.328 -		msp.ulValue = (ULONG)NULL; /* No additiona info */
   1.329 -		if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return (CD_ERROR);
   1.330 -		/* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */
   1.331 -		*position = MSF_TO_FRAMES(MSF_MINUTE(msp.ulReturn),MSF_SECOND(msp.ulReturn),MSF_FRAME(msp.ulReturn));
   1.332 +	/* Determine position */
   1.333 +	if (position != NULL) { /* The SDL $&$&%# CDROM call sends NULL pointer here! */
   1.334 +		if ((status == CD_PLAYING) || (status == CD_PAUSED)) {
   1.335 +			/* Get Position */
   1.336 +			msp.hwndCallback = NULLHANDLE; /* None */
   1.337 +			msp.ulReturn = 0; /* We want this information */
   1.338 +			msp.ulItem = MCI_STATUS_POSITION;
   1.339 +			msp.ulValue = 0; /* No additiona info */
   1.340 +			if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) {
   1.341 +				return (CD_ERROR);
   1.342 +			}
   1.343 +			/* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */
   1.344 +			*position = MSF_TO_FRAMES(MSF_MINUTE(msp.ulReturn),MSF_SECOND(msp.ulReturn),MSF_FRAME(msp.ulReturn));
   1.345  		}
   1.346 -	else *position = 0;
   1.347 +		else {
   1.348 +			*position = 0;
   1.349 +		}
   1.350  	}
   1.351 -return(status);
   1.352 +	return(status);
   1.353  }
   1.354  
   1.355  /* Start play - Ready for MCI */
   1.356  static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   1.357  {
   1.358 -MCI_GENERIC_PARMS mgp;
   1.359 -MCI_STATUS_PARMS msp;
   1.360 -MCI_PLAY_PARMS	mpp;
   1.361 -ULONG min,sec,frm;
   1.362 +	MCI_GENERIC_PARMS mgp;
   1.363 +	MCI_STATUS_PARMS msp;
   1.364 +	MCI_PLAY_PARMS	mpp;
   1.365 +	ULONG min,sec,frm;
   1.366  
   1.367 -/* Start MSF */
   1.368 -FRAMES_TO_MSF(start, &min, &sec, &frm);
   1.369 -MSF_MINUTE(mpp.ulFrom) = min;
   1.370 -MSF_SECOND(mpp.ulFrom) = sec;
   1.371 -MSF_FRAME(mpp.ulFrom) = frm;
   1.372 -/* End MSF */
   1.373 -FRAMES_TO_MSF(start+length, &min, &sec, &frm);
   1.374 -MSF_MINUTE(mpp.ulTo) = min;
   1.375 -MSF_SECOND(mpp.ulTo) = sec;
   1.376 -MSF_FRAME(mpp.ulTo) = frm;
   1.377 +	/* Start MSF */
   1.378 +	FRAMES_TO_MSF(start, &min, &sec, &frm);
   1.379 +	MSF_MINUTE(mpp.ulFrom) = min;
   1.380 +	MSF_SECOND(mpp.ulFrom) = sec;
   1.381 +	MSF_FRAME(mpp.ulFrom) = frm;
   1.382 +	/* End MSF */
   1.383 +	FRAMES_TO_MSF(start+length, &min, &sec, &frm);
   1.384 +	MSF_MINUTE(mpp.ulTo) = min;
   1.385 +	MSF_SECOND(mpp.ulTo) = sec;
   1.386 +	MSF_FRAME(mpp.ulTo) = frm;
   1.387  #ifdef DEBUG_CDROM
   1.388  	fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
   1.389  	playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
   1.390  	playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
   1.391  #endif
   1.392 -/* Verifies if it is paused first... and if it is, unpause before stopping it. */
   1.393 -msp.hwndCallback = (HWND)NULL; /* None */
   1.394 -msp.ulReturn = (ULONG)NULL; /* We want this information */
   1.395 -msp.ulItem = MCI_STATUS_MODE;
   1.396 -msp.ulValue = (ULONG)NULL; /* No additional information */
   1.397 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS)
   1.398 -	{
   1.399 -	if (msp.ulReturn == MCI_MODE_PAUSE)
   1.400 -		{
   1.401 -		mgp.hwndCallback = (HWND)NULL;		// None
   1.402 -		mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0);
   1.403 +	/* Verifies if it is paused first... and if it is, unpause before stopping it. */
   1.404 +	msp.hwndCallback = NULLHANDLE; /* None */
   1.405 +	msp.ulReturn = 0; /* We want this information */
   1.406 +	msp.ulItem = MCI_STATUS_MODE;
   1.407 +	msp.ulValue = 0; /* No additional information */
   1.408 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS) {
   1.409 +		if (msp.ulReturn == MCI_MODE_PAUSE) {
   1.410 +			mgp.hwndCallback = NULLHANDLE;	/* None */
   1.411 +			mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0);
   1.412  		}
   1.413  	}
   1.414 -/* Now play it. */
   1.415 -mpp.hwndCallback = (HWND)NULL;		// We do not want the info. temp
   1.416 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PLAY,MCI_FROM | MCI_TO,&mpp, 0)) == MCIERR_SUCCESS) return 0;
   1.417 -return (CD_ERROR);
   1.418 +	/* Now play it. */
   1.419 +	mpp.hwndCallback = NULLHANDLE;		/* We do not want the info. temp */
   1.420 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PLAY,MCI_FROM | MCI_TO,&mpp, 0)) == MCIERR_SUCCESS) {
   1.421 +		return 0;
   1.422 +	}
   1.423 +	return (CD_ERROR);
   1.424  }
   1.425  
   1.426  /* Pause play - Ready for MCI */
   1.427  static int SDL_SYS_CDPause(SDL_CD *cdrom)
   1.428  {
   1.429 -MCI_GENERIC_PARMS mgp;
   1.430 +	MCI_GENERIC_PARMS mgp;
   1.431  
   1.432 -mgp.hwndCallback = (HWND)NULL;		// None
   1.433 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PAUSE,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0;
   1.434 -return(CD_ERROR);
   1.435 +	mgp.hwndCallback = NULLHANDLE;		/* None */
   1.436 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PAUSE,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) {
   1.437 +		return 0;
   1.438 +	}
   1.439 +	return(CD_ERROR);
   1.440  }
   1.441  
   1.442  /* Resume play - Ready for MCI */
   1.443  static int SDL_SYS_CDResume(SDL_CD *cdrom)
   1.444  {
   1.445 -MCI_GENERIC_PARMS mgp;
   1.446 +	MCI_GENERIC_PARMS mgp;
   1.447  
   1.448 -mgp.hwndCallback = (HWND)NULL;		// None
   1.449 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_RESUME,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0;
   1.450 -return(CD_ERROR);
   1.451 +	mgp.hwndCallback = NULLHANDLE;		/* None */
   1.452 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_RESUME,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) {
   1.453 +		return 0;
   1.454 +	}
   1.455 +	return(CD_ERROR);
   1.456  }
   1.457  
   1.458  /* Stop play - Ready for MCI */
   1.459  static int SDL_SYS_CDStop(SDL_CD *cdrom)
   1.460  {
   1.461 -MCI_GENERIC_PARMS mgp;
   1.462 -MCI_STATUS_PARMS msp;
   1.463 +	MCI_GENERIC_PARMS mgp;
   1.464 +	MCI_STATUS_PARMS msp;
   1.465  
   1.466 -/* Verifies if it is paused first... and if it is, unpause before stopping it. */
   1.467 -msp.hwndCallback = (HWND)NULL; /* None */
   1.468 -msp.ulReturn = (ULONG)NULL; /* We want this information */
   1.469 -msp.ulItem = MCI_STATUS_MODE;
   1.470 -msp.ulValue = (ULONG)NULL; /* No additional information */
   1.471 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS)
   1.472 -	{
   1.473 -	if (msp.ulReturn == MCI_MODE_PAUSE)
   1.474 -		{
   1.475 -		mgp.hwndCallback = (HWND)NULL;		// None
   1.476 -		mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0);
   1.477 +	/* Verifies if it is paused first... and if it is, unpause before stopping it. */
   1.478 +	msp.hwndCallback = NULLHANDLE; /* None */
   1.479 +	msp.ulReturn = 0; /* We want this information */
   1.480 +	msp.ulItem = MCI_STATUS_MODE;
   1.481 +	msp.ulValue = 0; /* No additional information */
   1.482 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS) {
   1.483 +		if (msp.ulReturn == MCI_MODE_PAUSE) {
   1.484 +			mgp.hwndCallback = NULLHANDLE;	/* None */
   1.485 +			mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0);
   1.486  		}
   1.487  	}
   1.488 -/* Now stops the media */
   1.489 -mgp.hwndCallback = (HWND)NULL;		// None
   1.490 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STOP,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0;
   1.491 -return(CD_ERROR);
   1.492 +	/* Now stops the media */
   1.493 +	mgp.hwndCallback = NULLHANDLE;		/* None */
   1.494 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STOP,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) {
   1.495 +		return 0;
   1.496 +	}
   1.497 +	return(CD_ERROR);
   1.498  }
   1.499  
   1.500  /* Eject the CD-ROM - Ready for MCI */
   1.501  static int SDL_SYS_CDEject(SDL_CD *cdrom)
   1.502  {
   1.503 -MCI_SET_PARMS msp;
   1.504 +	MCI_SET_PARMS msp;
   1.505  
   1.506 -msp.hwndCallback = (HWND)NULL;		// None
   1.507 -msp.ulTimeFormat = (ULONG)NULL;		// No change
   1.508 -msp.ulSpeedFormat = (ULONG)NULL;		// No change
   1.509 -msp.ulAudio = (ULONG)NULL;				// No Channel
   1.510 -msp.ulLevel = (ULONG)NULL;				// No Volume
   1.511 -msp.ulOver = (ULONG)NULL;				// No Delay
   1.512 -msp.ulItem = (ULONG)NULL;					// No item
   1.513 -msp.ulValue = (ULONG)NULL;					// No value for item flag
   1.514 -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_SET,MCI_WAIT | MCI_SET_DOOR_OPEN,&msp, 0)) == MCIERR_SUCCESS) return 0;
   1.515 -return(CD_ERROR);
   1.516 +	msp.hwndCallback = NULLHANDLE;	/* None */
   1.517 +	msp.ulTimeFormat = 0;		/* No change */
   1.518 +	msp.ulSpeedFormat = 0;		/* No change */
   1.519 +	msp.ulAudio = 0;		/* No Channel */
   1.520 +	msp.ulLevel = 0;		/* No Volume */
   1.521 +	msp.ulOver = 0;			/* No Delay */
   1.522 +	msp.ulItem = 0;			/* No item */
   1.523 +	msp.ulValue = 0;		/* No value for item flag */
   1.524 +	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_SET,MCI_WAIT | MCI_SET_DOOR_OPEN,&msp, 0)) == MCIERR_SUCCESS) {
   1.525 +		return 0;
   1.526 +	}
   1.527 +	return(CD_ERROR);
   1.528  }
   1.529  
   1.530  /* Close the CD-ROM handle - Ready for MCI */
   1.531  static void SDL_SYS_CDClose(SDL_CD *cdrom)
   1.532  {
   1.533 -MCI_GENERIC_PARMS mgp;
   1.534 +	MCI_GENERIC_PARMS mgp;
   1.535  
   1.536 -mgp.hwndCallback = (HWND)NULL;		// None
   1.537 -mciSendCommand(cdrom->id,MCI_CLOSE,MCI_WAIT,&mgp, 0);
   1.538 +	mgp.hwndCallback = NULLHANDLE;		/* None */
   1.539 +	mciSendCommand(cdrom->id,MCI_CLOSE,MCI_WAIT,&mgp, 0);
   1.540  }
   1.541  
   1.542  /* Finalize CDROM Subsystem - Ready for MCI */
   1.543  void SDL_SYS_CDQuit(void)
   1.544  {
   1.545 -int i;
   1.546 +	int i;
   1.547  
   1.548 -if ( SDL_numcds > 0 )
   1.549 -	{
   1.550 -	for ( i=0; i<SDL_numcds; ++i )
   1.551 -		{
   1.552 -		SDL_free(SDL_cdlist[i]);
   1.553 +	if (SDL_numcds > 0) {
   1.554 +		for (i = 0; i < SDL_numcds; ++i) {
   1.555 +			SDL_free(SDL_cdlist[i]);
   1.556  		}
   1.557 -	SDL_numcds = 0;
   1.558 +		SDL_numcds = 0;
   1.559  	}
   1.560  }
   1.561