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

📄 mmimmstomobilesoft.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	{
		sprintf(buf, "%d", value);
	}
	return buf;
}

MMS_S32    MMS_atol(MMS_S8 *str)
{
	return (MMS_S32)atol(str); //stdlib.h
}

MMS_S32    MMS_getms()
{
	int	ms;
	MMS_TRACE_EVENT(("MMS_getms"));
//	srand((unsigned int)time(NULL));
	ms = rand();	
	return ms;
}

MMS_S32	   MMS_getrandstr(MMS_S8 *str)
{
	//modified by xie to avoid  there is .mms files with the same filename in /mms/message/ folder.	
	//04-07-09
#ifdef  _INNOVATION_EMULATOR_
	MMS_S8 fullname[128];
	MMS_S8 path[128];
	int len;
	WIN32_FIND_DATA FileData; 
	HANDLE hSearch; 
	BOOL fFinished = FALSE; 
	BOOL isDirectory;
	int nfiles = 0;
	int i = 0;
	
	GetCurrentDirectoryA(sizeof(path),path);
	strcat(path,"\\filesystem");
	strcat(path, "/mms/message/");

	while(1) 
	{
		HANDLE ret;
		memset(fullname, 0, sizeof(fullname));
		MMS_itoa(MMS_getms(), str, 10);
		strcpy(fullname, path, strlen(path));
		strcat(fullname,str);
		strcat(fullname, ".mms");
		if(INVALID_HANDLE_VALUE == FindFirstFileA(fullname, &FileData))
			return 1;
	}
		
#else
extern const char MMS_DIR[];
	T_FFS_STAT stat;
	char filename[MMS_FILEFULLNAME_LEN];
	
	MMS_TRACE_EVENT(("MMS_getrandstr"));
	if(!str)
	{
		return 0;
	}
	
	while(1) 
	{
		//memset(filename, 0, sizeof(filename));
		MMS_itoa(MMS_getms(), str, 10);
		sprintf(filename,"%s%s.mms", MMS_DIR, str);
		MMS_TRACE_EVENT(("%s",str));
		if(EFFS_NOTFOUND == ffs_stat(filename, &stat))
		{
			MMS_TRACE_EVENT(("produce new mms filename %s in MMS_getrandstr()",filename));
			return 1;
		}
	}
#endif	
}

MMS_S32	   MMS_time_ltoa(MMS_U32 datetime, char *timestr)
{
	TIMEDATE today;  
	T_RTC_DATE_TIME rtcTime;
	GetTimeDate(currdate.year, currdate.month, currdate.day, &today); 	
	RTC_GetDateTime(&rtcTime);

	sprintf(timestr, "%d-%d-%d %d:%d", currdate.year,currdate.month,currdate.day,rtcTime.hour,rtcTime.minute);
	return 1;
}

MMS_S32	   MMS_getsystemtime()
{
	return (MMS_S32)time(NULL);
}

/*************************************************************/
/***************显示及定时器接口*****************************/
/*************************************************************/
#define RGBX(r,g,b) (unsigned short)(((r/8)<<11)+((g/4)<<5)+(b/8))
#define IMAGE_BUFFER_SIZE (40*1024)
unsigned char image_buf[IMAGE_BUFFER_SIZE];

MMS_VOID MMSSetImageData(MMS_U8 value)
{
	memset(image_buf, value, IMAGE_BUFFER_SIZE);
	return;
}

MMS_U8  MMSSaveImageData(MMS_S8 *pixelData, MMS_U32  pixelNum, MMS_U32  pixelPos, MMS_U8 pixelType)
{
	unsigned char *img_buf = image_buf;
	int i = 0;
	
	if(pixelType == 1)
	{/* Gray Image */
	 		
		for(i = 0; i < pixelNum; i++)
		{
			*(img_buf +pixelPos*2 + i * 2 + 1) = *(pixelData + i);
			*(img_buf +pixelPos*2 + i * 2 + 0) = (char)0;
		}
	}
	else
	{/* 24 bit Color Image*/		
		for(i = 0; i < pixelNum; i++)
		{
			unsigned char r , g, b;
			unsigned short * pValue = (unsigned short *)(img_buf + pixelPos*2 + i * 2);
			r = *(pixelData + 3*i + 2);
			g = *(pixelData + 3*i + 1);
			b = *(pixelData + 3*i + 0);
		    *pValue = RGBX(r,g,b);
		}		
	}

	return 0;
}

