1 /*
2  *  main_WIN32.i - Main program, WIN32 specific stuff
3  *
4  *  Frodo (C) 1994-1997,2002 Christian Bauer
5  *  WIN32 code by J. Richard Sladkey <jrs@world.std.com>
6  */
7 
8 #include <math.h>
9 
10 // The application.
11 Frodo *TheApp;
12 
13 // WinMain args.
14 HINSTANCE hInstance;
15 int nCmdShow;
16 HWND hwnd;
17 
WinMain(HINSTANCE hInstance_arg,HINSTANCE,LPSTR lpCmdLine,int nCmdShow_arg)18 int PASCAL WinMain(HINSTANCE hInstance_arg, HINSTANCE /* hPrevInstance */, LPSTR lpCmdLine, int nCmdShow_arg)
19 {
20 	hInstance = hInstance_arg;
21 	nCmdShow = nCmdShow_arg;
22 	TheApp = new Frodo();
23 	TheApp->ArgvReceived(__argc, __argv);
24 	TheApp->ReadyToRun();
25 	delete TheApp;
26 	DestroyWindow(hwnd);
27 	return 0;
28 }
29 
30 /*
31  *  Constructor: Initialize member variables
32  */
33 
Frodo()34 Frodo::Frodo()
35 {
36 	TheC64 = NULL;
37 	prefs_path[0] = 0;
38 }
39 
40 
~Frodo()41 Frodo::~Frodo()
42 {
43 	delete TheC64;
44 }
45 
46 
47 /*
48  *  Process command line arguments
49  */
50 
ArgvReceived(int argc,char ** argv)51 void Frodo::ArgvReceived(int argc, char **argv)
52 {
53 	char *progname = argv[0];
54 	argc--, argv++;
55 	if (argc >= 1 && argv[0][0] != '\0') {
56 
57 		// XXX: This should be a function.
58 		char cwd[256];
59 		GetCurrentDirectory(sizeof(cwd), cwd);
60 		int cwd_len = strlen(cwd);
61 		if (cwd_len > 0 && cwd[cwd_len - 1] != '\\') {
62 			strcat(cwd, "\\");
63 			cwd_len++;
64 		}
65 		if (strnicmp(argv[0], cwd, cwd_len) == 0)
66 			strncpy(prefs_path, argv[0] + cwd_len, 255);
67 		else
68 			strncpy(prefs_path, argv[0], 255);
69 		int length = strlen(prefs_path);
70 		if (length > 4 && strchr(prefs_path, '.') == NULL)
71 			strcat(prefs_path, ".fpr");
72 	}
73 }
74 
75 
76 /*
77  *  Arguments processed, run emulation
78  */
79 
ReadyToRun(void)80 void Frodo::ReadyToRun(void)
81 {
82 	getcwd(AppDirPath, 256);
83 
84 	// Load preferences
85 	if (!prefs_path[0])
86 		strcpy(prefs_path, "Frodo.fpr");
87 	ThePrefs.Load(prefs_path);
88 
89 	if (ThePrefs.PrefsAtStartup) {
90 		if (!ThePrefs.ShowEditor(TRUE, prefs_path))
91 			return;
92 	}
93 
94 	// Create and start C64
95 	TheC64 = new C64;
96 	if (load_rom_files())
97 		TheC64->Run();
98 }
99 
100 
101 /*
102  *  Run preferences editor
103  */
104 
RunPrefsEditor(void)105 void Frodo::RunPrefsEditor(void)
106 {
107 	Prefs *prefs = new Prefs(ThePrefs);
108 	if (prefs->ShowEditor(FALSE, prefs_path)) {
109 		TheC64->NewPrefs(prefs);
110 		ThePrefs = *prefs;
111 	}
112 	delete prefs;
113 }
114