-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
1756 lines (1578 loc) · 58.3 KB
/
config.cpp
File metadata and controls
1756 lines (1578 loc) · 58.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//#define USE_LOGGING
//======================================================================
// This file is part of VCC (Virtual Color Computer).
// Vcc is Copyright 2015 by Joseph Forgione
//
// VCC (Virtual Color Computer) is free software, you can redistribute
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// VCC (Virtual Color Computer) is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VCC (Virtual Color Computer). If not, see
// <http://www.gnu.org/licenses/>.
//======================================================================
// FIXME: This should be defined on the command line
#define DIRECTINPUT_VERSION 0x0800
#include <vcc/util/limits.h>
#include <Windows.h>
#include <CommCtrl.h>
#include <stdio.h>
#include <Richedit.h>
//#include <shlwapi.h>
#include <iostream>
#include <direct.h>
#include <assert.h>
#include <string>
#pragma warning(push)
#pragma warning(disable:4091)
#include <ShlObj.h>
#pragma warning(pop)
#include "defines.h"
#include "resource.h"
#include "tcc1014graphics.h"
#include "mc6821.h"
#include "Vcc.h"
#include "tcc1014mmu.h"
#include "audio.h"
#include "pakinterface.h"
#include "DirectDrawInterface.h"
#include "joystickinput.h"
#include "keyboard.h"
#include "keyboardEdit.h"
#include <vcc/util/FileOps.h>
#include <vcc/util/DialogOps.h>
#include "Cassette.h"
#include "CommandLine.h"
#include <vcc/util/logger.h>
#include <vcc/util/settings.h>
#include <vcc/util/fileutil.h>
#include "config.h"
using namespace std;
using namespace VCC;
/********************************************/
/* Local Function Templates */
/********************************************/
int SelectFile(char *);
void RefreshJoystickStatus();
unsigned char TranslateDisp2Scan(int);
unsigned char TranslateScan2Disp(int);
void buildTransDisp2ScanTable();
void SetBootModulePath(const std::string);
void WriteCPUSettings();
void WriteAudioSettings();
void WriteWindowSize();
void WriteVideoSettings();
void WriteKeyboardSettings();
void WriteJoystickSettings();
LRESULT CALLBACK CpuConfig(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK AudioConfig(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DisplayConfig(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK InputConfig(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK JoyStickConfig(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK TapeConfig(HWND , UINT , WPARAM , LPARAM );
LRESULT CALLBACK BitBanger(HWND , UINT , WPARAM , LPARAM );
LRESULT CALLBACK Paths(HWND, UINT, WPARAM, LPARAM);
/********************************************/
/* Local Globals */
/********************************************/
// Structure for some (but not all) Vcc settings
struct STRConfig
{
unsigned char CPUMultiplyer = 0;
unsigned short MaxOverclock = 0;
unsigned char FrameSkip = 0;
unsigned char SpeedThrottle = 0;
unsigned char CpuType = 0;
unsigned char HaltOpcEnabled = 0; // 0x15 halt enabled
unsigned char BreakOpcEnabled = 0; // 0x113E halt enabled
unsigned char MonitorType = 0;
unsigned char PaletteType = 0;
unsigned char ScanLines = 0;
unsigned char Aspect = 0;
unsigned char RememberSize = 0;
Rect WindowRect;
unsigned char RamSize = 0;
unsigned char AutoStart = 0;
unsigned char CartAutoStart = 0;
unsigned char RebootNow = 0;
unsigned char SndOutDev = 0;
unsigned char KeyMap = 0;
char SoundCardName[64] = { 0 };
unsigned int AudioRate = 0; // 0 = Mute
char ModulePath[MAX_PATH] = { 0 };
char PathtoExe[MAX_PATH] = { 0 };
char FloppyPath[MAX_PATH] = { 0 };
char CassPath[MAX_PATH] = { 0 };
unsigned char ShowMousePointer = 0;
unsigned char UseExtCocoRom = 0;
char ExtRomFile[MAX_PATH] = { 0 };
unsigned char EnableOverclock = 0;
};
static STRConfig CurrentConfig;
static HICON CpuIcons[2],MonIcons[2],JoystickIcons[4];
static unsigned char temp=0,temp2=0;
static char gcIniFilePath[MAX_PATH]="";
static char KeyMapFilePath[MAX_PATH]="";
static char TapeFileName[MAX_PATH]="";
static char ExecDirectory[MAX_PATH]="";
static char SerialCaptureFile[MAX_PATH]="";
static unsigned char NumberofJoysticks=0;
TCHAR gcAppDataPath[MAX_PATH];
char OutBuffer[MAX_PATH]="";
extern SystemState EmuState;
extern char StickName[MAXSTICKS][STRLEN];
static unsigned int TapeCounter=0;
static unsigned char Tmode=STOP;
unsigned char TapeFastLoad = 1;
char Tmodes[4][10]={"STOP","PLAY","REC","STOP"};
static int NumberOfSoundCards=0;
constexpr auto MAXSOUNDCARDS = 12u;
static SndCardList SoundCards[MAXSOUNDCARDS];
CHARFORMAT CounterText;
CHARFORMAT ModeText;
// Key names and translation tables for keyboard Joystick
#define KEYNAME(x) (keyNames[x])
const char * const keyNames[] = {
"","ESC","1","2","3","4","5","6","7","8","9","0","-","=","BackSp",
"Tab","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
"P","Q","R","S","T","U","V","W","X","Y","Z","[","]","Bkslash",";",
"'","Comma",".","/","CapsLk","Shift","Ctrl","Alt","Space","Enter",
"Insert","Delete","Home","End","PgUp","PgDown","Left","Right",
"Up","Down","F1","F2"};
constexpr auto SCAN_TRANS_COUNT = 84u;
unsigned char _TranslateDisp2Scan[SCAN_TRANS_COUNT];
unsigned char _TranslateScan2Disp[SCAN_TRANS_COUNT] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,32,38,20,33,35,40,36,24,30,
31,42,43,55,52,16,34,19,21,22,23,25,26,27,45,46,0,51,44,41,39,18,
37,17,29,28,47,48,49,51,0,53,54,50,66,67,0,0,0,0,0,0,0,0,0,0,58,
64,60,0,62,0,63,0,59,65,61,56,57 };
// Pointer for settings
static Util::settings* gpSettings = nullptr;
/***********************************************************/
/* Establish ini file and Load Settings */
/***********************************************************/
//---------------------------------------------------------------
// Initial config. This should be called only once when VCC starts up
//---------------------------------------------------------------
void InitialLoadConfig(SystemState *LCState)
{
buildTransDisp2ScanTable();
GetModuleFileName(nullptr,ExecDirectory,MAX_PATH);
PathRemoveFileSpec(ExecDirectory);
strcpy(CurrentConfig.PathtoExe,ExecDirectory);
// Make sure scanlines is off
LCState->ScanLines=0;
// Get sound cards from audio.cpp
NumberOfSoundCards=GetSoundCardList(SoundCards);
// Establish application data path
TCHAR szPath[MAX_PATH] {};
std::string appData {};
if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_APPDATA, nullptr, 0, szPath))) {
Util::FixDirSlashes(szPath);
appData = std::string(szPath) + "/VCC";
}
Util::copy_to_char(appData,gcAppDataPath,MAX_PATH);
// Establish settings storage (ini file) path
std::string ini;
if (*CmdArg.IniFile) {
char buf[MAX_PATH];
if (GetFullPathNameA(CmdArg.IniFile, MAX_PATH, buf, nullptr))
ini = buf;
else
ini = CmdArg.IniFile; // fallback
Util::FixDirSlashes(ini);
} else {
ini = appData + "/Vcc.ini";
}
Util::copy_to_char(ini, gcIniFilePath, MAX_PATH);
// Establish application path
char AppName[MAX_LOADSTRING]="";
LoadString(nullptr, IDS_APP_TITLE,AppName, MAX_LOADSTRING);
Setting().write("Version","Release",AppName);
// Initial load settings
ReadIniFile();
UpdateConfig();
RefreshJoystickStatus();
//FIXME WindowHandle will always be null at this point!
//if (EmuState.WindowHandle != nullptr) InitSound();
}
//---------------------------------------------------------------
// Fatal if this is called before valid gcIniFilePath is established
//---------------------------------------------------------------
VCC::Util::settings& Setting()
{
if (!gpSettings) {
// Fatal if ini file can not be opened
if (!Util::ValidateRWFile(gcIniFilePath)) {
std::string s = "Can't open settings "
+ std::string(gcIniFilePath);
MessageBox(EmuState.WindowHandle,s.c_str(),"Fatal",0);
exit(0);
}
gpSettings = new Util::settings(gcIniFilePath);
}
return *gpSettings;
}
//---------------------------------------------------------------
// Change the ini file path. (from Vcc File menu)
//---------------------------------------------------------------
void SetIniFilePath(const char * path)
{
DLOG_C("SetgcIniFilePath %s\n",path);
if (Util::ValidateRWFile(path)) {
strcpy(gcIniFilePath,path);
// Destroy settings object
delete gpSettings;
gpSettings = nullptr;
// Load new settings
ReadIniFile();
// Reload boot module
UnloadPack();
LoadModule();
// Reset
EmuState.ResetPending=2;
UpdateConfig();
}
}
//---------------------------------------------------------------
// Return settings file path
//---------------------------------------------------------------
void GetIniFilePath( char *Path)
{
// FIXME convert to returning a string
strncpy(Path,gcIniFilePath,MAX_PATH);
DLOG_C("GetIniFilePath %s\n",Path);
return;
}
//---------------------------------------------------------------
// Flush the settings store
//---------------------------------------------------------------
void FlushSettings()
{
Setting().flush();
}
//---------------------------------------------------------------
// Set up sound cards
//---------------------------------------------------------------
void InitSound()
{
SoundInit(EmuState.WindowHandle,
SoundCards[CurrentConfig.SndOutDev].Guid, CurrentConfig.AudioRate);
}
//--------------------------------------------------------------------------
// Make sure boot module path is reasonable for cartridge_loader
// pakinterface loads boot module and saves the ModulePath setting
// Still need to verify the boot module after switching the ini file
//--------------------------------------------------------------------------
void SetBootModulePath(const std::string bootpath)
{
memset(CurrentConfig.ModulePath,0,sizeof(CurrentConfig.ModulePath));
if (bootpath.empty()) return;
std::string fullpath = Util::QualifyModPath(bootpath);
std::string file = Util::StripModPath(bootpath);
namespace fs = std::filesystem;
fs::path p = fullpath;
if (fs::exists(p) && (fs::file_size(p) > 2)) {
Setting().write("Module","OnBoot",file);
strncpy(CurrentConfig.ModulePath,
fullpath.c_str(),
sizeof(CurrentConfig.ModulePath));
} else {
// Delete the key if it does not
Setting().delete_key("Module","OnBoot");
std::string msg = "Invalid boot module '"+bootpath+"' removed";
MessageBox(EmuState.WindowHandle,msg.c_str(),"Warn",MB_OK);
}
}
//---------------------------------------------------------------
// Load Configuration Settings from ini file
//---------------------------------------------------------------
unsigned char ReadIniFile()
{
unsigned char Index=0;
//Loads the config structure from the hard disk
CurrentConfig.CPUMultiplyer = Setting().read("CPU","DoubleSpeedClock",2);
CurrentConfig.FrameSkip = Setting().read("CPU","FrameSkip",1);
CurrentConfig.SpeedThrottle = Setting().read("CPU","Throttle",1);
CurrentConfig.CpuType = Setting().read("CPU","CpuType",0);
CurrentConfig.MaxOverclock = Setting().read("CPU","MaxOverClock",100);
CurrentConfig.BreakOpcEnabled = Setting().read("CPU","BreakEnabled",0);
CurrentConfig.AudioRate = Setting().read("Audio","Rate",3);
Setting().read("Audio","SndCard","",CurrentConfig.SoundCardName,63);
CurrentConfig.MonitorType = Setting().read("Video","MonitorType",1);
CurrentConfig.PaletteType = Setting().read("Video","PaletteType",PALETTE_NTSC);
CurrentConfig.ScanLines = Setting().read("Video","ScanLines",0);
CurrentConfig.FrameSkip = Setting().read("Video","FrameSkip",1);
CurrentConfig.Aspect = Setting().read("Video","ForceAspect",1);
CurrentConfig.RememberSize = Setting().read("Video","RememberSize",1);
CurrentConfig.WindowRect.w = Setting().read("Video","WindowSizeX", 640);
CurrentConfig.WindowRect.h = Setting().read("Video","WindowSizeY", 480);
CurrentConfig.WindowRect.x = Setting().read("Video","WindowPosX",CW_USEDEFAULT);
CurrentConfig.WindowRect.y = Setting().read("Video","WindowPosY",CW_USEDEFAULT);
CurrentConfig.AutoStart = Setting().read("Misc","AutoStart",1);
CurrentConfig.CartAutoStart = Setting().read("Misc","CartAutoStart",1);
CurrentConfig.ShowMousePointer = Setting().read("Misc","ShowMousePointer",1);
CurrentConfig.UseExtCocoRom = Setting().read("Misc","UseExtCocoRom",0);
CurrentConfig.EnableOverclock = Setting().read("Misc","Overclock",1);
Setting().read("Misc","ExternalBasicImage","",CurrentConfig.ExtRomFile,MAX_PATH);
CurrentConfig.RamSize = Setting().read("Memory","RamSize",1);
CurrentConfig.KeyMap = Setting().read("Misc","KeyMapIndex",0);
if (CurrentConfig.KeyMap>3)
CurrentConfig.KeyMap=0; //Default to DECB Mapping
Setting().read("Misc","CustomKeyMapFile","",KeyMapFilePath,MAX_PATH);
if (*KeyMapFilePath == '\0') {
strcpy(KeyMapFilePath, gcAppDataPath);
strcat(KeyMapFilePath, "\\custom.keymap");
}
if (CurrentConfig.KeyMap == kKBLayoutCustom) LoadCustomKeyMap(KeyMapFilePath);
vccKeyboardBuildRuntimeTable((keyboardlayout_e)CurrentConfig.KeyMap);
// If bootpath is relative prepend the current module exe directory
std::string bootpath = Util::QualifyModPath(Setting().read("Module","OnBoot",""));
SetBootModulePath(bootpath);
LeftJS.UseMouse = Setting().read("LeftJoyStick" ,"UseMouse",1);
LeftJS.Left = Setting().read("LeftJoyStick" ,"Left",75);
LeftJS.Right = Setting().read("LeftJoyStick" ,"Right",77);
LeftJS.Up = Setting().read("LeftJoyStick" ,"Up",72);
LeftJS.Down = Setting().read("LeftJoyStick" ,"Down",80);
LeftJS.Fire1 = Setting().read("LeftJoyStick" ,"Fire1",59);
LeftJS.Fire2 = Setting().read("LeftJoyStick" ,"Fire2",60);
LeftJS.DiDevice = Setting().read("LeftJoyStick" ,"DiDevice",0);
LeftJS.HiRes = Setting().read("LeftJoyStick" ,"HiResDevice",0);
RightJS.UseMouse = Setting().read("RightJoyStick","UseMouse",1);
RightJS.Left = Setting().read("RightJoyStick","Left",75);
RightJS.Right = Setting().read("RightJoyStick","Right",77);
RightJS.Up = Setting().read("RightJoyStick","Up",72);
RightJS.Down = Setting().read("RightJoyStick","Down",80);
RightJS.Fire1 = Setting().read("RightJoyStick","Fire1",59);
RightJS.Fire2 = Setting().read("RightJoyStick","Fire2",60);
RightJS.DiDevice = Setting().read("RightJoyStick","DiDevice",0);
RightJS.HiRes = Setting().read("RightJoyStick", "HiResDevice",0);
Setting().read("DefaultPaths", "CassPath", "", CurrentConfig.CassPath, MAX_PATH);
Setting().read("DefaultPaths", "FloppyPath", "", CurrentConfig.FloppyPath, MAX_PATH);
for (Index = 0; Index < NumberOfSoundCards; Index++)
{
if (!strcmp(SoundCards[Index].CardName, CurrentConfig.SoundCardName))
{
CurrentConfig.SndOutDev = Index;
}
}
// Make sure Window geometry is reasonable
int sw = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int sh = GetSystemMetrics(SM_CYVIRTUALSCREEN);
if ( (CurrentConfig.WindowRect.w < 215) |
(CurrentConfig.WindowRect.h < 160) |
(CurrentConfig.WindowRect.x < -100) |
(CurrentConfig.WindowRect.y < -80) |
(CurrentConfig.WindowRect.x > sw-100) |
(CurrentConfig.WindowRect.y > sh-80) )
CurrentConfig.WindowRect = {0,0,640,480};
return 0;
}
//---------------------------------------------------------------
// Save Configuration Settings to ini file
//---------------------------------------------------------------
void WriteCPUSettings() {
Setting().write("CPU","DoubleSpeedClock",CurrentConfig.CPUMultiplyer);
Setting().write("CPU","FrameSkip",CurrentConfig.FrameSkip);
Setting().write("CPU","Throttle",CurrentConfig.SpeedThrottle);
Setting().write("CPU","CpuType",CurrentConfig.CpuType);
Setting().write("CPU","MaxOverClock", CurrentConfig.MaxOverclock);
Setting().write("CPU","BreakEnabled",CurrentConfig.BreakOpcEnabled);
Setting().write("Memory","RamSize",CurrentConfig.RamSize);
Setting().write("Misc","AutoStart",CurrentConfig.AutoStart);
Setting().write("Misc","CartAutoStart",CurrentConfig.CartAutoStart);
Setting().write("Misc","UseExtCocoRom",CurrentConfig.UseExtCocoRom);
Setting().write("Misc","Overclock", CurrentConfig.EnableOverclock);
Setting().write("Misc","ExternalBasicImage", CurrentConfig.ExtRomFile);
}
void WriteAudioSettings() {
Setting().write("Audio","SndCard",CurrentConfig.SoundCardName);
Setting().write("Audio","Rate",CurrentConfig.AudioRate);
}
void WriteWindowSize() {
if (CurrentConfig.RememberSize) {
Rect winRect = GetCurWindowSize();
Setting().write("Video","WindowSizeX",winRect.w);
Setting().write("Video","WindowSizeY",winRect.h);
Setting().write("Video","WindowPosX",winRect.x);
Setting().write("Video","WindowPosY",winRect.y);
}
}
void WriteVideoSettings() {
WriteWindowSize();
Setting().write("Video","MonitorType",CurrentConfig.MonitorType);
Setting().write("Video","PaletteType",CurrentConfig.PaletteType);
Setting().write("Video","ScanLines",CurrentConfig.ScanLines);
Setting().write("Video","ForceAspect",CurrentConfig.Aspect);
Setting().write("Video","RememberSize",CurrentConfig.RememberSize);
Setting().write("Video","FrameSkip",CurrentConfig.FrameSkip);
}
void WriteKeyboardSettings() {
Setting().write("Misc","KeyMapIndex",CurrentConfig.KeyMap);
}
void WriteJoystickSettings() {
Setting().write("LeftJoyStick","UseMouse",LeftJS.UseMouse);
Setting().write("LeftJoyStick","Left",LeftJS.Left);
Setting().write("LeftJoyStick","Right",LeftJS.Right);
Setting().write("LeftJoyStick","Up",LeftJS.Up);
Setting().write("LeftJoyStick","Down",LeftJS.Down);
Setting().write("LeftJoyStick","Fire1",LeftJS.Fire1);
Setting().write("LeftJoyStick","Fire2",LeftJS.Fire2);
Setting().write("LeftJoyStick","DiDevice",LeftJS.DiDevice);
Setting().write("LeftJoyStick", "HiResDevice", LeftJS.HiRes);
Setting().write("RightJoyStick","UseMouse",RightJS.UseMouse);
Setting().write("RightJoyStick","Left",RightJS.Left);
Setting().write("RightJoyStick","Right",RightJS.Right);
Setting().write("RightJoyStick","Up",RightJS.Up);
Setting().write("RightJoyStick","Down",RightJS.Down);
Setting().write("RightJoyStick","Fire1",RightJS.Fire1);
Setting().write("RightJoyStick","Fire2",RightJS.Fire2);
Setting().write("RightJoyStick","DiDevice",RightJS.DiDevice);
Setting().write("RightJoyStick", "HiResDevice", RightJS.HiRes);
Setting().write("Misc","ShowMousePointer",CurrentConfig.ShowMousePointer);
}
void LoadModule()
{
if (CurrentConfig.ModulePath[0])
{
PakLoadCartridge(CurrentConfig.ModulePath);
}
}
void SetWindowRect(const Rect& rect)
{
if (EmuState.WindowHandle != nullptr)
{
RECT ra = { 0,0,0,0 }; // left,top,right,bottom
::AdjustWindowRect(&ra, WS_OVERLAPPEDWINDOW, TRUE);
int windowBorderWidth = ra.right - ra.left;
int windowBorderHeight = ra.bottom - ra.top;
::GetWindowRect(EmuState.WindowHandle, &ra);
int width = rect.w + windowBorderWidth;
int height = rect.h + windowBorderHeight + GetRenderWindowStatusBarHeight();
int flags = SWP_NOOWNERZORDER | SWP_NOZORDER;
int x = rect.IsDefaultX() ? ra.left : rect.x;
int y = rect.IsDefaultY() ? ra.top : rect.y;
SetWindowPos(EmuState.WindowHandle, nullptr, x, y, width, height, flags);
}
}
// The following functions only work after InitialLoadConfig has been called
char * AppDirectory()
{
return gcAppDataPath;
}
char * GetKeyMapFilePath()
{
return KeyMapFilePath;
}
void SetKeyMapFilePath(const char *Path)
{
strcpy(KeyMapFilePath,Path);
Setting().write("Misc","CustomKeyMapFile",KeyMapFilePath);
}
/*******************************************************/
/* Apply video and CPU settings. Also Called by Vcc.c */
/*******************************************************/
void UpdateConfig ()
{
// Video
SetPaletteType();
SetMonitorType(CurrentConfig.MonitorType);
SetAspect(CurrentConfig.Aspect);
SetScanLines(CurrentConfig.ScanLines);
SetFrameSkip(CurrentConfig.FrameSkip);
EmuState.MousePointer = CurrentConfig.ShowMousePointer;
// Cpu
SetAutoStart(CurrentConfig.AutoStart);
SetSpeedThrottle(CurrentConfig.SpeedThrottle);
SetCPUMultiplyer(CurrentConfig.CPUMultiplyer);
SetRamSize(CurrentConfig.RamSize);
SetCpuType(CurrentConfig.CpuType);
SetOverclock(CurrentConfig.EnableOverclock);
if (CurrentConfig.BreakOpcEnabled) {
EmuState.Debugger.Enable_Break(true);
} else {
EmuState.Debugger.Enable_Break(false);
}
SetCartAutoStart(CurrentConfig.CartAutoStart);
if (CurrentConfig.RebootNow)
DoReboot();
CurrentConfig.RebootNow=0;
}
/********************************************/
/* Cpu Config */
/********************************************/
HWND hCpuDlg = nullptr;
void OpenCpuConfig() {
if (hCpuDlg==nullptr) {
hCpuDlg = CreateDialog
(EmuState.WindowInstance,(LPCTSTR) IDD_CPU,EmuState.WindowHandle,(DLGPROC) CpuConfig);
}
ShowWindow(hCpuDlg,SW_SHOWNORMAL);
SetFocus(hCpuDlg);
}
LRESULT CALLBACK CpuConfig(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
{
short int Ramchoice[4] = {IDC_128K,IDC_512K,IDC_2M,IDC_8M};
short int Cpuchoice[2] = {IDC_6809,IDC_6309};
unsigned char temp;
static STRConfig tmpcfg;
HWND hClkSpd = GetDlgItem(hDlg,IDC_CLOCKSPEED);
HWND hClkDsp = GetDlgItem(hDlg,IDC_CLOCKDISPLAY);
switch (message) {
case WM_INITDIALOG:
tmpcfg = CurrentConfig;
CpuIcons[0]=LoadIcon(EmuState.WindowInstance,(LPCTSTR)IDI_MOTO);
CpuIcons[1]=LoadIcon(EmuState.WindowInstance,(LPCTSTR)IDI_HITACHI2);
SendMessage(hClkSpd,TBM_SETRANGE,TRUE,MAKELONG(2,CurrentConfig.MaxOverclock));
sprintf(OutBuffer,"%2.3f Mhz",(float)CurrentConfig.CPUMultiplyer*.894);
SendMessage(hClkDsp,WM_SETTEXT,0,(LPARAM)(LPCSTR)OutBuffer);
SendMessage(hClkSpd,TBM_SETPOS,TRUE, CurrentConfig.CPUMultiplyer);
for (temp=0;temp<=3;temp++)
SendDlgItemMessage(hDlg,Ramchoice[temp],BM_SETCHECK,
(temp==CurrentConfig.RamSize),0);
for (temp=0;temp<=1;temp++)
SendDlgItemMessage(hDlg,Cpuchoice[temp],BM_SETCHECK,
(temp==CurrentConfig.CpuType),0);
SendDlgItemMessage (hDlg,IDC_CPUICON,STM_SETIMAGE,(WPARAM)IMAGE_ICON,
(LPARAM)CpuIcons[CurrentConfig.CpuType]);
SendDlgItemMessage(hDlg,IDC_ENABLE_BREAK,BM_SETCHECK,CurrentConfig.BreakOpcEnabled,0);
SendDlgItemMessage(hDlg,IDC_AUTOSTART,BM_SETCHECK,tmpcfg.AutoStart,0);
SendDlgItemMessage(hDlg,IDC_AUTOCART,BM_SETCHECK,tmpcfg.CartAutoStart,0);
SendDlgItemMessage(hDlg,IDC_USE_EXTROM,BM_SETCHECK,tmpcfg.UseExtCocoRom,0);
SendDlgItemMessage(hDlg,IDC_OVERCLOCK,BM_SETCHECK,tmpcfg.EnableOverclock,0);
SetDlgItemText(hDlg,IDC_ROMPATH,tmpcfg.ExtRomFile);
break;
case WM_HSCROLL:
tmpcfg.CPUMultiplyer = (unsigned char) SendMessage (hClkSpd,TBM_GETPOS,0,0);
sprintf(OutBuffer,"%2.3f Mhz",(float)tmpcfg.CPUMultiplyer*.894);
SendDlgItemMessage(hDlg,IDC_CLOCKDISPLAY,WM_SETTEXT,0,(LPARAM)(LPCSTR)OutBuffer);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
case IDCLOSE:
hCpuDlg = nullptr;
DestroyWindow(hDlg);
break;
case IDOK:
case IDAPPLY:
// Get coco3.rom path from dialog if external
if (tmpcfg.UseExtCocoRom) {
GetDlgItemText(hDlg,IDC_ROMPATH,tmpcfg.ExtRomFile,MAX_PATH);
}
// It is important that Cpu settings are not changed while the
// emulation is actually running. ResetPending causes Vcc.c to
// call UpdateConfig() which causes the settings to take effect.
// TODO: Use lock to avoid race condition instead?
if ( (CurrentConfig.RamSize != tmpcfg.RamSize) |
(CurrentConfig.CpuType != tmpcfg.CpuType) |
(CurrentConfig.UseExtCocoRom != tmpcfg.UseExtCocoRom) |
(strcmp(CurrentConfig.ExtRomFile,tmpcfg.ExtRomFile) != 0)) {
EmuState.ResetPending = 2; // Hard reset
} else {
EmuState.ResetPending = 4; // Update config
}
// Commit any CPU modifications
CurrentConfig.RamSize = tmpcfg.RamSize;
CurrentConfig.CpuType = tmpcfg.CpuType;
CurrentConfig.BreakOpcEnabled = tmpcfg.BreakOpcEnabled;
CurrentConfig.CPUMultiplyer = tmpcfg.CPUMultiplyer;
// Set CPU icon in dialog window
SendDlgItemMessage ( hDlg,IDC_CPUICON,STM_SETIMAGE,(WPARAM)IMAGE_ICON,
(LPARAM)CpuIcons[CurrentConfig.CpuType] );
CurrentConfig.AutoStart = tmpcfg.AutoStart;
CurrentConfig.CartAutoStart = tmpcfg.CartAutoStart;
CurrentConfig.UseExtCocoRom = tmpcfg.UseExtCocoRom;
CurrentConfig.EnableOverclock = tmpcfg.EnableOverclock;
strncpy(CurrentConfig.ExtRomFile,tmpcfg.ExtRomFile,MAX_PATH);
SetOverclock(CurrentConfig.EnableOverclock);
// FIXME should only save CPU stuff here
WriteCPUSettings();
// Exit dialog if IDOK
if (LOWORD(wParam)==IDOK) {
hCpuDlg = nullptr;
DestroyWindow(hDlg);
}
break;
case IDC_128K:
case IDC_512K:
case IDC_2M:
case IDC_8M:
for (temp=0;temp<=3;temp++) {
if (LOWORD(wParam) == Ramchoice[temp]) {
SendDlgItemMessage(hDlg,Ramchoice[temp],BM_SETCHECK,1,0);
tmpcfg.RamSize=temp;
} else {
SendDlgItemMessage(hDlg,Ramchoice[temp],BM_SETCHECK,0,0);
}
}
break;
case IDC_6809:
case IDC_6309:
for (temp=0;temp<=1;temp++) {
if (LOWORD(wParam) == Cpuchoice[temp]) {
tmpcfg.CpuType = temp;
SendDlgItemMessage(hDlg,Cpuchoice[temp],BM_SETCHECK,1,0);
} else {
SendDlgItemMessage(hDlg,Cpuchoice[temp],BM_SETCHECK,0,0);
}
}
break;
case IDC_ENABLE_BREAK:
tmpcfg.BreakOpcEnabled = (unsigned char)
SendDlgItemMessage(hDlg,IDC_ENABLE_BREAK,BM_GETCHECK,0,0);
break;
case IDC_AUTOSTART:
tmpcfg.AutoStart = (unsigned char)
SendDlgItemMessage(hDlg,IDC_AUTOSTART,BM_GETCHECK,0,0);
break;
case IDC_AUTOCART:
tmpcfg.CartAutoStart = (unsigned char)
SendDlgItemMessage(hDlg,IDC_AUTOCART,BM_GETCHECK,0,0);
break;
case IDC_USE_EXTROM:
tmpcfg.UseExtCocoRom = (unsigned char)
SendDlgItemMessage(hDlg,IDC_USE_EXTROM,BM_GETCHECK,0,0);
break;
case IDC_OVERCLOCK:
tmpcfg.EnableOverclock = (unsigned char)
SendDlgItemMessage(hDlg,IDC_OVERCLOCK,BM_GETCHECK,0,0);
break;
case IDC_BROWSE: {
FileDialog dlg;
dlg.setInitialDir(ExecDirectory);
dlg.setFilter("Rom Image\0*.rom\0\0");
dlg.setTitle("Coco3 Rom Image");
dlg.setFlags(OFN_FILEMUSTEXIST);
if (dlg.show()) {
dlg.getupath(tmpcfg.ExtRomFile,MAX_PATH);
SetDlgItemText(hDlg,IDC_ROMPATH,tmpcfg.ExtRomFile);
}
}
break;
} //End switch LOWORD(wParam)
break; //Break WM_COMMAND
} //END switch (message)
return 0;
}
/* Set overclocking */
void SetOverclock(unsigned char flag)
{
EmuState.OverclockFlag = flag;
if (hCpuDlg != nullptr)
SendDlgItemMessage(hCpuDlg,IDC_OVERCLOCK,BM_SETCHECK,flag,0);
}
/* Increase the overclock speed (2..100), as seen after a POKE 65497,0. */
void IncreaseOverclockSpeed()
{
if (CurrentConfig.CPUMultiplyer >= CurrentConfig.MaxOverclock) return;
CurrentConfig.CPUMultiplyer = (unsigned char)(CurrentConfig.CPUMultiplyer + 1);
// Send updates to the dialog if it's open.
if (hCpuDlg != nullptr) {
SendDlgItemMessage(hCpuDlg, IDC_CLOCKSPEED, TBM_SETPOS,
TRUE, CurrentConfig.CPUMultiplyer);
sprintf(OutBuffer, "%2.3f Mhz", (float)CurrentConfig.CPUMultiplyer * 0.894);
SendDlgItemMessage(hCpuDlg, IDC_CLOCKDISPLAY, WM_SETTEXT,
0, (LPARAM)(LPCSTR)OutBuffer);
}
EmuState.ResetPending = 4; // Without this, changing the config does nothing.
//SetCPUMultiplyer(CurrentConfig.CPUMultiplyer) may work here instead
}
/* Decrease the overclock speed */
void DecreaseOverclockSpeed()
{
if (CurrentConfig.CPUMultiplyer == 2) return;
CurrentConfig.CPUMultiplyer = (unsigned char)(CurrentConfig.CPUMultiplyer - 1);
// Send updates to the dialog if it's open.
if (hCpuDlg != nullptr) {
SendDlgItemMessage(hCpuDlg, IDC_CLOCKSPEED, TBM_SETPOS,
TRUE, CurrentConfig.CPUMultiplyer);
sprintf(OutBuffer, "%2.3f Mhz", (float)CurrentConfig.CPUMultiplyer * 0.894);
SendDlgItemMessage(hCpuDlg, IDC_CLOCKDISPLAY, WM_SETTEXT,
0, (LPARAM)(LPCSTR)OutBuffer);
}
EmuState.ResetPending = 4; // So emulation knows the speed changed
//SetCPUMultiplyer(CurrentConfig.CPUMultiplyer) may work here instead
}
/********************************************/
/* Tape Config */
/********************************************/
HWND hTapeDlg = nullptr;
void OpenTapeConfig() {
if (hTapeDlg==nullptr) {
hTapeDlg = CreateDialog
( EmuState.WindowInstance, (LPCTSTR) IDD_CASSETTE,
EmuState.WindowHandle, (DLGPROC) TapeConfig );
}
ShowWindow(hTapeDlg,SW_SHOWNORMAL);
SetFocus(hTapeDlg);
}
LRESULT CALLBACK TapeConfig(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
{
CounterText.cbSize = sizeof(CHARFORMAT);
CounterText.dwMask = CFM_BOLD | CFM_COLOR ;
CounterText.dwEffects = CFE_BOLD;
CounterText.crTextColor=RGB(255,255,255);
ModeText.cbSize = sizeof(CHARFORMAT);
ModeText.dwMask = CFM_BOLD | CFM_COLOR ;
ModeText.dwEffects = CFE_BOLD;
ModeText.crTextColor=RGB(255,0,0);
switch (message) {
case WM_INITDIALOG:
TapeCounter=GetTapeCounter();
sprintf(OutBuffer,"%i",TapeCounter);
SendDlgItemMessage(hDlg,IDC_TCOUNT,WM_SETTEXT,0,(LPARAM)(LPCSTR)OutBuffer);
SendDlgItemMessage(hDlg,IDC_MODE,WM_SETTEXT,0,(LPARAM)(LPCSTR)Tmodes[Tmode]);
GetTapeName(TapeFileName); // Defined in Cassette.cpp
SendDlgItemMessage(hDlg,IDC_TAPEFILE,WM_SETTEXT,0,(LPARAM)(LPCSTR)TapeFileName);
SendDlgItemMessage(hDlg,IDC_TCOUNT,EM_SETBKGNDCOLOR ,0,(LPARAM)RGB(0,0,0));
SendDlgItemMessage(hDlg,IDC_TCOUNT,EM_SETCHARFORMAT ,SCF_ALL,(LPARAM)&CounterText);
SendDlgItemMessage(hDlg,IDC_MODE,EM_SETBKGNDCOLOR ,0,(LPARAM)RGB(0,0,0));
SendDlgItemMessage(hDlg,IDC_MODE,EM_SETCHARFORMAT ,SCF_ALL,(LPARAM)&CounterText);
SendDlgItemMessage(hDlg,IDC_FASTLOAD, BM_SETCHECK, TapeFastLoad, 0);
break;
case WM_COMMAND:
switch (LOWORD (wParam)) {
case IDCANCEL:
case IDCLOSE:
hTapeDlg = nullptr;
DestroyWindow(hDlg);
break;
case IDOK:
case IDAPPLY:
UpdateConfig();
// FIXME Save changes (TapeFastLoad) to IniFile
if (LOWORD(wParam)==IDOK) {
hTapeDlg = nullptr;
DestroyWindow(hDlg);
}
break;
case IDC_PLAY:
SetTapeMode(PLAY);
break;
case IDC_REC:
SetTapeMode(REC);
break;
case IDC_STOP:
SetTapeMode(STOP);
break;
case IDC_EJECT:
SetTapeMode(EJECT);
break;
case IDC_RESET:
SetTapeCounter(0);
SetTapeMode(STOP);
break;
case IDC_TBROWSE:
LoadTape();
SendDlgItemMessage(hDlg, IDC_FASTLOAD, BM_SETCHECK, TapeFastLoad, 0);
SetTapeCounter(0, true);
break;
case IDC_FASTLOAD:
TapeFastLoad = (unsigned char)SendDlgItemMessage(hDlg, IDC_FASTLOAD, BM_GETCHECK, 0, 0);
break;
}
break; //End WM_COMMAND
}
return 0;
}
void UpdateTapeCounter(unsigned int Counter,unsigned char TapeMode, bool forced)
{
if (hTapeDlg==nullptr) return;
if (Counter != TapeCounter || forced)
{
TapeCounter = Counter;
sprintf(OutBuffer, "%i", TapeCounter);
SendDlgItemMessage(hTapeDlg, IDC_TCOUNT,
WM_SETTEXT, 0, (LPARAM)(LPCSTR)OutBuffer);
}
if (Tmode != TapeMode || forced)
{
Tmode = TapeMode;
SendDlgItemMessage(hTapeDlg, IDC_MODE,
WM_SETTEXT, 0, (LPARAM)(LPCSTR)Tmodes[Tmode]);
GetTapeName(TapeFileName);
PathStripPath(TapeFileName);
SendDlgItemMessage(hTapeDlg, IDC_TAPEFILE,
WM_SETTEXT, 0, (LPARAM)(LPCSTR)TapeFileName);
switch (Tmode) {
case REC:
SendDlgItemMessage(hTapeDlg, IDC_MODE, EM_SETBKGNDCOLOR, 0, (LPARAM)RGB(0xAF, 0, 0));
break;
case PLAY:
SendDlgItemMessage(hTapeDlg, IDC_MODE, EM_SETBKGNDCOLOR, 0, (LPARAM)RGB(0, 0xAF, 0));
break;
default:
SendDlgItemMessage(hTapeDlg, IDC_MODE, EM_SETBKGNDCOLOR, 0, (LPARAM)RGB(0, 0, 0));
break;
}
}
}
/********************************************/
/* Audio Config */
/********************************************/
HWND hAudioDlg = nullptr;
void OpenAudioConfig() {
if (hAudioDlg==nullptr) {
hAudioDlg = CreateDialog
(EmuState.WindowInstance,(LPCTSTR) IDD_AUDIO,EmuState.WindowHandle,(DLGPROC) AudioConfig);
}
ShowWindow(hAudioDlg,SW_SHOWNORMAL);
SetFocus(hAudioDlg);
}
LRESULT CALLBACK AudioConfig(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
{
int Index;
static STRConfig tmpcfg;
WPARAM bstate;
switch (message) {
case WM_INITDIALOG:
tmpcfg = CurrentConfig;
// Sound level bars (L and R are equal)
SendDlgItemMessage(hDlg,IDC_PROGRESSLEFT,PBM_SETPOS,0,0);
SendDlgItemMessage(hDlg,IDC_PROGRESSLEFT,PBM_SETRANGE32,0,0x7F);
SendDlgItemMessage(hDlg,IDC_PROGRESSRIGHT,PBM_SETPOS,0,0);
SendDlgItemMessage(hDlg,IDC_PROGRESSRIGHT,PBM_SETRANGE32,0,0x7F);
SendDlgItemMessage(hDlg,IDC_PROGRESSLEFT,PBM_SETPOS,0,0);
SendDlgItemMessage(hDlg,IDC_PROGRESSLEFT,PBM_SETBARCOLOR,0,0xFFFF); //bgr
SendDlgItemMessage(hDlg,IDC_PROGRESSRIGHT,PBM_SETBARCOLOR,0,0xFFFF);
SendDlgItemMessage(hDlg,IDC_PROGRESSLEFT,PBM_SETBKCOLOR,0,0);
SendDlgItemMessage(hDlg,IDC_PROGRESSRIGHT,PBM_SETBKCOLOR,0,0);
for (Index=0;Index<NumberOfSoundCards;Index++)
SendDlgItemMessage(hDlg,IDC_SOUNDCARD,CB_ADDSTRING,
(WPARAM)0,(LPARAM)SoundCards[Index].CardName);
// In coco3.cpp audio rate is forced to 0 (mute) or 3 (44100)
// Rate dropdown has been replaced with a mute check box
bstate = (tmpcfg.AudioRate==0) ? BST_CHECKED : BST_UNCHECKED;
SendDlgItemMessage(hDlg,IDC_MUTE,BM_SETCHECK,bstate,0);
// Sound device selection
tmpcfg.SndOutDev=0;
for (Index=0;Index<NumberOfSoundCards;Index++)
if (!strcmp(SoundCards[Index].CardName,tmpcfg.SoundCardName))
tmpcfg.SndOutDev=Index;
SendDlgItemMessage(hDlg,IDC_SOUNDCARD,CB_SETCURSEL,
(WPARAM)tmpcfg.SndOutDev,(LPARAM)0);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
case IDCLOSE:
hAudioDlg = nullptr;
DestroyWindow(hDlg);
break;
case IDOK:
case IDAPPLY:
tmpcfg.SndOutDev =
(unsigned char) SendDlgItemMessage(hDlg,IDC_SOUNDCARD,CB_GETCURSEL,0,0);
tmpcfg.AudioRate =
(SendDlgItemMessage(hDlg,IDC_MUTE,BM_GETCHECK,0,0) == BST_CHECKED)? 0:3;
if ( (CurrentConfig.SndOutDev != tmpcfg.SndOutDev) |
(CurrentConfig.AudioRate != tmpcfg.AudioRate)) {
SoundInit ( EmuState.WindowHandle,
SoundCards[tmpcfg.SndOutDev].Guid,
tmpcfg.AudioRate);
}
CurrentConfig.AudioRate = tmpcfg.AudioRate;
CurrentConfig.SndOutDev = tmpcfg.SndOutDev;
strcpy(CurrentConfig.SoundCardName, SoundCards[CurrentConfig.SndOutDev].CardName);
WriteAudioSettings();
if (LOWORD(wParam)==IDOK) {
hAudioDlg = nullptr;
DestroyWindow(hDlg);
}
break;
}
break;
}
return 0;
}
void UpdateSoundBar(const unsigned int * audioBuf,unsigned int bufLen)
{
if (hAudioDlg == nullptr) return; // Do nothing if dialog is not running
// Craig's method moved from audio.c with liberties taken for variable naming
// Get mid level for 100 samples, left and right