-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUiSystem.cpp
469 lines (387 loc) · 14.4 KB
/
UiSystem.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/////////////////////////////////////////////////////////////////////////////
// UiSystem.cpp
// Modified from wxWindows sample program, drawing.cpp, by Robert Roebling.
//
// This file contains the entry point for the emulator, as well as the
// locus of the GUI logic.
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
struct crt_state_t;
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "Cpu2200.h"
#include "Ui.h"
#include "UiCrtFrame.h"
#include "UiDiskCtrlCfgDlg.h"
#include "UiMyAboutDlg.h"
#include "UiPrinterFrame.h"
#include "UiSystem.h"
#include "UiSystemConfigDlg.h"
#include "UiTermMuxCfgDlg.h"
#include "host.h"
#ifdef __WXMAC__
#include "osx_utils.h"
#endif
#include "system2200.h"
#include "wx/cmdline.h" // req'd by wxCmdLineParser
#include "wx/filename.h"
// ============================================================================
// implementation
// ============================================================================
// Create a new application object: this macro will allow wxWindows to
// create the application object during program execution (it's better
// than using static object for many reasons) and also declares the
// accessor function wxGetApp() which will return the reference of the
// right type (i.e. TheApp and not wxApp)
IMPLEMENT_APP(TheApp)
// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------
// `Main program' equivalent: the program execution "starts" here
bool
TheApp::OnInit()
{
#if 0
// read wxToolBar notes to see why this is done
if (wxTheApp->GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32) {
wxSystemOptions::SetOption("msw.remap", 2);
}
#endif
#ifdef __WXMAC__
// try to disable accent menu popup in preference to auto-repeat
// on long keypresses
osxSetAccentMenuPrefs();
#endif
// event routing table
Bind(wxEVT_IDLE, &TheApp::OnIdle, this);
host::initialize();
system2200::initialize(); // build the world
system2200::reset(true); // cold start
// must call base class version to get command line processing
// if false, the app terminates
return wxApp::OnInit();
}
// this is called whenever the wxWidget event queue is empty,
// indicating there is no work pending.
void
TheApp::OnIdle(wxIdleEvent &event)
{
if (system2200::onIdle()) {
event.RequestMore(true); // give more idle events
}
}
// called just before quitting the entire app, but before wxWindows
// cleans up its internal resources.
// use this to clean up any allocated globals
int
TheApp::OnExit()
{
// clean up, which includes saving .ini file
host::terminate();
return 0;
}
// set the command line parsing options
void
TheApp::OnInitCmdLine(wxCmdLineParser& parser)
{
// set default wx options
wxApp::OnInitCmdLine(parser);
parser.DisableLongOptions(); // -foo, not --foo
// add options specific to this app
parser.AddOption("s", "script", "script file to load on startup", wxCMD_LINE_VAL_STRING);
}
// after the command line has been parsed, decode what it finds
bool
TheApp::OnCmdLineParsed(wxCmdLineParser& parser)
{
// let base class handle its defaults
const bool ok = wxApp::OnCmdLineParsed(parser);
if (ok) {
// do my processing here
// UI_info("Command line items: %d", parser.GetParamCount());
wxString filename;
#if 0
// this doesn't make sense anymore.
// (1) it wasn't useful to begin with
// (2) it can't be used with (M)VP setups as they must be configured before use
// (3) even with 2200T and a dumb CRT/keyboard, it is throwing errors, and
// I don't care to spend the time to fix it. it has something to do with
// attempting to route the first character to the keyboard before the
// universe has been built. the fix would be to simply save the script
// name and then have system2200 invoke it once the world was built.
if (parser.Found("s", &filename)) {
const int io_addr = 0x01; // default keyboard device
std::string fn(filename.c_str());
system2200::invokeKbScript(io_addr, -1, fn);
bool success = true; // old invokeScript returned a boolean
if (!success) {
const char *s = filename.c_str();
UI_warn("Failed to open script '%s'", s);
}
}
#endif
}
return ok;
}
// ========================================================================
// Help/About functions
// ========================================================================
// called by various frames to install the canonical help menu
// these are menu IDs so that the OnHelp_Launcher() knows which item is chosen
enum {
Help_Quickstart = 200,
Help_Configure,
Help_Keyboard,
Help_Menus,
Help_Printer,
Help_Script,
Help_DiskFactory,
Help_DiskCheat,
Help_Website,
Help_Relnotes,
Help_About = wxID_ABOUT,
};
static void
OnHelp_Launcher(wxCommandEvent &event)
{
wxString helpfile;
bool absolute = false;
switch (event.GetId()) {
case Help_Quickstart: helpfile = "quickstart.html"; break;
case Help_Configure: helpfile = "configure.html"; break;
case Help_Keyboard: helpfile = "keyboard.html"; break;
case Help_Menus: helpfile = "menus.html"; break;
case Help_Printer: helpfile = "printer.html"; break;
case Help_Script: helpfile = "script.html"; break;
case Help_DiskFactory: helpfile = "disk_factory.html"; break;
case Help_DiskCheat: helpfile = "disk_cheatsheet.html"; break;
case Help_Relnotes: helpfile = "relnotes.txt"; break;
case Help_Website: helpfile = "http://www.wang2200.org/"; absolute = true; break;
default:
assert(false);
return;
}
wxString sep(wxFileName::GetPathSeparator());
if (helpfile.EndsWith(".html")) {
// look in html/ subdirectory
helpfile = "html" + sep + helpfile;
}
wxString target_file = (absolute) ? helpfile
: ("file:" + sep + sep +
host::getAppHome() +
sep + helpfile);
#ifdef __WXMSW__
// wxLaunchDefaultBrowser()'s argument used to use windows-style paths,
// ie, backslash as a path separator. however, at some point between
// 2008 and 2014, that changed; now it takes canonical URL paths.
target_file.Replace(wxT("\\"), wxT("/"));
#endif
::wxLaunchDefaultBrowser(target_file);
}
static void
OnHelp_About(wxCommandEvent& WXUNUSED(event))
{
MyAboutDlg dlg(nullptr);
dlg.ShowModal();
}
// create a help menu, used for all frames that care
// and connect help menu items to the window event map
wxMenu*
TheApp::makeHelpMenu(wxWindow *win)
{
assert(win);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Quickstart);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Configure);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Keyboard);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Menus);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Printer);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Script);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_DiskFactory);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_DiskCheat);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Website);
win->Bind(wxEVT_MENU, &OnHelp_Launcher, Help_Relnotes);
win->Bind(wxEVT_MENU, &OnHelp_About, Help_About);
wxMenu *menuHelp = new wxMenu;
menuHelp->Append(Help_Quickstart, "&Quickstart", "Information for new users of WangEmu");
menuHelp->Append(Help_Configure, "&Configuration", "Information about configuring the emulator");
menuHelp->Append(Help_Keyboard, "&Keyboard", "Information about how the 2200 keyboard is mapped onto yours");
menuHelp->Append(Help_Menus, "&Menus", "Information about the emulator menu system");
menuHelp->Append(Help_Printer, "&Printer", "Information about the using the emulated printer");
menuHelp->Append(Help_Script, "&Script", "Information about loading files into the emulator");
menuHelp->Append(Help_DiskFactory, "Disk &Factory", "Information about creating and inspecting virtual disks");
menuHelp->Append(Help_DiskCheat, "&Disk Cheatsheet", "Information about cataloging disks, loading and saving files");
menuHelp->Append(Help_Website, "&Website", "Open a browser to the emulator's web site");
menuHelp->AppendSeparator();
menuHelp->Append(Help_Relnotes, "&Release notes...", "Detailed notes about this release");
menuHelp->Append(Help_About, "&About...", "Information about the program");
return menuHelp;
}
// ============================================================================
// alert messages
// ============================================================================
// shared code
static bool
UI_AlertMsg(long style, const std::string &title, const char *fmt, va_list &args)
{
char buff[1000];
vsnprintf(&buff[0], sizeof(buff), fmt, args);
std::string info(&buff[0]);
wxMessageDialog dialog(nullptr, info, title, style);
const int rv = dialog.ShowModal();
return (rv == wxID_YES);
}
// error icon
void
UI_error(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
UI_AlertMsg(wxICON_ERROR, "Error", fmt, args);
va_end(args);
}
// exclamation icon
void
UI_warn(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
UI_AlertMsg(wxICON_EXCLAMATION, "Warning", fmt, args);
va_end(args);
}
void
UI_info(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
UI_AlertMsg(wxICON_INFORMATION, "Information", fmt, args);
va_end(args);
}
// get a YES/NO confirmation. return true for yes.
bool
UI_confirm(const char *fmt, ...)
{
const long style = wxYES | wxNO | wxNO_DEFAULT | wxICON_EXCLAMATION;
// const long style = wxYES | wxNO | wxNO_DEFAULT | wxICON_QUESTION;
va_list args;
va_start(args, fmt);
const bool rv = UI_AlertMsg(style, "Question", fmt, args);
va_end(args);
return rv;
}
// ========================================================================
// interface between core and UI routines
//
// The core emulator calls these functions to interact with the GUI.
// These wrappers just invoke the appropriate instance.
// ========================================================================
// ---- Crt wrappers ----
// called at the start of time to create the actual display
std::shared_ptr<CrtFrame>
UI_displayInit(const int screen_type, const int io_addr, const int term_num,
crt_state_t *crt_state)
{
const int cpu_type = system2200::config().getCpuType();
const char *cpu_str = (cpu_type == Cpu2200::CPUTYPE_2200B) ? "2200B"
: (cpu_type == Cpu2200::CPUTYPE_2200T) ? "2200T"
: (cpu_type == Cpu2200::CPUTYPE_VP) ? "2200VP"
: (cpu_type == Cpu2200::CPUTYPE_MVP) ? "2200MVP"
: (cpu_type == Cpu2200::CPUTYPE_MVPC) ? "2200MVP-C"
: (cpu_type == Cpu2200::CPUTYPE_MICROVP) ? "MicroVP"
: "unknown cpu";
const char *disp_str = "unknown";
switch (screen_type) {
case UI_SCREEN_64x16: disp_str = "64x16"; break;
case UI_SCREEN_80x24: disp_str = "80x24"; break;
case UI_SCREEN_2236DE: disp_str = "2236DE"; break;
default: assert(false);
}
wxString title;
if (screen_type != UI_SCREEN_2236DE) {
// old style display
title.Printf("Wang %s %s CRT /0%02X", cpu_str, disp_str, io_addr);
} else {
// smart terminal mux
// internally, term_num is 0-indexed, but in Wang documentation,
// the terminal number is 1-based
title.Printf("MXD/%02X Term#%d Wang %s %s",
io_addr, term_num+1, cpu_str, disp_str);
}
// create the main application window
return std::make_shared<CrtFrame>(title, io_addr, term_num, crt_state);
}
// called before the display gets shut down
void
UI_displayDestroy(CrtFrame *wnd)
{
assert(wnd != nullptr);
wnd->destroyWindow();
}
// create a bell (0x07) sound for the given terminal
void UI_displayDing(CrtFrame *wnd)
{
assert(wnd != nullptr);
wnd->ding();
}
// inform the UI how far along the simulation is in emulated time
void
UI_setSimSeconds(unsigned long seconds, float relative_speed)
{
CrtFrame::setSimSeconds(seconds, relative_speed);
}
void
UI_diskEvent(int slot, int drive)
{
CrtFrame::diskEvent(slot, drive);
}
// ---- printer wrappers ----
// called at the start of time to create the actual display
std::shared_ptr<PrinterFrame>
UI_printerInit(int io_addr)
{
char title[32];
sprintf(&title[0], "Wang Printer /%03X", io_addr);
return std::make_shared<PrinterFrame>(&title[0], io_addr);
}
// called before the display gets shut down
void
UI_printerDestroy(PrinterFrame *wnd)
{
assert(wnd != nullptr);
wnd->destroyWindow();
}
// this is called only from IoCardPrinter::strobeOBS()
// emit a character to the display
void
UI_printerChar(PrinterFrame *wnd, uint8 byte)
{
assert(wnd != nullptr);
wnd->printChar(byte);
}
// ---- system configuration wrapper ----
// launch the system configuration dialog, which might eventually
// call back into system2200.setConfig() function.
void
UI_systemConfigDlg()
{
SystemConfigDlg(nullptr).ShowModal();
}
// invoke the appropriate card configuration dialog
void
UI_configureCard(IoCard::card_t card_type, CardCfgState *cfg)
{
assert(cfg != nullptr);
switch (card_type) {
case IoCard::card_t::disk:
DiskCtrlCfgDlg(nullptr, *cfg).ShowModal();
break;
case IoCard::card_t::term_mux:
TermMuxCfgDlg(nullptr, *cfg).ShowModal();
break;
default:
assert(false);
}
}
// vim: ts=8:et:sw=4:smarttab