 
/***************************************************************************
**
**    $Header:   D:/EPSLDV1/SRC/LOG/TRCSERVE.H__   1.6   10 Jun 1996 10:23:14   ZJRD  $
**
**    $Log:   D:/EPSLDV1/SRC/LOG/TRCSERVE.H__  $
** 
**    Rev 1.6   10 Jun 1996 10:23:14   ZJRD
** EasyPack/SLD Version 1.20
** 
**    Rev 1.5   05 Jun 1996 14:57:40   ZJRD
** EasyPack/SLD Version 1.96
** 
**    Rev 1.4   29 May 1996 09:34:24   ZJRD
** EasyPack/SLD Version 1.95
** 
**    Rev 1.3   16 May 1996 08:59:50   ZJRD
** EasyPack/SLD Version 1.94
** 
**    Rev 1.2   10 May 1996 09:16:18   ZJRD
** No change.
** 
**    Rev 1.1   02 May 1996 10:30:40   ZJRD
** EasyPack/SLD Version 1.92
** 
**    Rev 1.31   18 Apr 1996 12:55:48   Shirley
** No change.
** 
**    Rev 1.30   12 Apr 1996 10:34:48   Shirley
** EasyPack/SLD Version 1.90
** 
**    Rev 1.28   15 Feb 1996 08:49:14   Shirley
** No change.
** 
**    Rev 1.27   12 Feb 1996 14:04:42   Shirley
** No change.
** 
**    Rev 1.26   06 Feb 1996 15:31:18   Shirley
** No change.
** 
**    Rev 1.25   06 Feb 1996 13:46:08   Shirley
** No change.
** 
**    Rev 1.24   01 Feb 1996 10:19:40   Shirley
** EasyPack/SLD Version 0.35b
** 
**    Rev 1.23   26 Jan 1996 09:16:32   Shirley
** No change.
** 
**    Rev 1.22   25 Jan 1996 13:16:26   Shirley
** No change.
** 
**    Rev 1.21   24 Jan 1996 10:34:20   Shirley
** No change.
** 
**    Rev 1.20   23 Jan 1996 11:28:50   Shirley
** EasypPack/SLD Version 0.34c
** 
**    Rev 1.18   15 Jan 1996 16:10:32   Shirley
** EasyPack/SLD Version 0.34a
** 
**    Rev 1.16   30 Nov 1995 09:13:14   Shirley
** No change.
** 
**    Rev 1.15   28 Nov 1995 15:35:32   Shirley
** No change.
** 
**    Rev 1.14   21 Nov 1995 11:23:36   Shirley
** No change.
** 
**    Rev 1.13   13 Nov 1995 09:25:58   Shirley
** No change.
** 
**    Rev 1.12   12 Nov 1995 11:29:40   Shirley
** No change.
** 
**    Rev 1.11   08 Nov 1995 16:33:04   Shirley
** No change.
** 
**    Rev 1.10   08 Nov 1995 12:45:02   Shirley
** No change.
** 
**    Rev 1.9   02 Nov 1995 10:03:34   Shirley
** No change.
** 
**    Rev 1.8   27 Oct 1995 16:46:44   Shirley
** No change.
** 
**    Rev 1.7   27 Oct 1995 13:44:18   Shirley
** No change.
** 
**    Rev 1.6   25 Oct 1995 14:26:06   Shirley
** No change.
** 
**    Rev 1.5   18 Oct 1995 14:48:48   Shirley
** EasyPack/SLD Version 0.1e
** 
**    Rev 1.4   13 Oct 1995 13:21:12   Shirley
** EasyPack/SLD Version 0.1d
** 
**    Rev 1.3   29 Sep 1995 09:49:08   Shirley
** No change.
** 
**    Rev 1.2   20 Sep 1995 10:57:34   Shirley
** EasyPack/SLD Version 0.1b
** 
**    Rev 1.1   15 Sep 1995 09:47:10   Shirley
** EasyPack/SLDV0.1a 
** 
**    Rev 1.0   07 Sep 1995 09:53:44   Shirley
** Initial revision.
**
****************************************************************************/

