1 |
cebix |
1.1 |
/* |
2 |
|
|
* main_Be.h - Main program, BeOS specific stuff |
3 |
|
|
* |
4 |
cebix |
1.2 |
* Frodo (C) 1994-1997,2002-2003 Christian Bauer |
5 |
cebix |
1.1 |
* |
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 <AppKit.h> |
22 |
|
|
#include <StorageKit.h> |
23 |
|
|
#include <Path.h> |
24 |
|
|
#include <InterfaceKit.h> |
25 |
|
|
|
26 |
|
|
#include "Version.h" |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
// Global variables |
30 |
|
|
bool FromShell; |
31 |
|
|
BEntry AppDirectory; |
32 |
|
|
BBitmap *AboutBitmap; |
33 |
|
|
const BRect AboutFrame = BRect(0, 0, 383, 99); |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
/* |
37 |
|
|
* Create application object and start it |
38 |
|
|
*/ |
39 |
|
|
|
40 |
|
|
int main(int argc, char **argv) |
41 |
|
|
{ |
42 |
|
|
Frodo *the_app; |
43 |
|
|
|
44 |
|
|
srand(real_time_clock()); |
45 |
|
|
FromShell = (argc != 0); // !! This doesn't work... |
46 |
|
|
|
47 |
|
|
the_app = new Frodo(); |
48 |
|
|
if (the_app != NULL) { |
49 |
|
|
the_app->Run(); |
50 |
|
|
delete the_app; |
51 |
|
|
} |
52 |
|
|
return 0; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
/* |
57 |
|
|
* Constructor: Initialize member variables |
58 |
|
|
*/ |
59 |
|
|
|
60 |
|
|
Frodo::Frodo() : BApplication(APP_SIGNATURE), this_messenger(this) |
61 |
|
|
{ |
62 |
|
|
TheC64 = NULL; |
63 |
|
|
AboutBitmap = NULL; |
64 |
|
|
strcpy(prefs_path, "/boot/home/config/settings/Frodo_settings"); |
65 |
|
|
prefs_showing = false; |
66 |
|
|
|
67 |
|
|
// Create file panels |
68 |
|
|
open_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_OPEN_SNAPSHOT_RETURNED)); |
69 |
|
|
open_panel->Window()->SetTitle("Frodo: Load snapshot"); |
70 |
|
|
save_panel = new BFilePanel(B_SAVE_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_SAVE_SNAPSHOT_RETURNED)); |
71 |
|
|
save_panel->Window()->SetTitle("Frodo: Save snapshot"); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
/* |
76 |
|
|
* Process command line arguments |
77 |
|
|
*/ |
78 |
|
|
|
79 |
|
|
void Frodo::ArgvReceived(int32 argc, char **argv) |
80 |
|
|
{ |
81 |
|
|
if (argc == 2) { |
82 |
|
|
strncpy(prefs_path, argv[1], 1023); |
83 |
|
|
prefs_path[1023] = 0; |
84 |
|
|
} |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
/* |
89 |
|
|
* Process Browser arguments |
90 |
|
|
*/ |
91 |
|
|
|
92 |
|
|
void Frodo::RefsReceived(BMessage *message) |
93 |
|
|
{ |
94 |
|
|
// Set preferences path unless prefs editor is open or C64 is running |
95 |
|
|
if (!prefs_showing && !TheC64) { |
96 |
|
|
entry_ref the_ref; |
97 |
|
|
BEntry the_entry; |
98 |
|
|
|
99 |
|
|
if (message->FindRef("refs", &the_ref) == B_NO_ERROR) |
100 |
|
|
if (the_entry.SetTo(&the_ref) == B_NO_ERROR) |
101 |
|
|
if (the_entry.IsFile()) { |
102 |
|
|
BPath the_path; |
103 |
|
|
the_entry.GetPath(&the_path); |
104 |
|
|
strncpy(prefs_path, the_path.Path(), 1023); |
105 |
|
|
prefs_path[1023] = 0; |
106 |
|
|
} |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
/* |
112 |
|
|
* Arguments processed, prepare emulation and show preferences editor window |
113 |
|
|
*/ |
114 |
|
|
|
115 |
|
|
void Frodo::ReadyToRun(void) |
116 |
|
|
{ |
117 |
|
|
// Find application directory and cwd to it |
118 |
|
|
app_info the_info; |
119 |
|
|
GetAppInfo(&the_info); |
120 |
|
|
BEntry the_file(&the_info.ref); |
121 |
|
|
the_file.GetParent(&AppDirectory); |
122 |
|
|
BPath the_path; |
123 |
|
|
AppDirectory.GetPath(&the_path); |
124 |
|
|
strncpy(AppDirPath, the_path.Path(), 1023); |
125 |
|
|
AppDirPath[1023] = 0; |
126 |
|
|
chdir(AppDirPath); |
127 |
|
|
|
128 |
|
|
// Set up "about" window bitmap |
129 |
|
|
AboutBitmap = new BBitmap(AboutFrame, B_COLOR_8_BIT); |
130 |
|
|
FILE *logofile = fopen("Frodo Logo", "rb"); |
131 |
|
|
if (logofile != NULL) { |
132 |
|
|
fread(AboutBitmap->Bits(), 384*100, 1, logofile); |
133 |
|
|
fclose(logofile); |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
// Load preferences |
137 |
|
|
ThePrefs.Load(prefs_path); |
138 |
|
|
|
139 |
|
|
// Show preferences editor (sends MSG_STARTUP on close) |
140 |
|
|
prefs_showing = true; |
141 |
|
|
ThePrefs.ShowEditor(true, prefs_path); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
|
145 |
|
|
/* |
146 |
|
|
* Handle incoming messages |
147 |
|
|
*/ |
148 |
|
|
|
149 |
|
|
void Frodo::MessageReceived(BMessage *msg) |
150 |
|
|
{ |
151 |
|
|
switch (msg->what) { |
152 |
|
|
case MSG_STARTUP: // Start the emulation |
153 |
|
|
|
154 |
|
|
// Preferences editor is not longer on screen |
155 |
|
|
prefs_showing = false; |
156 |
|
|
|
157 |
|
|
// Create everything |
158 |
|
|
TheC64 = new C64; |
159 |
|
|
|
160 |
|
|
// Load ROMs |
161 |
|
|
if (!load_rom_files()) { |
162 |
|
|
PostMessage(B_QUIT_REQUESTED); |
163 |
|
|
return; |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
// Run the 6510 |
167 |
|
|
TheC64->Run(); |
168 |
|
|
break; |
169 |
|
|
|
170 |
|
|
case MSG_PREFS: // Show preferences editor |
171 |
|
|
if (TheC64 != NULL && !prefs_showing) { |
172 |
|
|
TheC64->Pause(); |
173 |
|
|
TheC64->TheDisplay->Pause(); |
174 |
|
|
|
175 |
|
|
Prefs *prefs = new Prefs(ThePrefs); |
176 |
|
|
prefs_showing = true; |
177 |
|
|
prefs->ShowEditor(false, prefs_path); // Sends MSG_PREFS_DONE on close |
178 |
|
|
} |
179 |
|
|
break; |
180 |
|
|
|
181 |
|
|
case MSG_PREFS_DONE: // Preferences editor closed |
182 |
|
|
Prefs *prefs; |
183 |
|
|
msg->FindPointer("prefs", &prefs); |
184 |
|
|
if (!msg->FindBool("canceled")) { |
185 |
|
|
TheC64->NewPrefs(prefs); |
186 |
|
|
ThePrefs = *prefs; |
187 |
|
|
} |
188 |
|
|
delete prefs; |
189 |
|
|
prefs_showing = false; |
190 |
|
|
|
191 |
|
|
TheC64->TheDisplay->Resume(); |
192 |
|
|
TheC64->Resume(); |
193 |
|
|
break; |
194 |
|
|
|
195 |
|
|
case MSG_RESET: // Reset C64 |
196 |
|
|
if (TheC64 != NULL) |
197 |
|
|
TheC64->Reset(); |
198 |
|
|
break; |
199 |
|
|
|
200 |
|
|
case MSG_NMI: // NMI |
201 |
|
|
if (TheC64 != NULL) |
202 |
|
|
TheC64->NMI(); |
203 |
|
|
break; |
204 |
|
|
|
205 |
|
|
case MSG_SAM: // Invoke SAM |
206 |
|
|
if (TheC64 != NULL && !prefs_showing && FromShell) { |
207 |
|
|
TheC64->Pause(); |
208 |
|
|
TheC64->TheDisplay->Pause(); |
209 |
|
|
SAM(TheC64); |
210 |
|
|
TheC64->TheDisplay->Resume(); |
211 |
|
|
TheC64->Resume(); |
212 |
|
|
} |
213 |
|
|
break; |
214 |
|
|
|
215 |
|
|
case MSG_NEXTDISK: // Insert next disk in drive 8 |
216 |
|
|
if (TheC64 != NULL && !prefs_showing && strlen(ThePrefs.DrivePath[0]) > 4) { |
217 |
|
|
char str[256]; |
218 |
|
|
strcpy(str, ThePrefs.DrivePath[0]); |
219 |
|
|
char *p = str + strlen(str) - 5; |
220 |
|
|
|
221 |
|
|
// If path matches "*.?64", increment character before the '.' |
222 |
|
|
if (p[1] == '.' && p[3] == '6' && p[4] == '4') { |
223 |
|
|
p[0]++; |
224 |
|
|
|
225 |
|
|
// If no such file exists, set character before the '.' to '1', 'a' or 'A' |
226 |
|
|
FILE *file; |
227 |
|
|
if ((file = fopen(str, "rb")) == NULL) { |
228 |
|
|
if (isdigit(p[0])) |
229 |
|
|
p[0] = '1'; |
230 |
|
|
else if (isupper(p[0])) |
231 |
|
|
p[0] = 'A'; |
232 |
|
|
else |
233 |
|
|
p[0] = 'a'; |
234 |
|
|
} else |
235 |
|
|
fclose(file); |
236 |
|
|
|
237 |
|
|
// Set new prefs |
238 |
|
|
TheC64->Pause(); |
239 |
|
|
Prefs *prefs = new Prefs(ThePrefs); |
240 |
|
|
strcpy(prefs->DrivePath[0], str); |
241 |
|
|
TheC64->NewPrefs(prefs); |
242 |
|
|
ThePrefs = *prefs; |
243 |
|
|
delete prefs; |
244 |
|
|
TheC64->Resume(); |
245 |
|
|
} |
246 |
|
|
} |
247 |
|
|
break; |
248 |
|
|
|
249 |
|
|
case MSG_TOGGLE_1541: // Toggle processor-level 1541 emulation |
250 |
|
|
if (TheC64 != NULL && !prefs_showing) { |
251 |
|
|
TheC64->Pause(); |
252 |
|
|
Prefs *prefs = new Prefs(ThePrefs); |
253 |
|
|
prefs->Emul1541Proc = !prefs->Emul1541Proc; |
254 |
|
|
TheC64->NewPrefs(prefs); |
255 |
|
|
ThePrefs = *prefs; |
256 |
|
|
delete prefs; |
257 |
|
|
TheC64->Resume(); |
258 |
|
|
} |
259 |
|
|
break; |
260 |
|
|
|
261 |
|
|
case MSG_OPEN_SNAPSHOT: |
262 |
|
|
if (TheC64 != NULL && !prefs_showing) |
263 |
|
|
open_panel->Show(); |
264 |
|
|
break; |
265 |
|
|
|
266 |
|
|
case MSG_SAVE_SNAPSHOT: |
267 |
|
|
if (TheC64 != NULL && !prefs_showing) |
268 |
|
|
save_panel->Show(); |
269 |
|
|
break; |
270 |
|
|
|
271 |
|
|
case MSG_OPEN_SNAPSHOT_RETURNED: |
272 |
|
|
if (TheC64 != NULL && !prefs_showing) { |
273 |
|
|
entry_ref the_ref; |
274 |
|
|
BEntry the_entry; |
275 |
|
|
if (msg->FindRef("refs", &the_ref) == B_NO_ERROR) |
276 |
|
|
if (the_entry.SetTo(&the_ref) == B_NO_ERROR) |
277 |
|
|
if (the_entry.IsFile()) { |
278 |
|
|
char path[1024]; |
279 |
|
|
BPath the_path; |
280 |
|
|
the_entry.GetPath(&the_path); |
281 |
|
|
strncpy(path, the_path.Path(), 1023); |
282 |
|
|
path[1023] = 0; |
283 |
|
|
TheC64->Pause(); |
284 |
|
|
TheC64->LoadSnapshot(path); |
285 |
|
|
TheC64->Resume(); |
286 |
|
|
} |
287 |
|
|
} |
288 |
|
|
break; |
289 |
|
|
|
290 |
|
|
case MSG_SAVE_SNAPSHOT_RETURNED: |
291 |
|
|
if (TheC64 != NULL && !prefs_showing) { |
292 |
|
|
entry_ref the_ref; |
293 |
|
|
BEntry the_entry; |
294 |
|
|
if (msg->FindRef("directory", &the_ref) == B_NO_ERROR) |
295 |
|
|
if (the_entry.SetTo(&the_ref) == B_NO_ERROR) { |
296 |
|
|
char path[1024]; |
297 |
|
|
BPath the_path; |
298 |
|
|
the_entry.GetPath(&the_path); |
299 |
|
|
strncpy(path, the_path.Path(), 1023); |
300 |
|
|
strncat(path, "/", 1023); |
301 |
|
|
strncat(path, msg->FindString("name"), 1023); |
302 |
|
|
path[1023] = 0; |
303 |
|
|
TheC64->Pause(); |
304 |
|
|
TheC64->SaveSnapshot(path); |
305 |
|
|
TheC64->Resume(); |
306 |
|
|
} |
307 |
|
|
} |
308 |
|
|
break; |
309 |
|
|
|
310 |
|
|
default: |
311 |
|
|
BApplication::MessageReceived(msg); |
312 |
|
|
} |
313 |
|
|
} |
314 |
|
|
|
315 |
|
|
|
316 |
|
|
/* |
317 |
|
|
* Quit requested (either by menu or by closing the C64 display window) |
318 |
|
|
*/ |
319 |
|
|
|
320 |
|
|
bool Frodo::QuitRequested(void) |
321 |
|
|
{ |
322 |
|
|
// Stop emulation |
323 |
|
|
if (TheC64) { |
324 |
|
|
TheC64->Quit(); |
325 |
|
|
delete TheC64; |
326 |
|
|
} |
327 |
|
|
|
328 |
|
|
delete AboutBitmap; |
329 |
|
|
delete open_panel; |
330 |
|
|
delete save_panel; |
331 |
|
|
|
332 |
|
|
return BApplication::QuitRequested(); |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
|
336 |
|
|
/* |
337 |
|
|
* Display "about" window |
338 |
|
|
*/ |
339 |
|
|
|
340 |
|
|
class AboutView : public BView { |
341 |
|
|
public: |
342 |
|
|
AboutView() : BView(AboutFrame, "", B_FOLLOW_NONE, B_WILL_DRAW) {} |
343 |
|
|
|
344 |
|
|
virtual void AttachedToWindow(void) |
345 |
|
|
{ |
346 |
|
|
SetHighColor(0, 0, 0); |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
virtual void Draw(BRect update) |
350 |
|
|
{ |
351 |
|
|
DrawBitmap(AboutBitmap, update, update); |
352 |
|
|
|
353 |
|
|
SetFont(be_bold_font); |
354 |
|
|
SetDrawingMode(B_OP_OVER); |
355 |
|
|
MovePenTo(204, 20); |
356 |
|
|
DrawString(VERSION_STRING); |
357 |
|
|
|
358 |
|
|
SetFont(be_plain_font); |
359 |
|
|
MovePenTo(204, 40); |
360 |
|
|
DrawString("by Christian Bauer"); |
361 |
|
|
MovePenTo(204, 52); |
362 |
|
|
DrawString("<cbauer@iphcip1.physik.uni-mainz.de>"); |
363 |
|
|
MovePenTo(204, 75); |
364 |
|
|
DrawString(B_UTF8_COPYRIGHT " Copyright 1994-1997"); |
365 |
|
|
MovePenTo(204, 87); |
366 |
|
|
DrawString("Freely distributable."); |
367 |
|
|
} |
368 |
|
|
|
369 |
|
|
virtual void MouseDown(BPoint point) |
370 |
|
|
{ |
371 |
|
|
Window()->PostMessage(B_QUIT_REQUESTED); |
372 |
|
|
} |
373 |
|
|
}; |
374 |
|
|
|
375 |
|
|
class AboutWindow : public BWindow { |
376 |
|
|
public: |
377 |
|
|
AboutWindow() : BWindow(AboutFrame, NULL, B_BORDERED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK) |
378 |
|
|
{ |
379 |
|
|
Lock(); |
380 |
|
|
MoveTo(100, 100); |
381 |
|
|
AboutView *view = new AboutView; |
382 |
|
|
AddChild(view); |
383 |
|
|
view->MakeFocus(); |
384 |
|
|
Unlock(); |
385 |
|
|
Show(); |
386 |
|
|
} |
387 |
|
|
}; |
388 |
|
|
|
389 |
|
|
void Frodo::AboutRequested(void) |
390 |
|
|
{ |
391 |
|
|
new AboutWindow(); |
392 |
|
|
} |