__interrupt void Int_TimerA0(void) {
	Clk.Sec_64++; //+ 1/32s
	Clk_Correct();

	TACCR0 += 1024;

	if (Clk.Sec_64 == 16) {
		Flag.Run |= R_HalfS;
		//cpu awake for one time each half a second
		LPM3_EXIT; //
	}

	if ((Clk.Sec_64 >= 32))//&& ( ~Flag.Run & R_Sec ) )
	{
		Clk.Sec_64 -= 32;
		Flag.Run |= (R_Sec + R_HalfS);

		gRTCOutCnt = 500;

		LPM3_EXIT;
	}

	GetKeyVal();

}
Exemple #2
0
/*
--------------------------------------------------------------------------------
  Function name : UINT32 MessageBoxKey(void)
  Author        : ZhengYongzhi
  Description   : 
                  
  Input         : 
  Return        : 

  History:     <author>         <time>         <version>       
             ZhengYongzhi      2009-4-3         Ver1.0
  desc:         ORG
--------------------------------------------------------------------------------
*/
_ATTR_HOLD_CODE_
uint32 DialogHoldKey(void)
{
    UINT32 HoldKeyVal;
    WIN    *HoldOffWin;
    
    HoldKeyVal =  GetKeyVal();
    
    switch (HoldKeyVal) 
    {
    case KEY_VAL_HOLD_ON:
        HoldState = HOLD_STATE_ON;
        SendMsg(MSG_HOLD_DISPLAY_ALL);
        break;
        
    case KEY_VAL_HOLD_OFF:
        HoldState = HOLD_STATE_OFF;
        SendMsg(MSG_HOLD_DISPLAY_ALL);
        break;  
        
    default:        
        break;
    }
    
    return (0);
}    
Exemple #3
0
void	KeyProc(void)	
{
	static uint8	u8KeyPressCnt	=	0;
	static uint16	u16PrevKey	=	0;
	uint16	u16Key	=	GetKeyVal();	

	if(u16Key==u16PrevKey)
	{
		u8KeyPressCnt++; 

		if(u8KeyPressCnt>KEY_END_TIME)
		{
			m_u16KeyAct	=	u16PrevKey;	
			
			if(m_u16KeyAct==0)
			{
				bKeyPress	=	0;		
			}
			else
			{
				bKeyPress	=	1;	
			}
			
			g_u16KeyRpyCnt++;	
			if(bFirstPress)
			{
				u8KeyPressCnt	=	0;
				bFirstPress		=	0;
                if((u16Key)&&(bNewKey))
				{
				    g_u16KeyUpAct = m_u16KeyAct;
                    if(bKeyMusic_EN) 
                    {
                        PlaySound(MusicKeyDown);
                    }
				}
			} 
			else
			{
				u8KeyPressCnt	=	KEY_RPY_TIME;
			}
		}
	}
	else
	{ 
		if(!bKeyPress)	
		{
			bNewKey		=	1;		
		}
		else
		{
			bNewKey		=	0;		
		}
		m_u16KeyAct		=	0;      	
		g_u16KeyRpyCnt	=	0;			
		bFirstPress		=	1; 			
		u16PrevKey		=	u16Key; 		
		u8KeyPressCnt	=	KEY_START_TIME;  
	}
}    
bool KeyVals::GetString(const char *_key, const char *&_val) const
{
	obUserData d;
	if(GetKeyVal(_key,d))
	{
		_val = d.GetString();
		return true;
	}
	return false;
}
bool KeyVals::GetEntity(const char *_key, GameEntity &_val) const
{
	obUserData d;
	if(GetKeyVal(_key,d))
	{
		_val = d.GetEntity();
		return true;
	}
	return false;
}
bool KeyVals::GetFloat(const char *_key, float &_val) const
{
	obUserData d;
	if(GetKeyVal(_key,d))
	{
		_val = d.GetFloat();
		return true;
	}
	return false;
}
bool KeyVals::GetVector(const char *_key, float *_v) const
{
	obUserData d;
	if(GetKeyVal(_key,d))
	{
		_v[0] = d.GetVector()[0];
		_v[1] = d.GetVector()[1];
		_v[2] = d.GetVector()[2];
		return true;
	}
	return false;
}
bool KeyVals::GetVector(const char *_key, float &_x,float &_y,float &_z) const
{
	obUserData d;
	if(GetKeyVal(_key,d))
	{
		_x = d.GetVector()[0];
		_y = d.GetVector()[1];
		_z = d.GetVector()[2];
		return true;
	}
	return false;
}
Exemple #9
0
//通知界面刷新皮肤
void CSkinMgr::Notify()
{
	CString s = CBcfFile::GetAppPath ();/////本地路径
	CString strSkin = GetSkinBcfFileName();
	CBcfFile f(s + "skin.bcf");
	TCHAR szUIPath[MAX_PATH];
	CString skinfolder;

	skinfolder = f.GetKeyVal(GetKeyVal(strSkin),"skinfolder","..\\" + GetSkinPath());
	wsprintf(szUIPath,"%s",skinfolder);

	BzDui::CPaintManagerUI::SetResourcePath(szUIPath);
	BzDui::CPaintManagerUI::ReloadSkin();
}
Exemple #10
0
/*
** 将语言包读取到哈希表中
*/
int CLang::LoadLangFile( char *file )
{
	int nRet = -1;
	char *pLangBuf = NULL;

    // 将语言包中的数据保存到缓冲区中
	int len = ReadFile( &pLangBuf, file );

	if ( len > 0 && pLangBuf != NULL )
    {
    	m_lang.Clear(); // 清空哈希表

    	char *pKey = NULL;
    	char *pVal = NULL;
    	char *pLine = NULL;

    	char *pLang = pLangBuf;

        // 从缓冲区中反复读取一行数据
        // 并从该行数据中提取关键字和值保存到哈希表中
    	while ( (pLine = GetLine( &pLang )) != NULL )
        {
        	GetKeyVal( &pKey, &pVal, pLine );
        	if ( pKey != NULL && pVal != NULL ) m_lang.Put( pKey, pVal );
        	Free( pLine );
        }

    	nRet = 0;
    }
	else
    {
    	if ( len == 0 )
        	FiPrint( "Load language file error: Empty file !\r\n" );
    	else if ( len == -1 ) 
        	FiPrint( "Load language file error: Read file error !\r\n" );
    	else
        	FiPrint( "Load language file error: Malloc memory failed !\r\n" );
    }
    
	Free( pLangBuf );
	return nRet;
}
static PSFINFO *LoadPSF(char *path, int level, int type) // Type==1 for just info load.
{
        FILE *fp;
        EXE_HEADER tmpHead;
        char *in,*out=0;
	u8 head[4];
        u32 reserved;
        u32 complen;
        u32 crc32; 
        uLongf outlen;
	PSFINFO *psfi;
	PSFINFO *tmpi;

	//printf("Loading: %s\n",path);
        if(!(fp=fopen(path,"rb")))
 	{
	 return(0);
	}
 
	fread(head,1,4,fp);
	if(memcmp(head,"PSF\x01",4)) return(0);

	psfi=malloc(sizeof(PSFINFO));
	memset(psfi,0,sizeof(PSFINFO));
        psfi->stop=~0;
        psfi->fade=0; 

        fread(&reserved,1,4,fp);
        fread(&complen,1,4,fp);
	complen=BFLIP32(complen);

        fread(&crc32,1,4,fp);
	crc32=BFLIP32(crc32);

        fseek(fp,reserved,SEEK_CUR);

        if(type)
	 fseek(fp,complen,SEEK_CUR);
        else
        {
         in=malloc(complen);
         out=malloc(1024*1024*2+0x800);
         fread(in,1,complen,fp);
         outlen=1024*1024*2;
         uncompress(out,&outlen,in,complen);
         free(in);
         memcpy(&tmpHead,out,sizeof(EXE_HEADER));
         psxRegs.pc = BFLIP32(tmpHead.pc0);
         psxRegs.GPR.n.gp = BFLIP32(tmpHead.gp0);
         psxRegs.GPR.n.sp = BFLIP32(tmpHead.S_addr);
         if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00;

 	 if(level)
 	 {
	  LoadPSXMem(BFLIP32(tmpHead.t_addr),BFLIP32(tmpHead.t_size),out+0x800);
          free(out);
	 }
        }

        {
         u8 tagdata[5];
         if(fread(tagdata,1,5,fp)==5)
         {
          if(!memcmp(tagdata,"[TAG]",5))
          {
           char linebuf[1024];

           while(fgets(linebuf,1024,fp)>0)
           {
            int x;
	    char *key=0,*value=0;

	    if(!GetKeyVal(linebuf,&key,&value))
	    { 
	     if(key) free(key);
	     if(value) free(value);
	     continue;
            }

	    AddKV(&psfi->tags,key,value);

	    if(!level)
	    {
       	     static char *yoinks[8]={"title","artist","game","year","genre",
                                  "copyright","psfby","comment"};
	     char **yoinks2[8]={&psfi->title,&psfi->artist,&psfi->game,&psfi->year,&psfi->genre,
                                    &psfi->copyright,&psfi->psfby,&psfi->comment};
	     for(x=0;x<8;x++)
	      if(!strcasecmp(key,yoinks[x]))
		*yoinks2[x]=value;
	     if(!strcasecmp(key,"length"))
	      psfi->stop=TimeToMS(value);
	     else if(!strcasecmp(key,"fade"))
	      psfi->fade=TimeToMS(value);
	    }

	    if(!strcasecmp(key,"_lib") && !type)
	    {
	     char *tmpfn;
	     /* Load file name "value" from the directory specified in
		the full path(directory + file name) "path"
	     */
	     tmpfn=findFileIgnoreCase(path,value);
	     if(!(tmpi=LoadPSF(tmpfn,level+1,0)))
	     {
	      //free(key);
	      //free(value); // key and value will be freed by FreeTags(psfi->tags)
	      free(tmpfn);
 	      if(!level) free(out);
	      fclose(fp);
	      FreeTags(psfi->tags);
	      free(psfi);
	      return(0);
	     }
	     FreeTags(tmpi->tags);
	     free(tmpi);
	     free(tmpfn);
	    }
           }
          }
         }
        }  

        fclose(fp);

	/* Now, if we're at level 0(main PSF), load the main executable, and any libN stuff */
        if(!level && !type)
        {
         LoadPSXMem(BFLIP32(tmpHead.t_addr),BFLIP32(tmpHead.t_size),out+0x800);
	 free(out);
        }

	if(!type)	/* Load libN */
	{
	 LIBNCACHE *cache;
	 PSFTAG *tag;
	 unsigned int libncount=0;
	 unsigned int cur=0;

	 tag=psfi->tags;
	 while(tag)
	 {
	  if(!strncasecmp(tag->key,"_lib",4) && tag->key[4])
	   libncount++;
	  tag=tag->next;
	 }

	 if(libncount)
	 {
	  cache=malloc(sizeof(LIBNCACHE)*libncount);

	  tag=psfi->tags;
	  while(tag)
	  {
	   if(!strncasecmp(tag->key,"_lib",4) && tag->key[4])
	   {
	    cache[cur].num=atoi(&tag->key[4]);
	    cache[cur].value=tag->value;
	    cur++;
	   }
	   tag=tag->next;
	  }
	  qsort(cache, libncount, sizeof(LIBNCACHE), ccomp);
	  for(cur=0;cur<libncount;cur++)
	  {
	   u32 ba[3];
	   char *tmpfn;

 	   if(cache[cur].num < 2) continue;

	   ba[0]=psxRegs.pc;
	   ba[1]=psxRegs.GPR.n.gp;
	   ba[2]=psxRegs.GPR.n.sp;

           /* Load file name "value" from the directory specified in
                the full path(directory + file name) "path"
             */
           tmpfn=findFileIgnoreCase(path,cache[cur].value);
           if(!(tmpi=LoadPSF(tmpfn,level+1,0)))
           {
            //free(key);
            //free(value);
            //free(tmpfn);
            //fclose(fp);
            //return(0);
           }
           free(tmpfn);
	   FreeTags(tmpi->tags);
	   free(tmpi);

	   psxRegs.pc=ba[0];
       	   psxRegs.GPR.n.gp=ba[1];
	   psxRegs.GPR.n.sp=ba[2];
	  }
	  free(cache);

	 }	// if(libncount)

	}	// if(!type)

	return(psfi);
}
Exemple #12
0
_ATTR_WiFiMUSICBrow_CODE_
UINT32 WiFiMusicBrowWinKeyProc(void)
{

    uint32  WifiApKeyVal;
    uint32 RetVal = RETURN_OK;
    TASK_ARG TaskArg;
	
    WifiApKeyVal =  GetKeyVal();
    switch (WifiApKeyVal) 
    {
        case KEY_VAL_MENU_SHORT_UP:
			if (0 != WiFiMusicBrowTreeInf.CurId)
			{
				WiFiMuisicBrowGetName();
				SendMsg(MSG_WIFI_MUSIC_SWITCH);
			}
            WinDestroy(&WiFiMusicBrowWin);
            break;
			
        case KEY_VAL_ESC_SHORT_UP:
            WinDestroy(&WiFiMusicBrowWin);
			break;

		case KEY_VAL_UP_SHORT_UP:
            WiFiMusicBrowTreeInf.PreCounter = WiFiMusicBrowTreeInf.KeyCounter;
            if (WiFiMusicBrowTreeInf.CurId > 0) 
            {
                WiFiMusicBrowTreeInf.CurId--;

                if (WiFiMusicBrowTreeInf.KeyCounter == 0) 
                {
                    WiFiMusicBrowTreeInf.KeyCounter = MAX_WIFI_LCD_BROWNUM - 1;
                    WiFiMusicBrowUpProc();                    
                    SendMsg(MSG_BROW_DIS_ALL_ITEM);
                }
                else
                {
                    WiFiMusicBrowTreeInf.KeyCounter--;
                    SendMsg(MSG_BROW_DIS_SELE_ITEM);
                }
            }
            else
            {
                WiFiMusicBrowTreeInf.CurId = WiFiMusicBrowTreeInf.DispTotalItem - 1;
                if (WiFiMusicBrowTreeInf.DispTotalItem > MAX_WIFI_LCD_BROWNUM)
                {
                    if (WiFiMusicBrowTreeInf.DispTotalItem % MAX_WIFI_LCD_BROWNUM)
                    {
                        WiFiMusicBrowTreeInf.KeyCounter = WiFiMusicBrowTreeInf.DispTotalItem % MAX_WIFI_LCD_BROWNUM - 1;
                    }
                    else
                    {
                        WiFiMusicBrowTreeInf.KeyCounter =  MAX_WIFI_LCD_BROWNUM - 1;
                    }
                    WiFiMusicBrowUpProc();
                    SendMsg(MSG_BROW_DIS_ALL_ITEM);
                }
                else
                {
                    WiFiMusicBrowTreeInf.KeyCounter = WiFiMusicBrowTreeInf.DispTotalItem - 1;
                    SendMsg(MSG_BROW_DIS_SELE_ITEM);
                }
            }
            break;
            
		case KEY_VAL_DOWN_SHORT_UP:
            WiFiMusicBrowTreeInf.PreCounter = WiFiMusicBrowTreeInf.KeyCounter;
            if(WiFiMusicBrowTreeInf.CurId < (WiFiMusicBrowTreeInf.DispTotalItem - 1))
            {
                WiFiMusicBrowTreeInf.CurId++; 
                if(WiFiMusicBrowTreeInf.KeyCounter >= MAX_WIFI_LCD_BROWNUM - 1) 
                {
                    WiFiMusicBrowTreeInf.KeyCounter = 0;
                    WiFiMusicBrowUpProc();                    
                    SendMsg(MSG_BROW_DIS_ALL_ITEM);//display all screen
                }
                else
                {
                    WiFiMusicBrowTreeInf.KeyCounter++;
                    SendMsg(MSG_BROW_DIS_SELE_ITEM);
                }  
            }
            else
            {
                WiFiMusicBrowTreeInf.CurId = 0;
                WiFiMusicBrowTreeInf.KeyCounter = 0;
                if(WiFiMusicBrowTreeInf.DispTotalItem > MAX_WIFI_LCD_BROWNUM)
                {
                    WiFiMusicBrowUpProc();
                    SendMsg(MSG_BROW_DIS_ALL_ITEM);
                }
                else
                {
                   SendMsg(MSG_BROW_DIS_SELE_ITEM);
                }                
            }
            break;
            
		default:        
			break;
    }
    return RetVal;
}
Exemple #13
0
static PSFINFO *LoadPSF(char *path, int level, int type,const char *pathDir) // Type==1 for just info load.
{
    FILE *fp;
    u8 *in,*out=0;
	u8 head[4];
    u32 reserved;
    u32 complen;
    u32 crc32;
    uLongf outlen;
	PSFINFO *psfi=NULL;
	PSFINFO *tmpi=NULL;

    u32 offset, plength;
	
	sexypsf_missing_psflib=0;

#ifdef DEBUG
	fprintf(stderr, "Searching (%s)\n", path);
#endif

	fp=fopen(path,"rb");
    if(!fp) return 0;

	fread(head,1,4,fp);
	if(memcmp(head,"PSF\x01",4)) return(0);

	psfi=malloc(sizeof(PSFINFO));
	if( psfi == NULL ) return(0);
	memset(psfi,0,sizeof(PSFINFO));
    psfi->stop=~0;
    psfi->fade=0;

    fread(&reserved,1,4,fp);
    fread(&complen,1,4,fp);
	complen=BFLIP32(complen);

    fread(&crc32,1,4,fp);
	crc32=BFLIP32(crc32);

#ifdef DEBUG
	fprintf(stderr, "CRC32 = 0x%x\n", crc32);
#endif

    fseek(fp,reserved,SEEK_CUR);

    if(type)
		fseek(fp,complen,SEEK_CUR);
    else {
        in=malloc(complen);
		if( !in ) return(0);
        out=malloc(1024*1024*2+0x800);
		if( !out ) {
			free(in);
			return(0);
		}
        fread(in,1,complen,fp);
        outlen=1024*1024*2;
        uncompress(out,&outlen,in,complen);
        free(in);

		psxRegs->pc = out[0x10] | out[0x11]<<8 | out[0x12]<<16 | out[0x13]<<24;
		psxRegs->GPR.n.gp = out[0x14] | out[0x15]<<8 | out[0x16]<<16 | out[0x17]<<24;
		psxRegs->GPR.n.sp = out[0x30] | out[0x31]<<8 | out[0x32]<<16 | out[0x33]<<24;

        if (psxRegs->GPR.n.sp == 0) psxRegs->GPR.n.sp = 0x801fff00;

#ifdef DEBUG
		fprintf(stderr, "%d Level: PC %x GP %x SP %x\n",
			level, psxRegs->pc, psxRegs->GPR.n.gp, psxRegs->GPR.n.sp);
#endif

 		if(level) {
			offset = out[0x18] | out[0x19]<<8 | out[0x1a]<<16 | out[0x1b]<<24;
			offset &= 0x3fffffff;	// kill any MIPS cache segment indicators
			plength = out[0x1c] | out[0x1d]<<8 | out[0x1e]<<16 | out[0x1f]<<24;

#ifdef DEBUG
			fprintf(stderr, "%d Level: offset %x plength: %d [%d]\n", level, offset, plength, plength);
#endif

			LoadPSXMem(offset,plength,(char*)out+0x800);
			free(out);

			// I don't really know how does this
			// work, but apparently it breaks the
			// loop that makes ff6 and ct to take
			// several seconds to start ...
			if( crc32 == 0xEFDE8EEE || crc32 == 0x545D9F65 )
				psxMemWrite32(0x5A66C, 0);

			// Same as above for Popolocrois
			if( crc32 == 0xF535726 )
				psxMemWrite32(0x5A990, 0);
		}
	}

    {
		u8 tagdata[5];
        if(fread(tagdata,1,5,fp)==5) {
			if(!memcmp(tagdata,"[TAG]",5)) {
				char linebuf[1024];
				while(fgets(linebuf,1024,fp)>0) {
					int x;
					char *key=0,*value=0;

					if(!GetKeyVal(linebuf,&key,&value)) {
						if(key) free(key);
						if(value) free(value);
						continue;
					}

					AddKV(&psfi->tags,key,value);

					if(!level) {
       					static char *yoinks[8]={"title","artist","game","year","genre",
                                  "copyright","psfby","comment"};
						char **yoinks2[8]={&psfi->title,&psfi->artist,&psfi->game,&psfi->year,&psfi->genre,
                                    &psfi->copyright,&psfi->psfby,&psfi->comment};
						for(x=0;x<8;x++)
							if(!strcasecmp(key,yoinks[x]))
								*yoinks2[x]=value;
						if(!strcasecmp(key,"length"))
							psfi->stop=TimeToMS(value);
						else if(!strcasecmp(key,"fade"))
							psfi->fade=TimeToMS(value);
					}

					if(!strcasecmp(key,"_lib") && !type) {
						char *tmpfn;
						/* Load file name "value" from the directory specified in
						   the full path(directory + file name) "path"
						*/
                        //printf("yo %s\nya %s\nyu%s\n",path,value,pathDir);
						tmpfn=GetFileWithBase(path,value,pathDir);
                        //printf("ru: %s\n",tmpfn);
						if(!(tmpi=LoadPSF(tmpfn,level+1,0,pathDir))) {
							//free(key);
							//free(value);
							sexypsf_missing_psflib=1;
							strcpy(sexypsf_psflib_str,value);
							free(tmpfn);
 							if(!level) free(out);
							fclose(fp);
							FreeTags(psfi->tags);
							free(psfi);
							return(0);
						}
						FreeTags(tmpi->tags);
						free(tmpi);
						free(tmpfn);
					}
				}
			}
		}
	}

    fclose(fp);

	/* Now, if we're at level 0(main PSF), load the main executable, and any libN stuff */
    if(!level && !type) {
		offset = out[0x18] | out[0x19]<<8 | out[0x1a]<<16 | out[0x1b]<<24;
		offset &= 0x3fffffff;	// kill any MIPS cache segment indicators
		plength = out[0x1c] | out[0x1d]<<8 | out[0x1e]<<16 | out[0x1f]<<24;

		// TODO - investigate: should i just make
		//        plength = outlen-0x800?

		// Philosoma has an illegal "plength".  *sigh*
		if (plength > (outlen-0x800))
		{
			plength = outlen-0x800;
		}

		if( psfi->game ) {
			// Suikoden Tenmei has an illegal "plength". *sigh sigh*
			if( !strncmp(psfi->game, "Suikoden: Tenmei no Chikai", 26) ) {
				plength = outlen-0x800;
			}

			// Einhänder has an illegal "plength". *sigh sigh sigh*
			if( !strncmp(psfi->game, "Einhänder", 9) ) {
				plength = outlen-0x800;
			}
		}

#ifdef DEBUG
		fprintf(stderr, "%d Level: offset %x plength: %d [%d]\n", level, offset, plength, outlen-2048);
#endif

		LoadPSXMem(offset,plength,(char*)out+0x800);
		free(out);
    }

	if(!type)	/* Load libN */{
		LIBNCACHE *cache;
		PSFTAG *tag;
		unsigned int libncount=0;
		unsigned int cur=0;

		tag=psfi->tags;
		while(tag) {
			if(!strncasecmp(tag->key,"_lib",4) && tag->key[4])
			libncount++;
			tag=tag->next;
		}

		if(libncount) {
			cache=malloc(sizeof(LIBNCACHE)*libncount);

			tag=psfi->tags;
			while(tag) {
				if(!strncasecmp(tag->key,"_lib",4) && tag->key[4]) {
					cache[cur].num=atoi(&tag->key[4]);
					cache[cur].value=tag->value;
					cur++;
				}
				tag=tag->next;
			}
			qsort(cache, libncount, sizeof(LIBNCACHE), ccomp);
			for(cur=0;cur<libncount;cur++) {
				u32 ba[3];
				char *tmpfn;

 				if(cache[cur].num < 2) continue;

				ba[0]=psxRegs->pc;
				ba[1]=psxRegs->GPR.n.gp;
				ba[2]=psxRegs->GPR.n.sp;

				/* Load file name "value" from the directory specified in
				the full path(directory + file name) "path"
				*/
				tmpfn=GetFileWithBase(path,cache[cur].value,pathDir);
				if(!(tmpi=LoadPSF(tmpfn,level+1,0,pathDir))) {
					//free(key);
					//free(value);
					//free(tmpfn);
					//fclose(fp);
			        //return(0);
				} else {
                    FreeTags(tmpi->tags);
                    free(tmpi);
                }
                free(tmpfn);


				psxRegs->pc=ba[0];
       			psxRegs->GPR.n.gp=ba[1];
				psxRegs->GPR.n.sp=ba[2];
			}
			free(cache);
		}	// if(libncount)

	}	// if(!type)

	return(psfi);
}
Exemple #14
0
// LoadPSF for Memory
static PSFINFO *memLoadPSF(char *addr, long size, int level, int type) // Type==1 for just info load.
{
    u8 *in,*out=0;
	u8 head[4];

    u32 reserved;
    u32 complen;
    u32 crc32;
    uLongf outlen;
	PSFINFO *psfi=NULL;
	PSFINFO *tmpi=NULL;
	u32 poffset, plength;
	u32 offset = 0;

	if( addr == NULL || size == 0 ) return(0);

	memread((void*)(head), 4, addr, size, &offset);
	if(memcmp(head,"PSF\x01",4)) return(0);

	psfi=malloc(sizeof(PSFINFO));
	memset(psfi,0,sizeof(PSFINFO));
    psfi->stop=~0;
    psfi->fade=0;

	memread((void*)(&reserved), 4, addr, size, &offset);
	memread((void*)(&complen), 4, addr, size, &offset);
	complen=BFLIP32(complen);

	memread((void*)(&crc32), 4, addr, size, &offset);
	crc32=BFLIP32(crc32);

	memseek(reserved, size, &offset);

	if(type) {
		memseek(complen, size, &offset);
	}
    else {
        in=malloc(complen);
        out=malloc(1024*1024*2+0x800);
		if( !in || !out ) { free(psfi); return (0); }
		memread((void*)(in), complen, addr, size, &offset);

        outlen=1024*1024*2;
        uncompress(out,&outlen,in,complen);
        free(in);

        psxRegs->pc = out[0x10] | out[0x11]<<8 | out[0x12]<<16 | out[0x13]<<24;
		psxRegs->GPR.n.gp = out[0x14] | out[0x15]<<8 | out[0x16]<<16 | out[0x17]<<24;
		psxRegs->GPR.n.sp = out[0x30] | out[0x31]<<8 | out[0x32]<<16 | out[0x33]<<24;

        if (psxRegs->GPR.n.sp == 0) psxRegs->GPR.n.sp = 0x801fff00;

#ifdef DEBUG
		fprintf(stderr, "%d Level: PC %x GP %x SP %x\n",
			level, psxRegs->pc, psxRegs->GPR.n.gp, psxRegs->GPR.n.sp);
#endif

 		if(level) {
			poffset = out[0x18] | out[0x19]<<8 | out[0x1a]<<16 | out[0x1b]<<24;
			poffset &= 0x3fffffff;	// kill any MIPS cache segment indicators
			plength = out[0x1c] | out[0x1d]<<8 | out[0x1e]<<16 | out[0x1f]<<24;

#ifdef DEBUG
			fprintf(stderr, "%d Level: offset %x plength: %d\n", level, poffset, plength);
#endif

			LoadPSXMem(poffset,plength,out+0x800);
			free(out);

			// I don't really know how does this
			// work, but apparently it breaks the
			// loop that makes ff6 and ct to take
			// several seconds to start ...
			if( crc32 == 0xEFDE8EEE || crc32 == 0x545D9F65 )
				psxMemWrite32(0x5A66C, 0);

			// Same as above for Popolocrois and Einhänder
			if( crc32 == 0xF535726 )
				psxMemWrite32(0x5A990, 0);
		}
	}

    {
		u8 tagdata[5];
		if( memread((void*)(tagdata), 5, addr, size, &offset) == 5 ) {
			if(!memcmp(tagdata,"[TAG]",5)) {
				char linebuf[1024];

				while( memfgets(linebuf, 1024, addr, size, &offset)>0 ) {
					int x;
					char *key=0,*value=0;

					if(!GetKeyVal(linebuf,&key,&value)) {
						if(key) free(key);
						if(value) free(value);
						continue;
					}

					AddKV(&psfi->tags,key,value);

					if(!level) {
       					static char *yoinks[8]={"title","artist","game","year","genre",
                                  "copyright","psfby","comment"};
						char **yoinks2[8]={&psfi->title,&psfi->artist,&psfi->game,&psfi->year,&psfi->genre,
                                    &psfi->copyright,&psfi->psfby,&psfi->comment};
						for(x=0;x<8;x++)
							if(!strcasecmp(key,yoinks[x]))
								*yoinks2[x]=value;
						if(!strcasecmp(key,"length"))
							psfi->stop=TimeToMS(value);
						else if(!strcasecmp(key,"fade"))
							psfi->fade=TimeToMS(value);
					}

					if(!strcasecmp(key,"_lib") && !type && __psflibs) {

						/* Search file name "value" from the __psflibs array */
						int n, found = 0;
						for(n=0;n<__psflibs->count;n++)
							if( !strcasecmp(value, __psflibs->libn[n].name) ) {
								found = 1;
								break;
							}

						if(!found || !(tmpi=memLoadPSF(__psflibs->libn[n].addr, __psflibs->libn[n].size, level+1,0))) {
							free(key);
							free(value);
							if(!level) free(out);

							FreeTags(psfi->tags);
							free(psfi);
							return(0);
						}

						FreeTags(tmpi->tags);
						free(tmpi);
					}
				}
			}
		}
	}

	/* Now, if we're at level 0(main PSF), load the main executable, and any libN stuff*/
    if(!level && !type) {
    	poffset = out[0x18] | out[0x19]<<8 | out[0x1a]<<16 | out[0x1b]<<24;
		poffset &= 0x3fffffff;	// kill any MIPS cache segment indicators
		plength = out[0x1c] | out[0x1d]<<8 | out[0x1e]<<16 | out[0x1f]<<24;

		// TODO - investigate: should i just make
		//        plength = outlen-0x800?

		// Philosoma has an illegal "plength".  *sigh*
		if (plength > (outlen-0x800))
		{
			plength = outlen-0x800;
		}

		if( psfi->game ) {
			// Suikoden Tenmei has an illegal "plength". *sigh sigh*
			if( !strncmp(psfi->game, "Suikoden: Tenmei no Chikai", 26) ) {
				plength = outlen-0x800;
			}

			// Einhänder has an illegal "plength". *sigh sigh sigh*
			if( !strncmp(psfi->game, "Einhänder", 9) ) {
				plength = outlen-0x800;
			}
		}

#ifdef DEBUG
		fprintf(stderr, "%d Level: offset %x plength: %d\n", level, poffset, plength);
#endif

		LoadPSXMem(poffset,plength,out+0x800);
		free(out);
    }

	if(!type && __psflibs)	/* Load libN */ {
		LIBNCACHE *cache;
		PSFTAG *tag;
		unsigned int libncount=0;
		unsigned int cur=0;

		tag=psfi->tags;
		while(tag) {
			if(!strncasecmp(tag->key,"_lib",4) && tag->key[4])
			libncount++;
			tag=tag->next;
		}

		if(libncount) {
			cache=malloc(sizeof(LIBNCACHE)*libncount);

			tag=psfi->tags;
			while(tag) {
				if(!strncasecmp(tag->key,"_lib",4) && tag->key[4]) {
					cache[cur].num=atoi(&tag->key[4]);
					cache[cur].value=tag->value;
					cur++;
				}
				tag=tag->next;
			}
			qsort(cache, libncount, sizeof(LIBNCACHE), ccomp);
			for(cur=0;cur<libncount;cur++) {
				u32 ba[3];

 				if(cache[cur].num < 2) continue;

				ba[0]=psxRegs->pc;
				ba[1]=psxRegs->GPR.n.gp;
				ba[2]=psxRegs->GPR.n.sp;

				/* Search file name "value" from the __psflibs array */
				int n, found = 0;
				for(n=0;n<__psflibs->count;n++)
					if( !strcasecmp(cache[cur].value, __psflibs->libn[n].name) ) {
						found = 1;
						break;
					}

				if(!found || !(tmpi=memLoadPSF(__psflibs->libn[n].addr,__psflibs->libn[n].size,level+1,0))) {
					//free(key);
					//free(value);
					//free(tmpfn);
					//fclose(fp);
					//return(0);
				}
				FreeTags(tmpi->tags);
				free(tmpi);

				psxRegs->pc=ba[0];
       			psxRegs->GPR.n.gp=ba[1];
				psxRegs->GPR.n.sp=ba[2];
			}
			free(cache);
		}	// if(libncount)

	}	// if(!type)

	return(psfi);
}
Exemple #15
0
uint8 read_card_loop()
{	
	uint8 ret;
	bit flag1;
	uint16 tick;
	cls();
	Display(0,0,g_z18pos.welcome_msg,0);
	tick = 0;
	g_lcd_flag = 0;
	flag1 = 0;
	if(z18pos_check_coll_interval())
		return KNG_POS_EXPIRED_COLL;
	Led_OnOff(1,0);
	while(1)
	{
		clr_dog();
		ret = GetKeyVal(1);
		if(ret != 0xFF)
			Lcd_onoff(1);
		if(ret == KEY_ESC)
			break;
		ret = mif_request(0);
		if(flag1)
		{
			cls();
			Display(0,0,g_z18pos.welcome_msg,0);
			flag1 = 0;
		}

		if(ret == Z18_FAILED)
		{
            z18pos_check_consume();
            kng_sleep(1);
			tick+=3;
			if(tick >= 60)
			{
				tick = 0;
				cls();
				Display(0,0,g_z18pos.welcome_msg,0);
				//Led_OnOff(1,1);
				Lcd_onoff(0);
				g_lcd_flag = 0;
                InitRtcTime();
	            ReadRtcTime(g_z18pos.curr_time);
			}
			if(z18pos_check_coll_interval())
			{
				KNG_AUDIO(AU_NEED_COL,Z18_AUDIO_DELAY);
				print_error(KNG_POS_EXPIRED_COLL,NULL);
				return KNG_POS_EXPIRED_COLL;
			}
		}
		else
		{
            InitRtcTime();
	        ReadRtcTime(g_z18pos.curr_time);
			memset(&g_mycard,0,sizeof g_mycard);
			g_mycard.last_login_sect = 0xFF;
			tick = 0;
			// 寻卡成功
			ret = consume_card();
			if(ret>0)
			{
				debug_string("consume [%d]\n",(uint16)ret);
			}
			switch(ret)
			{
			case KNG_POS_PARAM_ERROR:
				print_error(ret,"请联系管理员");
				break;
			case KNG_POS_HARDWARE_ERROR:
				print_error(ret,"请检查POS机");
				break;
			case KNG_POS_NO_RIGHT:
				print_error(ret,NULL);
				break;
			case  KNG_POS_NOT_SUPP_CARDTYPE:
				print_error(ret,NULL);
				break;
			case KNG_POS_SUCCESS:
				break;
			case KNG_POS_UNEXPECT_CARD:
				break;
            case KNG_POS_REC_FULL:
                KNG_AUDIO(AU_NEED_COL,Z18_AUDIO_DELAY);
                print_error(ret,"请采集");
                break;
			default:
				break;
			}
			flag1 = 1;
		}
	}
	return 0;
}