MMS_S8 * MMSGetImageData(MMS_S32  pixelPos, MMS_U32  pixelNum)
{
	//MMS_TRACE_EVENT(("MMSGetImageData"));
	return (char*)(image_buf + pixelPos * 2);	
}

MMS_U8 MMSBitBlt( MMS_U32 posX,	MMS_U32 posY, MMS_U32 width, MMS_U32 height,MMS_VOID * BmpPtr)
{
	MMS_TRACE_EVENT(("MMSBitBlt: %d ,%d,%d,%d",posX,posY,width,height));
#if 0
	{
		typedef int OS_HANDLE; 
   		 extern  LONG os_GetTaskName (OS_HANDLE Caller, OS_HANDLE TaskHandle, char * Name);
		  extern OS_HANDLE os_MyHandle ( void );
		  char task[10];
		  os_GetTaskName(NULL,os_MyHandle(),task);
    		MMS_TRACE_EVENT(("task: %s",task));
   	}
#endif   	

#ifdef MMI_MMSTASK_ENABLED
	/*if(!IsWinFocus_MMSTask())
		return 0;
	return dspl_BitBlt(posX,posY,width,height,0,BmpPtr,DSPL_BMPCOPY);
	*/
	{
		T_MMS_MMI_MMSBITBLT_IND parameter;
		parameter.posX = posX;
		parameter.posY = posY;
		parameter.width = width;
		parameter.height = height;
		parameter.BmpPtr = BmpPtr;
		/*请求mmi task处理MMS_BitBlt*/
		S_MMS_MMI_MMSBITBLT_IND(&parameter);
	}
#else
	return dspl_BitBlt(posX,posY,width,height,0,BmpPtr,DSPL_BMPCOPY);
#endif
}

#ifdef MMI_MMSTASK_ENABLED
MMS_U8 mmiMMSBitBlt( MMS_U32 posX,	MMS_U32 posY, MMS_U32 width, MMS_U32 height,MMS_VOID * BmpPtr)
{
	MMS_TRACE_EVENT(("mmiMMSBitBlt: %d ,%d,%d,%d",posX,posY,width,height));

	if(!IsWinFocus_MMSTask())
		return 0;
	
	return dspl_BitBlt(posX,posY,width,height,0,BmpPtr,DSPL_BMPCOPY);
}
#endif

/*talcon added for mms timer callback function*/
MMS_VOID * MMS_callbackfn = 0;
static int MMS_TimerCallBackFn(MfwEvt e, MfwTim *t)
{
	MMS_TRACE_EVENT(("MMS_TimerCallBackFn"));
#ifdef MMI_MMSTASK_ENABLED
	{
		extern BYTE get_mmstask_proc();
		if( get_mmstask_proc() )
		{
			MMS_TRACE_EVENT(("MMS_TimerCallBackFn:mms task in proc"));
			return 0;
		}
		else
		{
			T_MMI_MMS_TMCBFN_IND parameter;
			parameter.e = e;
			parameter.t = t;
			parameter.fn = MMS_callbackfn;
			M_MMI_MMS_TMCBFN_IND(&parameter);
		}
	}
#else
	((MfwCb)MMS_callbackfn)(e,t);
#endif
	return 0;
}

MMS_VOID	*MMS_settimer(MMS_S32 value, MMS_VOID * callback)
{
#ifdef MMI_MMSTASK_ENABLED
	MMS_TRACE_EVENT(("MMS_settimer"));
	return  mms_settimer(value,callback);
#else
	MMS_VOID *pTim;
	MMS_TRACE_EVENT(("MMS_settimer"));
	if(!callback)
	{
		MMS_TRACE_EVENT(("MMS_settimer():null callback!"));
		return NULL;
	}
	
	//pTim = timCreate(0,value,(MfwCb)callback);
	pTim = timCreate(mfw_parent (mfwFocus),value,(MfwCb)MMS_TimerCallBackFn);
	if(pTim)
	{
		timStart(pTim);
		MMS_callbackfn = callback;
		return pTim;
	}
	else
		return NULL;
#endif
}

MMS_S32		MMS_restarttimer(MMS_VOID *timer)
{
#ifdef MMI_MMSTASK_ENABLED
	MMS_TRACE_EVENT(("MMS_restarttimer"));
	return mms_restarttimer(timer);
#else
	MMS_TRACE_EVENT(("MMS_restarttimer"));
    	timStop(timer);
    	return (MMS_S32)timStart(timer);
#endif
}

MMS_S32		MMS_resettimervalue(MMS_VOID *timer, MMS_S32 fast)
{
#ifdef MMI_MMSTASK_ENABLED
	MMS_TRACE_EVENT(("MMS_resettimervalue"));
	return mms_resettimervalue(timer,fast);
#else
	MMS_TRACE_EVENT(("MMS_resettimervalue"));
	timStop(timer);
       return timSetTime(timer,fast);	 
#endif
}

MMS_S32		MMS_killtimer(MMS_VOID *timer)
{
#ifdef MMI_MMSTASK_ENABLED
	MMS_TRACE_EVENT(("MMS_killtimer"));
	return mms_killtimer( timer);
#else
	MMS_TRACE_EVENT(("MMS_killtimer"));
    	timStop(timer);
	MMS_callbackfn = 0;
    	return (MMS_S32)timDelete(timer);
#endif
}

MMS_U8		IsMMSLoseFocus(MMS_VOID)
{
  	MMS_TRACE_EVENT(("IsMMSLoseFocus()"));
 	return isIncomingCall;
}				 


MMS_U8 sys_getcharwidth(MMS_U8 ch)
{
//	MMS_TRACE_EVENT(("sys_getcharwidth(%c)",ch));
}


//Convert a UTF-8 byte sequence to a wide character.
//If the sequence is illegal or truncated by a NUL the first byte is
//returned.
//Does not include composing characters, of course.
unsigned short utf2unicode(unsigned char *p,int len)
{	
	if(!p)
		return 0;
	switch (len)
	{
	case 1:
	    return p[0];
	    /*lint -e527 */
		break;
		/*lint +e527 */		
	case 2:
		if ((p[1] & 0xc0) == 0x80)
		{
			return ((p[0] & 0x1f) << 6) + (p[1] & 0x3f);
		}
		break;
	case 3:
		if ((p[1] & 0xc0) == 0x80 && (p[2] & 0xc0) == 0x80)
		{
			return ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f);
		}
		break;
	default:
		break;
	}
	
	// Illegal value, just return the first byte 
	return p[0];
}


int unicode2utf(unsigned short unicode, char *word)
{
    word[0] = (0xe0 | (unicode>>12));
	word[1] = (0x80 | (unicode>>6&0x3f));
	word[2] = (0x80 | (unicode&0x3f));
	return 1;
}

MMS_S32	   MMS_char2utf8(MMS_S8 *strin, MMS_S8 *strout, MMS_S32 length )
{


	MMS_S32		outlen=0;
	MMS_U8	*p=(MMS_U8 *)(strin+1);
	
	MMS_U16	unicode;
	MMS_U8	word[4];
	MMS_TRACE_EVENT(("MMS_char2utf8"));

	if(!strin || !strout)
	{
		return 0;
	}
	
	if((MMS_U8)*strin != 0x80)
	{
		strcpy(strout,strin);
		return strlen(strin);
	}
	
	while(p[0] || p[1])
	{
		if((p[0]) == 0x00)
		{
			if(outlen < length)
			{
				strout[outlen++] = p[1];
				p +=2;
			}
			else
			{
				break;
			}
		}
		else
		{
			/* transfer from unicode ucs 16 to utf-8 */
			memset(word, 0, 3);
			unicode = (p[0]<<8)+p[1];
			unicode2utf(unicode, (MMS_S8 *)word);
			
			//printf("utf8 code: %.2x %.2x %.2x \r\n", word[0], word[1], word[2]);
			/* add word to strout buffer */
			strout[outlen++] = word[0];
			strout[outlen++] = word[1];
			strout[outlen++] = word[2];
			
			/* move strin buffer pointer */
			p += 2;
	
		}
	}
	strout[outlen] = 0;
	return outlen;
//#endif
}

