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

📄 madevdrv.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	else							count = 2;

	for ( i = 0; i < count; i++ )
	{
		packet_buffer[i] = (UINT8)( (address >> (7*i)) & 0x7F );
	}
	packet_buffer[i] = (UINT8)( (address >> (7*i)) | 0x80 );
	
	count++;
	packet_buffer[count] = (UINT8)( 0x80 | buffer_address );

	result = machdep_WaitImmediateFifoEmpty();
	if ( result < MASMW_SUCCESS )
	{
		machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
		MADEVDRV_DBGMSG(("MelDrv:machdep_WaitImmediateFifoEmpty() error!"));
		return result;
	}

	for ( i = 0; i <= count; i++ )
	{
		machdep_WriteDataReg( packet_buffer[i] );
	}

	valid_rx = (UINT8)(1 << (MA_VALID_RX + buffer_address));
	
	result = machdep_WaitValidData( valid_rx );
	if ( result < MASMW_SUCCESS )
	{
		machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
		MADEVDRV_DBGMSG(("MelDrv:machdep_WaitValidData() error!"));
		return result;
	}

	machdep_WriteStatusFlagReg( (UINT8)(valid_rx | (buffer_address + 1)) );
	
	read_data = machdep_ReadDataReg();

	machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
	return (SINT32)read_data;
}
/****************************************************************************
 *	MaDevDrv_SendDirectRamData
 *
 *	Description:
 *			write data to internal RAM.
 *	Arguments:
 *			address			internal RAM address
 *			data_type		type of data
 *			data_ptr		pointer ot the write byte data to internal RAM
 *			data_size		size of write byte data to internal RAM
 *	Return:
 *			MASMW_SUCCESS(0)
 *
 ****************************************************************************/
SINT32 MaDevDrv_SendDirectRamData
(
	UINT32	address,					/* address of internal ram */
	UINT8	data_type,					/* type of data */
	const UINT8 * data_ptr,				/* pointer to data */
	UINT32	data_size					/* size of data */
)
{
	UINT32	i, j;
	UINT8	packet_buffer[3+2];
	UINT32	count;
	UINT32	write_size;
	UINT8	write_data;
	UINT8	temp = 0;
	SINT32	result;

#if MASMW_DEBUG
	result = madebug_SendDirectRamData( address, data_type, data_ptr, data_size );
	if ( result < MASMW_SUCCESS ) return result;
#endif

	MADEVDRV_DBGMSG(("    MaDevDrv_SendDirectRamData: adrs=%04lX type=%d ptr=%p size=%ld\n", address, data_type, data_ptr, data_size));

	if ( data_size == 0 ) return MASMW_SUCCESS;

	machdep_WriteStatusFlagReg( MA_IMMEDIATE_WRITE_REG );
	

	packet_buffer[0] = (UINT8)( (address >>  0 ) & 0x7F );
	packet_buffer[1] = (UINT8)( (address >>  7 ) & 0x7F );
	packet_buffer[2] = (UINT8)( (address >> 14 ) | 0x80 );

	if ( data_type == 0 )
	{
		write_size = data_size;
	}
	else
	{
		write_size = (data_size / 8) * 7;
		if ( data_size % 8 != 0 )
			write_size = (UINT32)( write_size + (data_size % 8 - 1) );
	}

	if	( write_size < 0x0080 )
	{
		packet_buffer[3] = (UINT8)( (write_size >> 0) | 0x80 );
		count = 4;
	}
	else
	{
		packet_buffer[3] = (UINT8)( (write_size >> 0) & 0x7F );
		packet_buffer[4] = (UINT8)( (write_size >> 7) | 0x80 );
		count = 5;
	}

	result = machdep_WaitImmediateFifoEmpty();
	if ( result < MASMW_SUCCESS )
	{
		machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
		return result;
	}
	
	for ( i = 0; i < count; i++ )
	{
		machdep_WriteDataReg( packet_buffer[i] );
	}

	if ( data_type == 0 )
	{
#if 1
		i = data_size/64;
		while ( (i--) != 0 )
#else
		for ( i = 0; i < data_size/64; i++ )
#endif
		{
			result = machdep_WaitImmediateFifoEmpty();
			if ( result < MASMW_SUCCESS )
			{
				machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
				return result;
			}
#if 1
			j = 64;
			while ( (j--) != 0 )
#else
			for ( j = 0; j < 64; j++ )
#endif
			{
				machdep_WriteDataReg( *data_ptr++ );
			}
		}

		if ( (data_size%64) != 0 )
		{
			result = machdep_WaitImmediateFifoEmpty();
			if ( result < MASMW_SUCCESS )
			{
				machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
				return result;
			}
#if 1
			j = data_size%64;
			while ( (j--) != 0 )
#else
			for ( j = 0; j < (data_size%64); j++ )
#endif
			{
				machdep_WriteDataReg( *data_ptr++ );
			}
		}
	}
	else
	{
		for ( i = 0; i < data_size; i++ )
		{
			if ( (i & 0xFFFFFFC0) == 0 )
			{
				result = machdep_WaitImmediateFifoEmpty();
				if ( result < MASMW_SUCCESS )
				{
					machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
					return result;
				}
			}

			if ( ( i % 8 ) == 0 )
			{
				temp = *data_ptr++;
			}
			else
			{
				write_data = *data_ptr++;
				write_data |= (UINT8)( ( temp << (i % 8) ) & 0x80 );

				machdep_WriteDataReg( write_data );
			}
		}
	}

	machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );

	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaDevDrv_SendDirectRamVal
 *
 *	Description:
 *			
 *	Arguments:
 *			address		internal RAM address
 *			size		size of write byte data to internal RAM
 *			val			write byte data
 *	Return:
 *			0			success
 *
 ****************************************************************************/
SINT32 MaDevDrv_SendDirectRamVal
(
	UINT32	address,					/* address of internal ram */
	UINT32	data_size,					/* size of data */
	UINT8	val							/* write value */
)
{
	UINT32	i, j;						/* loop counter */
	UINT32	count;						/* count of packet */
	SINT32	result;						/* result of function */
	UINT8	packet_buffer[3+2];			/* packet buffer */

#if MASMW_DEBUG
	result = madebug_SendDirectRamVal( address, data_size, val );
	if ( result < MASMW_SUCCESS ) return result;
#endif

	MADEVDRV_DBGMSG(("    MaDevDrv_SendDirectRamVal: adrs=%04lX size=%ld val=%02X\n", address, data_size, val));

	if ( data_size == 0 ) return MASMW_SUCCESS;

	machdep_WriteStatusFlagReg( MA_IMMEDIATE_WRITE_REG );
	

	packet_buffer[0] = (UINT8)( (address >>  0 ) & 0x7F );
	packet_buffer[1] = (UINT8)( (address >>  7 ) & 0x7F );
	packet_buffer[2] = (UINT8)( (address >> 14 ) | 0x80 );

	if	( data_size < 0x0080 )
	{
		packet_buffer[3] = (UINT8)( (data_size >> 0) | 0x80 );
		count = 4;
	}
	else
	{
		packet_buffer[3] = (UINT8)( (data_size >> 0) & 0x7F );
		packet_buffer[4] = (UINT8)( (data_size >> 7) | 0x80 );
		count = 5;
	}


	result = machdep_WaitImmediateFifoEmpty();
	if ( result < MASMW_SUCCESS )
	{
		machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
		return result;
	}

	for ( i = 0; i < count; i++ )
	{
		machdep_WriteDataReg( packet_buffer[i] );
	}

#if 1
	i = data_size/64;
	while ( (i--) != 0 )
#else
	for ( i = 0; i < (data_size/64); i++ )
#endif
	{
		result = machdep_WaitImmediateFifoEmpty();
		if ( result < MASMW_SUCCESS )
		{
			machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
			return result;
		}

#if 1
		j = 64;
		while ( (j--) != 0 )
#else
		for ( j = 0; j < 64; j++ )
#endif
		{
			machdep_WriteDataReg( val );
		}
	}

	if ( (data_size%64) != 0 )
	{
		result = machdep_WaitImmediateFifoEmpty();
		if ( result < MASMW_SUCCESS )
		{
			machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
			return result;
		}
#if 1
		j = data_size%64;
		while ( (j--) != 0 )
#else
		for ( j = 0; j < (data_size%64); j++ )
#endif
		{
			machdep_WriteDataReg( val );
		}
	}

	machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );

	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaDevDrv_StreamSetup
 *
 *	Description:
 *			Setup wave data to the stream audio.
 *	Arguments:
 *			sa_id	stream audio slot number
 *	Return:
 *			0		success
 *			< 0		error code
 *
 ****************************************************************************/
static SINT32 MaDevDrv_StreamSetup
(
	UINT8	sa_id						/* stream audio number */
)
{
	UINT8	zero_val;
	UINT8	format;
	UINT8 *	wave_ptr;
	UINT32	wave_size;
	UINT32	ram_adrs;
	SINT32	result;

	format    = cinfo_ptr->streaminfo.format[sa_id];
	wave_ptr  = cinfo_ptr->streaminfo.wave_ptr[sa_id];
	wave_size = cinfo_ptr->streaminfo.wave_size[sa_id];

	ram_adrs = (UINT32)(MA_RAM_START_ADDRESS + (MA_RAM_BLOCK_SIZE * (7-sa_id)) + 0x20);

	if ( wave_size == MA_WAVE_SIZE )
		cinfo_ptr->streaminfo.end_point[sa_id] = (UINT16)wave_size;
	else
		if ( format < 2 )
			cinfo_ptr->streaminfo.end_point[sa_id] = (UINT16)(wave_size % MA_WAVE_SIZE);
		else
			cinfo_ptr->streaminfo.end_point[sa_id] =
				(UINT16)( (wave_size + (wave_size / MA_WAVE_SIZE) ) % MA_WAVE_SIZE );

	if ( wave_size > MA_WAVE_SIZE )
	{
		result = MaDevDrv_SendDirectRamData( ram_adrs, 0, wave_ptr, MA_WAVE_SIZE );
		if ( result != MASMW_SUCCESS ) return result;
		
		if ( format < 2 )					/* ADPCM */
		{
			wave_size -= MA_WAVE_SIZE;
			wave_ptr  += MA_WAVE_SIZE;
		}
		else								/* PCM */
		{
			wave_size -= (MA_WAVE_SIZE - 1);
			wave_ptr  += (MA_WAVE_SIZE - 1);
		}
	}
	else
	{
		result = MaDevDrv_SendDirectRamData( ram_adrs, 0, wave_ptr, wave_size );
		if ( result != MASMW_SUCCESS ) return result;
		
		if ( format < 2 )					/* ADPCM */
		{
			zero_val = (UINT8)0x80;
		}
		else								/* PCM */
		{
			zero_val = (UINT8)( ( format == 2 ) ? 0x80 : 0x00 );
		}
	
		MaDevDrv_SendDirectRamVal( ram_adrs + wave_size, MA_WAVE_SIZE - wave_size, zero_val );
		if ( result != MASMW_SUCCESS) return result;
	
		wave_ptr  += wave_size;
		wave_size -= wave_size;
	}

	cinfo_ptr->streaminfo.state[sa_id]	   = 2;
	cinfo_ptr->streaminfo.wave_ptr[sa_id]  = wave_ptr;
	cinfo_ptr->streaminfo.wave_size[sa_id] = wave_size;

	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaDevDrv_StreamUpdate
 *
 *	Description:
 *			Update wave data to the stream audio.
 *	Arguments:
 *			sa_id		stream audio slot number
 *	Return:
 *			0		success
 *			< 0		error code
 *
 ****************************************************************************/
static SINT32 MaDevDrv_StreamUpdate
(
	UINT8	sa_id						/* stream audio number */
)
{
	UINT8	packet[6];
	UINT16	write_block;
	UINT16	read_block;
	UINT32	ram_size;
	UINT8	format;
	UINT8 *	wave_ptr;
	UINT32	wave_size;
	SINT32	result = MASMW_SUCCESS;
	UINT32	ram_adrs;
	UINT16	pg_point;
	UINT16	end_point;
	UINT16	prv_point;
	UINT8	zero_val = 0x00;
	UINT32	reg_index;
	UINT8	ch;

	write_block = cinfo_ptr->streaminfo.write_block[sa_id];
	read_block  = cinfo_ptr->streaminfo.read_block[sa_id];
	format 		= cinfo_ptr->streaminfo.format[sa_id];

	reg_index = MA_NOP_2;
	packet[0] = (UINT8)(  reg_index       & 0x7F );		/* address part */
	packet[1] = (UINT8)( (reg_index >> 7) | 0x80 );
	packet[2] = (UINT8)(  0x00            | 0x80 );		/* data part */
	MaDevDrv_SendDirectPacket( packet, 3 );

	pg_point = (UINT8)MaDevDrv_ReceiveData( MA_WT_PG + (7 - sa_id), 0 );

	if ( format < 2 )					/* ADPCM */
	{
		pg_point = (UINT16)((pg_point & 0x3E) << 4);
		zero_val = (UINT8)0x80;
	}
	else								/* PCM */
	{
		pg_point = (UINT16)((pg_point & 0x1F) << 5);
		zero_val = (UINT8)( ( format == 2 ) ? 0x80 : 0x00 );
	}

	cinfo_ptr->streaminfo.position[sa_id]++;

	if ( pg_point == read_block )
	{
		return result;
	}

	ram_adrs = write_block + (MA_RAM_START_ADDRESS + (MA_RAM_BLOCK_SIZE * (7-sa_id)) + 0x20);

	if ( pg_point == MA_MIN_PG )
		read_block = (UINT16)(MA_MAX_PG - (1 << 5));
	else
		read_block = (UINT16)(pg_point  - (1 << 5));

	if ( read_block == write_block ) return result;

	if ( write_block < read_block )
	{
		ram_size = read_block - write_block;

		wave_ptr  = cinfo_ptr->streaminfo.wave_ptr[sa_id];
		wave_size = cinfo_ptr->streaminfo.wave_size[sa_id];

		if ( ram_size > wave_size )
		{
			MaDevDrv_SendDirectRamData( ram_adrs, 0, wave_ptr, wave_size );

			cinfo_ptr->streaminfo.wave_ptr[sa_id]  += wave_size;

⌨️ 快捷键说明

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