/***************************************************************************
**
** File name : TRCSERVE.H
** Author:BRIGHT CHEN, Chris Fang
** Description:
**
**
**    Finished date: 1995.9.1
**
**    Add date:1995.10.11
**        add  'void SetExcludeQualify(ULONG ulBegin,ULONG ulEnd);' to fix 
**        bug.
**
**    Copyright (C) 1995 Microtek International, Inc.
**    All Rights Reserved
**
****************************************************************************/


/////////////////////////////////
//trcserve.h
//Bright Cheng
//95/4
/////////////////////////////////
#ifndef _TRCSERVE_
#define _TRCSERVE_
#include "abitype.h"

#include "symblsvr.h"
#include <afx.h>
//Trcae server functions as an interface between ABI and shell or trace
// window.
#define MAX_TRC_LINE       128
#define MAX_INST_LINE      200   //max number of m_pTraceInfo
#define MAX_TRCWIN_LINE    50

#define STATUS_S 0  //refer to trace status john 95.7
#define STATUS_F 1
#define STATUS_R 2
#define STATUS_W 3
#define STATUS_AK 4
#define STATUS_S_F 7 //ONLY FOR 320 TRACE IN SW ANALYSE
#define GET_C_OK 1
#define GET_C_IS_LAST 0
#define GET_NOTHING_END -1
#define GET_NOTHING -2
#define NEED_MORE_FRAME -100
//used in file handle john 95.7
#define MAXCHARSALINE 600
#define FILEBUFFSIZE  2048

#define READFILEOK  2
#define READFILEEND 1
#define READFILENOTHING 0
#define GETSTRSMALL -1
#define GETSTRLARGER -2
#define GETSTROK 1

//ONLY FOR 320 trace 
#define STATUS_NORMAL 0 //first time to call getframe
#define STATUS_NORMAL_FOLLOW 1 //NORMAL REALLY
#define STATUS_MOVC 2  //has detected "movc"
#define STATUS_MOVC_GET_FETCH1 3 //has detected first fetch after "movc"(prefetch status_s)
#define STATUS_MOVC_GET_FETCH2 4 //has detected second fetch after "movc"
#define STATUS_MOVC_GET_FETCH3 5 //maybe has detected second fetch after "movc"

struct BusEvorQlfy
{
    WORD   setmode;         // no use.     may use as clearflag.
    BYTE   QlfyType[12];    // WORD (0-1), EVENT_ST_NO.-> ev1,ev2,ev3. 1,2,3.
                            //       or 0 means set qualify.
                            // WORD (2-3), EVENT_END_NO.  no use
                            // WORD (4-5), ADDR_QUALIFY->0:wildcard.xxxx
                            //                           01h:single.not use
                            //                           02h:other wildcard
                            // such as 2xxxh, 10xx10000001111x,
                            //                           10h:range
                            //                           20h:exclusive range
                            //                              ~10-20h
                            //                           40h:addr group
                            //WORD (6-7), DATA_QUALIFY->0:wildcard.xxxx
                            //                          01h:single.no baddr
                            //                          02h:other wildcard
                            //                          10h:range
                            //                          20h:exclusive range
                            //BYTE (8), STATUS_QUALIFY->0:not set , 1:set
                            //BYTE (9), EXTERN_QUALIFY
                            //BYTE(10),COUNT_QUALIFY->0:not set,1:set.only ev1
                            //BYTE(11),   reserved.
    DWORD  data1;           //start
    DWORD  data2;           //end   or mask for wildcard(0 means X)
    DWORD  status;          //SF:1h, FR:2h, RD:4h,WR:8h, AK:10h. or together.
    DWORD  extrn;
    DWORD  extMask;
    DWORD  count;           //only for ev1
    WORD   reserve[3];      // no use
    WORD   addrCount;
//    WORD   addr1[4];        //  BYTE   addr1[8]; start
//    WORD   addr2[4];        //  BYTE   addr2[8]; end or mask for wildcard(0:X)
//    WORD   addr3[4];        //  BYTE   addr3[8];
//    WORD   addr4[4];        //  BYTE   addr4[8];
//    WORD   addr5[4];        //  BYTE   addr5[8];
//    WORD   addr6[4];        //  BYTE   addr6[8];
//    WORD   addr7[4];        //  BYTE   addr7[8];
//    WORD   addr8[4];        //  BYTE   addr8[8];
//    WORD   addr9[4];        //  BYTE   addr9[8];
//    WORD   addr10[4];       //  BYTE   addr10[8];
    WORD   addr[10][4];
};

class CBusEvent
{
//constructor
public:
    CBusEvent(BYTE nEventID)
    {    m_eventID = nEventID;
         m_busEv.qlfyType[0] = m_eventID;
         m_tmpBusEv.qlfyType[0] = m_eventID;
         m_nClearflag = 1;
    }
    ~CBusEvent()
    {}

//member
public:
//    BusEvorQlfy   m_busEv;
    BUS_EVENT     m_busEv;
    BUS_EVENT     m_tmpBusEv;
    BYTE          m_eventID;            //only can be 1 or 2
    int           m_nClearflag;         //1=clear
    CString       m_strDisplay;         //for display on shell
    // added by john 95.8.10
    char * ArgPoint[35];
    int ArgMax;
//function          
private:                   
    void WildCardAddr(char *Input);
    void WildCardData(char *Input); 
    void SetAddr(int* indexhere);//analysis input for addr
    void SetData(int* indexhere);//analysis input for data
    void SetStatus(int* indexhere);//analysis input for status
public:               
    void ShellCmd(int nArgc, char* pszArgv[]);
    void ShowToShell();
    void Clear();
    void SetbyShell();
    int Init();
};

class CExtEvent
{
//contructor
public:
    CExtEvent()
    {
        m_extEv.qlfyType[0] = 3; 
        m_tmpExtEv.qlfyType[0] = 3;
        m_nClearflag = 0;      
        m_nStatusflag=0;
    }
    ~CExtEvent()
    {}

//member
public:
    int           m_nClearflag;           // 1=clear
    DWORD         m_nStatusflag;          // 0=low; 1=high
//    BusEvorQlfy   m_extEv;
    BUS_EVENT     m_extEv;
    BUS_EVENT     m_tmpExtEv;
    CString       m_strDisplay;
    // added by john 95.8.10
    char * ArgPoint[35];
    int ArgMax;

//function
public:              
    void ShellCmd(int nArgc, char* pszArgv[]);
    void ShowToShell();
    void Clear();
    void SetbyShell();
    int Init();
};

struct Trigger
{
    unsigned char TrigFlg;      // 0 delay count
                                // 1 foreward
                                // 2 backward
                                // 3 center
    unsigned char RunFlg;       // 0 without run
                                // with run
    DWORD DlayCnt;     // delay count(TrigFlg=0 used)
    WORD LevelCount ;
    WORD LevelID[4];            // level ID list
//Level1                     LevelCount = 1; LevelID[0] = 1
//Level2                     LevelCount = 1; LevelID[0] = 2
//Level1 then Level2         LevelCount = 2; LevelID[0] = 1, Level[2] =2;
//Level2 then Level1         LevelCount = 2; LevelID[0] = 2, Level[2] =1;
};

struct TrigLevel
{
    unsigned char TraceFlg; // 0 trace unchanged
                            // 1 trace ON
                            // 2 trace OFF
    unsigned char TimerFlg; // 0 timer unchanged
                            // 1 timer ON
                            // 2 timer OFF
    DWORD Condition ;    // condition list
                            // EV1  AAAAAAAAH
                            // EV2  CCCCCCCCH
                            // EV3  F0F0F0F0H
                            // EV4  FF00FF00H
                            // EV5  FFFF0000H
                            // EV1 OR EV2
                            // EEEEEEEE H
                            // EV2 AND EV3
                            // C0C0C0C0H
                            // EV3 AND EV4 AND EV5
                            // F0000000H
                         //end of condition list

};

class CLevel
{
//constructor
public:
    CLevel(int nLevelID)
    {  
      m_nLevelID = nLevelID;
      //added by john 95.7         // default level settings
      
      m_levelStruct.TraceFlg=1;           
      m_levelStruct.TimerFlg=1;
      m_levelStruct.Condition=0xfefefefe;
       
      if(1==m_nLevelID)
      {
       m_levelStruct.TraceFlg=1;           
       m_levelStruct.TimerFlg=1;
       m_levelStruct.Condition=0xfefefefe;
       } else
        {
         m_levelStruct.TraceFlg=1;           
         m_levelStruct.TimerFlg=1;
         m_levelStruct.Condition=0xfefefefe;
         }
      }
         
    ~CLevel()
    {}

//member
public:
    int                m_nLevelID;            // 1 or 2
    struct TrigLevel   m_levelStruct;    //only used for GongGong john 95.7
    struct TrigLevel   m_levelStructSave; //added by john 95.7 
    CString            m_strDisplay;    
    //added by john 95.7        
    CString m_strDisp;
    char * ArgPoint[12];
    int ArgMax;
//function
public:
//since the default setting of level1 is ev1 or ev2 or ev3,
//we may need a Initialize() to set member.
    void ShowToShell();
    void SetbyShell(int nArgc,char* pszArgv[]);
    int Init();
private://added by john 95.7
    void SetEvLogic(int* indexhere);
    void SetTraceStatus(int* indexhere);
    void SetTimerStatus(int *indexhere);  
};

class CTrigger
{
//constructor
public:
    CTrigger()
    {
        m_strDisplay1 = "";
        m_strDisplay2 = "";             
        m_nOnOffFlg=1;
        m_nTmpOnOffFlg=1;
        m_tmpTrig.TrigFlg=0;
        m_tmpTrig.RunFlg=0;   
        m_tmpTrig.DlayCnt=0;
        m_tmpTrig.LevelCount=1;
        m_tmpTrig.LevelID[0] = 1;
    }
    ~CTrigger()
    {}
//member
public:
    BYTE     m_nOnOffFlg;       //1=On
    BYTE     m_nTmpOnOffFlg;
    Trigger  m_trig;   
    Trigger  m_tmpTrig;         //added 95.8
    CString  m_strDisplay1;     //for trigger logic
    CString  m_strDisplay2;     //for trigger status
// added by john 95.8.10
    char * ArgPoint[35];
    int ArgMax;     
//function
public:                                       
    void ShellCmd(int nArgc, char* pszArgv[]);
    void ShowToShell();
    void SetbyShell();
    int Init();                     
private:
    void SetLevel(int * indexhere);    

};

class CQualify
{
//constructor
public:
    CQualify()
    {
     m_nClearflag = 1;
     m_qlfy.qlfyType[0]=0;
     m_tmpQlfy.qlfyType[0]=0;
     }
    ~CQualify()
    {}
//member
public:
    int          m_nClearflag;
//    BusEvorQlfy  m_qlfy;
    QUALIFY      m_qlfy;        
    QUALIFY      m_tmpQlfy; //added 95.8
    CString      m_strDisplay;
// added by john 95.8.10
    char * ArgPoint[35];
    int ArgMax;    
//function
public:
    void ShellCmd(int nArgc, char* pszArgv[]);
    void ShowToShell();
    void Clear();                     //by shell
    void SetbyShell();
    int Init();
private:
    void WildCardAddr(char *Input);
    void WildCardData(char *Input); 
    void SetAddr(int* indexhere);//analysis input for addr
    void SetData(int* indexhere);//analysis input for data
    void SetStatus(int* indexhere);//analysis input for status

};

struct FrameData
{
    WORD       phisicalNo;
    char       frameNo[5];
    char       addr[5];
    char       data[3];
    char       status[3];
    char       spare[6];
    char       portdata[3];
};

struct FrameInst
{
    WORD  phisicalNo;
    char  frameNo[5];
    char  addr[5];
    unsigned char  instruction[128];
};                         

struct FrameC
{
    WORD  phisicalNo;
    char  frameNo[5];
    char  line[10];
    unsigned char  c[256];
};

//john 95.7                                      
struct LineInfo
   {
      int   refertime;
      U32   module;
      UINT linenum;
      char* psrcline;
      public:
      LineInfo()
      {
         refertime=0;
         module=0;
         linenum=0;
         psrcline=NULL;
      }
   };

  
class CSrcFile
{
private:
   const int   m_nBuffers;          //max line info that can be store
   const int   m_nRefInc;           //the value to add to reference flag
                              //when a line is reference.
   const int   m_nAddLines;         //max line number when read from a
                              //file each time.
   int         m_nUsedBufs;
   LineInfo*   m_Buffer;
   
private:
   void     ModifyRefer(int index);
   void     Remove(int index);
   BOOL     GetIndex(U32 module, UINT line, int& index);
   int         DelOld(void);
   BOOL     AddNew(U32 module, UINT line);

public:
//construction and destruction:
   CSrcFile();
   ~CSrcFile();

//interface routine with outside    
   BOOL  GetALine(U32 openModule, UINT line , char * str);
};
 
class CListTrace
{
//constructor:
public:
    CListTrace();
    ~CListTrace();
//member
public:
    TRACE_INFO *   m_pTraceInfo;
    FrameData *   tmpTrcData;
    FrameData *   tmpTrcData2;
    WORD          m_lastFrameNo;
    WORD          m_lastQlfyNo;
    FrameInst *    tmpTrcInst;
    FrameInst *    tmpTrcInst2; 
    FrameC * tmpTrcC;
    FrameC * tmpTrcC2;
    QUALIFY FrameQualify;  //john 95.5                
    //added by john 95.7
    char * ArgPoint[35];
    int ArgMax;
    
private://added by john 95.7
    int readDirect;
    WORD BeginFrameNo;
    WORD EndFrameNo;
    WORD AbiFrameNum;  
    WORD RecordFrameStart;
    
    BOOL dataValid;
    BOOL instValid;
    BOOL cValid;
    WORD dataLen;
    WORD instLen;
    WORD cLen; 
    
    char *strTmpTmp;
    char *strTmpShow;               
    unsigned char sTatus320;//added by john 96.1 for 320
    void (CListTrace::* GetFrame) (WORD howMuch=0);//added by john 96.1 to seperate 
                               //320 trace from others
                               //if 320 GetFrame point to GetAbiFrame320()
                               // else GetFrame point to GetAbiFrame() 
//function:
public:       
    BOOL ListTrcDataToWnd(int readDirect,WORD* beginNo,WORD* endNo,
                          WORD* LineCount,FrameData* frameData);
                          
    BOOL ListTrcInstToWnd(int readDirect,WORD* beginNo,WORD* endNo,
                          WORD* LineCount,FrameInst* frameInst);
    BOOL ListTrcCToWnd(int readDirect,WORD* beginNo,WORD* endNo,
                          WORD* LineCount,FrameC* frameC);  
// readDirect    : -2   pageup. LineCount = current page line of Wnd.
//               : -1   lineup  LineCount = current page line of Wnd.
//               : 0    LineCount=pageline.Get the full screen before&behind
//               : 1    linedown
//               : 2    pagedown
//LineCount from Lane, return the real LineCount from ICE trace.
//beginNo,page beginNo, from Lane, return the real start begin frame no.
//end no ,page endNO, from Lane, return the real end frame no.
    //editted by john 95.7
    void CmdShell(int nArgc, char* pszArgv[]);
    void CmdShellx();//no use
    //BOOL GetLastFrame();
    //added by john for elapse time 96.1.30
    //marked by chris 96.5.10
//    STATUS GetElapseTime(unsigned short &day,unsigned short &hour,
//                   unsigned short &minute,unsigned short &second,
//                   unsigned short &ms,unsigned short &us);
    
private://added by john 95.7                                  
    void WildCardAddr(char *Input);
    void WildCardData(char *Input); 
    void SetAddr(int* indexhere);//analysis input for addr
    void SetData(int* indexhere);//analysis input for data
    void SetStatus(int* indexhere);//analysis input for status
    void GetAbiFrame(WORD howMuch=0);  //control all getting of abigetframe
                         //when it return it change the BeginFrameNo automatically
                         //and fille the trace buff from RecordFrameStart with information from ABI
                         //at same time it set the AbiFrameNum
                         //howMuch defines the number of frames to be read
                         //default 0 refers to max number define in const
    void GetAbiFrame320(WORD howMuch=0);  //control all getting of abigetframe
                         //when it return it change the BeginFrameNo automatically
                         //and fille the trace buff from RecordFrameStart with information from ABI
                         //at same time it set the AbiFrameNum
                         //howMuch defines the number of frames to be read
                         //default 0 refers to max number define in const                         
                         //added by john 96.1 only for module 320
    BOOL GetAsmStr(WORD *FramePoint,unsigned char *AsmResult);
                         //get a string from DAD,the FramePoint
                         //indicates where to start and when the
                         //function returns it's value will change 
                         //to next un-analysis Frame which status must be "S"
                         //RETURN VALUE REFERS TO WHETHER IT GET A ASM STR
    BOOL GetCStrNum(WORD *FramePoint,WORD *NextAddr,U16 * line , U32 * module);
                         //get information about a first valid string form C source on disk,             
                         //NextAddr return the next valid C source line address if return value is true        
                         //the FramePoint will be changed to first frame which can get a source line
                         //RETURN true refers  GET_C_IS_LAST 0 
                         //                    GET_C_OK 1
                         //                    GET_NOTHING_END -1
                         //                    GET_NOTHING -2
    BOOL GetCStr(U16 line , U32 module,char * str);                     
                         //return true if Get ok;
    void ListTrcDataToShell();// dispatch by listcmd
    void ListTrcAsmToShell(); //                           
    void ListTrcCToShell();   //
    void ListTrcMixToShell(); //                         
    void ListTrcModuleToShell(); 
    //used in show in windows 95.8                               
    void GetDataForWin(BOOL isUp,unsigned short &beginPos,
            unsigned short &endPos,unsigned short &length);//true for direction -1 or -2
    void GetAsmForWin(BOOL isUp,unsigned short &beginPos,
            unsigned short &endPos,unsigned short &length);
    void GetCForWin(BOOL isUp,unsigned short &beginPos,
            unsigned short &endPos,unsigned short &length);        
    //used to make the listing source quickly        
    void SetExcludeQualify(WORD ulBegin,WORD ulEnd,BOOL exClude);
    
};



BOOL ListTrcDataToWnd(int readDirect,WORD* beginNo,WORD* endNo,
                        WORD* LineCnt,FrameData* frameData);
BOOL ListTrcInstToWnd(int readDirect,WORD* beginNo,WORD* endNo,
                        WORD* LineCnt,FrameInst* frameInst);

void  SaveAllConfig(void);
void  RestoreAllConfig(void);
BOOL GetElapseTime(CString& etime, int fromshell=0);

//added by john 95.7
int InitLevel();
void LevelCmd(int nArgc, char* pszArgv[]);                

extern void DisplayErrorMessage(int);
extern int  TestKey(WORD);
extern void ShowLine(char*);
extern STATUS AbiClrEvent(int evId);
extern STATUS AbiSetEvent(/*BusEvorQlfy*/BUS_EVENT busEvData);

extern STATUS AbiSetTrigStatus(FLAG uTraceFlag);
extern STATUS AbiSetTrigLevel(int levelId, TRIGGER_LEVEL trigLevelData);
extern STATUS AbiSetTrigLogic(TRIGGER_LOGIC trigLogicData);
extern STATUS AbiGetTraceBuffer(UINT readDirect, UINT startFrame, UINT endFrame,
                         /*BusEvorQlfy*/QUALIFY Qualify,
                         TRACE_INFO* traceInfo, BYTE* frameNum,BYTE* readEnd);
extern STATUS AbiSetQualify(/*BusEvorQlfy*/QUALIFY qlfy);
extern STATUS AbiClrQualify();
extern STATUS AbiGetTraceLastFrame(UINT*);
extern STATUS AbiSetTimerStatus(FLAG uTimerFlag);
extern STATUS AbiSetTraceStatus(FLAG uTimerFlag);
extern STATUS AbiSetPort(PARA_PORT port);

//added by john 96.1.19 to support trace for 320
//NO USE TODAY 96.1.22
extern "C"
{
unsigned char WINAPI _export TRCGetCycleLen320(unsigned char instruction);
 }

#endif

//////////////////////////////(EOF)//////////////////////////////////
