ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/main_Be.h
Revision: 1.3
Committed: 2003-07-02T14:46:24Z (21 years, 3 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -4 lines
Log Message:
when the ROM files are not found, builtin defaults are used

File Contents

# User Rev Content
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 cebix 1.3 load_rom_files();
162 cebix 1.1
163     // Run the 6510
164     TheC64->Run();
165     break;
166    
167     case MSG_PREFS: // Show preferences editor
168     if (TheC64 != NULL && !prefs_showing) {
169     TheC64->Pause();
170     TheC64->TheDisplay->Pause();
171    
172     Prefs *prefs = new Prefs(ThePrefs);
173     prefs_showing = true;
174     prefs->ShowEditor(false, prefs_path); // Sends MSG_PREFS_DONE on close
175     }
176     break;
177    
178     case MSG_PREFS_DONE: // Preferences editor closed
179     Prefs *prefs;
180     msg->FindPointer("prefs", &prefs);
181     if (!msg->FindBool("canceled")) {
182     TheC64->NewPrefs(prefs);
183     ThePrefs = *prefs;
184     }
185     delete prefs;
186     prefs_showing = false;
187    
188     TheC64->TheDisplay->Resume();
189     TheC64->Resume();
190     break;
191    
192     case MSG_RESET: // Reset C64
193     if (TheC64 != NULL)
194     TheC64->Reset();
195     break;
196    
197     case MSG_NMI: // NMI
198     if (TheC64 != NULL)
199     TheC64->NMI();
200     break;
201    
202     case MSG_SAM: // Invoke SAM
203     if (TheC64 != NULL && !prefs_showing && FromShell) {
204     TheC64->Pause();
205     TheC64->TheDisplay->Pause();
206     SAM(TheC64);
207     TheC64->TheDisplay->Resume();
208     TheC64->Resume();
209     }
210     break;
211    
212     case MSG_NEXTDISK: // Insert next disk in drive 8
213     if (TheC64 != NULL && !prefs_showing && strlen(ThePrefs.DrivePath[0]) > 4) {
214     char str[256];
215     strcpy(str, ThePrefs.DrivePath[0]);
216     char *p = str + strlen(str) - 5;
217    
218     // If path matches "*.?64", increment character before the '.'
219     if (p[1] == '.' && p[3] == '6' && p[4] == '4') {
220     p[0]++;
221    
222     // If no such file exists, set character before the '.' to '1', 'a' or 'A'
223     FILE *file;
224     if ((file = fopen(str, "rb")) == NULL) {
225     if (isdigit(p[0]))
226     p[0] = '1';
227     else if (isupper(p[0]))
228     p[0] = 'A';
229     else
230     p[0] = 'a';
231     } else
232     fclose(file);
233    
234     // Set new prefs
235     TheC64->Pause();
236     Prefs *prefs = new Prefs(ThePrefs);
237     strcpy(prefs->DrivePath[0], str);
238     TheC64->NewPrefs(prefs);
239     ThePrefs = *prefs;
240     delete prefs;
241     TheC64->Resume();
242     }
243     }
244     break;
245    
246     case MSG_TOGGLE_1541: // Toggle processor-level 1541 emulation
247     if (TheC64 != NULL && !prefs_showing) {
248     TheC64->Pause();
249     Prefs *prefs = new Prefs(ThePrefs);
250     prefs->Emul1541Proc = !prefs->Emul1541Proc;
251     TheC64->NewPrefs(prefs);
252     ThePrefs = *prefs;
253     delete prefs;
254     TheC64->Resume();
255     }
256     break;
257    
258     case MSG_OPEN_SNAPSHOT:
259     if (TheC64 != NULL && !prefs_showing)
260     open_panel->Show();
261     break;
262    
263     case MSG_SAVE_SNAPSHOT:
264     if (TheC64 != NULL && !prefs_showing)
265     save_panel->Show();
266     break;
267    
268     case MSG_OPEN_SNAPSHOT_RETURNED:
269     if (TheC64 != NULL && !prefs_showing) {
270     entry_ref the_ref;
271     BEntry the_entry;
272     if (msg->FindRef("refs", &the_ref) == B_NO_ERROR)
273     if (the_entry.SetTo(&the_ref) == B_NO_ERROR)
274     if (the_entry.IsFile()) {
275     char path[1024];
276     BPath the_path;
277     the_entry.GetPath(&the_path);
278     strncpy(path, the_path.Path(), 1023);
279     path[1023] = 0;
280     TheC64->Pause();
281     TheC64->LoadSnapshot(path);
282     TheC64->Resume();
283     }
284     }
285     break;
286    
287     case MSG_SAVE_SNAPSHOT_RETURNED:
288     if (TheC64 != NULL && !prefs_showing) {
289     entry_ref the_ref;
290     BEntry the_entry;
291     if (msg->FindRef("directory", &the_ref) == B_NO_ERROR)
292     if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
293     char path[1024];
294     BPath the_path;
295     the_entry.GetPath(&the_path);
296     strncpy(path, the_path.Path(), 1023);
297     strncat(path, "/", 1023);
298     strncat(path, msg->FindString("name"), 1023);
299     path[1023] = 0;
300     TheC64->Pause();
301     TheC64->SaveSnapshot(path);
302     TheC64->Resume();
303     }
304     }
305     break;
306    
307     default:
308     BApplication::MessageReceived(msg);
309     }
310     }
311    
312    
313     /*
314     * Quit requested (either by menu or by closing the C64 display window)
315     */
316    
317     bool Frodo::QuitRequested(void)
318     {
319     // Stop emulation
320     if (TheC64) {
321     TheC64->Quit();
322     delete TheC64;
323     }
324    
325     delete AboutBitmap;
326     delete open_panel;
327     delete save_panel;
328    
329     return BApplication::QuitRequested();
330     }
331    
332    
333     /*
334     * Display "about" window
335     */
336    
337     class AboutView : public BView {
338     public:
339     AboutView() : BView(AboutFrame, "", B_FOLLOW_NONE, B_WILL_DRAW) {}
340    
341     virtual void AttachedToWindow(void)
342     {
343     SetHighColor(0, 0, 0);
344     }
345    
346     virtual void Draw(BRect update)
347     {
348     DrawBitmap(AboutBitmap, update, update);
349    
350     SetFont(be_bold_font);
351     SetDrawingMode(B_OP_OVER);
352     MovePenTo(204, 20);
353     DrawString(VERSION_STRING);
354    
355     SetFont(be_plain_font);
356     MovePenTo(204, 40);
357     DrawString("by Christian Bauer");
358     MovePenTo(204, 52);
359     DrawString("<cbauer@iphcip1.physik.uni-mainz.de>");
360     MovePenTo(204, 75);
361     DrawString(B_UTF8_COPYRIGHT " Copyright 1994-1997");
362     MovePenTo(204, 87);
363     DrawString("Freely distributable.");
364     }
365    
366     virtual void MouseDown(BPoint point)
367     {
368     Window()->PostMessage(B_QUIT_REQUESTED);
369     }
370     };
371    
372     class AboutWindow : public BWindow {
373     public:
374     AboutWindow() : BWindow(AboutFrame, NULL, B_BORDERED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK)
375     {
376     Lock();
377     MoveTo(100, 100);
378     AboutView *view = new AboutView;
379     AddChild(view);
380     view->MakeFocus();
381     Unlock();
382     Show();
383     }
384     };
385    
386     void Frodo::AboutRequested(void)
387     {
388     new AboutWindow();
389     }