-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cc
201 lines (151 loc) · 3.97 KB
/
main.cc
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
/****************************************************************
BeebEm - BBC Micro and Master 128 Emulator
Copyright (C) 1994 David Alan Gilbert
Copyright (C) 1994 Nigel Magnay
Copyright (C) 1997 Mike Wyatt
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
****************************************************************/
/* Mike Wyatt and NRM's port to win32 - 7/6/97 */
#include <stdio.h>
#include <stdarg.h>
#include <new>
#ifdef BEEBWIN
#include <windows.h>
#endif
#include "6502core.h"
#include "beebwin.h"
#include "log.h"
#include "serial.h"
#ifdef BEEBWIN
#include "SelectKeyDialog.h"
#endif
Model MachineType;
BeebWin *mainWin = nullptr;
#ifdef BEEBWIN
HINSTANCE hInst;
HWND hCurrentDialog = nullptr;
HACCEL hCurrentAccelTable = nullptr;
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
LPSTR /* lpszCmdLine */, int /* nCmdShow */)
{
hInst = hInstance;
OpenLog();
mainWin = new(std::nothrow) BeebWin();
if (mainWin == nullptr)
{
return 1;
}
if (!mainWin->Initialise())
{
delete mainWin;
return 1;
}
// Create serial threads
SerialInit();
for (;;)
{
MSG msg;
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) || mainWin->IsFrozen())
{
if (!GetMessage(&msg, // message structure
NULL, // handle of window receiving the message
0, // lowest message to examine
0))
break; // Quit the app on WM_QUIT
if (hCurrentDialog != nullptr && hCurrentAccelTable != nullptr)
{
TranslateAccelerator(hCurrentDialog, hCurrentAccelTable, &msg);
}
if (hCurrentDialog == nullptr)
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
else
{
bool handled = false;
if (selectKeyDialog != nullptr)
{
handled = selectKeyDialog->HandleMessage(msg);
}
if (!handled && !IsDialogMessage(hCurrentDialog, &msg))
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
}
}
if (!mainWin->IsFrozen() && !mainWin->IsPaused()) {
Exec6502Instruction();
}
}
mainWin->KillDLLs();
CloseLog();
Kill_Serial();
delete mainWin;
return 0;
}
#else
int _vscprintf (const char * format, va_list pargs) {
int retval;
va_list argcopy;
va_copy(argcopy, pargs);
retval = vsnprintf(NULL, 0, format, argcopy);
va_end(argcopy);
return retval;
}
int mainInit()
{
OpenLog();
mainWin = new(std::nothrow) BeebWin();
if (mainWin == nullptr)
{
return 1;
}
if (!mainWin->Initialise())
{
delete mainWin;
mainWin=0;
return 1;
}
// Create serial threads
SerialInit();
return 0;
}
int mainStep()
// for (;;)
{
// Windows MAIN
// keep processing instructions until WM_QUIT
// When there is a mesage or beeb is frozen, process Messages
// either to TranslateAccelerator
// Translates virtual key codes,Dispatches message to window
// to CurrentDialogue
bool done = false;
if (done)
return 1;
if (!mainWin->IsFrozen() && !mainWin->IsPaused()) {
Exec6502Instruction();
}
return 0;
}
int mainEnd()
{
mainWin->KillDLLs();
CloseLog();
Kill_Serial();
delete mainWin;
return 0;
}
#endif