📄 mapperdoc.cpp
字号:
//////////////////////////////////////////////////////////////////////
//
// File: mapperDoc.cpp
//
// $Archive: /ComemL/Util/PCfg/mapperDoc.cpp $
//
// Purpose:
//
// $Author: Tpm $
//
// $History: mapperDoc.cpp $
//
// ***************** Version 1 *****************
// User: Tpm Date: 7/13/98 Time: 8:38a
// Created in $/ComemL/Util/PCfg
//
// ***************** Version 44 *****************
// User: Tpm Date: 1/09/98 Time: 5:33p
// Updated in $/Comem/Mapper
// Change Target to Local Processor
//
// ***************** Version 43 *****************
// User: Stevek Date: 11/12/97 Time: 4:49p
// Updated in $/Comem/Mapper
// No longer save comemID
//
// ***************** Version 42 *****************
// User: Stevek Date: 11/07/97 Time: 11:14a
// Updated in $/Comem/Mapper
// Moved reference counting into the document.
//
// ***************** Version 41 *****************
// User: Stevek Date: 11/06/97 Time: 4:16p
// Updated in $/Comem/Mapper
// Added exclusive flag so that library calls don't get a "two mappers"
// error.
//
// ***************** Version 40 *****************
// User: Stevek Date: 11/06/97 Time: 5:02a
// Updated in $/Comem/Mapper
// Fixed errors that occurred without a driver loaded -- restored "no
// driver" functionality.
//
// ***************** Version 39 *****************
// User: Tpm Date: 11/04/97 Time: 11:35a
// Updated in $/Comem/Mapper
// Req: Add Toolbar buttons for File and View Memu Items.
// Fix: Done.
//
// ***************** Version 38 *****************
// User: Tpm Date: 11/03/97 Time: 10:03a
// Updated in $/Comem/Mapper
// Bug: ReadCfgFile() on startup uses dev->ReadCfgFile(); no longer gets
// lastfiletype
// Fix: Now call masterDocument->ReadCfgFile also.
//
// ***************** Version 37 *****************
// User: Tpm Date: 10/31/97 Time: 6:17p
// Updated in $/Comem/Mapper
// Bug: SWAP ICache/DCache locations.
// Bug: Recalc CACHE start addresses to mask off low order bit.
// Req: Make double-Click in Visual map bring up mem in local space.
// Fix: Space is remapped now.
//
// ***************** Version 36 *****************
// User: Tpm Date: 10/31/97 Time: 10:04a
// Updated in $/Comem/Mapper
// Req: Add Address Selector to Memory Views to select cache pages.
// Fix: Added Selector and strings for cache pages.
//
// ***************** Version 35 *****************
// User: Tpm Date: 10/30/97 Time: 9:18a
// Updated in $/Comem/Mapper
// Req: Implement "Load/Save Configuration" for .ini file.
// Fix: Added options to File Menu.
// Req: Should display .ini file ID in toolbar vice "Mapper1".
// Fix: Displays .ini file now.
// Bug: StartScreen Comem Number dropdown is too short.
// Fix: Changed properties to have "No Integral height"; now shows mult
// selections.
//
// ***************** Version 34 *****************
// User: Stevek Date: 10/28/97 Time: 3:16p
// Updated in $/Comem/Mapper
// Don't include comem_if anymore, include comemDevice.
//
// ***************** Version 33 *****************
// User: Tpm Date: 10/28/97 Time: 2:44p
// Updated in $/Comem/Mapper
// added "filename" parameter to get_hex_ini_parm()
//
// ***************** Version 32 *****************
// User: Tpm Date: 10/27/97 Time: 2:56p
// Updated in $/Comem/Mapper
// Req: Put CoMem ID into toolbar.
// Fix: Added Card # to TitleBar
//
// ***************** Version 31 *****************
// User: Stevek Date: 10/24/97 Time: 3:55p
// Updated in $/Comem/Mapper
// Started to seperate library functions out of mapper files.
// Current code is tested with one comem.
//
// ***************** Version 30 *****************
// User: Tpm Date: 10/24/97 Time: 8:57a
// Updated in $/Comem/Mapper
// Bug: Mapper uses VxD_loaded_check() (has dialog) on close document; use
// VxD_loaded().
// Fix: Done.
//
// ***************** Version 29 *****************
// User: Stevek Date: 10/23/97 Time: 11:59a
// Updated in $/Comem/Mapper
// Added comemID to closeDriver
//
// ***************** Version 28 *****************
// User: Stevek Date: 10/23/97 Time: 11:50a
// Updated in $/Comem/Mapper
// Naming convention changes, comemID changes for manual
//
// ***************** Version 27 *****************
// User: Tpm Date: 10/22/97 Time: 3:32p
// Updated in $/Comem/Mapper
// Bug: Mapper may not indicate if driver is not loaded.
// Fix:+if (errCode != NO_MAPPER_ERROR), ask if the user wants to tun
// without hardware
//
// ***************** Version 26 *****************
// User: Stevek Date: 10/22/97 Time: 12:58p
// Updated in $/Comem/Mapper
// Improved init of comemID
//
// ***************** Version 25 *****************
// User: Stevek Date: 10/22/97 Time: 12:27p
// Updated in $/Comem/Mapper
// Added header blocks to all files at once!
//
// Copyright (c) 1997 Anchor Chips, Inc. May not be reproduced without
// permission. See the license agreement for more details.
//
//////////////////////////////////////////////////////////////////////
// mapperDoc.cpp : implementation of the CMapperDoc class
//
#include "stdafx.h"
#include "mapper.h"
#include "mainfrm.h"
#include "comemDevice.h"
#include "CntrItem.h"
#include "SrvrItem.h"
//#include "startscreen.h"
//#include "DialogNButtons.h"
#include "memory_mgmt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc
IMPLEMENT_DYNCREATE(CMapperDoc, COleServerDoc)
BEGIN_MESSAGE_MAP(CMapperDoc, COleServerDoc)
//{{AFX_MSG_MAP(CMapperDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Enable default OLE container implementation
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, COleServerDoc::OnUpdatePasteMenu)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, COleServerDoc::OnUpdatePasteLinkMenu)
ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleServerDoc::OnUpdateObjectVerbMenu)
ON_COMMAND(ID_OLE_EDIT_CONVERT, COleServerDoc::OnEditConvert)
ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleServerDoc::OnUpdateEditLinksMenu)
ON_COMMAND(ID_OLE_EDIT_LINKS, COleServerDoc::OnEditLinks)
ON_UPDATE_COMMAND_UI(ID_OLE_VERB_FIRST, COleServerDoc::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CMapperDoc, COleServerDoc)
//{{AFX_DISPATCH_MAP(CMapperDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IMapper to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {CA215C42-79E5-11D0-B9F7-00A024BBE6B5}
static const IID IID_IMapper =
{ 0xca215c42, 0x79e5, 0x11d0, { 0xb9, 0xf7, 0x0, 0xa0, 0x24, 0xbb, 0xe6, 0xb5 } };
BEGIN_INTERFACE_MAP(CMapperDoc, COleServerDoc)
INTERFACE_PART(CMapperDoc, IID_IMapper, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc construction/destruction
CMapperDoc::CMapperDoc()
{
int i;
// Use OLE compound files
EnableCompoundFile();
EnableAutomation();
AfxOleLockApp();
masterDocument = this;
dev = NULL;
// Initialize class variables
cpuName = "No CPU name"; // Just a comment for the user
lastFileType = 0;
// Use the Vxd to get the device count
for (i = 0; i < COMEM_MAX_DEVICES; i++)
{
char buffer[0x100];
DWORD errCode = comemOpenDriver(i);
if (errCode != NO_ERROR)
{
comemCloseDriver(i);
break; // Went past the last one. Close the driver for Win95
}
comemCloseDriver(i);
}
if (i > 1)
{
// Ask the user for vendor/device ID
// CStartScreen mydialog(comemID, i);
//comemID = mydialog.DoModal();
// mydialog.DoModal();
// comemID = mydialog.m_nCoMemId;
}
else
comemID = 0;
CString strMainTitle;
// If no driver, adjust title accordingly
if (i == 0)
strMainTitle.Format("No Co-Mem Card -- Demo mode ", comemID);
else
strMainTitle.Format("Co-Mem Card %d ", comemID);
theApp.pMainFrame->SetTitle(strMainTitle);
// Open the driver (for good, this time) and get the device information.
comemOpenDriver(comemID);
DWORD refCount = 0;
if(comemGetStatus(&refCount, comemID) == NO_ERROR)
if (refCount > 1)
{
report_error("Comem device number %x is already in use by %d applications. Mapper must be the first program to contact the device.", comemID, refCount);
comemCloseDriver(comemID);
exit(1);
}
dev = comemDev[comemID];
readCfgFile(masterDocument->dev->mapdata, NULL);
}
CMapperDoc::~CMapperDoc()
{
AfxOleUnlockApp();
}
BOOL CMapperDoc::OnNewDocument()
{
if (!COleServerDoc::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
DeleteContents();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc server implementation
COleServerItem* CMapperDoc::OnGetEmbeddedItem()
{
// OnGetEmbeddedItem is called by the framework to get the COleServerItem
// that is associated with the document. It is only called when necessary.
CMapperSrvrItem* pItem = new CMapperSrvrItem(this);
ASSERT_VALID(pItem);
return pItem;
}
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc serialization
void CMapperDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
// Calling the base class COleServerDoc enables serialization
// of the container document's COleClientItem objects.
COleServerDoc::Serialize(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc diagnostics
#ifdef _DEBUG
void CMapperDoc::AssertValid() const
{
COleServerDoc::AssertValid();
}
void CMapperDoc::Dump(CDumpContext& dc) const
{
COleServerDoc::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc commands
void CMapperDoc::DeleteContents()
{
COleServerDoc::DeleteContents();
}
BOOL CMapperDoc::SaveModified()
{
if (IsModified())
{ // do not save the mapper.cmp document; contents are saved in .ini file
int result = AfxMessageBox( "Save modified Configuration (.ini) file?", MB_YESNO);
if (result == IDYES)
writeCfgFile(dev->mapdata); // Save the .ini file data
SetModifiedFlag(FALSE);
}
return COleServerDoc::SaveModified();
}
errcodeE CMapperDoc::writeCfgFile(blockT *block, const char *filename)
{
if (filename == NULL)
filename = ini_file_name;
flush_ini(filename); // Win95 buffers this stuff. Make sure we're synched with any other copies of mapper using this file
errcodeE retval = dev->writeCfgFile(block, filename);
if (retval != NO_MAPPER_ERROR)
return(retval);
theApp.m_pMapDoc->SetTitle(filename);
write_text_ini_parm("CPUNAME", cpuName , filename);
write_text_ini_parm("LASTFILE", lastFilename , filename);
write_hex_ini_parm("LASTFILETYPE", lastFileType , filename);
flush_ini(filename); // Win95 buffers this stuff. Make sure we're synched with any other copies of mapper using this file
return(NO_MAPPER_ERROR);
}
errcodeE CMapperDoc::readCfgFile(blockT *blockArray, const char *filename)
{
char buffer[0x100];
if (filename == NULL)
filename = ini_file_name;
flush_ini(filename); // Win95 buffers this stuff. Make sure we're synched with any other copies of mapper using this file
errcodeE retval = dev->readCfgFile(blockArray, filename);
if (retval != NO_MAPPER_ERROR)
return(retval);
if(theApp.m_pMapDoc)
theApp.m_pMapDoc->SetTitle(filename);
get_hex_ini_parm(&lastFileType , "LASTFILETYPE", filename);
buffer[0] = 0;
get_text_ini_parm(buffer , "LASTFILE", filename);
lastFilename = buffer;
get_text_ini_parm(buffer, "CPUNAME", filename);
cpuName = buffer;
flush_ini(filename); // Win95 buffers this stuff. Make sure we're synched with any other copies of mapper using this file
return(NO_MAPPER_ERROR);
}
// TBD -- Need to add
// virtual BOOL OnSaveDocument( LPCTSTR lpszPathName );
void CMapperDoc::OnCloseDocument()
{
// We can't do this after the document has been destroyed, so we do it here instead of in the application.
//TPMTPMTPM if (((CMapperApp *)AfxGetApp())->VxD_loaded())
if (((CPCfgApp *)AfxGetApp())->VxD_loaded())
{
// CDialogNButtons mydialog("Select memory allocation option",
// "When mapper is closed, you can either keep the memory allocated to the Local processor or deallocate the memory designated for the Local processor (and put the Local processor into reset).",
// "&Keep mem", "&Free mem", NULL);
// int result = mydialog.DoModal();
// if (result == ID_BUTTON1 || result == IDOK)
// {
// don't do anything special -- memory will stay around
// }
// else if (result == ID_BUTTON2 || result == IDCANCEL)
// {
// Reset the part
// targetReset(comemID);
// Clear old allocation and free the memory
// comemDestroyLinPtr(comemID);
// comemDeallocMemory(comemID);
// }
comemDestroyLinPtr(comemID);
comemDestroyBarPtr(comemID);
comemCloseDriver(comemID);
}
COleServerDoc::OnCloseDocument();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -