// Advnext.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "tutorial.h"
#include "tmouse.h"
#include "mainfrm.h"
#include "time.h"
#include "TrcDlg.h"
#include "trcwnd.h"
                    
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif                       

extern BOOL g_mbCanDoNext;
extern BOOL g_bAuto;
extern g_bCanDoExit;
extern void PopupMenu(CMenu &menu);
extern void Delay(int nDelay,BOOL bShow=0);
/*-------------------------------------------------------*/
/*               Trace action                            */
/*-------------------------------------------------------*/  
void CMainFrame::AdvanceEvent()
{
  switch(m_uNextAction){
     case 1: 
        //m_Trace.EnableWindow(FALSE);
        m_Memory.EnableWindow(FALSE);
        Trace_Advance();
        if(g_bAuto)
        {
         SetSysMouse(1);
         SetSysKey(1);
   	     KillTimer(IDAUTO);
	     SetTimer(IDAUTO,5000,NULL);
	    }   
        break;

     case 2:
        m_pMsgWnd->SetContent("TRCTRC0.TXT");
        SetArrow(2,1,60);
        break;
     case 3:                
        Trace_Bus();
        break;
     case 4:
     case 5:
        Trace_Option(m_uNextAction);
        break;     
           
     case 6:        
        ((CAdvanceWnd *)m_pAdvanceWnd)->LoadMsg("TRACE_ONLY");
        break;             
        
     case 7:  
        Trace_Event();
        break;             

     case 8:                            
        ((CTrcDlg *)m_pDlg)->AdrRang(0);
        Delay(400,1);
        ((CTrcDlg *)m_pDlg)->AdrRang();
        break;                         
     case 9:
        Trace_Address_Range();
        break;                
     case 10:
        ((CTrcDlg *)m_pDlg)->AdrMult(0);
        Delay(400,1);
        ((CTrcDlg *)m_pDlg)->AdrMult();
        break;
     case 11:
        Trace_Address_Mult();
        break;
     case 12:
        ((CTrcDlg *)m_pDlg)->AdrWide(0);
        Delay(400,1);
        ((CTrcDlg *)m_pDlg)->AdrWide();
        m_pMsgWnd->SetContent("trcDATA.txt");
        break;
     case 13:
        Trace_Address_Status();
        break;
     case 14:
        Trace_Event3();
        m_uNextCaseID=ID_ADVANCE_TRACE;
        m_uNextAction=0;
        break;        

     default: 
        m_uNextCaseID=ID_ADVANCE_TRACE;
        m_uNextAction=0;
        break;
  }        
  
 SetMouse(1);           
}
                      
/*-------------------------------------------------------*/
/*             How to use source/inst model              */
/*-------------------------------------------------------*/
void CMainFrame::Trace_Advance()
{                  
  CRect r;  
  m_pMsgWnd->GetWindowRect(&r);
  if(r.Width()>200)
     {
        m_pMsgWnd->ShowWindow(SW_HIDE);
        m_pMsgWnd->SetTitle("TRACE");
        m_pMsgWnd->MoveWindow(WinCxy.x+430,WinCxy.y+50,200,350);
        m_pMsgWnd->SetContent("TRCTRC.TXT");
        m_pMsgWnd->Invalidate();
        m_pMsgWnd->ShowWindow(SW_SHOW);
      }     
        
        m_pAdvanceWnd=(CWnd *)new 
                      CAdvanceWnd(m_hFlookInst,"TRACE_ONLY");
        //PaintUpBitmap(25,50,"TRACE_ONLY");
   CRect rect(25,256,379+25-2,285);             
   ((CAdvanceWnd*)m_pAdvanceWnd)->CreateTrace(rect);

   Delay(100);   
   for(;rect.top>10;rect.top-=30)
       { 
         if(rect.top>10 && rect.top<=30)
            rect.top=10;     
            bCase2Paint=0;
            m_pAdvanceWnd->MoveWindow(rect.left,rect.top,
                                      rect.Width(),rect.Height());
         Delay(100);}
   Delay(1000);
      
}                              

void CMainFrame::Trace_Event3()
{
   ((CTrcDlg *)m_pDlg)->event3();
    m_pMsgWnd->SetContent("trceven3.txt");
   Delay(500,1);    
   SetArrow(4,1,60);
/*   
   CRect rect;  
   m_pMsgWnd->GetWindowRect(&rect); 
   rect.left-=210;
   rect.top+=60;
   rect.right=rect.left+200;
   rect.bottom=rect.top+50;
   CWindowDC dc(m_pDlg);
   MoveArrow( dc,rect,4 );  
   m_bDC=1;
*/
}    

void CMainFrame::Trace_Address_Status()
{
   Delay(100);
   m_pMsgWnd->SetContent("trcstat.txt");
   SetArrow(8,0,160);
/*   
   CRect rect;  
   m_pMsgWnd->GetWindowRect(&rect); 
   rect.left-=210;
   rect.top+=160;
   rect.right=rect.left+200;
   rect.bottom=rect.top+50;
   CWindowDC dc(m_pDlg);
   MoveArrow( dc,rect,8,0 );  
   m_bDC=1;
*/
}                                     

void CMainFrame::Trace_Address_Mult()
{
   Delay(100);
   m_pMsgWnd->SetContent("trcmult.txt");
   SetArrow(4,1,60);
/*   
   CRect rect;  
   m_pMsgWnd->GetWindowRect(&rect); 
   rect.left-=210;
   rect.top+=60;
   rect.right=rect.left+200;
   rect.bottom=rect.top+50;
   CWindowDC dc(m_pDlg);
   MoveArrow( dc,rect,4);  
   m_bDC=1;
*/   
}                                   

void CMainFrame::Trace_Address_Range()
{   
   Delay(100);
   m_pMsgWnd->SetContent("TRCAITEM.TXT");
   SetArrow(4,1,60);
}

void CMainFrame::Trace_Event()
{                       
 if(g_bAuto)
    KillTimer(IDAUTO);
	    
 g_mbCanDoNext=0;   

 CMenu menu;     
 PopupMenu(menu);
 SetSysFilter(1);
 SetMouse(0);
 SetKey(0);
 m_nMenuCount=10; 
 int nYPos= 290;
 SetCursorPoint(170,nYPos,55,8);
 SetTimer(MENUTIMER,400,NULL);
 menu.TrackPopupMenu(TPM_CENTERALIGN,200,100,
                     CWnd::FromHandle(m_hWndMDIClient));
        
 menu.DestroyMenu(); 
 m_pMsgWnd->SetTitleFont(28,12,1600);
        //int nHeight=36,int nWidth=18,int nWeight=1600);
 m_pMsgWnd->SetTitle("TRACE - EVENT");
 m_pMsgWnd->SetContent("TRCeven1.TXT");
 CTrcDlg *pDlg=new CTrcDlg(this);
 SetDlgWnd(pDlg);
 SetArrow(2,1,30);
 if(g_bAuto)
    SetTimer(IDAUTO,5000,NULL);
	    
 g_mbCanDoNext=1;   
                  
}


void CMainFrame::Trace_Option(int nCase)
{
 CMenu menu;
 PopupMenu(menu);
 SetSysFilter(1);
 SetMouse(1);
 SetKey(1);
 m_nMenuCount=nCase-1; 
 int nYPos= nCase==4 ? 146 : 158;
 SetCursorPoint(170,nYPos,55,8);
 SetTimer(MENUTIMER,400,NULL);
 menu.TrackPopupMenu(TPM_CENTERALIGN,200,100,
                     CWnd::FromHandle(m_hWndMDIClient));

 if(nCase==4)
 {
    ((CAdvanceWnd *)m_pAdvanceWnd)->LoadMsg("TRACE_INST");
	 CRect rect;                            
	 m_pMsgWnd->GetWindowRect(&rect); 
	 rect.left-=205;
	 rect.top += nCase==4? 160: 220;
	 rect.right=rect.left+200;
	 rect.bottom=rect.top+50;
	 Delay(400,1);          
	 CWindowDC dc(this);
	 MoveArrow(dc,rect,1);
 }   
    //PaintUpBitmap(25,50,"TRACE_INST",0);
 else 
   ((CAdvanceWnd *)m_pAdvanceWnd)->LoadMsg("TRACE_SRC");
    //PaintUpBitmap(25,50,"TRACE_SRC",0);

 menu.DestroyMenu(); 
 
} 
/*-------------------------------------------------------*/
/*             Trace bus                                 */
/*-------------------------------------------------------*/
void CMainFrame::Trace_Bus()
{
  SetSysFilter(1);
  CWindowDC dc(this);
  m_pMsgWnd->SetContent("TRCWIN.TXT");
/*
  for(int i=0;i<10;i++)
     {
       Delay(50);
       dc.PatBlt(m_rectDes.left+22,m_rectDes.top+5,
                 314,19,DSTINVERT);
      }          
      
  Delay(30);
*/  
  CRect rect;  
  m_pMsgWnd->GetWindowRect(&rect); 
  rect.left-=205;
  rect.top+=50;
  rect.right=rect.left+200;
  rect.bottom=rect.top+50;
  MoveArrow( dc,rect,12);  
  SetSysFilter(0);                  
 }