
/***************************************************************************
**
**    $Header:   D:/ECB2S/SRC/LOG/BMEMVIEW.CPP   1.2.1.5   17 Apr 1997 15:42:02   ZJRD  $
**
**    $Log:   D:/ECB2S/SRC/LOG/BMEMVIEW.CPP  $
** 
**    Rev 1.2.1.5   17 Apr 1997 15:42:02   ZJRD
** No change.
** 
**    Rev 1.2.1.4   16 Apr 1997 10:16:08   ZJRD
** No change.
** 
**    Rev 1.2.1.3   10 Apr 1997 15:28:00   ZJRD
** 2.09F
** 
**    Rev 1.2.1.1   03 Apr 1997 15:09:40   ZJRD
** No change.
** 
**    Rev 1.2.1.0   28 Mar 1997 10:14:38   ZJRD
** easy pack sld 2.09d
** 
**    Rev 1.1   19 Mar 1997 11:25:56   ZJRD
** No change.
** 
**    Rev 1.0   12 Mar 1997 14:44:42   ZJRD
** Initial revision.
** 
**    Rev 1.7.1.0.1.2   09 Dec 1996 10:15:20   ZJRD
** EasyPack/SLD Version 2.0P
** 
**    Rev 1.7.1.0.1.0   11 Nov 1996 12:58:36   ZJRD
** EasyPack/SLD Version 2.01
** 
**    Rev 1.7.1.4   09 Sep 1996 13:16:12   ZJRD
** No change.
** 
**    Rev 1.7.1.3   05 Sep 1996 11:27:46   ZJRD
** No change.
** 
**    Rev 1.7.1.2   02 Sep 1996 09:54:52   ZJRD
** No change.
** 
**    Rev 1.7.1.1   28 Aug 1996 15:50:20   ZJRD
** No change.
** 
**    Rev 1.7.1.0   12 Aug 1996 10:54:22   ZJRD
** EasyPack/SLD Version 1.98
** 
**    Rev 1.6.1.0   19 Jul 1996 09:55:44   ZJRD
** EasyPack/SLD Version 1.20b
** 
**    Rev 1.8   20 Jun 1996 09:29:00   ZJRD
** EasyPack/SLD Version 1.20a
** 
**    Rev 1.6   10 Jun 1996 10:23:38   ZJRD
** EasyPack/SLD Version 1.20
** 
**    Rev 1.4   29 May 1996 09:35:00   ZJRD
** EasyPack/SLD Version 1.95
** 
**    Rev 1.3   16 May 1996 09:08:04   ZJRD
** No change.
** 
**    Rev 1.2   10 May 1996 09:09:36   ZJRD
** No change.
** 
**    Rev 1.1   02 May 1996 10:25:30   ZJRD
** EasyPack/SLD Version 1.92
** 
**    Rev 1.31   18 Apr 1996 13:00:10   Shirley
** EasyPack/SLD Version 1.91
** 
**    Rev 1.30   12 Apr 1996 10:35:30   Shirley
** EasyPack/SLD Version 1.90
** 
**    Rev 1.28   15 Feb 1996 08:50:44   Shirley
** No change.
** 
**    Rev 1.27   12 Feb 1996 14:05:24   Shirley
** No change.
** 
**    Rev 1.26   06 Feb 1996 15:31:58   Shirley
** No change.
** 
**    Rev 1.25   06 Feb 1996 13:45:10   Shirley
** No change.
** 
**    Rev 1.24   01 Feb 1996 10:17:58   Shirley
** No change.
** 
**    Rev 1.23   26 Jan 1996 09:20:36   Shirley
** No change.
** 
**    Rev 1.22   25 Jan 1996 13:20:30   Shirley
** No change.
** 
**    Rev 1.21   24 Jan 1996 10:37:48   Shirley
** No change.
** 
**    Rev 1.20   23 Jan 1996 11:23:16   Shirley
** EasypPack/SLD Version 0.34c
** 
**    Rev 1.19   18 Jan 1996 10:12:44   Shirley
** No change.
** 
**    Rev 1.18   15 Jan 1996 16:15:42   Shirley
** No change.
** 
**    Rev 1.17   04 Jan 1996 11:09:30   Shirley
** No change.
** 
**    Rev 1.16   30 Nov 1995 09:11:02   Shirley
** No change.
** 
**    Rev 1.15   28 Nov 1995 15:30:10   Shirley
** No change.
** 
**    Rev 1.14   21 Nov 1995 11:20:24   Shirley
** No change.
** 
**    Rev 1.13   13 Nov 1995 09:28:10   Shirley
** No change.
** 
**    Rev 1.12   12 Nov 1995 11:29:58   Shirley
** EasyPack/SLD Version 0.24
** 
**    Rev 1.11   08 Nov 1995 16:33:10   Shirley
** No change.
** 
**    Rev 1.10   08 Nov 1995 12:43:28   Shirley
** No change.
** 
**    Rev 1.9   02 Nov 1995 10:05:32   Shirley
** No change.
** 
**    Rev 1.8   27 Oct 1995 16:49:38   Shirley
** No change.
** 
**    Rev 1.7   27 Oct 1995 13:49:02   Shirley
** No change.
** 
**    Rev 1.6   25 Oct 1995 14:28:38   Shirley
** EasyPack/SLD Version 0.1f
**
**    Rev 1.4   13 Oct 1995 13:18:26   Shirley
** No change.
**
**    Rev 1.3   29 Sep 1995 09:47:50   Shirley
** No change.
**
**    Rev 1.2   20 Sep 1995 10:58:10   Shirley
** No change.
**
**    Rev 1.1   15 Sep 1995 09:48:48   Shirley
** EasyPack/SLDV0.1a
**
**    Rev 1.0   07 Sep 1995 09:54:00   Shirley
** Initial revision.
**
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
//
//  File name:  BMEMVIEW.CPP
//
//  Description:The implement file for the class: CBMemoryView
//
//  Author:     Lane Li         &       Daniel Lin
//
//  Date:       09/10/95
//
//  Modification:
//
//      1. 10/19/95, Initial version
//              modified function
//  Modification:
//
//      1. 09/10/95, Initial version
//
//
//  Copyright (C) 1995 Microtek International. All rights reserved.
//
/////////////////////////////////////////////////////////////////////////////

// bmemview.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "uicom.h"
#include "xview.h"
#include "bmemwnd.h"
#include "bmemview.h"
#include "grid.h"
#include "nwmemwnd.h"
#include "nwmem.h"

#include "btnbar.h"
#include "mainfrm.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

extern long MemServerDump(BYTE*, long, long, int);
extern int MemServerFill(long, BYTE, int);

extern BOOL GetSFRBYTEName(BYTE bAddr,CString &strName );
extern BOOL GetSFRBitName(BYTE bAddr,CString &strName );
extern BOOL GetCpuStatus(unsigned char & uchStatus);

void CBMemoryView::SetMyCaret()
{
     POINT pos = GetScrollPosition();
     pos.x = m_nTextBegin + m_pointCaret.x*m_nDxWidth;
     pos.y = m_pointCaret.y*m_nDxHeight - pos.y + 1;
     SetCaretPos(pos);
}

BOOL CBMemoryView::IsCaretIn()
{
     POINT pos;
     RECT rect;
     int y1,y2;

     pos = GetScrollPosition();
     GetClientRect(&rect);

     if ((pos.y%m_nDxHeight)>0) y1=pos.y/m_nDxHeight + 1;
     else y1 = pos.y/m_nDxHeight;

     y2 = (pos.y+rect.bottom)/m_nDxHeight-1;

     if ((y1<=m_pointCaret.y)&&(m_pointCaret.y<=y2)) return TRUE;
     else return FALSE;
}

void CBMemoryView::SwitchBit(POINT pos)
{
        BYTE value,value2;
        //value = m_bBitMem[pos.y*8+pos.x];
        
        value = m_bBitMem[pos.y*8+(7-pos.x)];      // Modify by Daniel Lin
                                                   // on 5.20.1996
        
        BeginWaitCursor();
        if (value&0x1) value = 0;
        else value = 1;

#ifndef _NOABI
        //MemServerFill((long)(pos.y*8+pos.x), value, 5);
        MemServerFill((long)(pos.y*8+(7-pos.x)), value, 5);
        //MemServerDump(&value2, (long)(pos.y*8+pos.x), 1, 5);
        MemServerDump(&value2, (long)(pos.y*8+(7-pos.x)), 1, 5);
#endif
        //m_bBitMem[pos.y*8+pos.x] = value2;
        m_bBitMem[pos.y*8+(7-pos.x)] = value2;        
        if (value!=value2) 
          MessageBeep(-1);
        else {
          if (isMemOn[0]&&(((CMemoryWindow *)pMemWnd[0])->m_nSpaceType==3)) {
             pMemWnd[0]->InvalidateRect(NULL,FALSE);
          }
          if (isMemOn[1]&&(((CMemoryWindow *)pMemWnd[1])->m_nSpaceType==3)) {
             pMemWnd[1]->InvalidateRect(NULL,FALSE);
          }
          if (isMemOn[2]&&(((CMemoryWindow *)pMemWnd[2])->m_nSpaceType==3)) {
             pMemWnd[2]->InvalidateRect(NULL,FALSE);
          }
        }

// Add by Daniel Lin on 5.23.1996
//        
#ifndef _NOABI
        MemServerDump(m_bBitMem, 0, 0xf8, 5);
#endif
        InvalidateRect(NULL, TRUE);
        
        EndWaitCursor();        
}

/////////////////////////////////////////////////////////////////////////////
// CBMemoryView

IMPLEMENT_DYNCREATE(CBMemoryView, CScrollView)

CBMemoryView::CBMemoryView()
{
     m_pParent = NULL;
     m_nTextBegin = 30;
     m_nDxWidth = 15;
     m_nDxHeight = 15;
     m_pointCaret.x = 0;
     m_pointCaret.y = 0;

     m_bBitMem = new BYTE[0xff];
     int i;
     for(i=0;i<0xff;i++)  m_bBitMem[i]=1;
}

CBMemoryView::~CBMemoryView()
{
   if ( NULL != m_bBitMem )
      delete []m_bBitMem;
}

BEGIN_MESSAGE_MAP(CBMemoryView, CScrollView)
     //{{AFX_MSG_MAP(CBMemoryView)
     ON_WM_CREATE()
     ON_WM_SIZE()
     ON_WM_LBUTTONDOWN()
     ON_WM_VSCROLL()
     ON_WM_KEYDOWN()
     ON_WM_KEYUP()
     ON_WM_LBUTTONDBLCLK()
     ON_COMMAND(ID_EDIT_BIT, OnEditBit)
     ON_UPDATE_COMMAND_UI(ID_EDIT_BIT, OnUpdateEditBit)
     ON_WM_SETFOCUS()
     ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
     ON_WM_RBUTTONDOWN()
     ON_WM_NCHITTEST()
     //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CBMemoryView drawing

void CBMemoryView::OnInitialUpdate()
{
        CScrollView::OnInitialUpdate();

        CSize sizeTotal;
        // TODO: calculate the total size of this view
        RECT rect;
        SIZE size1,size2;

        sizeTotal.cx = 0; // Modify by Daniel
        sizeTotal.cy = m_nDxHeight*31;
        size1.cx = 0;     // Modify by Daniel
        size1.cy = m_nDxHeight*3;
        size2.cx = 0;     // Modify by Daniel
        size2.cy = m_nDxHeight;
        SetScrollSizes(MM_TEXT, sizeTotal,size1, size2);

        m_pParent = GetParent();
        ((CBMemoryWindow *)m_pParent)->m_pView = this;
        m_pParent->GetWindowRect(&rect);

        m_pParent->MoveWindow(rect.left,
                rect.top,
                rect.right-rect.left+1,
                rect.bottom-rect.top+1);

#ifndef _NOABI
        MemServerDump(m_bBitMem, 0, 0xf8, 5);
#endif
        //InvalidateRect(NULL, TRUE);
}

void CBMemoryView::OnDraw(CDC* pDC)
{
        CDocument* pDoc = GetDocument();
        // TODO: add draw code here
        int i,j,addr;
        BYTE byte;
        WORD value;
        char buf[20];
        RECT rect1,rect2;
        int lpDxWidths[8];
        //RECT rect;
        char *regName = NULL;
        CString strName;
        
        pDC->SetMapMode(MM_TEXT);
        pDC->SelectStockObject(ANSI_FIXED_FONT);

        pDC->MoveTo(m_nTextBegin-4,0);
        pDC->LineTo(m_nTextBegin-4,m_nDxHeight*31);

        for(i = 0; i < 8; i++) lpDxWidths[i]=m_nDxWidth;

        addr = 0;
        rect1.left = 0;
        rect1.top = 0;
        rect1.right = m_nTextBegin-5;
        rect1.bottom = m_nDxHeight;

        GetClientRect(&rect2);
        rect2.left = m_nTextBegin;
        rect2.top = 0;
        rect2.bottom = m_nDxHeight;
        int regNo;
        for(regNo = 0; regNo < 31; regNo++) {
           sprintf(buf,"%02X",(regNo*8));
           pDC->ExtTextOut(rect1.left+5,rect1.top,
                           ETO_CLIPPED|ETO_OPAQUE,
                           &rect1,
                           buf,
                           2,
                           NULL);
           rect1.top+=m_nDxHeight;
           rect1.bottom+=m_nDxHeight;
   
           value = 0;
           for ( j = 0; j <= 7; j++ ) {
               byte = m_bBitMem[regNo*8+j];
               byte <<= (7-j);
               value = value + byte;
           }
           value |= 0x100;
           _itoa(value,buf,2);
           // Add by Daniel Lin on 5.20.1996 for the FAX on 5.16.96
           //
           int bufLen = strlen( buf );
           char buf2[20];
           memset( buf2, 0, 20 );
           
           for (int ii = bufLen; ii > 0; ii-- )
              buf2[bufLen-ii] = buf[ii-1];  
              
           pDC->ExtTextOut(rect2.left,rect2.top,
                           ETO_CLIPPED|ETO_OPAQUE,
                           &rect2,
                           //buf+1,
                           buf2,
                           8,
                           lpDxWidths);
           
           // For write the SFR byte name
           // Add by Daniel Lin on 5.20.1996
           //                
           
           int NameLeft = rect2.left + 8*m_nDxWidth+25;
           
           RECT nameRect = rect2;
           nameRect.left += 8*m_nDxWidth+25;
           
           BYTE bAddr = BYTE(regNo*8);
           BOOL bGetOk = FALSE;
         
           bGetOk = GetSFRBYTEName(bAddr, strName ); 
           if ( bGetOk ) {
              regName = new char[strName.GetLength() + 2];   
              strcpy( regName, strName.GetBuffer( strName.GetLength() ) );
           }
           else {
              regName = new char[5];       
              strcpy( regName, " " );
           }
           pDC->ExtTextOut(NameLeft, rect2.top,
                           ETO_CLIPPED|ETO_OPAQUE,
                           &nameRect,
                           regName,
                           strlen( regName ),
                           NULL);
           if (NULL != regName) delete []regName;
                       
           rect2.top += m_nDxHeight;
           rect2.bottom += m_nDxHeight;
        }
        
//      SetCaretPos(m_pointCaret);

}

/////////////////////////////////////////////////////////////////////////////
// CBMemoryView message handlers


int CBMemoryView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
     if (CScrollView::OnCreate(lpCreateStruct) == -1)
        return -1;

     // TODO: Add your specialized creation code here
     CreateSolidCaret(2,11);
     ShowCaret();

     POINT pos;
     pos.x = m_nTextBegin + m_pointCaret.x*m_nDxWidth;
     pos.y = m_pointCaret.y*m_nDxHeight + 1;
     SetCaretPos(pos);

     return 0;
}

void CBMemoryView::OnSize(UINT nType, int cx, int cy)
{
   CScrollView::OnSize(nType, cx, cy);

   // TODO: Add your message handler code here
   if (m_pParent!=NULL)
     m_pParent->InvalidateRect(NULL,TRUE);
}

void CBMemoryView::OnLButtonDown(UINT nFlags, CPoint point)
{
        // TODO: Add your message handler code here and/or call default
   POINT pos;

   if (point.x>=(int)m_nTextBegin)
      m_pointCaret.x = (point.x-m_nTextBegin+(m_nDxWidth/4))/m_nDxWidth;

   pos = GetScrollPosition();
   m_pointCaret.y = (point.y+pos.y)/m_nDxHeight;

   if (m_pointCaret.x<0) m_pointCaret.x = 0;
   if (m_pointCaret.x>7) m_pointCaret.x = 7;
   if (m_pointCaret.y<0) m_pointCaret.y = 0;
   if (m_pointCaret.y>30) m_pointCaret.y = 30;

   pos.x = m_nTextBegin + m_pointCaret.x*m_nDxWidth;
   pos.y = m_pointCaret.y*m_nDxHeight - pos.y + 1;
   SetCaretPos(pos);
   
   // Add on 5.17.96 & 5.20.96 by Daniel Lin
   //
   char *regName = NULL;
   CString strName;
   
   BYTE bAddr = BYTE(m_pointCaret.y*8+(7-m_pointCaret.x));
   BOOL bGetOk = FALSE;
   
   bGetOk = GetSFRBitName(bAddr, strName );   
   if ( bGetOk ) {
      regName = new char[strName.GetLength() + 2];   
      strcpy( regName, strName.GetBuffer( strName.GetLength() ) );
   }
   else {
      regName = new char[5];      
      strcpy( regName, " " );
   }
   
   CBMemoryWindow *frame = (CBMemoryWindow *)GetParent();
   strncpy( frame->m_strRegName, regName, strlen( regName ) );
   frame->WriteRegName( regName );
   if (NULL != regName) delete []regName;
   frame->m_pointCaret.x = m_pointCaret.x;
   frame->m_pointCaret.y = m_pointCaret.y;
            
   CScrollView::OnLButtonDown(nFlags, point);
}

void CBMemoryView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
        // TODO: Add your message handler code here and/or call default
        //UINT pos;
   switch (nSBCode) {
      case SB_THUMBTRACK:
//            Invalidate();
            break;
                        
      case SB_THUMBPOSITION:
            Invalidate();      
            break;
            
      default:
            break;
   }

   CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}  

void CBMemoryView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
        // TODO: Add your message handler code here and/or call default
   POINT pos;
   BOOL bIn;
   unsigned char uchCpuStatus;
   
   if (GetCpuStatus(uchCpuStatus)) {
     if ( 1 != uchCpuStatus ) {       // Is on GO status (STATUS_GO)
        switch (nChar) {
                case VK_RIGHT:
                        m_pointCaret.x++;
                        if (m_pointCaret.x>7) m_pointCaret.x = 7;
                        if (!IsCaretIn()) {
                          pos.x = 0;
                          pos.y = m_pointCaret.y * m_nDxHeight;
                          ScrollToPosition(pos);
                        }
                        break;
                        
                case VK_LEFT:
                        m_pointCaret.x--;;
                        if (m_pointCaret.x<0) m_pointCaret.x = 0;
                        if (!IsCaretIn()) {
                          pos.x = 0;
                          pos.y = m_pointCaret.y * m_nDxHeight;
                          ScrollToPosition(pos);
                        }
                        break;
                        
                case VK_UP:
                        bIn = IsCaretIn();
                        m_pointCaret.y--;
                        if (m_pointCaret.y<0) m_pointCaret.y = 0;
                        if (bIn) {
                          if (!IsCaretIn()) {
                            pos = GetScrollPosition();
                            pos.y -= m_nDxHeight;
                            if (pos.y<0) pos.y=0;
                            ScrollToPosition(pos);
                          }
                        }
                        else {
                          if (!IsCaretIn()) {
                            pos.x = 0;
                            pos.y = m_pointCaret.y * m_nDxHeight;
                            ScrollToPosition(pos);
                          }
                        }
                        break;
                        
                case VK_DOWN:
                        bIn = IsCaretIn();
                        m_pointCaret.y++;
                        if (m_pointCaret.y>30) m_pointCaret.y = 30;
                        if (bIn) {
                          if (!IsCaretIn()) {
                            pos = GetScrollPosition();
                            pos.y += m_nDxHeight;
                            ScrollToPosition(pos);
                          }
                        }
                        else {
                          if (!IsCaretIn()) {
                            pos.x = 0;
                            pos.y = m_pointCaret.y * m_nDxHeight;
                            ScrollToPosition(pos);
                          }
                        }
                        break;
                        
                case VK_PRIOR:
                        bIn = IsCaretIn();
                        pos = GetScrollPosition();
                        m_pointCaret.y-=3;
                        if (m_pointCaret.y<0) {
                          m_pointCaret.y=0;
                          pos.y = 0;
                          ScrollToPosition(pos);
                        }
                        else {
                          pos.y-=3*m_nDxHeight;
                          ScrollToPosition(pos);
                        }

                        if (bIn) {
                          if (!IsCaretIn()) {
                            pos = GetScrollPosition();
                            pos.y -= m_nDxHeight*3;
                            if (pos.y<0) pos.y=0;
                            ScrollToPosition(pos);
                          }
                        }
                        else {
                          if (!IsCaretIn()) {
                            pos.x = 0;
                            pos.y = m_pointCaret.y * m_nDxHeight;
                            ScrollToPosition(pos);
                          }
                        }
                        break;
                        
                case VK_NEXT:
                        bIn = IsCaretIn();
                        pos = GetScrollPosition();
                        m_pointCaret.y+=3;
                        if (m_pointCaret.y>30) {
                          m_pointCaret.y=30;
                          pos.y = 30*m_nDxHeight;
                          ScrollToPosition(pos);
                        }
                        else {
                          pos.y+=3*m_nDxHeight;
                          ScrollToPosition(pos);
                        }

                        if (bIn) {
                          if (!IsCaretIn()) {
                            pos = GetScrollPosition();
                            pos.y += m_nDxHeight*3;
                            ScrollToPosition(pos);
                          }
                        }
                        else {
                          if (!IsCaretIn()) {
                            pos.x = 0;
                            pos.y = m_pointCaret.y * m_nDxHeight;
                            ScrollToPosition(pos);
                          }
                        }
                        break;
                        
                default:
                        break;
        }
        SetMyCaret();

        // Add by Daniel Lin on 5.20.1996 for the FAX on 5.16.1996
        // 
        char *regName = NULL;
        CString strName;
         
        BYTE bAddr = BYTE(m_pointCaret.y*8+(7-m_pointCaret.x));
        BOOL bGetOk = FALSE;
         
        bGetOk = GetSFRBitName(bAddr, strName );   
        if ( bGetOk ) {
           regName = new char[strName.GetLength() + 2];   
           strcpy( regName, strName.GetBuffer( strName.GetLength() ) );
        }
        else {
           regName = new char[5];      
           strcpy( regName, " " );
        }
         
        CBMemoryWindow *frame = (CBMemoryWindow *)GetParent();
        strncpy( frame->m_strRegName, regName, strlen( regName ) );
        frame->WriteRegName( regName );
        if (NULL != regName) delete []regName;
        frame->m_pointCaret.x = m_pointCaret.x;
        frame->m_pointCaret.y = m_pointCaret.y;
     }
     else
      ShowStatusGo();
   }
   
   CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CBMemoryView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
        // TODO: Add your message handler code here and/or call default
   POINT pos;
   unsigned char uchCpuStatus;
   
   if (GetCpuStatus(uchCpuStatus)) {
     if ( 1 != uchCpuStatus ) {       // Is on GO status (STATUS_GO)
        switch (nChar) {
             case VK_SPACE:
                  if (!IsCaretIn()) {
                    pos.x = 0;
                    pos.y = m_pointCaret.y * m_nDxHeight;
                    ScrollToPosition(pos);
                  }

                  SwitchBit(m_pointCaret);
                  InvalidateRect(NULL,FALSE);
                  ::RepaintCPU();
                  ::RepaintPeri();
                  break;
                  
             default:
                  break;
        }
     }
     else
       ShowStatusGo();
   }
   
   CScrollView::OnKeyUp(nChar, nRepCnt, nFlags);
}

void CBMemoryView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
        // TODO: Add your message handler code here and/or call default
     if (point.x >= (int)m_nTextBegin) {
       SwitchBit(m_pointCaret);
       InvalidateRect(NULL,FALSE);
       UpdateWindow();
       ::RepaintCPU();
       ::RepaintPeri();
     }

     // Add by Daniel Lin on 5.20.1996 for the FAX on 5.16.1996
     // 
/*     
     char *regName = NULL;
     CString strName;
         
     BYTE bAddr = BYTE(m_pointCaret.y*8+(7-m_pointCaret.x));
     BOOL bGetOk = FALSE;
         
     bGetOk = GetSFRBitName(bAddr, strName );   
     if ( bGetOk ) {
        regName = new char[strName.GetLength() + 2];   
        memset( regName, 0, sizeof(regName) );         
        strcpy( regName, strName.GetBuffer( strName.GetLength() ) );
     }
     else {
        regName = new char[5];      
        strcpy( regName, " " );
     }
         
     CBMemoryWindow *frame = (CBMemoryWindow *)GetParent();
     strncpy( frame->m_strRegName, regName, strlen( regName ) );
     frame->WriteRegName( regName );
     if (NULL != regName) delete []regName;
     frame->m_pointCaret.x = m_pointCaret.x;
     frame->m_pointCaret.y = m_pointCaret.y;
*/     
     CScrollView::OnLButtonDblClk(nFlags, point);
}


void CBMemoryView::OnRButtonDown(UINT nFlags, CPoint point)
{
        // TODO: Add your message handler code here and/or call default
    LPARAM lParam;
    lParam = (WORD)point.y + 20;
    lParam <<= 16;
    lParam += (WORD)point.x;
    GetParent()->SendMessage(WM_RBUTTONDOWN, nFlags, lParam);

    CScrollView::OnRButtonDown(nFlags, point);
}


void CBMemoryView::OnEditBit()
{
        // TODO: Add your command handler code here
     POINT pos;
     if (!IsCaretIn()) {
       pos.x = 0;
       pos.y = m_pointCaret.y * m_nDxHeight;
       ScrollToPosition(pos);
     }

     SwitchBit(m_pointCaret);
     InvalidateRect(NULL,FALSE);
     ::RepaintCPU();
     ::RepaintPeri();
}

void CBMemoryView::OnUpdateEditBit(CCmdUI* pCmdUI)
{
   // TODO: Add your command update UI handler code here
   unsigned char uchCpuStatus;
  
   if (GetCpuStatus(uchCpuStatus)) {
     if ( 1 == uchCpuStatus ) {       // Is on GO status (STATUS_GO)
        pCmdUI->Enable(FALSE);
     }
     else {
      pCmdUI->Enable(TRUE);
     }      
   }
   else
      pCmdUI->Enable(TRUE);
}

void CBMemoryView::OnSetFocus(CWnd* pOldWnd)
{
     CScrollView::OnSetFocus(pOldWnd);

     // TODO: Add your message handler code here
     CreateSolidCaret(2,11);
     ShowCaret();
     SetMyCaret();
}

void CBMemoryView::OnViewRefresh()
{
        // TODO: Add your command handler code here
#ifndef _NOABI
        MemServerDump(m_bBitMem, 0, 0xf8, 5);
#endif
        InvalidateRect(NULL,TRUE);
}


UINT 
CBMemoryView::OnNcHitTest(CPoint point)
{
   // TODO: Add your message handler code here and/or call default
   unsigned char uchCpuStatus;
   
   if (GetCpuStatus(uchCpuStatus)) {
      if ( 1 != uchCpuStatus ) {       // Is on GO status (STATUS_GO)
         return CWnd::OnNcHitTest(point);
      }
      else {
         ShowStatusGo();
         return HTERROR;
      }         
   }
   else
      return HTERROR;
}

void   
CBMemoryView::ShowStatusGo()
{
   CString str = "Running. Halt CPU first.";
   ((CMainFrame*)((CXviewApp *)AfxGetApp()->m_pMainWnd))->m_wndStatusBar.UpdateStatusBar(0, str);
   MessageBeep( -1 );
}

///////////////////////////(EOF of the BMEMVIEW.CPP)/////////////////////




