⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdrom.cpp

📁 CD工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//********************************************************
//
//		CDRom::IsItPlaying  :-
//
//		determine if the drive is playing by sampling the
//		q-channel and the audio pause status sub-fn.
//
//********************************************************/

Boolean	CDRom::IsItPlaying( void )
{

	DWORD				detail, itTime, etTime, idTime, edTime ;
	BYTE				iSec, eSec ;
	struct dostime_t	iTime, eTime ;

	//	sample the q-channel for up to a couple seconds, to determine if
	//	something is happening....
	GetQInfo( ( DWORD far * ) &detail, ( DWORD far * ) &itTime,
			  ( DWORD far * ) &idTime ) ;
	_dos_gettime( &iTime ) ;
	while ( 1 ) {
		_dos_gettime( &eTime ) ;
		if ( abs( eTime.second - iTime.second ) > 2 )
			break ;
	}

	GetQInfo( ( DWORD far * ) &detail, ( DWORD far * ) &etTime,
			  ( DWORD far * ) &edTime ) ;
	iSec = HIBYTE( LOWORD( itTime ) ) ;
	eSec = HIBYTE( LOWORD( etTime ) ) ;

	//	if the sampled values are different, then the disk is playing....
	if ( iSec != eSec )
		return ( 1 ) ;
	return( 0 ) ;

}


//********************************************************
//
//		CDRom::GetPlayStatus  :-
//
//		gets the current play status (is the audio pgm
//		paused and the start/end address of the audio pgm.)
//		returns the desired info only if the corresponding
//		ptrs are non-null....
//
//********************************************************/

void	CDRom::GetPlayStatus( WORD far * paused, DWORD far * stAddr,
							  DWORD far * endAddr )
{

	PlayStatusCmd	plStatus ;
	lastStatus = cmdInterface.GetPlayStatus(
								( struct PlayStatusCmd far * ) &plStatus ) ;

	if ( paused ) {
		//	simplify it for 'em
		if ( plStatus.statusBits & 1 )
			*paused = 1 ;
		else *paused = 0 ;
	}
	if ( stAddr )
		*stAddr = plStatus.startAddress ;
	if ( endAddr )
		*endAddr = plStatus.endAddress ;

	return ;

}


//********************************************************
//
//		CDRom::PrintPlayStatus  :-
//
//		a diagnostic for testing the GetPlayStatus() mbr
//		fn....
//
//********************************************************/

void	CDRom::PrintPlayStatus( DWORD stAddr, DWORD endAddr )
{
	DisplayAddress( "Start Address == ", stAddr ) ;
	printf( "\n" ) ;
	DisplayAddress( "End Address == ", endAddr ) ;
	printf( "\n" ) ;
	return ;
}


//********************************************************
//
//		CDRom::LockDoor  :-
//
//		if the drive supports the fn, lock the door.
//		no check....
//
//********************************************************/

void		CDRom::LockDoor( int lock )
{

	lastStatus = cmdInterface.LockDoor( lock ) ;
	return ;

}


//********************************************************
//
//		CDRom::CloseTray  :-
//
//		do the opposite of Eject, that is if the drive
//		supports the fn.  no check....
//
//********************************************************/

void	CDRom::CloseTray( void )
{

	lastStatus = cmdInterface.CloseTray() ;
	return ;

}


//********************************************************
//
//		CDRom::Eject  :-
//
//		eject the disk (obviously....)
//
//********************************************************/

void	CDRom::Eject( void )
{

	lastStatus = cmdInterface.EjectDisk() ;
	return ;

}


//********************************************************
//
//		CDRom::Reset  :-
//
//		tell the cdrom driver to reset itself and therefore
//		stop any operation in progress....
//
//********************************************************/

void	CDRom::Reset( void )
{

	lastStatus = cmdInterface.ResetDisk() ;
	return ;

}


//********************************************************
//
//		CDRom::Stop  :-
//
//		stop/resume the current audio pgm immdiately.
//
//********************************************************/

void	CDRom::Stop( Boolean fStop )
{

	//	unnecessary to save the status for stop and probably
	//  the same for pause, but do it for the sake of consistency....
	lastStatus = cmdInterface.Stop( fStop ) ;
	return ;

}


//********************************************************
//
//		CDRom::PlayDisk  :-
//
//		play an audio pgm starting at a certain track.
//		must have called CDRom::ReadTOC() prior to using
//		this member fn....
//
//********************************************************/

int		CDRom::PlayDisk( int trackNumber )
{

	TrackInfoCmd	* ptr ;
	DWORD			num ;
	Str80			theBuff ;
	int				mins, secs ;

	if ( ( trackNumber < diskInfo.lowTrackNumber ) || 
		 ( trackNumber > diskInfo.highTrackNumber ) ) {
#if		! defined( _WINDOWS )
		printf( "%%%%%%  Invalid track number: %d.\n"
				"This disk has track numbers between %d and %d.\n",
				trackNumber, diskInfo.lowTrackNumber,
				diskInfo.highTrackNumber ) ;
#endif 
		return( 1 ) ;
	}

#if		! defined( _WINDOWS )
	printf( "Playing from " ) ;
	FormatDuration( trackNumber, TRACK_TIME | REM_DISK_TIME, theBuff ) ;
	printf( "%s\n", theBuff ) ;
#endif

	//	what's bizarre here is the addressing mode we request is
	//	supposedly red-book, but the conversion to hsg is real.  tried
	//	simply changing the addressing mode to ADDR_HSG, which failed
	//	completely.  i can only imagine that true hsg-formatted disks have
	//	a different geometry from redbook disks, but mscdex only supports
	//	one true addressing mode and the addressing mode byte is simply
	//	a way of indicating the consumer's agreement that the media in
	//	the drive actually conforms red-book geometry....
	num = RedToHsg( diskInfo.leadOut ) -
		  RedToHsg( trackInfo[ trackNumber ].startAddress ) ;
	return( Play( trackInfo[ trackNumber ].startAddress, num, ADDR_RED ) ) ;

}


//********************************************************
//
//		CDRom::PlayTrack  :-
//
//		play a sgl track, probably as part of a complex
//		audio pgm....
//
//********************************************************/

int		CDRom::PlayTrack( int trackNbr )
{

	DWORD		num ;
	Str80		theBuff ;

	if ( ( trackNbr < diskInfo.lowTrackNumber ) || 
		 ( trackNbr > diskInfo.highTrackNumber ) ) {
#if		! defined( _WINDOWS )
		printf( "%%%%%%  Invalid track number: %d.\n"
				"This disk has track numbers between %d and %d.\n",
				trackNbr, diskInfo.lowTrackNumber,
				diskInfo.highTrackNumber ) ;
#endif 
		return( 1 ) ;
	}

#if		! defined( _WINDOWS )
	printf( "Playing Sgl " ) ;
	FormatDuration( trackNbr, TRACK_TIME, theBuff ) ;
	printf( "%s\n", theBuff ) ;
#endif

	num = RedToHsg( trackInfo[ trackNbr + 1 ].startAddress ) -
		  RedToHsg( trackInfo[ trackNbr ].startAddress ) ;
	return( Play( trackInfo[ trackNbr ].startAddress, num, ADDR_RED ) ) ;

}


//********************************************************
//
//		CDRom::PlayPreview  :-
//
//		play a preview of the entire disk, by sampling the
//		1st 10 seconds of each track on the disk....
//
//********************************************************/

void	CDRom::PlayPreview( void )
{

	int	nTracks = diskInfo.highTrackNumber - diskInfo.lowTrackNumber + 1, i,
				prlgth, prmins, prsecs ;
	DWORD		num, details, tTime, dTime ;
	BYTE		secs, lsecs ;

	//	do n seconds worth of music for each track on the disk, but
	//	setup n + 1 secs worth and clip it usg GetQInfo(), where n
	//	is determined by the _PRVW_LGTH symbol....
	for ( i = diskInfo.lowTrackNumber ; nTracks > 0 ; nTracks--, i++ ) {
		//	hang in a tight loop until the track is done
		lsecs = secs = 0 ;

		//	must make sure that the track time is more than the preview lgth
		//	(which must be less than a minute.)  if the preview lgth >
		//	the current track's duration, then reduce the lgth of the preview
		prlgth = _PRVW_LGTH ;
		ComputeDuration( i, TRACK_TIME, ( int far * ) &prmins,
						 ( int far * ) &prsecs ) ;
		prmins = prmins * 60 + prsecs ;
		if ( prmins > ( prlgth + 1 ) )
			num = ( prlgth + 1 ) * 75L ;
		else {
			prlgth = prmins - 2 ;
			num = ( prlgth + 1 ) * 75L ;
		}
		Play( trackInfo[ i ].startAddress, num, ADDR_RED ) ;

		//	any key will abort the operation....
		while ( secs != prlgth ) {
			GetQInfo( ( DWORD far * ) &details, ( DWORD far * ) &tTime,
					  ( DWORD far * ) &dTime ) ;
			secs = HIBYTE( LOWORD( tTime ) ) ;
#if		! defined( _WINDOWS )
			if ( lsecs != secs ) {
				printf( "Previewing TN

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -