📄 myportioview.cpp
字号:
// MyPortIoView.cpp : implementation of the CMyPortIoView class
//
#include "stdafx.h"
#include "MyPortIo.h"
#include "MyPortIoDoc.h"
#include "MyPortIoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyPortIoView
IMPLEMENT_DYNCREATE(CMyPortIoView, CEditView)
BEGIN_MESSAGE_MAP(CMyPortIoView, CEditView)
//{{AFX_MSG_MAP(CMyPortIoView)
ON_COMMAND(ID_READ_CMOS, OnReadCmos)
ON_COMMAND(ID_SPEAKER_SOUND, OnSpeakerSound)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()
// 0x70是CMOS索引端口(只写)
// 0x71是CMOS数据端口
BYTE ReadCmos(BYTE index)
{
BYTE data;
::WritePortByte(0x70, index);
data = ::ReadPortByte(0x71);
return data;
}
// 0x61是speaker控制端口
// 0x43是8253/8254定时器控制端口
// 0x42是8253/8254定时器通道2的端口
void Sound(DWORD freq )
{
BYTE data;
if(freq>=20 && freq<=20000)
{
freq = 1193181 / freq;
data = ::ReadPortByte(0x61);
if((data & 3) == 0)
{
::WritePortByte(0x61, data | 3);
::WritePortByte(0x43, 0xb6);
}
::WritePortByte(0x42, (BYTE)(freq%256));
::WritePortByte(0x42, (BYTE)(freq/256));
}
}
void NoSound( void )
{
BYTE data;
data = ::ReadPortByte(0x61);
::WritePortByte(0x61, data & 0xfc);
}
/////////////////////////////////////////////////////////////////////////////
// CMyPortIoView construction/destruction
CMyPortIoView::CMyPortIoView()
{
// TODO: add construction code here
}
CMyPortIoView::~CMyPortIoView()
{
}
BOOL CMyPortIoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
BOOL bPreCreated = CEditView::PreCreateWindow(cs);
cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL); // Enable word-wrapping
return bPreCreated;
}
/////////////////////////////////////////////////////////////////////////////
// CMyPortIoView drawing
void CMyPortIoView::OnDraw(CDC* pDC)
{
CMyPortIoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMyPortIoView printing
BOOL CMyPortIoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default CEditView preparation
return CEditView::OnPreparePrinting(pInfo);
}
void CMyPortIoView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView begin printing.
CEditView::OnBeginPrinting(pDC, pInfo);
}
void CMyPortIoView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView end printing
CEditView::OnEndPrinting(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CMyPortIoView diagnostics
#ifdef _DEBUG
void CMyPortIoView::AssertValid() const
{
CEditView::AssertValid();
}
void CMyPortIoView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
CMyPortIoDoc* CMyPortIoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyPortIoDoc)));
return (CMyPortIoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyPortIoView message handlers
void CMyPortIoView::OnReadCmos()
{
// TODO: Add your command handler code here
CString strInfo;
CString strTmp;
BYTE data;
strInfo = "COMS DATA:\r\n";
// 读出CMOS 128个字节
for(int i=0;i<128;i++)
{
data = ::ReadCmos(i);
strTmp.Format("Byte %02X:\t%02X\r\n", i, data);
strInfo+=strTmp;
}
CEdit& Edit = GetEditCtrl();
Edit.SetWindowText(strInfo);
}
void CMyPortIoView::OnSpeakerSound()
{
// TODO: Add your command handler code here
// C调
// 1 = 262 Hz
::Sound(262);
::Sleep(200);
::NoSound();
// 2 = 288 Hz
::Sound(288);
::Sleep(200);
::NoSound();
// 3 = 320 Hz
::Sound(320);
::Sleep(200);
::NoSound();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -