-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNuanceMain.cpp
1274 lines (1126 loc) · 46.1 KB
/
NuanceMain.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
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
#include "basetypes.h"
#include <cstdio>
#include <string>
#include <windows.h>
#include <Commctrl.h>
#include <tchar.h>
#include <commdlg.h>
#include "external\glew-2.2.0\include\GL\glew.h"
#include <GL/gl.h>
#include <mutex>
#include "byteswap.h"
#include "Utility.h"
#include "comm.h"
//#include "CriticalSection.h"
#include "GLWindow.h"
#include "audio.h"
#include "mpe.h"
#include "NuonEnvironment.h"
#include "NuonMemoryMap.h"
#include "NuanceRes.h"
#include "joystick.h"
#include "video.h"
#include "ExecuteMEM.h"
#include "timer.h"
#include "Bios.h"
NuonEnvironment nuonEnv;
extern ControllerData *controller;
extern std::mutex gfx_lock;
extern VidChannel structMainChannel, structOverlayChannel;
extern bool bOverlayChannelActive, bMainChannelActive;
extern vidTexInfo videoTexInfo;
//
bool bQuit = false;
static bool bRun = false;
static bool load4firsttime = true;
GLWindow display;
static HICON iconApp;
static HBITMAP bmpLEDOn;
static HBITMAP bmpLEDOff;
static HWND picMPE0LED;
static HWND picMPE1LED;
static HWND picMPE2LED;
static HWND picMPE3LED;
static HWND textMPE0;
static HWND textMPE1;
static HWND textMPE2;
static HWND textMPE3;
static HWND textMPE0Pcexec;
static HWND textMPE1Pcexec;
static HWND textMPE2Pcexec;
static HWND textMPE3Pcexec;
static HWND cbLoadFile;
static HWND cbCfgInput;
static HWND cbSingleStep;
static HWND cbRun;
static HWND cbStop;
static HWND cbReset;
static HWND reTermDisplay;
static HWND cbCommStatus;
static HWND cbDisplayStatus;
static HWND cbMPEStatus;
static HWND cbDumpMPEs;
static HWND cbKprintfLog;
static HWND reStatus;
static OPENFILENAME ofn;
static char openFileName[512];
static unsigned long disassemblyMPE = 3;
static char whichStatus = -1;
static bool GetMPERunStatus(const uint32 which)
{
return (nuonEnv.mpe[which & 0x03].mpectl & MPECTRL_MPEGO) != 0;
}
static void SetMPERunStatus(const uint32 which, const bool run)
{
if(run)
nuonEnv.mpe[which & 0x03].mpectl |= MPECTRL_MPEGO;
else
nuonEnv.mpe[which & 0x03].mpectl &= ~MPECTRL_MPEGO;
}
static void UpdateStatusWindowDisplay()
{
char buf[1024];
if(whichStatus == 0)
{
sprintf_s(buf, sizeof(buf),"Pending Comm Requests = %lu\n",nuonEnv.pendingCommRequests);
SendMessage(reStatus,WM_SETTEXT,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE0 commctl = $%8.8lx, commxmit0 = $%8.8lx, commrecv0 = $%8.8lx, comminfo = $%8.8lx\n",nuonEnv.mpe[0].commctl,nuonEnv.mpe[0].commxmit[0],nuonEnv.mpe[0].commrecv[0],nuonEnv.mpe[0].comminfo);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE1 commctl = $%8.8lx, commxmit0 = $%8.8lx, commrecv0 = $%8.8lx, comminfo = $%8.8lx\n",nuonEnv.mpe[1].commctl,nuonEnv.mpe[1].commxmit[0],nuonEnv.mpe[1].commrecv[0],nuonEnv.mpe[1].comminfo);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE2 commctl = $%8.8lx, commxmit0 = $%8.8lx, commrecv0 = $%8.8lx, comminfo = $%8.8lx\n",nuonEnv.mpe[2].commctl,nuonEnv.mpe[2].commxmit[0],nuonEnv.mpe[2].commrecv[0],nuonEnv.mpe[2].comminfo);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE3 commctl = $%8.8lx, commxmit0 = $%8.8lx, commrecv0 = $%8.8lx, comminfo = $%8.8lx\n",nuonEnv.mpe[3].commctl,nuonEnv.mpe[3].commxmit[0],nuonEnv.mpe[3].commrecv[0],nuonEnv.mpe[3].comminfo);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
}
else if(whichStatus == 1)
{
sprintf_s(buf, sizeof(buf),"Main Channel = %s : Overlay Channel = %s\n",bMainChannelActive ? "ON" : "OFF",bOverlayChannelActive ? "ON" : "OFF");
SendMessage(reStatus,WM_SETTEXT,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Main Channel texture coordinates = (%.3f %.3f), (%.3f %.3f), (%.3f %.3f), (%.3f %.3f)\n",
videoTexInfo.mainTexCoords[0],videoTexInfo.mainTexCoords[1],
videoTexInfo.mainTexCoords[2],videoTexInfo.mainTexCoords[3],
videoTexInfo.mainTexCoords[4],videoTexInfo.mainTexCoords[5],
videoTexInfo.mainTexCoords[6],videoTexInfo.mainTexCoords[7]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Overlay Channel texture coordinates = (%.3f %.3f), (%.3f %.3f), (%.3f %.3f), (%.3f %.3f)\n",
videoTexInfo.osdTexCoords[0],videoTexInfo.osdTexCoords[1],
videoTexInfo.osdTexCoords[2],videoTexInfo.osdTexCoords[3],
videoTexInfo.osdTexCoords[4],videoTexInfo.osdTexCoords[5],
videoTexInfo.osdTexCoords[6],videoTexInfo.osdTexCoords[7]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Main Channel pixel type = %lu, Overlay Channel pixel type = %lu\n",(structMainChannel.dmaflags >> 4) & 0xF,(structOverlayChannel.dmaflags >> 4) & 0xF);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Main Channel base = $%8.8lx, Overlay Channel base = $%8.8lx\n",(structMainChannel.base),(structOverlayChannel.base));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Main Channel src_width = %lu, Main Channel src_height = %lu\n",(structMainChannel.src_width),(structMainChannel.src_height));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Main Channel dest_width = %lu, Main Channel dest_height = %lu\n",(structMainChannel.dest_width),(structMainChannel.dest_height));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Main Channel src_xoff = %lu, Main Channel src_yoff = %lu\n",(structMainChannel.src_xoff),(structMainChannel.src_yoff));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Main Channel dest_xoff = %lu, Main Channel dest_yoff = %lu\n",(structMainChannel.dest_xoff),(structMainChannel.dest_yoff));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Overlay Channel src_width = %lu, Overlay Channel src_height = %lu\n",(structOverlayChannel.src_width),(structOverlayChannel.src_height));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Overlay Channel dest_width = %lu, Overlay Channel dest_height = %lu\n",(structOverlayChannel.dest_width),(structOverlayChannel.dest_height));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Overlay Channel src_xoff = %lu, Overlay Channel src_yoff = %lu\n",(structOverlayChannel.src_xoff),(structOverlayChannel.src_yoff));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Overlay Channel dest_xoff = %lu, Overlay Channel dest_yoff = %lu\n",(structOverlayChannel.dest_xoff),(structOverlayChannel.dest_yoff));
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
}
else if (whichStatus == 2)
{
sprintf_s(buf, sizeof(buf),"Interpreter cache flushes: (%u, %u, %u, %u)\n",
nuonEnv.mpe[0].numInterpreterCacheFlushes,
nuonEnv.mpe[1].numInterpreterCacheFlushes,
nuonEnv.mpe[2].numInterpreterCacheFlushes,
nuonEnv.mpe[3].numInterpreterCacheFlushes);
SendMessage(reStatus,WM_SETTEXT,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Native code cache flushes: (%u, %u, %u, %u)\n",
nuonEnv.mpe[0].numNativeCodeCacheFlushes,
nuonEnv.mpe[1].numNativeCodeCacheFlushes,
nuonEnv.mpe[2].numNativeCodeCacheFlushes,
nuonEnv.mpe[3].numNativeCodeCacheFlushes);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Non-compilable packets: (%u, %u, %u, %u)\n",
nuonEnv.mpe[0].numNonCompilablePackets,
nuonEnv.mpe[1].numNonCompilablePackets,
nuonEnv.mpe[2].numNonCompilablePackets,
nuonEnv.mpe[3].numNonCompilablePackets);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Overlays in use: (%u, %u, %u, %u)\n",
nuonEnv.mpe[0].overlayManager.GetOverlaysInUse(),
nuonEnv.mpe[1].overlayManager.GetOverlaysInUse(),
nuonEnv.mpe[2].overlayManager.GetOverlaysInUse(),
nuonEnv.mpe[3].overlayManager.GetOverlaysInUse());
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE3 intvec1 = $%8.8lx, intvec2 = $%8.8lx\n",nuonEnv.mpe[3].intvec1,nuonEnv.mpe[3].intvec2);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE3 intctl = $%8.8lx, inten1 = $%8.8lx, inten2sel = $%8.8lx\n",nuonEnv.mpe[3].intctl,nuonEnv.mpe[3].inten1,nuonEnv.mpe[3].inten2sel);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE3 intsrc = $%8.8lx, excepsrc = $%8.8lx\n",nuonEnv.mpe[3].intsrc,nuonEnv.mpe[3].excepsrc);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE2 intvec1 = $%8.8lx, intvec2 = $%8.8lx\n",nuonEnv.mpe[2].intvec1,nuonEnv.mpe[2].intvec2);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE2 intctl = $%8.8lx, inten1 = $%8.8lx, inten2sel = $%8.8lx\n",nuonEnv.mpe[2].intctl,nuonEnv.mpe[2].inten1,nuonEnv.mpe[2].inten2sel);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE2 intsrc = $%8.8lx, excepsrc = $%8.8lx\n",nuonEnv.mpe[2].intsrc,nuonEnv.mpe[2].excepsrc);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE1 intvec1 = $%8.8lx, intvec2 = $%8.8lx\n",nuonEnv.mpe[1].intvec1,nuonEnv.mpe[1].intvec2);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE1 intctl = $%8.8lx, inten1 = $%8.8lx, inten2sel = $%8.8lx\n",nuonEnv.mpe[1].intctl,nuonEnv.mpe[1].inten1,nuonEnv.mpe[1].inten2sel);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE1 intsrc = $%8.8lx, excepsrc = $%8.8lx\n",nuonEnv.mpe[1].intsrc,nuonEnv.mpe[1].excepsrc);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE0 intvec1 = $%8.8lx, intvec2 = $%8.8lx\n",nuonEnv.mpe[0].intvec1,nuonEnv.mpe[0].intvec2);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE0 intctl = $%8.8lx, inten1 = $%8.8lx, inten2sel = $%8.8lx\n",nuonEnv.mpe[0].intctl,nuonEnv.mpe[0].inten1,nuonEnv.mpe[0].inten2sel);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE0 intsrc = $%8.8lx, excepsrc = $%8.8lx\n",nuonEnv.mpe[0].intsrc,nuonEnv.mpe[0].excepsrc);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"Stack pointers = [0: $%8.8lx, 1: $%8.8lx, 2: $%8.8lx, 3: $%8.8lx]\n",nuonEnv.mpe[0].sp,nuonEnv.mpe[1].sp,nuonEnv.mpe[2].sp,nuonEnv.mpe[3].sp);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"MPE %u:\n", disassemblyMPE);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v0 = (r00: $%8.8lx, r01: $%8.8lx, r02: $%8.8lx, r03: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[0],nuonEnv.mpe[disassemblyMPE].regs[1],nuonEnv.mpe[disassemblyMPE].regs[2],nuonEnv.mpe[disassemblyMPE].regs[3]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v1 = (r04: $%8.8lx, r05: $%8.8lx, r06: $%8.8lx, r07: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[4],nuonEnv.mpe[disassemblyMPE].regs[5],nuonEnv.mpe[disassemblyMPE].regs[6],nuonEnv.mpe[disassemblyMPE].regs[7]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v2 = (r08: $%8.8lx, r09: $%8.8lx, r10: $%8.8lx, r11: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[8],nuonEnv.mpe[disassemblyMPE].regs[9],nuonEnv.mpe[disassemblyMPE].regs[10],nuonEnv.mpe[disassemblyMPE].regs[11]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v3 = (r12: $%8.8lx, r13: $%8.8lx, r14: $%8.8lx, r15: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[12],nuonEnv.mpe[disassemblyMPE].regs[13],nuonEnv.mpe[disassemblyMPE].regs[14],nuonEnv.mpe[disassemblyMPE].regs[15]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v4 = (r16: $%8.8lx, r17: $%8.8lx, r18: $%8.8lx, r19: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[16],nuonEnv.mpe[disassemblyMPE].regs[17],nuonEnv.mpe[disassemblyMPE].regs[18],nuonEnv.mpe[disassemblyMPE].regs[19]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v5 = (r20: $%8.8lx, r21: $%8.8lx, r22: $%8.8lx, r23: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[20],nuonEnv.mpe[disassemblyMPE].regs[21],nuonEnv.mpe[disassemblyMPE].regs[22],nuonEnv.mpe[disassemblyMPE].regs[23]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v6 = (r24: $%8.8lx, r25: $%8.8lx, r26: $%8.8lx, r27: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[24],nuonEnv.mpe[disassemblyMPE].regs[25],nuonEnv.mpe[disassemblyMPE].regs[26],nuonEnv.mpe[disassemblyMPE].regs[27]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"v7 = (r28: $%8.8lx, r29: $%8.8lx, r30: $%8.8lx, r31: $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].regs[28],nuonEnv.mpe[disassemblyMPE].regs[29],nuonEnv.mpe[disassemblyMPE].regs[30],nuonEnv.mpe[disassemblyMPE].regs[31]);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"cc/rc0/rc1 = ($%8.8lx, $%8.8lx, $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].cc,nuonEnv.mpe[disassemblyMPE].rc0,nuonEnv.mpe[disassemblyMPE].rc1);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"rx/ry/ru/rv = ($%8.8lx, $%8.8lx, $%8.8lx, $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].rx,nuonEnv.mpe[disassemblyMPE].ry,nuonEnv.mpe[disassemblyMPE].ru,nuonEnv.mpe[disassemblyMPE].rv);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"rz/rzi1/rzi2 = ($%8.8lx, $%8.8lx, $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].rz,nuonEnv.mpe[disassemblyMPE].rzi1,nuonEnv.mpe[disassemblyMPE].rzi2);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"xyctl/uvctl/xyrange/uvrange = ($%8.8lx, $%8.8lx, $%8.8lx, $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].xyctl,nuonEnv.mpe[disassemblyMPE].uvctl,nuonEnv.mpe[disassemblyMPE].xyrange,nuonEnv.mpe[disassemblyMPE].uvrange);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
sprintf_s(buf, sizeof(buf),"acshift/svshift = ($%8.8lx, $%8.8lx)\n",nuonEnv.mpe[disassemblyMPE].acshift,nuonEnv.mpe[disassemblyMPE].svshift);
SendMessage(reStatus,EM_REPLACESEL,NULL,LPARAM(buf));
SendMessage(reStatus,EM_SETSEL,WPARAM(-1),LPARAM(-1));
}
else if (whichStatus == 3)
{
size_t i = nuonEnv.kprintCurrentLine;
bool first = true;
do {
i = (i + 1) % NuonEnvironment::KPRINT_RING_SIZE;
sprintf_s(buf, sizeof(buf), "%s\n", nuonEnv.kprintRingBuffer[i]);
if (first) {
SendMessage(reStatus, WM_SETTEXT, NULL, LPARAM(buf));
first = false;
}
else
{
SendMessage(reStatus, EM_REPLACESEL, NULL, LPARAM(buf));
}
SendMessage(reStatus, EM_SETSEL, WPARAM(-1), LPARAM(-1));
} while (i != nuonEnv.kprintCurrentLine);
}
}
static void UpdateControlPanelDisplay()
{
const HWND ledHandles[] = {picMPE0LED,picMPE1LED,picMPE2LED,picMPE3LED};
const HWND pcexecHandles[] = {textMPE0Pcexec,textMPE1Pcexec,textMPE2Pcexec,textMPE3Pcexec};
for(uint32 i = 0; i < 4; i++)
{
SendMessage(ledHandles[i],STM_SETIMAGE,IMAGE_BITMAP, GetMPERunStatus(i) ? LPARAM(bmpLEDOn) : LPARAM(bmpLEDOff));
char addressStr[16];
sprintf_s(addressStr, sizeof(addressStr), "$%8.8lX", GetMPERunStatus(i) ? nuonEnv.mpe[i].pcexec : 0);
SendMessage(pcexecHandles[i],WM_SETTEXT,0,LPARAM(addressStr));
}
char buf[1024];
sprintf_s(buf, sizeof(buf),"mpe%lu: $%8.8X\n{\n", disassemblyMPE, GetMPERunStatus(disassemblyMPE) ? nuonEnv.mpe[disassemblyMPE].pcexec : 0);
SendMessage(reTermDisplay,WM_SETTEXT,NULL,LPARAM(buf));
SendMessage(reTermDisplay,EM_SETSEL,WPARAM(-1),LPARAM(-1));
if(GetMPERunStatus(disassemblyMPE))
nuonEnv.mpe[disassemblyMPE].PrintInstructionCachePacket(buf, sizeof(buf), nuonEnv.mpe[disassemblyMPE].pcexec);
else
buf[0] = '\0';
SendMessage(reTermDisplay,EM_REPLACESEL,NULL,LPARAM(buf));
sprintf_s(buf, sizeof(buf),"}\n");
SendMessage(reTermDisplay,EM_REPLACESEL,NULL,LPARAM(buf));
}
static void OnMPELEDDoubleClick(uint32 which)
{
const HWND handles[] = {picMPE0LED,picMPE1LED,picMPE2LED,picMPE3LED};
which = which & 0x03;
const bool rs = GetMPERunStatus(which);
SetMPERunStatus(which,!rs);
SendMessage(handles[which],STM_SETIMAGE,IMAGE_BITMAP,rs ? LPARAM(bmpLEDOff) : LPARAM(bmpLEDOn));
}
static void ExecuteSingleStep()
{
nuonEnv.mpe[3].ExecuteSingleStep();
nuonEnv.mpe[2].ExecuteSingleStep();
nuonEnv.mpe[1].ExecuteSingleStep();
nuonEnv.mpe[0].ExecuteSingleStep();
if(nuonEnv.pendingCommRequests)
DoCommBusController();
}
static void SetDisassemblyMPE(int mpeIndex)
{
disassemblyMPE = mpeIndex;
UpdateControlPanelDisplay();
}
void StopEmulation(int mpeIndex)
{
EnableWindow(cbStop, FALSE);
EnableWindow(cbSingleStep, TRUE);
EnableWindow(cbLoadFile, FALSE);
EnableWindow(cbRun, TRUE);
bRun = false;
SetDisassemblyMPE(mpeIndex);
}
INT_PTR CALLBACK StatusWindowDialogProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
bQuit = true;
return FALSE;
case WM_COMMAND:
switch(HIWORD(wParam))
{
case BN_CLICKED:
if((HWND)lParam == cbCommStatus)
{
whichStatus = 0;
UpdateStatusWindowDisplay();
return TRUE;
}
else if((HWND)lParam == cbDisplayStatus)
{
whichStatus = 1;
UpdateStatusWindowDisplay();
return TRUE;
}
else if((HWND)lParam == cbMPEStatus)
{
whichStatus = 2;
UpdateStatusWindowDisplay();
return TRUE;
}
else if((HWND)lParam == cbDumpMPEs)
{
FILE* outFile;
if ( fopen_s(&outFile, "mpe0.bin","wb") == 0 )
{
fwrite(nuonEnv.mpe[0].dtrom,sizeof(uint8),MPE_LOCAL_MEMORY_SIZE,outFile);
fclose(outFile);
}
if ( fopen_s(&outFile, "mpe1.bin","wb") == 0 )
{
fwrite(nuonEnv.mpe[1].dtrom,sizeof(uint8),MPE_LOCAL_MEMORY_SIZE,outFile);
fclose(outFile);
}
if ( fopen_s(&outFile, "mpe2.bin","wb") == 0 )
{
fwrite(nuonEnv.mpe[2].dtrom,sizeof(uint8),MPE_LOCAL_MEMORY_SIZE,outFile);
fclose(outFile);
}
if ( fopen_s(&outFile, "mpe3.bin","wb") == 0 )
{
fwrite(nuonEnv.mpe[3].dtrom,sizeof(uint8),MPE_LOCAL_MEMORY_SIZE,outFile);
fclose(outFile);
}
return TRUE;
}
else if((HWND)lParam == cbKprintfLog)
{
whichStatus = 3;
UpdateStatusWindowDisplay();
return TRUE;
}
default:
return FALSE;
}
default:
return FALSE;
}
}
void Run()
{
uint32 bpAddr = 0;
FILE* inFile;
if ( fopen_s(&inFile, "breakpoint.txt", "r") == 0 )
{
fscanf_s(inFile,"%x",&bpAddr);
fclose(inFile);
}
nuonEnv.mpe[0].breakpointAddress = bpAddr;
nuonEnv.mpe[1].breakpointAddress = bpAddr;
nuonEnv.mpe[2].breakpointAddress = bpAddr;
nuonEnv.mpe[3].breakpointAddress = bpAddr;
EnableWindow(cbLoadFile,FALSE);
EnableWindow(cbRun,FALSE);
EnableWindow(cbSingleStep,FALSE);
EnableWindow(cbStop,TRUE);
bRun = true;
}
bool Load(const char* file = nullptr)
{
if(file || GetOpenFileName(&ofn))
{
if(file)
ofn.lpstrFile = (char*)file;
bool bSuccess = nuonEnv.mpe[3].LoadNuonRomFile(ofn.lpstrFile);
if(!bSuccess)
{
bSuccess = nuonEnv.mpe[3].LoadCoffFile(ofn.lpstrFile);
if(file && !bSuccess)
{
MessageBox(NULL,"Cannot open file or Invalid COFF or NUONROM-DISK file",ERROR,MB_ICONWARNING);
exit(0);
}
else if(!bSuccess)
MessageBox(NULL,"Invalid COFF or NUONROM-DISK file",ERROR,MB_ICONWARNING);
}
if(bSuccess)
{
nuonEnv.SetDVDBaseFromFileName(ofn.lpstrFile);
nuonEnv.mpe[3].Go();
UpdateControlPanelDisplay();
SetWindowPos(display.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
Run();
return true;
}
}
return false;
}
static int EditIDToCtrlrBitnum(int id)
{
switch (id)
{
case IDC_SET_DUP:
return CTRLR_BITNUM_DPAD_UP;
case IDC_SET_DRIGHT:
return CTRLR_BITNUM_DPAD_RIGHT;
case IDC_SET_DDOWN:
return CTRLR_BITNUM_DPAD_DOWN;
case IDC_SET_DLEFT:
return CTRLR_BITNUM_DPAD_LEFT;
case IDC_SET_CUP:
return CTRLR_BITNUM_BUTTON_C_UP;
case IDC_SET_CRIGHT:
return CTRLR_BITNUM_BUTTON_C_RIGHT;
case IDC_SET_CDOWN:
return CTRLR_BITNUM_BUTTON_C_DOWN;
case IDC_SET_CLEFT:
return CTRLR_BITNUM_BUTTON_C_LEFT;
case IDC_SET_A:
return CTRLR_BITNUM_BUTTON_A;
case IDC_SET_B:
return CTRLR_BITNUM_BUTTON_B;
case IDC_SET_L:
return CTRLR_BITNUM_BUTTON_L;
case IDC_SET_R:
return CTRLR_BITNUM_BUTTON_R;
case IDC_SET_NUON:
return CTRLR_BITNUM_BUTTON_NUON;
case IDC_SET_START:
return CTRLR_BITNUM_BUTTON_START;
default:
return -1;
}
}
void SetNewMapping(HWND hWnd, InputManager::InputType type, int idx, int subIdx)
{
char mappingStr[ControllerButtonMapping::MAPPING_STRING_SIZE];
ControllerButtonMapping newMap(type, idx, subIdx);
newMap.toString(mappingStr, _countof(mappingStr));
SetWindowText(hWnd, mappingStr);
SetFocus(GetNextDlgTabItem(GetParent(hWnd), hWnd, FALSE));
}
static WNDPROC pOrigEditProc;
LRESULT APIENTRY SetButtonControlProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Call down to base control handler first.
LRESULT res = CallWindowProc(pOrigEditProc, hWnd, uMsg, wParam, lParam);
// Intercept most keydown messages.
if ((uMsg == WM_GETDLGCODE) && lParam)
{
MSG* msg = (MSG*)lParam;
if (msg->message == WM_KEYDOWN)
{
switch (msg->wParam)
{
// Use default processing for Escape
case VK_ESCAPE:
break;
default:
SetNewMapping(hWnd, InputManager::KEY, (int)wParam, 0);
return DLGC_WANTMESSAGE;
}
}
}
return res;
}
struct JoyPressedCtx
{
InputManager::InputType type;
int idx;
int subIdx;
bool pressed;
};
static void AnyJoyPressed(void* ctx, InputManager::InputType type, int idx, int subIdx)
{
JoyPressedCtx * const joyCtx = (JoyPressedCtx *)ctx;
if (!joyCtx->pressed)
{
joyCtx->type = type;
joyCtx->idx = idx;
joyCtx->subIdx = subIdx;
joyCtx->pressed = true;
}
}
#define FOR_ALL_JOY_EDIT_CTRLS(_op) \
_op(IDC_SET_DUP); \
_op(IDC_SET_DDOWN); \
_op(IDC_SET_DLEFT); \
_op(IDC_SET_DRIGHT); \
_op(IDC_SET_START); \
_op(IDC_SET_NUON); \
_op(IDC_SET_CUP); \
_op(IDC_SET_CDOWN); \
_op(IDC_SET_CLEFT); \
_op(IDC_SET_CRIGHT); \
_op(IDC_SET_A); \
_op(IDC_SET_B); \
_op(IDC_SET_L); \
_op(IDC_SET_R)
static constexpr unsigned int IDT_JOY_TIMER = 0x00000001;
static HWND hFocusedWnd = nullptr;
static int joyGrabbed = -1;
INT_PTR CALLBACK CfgInputDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
InputManager* im = display.GetInputManager();
switch (msg)
{
case WM_INITDIALOG:
if (im)
{
size_t numJoysticks;
const Joystick* pJoysticks = im->EnumJoysticks(&numJoysticks);
const GUID& controller1Joystick = nuonEnv.GetController1Joystick();
int controller1JoystickIdx = -1;
HWND hwndCtrl = GetDlgItem(hwndDlg, IDC_JOYSTICK_COMBO);
for (size_t i = 0; i < numJoysticks; i++) {
SendMessage(hwndCtrl, CB_ADDSTRING, 0, (LPARAM)pJoysticks[i].tszName);
if (controller1Joystick == pJoysticks[i].guid)
{
controller1JoystickIdx = i;
}
}
if (numJoysticks)
{
if (controller1JoystickIdx < 0) controller1JoystickIdx = 0;
SendMessage(hwndCtrl, CB_SETCURSEL, controller1JoystickIdx, 0);
if (im->GrabJoystick(hwndDlg, controller1JoystickIdx)) joyGrabbed = controller1JoystickIdx;
}
else
{
SendMessage(hwndCtrl, CB_ADDSTRING, 0, (LPARAM)"No Joystick/Joypad controller found");
SendMessage(hwndCtrl, CB_SETCURSEL, 0, 0);
}
char mappingStr[ControllerButtonMapping::MAPPING_STRING_SIZE];
#define INIT_CTRLR_EDIT(id) \
do { \
hwndCtrl = GetDlgItem(hwndDlg, (id)); \
WNDPROC proc = (WNDPROC)SetWindowLongPtr(hwndCtrl, GWL_WNDPROC, (LONG_PTR)SetButtonControlProc); \
if (pOrigEditProc) \
{ \
assert(pOrigEditProc == proc); \
} \
else \
{ \
pOrigEditProc = proc; \
} \
nuonEnv.GetMappingForCTRLRBitnum(EditIDToCtrlrBitnum(id)).toString(mappingStr, _countof(mappingStr)); \
SetWindowText(hwndCtrl, mappingStr); \
} while (0)
FOR_ALL_JOY_EDIT_CTRLS(INIT_CTRLR_EDIT);
#undef INIT_CTRLR_EDIT
}
break;
case WM_DESTROY:
if (im)
{
HWND hwndCtrl;
#define UNINIT_CTRLR_EDIT(id) \
do { \
hwndCtrl = GetDlgItem(hwndDlg, (id)); \
SetWindowLongPtr(hwndCtrl, GWL_WNDPROC, (LONG_PTR)pOrigEditProc); \
} while(0)
FOR_ALL_JOY_EDIT_CTRLS(UNINIT_CTRLR_EDIT);
#undef UNINIT_CTRLR_EDIT
}
return TRUE;
case WM_CTLCOLORSTATIC:
{
HWND hWndCtrl = (HWND)lParam;
if (hWndCtrl == hFocusedWnd)
{
HDC hDC = (HDC)wParam;
SetBkColor(hDC, RGB(182, 208, 226));
return (INT_PTR)CreateSolidBrush(RGB(182, 208, 226));
}
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDB_OK:
{
EndDialog(hwndDlg, TRUE);
if (joyGrabbed >= 0)
{
im->UngrabJoystick();
joyGrabbed = -1;
}
HWND hJoyCombo = GetDlgItem(hwndDlg, IDC_JOYSTICK_COMBO);
LRESULT res = SendMessage(hJoyCombo, CB_GETCURSEL, 0, 0);
if (res != CB_ERR)
{
size_t numJoysticks;
const Joystick* pJoysticks = im->EnumJoysticks(&numJoysticks);
im->SetJoystick((size_t)res);
nuonEnv.SetController1Joystick(pJoysticks[res].guid);
}
#define APPLY_MAPPING(id) \
do { \
HWND hEditWnd = GetDlgItem(hwndDlg, (id)); \
char dlgText[ControllerButtonMapping::MAPPING_STRING_SIZE]; \
GetWindowTextA(hEditWnd, dlgText, _countof(dlgText)); \
ControllerButtonMapping newMap; \
ControllerButtonMapping::fromString(dlgText, &newMap); \
nuonEnv.SetControllerButtonMapping(EditIDToCtrlrBitnum(id), newMap); \
} while (0)
FOR_ALL_JOY_EDIT_CTRLS(APPLY_MAPPING);
#undef APPLY_MAPPING
}
return TRUE;
case IDB_CANCEL:
EndDialog(hwndDlg, FALSE);
if (joyGrabbed >= 0)
{
im->UngrabJoystick();
joyGrabbed = -1;
}
return TRUE;
case IDC_JOYSTICK_COMBO:
if (HIWORD(wParam) != CBN_SELENDOK) break;
if (joyGrabbed >= 0)
{
im->UngrabJoystick();
}
if (im)
{
HWND hJoyCombo = (HWND)lParam;
LRESULT res = SendMessage(hJoyCombo, CB_GETCURSEL, 0, 0);
if (res != CB_ERR)
{
if (im->GrabJoystick(hwndDlg, (size_t)res)) joyGrabbed = (int)res;
}
else
{
MessageBox(NULL, _T("Error sending GETCURSEL message"), _T("Error"), MB_ICONERROR);
}
}
return TRUE;
case IDC_SET_DUP:
case IDC_SET_DDOWN:
case IDC_SET_DLEFT:
case IDC_SET_DRIGHT:
case IDC_SET_START:
case IDC_SET_NUON:
case IDC_SET_CUP:
case IDC_SET_CDOWN:
case IDC_SET_CLEFT:
case IDC_SET_CRIGHT:
case IDC_SET_A:
case IDC_SET_B:
case IDC_SET_L:
case IDC_SET_R:
switch (HIWORD(wParam))
{
case EN_SETFOCUS:
{
HWND hEdit = (HWND)lParam;
hFocusedWnd = hEdit;
if (joyGrabbed >= 0)
{
im->UpdateState(NULL, NULL, NULL);
SetTimer(hwndDlg, IDT_JOY_TIMER, 50, nullptr);
}
InvalidateRect(hEdit, NULL, FALSE);
break;
}
case EN_KILLFOCUS:
{
HWND hEdit = (HWND)lParam;
if (hFocusedWnd == hEdit)
{
if (joyGrabbed >= 0) KillTimer(hwndDlg, IDT_JOY_TIMER);
hFocusedWnd = nullptr;
InvalidateRect(hEdit, NULL, FALSE);
}
break;
}
default:
break;
}
break;
}
case WM_TIMER:
if ((wParam == IDT_JOY_TIMER) && im && hFocusedWnd)
{
JoyPressedCtx ctx;
ctx.pressed = false;
im->UpdateState(NULL, AnyJoyPressed, &ctx);
if (ctx.pressed)
{
SetNewMapping(hFocusedWnd, ctx.type, ctx.idx, ctx.subIdx);
}
return 0;
}
break;
default:
break;
}
return FALSE;
}
INT_PTR CALLBACK ControlPanelDialogProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
bQuit = true;
return FALSE;
case WM_COMMAND:
switch(HIWORD(wParam))
{
case BN_CLICKED: /* Alias for STN_CLICKED */
if((HWND)lParam == cbRun)
{
Run();
return TRUE;
}
else if((HWND)lParam == cbSingleStep)
{
EnableWindow(cbRun,FALSE);
EnableWindow(cbSingleStep,FALSE);
EnableWindow(cbStop,TRUE);
ExecuteSingleStep();
UpdateStatusWindowDisplay();
UpdateControlPanelDisplay();
EnableWindow(cbRun,TRUE);
EnableWindow(cbSingleStep,TRUE);
EnableWindow(cbStop,FALSE);
return TRUE;
}
else if((HWND)lParam == cbStop)
{
StopEmulation(disassemblyMPE);
return TRUE;
}
else if((HWND)lParam == cbReset)
{
for(uint32 i = 0; i < 4; i++)
nuonEnv.mpe[i].Reset();
EnableWindow(cbLoadFile, TRUE);
return TRUE;
}
else if((HWND)lParam == cbLoadFile)
{
if (!load4firsttime)
nuonEnv.InitBios(); //!! hacky, but seems to work
if (Load())
load4firsttime = false;
return TRUE;
}
else if ((HWND)lParam == cbCfgInput)
{
HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwndDlg, GWL_HINSTANCE);
if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_CFG_INPUT), hwndDlg, CfgInputDialogProc))
{
if (MessageBox(hwndDlg, _T("Save Joystick config to configuration file?"), _T("Save Config"), MB_YESNO | MB_ICONQUESTION) == IDYES)
{
nuonEnv.SaveConfigFile(nullptr);
}
}
}
else if((HWND)lParam == textMPE0)
{
SetDisassemblyMPE(0);
}
else if((HWND)lParam == textMPE1)
{
SetDisassemblyMPE(1);
}
else if((HWND)lParam == textMPE2)
{
SetDisassemblyMPE(2);
}
else if((HWND)lParam == textMPE3)
{
SetDisassemblyMPE(3);
}
return TRUE;
case STN_DBLCLK:
{
if((HWND)lParam == picMPE0LED)
{
OnMPELEDDoubleClick(0);
return TRUE;
}
else if((HWND)lParam == picMPE1LED)
{
OnMPELEDDoubleClick(1);
return TRUE;
}
else if((HWND)lParam == picMPE2LED)
{
OnMPELEDDoubleClick(2);
return TRUE;
}
else if((HWND)lParam == picMPE3LED)
{
OnMPELEDDoubleClick(3);
return TRUE;
}
}
}
default:
return FALSE;
}
}
INT_PTR CALLBACK SplashScreenDialogProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CTLCOLORDLG:
return INT_PTR(GetStockObject(BLACK_BRUSH));
default:
return FALSE;
}
}
bool OnDisplayPaint(WPARAM wparam, LPARAM lparam)
{
if(bRun)
RenderVideo(display.clientWidth,display.clientHeight);
else
{
if(bUseSeparateThread) gfx_lock.lock();
glClear(GL_COLOR_BUFFER_BIT);
//glFlush();
SwapBuffers(display.hDC);
if(bUseSeparateThread) gfx_lock.unlock();
}
return true;
}
bool OnDisplayResize(uint16 width, uint16 height)
{
if(bUseSeparateThread) gfx_lock.lock();
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glClear(GL_COLOR_BUFFER_BIT);