ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/main_Amiga.h
Revision: 1.4
Committed: 2004-01-12T15:13:20Z (20 years, 9 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * main_Amiga.h - Main program, AmigaOS specific stuff
3 *
4 * Frodo (C) 1994-1997,2002-2004 Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <exec/types.h>
22 #include <exec/execbase.h>
23 #include <proto/exec.h>
24 #include <proto/intuition.h>
25
26
27 // Global variables
28 Frodo *be_app; // Pointer to Frodo object
29
30 // Library bases
31 extern ExecBase *SysBase;
32 struct GfxBase *GfxBase = NULL;
33 struct IntuitionBase *IntuitionBase = NULL;
34 struct Library *GadToolsBase = NULL;
35 struct Library *DiskfontBase = NULL;
36 struct Library *AslBase = NULL;
37
38 // Prototypes
39 void error_exit(char *str);
40 void open_libs(void);
41 void close_libs(void);
42
43
44 /*
45 * Create application object and start it
46 */
47
48 int main(int argc, char **argv)
49 {
50 if ((SysBase->AttnFlags & (AFF_68040 | AFF_68881)) != (AFF_68040 | AFF_68881))
51 error_exit("68040/68881 or higher required.\n");
52 open_libs();
53
54 ULONG secs, micros;
55 CurrentTime(&secs, &micros);
56 srand(micros);
57
58 be_app = new Frodo();
59 be_app->ArgvReceived(argc, argv);
60 be_app->ReadyToRun();
61 delete be_app;
62
63 close_libs();
64 return 0;
65 }
66
67
68 /*
69 * Low-level failure
70 */
71
72 void error_exit(char *str)
73 {
74 printf(str);
75 close_libs();
76 exit(20);
77 }
78
79
80 /*
81 * Open libraries
82 */
83
84 void open_libs(void)
85 {
86 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
87 error_exit("Couldn't open Gfx V39.\n");
88 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
89 error_exit("Couldn't open Intuition V39.\n");
90 if (!(GadToolsBase = OpenLibrary("gadtools.library", 39)))
91 error_exit("Couldn't open GadTools V39.\n");
92 if (!(DiskfontBase = OpenLibrary("diskfont.library", 39)))
93 error_exit("Couldn't open Diskfont V39.\n");
94 if (!(AslBase = OpenLibrary("asl.library", 39)))
95 error_exit("Couldn't open ASL V39.\n");
96 }
97
98
99 /*
100 * Close libraries
101 */
102
103 void close_libs(void)
104 {
105 if (AslBase)
106 CloseLibrary(AslBase);
107 if (DiskfontBase)
108 CloseLibrary(DiskfontBase);
109 if (GadToolsBase)
110 CloseLibrary(GadToolsBase);
111 if (IntuitionBase)
112 CloseLibrary((struct Library *)IntuitionBase);
113 if (GfxBase)
114 CloseLibrary((struct Library *)GfxBase);
115 }
116
117
118 /*
119 * Constructor: Initialize member variables
120 */
121
122 Frodo::Frodo()
123 {
124 TheC64 = NULL;
125 prefs_path[0] = 0;
126 }
127
128
129 /*
130 * Process command line arguments
131 */
132
133 void Frodo::ArgvReceived(int argc, char **argv)
134 {
135 if (argc == 2)
136 strncpy(prefs_path, argv[1], 255);
137 }
138
139
140 /*
141 * Arguments processed, run emulation
142 */
143
144 void Frodo::ReadyToRun(void)
145 {
146 getcwd(AppDirPath, 256);
147
148 // Load preferences
149 if (!prefs_path[0])
150 strcpy(prefs_path, "Frodo Prefs");
151 ThePrefs.Load(prefs_path);
152
153 // Show preferences editor
154 if (ThePrefs.ShowEditor(TRUE, prefs_path)) {
155
156 // Create and start C64
157 TheC64 = new C64;
158 load_rom_files();
159 TheC64->Run();
160 delete TheC64;
161 }
162 }
163
164
165 /*
166 * Run preferences editor
167 */
168
169 void Frodo::RunPrefsEditor(void)
170 {
171 Prefs *prefs = new Prefs(ThePrefs);
172 if (prefs->ShowEditor(FALSE, prefs_path)) {
173 TheC64->NewPrefs(prefs);
174 ThePrefs = *prefs;
175 }
176 delete prefs;
177 }