-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1546 lines (1296 loc) · 39.3 KB
/
main.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
#define STRICT
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <windowsx.h>
#include "dd.h"
#include "resource.h"
#include "stdio.h"
#include "types.h"
#include "movie.h"
#include <ddraw.h>
#include "hotkey.h"
#include "CommDlg.h"
#include "mednafen.h"
#include "general.h"
#include "CWindow.h"
#include "memView.h"
#include "ramwatch.h"
#include "ramsearch.h"
#include "Mmsystem.h"
#include "sound.h"
#include "aviout.h"
#include "video.h"
#include "aggdraw.h"
#include "GPU_osd.h"
#include "replay.h"
#include "pcejin.h"
#include "svnrev.h"
#include "xstring.h"
#include "lua-engine.h"
#include "recentmenu.h"
#include "shellapi.h"
#include "ParseCmdLine.h"
const int RECENTROM_START = 65000;
const int RECENTMOVIE_START = 65020;
const int RECENTLUA_START = 65040;
char Tmp_Str[1024];
//These are so that the commandline arguments can override autoload ones
bool skipAutoLoadROM = false;
bool skipAutoLoadMovie = false;
bool skipAutoLoadLua = false;
std::string GameName = "";
Pcejin pcejin;
SoundDriver * soundDriver = 0;
EmulateSpecStruct espec;
uint8 convert_buffer[1024*768*3];
LRESULT CALLBACK WndProc( HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK LuaScriptProc(HWND, UINT, WPARAM, LPARAM);
std::vector<HWND> LuaScriptHWnds;
BOOL Register( HINSTANCE hInst );
HWND Create( int nCmdShow, int w, int h );
// Prototypes
std::string RemovePath(std::string filename);
// Message handlers
void OnDestroy(HWND hwnd);
void OnCommand(HWND hWnd, int iID, HWND hwndCtl, UINT uNotifyCode);
void OnPaint(HWND hwnd);
// Globals
int WndX = 0; //Window position
int WndY = 0;
static char g_szAppName[] = "DDSamp";
HWND g_hWnd;
HINSTANCE g_hInstance;
bool g_bRunning;
void emulate();
void initialize();
void OpenConsole();
void LoadIniSettings();
void SaveIniSettings();
DWORD hKeyInputTimer;
int KeyInDelayMSec = 0;
int KeyInRepeatMSec = 16;
RecentMenu RecentROMs;
RecentMenu RecentMovies;
RecentMenu RecentLua;
WNDCLASSEX winClass;
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
MSG uMsg;
memset(&uMsg,0,sizeof(uMsg));
winClass.lpszClassName = "MY_WINDOWS_CLASS";
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.style = CS_HREDRAW | CS_VREDRAW;
winClass.lpfnWndProc = WndProc;
winClass.hInstance = hInstance;
winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV);
winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winClass.cbClsExtra = 0;
winClass.cbWndExtra = 0;
OpenConsole();
if( !RegisterClassEx(&winClass) )
return E_FAIL;
GetINIPath();
LoadSettings();
pcejin.aspectRatio = GetPrivateProfileInt("Video", "aspectratio", 0, IniName);
pcejin.windowSize = GetPrivateProfileInt("Video", "pcejin.windowSize", 1, IniName);
WndX = GetPrivateProfileInt("Main", "WndX", 0, IniName);
WndY = GetPrivateProfileInt("Main", "WndY", 0, IniName);
g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS",
pcejin.versionName.c_str(),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
WndX, WndY, 256, 232, NULL, NULL, hInstance, NULL );
if( g_hWnd == NULL )
return E_FAIL;
ScaleScreen(pcejin.windowSize);
soundInit();
LoadIniSettings();
InitSpeedThrottle();
RecentROMs.SetGUI_hWnd(g_hWnd);
RecentROMs.SetID(RECENTROM_START);
RecentROMs.SetMenuID(ID_FILE_RECENTROM);
RecentROMs.SetType("ROM");
RecentROMs.MakeRecentMenu(hInstance);
RecentROMs.GetRecentItemsFromIni(IniName, "General");
RecentMovies.SetGUI_hWnd(g_hWnd);
RecentMovies.SetID(RECENTMOVIE_START);
RecentMovies.SetMenuID(ID_MOVIE_RECENT);
RecentMovies.SetType("Movie");
RecentMovies.MakeRecentMenu(hInstance);
RecentMovies.GetRecentItemsFromIni(IniName, "General");
RecentLua.SetGUI_hWnd(g_hWnd);
RecentLua.SetID(RECENTLUA_START);
RecentLua.SetMenuID(ID_LUA_RECENT);
RecentLua.SetType("Lua");
RecentLua.MakeRecentMenu(hInstance);
RecentLua.GetRecentItemsFromIni(IniName, "General");
DirectDrawInit();
InitCustomControls();
InitCustomKeys(&CustomKeys);
LoadHotkeyConfig();
LoadInputConfig();
DragAcceptFiles(g_hWnd, true);
extern void Agg_init();
Agg_init();
if (osd) {delete osd; osd =NULL; }
osd = new OSDCLASS(-1);
di_init();
DWORD wmTimerRes;
TIMECAPS tc;
if (timeGetDevCaps(&tc, sizeof(TIMECAPS))== TIMERR_NOERROR)
{
wmTimerRes = std::min(std::max(tc.wPeriodMin, (UINT)1), tc.wPeriodMax);
timeBeginPeriod (wmTimerRes);
}
else
{
wmTimerRes = 5;
timeBeginPeriod (wmTimerRes);
}
if (KeyInDelayMSec == 0) {
DWORD dwKeyboardDelay;
SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &dwKeyboardDelay, 0);
KeyInDelayMSec = 250 * (dwKeyboardDelay + 1);
}
if (KeyInRepeatMSec == 0) {
DWORD dwKeyboardSpeed;
SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &dwKeyboardSpeed, 0);
KeyInRepeatMSec = (int)(1000.0/(((30.0-2.5)/31.0)*dwKeyboardSpeed+2.5));
}
if (KeyInRepeatMSec < (int)wmTimerRes)
KeyInRepeatMSec = (int)wmTimerRes;
if (KeyInDelayMSec < KeyInRepeatMSec)
KeyInDelayMSec = KeyInRepeatMSec;
hKeyInputTimer = timeSetEvent (KeyInRepeatMSec, 0, KeyInputTimer, 0, TIME_PERIODIC);
ShowWindow( g_hWnd, nCmdShow );
UpdateWindow( g_hWnd );
initialize();
if (lpCmdLine[0])ParseCmdLine(lpCmdLine, g_hWnd);
if (RecentROMs.GetAutoLoad() && (!skipAutoLoadROM))
{
ALoad(RecentROMs.GetRecentItem(0).c_str());
}
//Intentionally does not prompt for a game if no game specified, user should be forced to autoload roms as well, for this to work properly
if (RecentMovies.GetAutoLoad() && (!skipAutoLoadMovie))
{
LoadMovie(RecentMovies.GetRecentItem(0).c_str(), 1, false, false);
}
if (RecentLua.GetAutoLoad() && (!skipAutoLoadLua))
{
char temp [1024];
strcpy(temp, RecentLua.GetRecentItem(0).c_str());
HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), g_hWnd, (DLGPROC) LuaScriptProc);
SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp);
}
while( uMsg.message != WM_QUIT )
{
if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &uMsg );
DispatchMessage( &uMsg );
}
else {
emulate();
render();
}
if(!pcejin.started)
Sleep(1);
}
// shutDown();
timeEndPeriod (wmTimerRes);
CloseAllToolWindows();
UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance );
return uMsg.wParam;
}
#include <fcntl.h>
#include <io.h>
HANDLE hConsole;
void OpenConsole()
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
if (hConsole) return;
AllocConsole();
//redirect stdio
long lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
int hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
FILE *fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
}
HWND Create( int nCmdShow, int w, int h )
{
RECT rc;
// Calculate size of window based on desired client window size
rc.left = 0;
rc.top = 0;
rc.right = w;
rc.bottom = h;
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
HWND hwnd = CreateWindow(g_szAppName, g_szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
rc.right-rc.left, rc.bottom-rc.top,
NULL, NULL, g_hInstance, NULL);
if (hwnd == NULL)
return hwnd;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
OpenConsole();
return hwnd;
}
void LoadGame(){
char szChoice[MAX_PATH]={0};
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = g_hWnd;
ofn.lpstrFilter = "PC Engine Files (*.pce, *.cue, *.toc, *.sgx *.zip)\0*.pce;*.cue;*.toc;*.sgx;*.zip\0All files(*.*)\0*.*\0\0";
ofn.lpstrFile = (LPSTR)szChoice;
ofn.lpstrTitle = "Select a file to open";
ofn.lpstrDefExt = "pce";
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetOpenFileName(&ofn)) {
pcejin.romLoaded = true;
pcejin.started = true;
if(strlen(szChoice) > 4 && (!strcasecmp(szChoice + strlen(szChoice) - 4, ".cue") || !strcasecmp(szChoice + strlen(szChoice) - 4, ".toc"))) {
char ret[MAX_PATH];
GetPrivateProfileString("Main", "Bios", "pce.cdbios PATH NOT SET", ret, MAX_PATH, IniName);
if(std::string(ret) == "pce.cdbios PATH NOT SET") {
pcejin.started = false;
pcejin.romLoaded = false;
MDFN_DispMessage("specify your PCE CD bios");
return;
}
}
if(!MDFNI_LoadGame(szChoice)) {
pcejin.started = false;
pcejin.romLoaded = false;
}
if (AutoRWLoad)
{
//Open Ram Watch if its auto-load setting is checked
OpenRWRecentFile(0);
RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), g_hWnd, (DLGPROC) RamWatchProc);
}
StopMovie();
ResetFrameCount();
RecentROMs.UpdateRecentItems(szChoice);
std::string romname = noExtension(RemovePath(szChoice));
std::string temp = pcejin.versionName;
GameName = romname;
temp.append(" ");
temp.append(romname);
SetWindowText(g_hWnd, temp.c_str());
}
}
void LoadGameShort(char filename[256]) {
pcejin.romLoaded = true;
pcejin.started = true;
if(!MDFNI_LoadGame(filename)) {
pcejin.started = false;
pcejin.romLoaded = false;
}
if (AutoRWLoad)
{
//Open Ram Watch if its auto-load setting is checked
OpenRWRecentFile(0);
RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), g_hWnd, (DLGPROC) RamWatchProc);
}
StopMovie();
RecentROMs.UpdateRecentItems(filename);
std::string romname = noExtension(RemovePath(filename));
GameName = romname;
std::string temp = pcejin.versionName;
temp.append(" ");
temp.append(romname);
SetWindowText(g_hWnd, temp.c_str());
}
void RecordAvi()
{
char szChoice[MAX_PATH]={0};
std::string fname;
int x;
std::wstring la = L"";
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = g_hWnd;
ofn.lpstrFilter = "Avi file (*.avi)\0*.avi\0All files(*.*)\0*.*\0\0";
ofn.lpstrFile = (LPSTR)szChoice;
ofn.lpstrTitle = "Avi Thingy";
ofn.lpstrDefExt = "avi";
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetSaveFileName(&ofn))
DRV_AviBegin(szChoice);
}
void StopAvi()
{
DRV_AviEnd();
}
void UpdateToolWindows()
{
Update_RAM_Search(); //Update_RAM_Watch() is also called; hotkey.cpp - HK_StateLoadSlot & State_Load also call these functions
RefreshAllToolWindows();
}
DWORD checkMenu(UINT idd, bool check)
{
return CheckMenuItem(GetMenu(g_hWnd), idd, MF_BYCOMMAND | (check?MF_CHECKED:MF_UNCHECKED));
}
void LoadIniSettings(){
Hud.FrameCounterDisplay = GetPrivateProfileBool("Display","FrameCounter", false, IniName);
Hud.ShowInputDisplay = GetPrivateProfileBool("Display","Display Input", false, IniName);
Hud.ShowLagFrameCounter = GetPrivateProfileBool("Display","Display Lag Counter", false, IniName);
Hud.DisplayStateSlots = GetPrivateProfileBool("Display","Display State Slots", false, IniName);
soundDriver->userMute = (GetPrivateProfileBool("Main", "Muted", false, IniName));
if(soundDriver->userMute)
soundDriver->mute();
//RamWatch Settings
AutoRWLoad = GetPrivateProfileBool("RamWatch", "AutoRWLoad", 0, IniName);
RWSaveWindowPos = GetPrivateProfileBool("RamWatch", "SaveWindowPos", 0, IniName);
ramw_x = GetPrivateProfileInt("RamWatch", "WindowX", 0, IniName);
ramw_y = GetPrivateProfileInt("RamWatch", "WindowY", 0, IniName);
for(int i = 0; i < MAX_RECENT_WATCHES; i++)
{
char str[256];
sprintf(str, "Recent Watch %d", i+1);
GetPrivateProfileString("Watches", str, "", &rw_recent_files[i][0], 1024, IniName);
}
}
void SaveIniSettings(){
SaveSettings();
WritePrivateProfileInt("Video", "aspectratio", pcejin.aspectRatio, IniName);
WritePrivateProfileInt("Video", "pcejin.windowSize", pcejin.windowSize, IniName);
WritePrivateProfileInt("Main", "Muted", soundDriver->userMute, IniName);
WritePrivateProfileInt("Main", "WndX", WndX, IniName);
WritePrivateProfileInt("Main", "WndY", WndY, IniName);
//RamWatch Settings
WritePrivateProfileBool("RamWatch", "AutoRWLoad", AutoRWLoad, IniName);
WritePrivateProfileBool("RamWatch", "SaveWindowPos", RWSaveWindowPos, IniName);
WritePrivateProfileInt("RamWatch", "WindowX", ramw_x, IniName);
WritePrivateProfileInt("RamWatch", "WindowY", ramw_y, IniName);
for(int i = 0; i < MAX_RECENT_WATCHES; i++)
{
char str[256];
sprintf(str, "Recent Watch %d", i+1);
WritePrivateProfileString("Watches", str, &rw_recent_files[i][0], IniName);
}
RecentROMs.SaveRecentItemsToIni(IniName, "General");
RecentMovies.SaveRecentItemsToIni(IniName, "General");
RecentLua.SaveRecentItemsToIni(IniName, "General");
}
std::string a = "a";
void RecordMovie(HWND hWnd){
char szChoice[MAX_PATH]={0};
soundDriver->pause();
OPENFILENAME ofn;
// browse button
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = "Movie File (*.mc2)\0*.mc2\0All files(*.*)\0*.*\0\0";
ofn.lpstrFile = (LPSTR)szChoice;
ofn.lpstrTitle = "Record a new movie";
ofn.lpstrDefExt = "mc2";
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetSaveFileName(&ofn))
SaveMovie(szChoice, a, 1);
//If user did not specify an extension, add .dsm for them
// fname = szChoice;
// x = fname.find_last_of(".");
// if (x < 0)
// fname.append(".mc2");
// SetDlgItemText(hwndDlg, IDC_EDIT_FILENAME, fname.c_str());
//if(GetSaveFileName(&ofn))
// UpdateRecordDialogPath(hwndDlg,szChoice);
pcejin.tempUnPause();
}
void PlayMovie(HWND hWnd){
char szChoice[MAX_PATH]={0};
OPENFILENAME ofn;
soundDriver->pause();
// browse button
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = "Movie File (*.mc2, *.mcm)\0*.mc2;*.mcm\0All files(*.*)\0*.*\0\0";
ofn.lpstrFile = (LPSTR)szChoice;
ofn.lpstrTitle = "Play a movie";
ofn.lpstrDefExt = "mc2";
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetOpenFileName(&ofn)) {
if(toupper(strright(szChoice,4)) == ".MC2")
LoadMovie(szChoice, 1, 0, 0);
else if(toupper(strright(szChoice,4)) == ".MCM")
LoadMCM(szChoice, true);
}
pcejin.tempUnPause();
}
void ConvertMCM(HWND hWnd){
char szChoice[MAX_PATH]={0};
OPENFILENAME ofn;
soundDriver->pause();
// browse button
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = "Mednafen Movie File (*.mcm)\0*.mcm\0All files(*.*)\0*.*\0\0";
ofn.lpstrFile = (LPSTR)szChoice;
ofn.lpstrTitle = "Select a movie to convert";
ofn.lpstrDefExt = "mcm";
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetOpenFileName(&ofn)) {
LoadMCM(szChoice, false);
if(pcejin.romLoaded) {
osd->addLine("Check that directory");
osd->addLine("for an .mc2 file");
}
else
MessageBox(hWnd, "Check that directory for an .mc2 file", "Conversion", NULL);
}
pcejin.tempUnPause();
}
void ALoad(const char* filename)
{
pcejin.romLoaded = true;
pcejin.started = true;
if(!MDFNI_LoadGame(filename))
{
pcejin.started = false;
pcejin.romLoaded = false;
GameName = "";
SetWindowText(g_hWnd, pcejin.versionName.c_str());
}
if (AutoRWLoad)
{
//Open Ram Watch if its auto-load setting is checked
OpenRWRecentFile(0);
RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), g_hWnd, (DLGPROC) RamWatchProc);
}
RecentROMs.UpdateRecentItems(filename);
std::string romname = noExtension(RemovePath(filename));
GameName = romname;
std::string temp = pcejin.versionName;
temp.append(" ");
temp.append(romname);
SetWindowText(g_hWnd, temp.c_str());
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
HWND hDlg;
switch(Message)
{
case WM_KEYDOWN:
if(wParam != VK_PAUSE)
break;
// case WM_SYSKEYDOWN:
case WM_CUSTKEYDOWN:
{
int modifiers = GetModifiers(wParam);
if(!HandleKeyMessage(wParam,lParam, modifiers))
return 0;
break;
}
case WM_KEYUP:
if(wParam != VK_PAUSE)
break;
case WM_SYSKEYUP:
case WM_CUSTKEYUP:
{
int modifiers = GetModifiers(wParam);
HandleKeyUp(wParam, lParam, modifiers);
}
break;
case WM_SIZE:
switch(wParam)
{
case SIZE_MINIMIZED:
break;
case SIZE_MAXIMIZED:
pcejin.maximized = true;
break;
case SIZE_RESTORED:
pcejin.maximized = false;
break;
default:
break;
}
return 0;
case WM_MOVE:
RECT rect;
GetWindowRect(hWnd,&rect);
WndX = rect.left;
WndY = rect.top;
return 0;
case WM_DROPFILES:
{
char filename[MAX_PATH] = "";
DragQueryFile((HDROP)wParam,0,filename,MAX_PATH);
DragFinish((HDROP)wParam);
std::string fileDropped = filename;
//-------------------------------------------------------
//Check if mcm file, if so auto-convert and play
//-------------------------------------------------------
if (!(fileDropped.find(".mcm") == std::string::npos) && (fileDropped.find(".mcm") == fileDropped.length()-4))
{
if (!pcejin.romLoaded) //If no ROM is loaded, prompt for one
{
soundDriver->pause();
LoadGame();
pcejin.tempUnPause();
}
if (pcejin.romLoaded && !(fileDropped.find(".mcm") == std::string::npos))
LoadMCM(fileDropped.c_str(), true);
}
//-------------------------------------------------------
//Check if Movie file
//-------------------------------------------------------
else if (!(fileDropped.find(".mc2") == std::string::npos) && (fileDropped.find(".mc2") == fileDropped.length()-4))
{
if (!pcejin.romLoaded) //If no ROM is loaded, prompt for one
{
soundDriver->pause();
LoadGame();
pcejin.tempUnPause();
}
if (pcejin.romLoaded && !(fileDropped.find(".mc2") == std::string::npos))
{
LoadMovie(fileDropped.c_str(), 1, false, false);
RecentMovies.UpdateRecentItems(fileDropped);
}
}
//-------------------------------------------------------
//Check if Savestate file
//-------------------------------------------------------
else if (!(fileDropped.find(".nc") == std::string::npos))
{
if (fileDropped.find(".nc") == fileDropped.length()-4)
{
if ((fileDropped[fileDropped.length()-1] >= '0' && fileDropped[fileDropped.length()-1] <= '9'))
{
MDFNSS_Load(filename, NULL);
UpdateToolWindows();
}
}
}
//-------------------------------------------------------
//Check if Lua script file
//-------------------------------------------------------
else if (!(fileDropped.find(".lua") == std::string::npos) && (fileDropped.find(".lua") == fileDropped.length()-4)) //ROM is already loaded and .dsm in filename
{
if(LuaScriptHWnds.size() < 16)
{
char temp [1024];
strcpy(temp, fileDropped.c_str());
HWND IsScriptFileOpen(const char* Path);
RecentLua.UpdateRecentItems(fileDropped);
if(!IsScriptFileOpen(temp))
{
HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), hWnd, (DLGPROC) LuaScriptProc);
SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp);
}
}
}
//-------------------------------------------------------
//Check if watchlist file
//-------------------------------------------------------
else if (!(fileDropped.find(".wch") == std::string::npos) && (fileDropped.find(".wch") == fileDropped.length()-4)) //ROM is already loaded and .dsm in filename
{
if(!RamWatchHWnd)
{
RamWatchHWnd = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc);
}
else
SetForegroundWindow(RamWatchHWnd);
Load_Watches(true, fileDropped.c_str());
}
//-------------------------------------------------------
//Else load it as a ROM
//-------------------------------------------------------
else
{
ALoad(fileDropped.c_str());
}
}
return 0;
case WM_ENTERMENULOOP:
soundDriver->pause();
EnableMenuItem(GetMenu(hWnd), IDM_RECORD_MOVIE, MF_BYCOMMAND | (movieMode == MOVIEMODE_INACTIVE && pcejin.romLoaded) ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(GetMenu(hWnd), IDM_PLAY_MOVIE, MF_BYCOMMAND | (movieMode == MOVIEMODE_INACTIVE && pcejin.romLoaded) ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(GetMenu(hWnd), IDM_STOPMOVIE, MF_BYCOMMAND | (movieMode != MOVIEMODE_INACTIVE) ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(GetMenu(hWnd), IDM_RESTARTMOVIE, MF_BYCOMMAND | (movieMode != MOVIEMODE_INACTIVE) ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(GetMenu(hWnd), IDM_FILE_STOPAVI, MF_BYCOMMAND | (DRV_AviIsRecording()) ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(GetMenu(hWnd), IDM_FILE_RECORDAVI, MF_BYCOMMAND | (!DRV_AviIsRecording()) ? MF_ENABLED : MF_GRAYED);
//Window Size
checkMenu(IDC_WINDOW1X, ((pcejin.windowSize==1)));
checkMenu(IDC_WINDOW2X, ((pcejin.windowSize==2)));
checkMenu(IDC_WINDOW3X, ((pcejin.windowSize==3)));
checkMenu(IDC_WINDOW4X, ((pcejin.windowSize==4)));
checkMenu(IDC_ASPECT, ((pcejin.aspectRatio)));
checkMenu(ID_VIEW_FRAMECOUNTER,Hud.FrameCounterDisplay);
checkMenu(ID_VIEW_DISPLAYINPUT,Hud.ShowInputDisplay);
checkMenu(ID_VIEW_DISPLAYSTATESLOTS,Hud.DisplayStateSlots);
checkMenu(ID_VIEW_DISPLAYLAG,Hud.ShowLagFrameCounter);
checkMenu(IDM_MUTE,soundDriver->userMute);
break;
case WM_EXITMENULOOP:
pcejin.tempUnPause();
break;
case WM_CLOSE:
{
SaveIniSettings();
PostQuitMessage(0);
}
case WM_DESTROY:
{
PostQuitMessage(0);
}
// HANDLE_MSG(hWnd, WM_DESTROY, OnDestroy);
// HANDLE_MSG(hWnd, WM_PAINT, OnPaint);
// HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
case WM_COMMAND:
//Recent ROMs
if(wParam >= RECENTROM_START && wParam <= RECENTROM_START + RecentROMs.MAX_RECENT_ITEMS - 1)
{
ALoad(RecentROMs.GetRecentItem(wParam - RECENTROM_START).c_str());
break;
}
else if (wParam == RecentROMs.GetClearID())
{
RecentROMs.ClearRecentItems();
break;
}
else if (wParam == RecentROMs.GetAutoloadID())
{
RecentROMs.FlipAutoLoad();
break;
}
//Recent Movies
if(wParam >= RECENTMOVIE_START && wParam <= RECENTMOVIE_START + RecentMovies.MAX_RECENT_ITEMS - 1)
{
strcpy(Tmp_Str, RecentMovies.GetRecentItem(wParam - RECENTMOVIE_START).c_str());
RecentMovies.UpdateRecentItems(Tmp_Str);
//WIN32_StartMovieReplay(Str_Tmp);
break;
}
else if (wParam == RecentMovies.GetClearID())
{
RecentMovies.ClearRecentItems();
break;
}
else if (wParam == RecentMovies.GetAutoloadID())
{
RecentMovies.FlipAutoLoad();
break;
}
//Recent Lua
if(wParam >= RECENTLUA_START && wParam <= RECENTLUA_START + RecentLua.MAX_RECENT_ITEMS - 1)
{
if(LuaScriptHWnds.size() < 16)
{
char temp [1024];
strcpy(temp, RecentLua.GetRecentItem(wParam - RECENTLUA_START).c_str());
HWND IsScriptFileOpen(const char* Path);
RecentLua.UpdateRecentItems(temp);
if(!IsScriptFileOpen(temp))
{
HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), hWnd, (DLGPROC) LuaScriptProc);
SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp);
}
}
break;
}
else if (wParam == RecentLua.GetClearID())
{
RecentLua.ClearRecentItems();
break;
}
else if (wParam == RecentLua.GetAutoloadID())
{
RecentLua.FlipAutoLoad();
break;
}
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDC_WINDOW1X:
pcejin.windowSize=1;
ScaleScreen(pcejin.windowSize);
break;
case IDC_WINDOW2X:
pcejin.windowSize=2;
ScaleScreen(pcejin.windowSize);
break;
case IDC_WINDOW3X:
pcejin.windowSize=3;
ScaleScreen(pcejin.windowSize);
break;
case IDC_WINDOW4X:
pcejin.windowSize=4;
ScaleScreen(pcejin.windowSize);
break;
case IDC_ASPECT:
pcejin.aspectRatio ^= 1;
ScaleScreen(pcejin.windowSize);
break;
case IDM_EXIT:
SaveIniSettings();
PostQuitMessage(0);
break;
case IDM_RESET:
PCE_Power();
break;
case IDM_OPEN_ROM:
soundDriver->pause();
LoadGame();
pcejin.tempUnPause();
break;
case IDM_RECORD_MOVIE:
soundDriver->pause();
MovieRecordTo();
pcejin.tempUnPause();
return 0;
case IDM_PLAY_MOVIE:
soundDriver->pause();
Replay_LoadMovie();
pcejin.tempUnPause();
return 0;
case IDM_INPUT_CONFIG:
soundDriver->pause();
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_INPUTCONFIG), hWnd, DlgInputConfig);
pcejin.tempUnPause();
// RunInputConfig();
break;
case IDM_HOTKEY_CONFIG:
{
soundDriver->pause();
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_KEYCUSTOM), hWnd, DlgHotkeyConfig);
pcejin.tempUnPause();
}
break;
case IDM_BIOS_CONFIG:
soundDriver->pause();
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_BIOS), hWnd, (DLGPROC) BiosSettingsDlgProc);
// DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_KEYCUSTOM), hWnd, BiosSettingsDlgProc);
pcejin.tempUnPause();
break;
case ID_VIEW_FRAMECOUNTER:
Hud.FrameCounterDisplay ^= true;
WritePrivateProfileBool("Display", "FrameCounter", Hud.FrameCounterDisplay, IniName);
return 0;
case ID_VIEW_DISPLAYINPUT:
Hud.ShowInputDisplay ^= true;
WritePrivateProfileBool("Display", "Display Input", Hud.ShowInputDisplay, IniName);
osd->clear();
return 0;
case ID_VIEW_DISPLAYSTATESLOTS:
Hud.DisplayStateSlots ^= true;
WritePrivateProfileBool("Display", "Display State Slots", Hud.DisplayStateSlots, IniName);
osd->clear();
return 0;
case ID_VIEW_DISPLAYLAG:
Hud.ShowLagFrameCounter ^= true;
WritePrivateProfileBool("Display", "Display Lag Counter", Hud.ShowLagFrameCounter, IniName);
osd->clear();
return 0;
case IDC_NEW_LUA_SCRIPT:
if(LuaScriptHWnds.size() < 16)
{
CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), g_hWnd, (DLGPROC) LuaScriptProc);
}
break;
case IDM_CONVERT_MCM:
ConvertMCM(hWnd);
break;
case IDM_MUTE:
soundDriver->doUserMute();
break;
case IDM_STOPMOVIE:
StopMovie();
return 0;
break;
case IDM_RESTARTMOVIE:
PCE_Power();
ResetFrameCount();
movieMode = MOVIEMODE_PLAY;
movie_readonly = true;
return 0;
break;
case ID_RAM_SEARCH:
if(!RamSearchHWnd)
{
InitRamSearch();
RamSearchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMSEARCH), hWnd, (DLGPROC) RamSearchProc);
}
else
SetForegroundWindow(RamSearchHWnd);
break;
case ID_RAM_WATCH:
if(!RamWatchHWnd)
{
RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc);
}
else
SetForegroundWindow(RamWatchHWnd);
return 0;
case IDM_MEMORY:
if (!RegWndClass("MemView_ViewBox", MemView_ViewBoxProc, 0, sizeof(CMemView*)))
return 0;
OpenToolWindow(new CMemView());
return 0;
case IDM_ABOUT:
soundDriver->pause();
DialogBox(winClass.hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
pcejin.tempUnPause();
break;
case IDM_FILE_RECORDAVI:
soundDriver->pause();
RecordAvi();
pcejin.tempUnPause();
break;
case IDM_FILE_STOPAVI:
StopAvi();
break;
}
break;
}
return DefWindowProc(hWnd, Message, wParam, lParam);
}