-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdd60.cpp
More file actions
2922 lines (2547 loc) · 81.5 KB
/
dd60.cpp
File metadata and controls
2922 lines (2547 loc) · 81.5 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
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/////////////////////////////////////////////////////////////////////////////
// Name: dd60.cpp
// Purpose: dd60 interface to wxWindows
// Author: Paul Koning
// Modified by:
// Created: 08/02/2005
// Copyright: (c) Paul Koning
// Licence: DtCyber license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
/*
** -----------------
** Private Constants
** -----------------
*/
#define NetBufSize 65536
#define STATUS_TRC 0
#define STATUS_CONN 2
#define STATUSPANES 3
#define KNOBPANE 1
// For Retina display support on the Mac, we need to deal with the
// fact that display units are not actually pixels, but "points" [sic]
// and that the actual pixels may be smaller.
// Character pattern sizes in points, allowing for going over the
// allotted space some. There are two pixels per point, and we add
// another 50% of space around the basic character allotment, so
// the values used are pixel size times three.
#define CHAR8SIZE (8 * 3)
#define CHAR16SIZE (16 * 3)
#define CHAR32SIZE (32 * 3)
#define DD60CHARS 060 // number of characters in pattern arrays
// Display parameters
#define DefaultInterval 0.1
#define DefRemoteInterval 3.0
// For display rate 0 we get all the data from the server without
// block boundary marking, so the decay machinery has to be based on
// elapsed time rather than being done at block boundaries. Define
// the delta time, in microseconds, between refresh and decay actions.
#define DecayTimeus 20000
#if defined(__WXMAC__)
#define SmallPointSize 12
#else
#define SmallPointSize 10
#endif
// Default preference settings
#define DefSizeX 84
#define DefSizeY 99
#define DefFocus 82
#define DefIntensity 160 // For fast (decaying) refresh
#define DefSlowIntens 195 // For slow (replacing) refresh
//#define DisplayMargin 8
// Literal strings for wxConfig key strings. These are defined
// because they appear in two places, so this way we avoid getting
// the two out of sync. Note that they should *not* be changed after
// once being defined, since that invalidates people's stored
// preferences.
#define PREF_FOREGROUND "foreground"
#define PREF_PORT "port"
#define PREF_CONNECT "autoconnect"
#define PREF_SIZEX "sizeX"
#define PREF_SIZEY "sizeY"
#define PREF_FOCUS "focus"
#define PREF_FASTINTENS "intensity"
#define PREF_SLOWINTENS "slowintensity"
/*
** -----------------------
** Private Macro Functions
** -----------------------
*/
#ifdef DEBUG
#define TRACEN(str) \
if (traceDd60) \
{ \
fprintf (traceF, str "\n"); \
}
#define TRACE1(str, arg) \
if (traceDd60) \
{ \
fprintf (traceF, str "\n", arg); \
}
#define TRACE2(str, arg1, arg2) \
if (traceDd60) \
{ \
fprintf (traceF, str "\n", arg1, arg2); \
}
#else
#define TRACEN(str)
#define TRACE1(str, arg)
#define TRACE2(str, arg1, arg2)
#endif
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifdef _WIN32
#include <wx/setup.h>
#endif
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/clipbrd.h"
#include "wx/colordlg.h"
#include "wx/config.h"
#include "wx/image.h"
#include "wx/filename.h"
#include "wx/metafile.h"
#include "wx/print.h"
#include "wx/printdlg.h"
#include "wx/rawbmp.h"
#include <wx/validate.h>
#include <wx/valnum.h>
#include <wx/aboutdlg.h>
extern "C"
{
#if defined(_WIN32)
#include <winsock.h>
#include <process.h>
#define round(x) floor ((x) + 0.5)
#else
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#endif
#include <stdlib.h>
#include "const.h"
#include "types.h"
#include "proto.h"
#include "dd60version.h"
#include "ptermversion.h"
#include "iir.h"
#include "knob.h"
#include "dd60.h"
#if wxUSE_LIBGNOMEPRINT
#include "wx/html/forcelnk.h"
//FORCE_LINK(gnome_print)
#endif
#if defined (__WXGTK__)
// Attempting to include the gtk.h file yields infinite compile errors, so
// instead we just declare the two functions we need, leaving any
// issues of data structures unstated.
struct GtkSettings;
extern void gtk_settings_set_string_property (GtkSettings *, const char *,
const char *, const char *);
extern GtkSettings * gtk_settings_get_default (void);
#endif
extern float mainDisplayScale (void);
}
// Note that we don't do SSE2, only AVX2 on Intel, otherwise things get
// overly complicated.
#ifdef __AVX2__
#define VECSIZE 32
#else
#ifdef __aarch64__
// Assume NEON SIMD is supported
#define VECSIZE 16
#else
#define VECSIZE 0
#endif
#endif
#if VECSIZE
typedef unsigned char bytevec __attribute__ ((vector_size (VECSIZE)));
#ifdef __aarch64__
// Arm64 SIMD
inline void addsat32 (bytevec *pmap, const bytevec *pdata)
{
asm ("uqadd %0.16b,%0.16b,%2.16b\n"
"uqadd %1.16b,%1.16b,%3.16b"
: "+w"(pmap[0]), "+w"(pmap[1])
: "w"(pdata[0]), "w"(pdata[1]));
}
#else
#if (VECSIZE == 32)
inline void addsat32 (bytevec *pmap, const bytevec *pdata)
{
*pmap = __builtin_ia32_paddusb256 (*pmap, *pdata);
}
#else
inline void addsat32 (bytevec *pmap, const bytevec *pdata)
{
pmap[0] = __builtin_ia32_paddusb128 (pmap[0], pdata[0]);
pmap[1] = __builtin_ia32_paddusb128 (pmap[1], pdata[1]);
}
#endif
#endif
#endif
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
// the application icon (under Windows and OS/2 it is in resources)
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
//#include "dd60.xpm"
#endif
#include "chargen.h"
// ----------------------------------------------------------------------------
// global variables
// ----------------------------------------------------------------------------
bool emulationActive = true;
// Global print data, to remember settings during the session
wxPrintData *g_printData;
// Global page setup data
wxPageSetupDialogData* g_pageSetupData;
// ----------------------------------------------------------------------------
// local variables
// ----------------------------------------------------------------------------
class Dd60App;
static Dd60App *dd60App;
class Dd60Panel;
static FILE *traceF;
static char traceFn[20];
#ifdef DEBUG
static wxLogWindow *logwindow;
#endif
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class Dd60Frame;
// Dd60 screen printout
class Dd60Printout: public wxPrintout
{
public:
Dd60Printout (Dd60Frame *owner,
const wxString &title = _("DD60 printout"));
bool OnPrintPage (int page);
bool HasPage (int page);
void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
void DrawPage (wxDC *dc, int page);
private:
Dd60Frame *m_owner;
};
// Define a new application type, each program should derive a class from wxApp
class Dd60App : public wxApp
{
public:
// override base class virtuals
// ----------------------------
// this one is called on application startup and is a good place for the app
// initialization (doing it here and not in the ctor allows to have an error
// return: if OnInit () returns false, the application terminates)
virtual bool OnInit (void);
virtual int OnExit (void);
// event handlers
void OnConnect (wxCommandEvent &event);
void OnPref (wxCommandEvent& event);
void OnQuit (wxCommandEvent& event);
void OnAbout (wxCommandEvent& event);
bool DoConnect (bool ask, double interval = 0.0);
static wxColour SelectColor (wxColour &initcol);
void WritePrefs (void);
wxColour m_fgColor;
wxConfig *m_config;
long m_port;
int m_sizeX;
int m_sizeY;
int m_focus;
int m_fastintens;
int m_slowintens;
bool m_connect;
double m_interval;
Dd60Frame *m_firstFrame;
wxString m_defDir;
private:
wxLocale m_locale; // locale we'll be using
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE ()
};
// define a scrollable canvas for drawing onto
class Dd60Canvas: public wxScrolledWindow
{
public:
Dd60Canvas (Dd60Frame *parent);
void OnDraw (wxDC &dc);
void OnEraseBackground (wxEraseEvent &);
void OnKey (wxKeyEvent& event);
private:
Dd60Frame *m_owner;
DECLARE_EVENT_TABLE ()
};
class Dd60StatusBar : public wxBoxSizer
{
public:
Dd60StatusBar (Dd60Frame *parent);
void SetPanel (Dd60Panel *panel);
void SetStatusText (const wxChar *str, int idx);
wxWindow *m_parent;
wxStaticText *msg1;
wxStaticText *msg3;
Dd60Panel *m_panel;
};
#if defined(__WXMAC__)
#define DD60_MDI 1
#else
#define DD60_MDI 0
#endif
#if DD60_MDI
#define Dd60FrameBase wxMDIChildFrame
class Dd60MainFrame : public wxMDIParentFrame
{
public:
Dd60MainFrame (void);
};
static Dd60MainFrame *Dd60FrameParent;
#else
#define Dd60FrameBase wxFrame
#define Dd60FrameParent NULL
#endif
// Define a new frame type: this is going to be our main frame
class Dd60Frame : public Dd60FrameBase
{
friend void Dd60Canvas::OnDraw(wxDC &dc);
friend void Dd60Printout::DrawPage (wxDC *dc, int page);
typedef wxAlphaPixelData PixelData;
public:
// ctor(s)
Dd60Frame(int port, double interval, const wxString& title);
~Dd60Frame ();
// Callback handlers
static void connCallback (NetFet *np, int portNum, void *arg);
static void dataCallback (NetFet *np, int bytes, void *arg);
// event handlers (these functions should _not_ be virtual)
void OnClose (wxCloseEvent& event);
void OnIdle (wxIdleEvent& event);
void OnQuit (wxCommandEvent& event);
void OnCopyScreen (wxCommandEvent &event);
void OnSaveScreen (wxCommandEvent &event);
void OnPrint (wxCommandEvent& event);
void OnPrintPreview (wxCommandEvent& event);
void OnPageSetup (wxCommandEvent& event);
void OnActivate (wxActivateEvent &event);
void UpdateSettings (void);
void PrepareDC(wxDC& dc);
void dd60SendKey(int key);
void dd60SetTrace (bool fileaction);
void dd60LoadChars (void);
bool traceDd60;
Dd60Frame *m_nextFrame;
Dd60Frame *m_prevFrame;
bool truekb;
int m_intens;
bool m_fastupdate;
int m_pscale;
int m_xsize;
int m_ysize;
int m_displaymargin;
int xadjust (int x) const
{
return (x + currentXOffset) * m_pscale + m_displaymargin;
}
int yadjust (int y) const
{
return y * m_pscale + m_displaymargin;
}
private:
bool m_firstTime;
Dd60StatusBar *m_statusBar;
wxPen m_foregroundPen;
wxBrush m_foregroundBrush;
wxBitmap *m_screenmap;
PixelData *m_pixmap;
u32 m_maxalpha;
#if VECSIZE
bytevec m_blank;
#endif
u32 m_red;
u32 m_green;
u32 m_blue;
struct timeval m_prevRefresh;
Dd60Canvas *m_canvas;
NetPortSet m_portset;
NetFet *m_fet;
int m_port;
int m_interval;
bool m_startBlock;
// Character patterns are stored in three pixel vectors. These are
// not bitmaps or images, because we display them by adding them
// into the current screen pixel values (similar to what the CRT
// beam would do). They are RBG to simulate the color distortion
// that comes from saturation. (That may be overkill...) The pixels
// for each character are in a contiguous set of bytes in the vector;
// the character display operation spreads them over multiple scanlines.
u8 *m_char8;
u8 *m_char16;
u8 *m_char32;
// DD60 display emulation state
int mode;
int currentX;
int currentY;
int currentXOffset;
// Trace related state
unsigned int trace_idx;
char trace_txt[120];
wxFont m_traceFont;
wxBoxSizer *m_sizer;
// Other stuff
#if VECSIZE && defined (__x86_64)
bool avx2;
#endif
// DD60 drawing primitives
void dd60SetName (wxString &winName);
void dd60SetStatus (wxString &str);
void dd60LoadCharSize (int size, int tsize, u8 *vec);
inline void procDd60Char (unsigned int d);
void dd60ShowTrace (bool enable);
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE ()
};
// define the preferences dialog
class Dd60PrefDialog : public wxDialog
{
public:
Dd60PrefDialog (Dd60Frame *parent, wxWindowID id, const wxString &title);
void OnButton (wxCommandEvent& event);
void OnCheckbox (wxCommandEvent& event);
void OnClose (wxCloseEvent &) { EndModal (wxID_CANCEL); }
wxBitmapButton *m_fgButton;
wxButton *m_okButton;
wxButton *m_cancelButton;
wxButton *m_resetButton;
wxCheckBox *m_autoConnect;
wxCheckBox *m_statusCheck;
wxTextCtrl *m_portText;
wxColour m_fgColor;
bool m_connect;
wxString m_port;
private:
void paintBitmap (wxBitmap &bm, wxColour &color);
DECLARE_EVENT_TABLE ()
};
// define the preferences dialog
class Dd60ConnDialog : public wxDialog
{
public:
Dd60ConnDialog (wxWindowID id, const wxString &title);
void OnOK (wxCommandEvent& event);
void OnClose (wxCloseEvent &) { EndModal (wxID_CANCEL); }
wxTextCtrl *m_portText;
wxComboBox *m_delayText;
wxString m_port;
wxString m_delay;
private:
DECLARE_EVENT_TABLE ()
};
// Define a panel for the controls.
class Dd60Panel : public wxPanel
{
public:
Dd60Panel (Dd60Frame *parent);
bool AcceptsFocus (void) const { return false; }
int sizeX (void) const
{
return m_sizeX->GetValue ();
}
int sizeY (void) const
{
return m_sizeY->GetValue ();
}
double beamsize (void) const { return 0.01 * m_focus->GetValue (); }
int intensity (void) const { return m_intens->GetValue (); }
#if 0
double r1_029 (void) const { return (double ) (m_r1_029->GetValue ()); }
double c1_029 (void) const { return 1.0e-12 * m_c1_029->GetValue (); }
double c1_a2 (void) const { return 1.0e-12 * m_c1_a2->GetValue (); }
double c4_a2 (void) const { return 1.0e-12 * m_c4_a2->GetValue (); }
int delay (void) const { return m_beamdelay->GetValue (); }
int red (void) const { return m_red->GetValue (); }
int green (void) const { return m_green->GetValue (); }
int blue (void) const { return m_blue->GetValue (); }
bool get620on (void) const { return m_620on->GetValue (); }
bool getc19on (void) const { return m_c19on->GetValue (); }
bool get029on (void) const { return m_029on->GetValue (); }
bool getv1aon (void) const { return m_v1aon->GetValue (); }
bool getv3on (void) const { return m_v3on->GetValue (); }
#endif
void OnScroll (wxScrollEvent& event);
private:
Dd60Frame *m_parent;
wxFlexGridSizer *m_sizer;
wxKnob *m_sizeX;
wxKnob *m_sizeY;
wxKnob *m_focus;
wxKnob *m_intens;
#if 0
wxKnob *m_c2_019;
wxKnob *m_r1_029; // 029 amp pot
wxKnob *m_c1_029; // 029 amp trimcap
wxKnob *m_c1_a2; // v1a trimcap
wxKnob *m_c4_a2; // v3 trimcap
wxKnob *m_beamdelay; // delay (in simclock ticks) for on/off
wxKnob *m_red; // red pixel value
wxKnob *m_green; // green pixel value
wxKnob *m_blue; // blue pixel value
wxCheckBox *m_620on;
wxCheckBox *m_c19on;
wxCheckBox *m_029on;
wxCheckBox *m_v1aon;
wxCheckBox *m_v3on;
#endif
// any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE()
};
// Character waveform generator. This generates the unfiltered
// waveform, i.e., an idealized waveform made up of straight lines
// (constant slope ramps, or constant voltages). It implements
// the CC545 character generator patterns from document 60469310.
class Chargen
{
public:
void SetStepCount (int n)
{
m_stepcount = n;
}
void Start (int ch)
{
m_x = m_y = 0;
m_on = false;
m_dx = 1;
m_dy = -1;
m_chardata = chargen[ch];
m_step = m_stroke = 0;
}
void Step (void);
double X (void) const
{
return m_x;
}
double Y (void) const
{
return m_y;
}
bool Done (void) const
{
return (m_stroke == sizeof (chargen[0]) / sizeof (chargen[0][0]));
}
bool On (void) const
{
return m_on;
}
private:
double m_x, m_y;
int m_dx, m_dy, m_step, m_stroke;
bool m_on;
const u8 *m_chardata;
int m_stepcount;
};
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// menu items
Dd60_CopyScreen = 1,
Dd60_ConnectAgain,
Dd60_SaveScreen,
// Menu items with standard ID values
Dd60_Print = wxID_PRINT,
Dd60_Page_Setup = wxID_PRINT_SETUP,
Dd60_Preview = wxID_PREVIEW,
Dd60_Connect = wxID_NEW,
Dd60_Quit = wxID_EXIT,
Dd60_Close = wxID_CLOSE,
Dd60_Pref = wxID_PREFERENCES,
// it is important for the id corresponding to the "About" command to have
// this standard value as otherwise it won't be handled properly under Mac
// (where it is special and put into the "Apple" menu)
Dd60_About = wxID_ABOUT
};
// ----------------------------------------------------------------------------
// event tables and other macros for wxWindows
// ----------------------------------------------------------------------------
// the event tables connect the wxWindows events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(Dd60Frame, wxFrame)
EVT_CLOSE(Dd60Frame::OnClose)
EVT_IDLE(Dd60Frame::OnIdle)
EVT_ACTIVATE(Dd60Frame::OnActivate)
EVT_MENU(Dd60_Close, Dd60Frame::OnQuit)
EVT_MENU(Dd60_CopyScreen, Dd60Frame::OnCopyScreen)
EVT_MENU(Dd60_SaveScreen, Dd60Frame::OnSaveScreen)
EVT_MENU(Dd60_Print, Dd60Frame::OnPrint)
EVT_MENU(Dd60_Preview, Dd60Frame::OnPrintPreview)
EVT_MENU(Dd60_Page_Setup, Dd60Frame::OnPageSetup)
END_EVENT_TABLE ()
BEGIN_EVENT_TABLE(Dd60App, wxApp)
EVT_MENU(Dd60_Connect, Dd60App::OnConnect)
EVT_MENU(Dd60_ConnectAgain, Dd60App::OnConnect)
EVT_MENU(Dd60_Pref, Dd60App::OnPref)
EVT_MENU(Dd60_Quit, Dd60App::OnQuit)
EVT_MENU(Dd60_About, Dd60App::OnAbout)
END_EVENT_TABLE ()
// Create a new application object: this macro will allow wxWindows to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also implements the accessor function
// wxGetApp () which will return the reference of the right type (i.e. Dd60App and
// not wxApp)
IMPLEMENT_APP(Dd60App)
// ============================================================================
// implementation
// ============================================================================
#define pi 3.14159265358979323846
// *** TEMP
#define STEPMHZ 10
#define STEPHZ (STEPMHZ * 1000000)
#define BWRATIO 100
#define BW 4
// Normal distribution (bell curve) function
static double bell (double x, double sigma)
{
return (1 / (sigma * sqrt (2. * pi))) *
exp (-((x * x) / (2. * sigma * sigma)));
}
// Number of steps per stroke element, as a function of chosen bandwidth
static int stepcount (int height)
{
return BW * BWRATIO / STEPMHZ;
}
// Normalize the intensity to account for beam size and character size
// The input intensity value is the value we want to end up with in the
// pixel for a double speed stroke.
static double normInt (int intens, int size)
{
double step = size / (4.0 * stepcount (size));
return intens * step;
}
void Dd60Frame::connCallback (NetFet *fet, int, void *arg)
{
wxWakeUpIdle ();
}
void Dd60Frame::dataCallback (NetFet *, int, void *arg)
{
wxWakeUpIdle ();
}
// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------
// 'Main program' equivalent: the program execution "starts" here
bool Dd60App::OnInit (void)
{
int r, g, b;
wxString rgb;
double interval;
dd60App = this;
m_firstFrame = NULL;
g_printData = new wxPrintData;
g_pageSetupData = new wxPageSetupDialogData;
snprintf (traceFn, sizeof (traceFn), "dd60_%d.trc", getpid ());
m_locale.Init(wxLANGUAGE_DEFAULT);
m_locale.AddCatalog(wxT("dd60"));
#ifdef DEBUG
logwindow = new wxLogWindow (NULL, "dd60 log", true, false);
#endif
if (argc > 3)
{
printf ("usage: dd60 [ interval [ portnum ]]\n");
exit (1);
}
m_config = new wxConfig (wxT ("Dd60"));
if (argc > 2)
{
argv[2].ToCLong (&m_port);
}
else
{
m_port = m_config->Read (wxT (PREF_PORT), DefDd60Port);
}
if (argc > 1)
{
argv[1].ToCDouble (&interval);
if (interval != 0.0 && (interval < 0.02 || interval > 63.0))
{
fprintf (stderr, "interval value out of range\n");
exit (1);
}
}
else
{
if (m_port == DefDd60Port)
{
interval = DefaultInterval;
}
else
{
interval = DefRemoteInterval;
}
}
// Use this interval as the initial default
m_interval = interval;
// 20 255 80 is RGB for DD60 green
m_config->Read (wxT (PREF_FOREGROUND), &rgb, wxT ("20 255 80"));
sscanf (rgb.mb_str (), "%d %d %d", &r, &g, &b);
m_fgColor = wxColour (r, g, b);
m_connect = (m_config->Read (wxT (PREF_CONNECT), 1) != 0);
m_sizeX = m_config->Read (wxT (PREF_SIZEX), DefSizeX);
m_sizeY = m_config->Read (wxT (PREF_SIZEY), DefSizeY);
m_focus = m_config->Read (wxT (PREF_FOCUS), DefFocus);
m_fastintens = m_config->Read (wxT (PREF_FASTINTENS), DefIntensity);
m_slowintens = m_config->Read (wxT (PREF_SLOWINTENS), DefSlowIntens);
#if DD60_MDI
// On Mac, the style rule is that the application keeps running even
// if all its windows are closed.
// SetExitOnFrameDelete(false);
Dd60FrameParent = new Dd60MainFrame ();
Dd60FrameParent->Show (true);
#endif
// Add some handlers so we can save the screen in various formats
// Note that the BMP handler is always loaded, don't do it again.
wxImage::AddHandler (new wxPNGHandler);
wxImage::AddHandler (new wxPNMHandler);
wxImage::AddHandler (new wxTIFFHandler);
wxImage::AddHandler (new wxXPMHandler);
// create the main application window
// If arguments are present, always connect without asking
if (!DoConnect (!(m_connect || argc > 1), interval))
{
return false;
}
// success: wxApp::OnRun () will be called which will enter the main message
// loop and the application will run. If we returned false here, the
// application would exit immediately.
return true;
}
int Dd60App::OnExit (void)
{
delete g_printData;
delete g_pageSetupData;
#ifdef DEBUG
delete logwindow;
#endif
return 0;
}
void Dd60App::OnConnect (wxCommandEvent &event)
{
DoConnect (event.GetId () == Dd60_Connect);
}
bool Dd60App::DoConnect (bool ask, double interval)
{
Dd60Frame *frame;
if (ask)
{
Dd60ConnDialog dlg (wxID_ANY, _("Connect to DtCyber console"));
dlg.CenterOnScreen ();
if (dlg.ShowModal () == wxID_OK)
{
if (dlg.m_port.IsEmpty ())
{
m_port = DefDd60Port;
}
else
{
dlg.m_port.ToCLong (&m_port);
}
if (dlg.m_delay.IsEmpty ())
{
if (m_port == DefDd60Port)
{
interval = DefaultInterval;
}
else
{
interval = DefRemoteInterval;
}
}
else
{
dlg.m_delay.ToCDouble (&interval);
if (interval != 0.0 && (interval < 0.02 || interval > 63.0))
{
fprintf (stderr, "interval value out of range\n");
return false;
}
}
}
else
{
return false; // connect canceled
}
}
// create the main application window
frame = new Dd60Frame(m_port, interval, wxT("Dd60"));
if (frame != NULL)
{
if (m_firstFrame != NULL)
{
m_firstFrame->m_prevFrame = frame;
}
frame->m_nextFrame = m_firstFrame;
m_firstFrame = frame;
// Use this interval as the default next time
m_interval = interval;
}
return (frame != NULL);
}
#ifdef __AVX2__
#define DD60_SSE L" with AVX2."
#else
#define DD60_SSE L"."
#endif
void Dd60App::OnAbout(wxCommandEvent&)
{
wxAboutDialogInfo info;
info.SetName (wxT ("DD60"));
info.SetVersion (wxT ("V" DD60VERSION));
info.SetDescription (_("DtCyber console (DD60) emulator" DD60_SSE
L"\n built with wxWidgets V" wxT (WXVERSION)
L"\n build date " wxT(PTERMBUILDDATE)));
info.SetCopyright (wxT("(C) 2004-2018 by Paul Koning"));
info.AddDeveloper ("Paul Koning");
wxAboutBox(info);
}
void Dd60App::OnPref (wxCommandEvent&)
{
Dd60Frame *frame;
Dd60PrefDialog dlg (NULL, wxID_ANY, _("Dd60 Preferences"));
if (dlg.ShowModal () == wxID_OK)
{
m_fgColor = dlg.m_fgColor;
for (frame = m_firstFrame; frame != NULL; frame = frame->m_nextFrame)
{
frame->UpdateSettings ();
}
m_port = atoi (wxString (dlg.m_port).mb_str ());
m_connect = dlg.m_connect;
WritePrefs ();
}
}
void Dd60App::WritePrefs (void)
{
wxString rgb;