
/***************************************************************************
**
**    $Header:   D:/ECB2S/SRC/LOG/FUNCTION.CPP   1.2.1.4   17 Apr 1997 15:52:34   ZJRD  $
**
**    $Log:   D:/ECB2S/SRC/LOG/FUNCTION.CPP  $
** 
**    Rev 1.2.1.4   17 Apr 1997 15:52:34   ZJRD
** No change.
** 
**    Rev 1.2.1.3   16 Apr 1997 10:23:58   ZJRD
** No change.
** 
**    Rev 1.2.1.2   10 Apr 1997 15:34:42   ZJRD
** No change.
** 
**    Rev 1.2.1.1   03 Apr 1997 15:14:50   ZJRD
** No change.
** 
**    Rev 1.2.1.0   28 Mar 1997 10:19:58   ZJRD
** easy pack sld 2.09d
** 
**    Rev 1.1   19 Mar 1997 11:30:24   ZJRD
** No change.
** 
**    Rev 1.0   12 Mar 1997 14:46:50   ZJRD
** Initial revision.
** 
**    Rev 1.7.1.0.1.2   09 Dec 1996 10:15:18   ZJRD
** EasyPack/SLD Version 2.0P
** 
**    Rev 1.7.1.0.1.0   11 Nov 1996 12:58:34   ZJRD
** EasyPack/SLD Version 2.01
** 
**    Rev 1.7.1.4   09 Sep 1996 13:16:08   ZJRD
** EasyPack/SLD Version 1.9f
** 
**    Rev 1.7.1.3   05 Sep 1996 11:27:40   ZJRD
** No change.
** 
**    Rev 1.7.1.2   02 Sep 1996 09:54:46   ZJRD
** No change.
** 
**    Rev 1.7.1.1   28 Aug 1996 15:50:16   ZJRD
** No change.
** 
**    Rev 1.7.1.0   12 Aug 1996 10:54:18   ZJRD
** EasyPack/SLD Version 1.98
** 
**    Rev 1.5   05 Jun 1996 14:57:20   ZJRD
** No change.
** 
**    Rev 1.4   29 May 1996 09:34:56   ZJRD
** No change.
** 
**    Rev 1.3   16 May 1996 09:07:58   ZJRD
** No change.
** 
**    Rev 1.2   10 May 1996 09:09:30   ZJRD
** No change.
** 
**    Rev 1.1   02 May 1996 10:25:24   ZJRD
** EasyPack/SLD Version 1.92
** 
**    Rev 1.29   18 Apr 1996 13:00:04   Shirley
** No change.
** 
**    Rev 1.28   12 Apr 1996 10:35:24   Shirley
** EasyPack/SLD Version 1.90
** 
**    Rev 1.26   15 Feb 1996 08:50:38   Shirley
** No change.
** 
**    Rev 1.25   12 Feb 1996 14:05:20   Shirley
** No change.
** 
**    Rev 1.24   06 Feb 1996 15:31:52   Shirley
** No change.
** 
**    Rev 1.23   06 Feb 1996 13:45:06   Shirley
** No change.
** 
**    Rev 1.22   01 Feb 1996 10:17:54   Shirley
** No change.
** 
**    Rev 1.21   26 Jan 1996 09:16:02   Shirley
** No change.
** 
**    Rev 1.20   25 Jan 1996 13:15:54   Shirley
** No change.
** 
**    Rev 1.19   24 Jan 1996 10:35:40   Shirley
** No change.
** 
**    Rev 1.18   23 Jan 1996 11:26:28   Shirley
** No change.
** 
**    Rev 1.17   18 Jan 1996 10:15:06   Shirley
** No change.
** 
**    Rev 1.16   15 Jan 1996 16:16:22   Shirley
** No change.
** 
**    Rev 1.15   04 Jan 1996 11:08:28   Shirley
** No change.
** 
**    Rev 1.14   30 Nov 1995 09:09:02   Shirley
** No change.
** 
**    Rev 1.13   28 Nov 1995 15:31:50   Shirley
** No change.
** 
**    Rev 1.12   21 Nov 1995 11:18:30   Shirley
** No change.
** 
**    Rev 1.11   13 Nov 1995 09:24:10   Shirley
** No change.
** 
**    Rev 1.10   12 Nov 1995 11:32:20   Shirley
** EasyPack/SLD Version 0.24
** 
**    Rev 1.9   08 Nov 1995 16:30:44   Shirley
** No change.
** 
**    Rev 1.8   08 Nov 1995 12:45:22   Shirley
** No change.
** 
**    Rev 1.7   02 Nov 1995 10:05:42   Shirley
** EasyPack/SLD Version 0.21
** 
**    Rev 1.2   13 Oct 1995 13:22:38   Shirley
** No change.
** 
**    Rev 1.1   29 Sep 1995 09:53:12   Shirley
** No change.
** 
**    Rev 1.0   20 Sep 1995 10:56:42   Shirley
** Initial revision.
** 
**    
** 
** 
**
**
**
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
//
//  File name:  FUNCTION.CPP
//
//  Description:The Completement file of funtctions  for Peripheral window
//
//  Author:     Jerry Yan
//
//  Date:       09/18/95
//
//  Modification:
//
//      1. 04/18/95, Initial version 
//
//
//  Copyright (C) 1995 Microtek International. All rights reserved.
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "string.h"
#include "mylist.h" 
#include "listcol.h"



#define BUFFERLONG           200 

extern  int GetCpuInfo(char buffer[BUFFERLONG],int *regnum)
{
     char* cpuname;
  // cpuname=GetCpuName();
     cpuname="8031";                 
     *regnum=GetPrivateProfileInt(cpuname,"MAX_REG",1,"c:\\yyh\\regis\\register.ini");
     GetPrivateProfileString(cpuname,"register","NOFOUND",buffer,
                                   BUFFERLONG,"c:\\yyh\\regis\\register.ini");  
     if (buffer=="NOFOUND" || *regnum==1)  
         return 0;
     return 1;                               
};     

extern   int GetRegInfo(char buffer[BUFFERLONG],char* regname)
{
     GetPrivateProfileString("bitname",regname,"NOFOUND",buffer,
                                   BUFFERLONG,"c:\\yyh\\regis\\register.ini");  
     if (buffer=="NOFOUND")  
         return 0;
     return 1;                               
}; 


extern  int Hex2Dec(char* reg_value)
{      
   int sum=0;
   int i=0; 
   
   while(  (reg_value[i] !=' ') &&(reg_value[i] !='H') && (reg_value[i] !='\0') )
   {   
       sum*=16;
       switch(reg_value[i]){
              case '0': sum+=0; 
                        break; 
              case '1': sum+=1;
                        break;
              case '2': sum+=2;
                        break;
              case '3': sum+=3;
                        break;
              case '4': sum+=4;
                        break;
              case '5': sum+=5;          
                        break;
              case '6': sum+=6;
                        break;
              case '7': sum+=7;
                        break;
              case '8': sum+=8;
                        break;
              case '9': sum+=9;
                        break;
              case 'A': sum+=10;
                        break;
              case 'B': sum+=11;
                        break;
              case 'C': sum+=12;
                        break;
              case 'D': sum+=13;
                        break;
              case 'E': sum+=14;
                        break;
              case 'F': sum+=15;
                        break;
           }
       
      i++;    
   }
   return sum;
}                                       



class CMyList; 
extern int ITEMRANGE; 
extern STATUS AbiGetOneReg(REG_ID,UINT*);
extern REGISTER RegVal[MAXRANGE];
 
extern  void FreshPer() 
{
	if(AfxGetMainWnd()->GetDescendantWindow(IDC_LIST1))
    {   
         int i;
         for (i=0;i<ITEMRANGE;i++) 
           { 
      		  AbiGetOneReg(RegVal[i].id,&(RegVal[i].value) );
    		}
    	((CMyList*)(AfxGetMainWnd()->GetDescendantWindow(IDC_LIST1)))->ResetContent();
	    ((CMyList*)(AfxGetMainWnd()->GetDescendantWindow(IDC_LIST1)))->InitList();
	}
}	       


extern int CheckString(CString string)
{
	int len,i=0;
	len=string.GetLength();
	int count=0, sum=0;
    
    if(NULL==strstr( string.GetBuffer(16), "0X" )) //Decimal
    {
 	   string.ReleaseBuffer();
   	   while((string[i]==' ')&&(i<len-1) ) i++; 
	   while((string[i]=='0')&&(i<len-1) ) i++;
	   while( ((string[i]>='0') &&(string[i]<='9')) )
		{
		   sum=(string[i]-'0')+sum*10;
		   i++;     
		   count++;   
		   if(i==len) break;  
		   if(count>3) return 0;
		 }
       while( i<len ) 
         if(string[i]==' ')  i++; 
         else break;
	   if(i<len)   return 0; 
       return 2; 

	 }
	 else
	 {
	    while((string[i]==' ')&&(i<len-1) ) i++; 
	    while((string[i]=='0')&&(i<len-1) ) i++;
	    while(string[i]!='X') return 0;
	    i++; 
	    while((string[i]=='0')&&(i<len-1) ) i++; 
	    
	    while( ((string[i]>='0')&&(string[i]<='9'))||
	    	   ((string[i]<='F')&&(string[i]>='A')) )
	    {
		   i++;     
		   count++;
		   if(i==len) break;
		 }                                  
	    while( i<len ) 
	       if(string[i]==' ')  i++; 
	       else break;
		if(i<len) return 0; 
	    if(count>2) return 0;
	    return 1; 
	  } 
}	 