-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLoadCode.cpp
More file actions
172 lines (144 loc) · 4.32 KB
/
LoadCode.cpp
File metadata and controls
172 lines (144 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*-----------------------------------------------------------------------------
6502 Macroassembler and Simulator
Copyright (C) 1995-2003 Michal Kowalski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------------*/
// LoadCode.cpp : implementation file
//
#include "stdafx.h"
//#include "6502.h"
#include "LoadCode.h"
#include "LoadCodeOptions.h"
#include <Dlgs.h>
#include "IntelHex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int CLoadCode::m_nInitPos= 0;
/////////////////////////////////////////////////////////////////////////////
// CLoadCode
IMPLEMENT_DYNAMIC(CLoadCode, CFileDialog)
CLoadCode::CLoadCode(LPCTSTR lpszFileName, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(TRUE, _T(""), lpszFileName,
OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
lpszFilter, pParentWnd)
{
m_strTitle.LoadString(IDS_LOAD_CODE_DLG);
m_ofn.lpstrTitle = m_strTitle;
m_ofn.nFilterIndex = m_nInitPos+1;
}
BEGIN_MESSAGE_MAP(CLoadCode, CFileDialog)
//{{AFX_MSG_MAP(CLoadCode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
void CLoadCode::LoadCode() // wczytanie kodu 6502 do symulatora
{
m_nInitPos = m_ofn.nFilterIndex - 1;
CString fileName= GetPathName();
if (fileName.GetLength() == 0)
return;
CFileException exception;
CFile file;
if (!file.Open(fileName, CFile::modeRead | CFile::shareDenyWrite, &exception))
{
CString msg;
TCHAR buf[256];
exception.GetErrorMessage(buf,255);
AfxFormatString2(msg,IDS_LOAD_CODE_ERR_1,fileName,buf);
AfxMessageBox(msg);
return;
}
try
{
CString ext= GetFileExt();
CString extensions;
extensions.LoadString(IDS_CODE_EXTENSIONS);
ext.MakeLower();
int nPos= extensions.Find(ext);
switch (nPos >= 0 ? nPos / 4 : -1)
{ // zdeterminowanie typu na podstawie rozszerzenia pliku do zapisu
case 0: // 65h
case 1: // hex
m_nPos = 0;
break;
case 2: // 65m
case 3: // s9
m_nPos = 1;
break;
case 4: // 65b
m_nPos = 2;
break;
case 5: // 65p
m_nPos = 3;
break;
case 6: // com
m_nPos = 4;
break;
default:
m_nPos = m_ofn.nFilterIndex - 1;
if (m_ofn.nFilterIndex == 6) // wszystkie pliki (*.*) ?
m_nPos = 2;
break;
} // jeœli nierozpoznane rozszerzenie, u¿ywamy typu wybranego w pude³ku dialogowym
CLoadCodeOptions dlg;
if (m_nPos == 2 && dlg.DoModal() != IDOK) // podanie adresu jeœli typ 'plik binarny'
return;
ASSERT(dlg.m_uStart <= 0xFFFF);
CArchive archive(&file, CArchive::load, 1024 * 8);
theApp.m_global.LoadCode(archive, dlg.m_uStart, 0xFFFF, m_nPos, dlg.m_bClearMem ? dlg.m_uFill : -1);
archive.Close();
theApp.m_global.CreateDeasm();
}
catch (CException *exception)
{
CString msg;
TCHAR buf[256];
exception->GetErrorMessage(buf,255);
AfxFormatString2(msg, IDS_LOAD_CODE_ERR_2, fileName, buf);
AfxMessageBox(msg);
exception->Delete();
return;
}
catch (CIntelHex::CIntelHexException exception)
{
CString msg;
TCHAR buf[256];
exception.GetErrorMessage(buf,sizeof(buf));
// AfxFormatString2(msg,IDS_SAVE_CODE_ERR_2,fileName,buf);
AfxMessageBox(buf);
return;
}
}
/*
void CLoadCode::OnTypeChange()
{
CWnd *pWnd= GetParent();
if (pWnd == NULL)
return;
m_nInitPos = m_nPos = pWnd->SendDlgItemMessage(cmb1,CB_GETCURSEL);
}
*/
BOOL CLoadCode::OnInitDialog()
{
/*
CWnd *pWnd= GetParent();
if (pWnd)
m_nPos = m_nInitPos = pWnd->SendDlgItemMessage(cmb1,CB_SETCURSEL,m_nInitPos);
*/
CFileDialog::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}