MMS_S32	   MMS_utf82char(MMS_S8 *strin, MMS_S8 *strout, MMS_S32 length)
{

	MMS_S32 outlen=0;
	MMS_U8 *p=(MMS_U8 *)strin;
	MMS_S8 *pOut = strout;

	MMS_S32 len;
	MMS_U16	unicode;
	MMS_U8 word[2];
	
	// Lookup table to quickly get the length in bytes of a UTF-8 character from
	// the first byte of a UTF-8 string.  Bytes which are illegal when used as the
	// first byte have a one, because these will be used separately.
	static MMS_S8 utf8len_tab[256] =
	{
		1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
		1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
		1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
		1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
		1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 
		1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 
		2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
		3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1,
	};

	MMS_TRACE_EVENT(("MMS_utf82char"));
	
	if(!strin || !strout)
	{
		return 0;
	}

	if(p[0]==0xef && p[1]==0xbb && p[2]==0xbf)
	{	//jump over identify bytes
		p += 3;
	}
	else if(p[0]==0xff && p[1]==0xfe)
	{	//jump over identify bytes 
		p += 2;
	}

	pOut[0] = '\x80';
	pOut++;

	while(p[0])
	{
		// get a utf-8 word 
		len = utf8len_tab[p[0]];
		if(len > (MMS_S32)strlen((MMS_S8*)p))
		{
			break;
		}

		// transfer it to unicode ucs-16, and  
		if(len>1)
		{
			//printf("utf8 code: %.2x %.2x %.2x \r\n", p[0], p[1], p[2]);
			unicode = utf2unicode(p, len);
		}
		else
		{
			//printf("utf8 code: %.2x \r\n", p[0]);
			unicode = p[0];
		}

		//printf("ucs2 code: %.4x \r\n", unicode);

		// transfer unicode to ansi gb2312 
		memset(word, 0, 2);
		if(len>1)
		{
			word[0] = (unicode&0xff00)>>8;
			word[1] = (MMS_S8)(unicode&0x00ff);
			//printf("gb code: %.2x %.2x \r\n", word[0], word[1]);
		}
		else
		{
			//printf("gb code: %.2x \r\n", word[0]);
			word[1] = p[0];
		}

		// add word to strout buffer 
		if(outlen <= length-len)
		{
			pOut[outlen++] = word[0];
            pOut[outlen++] = word[1];
		}
		else
		{
			break;
		}

		// move strin buffer pointer 
		p += len;
	}

	pOut[outlen] = 0;
	pOut[outlen+1] = 0;
	return outlen;
}

MMS_U8	   MMS_MidiStop(MMS_S8 *filename)
{
#ifndef _INNOVATION_EMULATOR_
	MMS_TRACE_EVENT(("MMS_MidiStop(%s)",filename));
	MI_PlayMusic_Stop();
	return 0;
#endif
}

MMS_U8	   MMS_MidiPlay(MMS_S8 *filename, MMS_U8 loop)
{
#ifndef _INNOVATION_EMULATOR_
	MMS_TRACE_EVENT(("MMS_MidiPlay(%s,%d)",filename, loop));
	MI_PlayFile_Start((const char*)filename, 0xff, loop);
	return 0;
#endif
}

MMS_VOID   MMS_Sleep(MMS_U32 ms)
{
#ifndef  MMI_MMSTASK_ENABLED
    //rvf_delay(ms);
    rvf_delay((MMS_U32)(ms+4)/5);	//convert ms to system tick(one tick = 4.62ms)
#endif
}

/*************************************
$Description:
	check free space for mms,if returnvalus is smaller than new mms size, 
	manager will handle it as autorecv is off
$Author: Talcon Hu
*****************************************/
MMS_S32    MMS_Get_Free_Space(MMS_VOID)
{

⌨️ 快捷键说明

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