-
Notifications
You must be signed in to change notification settings - Fork 10
/
Main.cpp
1972 lines (1743 loc) · 71.5 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
/*
* Project 64 - A Nintendo 64 emulator.
*
* (c) Copyright 2001 zilmar ([email protected]) and
* Jabo ([email protected]).
*
* pj64 homepage: www.pj64.net
*
* Permission to use, copy, modify and distribute Project64 in both binary and
* source form, for non-commercial purposes, is hereby granted without fee,
* providing that this license information and copyright notice appear with
* all copies and any derived work.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event shall the authors be held liable for any damages
* arising from the use of this software.
*
* Project64 is freeware for PERSONAL USE only. Commercial users should
* seek permission of the copyright holders first. Commercial use includes
* charging money for Project64 or software derived from Project64.
*
* The copyright holders request that bug fixes and improvements to the code
* should be forwarded to them so if they want them.
*
*/
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <shlobj.h>
#include <stdio.h>
#include <shellapi.h>
#include "main.h"
#include "cheats.h"
#include "cpu.h"
#include "plugin.h"
#include "debugger.h"
#include "Settings.h"
#include "htmlHelp.h"
#include "resource.h"
LARGE_INTEGER Frequency, Frames[NoOfFrames], LastFrame;
BOOL HaveDebugger, AutoLoadMapFile, ShowUnhandledMemory, ShowTLBMisses,
ShowDListAListCount, ShowCompMem, Profiling, IndvidualBlock, AutoStart,
AutoSleep, DisableRegCaching, UseIni, UseTlb, UseLinking, RomBrowser,
IgnoreMove, Rercursion, ShowPifRamErrors, LimitFPS, ShowCPUPer, AutoZip,
AutoFullScreen, SystemABL, AlwaysOnTop, BasicMode, DelaySI, RememberCheats, AudioSignal;
DWORD CurrentFrame, CPU_Type, SystemCPU_Type, SelfModCheck, SystemSelfModCheck,
RomsToRemember, RomDirsToRemember;
HWND hMainWindow, hHiddenWin, hStatusWnd;
char CurrentSave[256];
HMENU hMainMenu;
HINSTANCE hInst;
void MenuSetText ( HMENU hMenu, int MenuPos, char * Title, char * ShotCut );
void RomInfo ( void );
void SetupMenu ( HWND hWnd );
LRESULT CALLBACK AboutIniBoxProc ( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK Main_Proc ( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK RomInfoProc ( HWND, UINT, WPARAM, LPARAM );
void AboutIniBox (void) {
DialogBox(hInst, MAKEINTRESOURCE(IDD_About_Ini), hMainWindow, (DLGPROC)AboutIniBoxProc);
}
LRESULT CALLBACK AboutIniBoxProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static char RDBHomePage[300], CHTHomePage[300], RDXHomePage[300];
switch (uMsg) {
case WM_INITDIALOG:
{
char * IniFile, String[200],String2[200];
SetWindowText(hDlg, GS(INI_TITLE));
//Language
SetDlgItemText(hDlg,IDC_LAN,GS(INI_CURRENT_LANG));
sprintf(String,"%s: %s",GS(INI_AUTHOR),GS(LANGUAGE_AUTHOR));
SetDlgItemText(hDlg,IDC_LAN_AUTHOR,String);
sprintf(String,"%s: %s",GS(INI_VERSION),GS(LANGUAGE_VERSION));
SetDlgItemText(hDlg,IDC_LAN_VERSION,String);
sprintf(String,"%s: %s",GS(INI_DATE),GS(LANGUAGE_DATE));
SetDlgItemText(hDlg,IDC_LAN_DATE,String);
if (strlen(GS(LANGUAGE_NAME)) == 0) {
EnableWindow(GetDlgItem(hDlg,IDC_LAN),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_LAN_AUTHOR),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_LAN_VERSION),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_LAN_DATE),FALSE);
}
//RDB
IniFile = GetIniFileName();
SetDlgItemText(hDlg,IDC_RDB,GS(INI_CURRENT_RDB));
_GetPrivateProfileString("Meta","Author","",String,sizeof(String),IniFile);
if (strlen(String) == 0) {
EnableWindow(GetDlgItem(hDlg,IDC_RDB),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDB_AUTHOR),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDB_VERSION),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDB_DATE),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDB_HOME),FALSE);
}
sprintf(String2,"%s: %s",GS(INI_AUTHOR),String);
SetDlgItemText(hDlg,IDC_RDB_AUTHOR,String2);
_GetPrivateProfileString("Meta","Version","",String,sizeof(String),IniFile);
sprintf(String2,"%s: %s",GS(INI_VERSION),String);
SetDlgItemText(hDlg,IDC_RDB_VERSION,String2);
_GetPrivateProfileString("Meta","Date","",String,sizeof(String),IniFile);
sprintf(String2,"%s: %s",GS(INI_DATE),String);
SetDlgItemText(hDlg,IDC_RDB_DATE,String2);
_GetPrivateProfileString("Meta","Homepage","",RDBHomePage,sizeof(RDBHomePage),IniFile);
SetDlgItemText(hDlg,IDC_RDB_HOME,GS(INI_HOMEPAGE));
if (strlen(RDBHomePage) == 0) {
EnableWindow(GetDlgItem(hDlg,IDC_RDB_HOME),FALSE);
}
//Cheat
SetDlgItemText(hDlg,IDC_CHT,GS(INI_CURRENT_CHT));
IniFile = GetCheatIniFileName();
_GetPrivateProfileString("Meta","Author","",String,sizeof(String),IniFile);
if (strlen(String) == 0) {
EnableWindow(GetDlgItem(hDlg,IDC_CHT),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_CHT_AUTHOR),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_CHT_VERSION),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_CHT_DATE),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_CHT_HOME),FALSE);
}
sprintf(String2,"%s: %s",GS(INI_AUTHOR),String);
SetDlgItemText(hDlg,IDC_CHT_AUTHOR,String2);
_GetPrivateProfileString("Meta","Version","",String,sizeof(String),IniFile);
sprintf(String2,"%s: %s",GS(INI_VERSION),String);
SetDlgItemText(hDlg,IDC_CHT_VERSION,String2);
_GetPrivateProfileString("Meta","Date","",String,sizeof(String),IniFile);
sprintf(String2,"%s: %s",GS(INI_DATE),String);
SetDlgItemText(hDlg,IDC_CHT_DATE,String2);
_GetPrivateProfileString("Meta","Homepage","",CHTHomePage,sizeof(CHTHomePage),IniFile);
SetDlgItemText(hDlg,IDC_CHT_HOME,GS(INI_HOMEPAGE));
if (strlen(CHTHomePage) == 0) {
EnableWindow(GetDlgItem(hDlg,IDC_CHT_HOME),FALSE);
}
//Extended Info
SetDlgItemText(hDlg,IDC_RDX,GS(INI_CURRENT_RDX));
IniFile = GetExtIniFileName();
_GetPrivateProfileString("Meta","Author","",String,sizeof(String),IniFile);
if (strlen(String) == 0) {
EnableWindow(GetDlgItem(hDlg,IDC_RDX),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDX_AUTHOR),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDX_VERSION),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDX_DATE),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_RDX_HOME),FALSE);
}
sprintf(String2,"%s: %s",GS(INI_AUTHOR),String);
SetDlgItemText(hDlg,IDC_RDX_AUTHOR,String2);
_GetPrivateProfileString("Meta","Version","",String,sizeof(String),IniFile);
sprintf(String2,"%s: %s",GS(INI_VERSION),String);
SetDlgItemText(hDlg,IDC_RDX_VERSION,String2);
_GetPrivateProfileString("Meta","Date","",String,sizeof(String),IniFile);
sprintf(String2,"%s: %s",GS(INI_DATE),String);
SetDlgItemText(hDlg,IDC_RDX_DATE,String2);
_GetPrivateProfileString("Meta","Homepage","",RDXHomePage,sizeof(CHTHomePage),IniFile);
SetDlgItemText(hDlg,IDC_RDX_HOME,GS(INI_HOMEPAGE));
if (strlen(RDXHomePage) == 0) {
EnableWindow(GetDlgItem(hDlg,IDC_RDX_HOME),FALSE);
}
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_RDB_HOME: ShellExecute(NULL,"open",RDBHomePage,NULL,NULL,SW_SHOWNORMAL); break;
case IDC_CHT_HOME: ShellExecute(NULL,"open",CHTHomePage,NULL,NULL,SW_SHOWNORMAL); break;
case IDC_RDX_HOME: ShellExecute(NULL,"open",RDXHomePage,NULL,NULL,SW_SHOWNORMAL); break;
case IDOK:
case IDCANCEL:
EndDialog(hDlg,0);
break;
}
default:
return FALSE;
}
return TRUE;
}
void AlwaysOnTopWindow(HWND hWnd) {
SetWindowPos(hWnd,(AlwaysOnTop?HWND_TOPMOST:HWND_NOTOPMOST),0,0,0,0,SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE);
}
DWORD AsciiToHex (char * HexValue) {
DWORD Count, Finish, Value = 0;
Finish = strlen(HexValue);
if (Finish > 8 ) { Finish = 8; }
for (Count = 0; Count < Finish; Count++){
Value = (Value << 4);
switch( HexValue[Count] ) {
case '0': break;
case '1': Value += 1; break;
case '2': Value += 2; break;
case '3': Value += 3; break;
case '4': Value += 4; break;
case '5': Value += 5; break;
case '6': Value += 6; break;
case '7': Value += 7; break;
case '8': Value += 8; break;
case '9': Value += 9; break;
case 'A': Value += 10; break;
case 'a': Value += 10; break;
case 'B': Value += 11; break;
case 'b': Value += 11; break;
case 'C': Value += 12; break;
case 'c': Value += 12; break;
case 'D': Value += 13; break;
case 'd': Value += 13; break;
case 'E': Value += 14; break;
case 'e': Value += 14; break;
case 'F': Value += 15; break;
case 'f': Value += 15; break;
default:
Value = (Value >> 4);
Count = Finish;
}
}
return Value;
}
void ChangeWinSize ( HWND hWnd, long width, long height, HWND hStatusBar ) {
WINDOWPLACEMENT wndpl;
RECT rc1, swrect;
wndpl.length = sizeof(wndpl);
GetWindowPlacement( hWnd, &wndpl);
if ( hStatusBar != NULL ) {
GetClientRect( hStatusBar, &swrect );
SetRect( &rc1, 0, 0, width, height + swrect.bottom );
} else {
SetRect( &rc1, 0, 0, width, height );
}
AdjustWindowRectEx( &rc1,GetWindowLong( hWnd, GWL_STYLE ),
GetMenu( hWnd ) != NULL, GetWindowLong( hWnd, GWL_EXSTYLE ) );
MoveWindow( hWnd, wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.top,
rc1.right - rc1.left, rc1.bottom - rc1.top, TRUE );
}
void __cdecl DisplayError (char * Message, ...) {
char Msg[1000];
va_list ap;
if (inFullScreen) { return; }
va_start( ap, Message );
vsprintf( Msg, Message, ap );
va_end( ap );
MessageBox(NULL,Msg,GS(MSG_MSGBOX_TITLE),MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
SetActiveWindow(hMainWindow);
}
void DisplayFPS (void) {
if (CurrentFrame > (NoOfFrames << 3)) {
LARGE_INTEGER Total;
char Message[100];
int count;
Total.QuadPart = 0;
for (count = 0; count < NoOfFrames; count ++) {
Total.QuadPart += Frames[count].QuadPart;
}
sprintf(Message, "FPS: %.2f", Frequency.QuadPart/ ((double)Total.QuadPart / (NoOfFrames << 3)));
SendMessage( hStatusWnd, SB_SETTEXT, 1, (LPARAM)Message );
} else {
SendMessage( hStatusWnd, SB_SETTEXT, 1, (LPARAM)"FPS: -.--" );
}
}
void FixMenuLang (HMENU hMenu) {
HMENU hSubMenu;
MenuSetText(hMenu, 0, GS(MENU_FILE), NULL);
MenuSetText(hMenu, 1, GS(MENU_SYSTEM), NULL);
MenuSetText(hMenu, 2, GS(MENU_OPTIONS), NULL);
MenuSetText(hMenu, 3, GS(MENU_DEBUGGER), NULL);
MenuSetText(hMenu, 4, GS(MENU_HELP), NULL);
//File
hSubMenu = GetSubMenu(hMenu,0);
MenuSetText(hSubMenu, 0, GS(MENU_OPEN), "Ctrl+O");
MenuSetText(hSubMenu, 1, GS(MENU_ROM_INFO), NULL);
MenuSetText(hSubMenu, 3, GS(MENU_START), "F11");
MenuSetText(hSubMenu, 4, GS(MENU_END), "F12");
MenuSetText(hSubMenu, 6, GS(MENU_LANGUAGE), NULL);
MenuSetText(hSubMenu, 8, GS(MENU_CHOOSE_ROM), NULL);
MenuSetText(hSubMenu, 9, GS(MENU_REFRESH), "F5");
MenuSetText(hSubMenu, 11, GS(MENU_RECENT_ROM), NULL);
MenuSetText(hSubMenu, 12, GS(MENU_RECENT_DIR), NULL);
MenuSetText(hSubMenu, 14, GS(MENU_EXIT), "Alt+F4");
//System
hSubMenu = GetSubMenu(hMenu,1);
MenuSetText(hSubMenu, 0, GS(MENU_RESET),"F1");
MenuSetText(hSubMenu, 1, GS(CPU_Paused?MENU_RESUME:MENU_PAUSE),"F2");
MenuSetText(hSubMenu, 2, GS(MENU_BITMAP),"F3");
MenuSetText(hSubMenu, 4, GS(MENU_LIMIT_FPS),"F4");
MenuSetText(hSubMenu, 6, GS(MENU_SAVE),"F5");
MenuSetText(hSubMenu, 7, GS(MENU_SAVE_AS),"Ctrl+S");
MenuSetText(hSubMenu, 8, GS(MENU_RESTORE),"F7");
MenuSetText(hSubMenu, 9, GS(MENU_LOAD),"Ctrl+L");
MenuSetText(hSubMenu,11, GS(MENU_CURRENT_SAVE),NULL);
MenuSetText(hSubMenu,13, GS(MENU_CHEAT),"Ctrl+C");
MenuSetText(hSubMenu,14, GS(MENU_GS_BUTTON),"F9");
//Options
hSubMenu = GetSubMenu(hMenu,2);
MenuSetText(hSubMenu, 0, GS(MENU_FULL_SCREEN), "Alt+Enter");
MenuSetText(hSubMenu, 1, GS(MENU_ON_TOP), "Ctrl+A");
MenuSetText(hSubMenu, 3, GS(MENU_CONFG_GFX), NULL);
MenuSetText(hSubMenu, 4, GS(MENU_CONFG_AUDIO), NULL);
MenuSetText(hSubMenu, 5, GS(MENU_CONFG_CTRL), NULL);
MenuSetText(hSubMenu, 6, GS(MENU_CONFG_RSP), NULL);
MenuSetText(hSubMenu, 8, GS(MENU_SHOW_CPU), NULL);
MenuSetText(hSubMenu, 9, GS(MENU_SETTINGS), "Ctrl+T");
//Help Menu
hSubMenu = GetSubMenu(hMenu,4);
#ifdef BETA_VERSION
MenuSetText(hSubMenu, 2, GS(MENU_USER_MAN), NULL);
MenuSetText(hSubMenu, 3, GS(MENU_GAME_FAQ), NULL);
MenuSetText(hSubMenu, 5, GS(MENU_ABOUT_INI), NULL);
MenuSetText(hSubMenu, 6, GS(MENU_ABOUT_PJ64), NULL);
#else
MenuSetText(hSubMenu, 0, GS(MENU_USER_MAN), NULL);
MenuSetText(hSubMenu, 1, GS(MENU_GAME_FAQ), NULL);
MenuSetText(hSubMenu, 3, GS(MENU_FORUM), NULL);
MenuSetText(hSubMenu, 4, GS(MENU_HOMEPAGE), NULL);
MenuSetText(hSubMenu, 6, GS(MENU_ABOUT_INI), NULL);
MenuSetText(hSubMenu, 7, GS(MENU_ABOUT_PJ64), NULL);
#endif
//Save Slot
hSubMenu = GetSubMenu(hMenu,1);
hSubMenu = GetSubMenu(hSubMenu,11);
MenuSetText(hSubMenu, 0, GS(MENU_SLOT_DEFAULT), "~");
MenuSetText(hSubMenu, 2, GS(MENU_SLOT_1), "1");
MenuSetText(hSubMenu, 3, GS(MENU_SLOT_2), "2");
MenuSetText(hSubMenu, 4, GS(MENU_SLOT_3), "3");
MenuSetText(hSubMenu, 5, GS(MENU_SLOT_4), "4");
MenuSetText(hSubMenu, 6, GS(MENU_SLOT_5), "5");
MenuSetText(hSubMenu, 7, GS(MENU_SLOT_6), "6");
MenuSetText(hSubMenu, 8, GS(MENU_SLOT_7), "7");
MenuSetText(hSubMenu, 9, GS(MENU_SLOT_8), "8");
MenuSetText(hSubMenu, 10, GS(MENU_SLOT_9), "9");
MenuSetText(hSubMenu, 11, GS(MENU_SLOT_10), "0");
}
char * GetExtIniFileName(void) {
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR];
char fname[_MAX_FNAME],ext[_MAX_EXT];
static char IniFileName[_MAX_PATH];
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
_splitpath( path_buffer, drive, dir, fname, ext );
sprintf(IniFileName,"%s%s%s",drive,dir,ExtIniName);
return IniFileName;
}
char * GetIniFileName(void) {
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR];
char fname[_MAX_FNAME],ext[_MAX_EXT];
static char IniFileName[_MAX_PATH];
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
_splitpath( path_buffer, drive, dir, fname, ext );
sprintf(IniFileName,"%s%s%s",drive,dir,IniName);
return IniFileName;
}
char * GetLangFileName(void) {
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR];
char fname[_MAX_FNAME],ext[_MAX_EXT];
static char IniFileName[_MAX_PATH];
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
_splitpath( path_buffer, drive, dir, fname, ext );
sprintf(IniFileName,"%s%s%s",drive,dir,LangFileName);
return IniFileName;
}
char * GetNotesIniFileName(void) {
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR];
char fname[_MAX_FNAME],ext[_MAX_EXT];
static char IniFileName[_MAX_PATH];
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
_splitpath( path_buffer, drive, dir, fname, ext );
sprintf(IniFileName,"%s%s%s",drive,dir,NotesIniName);
return IniFileName;
}
int GetStoredWinPos( char * WinName, DWORD * X, DWORD * Y ) {
long lResult;
HKEY hKeyResults = 0;
char String[200];
sprintf(String,"Software\\N64 Emulation\\%s\\Page Setup",AppName);
lResult = RegOpenKeyEx( HKEY_CURRENT_USER,String,0, KEY_ALL_ACCESS,&hKeyResults);
if (lResult == ERROR_SUCCESS) {
DWORD Type, Value, Bytes = 4;
sprintf(String,"%s Top",WinName);
lResult = RegQueryValueEx(hKeyResults,String,0,&Type,(LPBYTE)(&Value),&Bytes);
if (Type == REG_DWORD && lResult == ERROR_SUCCESS) {
*Y = Value;
} else {
RegCloseKey(hKeyResults);
return FALSE;
}
sprintf(String,"%s Left",WinName);
lResult = RegQueryValueEx(hKeyResults,String,0,&Type,(LPBYTE)(&Value),&Bytes);
if (Type == REG_DWORD && lResult == ERROR_SUCCESS) {
*X = Value;
} else {
RegCloseKey(hKeyResults);
return FALSE;
}
RegCloseKey(hKeyResults);
return TRUE;
}
return FALSE;
}
int GetStoredWinSize( char * WinName, DWORD * Width, DWORD * Height ) {
long lResult;
HKEY hKeyResults = 0;
char String[200];
sprintf(String,"Software\\N64 Emulation\\%s\\Page Setup",AppName);
lResult = RegOpenKeyEx( HKEY_CURRENT_USER,String,0, KEY_ALL_ACCESS,&hKeyResults);
if (lResult == ERROR_SUCCESS) {
DWORD Type, Value, Bytes = 4;
sprintf(String,"%s Width",WinName);
lResult = RegQueryValueEx(hKeyResults,String,0,&Type,(LPBYTE)(&Value),&Bytes);
if (Type == REG_DWORD && lResult == ERROR_SUCCESS) {
*Width = Value;
} else {
RegCloseKey(hKeyResults);
return FALSE;
}
sprintf(String,"%s Height",WinName);
lResult = RegQueryValueEx(hKeyResults,String,0,&Type,(LPBYTE)(&Value),&Bytes);
if (Type == REG_DWORD && lResult == ERROR_SUCCESS) {
*Height = Value;
} else {
RegCloseKey(hKeyResults);
return FALSE;
}
RegCloseKey(hKeyResults);
return TRUE;
}
return FALSE;
}
void LoadSettings (void) {
HKEY hKeyResults;
char String[200];
long lResult;
IgnoreMove = FALSE;
CPU_Type = Default_CPU;
SystemCPU_Type = Default_CPU;
SystemSelfModCheck = Default_SelfModCheck;
SystemRdramSize = Default_RdramSize;
SystemABL = Default_AdvancedBlockLink;
AutoStart = Default_AutoStart;
AutoSleep = Default_AutoSleep;
DisableRegCaching = Default_DisableRegCaching;
UseIni = Default_UseIni;
AutoZip = Default_AutoZip;
AutoFullScreen = FALSE;
RomsToRemember = Default_RomsToRemember;
RomDirsToRemember = Default_RomsDirsToRemember;
AutoLoadMapFile = Default_AutoMap;
ShowUnhandledMemory = Default_ShowUnhandledMemory;
ShowCPUPer = Default_ShowCPUPer;
LimitFPS = Default_LimitFPS;
AlwaysOnTop = Default_AlwaysOnTop;
BasicMode = Default_BasicMode;
RememberCheats = Default_RememberCheats;
ShowTLBMisses = Default_ShowTLBMisses;
Profiling = Default_ProfilingOn;
IndvidualBlock = Default_IndvidualBlock;
RomBrowser = Default_UseRB;
Rercursion = Default_Rercursion;
HaveDebugger = FALSE;
sprintf(String,"Software\\N64 Emulation\\%s",AppName);
lResult = RegOpenKeyEx( HKEY_CURRENT_USER,String,0,KEY_ALL_ACCESS,
&hKeyResults);
if (lResult == ERROR_SUCCESS) {
DWORD Type, Bytes = 4;
lResult = RegQueryValueEx(hKeyResults,"Remember Cheats",0,&Type,(LPBYTE)(&RememberCheats),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { RememberCheats = Default_RememberCheats; }
lResult = RegQueryValueEx(hKeyResults,"Basic Mode",0,&Type,(LPBYTE)(&BasicMode),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { BasicMode = Default_BasicMode; }
lResult = RegQueryValueEx(hKeyResults,"Pause emulation when window is not active",0,&Type,(BYTE *)(&AutoSleep),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { AutoSleep = Default_AutoSleep; }
lResult = RegQueryValueEx(hKeyResults,"On open rom go full screen",0,&Type,(BYTE *)(&AutoFullScreen),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { AutoFullScreen = FALSE; }
if (!BasicMode) {
#if (!defined(EXTERNAL_RELEASE))
DWORD Value;
lResult = RegQueryValueEx(hKeyResults,"Debugger",0,&Type,(LPBYTE)(&Value),&Bytes);
if (Type == REG_DWORD && lResult == ERROR_SUCCESS) {
if (Value == 0x9348ae97) { HaveDebugger = TRUE; }
}
#endif
lResult = RegQueryValueEx(hKeyResults,"Limit FPS",0,&Type,(LPBYTE)(&LimitFPS),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { LimitFPS = Default_LimitFPS; }
lResult = RegQueryValueEx(hKeyResults,"Roms To Remember",0,&Type,(BYTE *)(&RomsToRemember),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { RomsToRemember = Default_RomsToRemember; }
lResult = RegQueryValueEx(hKeyResults,"Rom Dirs To Remember",0,&Type,(BYTE *)(&RomDirsToRemember),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { RomDirsToRemember = Default_RomsDirsToRemember; }
lResult = RegQueryValueEx(hKeyResults,"Start Emulation when rom is opened",0,&Type,(BYTE *)(&AutoStart),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { AutoStart = Default_AutoStart; }
lResult = RegQueryValueEx(hKeyResults,"Use Rom Browser",0,&Type,(BYTE *)(&RomBrowser),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { RomBrowser = Default_UseRB; }
lResult = RegQueryValueEx(hKeyResults,"Use Recursion",0,&Type,(BYTE *)(&Rercursion),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { Rercursion = Default_Rercursion; }
lResult = RegQueryValueEx(hKeyResults,"Always overwrite default settings with ones from ini?",0,&Type,(BYTE *)(&UseIni),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { UseIni = Default_UseIni; }
lResult = RegQueryValueEx(hKeyResults,"Automatically compress instant saves",0,&Type,(BYTE *)(&AutoZip),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { AutoZip = Default_AutoZip; }
lResult = RegQueryValueEx(hKeyResults,"CPU Type",0,&Type,(BYTE *)(&SystemCPU_Type),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { SystemCPU_Type = Default_CPU; }
lResult = RegQueryValueEx(hKeyResults,"Self modifying code method",0,&Type,(LPBYTE)(&SystemSelfModCheck),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { SystemSelfModCheck = Default_SelfModCheck; }
lResult = RegQueryValueEx(hKeyResults,"Advanced Block Linking",0,&Type,(LPBYTE)(&SystemABL),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { SystemABL = Default_AdvancedBlockLink; }
lResult = RegQueryValueEx(hKeyResults,"Default RDRAM Size",0,&Type,(LPBYTE)(&SystemRdramSize),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { SystemRdramSize = Default_RdramSize; }
lResult = RegQueryValueEx(hKeyResults,"Show CPU %",0,&Type,(LPBYTE)(&ShowCPUPer),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { ShowCPUPer = Default_ShowCPUPer; }
lResult = RegQueryValueEx(hKeyResults,"Always On Top",0,&Type,(LPBYTE)(&AlwaysOnTop),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { AlwaysOnTop = Default_AlwaysOnTop; }
}
#if (!defined(EXTERNAL_RELEASE))
if (HaveDebugger) {
lResult = RegQueryValueEx(hKeyResults,"Auto Load Map File",0,&Type,(BYTE *)(&AutoLoadMapFile),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { AutoLoadMapFile = Default_AutoMap; }
lResult = RegQueryValueEx(hKeyResults,"Show Unhandled Memory Accesses",0,&Type,(LPBYTE)(&ShowUnhandledMemory),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { ShowUnhandledMemory = Default_ShowUnhandledMemory; }
lResult = RegQueryValueEx(hKeyResults,"Show Load/Store TLB Misses",0,&Type,(LPBYTE)(&ShowTLBMisses),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { ShowTLBMisses = Default_ShowTLBMisses; }
lResult = RegQueryValueEx(hKeyResults,"Show Dlist/Alist Count",0,&Type,(LPBYTE)(&ShowDListAListCount),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { ShowDListAListCount = Default_ShowDlistCount; }
lResult = RegQueryValueEx(hKeyResults,"Show Compile Memory",0,&Type,(LPBYTE)(&ShowCompMem),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { ShowCompMem = Default_ShowCompileMemory; }
lResult = RegQueryValueEx(hKeyResults,"Show Pif Ram Errors",0,&Type,(LPBYTE)(&ShowPifRamErrors),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { ShowPifRamErrors = Default_ShowPifRamErrors; }
lResult = RegQueryValueEx(hKeyResults,"Profiling On",0,&Type,(LPBYTE)(&Profiling),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { Profiling = Default_ProfilingOn; }
lResult = RegQueryValueEx(hKeyResults,"Log Indvidual Blocks",0,&Type,(LPBYTE)(&IndvidualBlock),&Bytes);
if (Type != REG_DWORD || lResult != ERROR_SUCCESS) { IndvidualBlock = Default_IndvidualBlock; }
}
#endif
RegCloseKey(hKeyResults);
}
}
int InitalizeApplication ( HINSTANCE hInstance ) {
INITCOMMONCONTROLSEX IntComStruct;
HKEY hKeyResults = 0;
CoInitialize(NULL);
IntComStruct.dwSize = sizeof(IntComStruct);
IntComStruct.dwICC = ICC_TREEVIEW_CLASSES;
InitCommonControls();
InitCommonControlsEx(&IntComStruct);
hInst = hInstance;
{
char String[200];
sprintf(String,"Software\\N64 Emulation\\%s",AppName);
//Language selection if none found
LoadLanguage(String);
}
if (!Allocate_Memory()) {
DisplayError(GS(MSG_MEM_ALLOC_ERROR));
return FALSE;
}
hPauseMutex = CreateMutex(NULL,FALSE,NULL);
InitiliazeCPUFlags();
LoadSettings();
SetupRegisters(&Registers);
QueryPerformanceFrequency(&Frequency);
#if (!defined(EXTERNAL_RELEASE))
LoadLogOptions(&LogOptions, FALSE);
StartLog();
#endif
LoadRomBrowserColoumnInfo ();
InitilizeInitialCompilerVariable();
return TRUE;
}
void CheckedMenuItem(UINT uMenuID, BOOL * Flag, char * FlagName) {
char String[256];
DWORD Disposition;
HKEY hKeyResults;
long lResult;
UINT uState;
uState = GetMenuState( hMainMenu, uMenuID, MF_BYCOMMAND);
hKeyResults = 0;
Disposition = 0;
if ( uState & MFS_CHECKED ) {
CheckMenuItem( hMainMenu, uMenuID, MF_BYCOMMAND | MFS_UNCHECKED );
*Flag = FALSE;
} else {
CheckMenuItem( hMainMenu, uMenuID, MF_BYCOMMAND | MFS_CHECKED );
*Flag = TRUE;
}
sprintf(String,"Software\\N64 Emulation\\%s",AppName);
lResult = RegCreateKeyEx( HKEY_CURRENT_USER,String,0,"",
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKeyResults,&Disposition);
if (lResult == ERROR_SUCCESS) {
RegSetValueEx(hKeyResults,FlagName,0,REG_DWORD,(BYTE *)Flag,sizeof(DWORD));
}
RegCloseKey(hKeyResults);
}
LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
#if (!defined(EXTERNAL_RELEASE))
char String[256];
DWORD Disposition;
HKEY hKeyResults;
long lResult;
UINT uState;
#endif
HMENU hMenu;
switch (uMsg) {
case WM_CREATE:
if ( hHiddenWin ) {
hStatusWnd = CreateStatusWindow( WS_CHILD | WS_VISIBLE, "", hWnd, 100 );
SendMessage( hStatusWnd, SB_SETTEXT, 0, (LPARAM)"" );
ChangeWinSize ( hWnd, 640, 480, hStatusWnd );
}
break;
case WM_SYSCOMMAND:
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
case SC_MAXIMIZE:
SetRomBrowserMaximized(TRUE);
return DefWindowProc(hWnd,uMsg,wParam,lParam);
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
break;
case WM_PAINT:
if (RomListVisible()) { ValidateRect(hWnd,NULL); break; }
if (hWnd == hHiddenWin) { ValidateRect(hWnd,NULL); break; }
__try {
if (CPU_Paused && DrawScreen != NULL) { DrawScreen(); }
} __except( r4300i_CPU_MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) {
DisplayError(GS(MSG_UNKNOWN_MEM_ACTION));
ExitThread(0);
}
ValidateRect(hWnd,NULL);
break;
case WM_MOVE:
if (IgnoreMove) { break; }
if (hWnd == hHiddenWin) { break; }
if (MoveScreen != NULL && CPURunning) {
MoveScreen((int)(short) LOWORD(lParam), (int)(short) HIWORD(lParam));
}
if (IsIconic(hWnd)) {
if (!CPU_Paused && !inFullScreen) { PauseCpu(); break; }
break;
} else {
if (!ManualPaused && (CPU_Paused || CPU_Action.Pause)) { PauseCpu(); break; }
}
if (!RomListVisible() || (RomListVisible() && !IsRomBrowserMaximized())) {
StoreCurrentWinPos( RomListVisible()?"Main.RomList":"Main", hWnd );
}
break;
case WM_SIZE:
if (hWnd == hHiddenWin) { break; }
{
RECT clrect, swrect;
int Parts[2];
GetClientRect( hWnd, &clrect );
GetClientRect( hStatusWnd, &swrect );
Parts[0] = (LOWORD( lParam) - (int)( clrect.right * 0.25 ));
Parts[1] = LOWORD( lParam);
SendMessage( hStatusWnd, SB_SETPARTS, 2, (LPARAM)&Parts[0] );
MoveWindow ( hStatusWnd, 0, clrect.bottom - swrect.bottom,
LOWORD( lParam ), HIWORD( lParam ), TRUE );
DisplayFPS();
}
ResizeRomListControl(LOWORD(lParam),HIWORD( lParam ));
if (!IgnoreMove) {
if (wParam == SIZE_RESTORED && RomListVisible()) {
SetRomBrowserMaximized(FALSE);
SetRomBrowserSize(LOWORD(lParam),HIWORD( lParam ));
}
}
break;
case WM_SETFOCUS:
if (hWnd == hHiddenWin) { break; }
if (AutoSleep && !ManualPaused && (CPU_Paused || CPU_Action.Pause)) { PauseCpu(); }
RomList_SetFocus();
break;
case WM_KILLFOCUS:
if (hWnd == hHiddenWin) { break; }
if (AutoSleep && !CPU_Paused) { PauseCpu(); }
break;
case WM_NOTIFY:
if (wParam == IDC_ROMLIST) { RomListNotify((LPNMHDR)lParam); }
return DefWindowProc(hWnd,uMsg,wParam,lParam);
break;
case WM_DRAWITEM:
if (wParam == IDC_ROMLIST) { RomListDrawItem((LPDRAWITEMSTRUCT)lParam); }
break;
case WM_MENUSELECT:
switch (LOWORD(wParam)) {
case ID_PLAYGAME: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_PLAY_GAME)); break;
case ID_POPUPMENU_ROMINFORMATION: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_INFO)); break;
case ID_EDITSETTINGS: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SETTINGS)); break;
case ID_EDITCHEATS: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_CHEATS)); break;
case ID_FILE_OPEN_ROM: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_OPEN)); break;
case ID_FILE_ROM_INFO: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_ROM_INFO)); break;
case ID_FILE_STARTEMULATION: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_START)); break;
case ID_FILE_ENDEMULATION: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_END)); break;
case ID_FILE_ROMDIRECTORY: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_CHOOSE_ROM)); break;
case ID_FILE_REFRESHROMLIST: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_REFRESH)); break;
case ID_FILE_EXIT: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_EXIT)); break;
case ID_CPU_RESET: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_RESET)); break;
case ID_CPU_PAUSE: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_PAUSE)); break;
case ID_SYSTEM_GENERATEBITMAP: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_BITMAP)); break;
case ID_SYSTEM_LIMITFPS: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_LIMIT_FPS)); break;
case ID_CPU_SAVE: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_SAVE)); break;
case ID_CPU_SAVEAS: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_SAVE_AS)); break;
case ID_CPU_RESTORE: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_RESTORE)); break;
case ID_CPU_LOAD: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_LOAD)); break;
case ID_OPTIONS_CHEATS: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_CHEAT)); break;
case ID_SYSTEM_GSBUTTON: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GS_BUTTON)); break;
case ID_OPTIONS_FULLSCREEN: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_FULL_SCREEN)); break;
case ID_OPTIONS_ALWAYSONTOP: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_ON_TOP)); break;
case ID_OPTIONS_CONFIG_GFX: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_CONFG_GFX)); break;
case ID_OPTIONS_CONFIG_AUDIO: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_CONFG_AUDIO)); break;
case ID_OPTIONS_CONFIG_CONTROL: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_CONFG_CTRL)); break;
case ID_OPTIONS_CONFIG_RSP: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_CONFG_RSP)); break;
case ID_OPTIONS_SHOWCPUUSAGE: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_SHOW_CPU)); break;
case ID_OPTIONS_SETTINGS: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_SETTINGS)); break;
case ID_HELP_CONTENTS: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_USER_MAN)); break;
case ID_HELP_GAMEFAQ: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_FAQ)); break;
case ID_HELP_ABOUTSETTINGFILES: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_ABOUT_INI)); break;
case ID_HELP_ABOUT: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_ABOUT_PJ64)); break;
case ID_CURRENTSAVE_DEFAULT: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_1: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_2: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_3: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_4: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_5: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_6: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_7: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_8: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_9: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
case ID_CURRENTSAVE_0: SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_GAME_SLOT)); break;
default:
if (LOWORD(wParam) >= ID_FILE_RECENT_FILE && LOWORD(wParam) <= (ID_FILE_RECENT_FILE + RomsToRemember)) {
SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_RECENT_ROM));
} else if (LOWORD(wParam) >= ID_FILE_RECENT_DIR && LOWORD(wParam) <= (ID_FILE_RECENT_DIR + RomDirsToRemember)) {
SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_RECENT_DIR));
} else if (LOWORD(wParam) >= ID_LANG_SELECT && LOWORD(wParam) <= (ID_LANG_SELECT + 100)) {
SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)GS(MENUDES_LANGUAGES));
} else {
SendMessage(hStatusWnd,SB_SETTEXT,0,(LPARAM)"");
}
break;
}
break;
case WM_KEYDOWN:
if (!CPURunning) { break; }
if (WM_KeyDown) { WM_KeyDown(wParam, lParam); };
break;
case WM_KEYUP:
if (!CPURunning) { break; }
if (WM_KeyUp) { WM_KeyUp(wParam, lParam); };
break;
//case WM_ERASEBKGND: break;
case WM_USER + 10:
if (hWnd == hHiddenWin) { break; }
if (!wParam) {
while (ShowCursor(FALSE) >= 0) { Sleep(0); }
} else {
while (ShowCursor(TRUE) < 0) { Sleep(0); }
}
break;
case WM_USER + 17: SetFocus(hMainWindow); break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_PLAYGAME:
if (strlen(CurrentRBFileName) > 0) {
DWORD ThreadID;
strcpy(CurrentFileName,CurrentRBFileName);
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)OpenChosenFile,NULL,0, &ThreadID);
}
break;
case ID_EDITSETTINGS: ChangeRomSettings(hWnd); break;
case ID_EDITCHEATS: ChangeRomCheats(hMainWindow); break;
case ID_POPUPMENU_ROMINFORMATION:
{
char OrigRomName[sizeof(RomName)], OrigFileName[sizeof(CurrentFileName)];
BYTE OrigByteHeader[sizeof(RomHeader)];
DWORD OrigFileSize;
//Make copy of current Game values
strncpy(OrigRomName,RomName,sizeof(OrigRomName));
strncpy(OrigFileName,CurrentFileName,sizeof(OrigFileName));
memcpy(OrigByteHeader,RomHeader,sizeof(RomHeader));
strncpy(CurrentFileName,CurrentRBFileName,sizeof(CurrentFileName));
OrigFileSize = RomFileSize;
//Load header of selected Rom
LoadRomHeader();
//Display Information
RomInfo();
//Restore settings
strncpy(RomName,OrigRomName,sizeof(RomName));
strncpy(CurrentFileName,OrigFileName,sizeof(CurrentFileName));
memcpy(RomHeader,OrigByteHeader,sizeof(RomHeader));
RomFileSize = OrigFileSize;
}
break;
case ID_FILE_OPEN_ROM: OpenN64Image(); break;
case ID_FILE_ROM_INFO: RomInfo(); break;
case ID_FILE_STARTEMULATION:
if (strlen(RomName) == 0) { break; }
HideRomBrowser();
StartEmulation();
break;
case ID_FILE_ENDEMULATION:
if (inFullScreen) {
CPU_Paused = TRUE;
SendMessage(hMainWindow,WM_COMMAND,ID_OPTIONS_FULLSCREEN,0);
CPU_Paused = FALSE;
}
CloseCpu();
hMenu = GetMenu(hMainWindow);
EnableMenuItem(hMenu,ID_FILE_STARTEMULATION,MFS_ENABLED|MF_BYCOMMAND);
if (DrawScreen != NULL) { DrawScreen(); }
CloseCheatWindow();
if (RomBrowser) {
ShowRomList(hMainWindow);
}
break;
case ID_FILE_ROMDIRECTORY: SelectRomDir(); break;
case ID_FILE_REFRESHROMLIST: RefreshRomBrowser(); break;
case ID_FILE_EXIT: DestroyWindow(hWnd); break;
case ID_CPU_RESET:
CloseCpu();
StartEmulation();
break;
case ID_CPU_PAUSE: ManualPaused = TRUE; PauseCpu(); break;
case ID_CPU_SAVE:
if (CPU_Paused) {
if (!Machine_SaveState()) {
CPU_Action.SaveState = TRUE;
CPU_Action.DoSomething = TRUE;
}
} else {
CPU_Action.SaveState = TRUE;
CPU_Action.DoSomething = TRUE;
}
break;
case ID_CPU_SAVEAS:
{
char drive[_MAX_DRIVE] ,dir[_MAX_DIR], fname[_MAX_FNAME],ext[_MAX_EXT];
char Directory[255], SaveFile[255];
OPENFILENAME openfilename;
if (BasicMode) { break; }
memset(&SaveFile, 0, sizeof(SaveFile));
memset(&openfilename, 0, sizeof(openfilename));
GetInstantSaveDir( Directory );
openfilename.lStructSize = sizeof( openfilename );
openfilename.hwndOwner = hMainWindow;
openfilename.lpstrFilter = "PJ64 Saves (*.zip, *.pj)\0*.pj?;*.pj;*.zip;";
openfilename.lpstrFile = SaveFile;
openfilename.lpstrInitialDir = Directory;
openfilename.nMaxFile = MAX_PATH;
openfilename.Flags = OFN_HIDEREADONLY;
if (GetSaveFileName (&openfilename)) {
_splitpath( SaveFile, drive, dir, fname, ext );
if (strcmp(ext, "pj") == 0 || strcmp(ext, "zip") == 0) {
_makepath( SaveFile, drive, dir, fname, NULL );
}
strcpy(SaveAsFileName,SaveFile);
if (CPU_Paused) {
if (!Machine_SaveState()) {
CPU_Action.SaveState = TRUE;
CPU_Action.DoSomething = TRUE;
}
} else {
CPU_Action.SaveState = TRUE;
CPU_Action.DoSomething = TRUE;
}
}
}
break;
case ID_CPU_RESTORE:
CPU_Action.RestoreState = TRUE;
CPU_Action.DoSomething = TRUE;
break;
case ID_CPU_LOAD:
{
char Directory[255], SaveFile[255];
OPENFILENAME openfilename;
if (BasicMode) { break; }
memset(&SaveFile, 0, sizeof(SaveFile));
memset(&openfilename, 0, sizeof(openfilename));
GetInstantSaveDir( Directory );
openfilename.lStructSize = sizeof( openfilename );
openfilename.hwndOwner = hMainWindow;
openfilename.lpstrFilter = "PJ64 Saves (*.zip, *.pj)\0*.pj?;*.pj;*.zip;";
openfilename.lpstrFile = SaveFile;
openfilename.lpstrInitialDir = Directory;
openfilename.nMaxFile = MAX_PATH;
openfilename.Flags = OFN_HIDEREADONLY;
if (GetOpenFileName (&openfilename)) {
strcpy(LoadFileName,SaveFile);
CPU_Action.RestoreState = TRUE;
CPU_Action.DoSomething = TRUE;
}
}
break;