-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChildView.cpp
292 lines (217 loc) · 6.25 KB
/
ChildView.cpp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// ChildView.cpp : implementation of the CChildView class
//
#include "stdafx.h"
#include <Afxwin.h>
#include "MainApp.h"
#include "ChildView.h"
#include "WinTrs80Thread.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#if 0 // Code to draw a splitter bar out of CSplitterWnd::OnDrawSplitter()
case splitBar:
if (!afxData.bWin4)
{
pDC->Draw3dRect(rect, afxData.clrBtnHilite, afxData.clrBtnShadow);
rect.InflateRect(-CX_BORDER, -CY_BORDER);
}
break;
default:
ASSERT(FALSE); // unknown splitter type
}
// fill the middle
COLORREF clr = afxData.clrBtnFace;
pDC->FillSolidRect(rect, clr);
}
#endif
/////////////////////////////////////////////////////////////////////////////
// CChildView
CChildView::CChildView()
{
m_trs80_thread = NULL;
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView, CWnd)
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_WM_CANCELMODE()
ON_WM_CREATE()
ON_WM_CAPTURECHANGED()
ON_WM_CHAR()
ON_WM_CONTEXTMENU()
ON_WM_DROPFILES()
ON_WM_COPYDATA()
ON_WM_KEYDOWN()
ON_WM_DESTROY()
ON_WM_KEYUP()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
return TRUE;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (m_trs80_thread)
m_trs80_thread->Paint(&dc);
// Do not call CWnd::OnPaint() for painting messages
}
void CChildView::OnCancelMode()
{
CWnd ::OnCancelMode();
// TODO: Add your message handler code here
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd ::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CChildView::OnCaptureChanged(CWnd *pWnd)
{
// TODO: Add your message handler code here
CWnd ::OnCaptureChanged(pWnd);
}
void CChildView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
}
void CChildView::OnDropFiles(HDROP hDropInfo)
{
// should detect and warn if multiple files dropped in future...
TCHAR szFileName[_MAX_PATH];
::DragQueryFile(hDropInfo, 0, szFileName, _MAX_PATH);
::DragFinish(hDropInfo);
FILE* fp = fopen(szFileName, "rb");
if (fp==NULL)
{
::AfxMessageBox("Unable to open file");
return;
}
unsigned char* buf = m_trs80_config.m_dsk_image; // use as disk image as temp storage
size_t size = fread(buf, sizeof (buf[0]), sizeof (m_trs80_config.m_dsk_image), fp);
if (size == 0)
{
::AfxMessageBox("Error reading file");
return;
}
if (size >= sizeof(m_trs80_config.m_dsk_image))
{
::AfxMessageBox("Invalid File type -- Must be CMD, BAS, or DSK (JV1 only)");
return;
}
fclose(fp);
if (m_trs80_thread)
{
m_trs80_thread->KillThreadAsync();
WaitForSingleObject(m_trs80_thread->m_hThread, INFINITE);
// delete m_trs80_thread; CWindowThread is automaticly deleteing the object
}
if (stricmp(szFileName+strlen(szFileName)-4, ".dsk")==0)
{
m_trs80_config.m_syssoft_level = TRS80_SYSSOFT_DOS;
m_trs80_config.m_dos_type = TRS80_DOSTYPE_NEW_A;
m_trs80_config.m_boot_mode = TRS80_BOOTMODE_NORMAL;
m_trs80_config.m_load_drive1 = TRUE;
// memcpy(m_trs80_config.m_dsk_image, buf, size); Already there
if (size % 256 !=0)
{
::AfxMessageBox("Invalid File type -- only JV1 .dsk files supported");
return;
}
}
else
{
m_trs80_config.m_syssoft_level = TRS80_SYSSOFT_ROM;
m_trs80_config.m_boot_mode = TRS80_BOOTMODE_AUTORUN;
m_trs80_config.m_image = buf;
m_trs80_config.m_size = size;
if (stricmp(szFileName+strlen(szFileName)-4, ".bas")==0)
m_trs80_config.m_autorun_mode = TRS80_AUTORUNMODE_ROMBASIC;
else
m_trs80_config.m_autorun_mode = TRS80_AUTORUNMODE_CMD;
}
m_trs80_thread = new CWinTrs80Thread(this, &m_trs80_thread, &m_trs80_config);
if (m_trs80_thread)
m_trs80_thread->CreateThread(0);
return;
}
BOOL CChildView::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
// TODO: Add your message handler code here and/or call default
return CWnd ::OnCopyData(pWnd, pCopyDataStruct);
}
void CChildView::OnDestroy()
{
CWnd ::OnDestroy();
if (m_trs80_thread)
{
m_trs80_thread->KillThreadAsync();
WaitForSingleObject(m_trs80_thread->m_hThread, INFINITE);
// delete m_trs80_thread; CWindowThread is automaticly deleteing the object
m_trs80_thread = NULL;
}
}
void CChildView::OnKeyDown(UINT vk, UINT nRepCnt, UINT nFlags)
{
if (m_trs80_thread)
{
if (vk == VK_SHIFT)
m_trs80_thread->SetCharDown(TRS80_KEY_SHIFT, nFlags & 0xFF);
else if (vk == VK_CONTROL)
m_trs80_thread->SetCharDown(TRS80_KEY_CTRL, nFlags & 0xFF);
else if (vk==0x1b || vk==VK_PAUSE) // ESC or pause/break
m_trs80_thread->SetCharDown(TRS80_KEY_BREAK, nFlags & 0xFF);
else if (vk == VK_LEFT || vk == 8) // bs or left
m_trs80_thread->SetCharDown(TRS80_KEY_LEFT, nFlags & 0xFF);
else if (vk == VK_RIGHT )
m_trs80_thread->SetCharDown(TRS80_KEY_RIGHT, nFlags & 0xFF);
else if (vk == VK_UP)
m_trs80_thread->SetCharDown(TRS80_KEY_UP, nFlags & 0xFF);
else if (vk == VK_DOWN)
m_trs80_thread->SetCharDown(TRS80_KEY_DOWN, nFlags & 0xFF);
else if (vk == VK_HOME)
m_trs80_thread->SetCharDown(TRS80_KEY_CLEAR, nFlags & 0xFF);
}
CWnd ::OnKeyDown(vk, nRepCnt, nFlags);
}
void CChildView::OnChar(UINT c, UINT nRepCnt, UINT nFlags)
{
if (c == 8) // handeled by OnKeyDown
return;
if (m_trs80_thread)
m_trs80_thread->SetCharDown(c, nFlags & 0xFF); // Bug in Win docs, scan code is in LSB
CWnd ::OnChar(c, nRepCnt, nFlags);
}
void CChildView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (m_trs80_thread)
{
if (nChar == VK_SHIFT)
m_trs80_thread->SetCharUp(TRS80_KEY_SHIFT, nFlags & 0xFF);
else if (nChar == VK_CONTROL)
m_trs80_thread->SetCharUp(TRS80_KEY_CTRL, nFlags & 0xFF);
else
m_trs80_thread->SetCharUp(0, nFlags&0xFF);
}
CWnd ::OnKeyUp(nChar, nRepCnt, nFlags);
}
BOOL CChildView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return CWnd ::OnEraseBkgnd(pDC);
}