ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/main_Be.h
Revision: 1.4
Committed: 2003-07-09T13:54:22Z (21 years, 4 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.3: +3 -2 lines
Log Message:
applied misc fixes that have accumulated over the time

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